From cbab54e84892dcf634b50c24ecc2e0c512f06ddd Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Wed, 21 Apr 2021 09:27:34 +0200 Subject: [PATCH] 1.0.2 --- manifest.json | 2 +- src/ExcalidrawView.ts | 4 ++-- src/main.ts | 45 +++++++++++++++++++++++-------------------- src/openDrawing.ts | 4 +--- versions.json | 1 + 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/manifest.json b/manifest.json index 30d591e..fd09183 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.0.1", + "version": "1.0.2", "minAppVersion": "0.11.13", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 24ff1aa..f6075e0 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -33,7 +33,7 @@ export default class ExcalidrawView extends TextFileView { - setViewData (data: string, clear: boolean) { + setViewData (data: string, clear: boolean) { if (this.app.workspace.layoutReady) { this.loadDrawing(data,clear); } else { @@ -41,7 +41,7 @@ export default class ExcalidrawView extends TextFileView { } } - private loadDrawing (data:string, clear:boolean) :void { + private loadDrawing (data:string, clear:boolean) :void { if(clear) this.clear(); const excalidrawData = JSON.parse(data); this.instantiateExcalidraw({ diff --git a/src/main.ts b/src/main.ts index 3a2fad4..7d07e2c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,7 +31,6 @@ import { export default class ExcalidrawPlugin extends Plugin { public settings: ExcalidrawSettings; - public view: ExcalidrawView; private openDialog: OpenFileDialog; constructor(app: App, manifest: PluginManifest) { @@ -43,12 +42,12 @@ export default class ExcalidrawPlugin extends Plugin { this.registerView( VIEW_TYPE_EXCALIDRAW, - (leaf: WorkspaceLeaf) => (this.view = new ExcalidrawView(leaf)) + (leaf: WorkspaceLeaf) => new ExcalidrawView(leaf) ); this.registerExtensions([EXCALIDRAW_FILE_EXTENSION],VIEW_TYPE_EXCALIDRAW); - this.registerMarkdownCodeBlockProcessor(CODEBLOCK_EXCALIDRAW, (source,el,ctx) => { + this.registerMarkdownCodeBlockProcessor(CODEBLOCK_EXCALIDRAW, async (source,el,ctx) => { const parseError = (message: string) => { el.createDiv("excalidraw-error",(el)=> { el.createEl("p","Please provide a link to an excalidraw file: [[file."+EXCALIDRAW_FILE_EXTENSION+"]]"); @@ -92,23 +91,19 @@ export default class ExcalidrawPlugin extends Plugin { return; } - this.app.vault.read(file).then(async (content: string) => { - const svg = ExcalidrawView.getSVG(content); - if(!svg) { - parseError("Parse error. Not a valid Excalidraw file."); - return; - } - el.createDiv("excalidraw-svg",(el)=> { - svg.removeAttribute('width'); - svg.removeAttribute('height'); - svg.style.setProperty('width',fwidth); - if(fheight) svg.style.setProperty('height',fheight); - el.appendChild(svg); - }) + const content = await this.app.vault.read(file); + const svg = ExcalidrawView.getSVG(content); + if(!svg) { + parseError("Parse error. Not a valid Excalidraw file."); + return; + } + el.createDiv("excalidraw-svg",(el)=> { + svg.removeAttribute('width'); + svg.removeAttribute('height'); + svg.style.setProperty('width',fwidth); + if(fheight) svg.style.setProperty('height',fheight); + el.appendChild(svg); }); - - - }); await this.loadSettings(); @@ -168,8 +163,16 @@ export default class ExcalidrawPlugin extends Plugin { } public async openDrawing(drawingFile: TFile) { - let leaf = this.view ? this.view.leaf : this.app.workspace.activeLeaf; - + const leafs = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); + let leaf:WorkspaceLeaf = null; + + if (leafs?.length > 0) { + leaf = leafs[0]; + } + if(!leaf) { + leaf = this.app.workspace.activeLeaf; + } + if(!leaf) { leaf = this.app.workspace.getLeaf(); } diff --git a/src/openDrawing.ts b/src/openDrawing.ts index b60ce11..d8e8004 100644 --- a/src/openDrawing.ts +++ b/src/openDrawing.ts @@ -36,9 +36,7 @@ export class OpenFileDialog extends FuzzySuggestModal { getItems(): TFile[] { const excalidrawFiles = this.app.vault.getFiles(); - if(excalidrawFiles) { - return excalidrawFiles.filter((f:TFile) => (f.extension==EXCALIDRAW_FILE_EXTENSION)); - } else return []; + return (excalidrawFiles || []).filter((f:TFile) => (f.extension==EXCALIDRAW_FILE_EXTENSION)); } getItemText(item: TFile): string { diff --git a/versions.json b/versions.json index 3caf4d6..a701968 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "1.0.2": "0.11.13", "1.0.1": "0.11.13", "1.0.0": "0.11.13" } \ No newline at end of file