127 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			127 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /*
 | |
| THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
 | |
| if you want to view the source, please visit the github repository of this plugin
 | |
| */
 | |
| 
 | |
| var __defProp = Object.defineProperty;
 | |
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
 | |
| var __getOwnPropNames = Object.getOwnPropertyNames;
 | |
| var __hasOwnProp = Object.prototype.hasOwnProperty;
 | |
| var __export = (target, all) => {
 | |
|   for (var name in all)
 | |
|     __defProp(target, name, { get: all[name], enumerable: true });
 | |
| };
 | |
| var __copyProps = (to, from, except, desc) => {
 | |
|   if (from && typeof from === "object" || typeof from === "function") {
 | |
|     for (let key of __getOwnPropNames(from))
 | |
|       if (!__hasOwnProp.call(to, key) && key !== except)
 | |
|         __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
 | |
|   }
 | |
|   return to;
 | |
| };
 | |
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
 | |
| 
 | |
| // main.ts
 | |
| var main_exports = {};
 | |
| __export(main_exports, {
 | |
|   SyncGraphSettingTab: () => SyncGraphSettingTab,
 | |
|   default: () => SyncGraphPlugin
 | |
| });
 | |
| module.exports = __toCommonJS(main_exports);
 | |
| var import_obsidian = require("obsidian");
 | |
| var DEFAULT_SETTINGS = {
 | |
|   autoSync: false,
 | |
|   defaultDepth: 1,
 | |
|   defaultIncomingLinks: true,
 | |
|   defaultOutgoingLinks: true,
 | |
|   defaultNeighborLinks: true,
 | |
|   defaultShowTags: true
 | |
| };
 | |
| var SyncGraphSettingTab = class extends import_obsidian.PluginSettingTab {
 | |
|   constructor(app, plugin) {
 | |
|     super(app, plugin);
 | |
|     this.plugin = plugin;
 | |
|   }
 | |
|   display() {
 | |
|     let { containerEl } = this;
 | |
|     containerEl.empty();
 | |
|     new import_obsidian.Setting(containerEl).setName("Auto Sync").setDesc("Automatically sync graph settings to local graph when active leaf changes").addToggle((toggle) => toggle.setValue(this.plugin.settings.autoSync).onChange(async (value) => {
 | |
|       this.plugin.settings.autoSync = value;
 | |
|       await this.plugin.saveSettings();
 | |
|     }));
 | |
|     new import_obsidian.Setting(containerEl).setName("Default depth").setDesc("Default depth to set for local graph").addSlider((value) => value.setLimits(1, 5, 1).setValue(this.plugin.settings.defaultDepth).onChange(async (value2) => {
 | |
|       this.plugin.settings.defaultDepth = value2;
 | |
|       await this.plugin.saveSettings();
 | |
|     }).setDynamicTooltip());
 | |
|     new import_obsidian.Setting(containerEl).setName("Default Incoming Links").setDesc('Default "Incoming Links" flag to set for local graph').addToggle((toggle) => toggle.setValue(this.plugin.settings.defaultIncomingLinks).onChange(async (value) => {
 | |
|       this.plugin.settings.defaultIncomingLinks = value;
 | |
|       await this.plugin.saveSettings();
 | |
|     }));
 | |
|     new import_obsidian.Setting(containerEl).setName("Default Outgoing Links").setDesc('Default "Outgoing Links" flag to set for local graph').addToggle((toggle) => toggle.setValue(this.plugin.settings.defaultOutgoingLinks).onChange(async (value) => {
 | |
|       this.plugin.settings.defaultOutgoingLinks = value;
 | |
|       await this.plugin.saveSettings();
 | |
|     }));
 | |
|     new import_obsidian.Setting(containerEl).setName("Default Neighbor Links").setDesc('Default "Neighbor Links" flag to set for local graph').addToggle((toggle) => toggle.setValue(this.plugin.settings.defaultNeighborLinks).onChange(async (value) => {
 | |
|       this.plugin.settings.defaultNeighborLinks = value;
 | |
|       await this.plugin.saveSettings();
 | |
|     }));
 | |
|   }
 | |
| };
 | |
| var SyncGraphPlugin = class extends import_obsidian.Plugin {
 | |
|   async onload() {
 | |
|     await this.loadSettings();
 | |
|     this.addSettingTab(new SyncGraphSettingTab(this.app, this));
 | |
|     this.addCommand({
 | |
|       id: "sync-graph-settings-to-localgraph",
 | |
|       name: "Sync Graph Settings to Local Graph",
 | |
|       callback: async () => {
 | |
|         await this.syncGlobalToLocal();
 | |
|       }
 | |
|     });
 | |
|     this.app.workspace.on("active-leaf-change", async () => {
 | |
|       if (this.settings.autoSync) {
 | |
|         await this.syncGlobalToLocal();
 | |
|       }
 | |
|     });
 | |
|   }
 | |
|   async loadSettings() {
 | |
|     this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
 | |
|   }
 | |
|   async syncGlobalToLocal() {
 | |
|     const configDir = this.app.vault.configDir;
 | |
|     const graphConfigPath = (0, import_obsidian.normalizePath)(configDir + "/graph.json");
 | |
|     const graphConfigJson = await this.app.vault.adapter.read(graphConfigPath);
 | |
|     const graphConfig = JSON.parse(graphConfigJson);
 | |
|     const graphColorGroups = graphConfig.colorGroups;
 | |
|     const searchFilters = graphConfig.search;
 | |
|     const closeSettings = graphConfig.close;
 | |
|     const lineSizeMultiplier = graphConfig.lineSizeMultiplier;
 | |
|     const nodeSizeMultiplier = graphConfig.nodeSizeMultiplier;
 | |
|     const showTags = graphConfig.showTags;
 | |
|     this.getLocalGraphLeaves().forEach((leaf) => {
 | |
|       this.setSettings(leaf, graphColorGroups, searchFilters, closeSettings, lineSizeMultiplier, nodeSizeMultiplier, showTags);
 | |
|     });
 | |
|   }
 | |
|   getLocalGraphLeaves() {
 | |
|     return this.app.workspace.getLeavesOfType("localgraph");
 | |
|   }
 | |
|   setSettings(localGraphLeaf, colorGroups, searchFilters, closeSettings, lineSizeMultiplier, nodeSizeMultiplier, showTags) {
 | |
|     const viewState = localGraphLeaf.getViewState();
 | |
|     viewState.state.options.colorGroups = colorGroups;
 | |
|     viewState.state.options.search = searchFilters;
 | |
|     viewState.state.options.close = closeSettings;
 | |
|     viewState.state.options.lineSizeMultiplier = lineSizeMultiplier;
 | |
|     viewState.state.options.nodeSizeMultiplier = nodeSizeMultiplier;
 | |
|     viewState.state.options.showTags = showTags;
 | |
|     viewState.state.options.localJumps = this.settings.defaultDepth;
 | |
|     viewState.state.options.localBacklinks = this.settings.defaultIncomingLinks;
 | |
|     viewState.state.options.localForelinks = this.settings.defaultOutgoingLinks;
 | |
|     viewState.state.options.localInterlinks = this.settings.defaultNeighborLinks;
 | |
|     localGraphLeaf.setViewState(viewState);
 | |
|   }
 | |
|   async saveSettings() {
 | |
|     await this.saveData(this.settings);
 | |
|   }
 | |
| };
 | |
| 
 | |
| /* nosourcemap */ |