Skip to content

Commit

Permalink
trying to resolve issue with slidingPanes
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed May 6, 2021
1 parent a26e565 commit 660f6e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/ExcalidrawView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ export interface ExportSettings {
}

export default class ExcalidrawView extends TextFileView {
private getScene: any;
private getScene: Function;
private refresh: Function;
private excalidrawRef: React.MutableRefObject<any>;
private justLoaded: boolean;
private plugin: ExcalidrawPlugin;

constructor(leaf: WorkspaceLeaf, plugin: ExcalidrawPlugin) {
super(leaf);
this.getScene = null;
this.refresh = null;
this.excalidrawRef = null;
this.plugin = plugin;
this.justLoaded = false;
Expand Down Expand Up @@ -125,6 +127,7 @@ export default class ExcalidrawView extends TextFileView {
if(this.excalidrawRef) {
this.excalidrawRef = null;
this.getScene = null;
this.refresh = null;
ReactDOM.unmountComponentAtNode(this.contentEl);
}
}
Expand Down Expand Up @@ -183,7 +186,7 @@ export default class ExcalidrawView extends TextFileView {
width: undefined,
height: undefined
});

this.excalidrawRef = excalidrawRef;
React.useEffect(() => {
setDimensions({
Expand All @@ -197,6 +200,7 @@ export default class ExcalidrawView extends TextFileView {
width: this.contentEl.clientWidth,
height: this.contentEl.clientHeight,
});
console.log("Excalidraw resize",this.contentEl.clientWidth,this.contentEl.clientHeight);
} catch(err) {console.log ("Excalidraw React-Wrapper, onResize ",err)}
};
window.addEventListener("resize", onResize);
Expand All @@ -220,6 +224,11 @@ export default class ExcalidrawView extends TextFileView {
}
});
};

this.refresh = () => {
if(!excalidrawRef?.current) return;
excalidrawRef.current.refresh();
};

return React.createElement(
React.Fragment,
Expand All @@ -233,7 +242,6 @@ export default class ExcalidrawView extends TextFileView {
},
React.createElement(Excalidraw.default, {
ref: excalidrawRef,
key: "xyz",
width: dimensions.width,
height: dimensions.height,
UIOptions: {
Expand All @@ -245,6 +253,7 @@ export default class ExcalidrawView extends TextFileView {
},
},
initialData: initdata,
detectScroll: true,
onChange: (et:ExcalidrawElement[],st:AppState) => {
if(this.justLoaded) {
this.justLoaded = false;
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export default class ExcalidrawPlugin extends Plugin {
.forEach((el) => el.dispatchEvent(e));
}

public async openDrawing(drawingFile: TFile, onNewPane: boolean) {
public openDrawing(drawingFile: TFile, onNewPane: boolean) {
const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW);
let leaf:WorkspaceLeaf = null;

Expand Down

0 comments on commit 660f6e0

Please sign in to comment.