force to open markdown command palette action, fixed decompress

This commit is contained in:
zsviczian
2024-05-15 22:02:06 +02:00
parent ae4f4b4f08
commit 26812dd297
4 changed files with 39 additions and 9 deletions

View File

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

View File

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

View File

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

View File

@@ -186,6 +186,8 @@ export default class ExcalidrawPlugin extends Plugin {
private textMeasureDiv:HTMLDivElement = null;
public editorHandler: EditorHandler;
public activeLeafChangeEventHandler: (leaf: WorkspaceLeaf) => Promise<void>;
//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);