This commit is contained in:
Zsolt Viczian
2021-04-21 09:27:34 +02:00
parent 39085bc962
commit cbab54e848
5 changed files with 29 additions and 27 deletions

View File

@@ -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",

View File

@@ -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({

View File

@@ -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();
}

View File

@@ -36,9 +36,7 @@ export class OpenFileDialog extends FuzzySuggestModal<TFile> {
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 {

View File

@@ -1,4 +1,5 @@
{
"1.0.2": "0.11.13",
"1.0.1": "0.11.13",
"1.0.0": "0.11.13"
}