This commit is contained in:
Mossy1022 2024-05-31 02:11:15 -04:00
commit aa82b713e8
7 changed files with 141 additions and 132 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
node_modules/

View file

@ -1,6 +1,11 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import dotenv from "dotenv";
dotenv.config();
import fs from "fs";
import path from "path";
const banner =
`/*
@ -11,6 +16,24 @@ if you want to view the source, please visit the github repository of this plugi
const prod = (process.argv[2] === "production");
// const copy_to_plugins = {
// name: 'copy_to_plugins',
// setup(build) {
// build.onEnd(() => {
// const plugin_path = path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view");
// if (!fs.existsSync(plugin_path)) {
// fs.mkdirSync(plugin_path);
// }
// fs.copyFileSync("./main.js", path.join(plugin_path, "main.js"));
// fs.copyFileSync("./manifest.json", path.join(plugin_path, "manifest.json"));
// fs.copyFileSync("./styles.css", path.join(plugin_path, "styles.css"));
// console.log("Plugin built and copied to obsidian plugins folder");
// });
// }
// };
const context = await esbuild.context({
banner: {
js: banner,
@ -31,18 +54,21 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
...builtins
],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
plugins: [
// copy_to_plugins
]
});
if (prod) {
if(!prod) await context.watch();
else {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
}

56
main.js

File diff suppressed because one or more lines are too long

126
main.ts
View file

@ -3,11 +3,11 @@ import * as d3 from "d3";
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';
interface MyPluginSettings {
interface ScGraphViewSettings {
mySetting: string;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
const DEFAULT_SETTINGS: ScGraphViewSettings = {
mySetting: 'default'
}
@ -75,15 +75,15 @@ class MyItemView extends ItemView {
}
getViewType(): string {
return "My Item View";
return "Smart Graph View";
}
getDisplayText(): string {
return "My Item View";
return "Smart Graph View";
}
getIcon(): string {
return "dice";
return "git-fork";
}
// Function to update node appearance based on selection and highlight state
@ -173,7 +173,6 @@ class MyItemView extends ItemView {
// Helper function to truncate labels, extract filenames or parts after hashtags, and remove brackets
formatLabel(path: string, truncate: boolean = true) {
console.log('formatting: ', truncate);
if (truncate) {
if (path.includes('#')) {
const parts = path.split('#');
@ -661,9 +660,7 @@ class MyItemView extends ItemView {
console.log('Update already in progress. Skipping...');
return;
} else {
console.log('Update not in progress . Skipping...');
}
this.isChangingConnectionType = false;
@ -707,7 +704,6 @@ class MyItemView extends ItemView {
}
return true;
});
console.log('Validated Links:', this.validatedLinks);
// Safeguard to prevent infinite loop
@ -829,7 +825,6 @@ class MyItemView extends ItemView {
}
}
that.unhighlightNode();
console.log('selecting node', d.selected);
d3.select(this).attr('stroke', d.selected ? 'blanchedalmond' : 'transparent').attr('stroke-width', d.selected ? 1.5 : 0.3); // Change stroke color back to less visible on mouse out
svgGroup.select(`text[data-id='${d.id}']`).transition().duration(250).attr('y', d.y);
}),
@ -1504,7 +1499,6 @@ class MyItemView extends ItemView {
}
}
/*
Main Colors
Menu text: #a3aecb
@ -1515,31 +1509,29 @@ class MyItemView extends ItemView {
SliderKnob: #f3ee5d
*/
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
export default class ScGraphView extends Plugin {
settings: ScGraphViewSettings;
async onload() {
await this.loadSettings();
// Register the new view
this.registerView("My Item View", (leaf: WorkspaceLeaf) => new MyItemView(leaf));
this.registerView("Smart Graph View", (leaf: WorkspaceLeaf) => new MyItemView(leaf));
// Register hover link source
this.registerHoverLinkSource('D3', {
display: 'D3 Hover Link Source',
defaultMod: true
});
// Register hover link source
this.registerHoverLinkSource('Smart Graph', {
display: 'Smart Graph Hover Link Source',
defaultMod: true
});
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Smart Graph', (evt: MouseEvent) => {
const ribbonIconEl = this.addRibbonIcon('git-fork', 'Smart Graph', (evt: MouseEvent) => {
// Called when the user clicks the icon.
// Create a new leaf in the current workspace
let leaf = this.app.workspace.getLeaf(true);
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
type: "Smart Graph View",
active: true,
});
})
@ -1560,26 +1552,26 @@ export default class MyPlugin extends Plugin {
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
type: "Smart Graph View",
active: true,
});
}
});
// This adds an editor command that can perform some operation on the current editor instance
this.addCommand({
id: 'sample-editor-command',
name: 'Sample editor command',
callback: () => {
// Create a new leaf in the current workspace
let leaf = this.app.workspace.getLeaf(true);
// // This adds an editor command that can perform some operation on the current editor instance
// this.addCommand({
// id: 'sample-editor-command',
// name: 'Sample editor command',
// callback: () => {
// // Create a new leaf in the current workspace
// let leaf = this.app.workspace.getLeaf(true);
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
active: true,
});
}
});
// // Set the new leaf's view to your custom view
// leaf.setViewState({
// type: "Smart Graph View",
// active: true,
// });
// }
// });
// This adds a complex command that can check whether the current state of the app allows execution of the command
this.addCommand({
@ -1591,23 +1583,23 @@ export default class MyPlugin extends Plugin {
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
type: "Smart Graph View",
active: true,
});
}
});
// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SampleSettingTab(this.app, this));
// // This adds a settings tab so the user can configure various aspects of the plugin
// this.addSettingTab(new SampleSettingTab(this.app, this));
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
console.log('click', evt);
});
// console.log('click', evt);
});
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
// // When registering intervals, this function will automatically clear the interval when the plugin is disabled.
// this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
}
onunload() {}
@ -1621,28 +1613,28 @@ export default class MyPlugin extends Plugin {
}
}
class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
// class SampleSettingTab extends PluginSettingTab {
// plugin: ScGraphView;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
// constructor(app: App, plugin: ScGraphView) {
// super(app, plugin);
// this.plugin = plugin;
// }
display(): void {
const {containerEl} = this;
// display(): void {
// const {containerEl} = this;
containerEl.empty();
// containerEl.empty();
new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret... This will change everything')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}
// new Setting(containerEl)
// .setName('Setting #1')
// .setDesc('It\'s a secret')
// .addText(text => text
// .setPlaceholder('Enter your secret... This will change everything')
// .setValue(this.plugin.settings.mySetting)
// .onChange(async (value) => {
// this.plugin.settings.mySetting = value;
// await this.plugin.saveSettings();
// }));
// }
// }

View file

@ -1,11 +1,12 @@
{
"id": "D3",
"name": "D3 Plugin",
"id": "Smart-Connections-Graph-View",
"name": "Smart Connections Graph View",
"version": "1.0.2",
"minAppVersion": "0.15.0",
"description": "Demonstrates some of the capabilities of the Obsidian API.",
"author": "Obsidian",
"authorUrl": "https://obsidian.md",
"fundingUrl": "https://obsidian.md/pricing",
"isDesktopOnly": false
"description": "A plugin that allows you to view your Smart Connections in a graph format.",
"author": "Evan Moscoso",
"authorUrl": "https://github.com/mossy426",
"fundingUrl": "https://github.com/mossy426",
"isDesktopOnly": true
}

21
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "obsidian-sample-plugin",
"version": "1.0.0",
"name": "smart-connections-graph-view",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "obsidian-sample-plugin",
"version": "1.0.0",
"name": "smart-connections-graph-view",
"version": "1.0.2",
"license": "MIT",
"dependencies": {
"bootstrap": "^5.3.3",
@ -18,6 +18,7 @@
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"dotenv": "^16.4.5",
"esbuild": "0.17.3",
"obsidian": "latest",
"tslib": "2.4.0",
@ -1668,6 +1669,18 @@
"node": ">=6.0.0"
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"dev": true,
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/esbuild": {
"version": "0.17.3",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.3.tgz",

View file

@ -1,15 +1,20 @@
{
"name": "obsidian-sample-plugin",
"version": "1.0.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"name": "smart-connections-graph-view",
"version": "1.0.2",
"description": "A plugin that allows you to view your Smart Connections in a graph format.",
"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": "",
"keywords": [
"Obsidian",
"Smart Connections",
"Graph",
"View"
],
"author": "Evan Moscoso",
"license": "MIT",
"devDependencies": {
"@types/d3": "^7.4.3",
@ -17,6 +22,7 @@
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"dotenv": "^16.4.5",
"esbuild": "0.17.3",
"obsidian": "latest",
"tslib": "2.4.0",