Skip to content

Commit

Permalink
1.9.25
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Oct 22, 2023
1 parent 84af0c2 commit 06475ae
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 74 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "1.9.24",
"version": "1.9.25",
"minAppVersion": "1.1.6",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@zsviczian/excalidraw": "0.16.1-obsidian-4",
"@zsviczian/excalidraw": "0.16.1-obsidian-5",
"chroma-js": "^2.4.2",
"clsx": "^2.0.0",
"colormaster": "^1.2.1",
Expand Down
38 changes: 25 additions & 13 deletions src/ExcalidrawAutomate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { getAttachmentsFolderAndFilePath, getLeaf, getNewOrAdjacentLeaf, isObsid
import { AppState, BinaryFileData, DataURL, ExcalidrawImperativeAPI, Point } from "@zsviczian/excalidraw/types/types";
import { EmbeddedFile, EmbeddedFilesLoader, FileData } from "src/EmbeddedFileLoader";
import { tex2dataURL } from "src/LaTeX";
import { NewFileActions, Prompt } from "src/dialogs/Prompt";
import { GenericInputPrompt, NewFileActions, Prompt } from "src/dialogs/Prompt";
import { t } from "src/lang/helpers";
import { ScriptEngine } from "src/Scripts";
import { ConnectionPoint, DeviceType } from "src/types";
Expand All @@ -79,6 +79,7 @@ import { ClipboardData } from "@zsviczian/excalidraw/types/clipboard";
import { emulateKeysForLinkClick, KeyEvent, PaneTarget } from "src/utils/ModifierkeyHelper";
import { Mutable } from "@zsviczian/excalidraw/types/utility-types";
import PolyBool from "polybooljs";
import { compressToBase64, decompressFromBase64 } from "lz-string";

extendPlugins([
HarmonyPlugin,
Expand Down Expand Up @@ -121,6 +122,14 @@ export class ExcalidrawAutomate {
return getNewUniqueFilepath(app.vault, filename, folderAndPath.folder);
}

public compressToBase64(str:string):string {
return compressToBase64(str);
}

public decompressFromBase64(str:string):string {
return decompressFromBase64(str);
}

/**
* Prompts the user with a dialog to select new file action.
* - create markdown file
Expand All @@ -147,14 +156,14 @@ export class ExcalidrawAutomate {
return null;
}
const modifierKeys = emulateKeysForLinkClick(targetPane);
const newFilePrompt = new NewFileActions(
this.plugin,
newFileNameOrPath,
modifierKeys,
this.targetView,
shouldOpenNewFile,
parentFile
)
const newFilePrompt = new NewFileActions({
plugin: this.plugin,
path: newFileNameOrPath,
keys: modifierKeys,
view: this.targetView,
openNewFile: shouldOpenNewFile,
parentFile: parentFile
})
newFilePrompt.open();
return await newFilePrompt.waitForClose;
}
Expand Down Expand Up @@ -2791,13 +2800,16 @@ function errorMessage(message: string, source: string) {
export const insertLaTeXToView = (view: ExcalidrawView) => {
const app = view.plugin.app;
const ea = view.plugin.ea;
const prompt = new Prompt(
GenericInputPrompt.Prompt(
view,
view.plugin,
app,
t("ENTER_LATEX"),
view.plugin.settings.latexBoilerplate,
"\\color{red}\\oint_S {E_n dA = \\frac{1}{{\\varepsilon _0 }}} Q_{inside}",
);
prompt.openAndGetValue(async (formula: string) => {
view.plugin.settings.latexBoilerplate,
undefined,
3
).then(async (formula: string) => {
if (!formula) {
return;
}
Expand Down
17 changes: 11 additions & 6 deletions src/ExcalidrawView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ import { CanvasNodeFactory, ObsidianCanvasNode } from "./utils/CanvasNodeFactory
import { EmbeddableMenu } from "./menu/EmbeddableActionsMenu";
import { useDefaultExcalidrawFrame } from "./utils/CustomEmbeddableUtils";
import { UniversalInsertFileModal } from "./dialogs/UniversalInsertFileModal";
import { moment } from "obsidian";
import { shouldRenderMermaid } from "./utils/MermaidUtils";
import { get } from "http";

declare const PLUGIN_VERSION:string;

Expand Down Expand Up @@ -987,8 +985,9 @@ export default class ExcalidrawView extends TextFileView {
const equation = this.excalidrawData.getEquation(
selectedImage.fileId,
).latex;
const prompt = new Prompt(this.app, t("ENTER_LATEX"), equation, "");
prompt.openAndGetValue(async (formula: string) => {
GenericInputPrompt.Prompt(this,this.plugin,this.app,t("ENTER_LATEX"),undefined,equation, undefined, 3).then(async (formula: string) => {
// const prompt = new Prompt(this.app, t("ENTER_LATEX"), equation, "");
// prompt.openAndGetValue(async (formula: string) => {
if (!formula || formula === equation) {
return;
}
Expand Down Expand Up @@ -1075,7 +1074,13 @@ export default class ExcalidrawView extends TextFileView {
this.exitFullscreen();
}
if (!file) {
new NewFileActions(this.plugin, linkText, keys, this).open();
new NewFileActions({
plugin: this.plugin,
path: linkText,
keys,
view: this,
sourceElement: el
}).open();
return;
}
if(this.linksAlwaysOpenInANewPane && !anyModifierKeysPressed(keys)) {
Expand Down Expand Up @@ -3206,7 +3211,7 @@ export default class ExcalidrawView extends TextFileView {
},
libraryReturnUrl: "app://obsidian.md",
autoFocus: true,
langCode: obsidianToExcalidrawMap[moment.locale()]??"en-EN",
langCode: obsidianToExcalidrawMap[this.plugin.locale]??"en-EN",
onChange: (et: ExcalidrawElement[], st: AppState) => {
const canvasColorChangeHook = () => {
const canvasColor = st.viewBackgroundColor === "transparent" ? "white" : st.viewBackgroundColor;
Expand Down
6 changes: 6 additions & 0 deletions src/constMathJaxSource.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { customAlphabet } from "nanoid";
import { DeviceType } from "./types";
import { ExcalidrawLib } from "./ExcalidrawLib";
import { moment } from "obsidian";
//This is only for backward compatibility because an early version of obsidian included an encoding to avoid fantom links from littering Obsidian graph view
declare const PLUGIN_VERSION:string;

export const ERROR_IFRAME_CONVERSION_CANCELED = "iframe conversion canceled";

declare const excalidrawLib: typeof ExcalidrawLib;

export const LOCALE = moment.locale();

export const obsidianToExcalidrawMap: { [key: string]: string } = {
'en': 'en-US',
'af': 'af-ZA', // Assuming South Africa for Afrikaans
Expand Down
23 changes: 23 additions & 0 deletions src/dialogs/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ I develop this plugin as a hobby, spending my free time doing this. If you find
<div class="ex-coffee-div"><a href="https://ko-fi.com/zsolt"><img src="https://cdn.ko-fi.com/cdn/kofi3.png?v=3" height=45></a></div>
`,
"1.9.25":`
## Fixed
- Fixed issues with creating Markdown or Excalidraw files for non-existing documents [#1385](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1385)
- Resolved a bug where changing the section/block filter after duplicating a markdown embeddable now works correctly on the first attempt [#1387](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1387)
## New
- Easily create a markdown file and embed it as an embedded frame with a single click when clicking a link pointing to a non-existent file.
![image](https://github.com/zsviczian/obsidian-excalidraw-plugin/assets/14358394/4b9de54d-2382-4a52-b500-918ba2a60133)
- Offline LaTeX support. The MathJax package is now included in the plugin, eliminating the need for an internet connection. [#1383](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1383), [#936](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/936), [#1289](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1289)
## Minor Updates from excalidraw.com
- Improved the laser pointer in dark mode.
- Removed bound arrows from frames.
- Enhanced fill rendering.
- Maintained the z-order of elements added to frames.
## New in ExcalidrawAutomate
- Introduced two LZString functions in ExcalidrawAutomate:
${String.fromCharCode(96,96,96)}typescript
compressToBase64(str:string):string;
decompressFromBase64(str:string):string;
${String.fromCharCode(96,96,96)}
`,
"1.9.24":`
## Fixed
- Resolved some hidden Image and Backup Cache initialization errors.
Expand Down
80 changes: 66 additions & 14 deletions src/dialogs/Prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import {
} from "obsidian";
import ExcalidrawView from "../ExcalidrawView";
import ExcalidrawPlugin from "../main";
import { sleep } from "../utils/Utils";
import { escapeRegExp, sleep } from "../utils/Utils";
import { getLeaf } from "../utils/ObsidianUtils";
import { checkAndCreateFolder, splitFolderAndFilename } from "src/utils/FileUtils";
import { KeyEvent, isCTRL } from "src/utils/ModifierkeyHelper";
import { t } from "src/lang/helpers";
import { ExcalidrawElement, getEA } from "src";
import { ExcalidrawAutomate } from "src/ExcalidrawAutomate";
import { MAX_IMAGE_SIZE } from "src/constants";

export type ButtonDefinition = { caption: string; tooltip?:string; action: Function };

Expand Down Expand Up @@ -461,22 +464,44 @@ export class NewFileActions extends Modal {
private resolvePromise: (file: TFile|null) => void;
private rejectPromise: (reason?: any) => void;
private newFile: TFile = null;

constructor(
private plugin: ExcalidrawPlugin,
private path: string,
private keys: KeyEvent,
private view: ExcalidrawView,
private openNewFile: boolean = true,
private parentFile?: TFile,
) {
private plugin: ExcalidrawPlugin;
private path: string;
private keys: KeyEvent;
private view: ExcalidrawView;
private openNewFile: boolean;
private parentFile: TFile;
private sourceElement: ExcalidrawElement;

constructor({
plugin,
path,
keys,
view,
openNewFile = true,
parentFile,
sourceElement,
}: {
plugin: ExcalidrawPlugin;
path: string;
keys: KeyEvent;
view: ExcalidrawView;
openNewFile?: boolean;
parentFile?: TFile;
sourceElement?: ExcalidrawElement;
}) {
super(plugin.app);
this.plugin = plugin;
this.path = path;
this.keys = keys;
this.view = view;
this.openNewFile = openNewFile;
this.sourceElement = sourceElement;
if(!parentFile) this.parentFile = view.file;
this.waitForClose = new Promise<TFile|null>((resolve, reject) => {
this.resolvePromise = resolve;
this.rejectPromise = reject;
});
}
}

onOpen(): void {
this.createForm();
Expand Down Expand Up @@ -528,7 +553,7 @@ export class NewFileActions extends Modal {

const createFile = async (data: string): Promise<TFile> => {
if (!this.path.includes("/")) {
const re = new RegExp(`${this.parentFile.name}$`, "g");
const re = new RegExp(`${escapeRegExp(this.parentFile.name)}$`, "g");
this.path = this.parentFile.path.replace(re, this.path);
}
if (!this.path.match(/\.md$/)) {
Expand All @@ -540,7 +565,31 @@ export class NewFileActions extends Modal {
return f;
};

const bMd = el.createEl("button", { text: t("PROMPT_BUTTON_CREATE_MARKDOWN") });
if(this.sourceElement) {
const bEmbedMd = el.createEl("button", {
text: t("PROMPT_BUTTON_EMBED_MARKDOWN"),
attr: {"aria-label": t("PROMPT_BUTTON_EMBED_MARKDOWN_ARIA")},
});
bEmbedMd.onclick = async () => {
if (!checks) {
return;
}
const f = await createFile("");
if(f) {
const ea:ExcalidrawAutomate = getEA(this.view);
ea.copyViewElementsToEAforEditing([this.sourceElement]);
ea.getElement(this.sourceElement.id).isDeleted = true;
ea.addEmbeddable(this.sourceElement.x, this.sourceElement.y,MAX_IMAGE_SIZE, MAX_IMAGE_SIZE, undefined,f);
ea.addElementsToView();
}
this.close();
};
}

const bMd = el.createEl("button", {
text: t("PROMPT_BUTTON_CREATE_MARKDOWN"),
attr: {"aria-label": t("PROMPT_BUTTON_CREATE_MARKDOWN_ARIA")},
});
bMd.onclick = async () => {
if (!checks) {
return;
Expand All @@ -550,7 +599,10 @@ export class NewFileActions extends Modal {
this.close();
};

const bEx = el.createEl("button", { text: t("PROMPT_BUTTON_CREATE_EXCALIDRAW") });
const bEx = el.createEl("button", {
text: t("PROMPT_BUTTON_CREATE_EXCALIDRAW"),
attr: {"aria-label": t("PROMPT_BUTTON_CREATE_EXCALIDRAW_ARIA")},
});
bEx.onclick = async () => {
if (!checks) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/dialogs/ScriptInstallPrompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MarkdownRenderer, Modal, Notice, request } from "obsidian";
import ExcalidrawPlugin from "../main";
import { errorlog, log } from "../utils/Utils";
import { errorlog, escapeRegExp, log } from "../utils/Utils";

const URL =
"https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/index-new.md";
Expand Down Expand Up @@ -134,7 +134,7 @@ export class ScriptInstallPrompt extends Modal {

let lastIndex = 0;
let match;
const regex = new RegExp(searchTerm, 'gi');
const regex = new RegExp(escapeRegExp(searchTerm), 'gi');

// Iterate over all matches in the text node
while ((match = regex.exec(nodeContent)) !== null) {
Expand Down
14 changes: 13 additions & 1 deletion src/dialogs/SuggesterInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
{
field: "addEmbeddable",
code: "addEmbeddable(topX: number, topY: number, width: number, height: number, url?: string, file?: TFile): string;",
desc: "Adds an iframe to the drawing. If url is not null then the iframe will be loaded from the url. The url maybe a markdown link to an note in the Vault or a weblink. If url is null then the iframe will be loaded from the file. Both the url and the file may not be null.",
desc: "Adds an iframe/webview (depending on content and platform) to the drawing. If url is not null then the iframe/webview will be loaded from the url. The url maybe a markdown link to an note in the Vault or a weblink. If url is null then the iframe/webview will be loaded from the file. Both the url and the file may not be null.",
after: "",
},
{
Expand Down Expand Up @@ -540,6 +540,18 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
desc: "Zoom tarteView to fit elements provided as input. elements === [] will zoom to fit the entire scene. SelectElements toggles whether the elements should be in a selected state at the end of the operation.",
after: "",
},
{
field: "compressToBase64",
code: "compressToBase64(str: string):string",
desc: "Compresses String to a Base64 string using LZString",
after: "",
},
{
field: "decompressFromBase64",
code: "decompressFromBase64(str: string):string",
desc: "Decompresses a base 64 compressed string using LZString",
after: "",
},
];

export const EXCALIDRAW_SCRIPTENGINE_INFO: SuggesterInfo[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/UniversalInsertFileModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class UniversalInsertFileModal extends Modal {
new Setting(ce)
.addButton(button => {
button
.setButtonText("as iFrame")
.setButtonText("as Embeddable")
.onClick(async () => {
const path = app.metadataCache.fileToLinktext(
file,
Expand Down
10 changes: 2 additions & 8 deletions src/lang/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ru from "./locale/ru";
import tr from "./locale/tr";
import zhCN from "./locale/zh-cn";
import zhTW from "./locale/zh-tw";
import { LOCALE } from "src/constants";

const localeMap: { [k: string]: Partial<typeof en> } = {
ar,
Expand Down Expand Up @@ -52,16 +53,9 @@ const localeMap: { [k: string]: Partial<typeof en> } = {
"zh-tw": zhTW,
};

const locale = localeMap[moment.locale()];
const locale = localeMap[LOCALE];

export function t(str: keyof typeof en): string {
if (!locale) {
errorlog({
where: "helpers.t",
message: "Error: Excalidraw locale not found",
locale: moment.locale(),
});
}

return (locale && locale[str]) || en[str];
}
Loading

0 comments on commit 06475ae

Please sign in to comment.