Skip to content

Commit 3d15915

Browse files
authored
Merge pull request #8 from GreenArron/master
Fix missing imports with custom types
2 parents 7ae6ebf + 433bd41 commit 3d15915

File tree

9 files changed

+45
-25
lines changed

9 files changed

+45
-25
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Obsidian Nested tags graph Plugin
22

3+
> **Note**: this is a fork from [drPilman's addon](https://github.com/drPilman/obsidian-graph-nested-tags) updated to work with new obsidian versions, inspired by code from [folders2graph](https://github.com/ratibus11/folders2graph).
4+
35
This is a plugin for [Obsidian](https://obsidian.md).
46

57
Links nested tags (Sub_tag->Tag) in graph view:
@@ -12,10 +14,10 @@ Links nested tags (Sub_tag->Tag) in graph view:
1214
4. Profit!!!
1315

1416

15-
[obsidian forum feature request](https://forum.obsidian.md/t/view-structure-of-nested-tags-on-graph/11386/22)
17+
[Original Obsidian forum feature request](https://forum.obsidian.md/t/view-structure-of-nested-tags-on-graph/11386/22)
1618

1719
> Caution! At the moment, there is no Obsidian API for working with the graph. So I did a bit of reverse engineering and found this method. Since this is not part of the public API, I have no confidence that this will work on newer versions.
1820
1921
## Manually installing the plugin
2022

21-
- Copy over `main.js`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/graph-nested-tags/`.
23+
- Go to releases, copy over `main.js`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/graph-nested-tags/`.

esbuild.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const context = await esbuild.context({
1515
banner: {
1616
js: banner,
1717
},
18-
entryPoints: ["main.ts"],
18+
entryPoints: ["src/main.ts"],
1919
bundle: true,
2020
external: [
2121
"obsidian",

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "graph-nested-tags",
33
"name": "Nested tags graph",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"minAppVersion": "0.15.0",
66
"description": "Links nested tags in graph view",
77
"author": "drpilman",

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "graph-nested-tags",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Links nested tags in graph view",
5-
"main": "main.js",
5+
"main": "src/main.js",
66
"scripts": {
77
"dev": "node esbuild.config.mjs",
88
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { WorkspaceLeaf } from "obsidian";
2+
import { LeafRenderer } from "./LeafRenderer";
3+
4+
type CustomLeaf = {
5+
view: {
6+
renderer: LeafRenderer;
7+
};
8+
};
9+
10+
export type GraphLeafWithCustomRenderer = WorkspaceLeaf & CustomLeaf;

src/interfaces/LeafRenderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type LeafRenderer = {
2+
setData: Function;
3+
originalSetData?: Function;
4+
};

main.ts renamed to src/main.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { Plugin } from "obsidian";
2-
import { GraphLeaf } from "types";
2+
import { GraphLeafWithCustomRenderer } from "./interfaces/GraphLeafWithCustomRenderer";
3+
34

45
export default class GraphNestedTagsPlugin extends Plugin {
5-
// At nodes changes graphLeaf.view.renderer.setData calls, so we need to step in and change links.
6-
inject_setData(graphLeaf: GraphLeaf) {
7-
const r = graphLeaf.view.renderer;
6+
// inject our own wrapper around graphLeaf.view.renderer.setData
7+
// which will manipulate add tag -> subtag hierarchy
8+
inject_setData(graphLeaf: GraphLeafWithCustomRenderer) {
9+
const leafRenderer = graphLeaf.view.renderer;
810

9-
if (!r._setData) {
10-
r._setData = r.setData;
11+
if (leafRenderer.originalSetData == undefined) {
12+
leafRenderer.originalSetData = leafRenderer.setData;
1113
}
12-
r.setData = (data: any) => {
14+
15+
leafRenderer.setData = (data: any) => {
1316
const nodes = data.nodes;
1417
let parent;
1518
let last_tag: string;
@@ -30,7 +33,7 @@ export default class GraphNestedTagsPlugin extends Plugin {
3033
}
3134
}
3235
}
33-
return r._setData?.(data);
36+
return leafRenderer.originalSetData?.(data);
3437
};
3538
return graphLeaf;
3639
}
@@ -43,9 +46,9 @@ export default class GraphNestedTagsPlugin extends Plugin {
4346
"graph"
4447
)) {
4548
if (
46-
(leaf as GraphLeaf).view.renderer._setData === undefined
49+
(leaf as GraphLeafWithCustomRenderer).view.renderer.originalSetData === undefined
4750
) {
48-
this.inject_setData(leaf as GraphLeaf);
51+
this.inject_setData(leaf as GraphLeafWithCustomRenderer);
4952
}
5053
}
5154
})
@@ -58,13 +61,13 @@ export default class GraphNestedTagsPlugin extends Plugin {
5861
}
5962

6063
onunload() {
61-
// undone injections and reload the Graphs
64+
// undo injections and reload the Graphs
6265
for (const leaf of this.app.workspace.getLeavesOfType(
6366
"graph"
64-
) as GraphLeaf[]) {
65-
if (leaf.view.renderer._setData) {
66-
leaf.view.renderer.setData = leaf.view.renderer._setData;
67-
delete leaf.view.renderer._setData;
67+
) as GraphLeafWithCustomRenderer[]) {
68+
if (leaf.view.renderer.originalSetData) {
69+
leaf.view.renderer.setData = leaf.view.renderer.originalSetData;
70+
delete leaf.view.renderer.originalSetData;
6871
leaf.view.unload();
6972
leaf.view.load();
7073
}
@@ -74,4 +77,4 @@ export default class GraphNestedTagsPlugin extends Plugin {
7477
async loadSettings() {}
7578

7679
async saveSettings() {}
77-
}
80+
}

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"1.0.0": "0.15.0",
33
"1.0.1": "0.15.0",
4-
"1.0.2": "0.15.0"
4+
"1.0.2": "0.15.0",
5+
"1.0.3": "0.15.0"
56
}

0 commit comments

Comments
 (0)