Skip to content

Commit

Permalink
Merge pull request #20 from terrastruct/18/add-pad-sketch-options
Browse files Browse the repository at this point in the history
options: add pad/sketch options
  • Loading branch information
Bernard Xie authored Jan 12, 2023
2 parents 9508bbf + 62d2f53 commit fa14964
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 32 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
Expand Down
40 changes: 37 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface D2PluginSettings {
debounce: number;
theme: number;
d2Path: string;
pad: number;
sketch: boolean;
}

export const DEFAULT_SETTINGS: D2PluginSettings = {
Expand All @@ -17,6 +19,8 @@ export const DEFAULT_SETTINGS: D2PluginSettings = {
theme: 0,
apiToken: "",
d2Path: "",
pad: 100,
sketch: false,
};

export class D2SettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -93,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 {
Expand All @@ -102,6 +106,36 @@ 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 === "") {
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)")
Expand All @@ -113,7 +147,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");
Expand All @@ -128,7 +162,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
Expand Down
4 changes: 3 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit fa14964

Please sign in to comment.