From b5b78022857ed21d1e9c87444b26749fddbedadd Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Thu, 12 Jan 2023 12:14:25 -0800 Subject: [PATCH 1/4] add options --- src/processor.ts | 2 ++ src/settings.ts | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/processor.ts b/src/processor.ts index 52e2cc2..2da9ffe 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -159,6 +159,8 @@ export class D2Processor { "-", `--theme=${this.plugin.settings.theme}`, `--layout=${this.plugin.settings.layoutEngine}`, + `--pad=${this.plugin.settings.pad}`, + `--sketch=${this.plugin.settings.sketch}`, "--bundle=false", ]; const cmd = args.join(" "); diff --git a/src/settings.ts b/src/settings.ts index a5883d5..1e07432 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -9,6 +9,8 @@ export interface D2PluginSettings { debounce: number; theme: number; d2Path: string; + pad: number; + sketch: boolean; } export const DEFAULT_SETTINGS: D2PluginSettings = { @@ -17,6 +19,8 @@ export const DEFAULT_SETTINGS: D2PluginSettings = { theme: 0, apiToken: "", d2Path: "", + pad: 100, + sketch: false, }; export class D2SettingsTab extends PluginSettingTab { @@ -102,6 +106,39 @@ export class D2SettingsTab extends PluginSettingTab { }) ); + new Setting(containerEl) + .setName("Pad") + .setDesc("Pixels padded around the rendered diagram") + .addText((text) => + text + .setPlaceholder(String(DEFAULT_SETTINGS.pad)) + .setValue(String(this.plugin.settings.pad)) + .onChange(async (value) => { + if (isNaN(Number(value))) { + new Notice("Please specify a valid number"); + this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); + } else if (value === undefined) { + this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); + } else if (Number(value) < 100) { + new Notice("The value must be greater than 100"); + this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); + } else { + this.plugin.settings.pad = Number(value); + } + await this.plugin.saveSettings(); + }) + ); + + new Setting(containerEl) + .setName("Sketch mode") + .setDesc("Render the diagram to look like it was sketched by hand") + .addToggle((toggle) => + toggle.setValue(this.plugin.settings.sketch).onChange(async (value) => { + this.plugin.settings.sketch = value; + await this.plugin.saveSettings(); + }) + ); + new Setting(containerEl) .setName("Debounce") .setDesc("How often should the diagram refresh in milliseconds (min 100)") @@ -128,7 +165,7 @@ export class D2SettingsTab extends PluginSettingTab { new Setting(containerEl) .setName("Path (optional)") .setDesc( - "Customize the local path to the directory `d2` is installed in. This is only necessary if `d2` is not found automatically by the plugin (but is installed)." + "Customize the local path to the directory `d2` is installed in (ex. if d2 is located at `/usr/local/bin/d2`, then the path is `/usr/local/bin`). This is only necessary if `d2` is not found automatically by the plugin (but is installed)." ) .addText((text) => { text From 4b6d2ed3128a3bf562c2a33befdf5841dcbe4806 Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Thu, 12 Jan 2023 12:20:36 -0800 Subject: [PATCH 2/4] fix defaults --- src/settings.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index 1e07432..becb538 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -97,7 +97,7 @@ export class D2SettingsTab extends PluginSettingTab { .setPlaceholder("Enter a theme ID") .setValue(String(this.plugin.settings.theme)) .onChange(async (value) => { - if (!isNaN(Number(value)) || value === undefined) { + if (!isNaN(Number(value)) || value === "") { this.plugin.settings.theme = Number(value || DEFAULT_SETTINGS.theme); await this.plugin.saveSettings(); } else { @@ -114,17 +114,16 @@ export class D2SettingsTab extends PluginSettingTab { .setPlaceholder(String(DEFAULT_SETTINGS.pad)) .setValue(String(this.plugin.settings.pad)) .onChange(async (value) => { + console.log(value, value === undefined); if (isNaN(Number(value))) { new Notice("Please specify a valid number"); this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); - } else if (value === undefined) { - this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); - } else if (Number(value) < 100) { - new Notice("The value must be greater than 100"); + } else if (value === "") { this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); } else { this.plugin.settings.pad = Number(value); } + console.log(this.plugin.settings.pad); await this.plugin.saveSettings(); }) ); @@ -150,7 +149,7 @@ export class D2SettingsTab extends PluginSettingTab { if (isNaN(Number(value))) { new Notice("Please specify a valid number"); this.plugin.settings.debounce = Number(DEFAULT_SETTINGS.debounce); - } else if (value === undefined) { + } else if (value === "") { this.plugin.settings.debounce = Number(DEFAULT_SETTINGS.debounce); } else if (Number(value) < 100) { new Notice("The value must be greater than 100"); From a3bf76c6986b5b0ed0ffb6124d363f60b33d7485 Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Thu, 12 Jan 2023 12:23:07 -0800 Subject: [PATCH 3/4] Remove console log --- src/settings.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index becb538..f936d7f 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -114,7 +114,6 @@ export class D2SettingsTab extends PluginSettingTab { .setPlaceholder(String(DEFAULT_SETTINGS.pad)) .setValue(String(this.plugin.settings.pad)) .onChange(async (value) => { - console.log(value, value === undefined); if (isNaN(Number(value))) { new Notice("Please specify a valid number"); this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad); @@ -123,7 +122,6 @@ export class D2SettingsTab extends PluginSettingTab { } else { this.plugin.settings.pad = Number(value); } - console.log(this.plugin.settings.pad); await this.plugin.saveSettings(); }) ); From 62d2f5393b9b86bd9268be689dd5eb9ff42fabc5 Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Thu, 12 Jan 2023 12:33:36 -0800 Subject: [PATCH 4/4] Update version --- manifest.json | 2 +- package.json | 54 +++++++++++++++++++++++++-------------------------- versions.json | 4 +++- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/manifest.json b/manifest.json index 003f83b..153a551 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "d2-obsidian", "name": "D2", - "version": "1.0.1", + "version": "1.1.0", "minAppVersion": "0.15.0", "description": "The official D2 plugin for Obsidian. D2 is a modern diagram scripting language that turns text to diagrams.", "author": "Terrastruct", diff --git a/package.json b/package.json index fc011ea..c8bf1c8 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,29 @@ { - "name": "d2-obsidian", - "version": "1.0.0", - "description": "This is the official D2 plugin for Obsidian.", - "main": "main.js", - "scripts": { - "dev": "node esbuild.config.mjs", - "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json" - }, - "keywords": [], - "author": "", - "license": "MIT", - "devDependencies": { - "@types/lodash.debounce": "^4.0.7", - "@types/node": "^16.11.6", - "@typescript-eslint/eslint-plugin": "5.29.0", - "@typescript-eslint/parser": "5.29.0", - "builtin-modules": "3.3.0", - "esbuild": "0.14.47", - "obsidian": "latest", - "tslib": "2.4.0", - "typescript": "4.7.4" - }, - "dependencies": { - "child_process": "^1.0.2", - "lodash.debounce": "^4.0.8" - } + "name": "d2-obsidian", + "version": "1.1.0", + "description": "This is the official D2 plugin for Obsidian.", + "main": "main.js", + "scripts": { + "dev": "node esbuild.config.mjs", + "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "version": "node version-bump.mjs && git add manifest.json versions.json" + }, + "keywords": [], + "author": "", + "license": "MIT", + "devDependencies": { + "@types/lodash.debounce": "^4.0.7", + "@types/node": "^16.11.6", + "@typescript-eslint/eslint-plugin": "5.29.0", + "@typescript-eslint/parser": "5.29.0", + "builtin-modules": "3.3.0", + "esbuild": "0.14.47", + "obsidian": "latest", + "tslib": "2.4.0", + "typescript": "4.7.4" + }, + "dependencies": { + "child_process": "^1.0.2", + "lodash.debounce": "^4.0.8" + } } diff --git a/versions.json b/versions.json index 1b5630e..04a7491 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,5 @@ { - "1.0.1": "0.15.0" + "1.1.0": "0.15.0", + "1.0.1": "0.15.0", + "1.0.0": "0.15.0" }