Skip to content

Commit 4810415

Browse files
integration of circuit-sketcher-core 1.2.0 with new features and some bug fixes
integration of circuit-sketcher-core 1.2.0 with new features and some bug fixes
1 parent 14615ce commit 4810415

File tree

5 files changed

+71
-20
lines changed

5 files changed

+71
-20
lines changed

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.0.0",
4+
"version": "1.1.0",
55
"minAppVersion": "0.15.0",
66
"description": "A plugin for drawing circuits on a canvas, based on circuit-sketcher-core.",
77
"author": "Code Forge Temple",

package-lock.json

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

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "circuit-sketcher-obsidian-plugin",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"main": "main.js",
55
"author": "Code Forge Temple",
66
"license": "GPL",
@@ -13,7 +13,7 @@
1313
},
1414
"keywords": [],
1515
"dependencies": {
16-
"circuit-sketcher-core": "git+https://github.com/code-forge-temple/circuit-sketcher-core.git",
16+
"circuit-sketcher-core": "github:code-forge-temple/circuit-sketcher-core",
1717
"obsidian": "^1.7.2",
1818
"react": "^19.0.0",
1919
"react-dom": "^19.0.0"
@@ -41,6 +41,7 @@
4141
"typescript-eslint": "^8.18.0",
4242
"url-loader": "^4.1.1",
4343
"webpack": "^5.97.1",
44-
"webpack-cli": "^5.1.4"
44+
"webpack-cli": "^5.1.4",
45+
"webpack-preprocessor-loader": "^1.3.0"
4546
}
46-
}
47+
}

src/CircuitSketcherView.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class CircuitSketcherView extends TextFileView {
2121
private root: Root | null = null;
2222

2323
constructor (leaf: WorkspaceLeaf, plugin: CircuitSketcherPlugin) {
24+
// #!dev
25+
console.log("CircuitSketcherView.constructor()");
26+
2427
super(leaf);
2528

2629
this.plugin = plugin;
@@ -39,13 +42,16 @@ export class CircuitSketcherView extends TextFileView {
3942
// Set the data to the editor. This is used to load the file contents.
4043
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4144
setViewData = async (fileContents: string, clear: boolean) => {
45+
// #!dev
46+
console.log("CircuitSketcherView.setViewData() - NEW FILE");
47+
4248
LocalStorageManager.setLibrary(await this.plugin.getLibraryFile());
4349

4450
const viewDomContent = this.containerEl.children[1];
4551

46-
if (!this.root) {
47-
this.root = createRoot(viewDomContent);
48-
}
52+
this.clear();
53+
54+
this.root = createRoot(viewDomContent);
4955

5056
this.root.render(
5157
<StrictMode>
@@ -56,16 +62,27 @@ export class CircuitSketcherView extends TextFileView {
5662

5763
// Gets the data from the editor. This will be called to save the editor contents to the file.
5864
getViewData = (): string => {
65+
// #!dev
66+
console.log("CircuitSketcherView.getViewData() - OLD FILE");
67+
5968
const fileContents = CanvasManager.getInstance().stringify(true);
6069

6170
this.plugin.setLibraryFile(LocalStorageManager.getLibrary(true));
6271

6372
return fileContents;
6473
}
6574

66-
clear (): void {}
75+
// Clear the editor. This is usually called when we're about to open a completely different file, so it's best to clear any editor states like undo-redo history, and any caches/indexes associated with the previous file contents.
76+
clear (): void {
77+
// #!dev
78+
console.log("CircuitSketcherView.clear()");
6779

68-
async onClose () {
80+
CanvasManager.destroy();
81+
82+
this.clearHtml();
83+
}
84+
85+
clearHtml (): void {
6986
if (this.root) {
7087
this.root.unmount();
7188
this.root = null;
@@ -76,7 +93,12 @@ export class CircuitSketcherView extends TextFileView {
7693
while (viewDomContent.firstChild) {
7794
viewDomContent.removeChild(viewDomContent.firstChild);
7895
}
96+
}
7997

80-
CanvasManager.destroy();
98+
async onClose () {
99+
// #!dev
100+
console.log("CircuitSketcherView.onClose()");
101+
102+
this.clear();
81103
}
82104
}

webpack.config.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,30 @@ const postcssLoader = {
1515
},
1616
};
1717

18+
const ENVIRONMENT = "production";
19+
1820
module.exports = {
1921
entry: "./src/main.ts",
2022
module: {
2123
rules: [
2224
{
2325
test: /\.tsx?$/,
24-
use: "ts-loader",
26+
use: [
27+
{
28+
loader: "ts-loader",
29+
},
30+
{
31+
loader: "webpack-preprocessor-loader",
32+
options: {
33+
params: {
34+
dev: ENVIRONMENT === "development", // for preprocessor commands defined with `#!if dev` and `#!endif`
35+
},
36+
directives: {
37+
dev: ENVIRONMENT === "development", // for preprocessor command `#!dev`
38+
},
39+
},
40+
},
41+
],
2542
exclude: /node_modules/,
2643
},
2744
{
@@ -58,7 +75,7 @@ module.exports = {
5875
externals: {
5976
obsidian: "commonjs obsidian",
6077
},
61-
mode: "production",
78+
mode: ENVIRONMENT,
6279
plugins: [
6380
new webpack.BannerPlugin({
6481
banner: `/*! Also see LICENSE file in the root of the project. */`,

0 commit comments

Comments
 (0)