diff --git a/manifest-beta.json b/manifest-beta.json index 768f102..18909a7 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "2.1.8.1-beta-1", + "version": "2.1.8.1-beta-2", "minAppVersion": "1.1.6", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index db4fca1..4b599f6 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -56,7 +56,7 @@ import { getAttachmentsFolderAndFilePath, getLeaf, getNewOrAdjacentLeaf, isObsid import { AppState, BinaryFileData, DataURL, ExcalidrawImperativeAPI, Point } from "@zsviczian/excalidraw/types/excalidraw/types"; import { EmbeddedFile, EmbeddedFilesLoader, FileData } from "src/EmbeddedFileLoader"; import { tex2dataURL } from "src/LaTeX"; -import { GenericInputPrompt, NewFileActions, Prompt } from "src/dialogs/Prompt"; +import { GenericInputPrompt, NewFileActions } from "src/dialogs/Prompt"; import { t } from "src/lang/helpers"; import { ScriptEngine } from "src/Scripts"; import { ConnectionPoint, DeviceType } from "src/types"; @@ -78,7 +78,7 @@ import { TInput } from "colormaster/types"; import {ConversionResult, svgToExcalidraw} from "src/svgToExcalidraw/parser" import { ROUNDNESS } from "src/constants/constants"; import { ClipboardData } from "@zsviczian/excalidraw/types/excalidraw/clipboard"; -import { emulateKeysForLinkClick, KeyEvent, PaneTarget } from "src/utils/ModifierkeyHelper"; +import { emulateKeysForLinkClick, PaneTarget } from "src/utils/ModifierkeyHelper"; import { Mutable } from "@zsviczian/excalidraw/types/excalidraw/utility-types"; import PolyBool from "polybooljs"; import { EmbeddableMDCustomProps } from "./dialogs/EmbeddableSettings"; diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index f0a6cb7..22bf6e3 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -36,6 +36,7 @@ export default { TRANSCLUDE: "Embed a drawing", TRANSCLUDE_MOST_RECENT: "Embed the most recently edited drawing", TOGGLE_LEFTHANDED_MODE: "Toggle left-handed mode", + FLIP_IMAGE: "Open the back-of-the-note of the selected excalidraw image", NEW_IN_NEW_PANE: "Create new drawing - IN AN ADJACENT WINDOW", NEW_IN_NEW_TAB: "Create new drawing - IN A NEW TAB", NEW_IN_ACTIVE_PANE: "Create new drawing - IN THE CURRENT ACTIVE WINDOW", diff --git a/src/main.ts b/src/main.ts index 63451a2..8212f7d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -186,6 +186,8 @@ export default class ExcalidrawPlugin extends Plugin { private textMeasureDiv:HTMLDivElement = null; public editorHandler: EditorHandler; public activeLeafChangeEventHandler: (leaf: WorkspaceLeaf) => Promise; + //if set, the next time this file is opened it will be opened as markdown + public forceToOpenInMarkdownFilepath: string = null; constructor(app: App, manifest: PluginManifest) { super(app, manifest); @@ -876,9 +878,9 @@ export default class ExcalidrawPlugin extends Plugin { (async () => { const data = await this.app.vault.read(activeFile); - const parts = data.split("\n##? Drawing\n```compressed-json\n"); + const parts = data.split("\n## Drawing\n```compressed-json\n"); if(parts.length!==2) return; - const header = parts[0] + "\n# Drawing\n```json\n"; + const header = parts[0] + "\n## Drawing\n```json\n"; const compressed = parts[1].split("\n```\n%%"); if(compressed.length!==2) return; const decompressed = decompress(compressed[0]); @@ -1583,6 +1585,31 @@ export default class ExcalidrawPlugin extends Plugin { }, }); + this.addCommand({ + id: "flip-image", + name: t("FLIP_IMAGE"), + checkCallback: (checking:boolean) => { + const view = this.app.workspace.getActiveViewOfType(ExcalidrawView); + if(!view) return false; + if(!view.excalidrawAPI) return false; + const els = view.getViewSelectedElements().filter(el=>el.type==="image"); + if(els.length !== 1) { + return false; + } + const el = els[0] as ExcalidrawImageElement; + let ef = view.excalidrawData.getFile(el.fileId); + if(!ef) { + return false; + } + if(!this.isExcalidrawFile(ef.file)) { + return false; + } + if(checking) return true; + this.forceToOpenInMarkdownFilepath = ef.file?.path; + this.openDrawing(ef.file, DEVICE.isMobile ? "new-tab":"popout-window", true); + } + }) + this.addCommand({ id: "reset-image-to-100", name: t("RESET_IMG_TO_100"), @@ -2393,18 +2420,20 @@ export default class ExcalidrawPlugin extends Plugin { markdownViewLoaded && self.excalidrawFileModes[this.id || state.state.file] !== "markdown" ) { - if (fileShouldDefaultAsExcalidraw(state.state.file,this.app)) { + const file = state.state.file; + if ((self.forceToOpenInMarkdownFilepath !== file) && fileShouldDefaultAsExcalidraw(file,this.app)) { // If we have it, force the view type to excalidraw const newState = { ...state, type: VIEW_TYPE_EXCALIDRAW, }; - self.excalidrawFileModes[state.state.file] = + self.excalidrawFileModes[file] = VIEW_TYPE_EXCALIDRAW; return next.apply(this, [newState, ...rest]); } + self.forceToOpenInMarkdownFilepath = null; } if(markdownViewLoaded) { @@ -3113,10 +3142,10 @@ export default class ExcalidrawPlugin extends Plugin { } let leaf: WorkspaceLeaf; if(location === "popout-window") { - leaf = app.workspace.openPopoutLeaf(); + leaf = this.app.workspace.openPopoutLeaf(); } if(location === "new-tab") { - leaf = app.workspace.getLeaf('tab'); + leaf = this.app.workspace.getLeaf('tab'); } if(!leaf) { leaf = this.app.workspace.getLeaf(false);