mirror of
				https://github.com/excalidraw/excalidraw.git
				synced 2025-11-04 12:54:23 +01:00 
			
		
		
		
	@@ -105,11 +105,14 @@ import { isLinearElement } from "../element/typeChecks";
 | 
			
		||||
import { rescalePoints } from "../points";
 | 
			
		||||
import { actionFinalize } from "../actions";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param func handler taking at most single parameter (event).
 | 
			
		||||
 */
 | 
			
		||||
function withBatchedUpdates<
 | 
			
		||||
  TFunction extends ((event: any) => void) | (() => void)
 | 
			
		||||
>(func: TFunction) {
 | 
			
		||||
>(func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never) {
 | 
			
		||||
  return (event => {
 | 
			
		||||
    unstable_batchedUpdates(func, event);
 | 
			
		||||
    unstable_batchedUpdates(func as TFunction, event);
 | 
			
		||||
  }) as TFunction;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -164,30 +167,28 @@ export class App extends React.Component<any, AppState> {
 | 
			
		||||
    this.actionManager.registerAction(createRedoAction(history));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private syncActionResult = withBatchedUpdates(
 | 
			
		||||
    (res: ActionResult, commitToHistory: boolean = true) => {
 | 
			
		||||
      if (this.unmounted) {
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      if (res.elements) {
 | 
			
		||||
        globalSceneState.replaceAllElements(res.elements);
 | 
			
		||||
        if (commitToHistory) {
 | 
			
		||||
          history.resumeRecording();
 | 
			
		||||
        }
 | 
			
		||||
  private syncActionResult = withBatchedUpdates((res: ActionResult) => {
 | 
			
		||||
    if (this.unmounted) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (res.elements) {
 | 
			
		||||
      globalSceneState.replaceAllElements(res.elements);
 | 
			
		||||
      if (res.commitToHistory) {
 | 
			
		||||
        history.resumeRecording();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      if (res.appState) {
 | 
			
		||||
        if (commitToHistory) {
 | 
			
		||||
          history.resumeRecording();
 | 
			
		||||
        }
 | 
			
		||||
        this.setState(state => ({
 | 
			
		||||
          ...res.appState,
 | 
			
		||||
          isCollaborating: state.isCollaborating,
 | 
			
		||||
          collaborators: state.collaborators,
 | 
			
		||||
        }));
 | 
			
		||||
    if (res.appState) {
 | 
			
		||||
      if (res.commitToHistory) {
 | 
			
		||||
        history.resumeRecording();
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  );
 | 
			
		||||
      this.setState(state => ({
 | 
			
		||||
        ...res.appState,
 | 
			
		||||
        isCollaborating: state.isCollaborating,
 | 
			
		||||
        collaborators: state.collaborators,
 | 
			
		||||
      }));
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  private onCut = withBatchedUpdates((event: ClipboardEvent) => {
 | 
			
		||||
    if (isWritableElement(event.target)) {
 | 
			
		||||
@@ -917,7 +918,11 @@ export class App extends React.Component<any, AppState> {
 | 
			
		||||
              ) {
 | 
			
		||||
                loadFromBlob(file)
 | 
			
		||||
                  .then(({ elements, appState }) =>
 | 
			
		||||
                    this.syncActionResult({ elements, appState }),
 | 
			
		||||
                    this.syncActionResult({
 | 
			
		||||
                      elements,
 | 
			
		||||
                      appState,
 | 
			
		||||
                      commitToHistory: false,
 | 
			
		||||
                    }),
 | 
			
		||||
                  )
 | 
			
		||||
                  .catch(error => console.error(error));
 | 
			
		||||
              }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user