Skip to content

Commit d91f605

Browse files
added new features: embed circuit diagrams in notes + create new circuit in contextual menu of obsidian explorer
1 parent ee8301c commit d91f605

File tree

13 files changed

+278
-68
lines changed

13 files changed

+278
-68
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# circuit-sketcher-obsidian-plugin
2+
3+
> ⭐️ If you like this plugin, please consider [starring the repository](https://github.com/code-forge-temple/circuit-sketcher-obsidian-plugin) on GitHub!
4+
25
A plugin for Obsidian to draw circuits on a canvas. It is based on the [code-forge-temple/circuit-sketcher-core](https://github.com/code-forge-temple/circuit-sketcher-core).
36

47
## Table of Contents
@@ -14,6 +17,7 @@ A plugin for Obsidian to draw circuits on a canvas. It is based on the [code-for
1417
- Save and load circuit designs.
1518
- Customizable library for circuit elements.
1619
- Responsive design with automatic resizing.
20+
- **Embed circuit diagrams in notes:** Reference `.circuit-sketcher` files in your notes (e.g., by dragging and dropping the file into a note). In read mode, an image of the circuit will be displayed automatically.
1721

1822
## Installation
1923

@@ -28,7 +32,7 @@ or
2832

2933
## Usage
3034

31-
1. Use the ribbon icon or command palette to create a new circuit sketcher file.
35+
1. Use the ribbon icon, command palette, or right-click on a target folder in the file explorer and select **Create new Circuit Sketcher file** to create a new circuit sketcher file.
3236
2. Start drawing your circuit on the canvas:
3337
- On the canvas, right-click to show the canvas menu, and select `Create Node`.
3438
- Right-click on the node to show the node menu, select `Change Image`, and choose an image relevant to your circuit node.

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "circuit-sketcher",
33
"name": "Circuit Sketcher",
4-
"version": "1.1.4",
4+
"version": "1.2.0",
55
"minAppVersion": "0.15.0",
66
"description": "Draw circuits on a canvas using circuit-sketcher-core.",
77
"author": "Code Forge Temple",

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "circuit-sketcher-obsidian-plugin",
3-
"version": "1.1.4",
3+
"version": "1.2.0",
44
"main": "main.js",
55
"author": "Code Forge Temple",
66
"license": "GPL",

src/CircuitSketcherSettingTab.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,36 @@ export class CircuitSketcherSettingTab extends PluginSettingTab {
2121

2222
containerEl.empty();
2323

24+
containerEl.createEl("h3", {text: "Circuit Sketcher Plugin"});
25+
26+
new Setting(containerEl)
27+
.setName("Version")
28+
.setDesc("Current plugin version")
29+
.addText(text => text.setValue(this.plugin.manifest.version).setDisabled(true));
30+
31+
containerEl.createEl("div", {cls: "setting-item-divider"});
32+
33+
containerEl.createEl("h3", {text: "Library"});
2434
new Setting(containerEl)
25-
.setName("Library")
2635
.setDesc("The Circuit Sketcher library will allow you to save any circuit element custom design you create and make it available throughout any .circuit-sketcher file.");
2736

2837
new Setting(containerEl)
2938
.setName("Library path")
30-
.setDesc("The Circuit Sketcher library will be stored at: vault_root/.lib.circuit-sketcher")
39+
.setDesc(`The Circuit Sketcher library will be stored at: vault_root/${this.plugin.settings.libraryPath}`)
3140
.addText(text => text.setValue(this.plugin.settings.libraryPath).setDisabled(true));
41+
42+
containerEl.createEl("div", {cls: "setting-item-divider"});
43+
44+
containerEl.createEl("h3", {text: "Cache"});
45+
46+
new Setting(containerEl)
47+
.setDesc("The Circuit Sketcher cache stores generated circuit images and data to improve performance and reduce redundant computations. " +
48+
"It is recommended not to delete the cache, as doing so will cause references to circuit sketches in your notes to become invisible until they are regenerated.");
49+
50+
new Setting(containerEl)
51+
.setName("Cache path")
52+
.setDesc(`The Circuit Sketcher cache will be stored at: vault_root/${this.plugin.settings.cachePath}`)
53+
.addText(text => text.setValue(this.plugin.settings.cachePath).setDisabled(true));
54+
3255
}
3356
}

src/CircuitSketcherView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export class CircuitSketcherView extends TextFileView {
6161

6262
this.root.render(
6363
<StrictMode>
64-
<App fileContents= {fileContents} />
64+
<App
65+
fileContents= {fileContents}
66+
onLoaded={() => {
67+
this.plugin.setCacheImageFile(this.file?.path, CanvasManager.getInstance().toPng);
68+
}} />
6569
</StrictMode>,
6670
);
6771
}
@@ -74,6 +78,7 @@ export class CircuitSketcherView extends TextFileView {
7478
const fileContents = CanvasManager.getInstance().stringify(true);
7579

7680
this.plugin.setLibraryFile(LocalStorageManager.getLibrary(true));
81+
this.plugin.setCacheImageFile(this.file?.path, CanvasManager.getInstance().toPng);
7782

7883
return fileContents;
7984
}

src/UpgradablePlugin.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/************************************************************************
2+
* Copyright (C) 2025 Code Forge Temple *
3+
* This file is part of circuit-sketcher-obsidian-plugin project. *
4+
* Licensed under the GNU General Public License v3.0. *
5+
* See the LICENSE file in the project root for more information. *
6+
************************************************************************/
7+
8+
9+
import {App, Plugin, PluginManifest} from "obsidian";
10+
import {compareVersions, createIntermediaryFolders} from "./utils/utils";
11+
import {CircuitSketcherSettings} from "./types/types";
12+
import {READONLY_SETTINGS} from "./constants/constants";
13+
14+
15+
export default class UpgradablePlugin extends Plugin {
16+
settings: CircuitSketcherSettings;
17+
18+
constructor (app: App, manifest: PluginManifest) {
19+
super(app, manifest);
20+
21+
this.settings = READONLY_SETTINGS;
22+
}
23+
24+
async onload () {
25+
await this.loadSettings();
26+
}
27+
28+
async loadSettings () {
29+
this.settings = Object.assign({}, await this.loadData(), READONLY_SETTINGS);
30+
31+
const manifestVersion = this.manifest.version;
32+
const storedVersion = this.settings.dataVersion || "0.0.0";
33+
34+
if (compareVersions(manifestVersion, storedVersion) > 0) {
35+
await this.migrateData(storedVersion);
36+
37+
this.settings.dataVersion = manifestVersion;
38+
39+
await this.saveSettings();
40+
}
41+
}
42+
43+
async migrateData (storedVersion: string) {
44+
if(compareVersions("1.2.0", storedVersion) > 0) {
45+
await this.migrateLibraryFile();
46+
}
47+
}
48+
49+
async saveSettings () {
50+
await this.saveData(this.settings);
51+
}
52+
53+
private async migrateLibraryFile (): Promise<void> {
54+
const OLD_LIBRARY_PATH = `circuit-sketcher.lib`;
55+
const migrationNeeded = await this.app.vault.adapter.exists(OLD_LIBRARY_PATH);
56+
57+
if (migrationNeeded) {
58+
try {
59+
await createIntermediaryFolders(this.app.vault, this.settings.libraryPath);
60+
await this.app.vault.adapter.rename(OLD_LIBRARY_PATH, this.settings.libraryPath);
61+
} catch {/*ignore*/ }
62+
}
63+
}
64+
}

src/components/App/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "./App.scss";
1010
import {DrawBoardProps} from "../DrawBoard/DrawBoard";
1111

1212

13-
export const App = ({fileContents}: DrawBoardProps) => {
13+
export const App = (props: DrawBoardProps) => {
1414
const [isLoaded, setIsLoaded] = useState(false);
1515
const [DrawBoard, setDrawBoard] = useState<React.ComponentType<DrawBoardProps> | null>(null);
1616
const loadingElement = (
@@ -35,7 +35,7 @@ export const App = ({fileContents}: DrawBoardProps) => {
3535
return (
3636
<div className="circuit-sketcher-plugin">
3737
<Suspense fallback={loadingElement}>
38-
<DrawBoard fileContents= {fileContents} />
38+
<DrawBoard {...props} />
3939
</Suspense>
4040
</div>
4141
);

src/components/DrawBoard/DrawBoard.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import './DrawBoard.scss';
1111

1212
export type DrawBoardProps = {
1313
fileContents: string;
14+
onLoaded: () => void;
1415
};
1516

1617
const CANVAS_ID = "circuit-board";
1718

18-
export const DrawBoard = ({fileContents}: DrawBoardProps) => {
19+
export const DrawBoard = ({fileContents, onLoaded}: DrawBoardProps) => {
1920
const canvasRef = useRef<HTMLDivElement>(null);
2021
const resizeTimeoutRef = useRef<number | null>(null);
2122
const containerRef = useRef<HTMLDivElement>(null);
@@ -24,7 +25,9 @@ export const DrawBoard = ({fileContents}: DrawBoardProps) => {
2425
if (!canvasRef.current) return;
2526

2627
CanvasManager.setCanvasId(CANVAS_ID).getInstance().parse(fileContents);
27-
}, [fileContents]);
28+
29+
onLoaded();
30+
}, [fileContents, onLoaded]);
2831

2932
const handleResize = () => {
3033
if (resizeTimeoutRef.current) {

src/constants/constants.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/************************************************************************
2+
* Copyright (C) 2025 Code Forge Temple *
3+
* This file is part of circuit-sketcher-obsidian-plugin project. *
4+
* Licensed under the GNU General Public License v3.0. *
5+
* See the LICENSE file in the project root for more information. *
6+
************************************************************************/
7+
8+
import {CircuitSketcherSettings} from "../types/types";
9+
10+
export const FILE_EXTENSION = "circuit-sketcher";
11+
export const BASE_FOLDER = ".circuit-sketcher";
12+
export const NEW_LIBRARY_CONTENT = "{}";
13+
export const CREATE_FILE_COMMAND = "Create new Circuit Sketcher file";
14+
15+
export const READONLY_SETTINGS: CircuitSketcherSettings = {
16+
libraryPath: `${BASE_FOLDER}/circuit-sketcher.lib`,
17+
cachePath: `${BASE_FOLDER}/circuit-sketcher.cache`,
18+
};

0 commit comments

Comments
 (0)