From 2b17138e5eda36ae1a4ce51b177dc318f919f1c3 Mon Sep 17 00:00:00 2001 From: mProjectsCode Date: Wed, 14 Jun 2023 16:38:11 +0200 Subject: [PATCH] added setting to disable js view fields --- manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/renderChildren/JsViewFieldMDRC.ts | 8 ++++---- src/settings/Settings.ts | 2 ++ src/settings/SettingsTab.ts | 11 +++++++++++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/manifest.json b/manifest.json index c4eaef79..8c6469df 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-meta-bind-plugin", "name": "Meta Bind Plugin", - "version": "0.5.0", + "version": "0.5.1", "minAppVersion": "0.14.0", "description": "This plugin can create input fields inside your notes and bind them to metadata fields.", "author": "Moritz Jung", diff --git a/package-lock.json b/package-lock.json index 18fba178..c03a7745 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-meta-bind-plugin", - "version": "0.5.0", + "version": "0.5.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-meta-bind-plugin", - "version": "0.5.0", + "version": "0.5.1", "license": "GPL-3.0", "dependencies": { "@codemirror/language": "https://github.com/lishid/cm-language", diff --git a/package.json b/package.json index 14643e7d..9db6a3cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-meta-bind-plugin", - "version": "0.5.0", + "version": "0.5.1", "description": "This plugin can create input fields inside your notes and bind them to metadata fields.", "main": "main.js", "scripts": { diff --git a/src/renderChildren/JsViewFieldMDRC.ts b/src/renderChildren/JsViewFieldMDRC.ts index 7f9f4794..15071a8f 100644 --- a/src/renderChildren/JsViewFieldMDRC.ts +++ b/src/renderChildren/JsViewFieldMDRC.ts @@ -1,5 +1,5 @@ import MetaBindPlugin from '../main'; -import { ErrorLevel, MetaBindExpressionError } from '../utils/errors/MetaBindErrors'; +import { ErrorLevel, MetaBindExpressionError, MetaBindJsError } from '../utils/errors/MetaBindErrors'; import { Listener, Signal } from '../utils/Signal'; import { RenderChildType } from './InputFieldMDRC'; import { JsViewFieldDeclaration } from '../parsers/ViewFieldDeclarationParser'; @@ -82,10 +82,10 @@ export class JsViewFieldMDRC extends AbstractViewFieldMDRC { async evaluateExpression(): Promise { if (!this.expression) { - throw new Error("Can't evaluate expression. Expression is undefined."); + throw new MetaBindJsError(ErrorLevel.CRITICAL, "Can't evaluate expression.", 'Expression is undefined.'); } - if (!(this.plugin instanceof MetaBindPlugin)) { - throw new Error("Can't evaluate expression. JS expressions are unsupported outside of obsidian."); + if (!this.plugin.settings.enableJs) { + throw new MetaBindJsError(ErrorLevel.CRITICAL, "Can't evaluate expression.", 'JS expressions are disabled in the plugin settings.'); } const context = this.buildContext(); diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index 62b51329..d12169c4 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -53,6 +53,7 @@ export interface MetaBindPluginSettings { syncInterval: number; maxSyncInterval: number; minSyncInterval: number; + enableJs: boolean; inputTemplates: string; } @@ -66,6 +67,7 @@ export const DEFAULT_SETTINGS: MetaBindPluginSettings = { syncInterval: 200, minSyncInterval: 50, maxSyncInterval: 1000, + enableJs: false, inputTemplates: '', }; diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index e2d94cdc..4d2ba85c 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -103,6 +103,17 @@ export class MetaBindSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName('Enable JS Input Fields') + .setDesc("Enable the processing of JavaScript input fields. This is potentially DANGEROUS, thus it's disabled by default. RESTART REQUIRED.") + .addToggle(cb => { + cb.setValue(this.plugin.settings.enableJs); + cb.onChange(data => { + this.plugin.settings.enableJs = data; + this.plugin.saveSettings(); + }); + }); + new Setting(containerEl) .setName('Disable Code Block Restrictions') .setDesc('Disable restrictions on which input fields can be created in which code blocks. Not recommended unless you know what you are doing.')