From ad98d114e1e87db15911f05eda8f671cfe35dc7e Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Wed, 5 Jan 2022 21:09:36 +0100 Subject: [PATCH] scriptSettings --- src/ExcalidrawAutomate.ts | 35 +++++++++++++++-------------------- src/Scripts.ts | 7 +++++-- src/settings.ts | 2 ++ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 95bff35..87cc60b 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -39,12 +39,6 @@ declare type ConnectionPoint = "top" | "bottom" | "left" | "right" | null; const GAP = 4; export interface ExcalidrawAutomate { - renderMarkdown( - markdown: string, - el: HTMLElement, - sourcePath: string, - component: Component, - ): Promise; plugin: ExcalidrawPlugin; elementsDict: {}; //contains the ExcalidrawElements currently edited in Automate indexed by el.id imagesDict: {}; //the images files including DataURL, indexed by fileId @@ -217,6 +211,9 @@ export interface ExcalidrawAutomate { b: readonly [number, number], gap?: number, //if given, element is inflated by this value ): Point[]; + activeScript: string; + getScriptSettings(): {}; + setScriptSettings(settings:any):Promise; } declare let window: any; @@ -225,20 +222,7 @@ export async function initExcalidrawAutomate( plugin: ExcalidrawPlugin, ): Promise { window.ExcalidrawAutomate = { - renderMarkdown( - markdown: string, - el: HTMLElement, - sourcePath: string, - component: Component, - ): Promise { - return MarkdownRenderer.renderMarkdown( - markdown, - el, - sourcePath, - component, - ); - }, - plugin, + plugin: plugin, elementsDict: {}, imagesDict: {}, style: { @@ -988,6 +972,7 @@ export async function initExcalidrawAutomate( }, reset() { this.clear(); + this.activeScript = null; this.style.strokeColor = "#000000"; this.style.backgroundColor = "transparent"; this.style.angle = 0; @@ -1256,6 +1241,16 @@ export async function initExcalidrawAutomate( ): Point[] { return intersectElementWithLine(element, a, b, gap); }, + activeScript: null, + getScriptSettings(): {} { + if(!this.activeScript) return null; + return this.plugin.settings.scriptEngineSettings[this.activeScript]; + }, + async setScriptSettings(settings:any): Promise { + if(!this.activeScript) return null; + this.plugin.settings.scriptEngineSettings[this.activeScript] = settings; + await this.plugin.saveSettings(); + }, }; await initFonts(); return window.ExcalidrawAutomate; diff --git a/src/Scripts.ts b/src/Scripts.ts index 0ec3f6b..939586e 100644 --- a/src/Scripts.ts +++ b/src/Scripts.ts @@ -153,16 +153,19 @@ export class ScriptEngine { return; } + this.plugin.ea.activeScript = this.getScriptName(f); + //https://stackoverflow.com/questions/45381204/get-asyncfunction-constructor-in-typescript changed tsconfig to es2017 //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor; - - return await new AsyncFunction("ea", "utils", script)(this.plugin.ea, { + const result = await new AsyncFunction("ea", "utils", script)(this.plugin.ea, { inputPrompt: (header: string, placeholder?: string, value?: string) => ScriptEngine.inputPrompt(this.plugin.app, header, placeholder, value), suggester: (displayItems: string[], items: string[]) => ScriptEngine.suggester(this.plugin.app, displayItems, items), }); + this.plugin.ea.activeScript = null; + return result; } public static async inputPrompt( diff --git a/src/settings.ts b/src/settings.ts index 3f95a57..d779e0e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -58,6 +58,7 @@ export interface ExcalidrawSettings { mdFont: string; mdFontColor: string; mdCSS: string; + scriptEngineSettings: {}; } export const DEFAULT_SETTINGS: ExcalidrawSettings = { @@ -113,6 +114,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = { mdFont: "Virgil", mdFontColor: "Black", mdCSS: "", + scriptEngineSettings: {}, }; export class ExcalidrawSettingTab extends PluginSettingTab {