scriptSettings

This commit is contained in:
Zsolt Viczian
2022-01-05 21:09:36 +01:00
parent c90370a606
commit ad98d114e1
3 changed files with 22 additions and 22 deletions

View File

@@ -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<void>;
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<void>;
}
declare let window: any;
@@ -225,20 +222,7 @@ export async function initExcalidrawAutomate(
plugin: ExcalidrawPlugin,
): Promise<ExcalidrawAutomate> {
window.ExcalidrawAutomate = {
renderMarkdown(
markdown: string,
el: HTMLElement,
sourcePath: string,
component: Component,
): Promise<void> {
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<void> {
if(!this.activeScript) return null;
this.plugin.settings.scriptEngineSettings[this.activeScript] = settings;
await this.plugin.saveSettings();
},
};
await initFonts();
return window.ExcalidrawAutomate;

View File

@@ -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(

View File

@@ -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 {