@@ -167,7 +167,10 @@ import {
167167} from "../keys" ;
168168import { distance2d , getGridPoint , isPathALoop } from "../math" ;
169169import { renderSceneThrottled } from "../renderer/renderScene" ;
170- import { invalidateShapeForElement } from "../renderer/renderElement" ;
170+ import {
171+ clearRenderCache ,
172+ invalidateShapeForElement ,
173+ } from "../renderer/renderElement" ;
171174import {
172175 calculateScrollCenter ,
173176 getTextBindableContainerAtPosition ,
@@ -270,7 +273,7 @@ const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
270273export const useDevice = ( ) => useContext < Device > ( DeviceContext ) ;
271274const ExcalidrawContainerContext = React . createContext < {
272275 container : HTMLDivElement | null ;
273- id : string | null ;
276+ id ? : string | null ;
274277} > ( { container : null , id : null } ) ;
275278export const useExcalidrawContainer = ( ) =>
276279 useContext ( ExcalidrawContainerContext ) ;
@@ -385,6 +388,7 @@ class App extends React.Component<AppProps, AppState> {
385388 setActiveTool : this . setActiveTool ,
386389 setCursor : this . setCursor ,
387390 resetCursor : this . resetCursor ,
391+ app : this ,
388392 } as const ;
389393 if ( typeof excalidrawRef === "function" ) {
390394 excalidrawRef ( api ) ;
@@ -484,6 +488,7 @@ class App extends React.Component<AppProps, AppState> {
484488 return (
485489 < div
486490 className = { clsx ( "excalidraw excalidraw-container" , {
491+ "excalidraw--zen-mode" : zenModeEnabled ,
487492 "excalidraw--view-mode" : viewModeEnabled ,
488493 "excalidraw--mobile" : this . device . isMobile ,
489494 } ) }
@@ -499,6 +504,7 @@ class App extends React.Component<AppProps, AppState> {
499504 >
500505 < DeviceContext . Provider value = { this . device } >
501506 < LayerUI
507+ onHomeButtonClick = { this . props . onHomeButtonClick }
502508 canvas = { this . canvas }
503509 appState = { this . state }
504510 files = { this . files }
@@ -529,6 +535,7 @@ class App extends React.Component<AppProps, AppState> {
529535 }
530536 showThemeBtn = {
531537 typeof this . props ?. theme === "undefined" &&
538+ this . props . UIOptions . canvasActions &&
532539 this . props . UIOptions . canvasActions . theme
533540 }
534541 libraryReturnUrl = { this . props . libraryReturnUrl }
@@ -787,6 +794,13 @@ class App extends React.Component<AppProps, AppState> {
787794 } ;
788795 }
789796
797+ if ( initialData ?. scrollX != null ) {
798+ scene . appState . scrollX = initialData . scrollX ;
799+ }
800+ if ( initialData ?. scrollY != null ) {
801+ scene . appState . scrollY = initialData . scrollY ;
802+ }
803+
790804 this . resetHistory ( ) ;
791805 this . syncActionResult ( {
792806 ...scene ,
@@ -917,6 +931,25 @@ class App extends React.Component<AppProps, AppState> {
917931 this . unmounted = true ;
918932 this . removeEventListeners ( ) ;
919933 this . scene . destroy ( ) ;
934+ clearRenderCache ( ) ;
935+
936+ this . scene = new Scene ( ) ;
937+ this . history = new History ( ) ;
938+ this . actionManager = new ActionManager (
939+ this . syncActionResult ,
940+ ( ) => this . state ,
941+ ( ) => this . scene . getElementsIncludingDeleted ( ) ,
942+ this ,
943+ ) ;
944+ this . library = new Library ( this ) ;
945+ this . canvas = null ;
946+ this . rc = null ;
947+
948+ // @ts -ignore
949+ this . excalidrawContainerRef . current = undefined ;
950+ this . nearestScrollableContainer = undefined ;
951+ this . excalidrawContainerValue = { container : null , id : "unmounted" } ;
952+
920953 clearTimeout ( touchTimeout ) ;
921954 touchTimeout = 0 ;
922955 }
@@ -975,6 +1008,7 @@ class App extends React.Component<AppProps, AppState> {
9751008 this . disableEvent ,
9761009 false ,
9771010 ) ;
1011+ document . fonts ?. removeEventListener ?.( "loadingdone" , this . onFontLoaded ) ;
9781012
9791013 document . removeEventListener (
9801014 EVENT . GESTURE_START ,
@@ -1122,6 +1156,15 @@ class App extends React.Component<AppProps, AppState> {
11221156 } ) ;
11231157 }
11241158
1159+ if (
1160+ ! this . props . UIOptions . canvasActions &&
1161+ this . state . openMenu === "canvas"
1162+ ) {
1163+ this . setState ( {
1164+ openMenu : null ,
1165+ } ) ;
1166+ }
1167+
11251168 if ( this . props . name && prevProps . name !== this . props . name ) {
11261169 this . setState ( {
11271170 name : this . props . name ,
@@ -1269,6 +1312,7 @@ class App extends React.Component<AppProps, AppState> {
12691312 this . scene . getElementsIncludingDeleted ( ) ,
12701313 this . state ,
12711314 this . files ,
1315+ this . props . id ,
12721316 ) ;
12731317 }
12741318 }
0 commit comments