/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var m=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var L=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},A=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of M(e))!C.call(r,a)&&a!==t&&m(r,a,{get:()=>e[a],enumerable:!(s=P(e,a))||s.enumerable});return r};var D=r=>A(m({},"__esModule",{value:!0}),r);var E={};L(E,{default:()=>v});module.exports=D(E);var N=require("obsidian");var o=require("obsidian"),S={nodePositions:[],pinnedNodes:[],globalOptions:{},workspacesGraphData:{},automaticallyRestoreNodePositions:!0,enableSaveOptions:!1,enableWorkspaces:!1,timesShowedRestoredNotification:0,showSaveNotification:!1,enableGraphSimulationCommands:!1,enableAutoSave:!1,autoSaveIntervalMinutes:5},u=class extends o.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t}display(){let{containerEl:e}=this;e.empty(),e.createEl("h2",{text:"Settings for PersistentGraphPlugin"}),this.UIAutomaticallyRestoreNodePositions(),this.UIEnableSaveOptions(),this.UIEnableWorkspaces(),this.UIShowSaveNotification(),this.UIEnableAutoSave(),this.UIEnableGraphSimulationCommands()}UIAutomaticallyRestoreNodePositions(){let{containerEl:e}=this;new o.Setting(e).setName("Automatically restore node positions").setDesc("Restore node positions every time a graph view is opened").addToggle(t=>t.setValue(this.plugin.settings.automaticallyRestoreNodePositions).onChange(s=>{this.plugin.settings.automaticallyRestoreNodePositions=s,this.plugin.saveSettings()}))}UIEnableSaveOptions(){let{containerEl:e}=this;new o.Setting(e).setName("Save the filtered configuration").setDesc("Filters, Groups, Display, Forces").addToggle(t=>t.setValue(this.plugin.settings.enableSaveOptions).onChange(s=>{this.plugin.settings.enableSaveOptions=s,this.plugin.saveSettings()}))}UIEnableWorkspaces(){let{containerEl:e}=this;new o.Setting(e).setName("Save graph layout separately for each workspace").setDesc("Use workspace name as storage key").addToggle(t=>t.setValue(this.plugin.settings.enableWorkspaces).onChange(s=>{this.plugin.settings.enableWorkspaces=s,this.plugin.saveSettings()}))}UIShowSaveNotification(){let{containerEl:e}=this;new o.Setting(e).setName("Show notification on save").setDesc("Display a notice when saving the graph").addToggle(t=>t.setValue(this.plugin.settings.showSaveNotification).onChange(s=>{this.plugin.settings.showSaveNotification=s,this.plugin.saveSettings()}))}UIEnableAutoSave(){let{containerEl:e}=this;new o.Setting(e).setName("Enable Auto Save").setDesc("Automatically save graph changes").addToggle(t=>t.setValue(this.plugin.settings.enableAutoSave).onChange(s=>{this.plugin.settings.enableAutoSave=s,this.plugin.saveSettings(),s?this.plugin.graphManager.startAutoSave():this.plugin.graphManager.stopAutoSave(),this.display()})),this.plugin.settings.enableAutoSave&&new o.Setting(e).setName("Auto Save Interval").setDesc("Interval in minutes to auto save the graph").addSlider(t=>t.setLimits(1,60,1).setValue(this.plugin.settings.autoSaveIntervalMinutes).setDynamicTooltip().onChange(s=>{this.plugin.settings.autoSaveIntervalMinutes=s,this.plugin.saveSettings(),this.plugin.settings.enableAutoSave&&this.plugin.graphManager.startAutoSave()}))}UIEnableGraphSimulationCommands(){let{containerEl:e}=this;new o.Setting(e).setName("Enable graph simulation commands").setDesc(`Controls whether "Run graph simulation" and "Stop graph simulation" commands are available. Requires restart.`).addToggle(t=>t.setValue(this.plugin.settings.enableGraphSimulationCommands).onChange(s=>{this.plugin.settings.enableGraphSimulationCommands=s,this.plugin.saveSettings()}))}};var g=require("obsidian");var c=class{constructor(e){this.plugin=e;this.plugin.settings.pinnedNodes||(this.plugin.settings.pinnedNodes=[]),this._pinnedSet=new Set(this.plugin.settings.pinnedNodes)}isPinned(e){return this._pinnedSet.has(e)}async pinNode(e,t){this.plugin.settings.pinnedNodes||(this.plugin.settings.pinnedNodes=[]),this.isPinned(e)||(this.plugin.settings.pinnedNodes.push(e),this._pinnedSet.add(e),await this.plugin.saveSettings());let s=t.view.renderer.nodes.find(a=>a.id===e);s&&t.view.renderer.worker.postMessage({forceNode:{id:s.id,x:s.x,y:s.y}})}async unpinNode(e,t){this.plugin.settings.pinnedNodes&&(this.isPinned(e)&&(this.plugin.settings.pinnedNodes=this.plugin.settings.pinnedNodes.filter(s=>s!==e),this._pinnedSet.delete(e),await this.plugin.saveSettings()),t.view.renderer.worker.postMessage({forceNode:{id:e,x:null,y:null}}))}patchWorker(e){var a,i;let t=(i=(a=e==null?void 0:e.view)==null?void 0:a.renderer)==null?void 0:i.worker;if(!t||t.__pinPatched)return;let s=t.postMessage.bind(t);t.postMessage=n=>{var p,l;if(((p=n==null?void 0:n.forceNode)==null?void 0:p.x)===null&&((l=n==null?void 0:n.forceNode)==null?void 0:l.y)===null&&this.isPinned(n.forceNode.id)){this.pinNode(n.forceNode.id,e);return}s(n)},t.__pinPatched=!0}handleRename(e,t){let s=!1;return this.plugin.settings.pinnedNodes?(this.plugin.settings.pinnedNodes=this.plugin.settings.pinnedNodes.map(a=>a===t?(s=!0,e):a.startsWith(t+"/")?(s=!0,e+a.substring(t.length)):a),s&&(this._pinnedSet=new Set(this.plugin.settings.pinnedNodes)),s):!1}};var d=class{constructor(e){this.plugin=e;this.autoSaveInterval=null;this.pinManager=new c(e)}get app(){return this.plugin.app}get settings(){return this.plugin.settings}getActiveLeaf(){let e=this.app.workspace.getMostRecentLeaf();return(e==null?void 0:e.view.getViewType())==="graph"?e:null}findGraphLeaf(){let e=this.getActiveLeaf();if(e)return e;let t=this.app.workspace.getLeavesOfType("graph");if(t.length!=1){t.length<1?new g.Notice("No graph view open"):new g.Notice("More than one graph view open, please choose an active one");return}return t[0]}getActiveWorkspaceName(){if(!this.settings.enableWorkspaces)return null;let e=this.app.internalPlugins.getPluginById("workspaces");return e==null?void 0:e.instance.activeWorkspace}getGraphData(){let e=this.getActiveWorkspaceName();return e&&this.settings.workspacesGraphData[e]?this.settings.workspacesGraphData[e]:{nodePositions:this.settings.nodePositions,options:{}}}saveGraphData(){let e=this.findGraphLeaf();if(!e)return;let t=this.getActiveWorkspaceName(),s=e.view.renderer.nodes.map(i=>({id:i.id,x:i.x,y:i.y})),a=this.settings.enableSaveOptions?e.view.dataEngine.getOptions():{};if(t){this.settings.workspacesGraphData[t]={options:a,nodePositions:s};return}this.settings.nodePositions=s,this.settings.globalOptions=a,this.settings.showSaveNotification&&new g.Notice("Graph data saved successfully!")}restoreGraphData(e,t){if(t===void 0&&(t=this.findGraphLeaf()),!t)return;let{nodePositions:s}=e;s.forEach(a=>{t.view.renderer.worker.postMessage({forceNode:a})}),setTimeout(async()=>{for(let a=0;a{t.includes(a)||delete this.settings.workspacesGraphData[a]}),this.plugin.saveSettings()}runGraphSimulation(){let e=this.findGraphLeaf();e&&e.view.renderer.worker.postMessage({run:!0,alpha:1,alphaTarget:1})}stopGraphSimulation(){let e=this.findGraphLeaf();e&&e.view.renderer.worker.postMessage({run:!0,alpha:0,alphaTarget:0})}awaitRenderLoaded(e){window.requestAnimationFrame(()=>{var t,s;if((s=(t=e.view.containerEl.querySelector(".mod-search-setting"))==null?void 0:t.classList)!=null&&s.contains("is-loading")){this.awaitRenderLoaded(e);return}this.restoreOnceNodeCountStable(e,0,0,0)})}async restoreOnceNodeCountStable(e,t,s,a){if(!(!e||!e.view||!e.view.renderer)&&!(a>20)&&this.settings.automaticallyRestoreNodePositions){let i=e.view.renderer.nodes.length;i===t?s>=3?this.restoreGraphData(this.getGraphData(),e):setTimeout(()=>{this.restoreOnceNodeCountStable(e,i,s+1,a+1)},200):setTimeout(()=>{this.restoreOnceNodeCountStable(e,i,0,a+1)},200)}}startAutoSave(){this.stopAutoSave(),this.autoSaveInterval=window.setInterval(async()=>{this.saveGraphData(),await this.plugin.saveSettings()},(this.settings.autoSaveIntervalMinutes||5)*6e4)}stopAutoSave(){this.autoSaveInterval!==null&&(window.clearInterval(this.autoSaveInterval),this.autoSaveInterval=null)}handleRename(e,t){let s=!1,a=i=>{i.forEach(n=>{n.id===t?(n.id=e.path,s=!0):n.id.startsWith(t+"/")&&(n.id=e.path+n.id.substring(t.length),s=!0)})};this.settings.nodePositions&&a(this.settings.nodePositions),this.settings.workspacesGraphData&&Object.values(this.settings.workspacesGraphData).forEach(i=>{i.nodePositions&&a(i.nodePositions)}),this.pinManager.handleRename(e.path,t)&&(s=!0),s&&this.plugin.saveSettings()}};var w=require("obsidian");function f(r,e,t){let a=r.view.containerEl.querySelector(".view-actions");if(!a||a.querySelector(".persistent-graph-save-btn"))return;let i=(l,G,y,k)=>{let h=document.createElement("div");return h.className=`clickable-icon view-action ${k}`,h.setAttribute("aria-label",G),(0,w.setIcon)(h,l),h.addEventListener("click",y),h},n=i("rotate-ccw","Restore graph positions",()=>e.restoreGraphData(e.getGraphData()),"persistent-graph-restore-btn"),p=i("save","Save graph positions",async()=>{e.saveGraphData(),await t.saveSettings()},"persistent-graph-save-btn");a.prepend(p,n)}function b(r,e,t){let s=r.view.containerEl,a=s.querySelector(".persistent-graph-save-btn"),i=s.querySelector(".persistent-graph-restore-btn");a==null||a.remove(),i==null||i.remove()}var v=class extends N.Plugin{onLayoutChange(){this.app.workspace.getLeavesOfType("graph").forEach(i=>{f(i,this.graphManager,this),this.graphManager.pinManager.patchWorker(i)});let t=this.graphManager.getActiveLeaf();if(!t||t.view.getViewType()!="graph"||t.view.renderer.autoRestored)return;t.view.renderer.autoRestored=!0;let{options:s}=this.graphManager.getGraphData(),a={};s&&s.hasOwnProperty("search")&&(a=s),t.view.dataEngine.setOptions({...a,"collapse-filter":!1}),setTimeout(()=>this.graphManager.awaitRenderLoaded(t),600)}async onload(){await this.loadSettings(),this.graphManager=new d(this),this.app.workspace.getLeavesOfType("graph").forEach(t=>{f(t,this.graphManager,this),this.graphManager.pinManager.patchWorker(t)}),this.registerEvent(this.app.workspace.on("file-menu",(t,s)=>{let a=this.graphManager.getActiveLeaf();if(!a)return;let i=s.path,n=this.graphManager.pinManager.isPinned(i);t.addItem(p=>{p.setTitle(n?"Unpin node":"Pin node").setIcon(n?"pin-off":"pin").onClick(async()=>{n?await this.graphManager.pinManager.unpinNode(i,a):await this.graphManager.pinManager.pinNode(i,a)})})})),this.registerEvent(this.app.workspace.on("layout-change",this.onLayoutChange.bind(this))),this.registerEvent(this.app.metadataCache.on("resolved",this.graphManager.freedWorkspacesData.bind(this.graphManager))),this.registerEvent(this.app.vault.on("rename",(t,s)=>{this.graphManager.handleRename(t,s)})),this.settings.enableAutoSave&&this.graphManager.startAutoSave(),this.addCommand({id:"save-node-positions",name:"Save graph node positions",callback:async()=>{this.graphManager.saveGraphData(),await this.saveSettings()}}),this.addCommand({id:"restore-node-positions",name:"Restore graph node positions",callback:()=>{this.graphManager.restoreGraphData(this.graphManager.getGraphData())}}),this.settings.enableGraphSimulationCommands&&(this.addCommand({id:"run-graph-simulation",name:"Run graph simulation",callback:()=>{this.graphManager.runGraphSimulation()}}),this.addCommand({id:"stop-graph-simulation",name:"Stop graph simulation",callback:()=>{this.graphManager.stopGraphSimulation()}})),this.addSettingTab(new u(this.app,this))}onunload(){this.settings.enableAutoSave&&this.graphManager.stopAutoSave(),this.app.workspace.getLeavesOfType("graph").forEach(t=>{b(t,this.graphManager,this)})}async loadSettings(){this.settings=Object.assign({},S,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}}; /* nosourcemap */