Oscar Plaisant 3a5cad8e48 update
2024-12-17 18:49:14 +01:00

124 lines
5.3 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
};
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").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").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").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").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").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;
this.getLocalGraphLeaves().forEach((leaf) => {
this.setSettings(leaf, graphColorGroups, searchFilters, closeSettings, lineSizeMultiplier, nodeSizeMultiplier);
});
}
getLocalGraphLeaves() {
return this.app.workspace.getLeavesOfType("localgraph");
}
setSettings(localGraphLeaf, colorGroups, searchFilters, closeSettings, lineSizeMultiplier, nodeSizeMultiplier) {
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.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 */