mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
scriptSettings
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user