From 5ff8caa04fcde3a20c95f9a2d2d4d73290694529 Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Mon, 23 May 2022 21:42:16 +0200 Subject: [PATCH] 1.6.32 --- manifest.json | 2 +- src/ExcalidrawView.ts | 37 ++++++++++++++++++++++++++++++------- src/LaTeX.ts | 1 - src/dialogs/Messages.ts | 6 ++++++ src/lang/locale/en.ts | 4 ++++ src/main.ts | 10 +++++++--- src/settings.ts | 24 ++++++++++++++++++++++++ versions.json | 2 +- 8 files changed, 73 insertions(+), 13 deletions(-) diff --git a/manifest.json b/manifest.json index 2f284dc..504bca0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.6.31", + "version": "1.6.32", "minAppVersion": "0.12.16", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 28b1f09..6dd15b3 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -409,6 +409,7 @@ export default class ExcalidrawView extends TextFileView { } } + private preventReloadResetTimer: NodeJS.Timeout = null; async save(preventReload: boolean = true, forcesave: boolean = false) { //debug({where:"save", preventReload, forcesave, semaphores:this.semaphores}); if (this.semaphores.saving) { @@ -450,10 +451,23 @@ export default class ExcalidrawView extends TextFileView { //reload() is triggered indirectly when saving by the modifyEventHandler in main.ts //prevent reload is set here to override reload when not wanted: typically when the user is editing //and we do not want to interrupt the flow by reloading the drawing into the canvas. + if(this.preventReloadResetTimer) { + clearTimeout(this.preventReloadResetTimer); + this.preventReloadResetTimer = null; + } + this.semaphores.preventReload = preventReload; await super.save(); this.lastSaveTimestamp = this.file.stat.mtime; this.clearDirty(); + + //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/629 + //there were odd cases when preventReload semaphore did not get cleared and consequently a synchronized image + //did not update the open drawing + if(preventReload) { + const self = this; + this.preventReloadResetTimer = setTimeout(()=>self.semaphores.preventReload = false,2000); + } } if (!this.semaphores.autosaving) { @@ -754,7 +768,7 @@ export default class ExcalidrawView extends TextFileView { latex: formula, isLoaded: false, }); - await this.save(true); + await this.save(false); await updateEquation( formula, selectedImage.fileId, @@ -766,7 +780,7 @@ export default class ExcalidrawView extends TextFileView { }); return; } - await this.save(true); //in case pasted images haven't been saved yet + await this.save(false); //in case pasted images haven't been saved yet if (this.excalidrawData.hasFile(selectedImage.fileId)) { if (ev.altKey) { const ef = this.excalidrawData.getFile(selectedImage.fileId); @@ -786,7 +800,7 @@ export default class ExcalidrawView extends TextFileView { return; } ef.resetImage(this.file.path, link); - await this.save(true); + await this.save(false); await this.loadSceneFiles(); this.setDirty(); }); @@ -1042,7 +1056,8 @@ export default class ExcalidrawView extends TextFileView { warningUnknowSeriousError(); return; } - const editing = api.getAppState().editingElement !== null; + const st = api.getAppState(); + const editing = st.editingElement !== null; //this will reset positioning of the cursor in case due to the popup keyboard, //or the command palette, or some other unexpected reason the onResize would not fire... this.refresh(); @@ -1052,7 +1067,8 @@ export default class ExcalidrawView extends TextFileView { this.semaphores.dirty == this.file?.path && this.plugin.settings.autosave && !this.semaphores.forceSaving && - !editing + !editing && + st.draggingElement === null //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/630 ) { this.autosaveTimer = null; this.semaphores.autosaving = true; @@ -1450,8 +1466,7 @@ export default class ExcalidrawView extends TextFileView { } } return; - } - if(!sceneElement) { + } else if(!sceneElement) { manageMapChanges(incomingElement); if(idx === 0) { @@ -1463,6 +1478,14 @@ export default class ExcalidrawView extends TextFileView { sceneElements.splice(parentLayer+1,0,incomingElement); sceneElementIds.splice(parentLayer+1,0,incomingElement.id); } + } else if(sceneElement && incomingElement.type === "image") { //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/632 + if(inData.getFile(incomingElement.fileId)) { + this.excalidrawData.setFile( + incomingElement.fileId, + inData.getFile(incomingElement.fileId) + ); + reloadFiles = true; + } } }) this.previousSceneVersion = getSceneVersion(sceneElements); diff --git a/src/LaTeX.ts b/src/LaTeX.ts index a1c76b1..e4f9e68 100644 --- a/src/LaTeX.ts +++ b/src/LaTeX.ts @@ -6,7 +6,6 @@ import { FileId } from "@zsviczian/excalidraw/types/element/types"; import { errorlog, getImageSize, log, sleep, svgToBase64 } from "./utils/Utils"; import { fileid } from "./Constants"; import html2canvas from "html2canvas"; -import { count } from "console"; import { Notice } from "obsidian"; declare let window: any; diff --git a/src/dialogs/Messages.ts b/src/dialogs/Messages.ts index c744caa..2b38379 100644 --- a/src/dialogs/Messages.ts +++ b/src/dialogs/Messages.ts @@ -17,6 +17,12 @@ I develop this plugin as a hobby, spending most of my free time doing this. If y
`, +"1.6.32": ` +## Fixed +- Filenames of embedded images and markdown documents did not get updated if the drawing was open in a work-pane while you changed the filename of the embedded file (image or markdown document) [632](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/632). +- When you created a new text element and immediately dragged it, sometimes autosave interrupted the drag action and Excalidraw dropped the element you were dragging [630](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/630) +- In some edge cases when you had the drawing open on your desktop and you also opened the same image on your tablet, Sync seemed to work in the background but the changes did not appear on the desktop until you closed and opened the drawing again. [629](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/629) +- LaTeX support: Excalidraw must download a javascript library from one of the hosting sites for MathJax tex2svg. It seems that some people do not have access to the URL recommended in the first place by [MathJax](https://docs.mathjax.org/en/latest/web/start.html). If LaTeX formulas do not render correctly in Excalidraw, try changing the source server under Compatibility Settings in Excalidraw Plugin Settings. [628](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/628)`, "1.6.31": ` Minor update: diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 09fd8b2..27a1780 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -346,6 +346,10 @@ export default { "By enabling this feature drawings you create with the ribbon icon, the command palette actions, " + "and the file explorer are going to be all legacy *.excalidraw files. This setting will also turn off the reminder message " + "when you open a legacy file for editing.", + MATHJAX_NAME: "MathJax (LaTeX) javascript library host", + MATHJAX_DESC: "If you are using LaTeX equiations in Excalidraw then the plugin needs to load a javascript library for that. " + + "Some users are unable to access certain host servers. If you are experiencing issues try changing the host here. You may need to "+ + "restart Obsidian after closing settings, for this change to take effect.", EXPERIMENTAL_HEAD: "Experimental features", EXPERIMENTAL_DESC: "Some of these setting will not take effect immediately, only when the File Explorer is refreshed, or Obsidian restarted.", diff --git a/src/main.ts b/src/main.ts index 4e7a580..db5da45 100644 --- a/src/main.ts +++ b/src/main.ts @@ -256,12 +256,17 @@ export default class ExcalidrawPlugin extends Plugin { }); } - private loadMathJax() { + public loadMathJax() { const self = this; this.app.workspace.onLayoutReady(async () => { //loading Obsidian MathJax as fallback await loadMathJax(); try { + if(self.mathjaxDiv) { + document.body.removeChild(self.mathjaxDiv); + self.mathjax = null; + self.mathjaxLoaderFinished = false; + } self.mathjaxDiv = document.body.createDiv(); self.mathjaxDiv.title = "Excalidraw MathJax Support"; self.mathjaxDiv.style.display = "none"; @@ -273,7 +278,6 @@ export default class ExcalidrawPlugin extends Plugin { const script = doc.createElement("script"); script.type = "text/javascript"; script.onload = () => { - debugger; const win = iframe.contentWindow; //@ts-ignore win.MathJax.startup.pagePromise.then(async () => { @@ -300,7 +304,7 @@ export default class ExcalidrawPlugin extends Plugin { self.mathjaxLoaderFinished = true; }); }; - script.src = "https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js"; + script.src = self.settings.mathjaxSourceURL; // "https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js"; //script.src = MATHJAX_DATAURL; doc.head.appendChild(script); } catch { diff --git a/src/settings.ts b/src/settings.ts index 2d82c74..1c2f745 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -100,6 +100,7 @@ export interface ExcalidrawSettings { defaultTrayMode: boolean; previousRelease: string; showReleaseNotes: boolean; + mathjaxSourceURL: string; } export const DEFAULT_SETTINGS: ExcalidrawSettings = { @@ -179,6 +180,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = { defaultTrayMode: false, previousRelease: "1.6.13", showReleaseNotes: true, + mathjaxSourceURL: "https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js" }; const fragWithHTML = (html: string) => @@ -188,6 +190,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab { plugin: ExcalidrawPlugin; private requestEmbedUpdate: boolean = false; private requestReloadDrawings: boolean = false; + private reloadMathJax: boolean = false; //private applyDebounceTimer: number = 0; constructor(app: App, plugin: ExcalidrawPlugin) { @@ -228,6 +231,9 @@ export class ExcalidrawSettingTab extends PluginSettingTab { this.plugin.triggerEmbedUpdates(); } this.plugin.scriptEngine.updateScriptPath(); + if(this.reloadMathJax) { + this.plugin.loadMathJax(); + } } async display() { @@ -1108,6 +1114,24 @@ export class ExcalidrawSettingTab extends PluginSettingTab { }), ); + //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/628 + new Setting(containerEl) + .setName(t("MATHJAX_NAME")) + .setDesc(t("MATHJAX_DESC")) + .addDropdown((dropdown) => { + dropdown + .addOption("https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js", "jsdelivr") + .addOption("https://unpkg.com/mathjax@3.2.1/es5/tex-svg.js", "unpkg") + .addOption("https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.1/es5/tex-svg-full.min.js","cdnjs") + .setValue(this.plugin.settings.mathjaxSourceURL) + .onChange((value)=> { + this.plugin.settings.mathjaxSourceURL = value; + this.reloadMathJax = true; + this.applySettingsUpdate(); + }) + }) + + this.containerEl.createEl("h1", { text: t("EXPERIMENTAL_HEAD") }); this.containerEl.createEl("p", { text: t("EXPERIMENTAL_DESC") }); diff --git a/versions.json b/versions.json index 9a10437..2820ba9 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,4 @@ { - "1.6.31": "0.12.16", + "1.6.32": "0.12.16", "1.4.2": "0.11.13" }