mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: support updating appState in updateScene API (#3576)
* feat: support updating appState in updateScene API * make `updateScene.data.appState` more type-safe * restore `appState` when passing to `updateScene` * fix Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
f1cf28a84e
commit
78da4c075e
5 changed files with 29 additions and 21 deletions
|
@ -1458,26 +1458,30 @@ class App extends React.Component<AppProps, AppState> {
|
|||
}
|
||||
};
|
||||
|
||||
public updateScene = withBatchedUpdates((sceneData: SceneData) => {
|
||||
if (sceneData.commitToHistory) {
|
||||
this.history.resumeRecording();
|
||||
}
|
||||
public updateScene = withBatchedUpdates(
|
||||
<K extends keyof AppState>(sceneData: {
|
||||
elements?: SceneData["elements"];
|
||||
appState?: Pick<AppState, K> | null;
|
||||
collaborators?: SceneData["collaborators"];
|
||||
commitToHistory?: SceneData["commitToHistory"];
|
||||
}) => {
|
||||
if (sceneData.commitToHistory) {
|
||||
this.history.resumeRecording();
|
||||
}
|
||||
|
||||
// currently we only support syncing background color
|
||||
if (sceneData.appState?.viewBackgroundColor) {
|
||||
this.setState({
|
||||
viewBackgroundColor: sceneData.appState.viewBackgroundColor,
|
||||
});
|
||||
}
|
||||
if (sceneData.appState) {
|
||||
this.setState(sceneData.appState);
|
||||
}
|
||||
|
||||
if (sceneData.elements) {
|
||||
this.scene.replaceAllElements(sceneData.elements);
|
||||
}
|
||||
if (sceneData.elements) {
|
||||
this.scene.replaceAllElements(sceneData.elements);
|
||||
}
|
||||
|
||||
if (sceneData.collaborators) {
|
||||
this.setState({ collaborators: sceneData.collaborators });
|
||||
}
|
||||
});
|
||||
if (sceneData.collaborators) {
|
||||
this.setState({ collaborators: sceneData.collaborators });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
private onSceneUpdated = () => {
|
||||
this.setState({});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue