Files

9 lines
26 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 H=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var Te=(n,e)=>{for(var t in e)H(n,t,{get:e[t],enumerable:!0})},Ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ee(e))!xe.call(n,i)&&i!==t&&H(n,i,{get:()=>e[i],enumerable:!(r=Fe(e,i))||r.enumerable});return n};var Ce=n=>Ie(H({},"__esModule",{value:!0}),n);var Ne={};Te(Ne,{default:()=>U});module.exports=Ce(Ne);var ye=require("obsidian");var G="is-resolved",j="is-unresolved";var L=require("@codemirror/state"),B=L.StateEffect.define(),Pe=L.StateEffect.define(),I=null,ne=n=>{I=n},S=L.StateField.define({create(n){return I||{raw:[],asPathes:[]}},update(n,e){let t=n;for(let r of e.effects)r.is(B)?(t=r.value,I=r.value):r.is(Pe)&&(t={raw:[],asPathes:[]},I={raw:[],asPathes:[]});return t}});var ie=require("@codemirror/view");var oe=n=>(n.subscribe(e=>{ne(e)}),ie.EditorView.updateListener.of(e=>{e.view.dom.dataset.folderRegistered||(e.view.dom.dataset.folderRegistered="true",n.subscribe(t=>{e.view.dom.isConnected&&e.view.dispatch({effects:[B.of(t)]})}))}));var O=require("@codemirror/view"),ge=require("@codemirror/state"),me=require("@codemirror/language");function Oe(n,e){var t=typeof Symbol!="undefined"&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=Me(n))||e&&n&&typeof n.length=="number"){t&&(n=t);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Me(n,e){if(n){if(typeof n=="string")return ae(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);if(t==="Object"&&n.constructor&&(t=n.constructor.name),t==="Map"||t==="Set")return Array.from(n);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return ae(n,e)}}function ae(n,e){(e==null||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function se(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}function z(n,e,t){return e&&se(n.prototype,e),t&&se(n,t),n}var J=function(){return typeof Symbol=="function"},Q=function(n){return J()&&Boolean(Symbol[n])},X=function(n){return Q(n)?Symbol[n]:"@@"+n};J()&&!Q("observable")&&(Symbol.observable=Symbol("observable"));var _e=X("iterator"),$=X("observable"),le=X("species");function P(n,e){var t=n[e];if(t!=null){if(typeof t!="function")throw new TypeError(t+" is not a function");return t}}function y(n){var e=n.constructor;return e!==void 0&&(e=e[le],e===null&&(e=void 0)),e!==void 0?e:b}function We(n){return n instanceof b}function w(n){w.log?w.log(n):setTimeout(function(){throw n})}function C(n){Promise.resolve().then(function(){try{n()}catch(e){w(e)}})}function ce(n){var e=n._cleanup;if(e!==void 0&&(n._cleanup=void 0,!!e))try{if(typeof e=="function")e();else{var t=P(e,"unsubscribe");t&&t.call(e)}}catch(r){w(r)}}function K(n){n._observer=void 0,n._queue=void 0,n._state="closed"}function Ae(n){var e=n._queue;if(e){n._queue=void 0,n._state="ready";for(var t=0;t<e.length&&(ue(n,e[t].type,e[t].value),n._state!=="closed");++t);}}function ue(n,e,t){n._state="running";var r=n._observer;try{var i=P(r,e);switch(e){case"next":i&&i.call(r,t);break;case"error":if(K(n),i)i.call(r,t);else throw t;break;case"complete":K(n),i&&i.call(r);break}}catch(s){w(s)}n._state==="closed"?ce(n):n._state==="running"&&(n._state="ready")}function q(n,e,t){if(n._state!=="closed"){if(n._state==="buffering"){n._queue.push({type:e,value:t});return}if(n._state!=="ready"){n._state="buffering",n._queue=[{type:e,value:t}],C(function(){return Ae(n)});return}ue(n,e,t)}}var Ve=function(){function n(t,r){this._cleanup=void 0,this._observer=t,this._queue=void 0,this._state="initializing";var i=new De(this);try{this._cleanup=r.call(void 0,i)}catch(s){i.error(s)}this._state==="initializing"&&(this._state="ready")}var e=n.prototype;return e.unsubscribe=function(){this._state!=="closed"&&(K(this),ce(this))},z(n,[{key:"closed",get:function(){return this._state==="closed"}}]),n}(),De=function(){function n(t){this._subscription=t}var e=n.prototype;return e.next=function(r){q(this._subscription,"next",r)},e.error=function(r){q(this._subscription,"error",r)},e.complete=function(){q(this._subscription,"complete")},z(n,[{key:"closed",get:function(){return this._subscription._state==="closed"}}]),n}(),b=function(){function n(t){if(!(this instanceof n))throw new TypeError("Observable cannot be called as a function");if(typeof t!="function")throw new TypeError("Observable initializer must be a function");this._subscriber=t}var e=n.prototype;return e.subscribe=function(r){return(typeof r!="object"||r===null)&&(r={next:r,error:arguments[1],complete:arguments[2]}),new Ve(r,this._subscriber)},e.forEach=function(r){var i=this;return new Promise(function(s,a){if(typeof r!="function"){a(new TypeError(r+" is not a function"));return}function o(){l.unsubscribe(),s()}var l=i.subscribe({next:function(u){try{r(u,o)}catch(c){a(c),l.unsubscribe()}},error:a,complete:s})})},e.map=function(r){var i=this;if(typeof r!="function")throw new TypeError(r+" is not a function");var s=y(this);return new s(function(a){return i.subscribe({next:function(o){try{o=r(o)}catch(l){return a.error(l)}a.next(o)},error:function(o){a.error(o)},complete:function(){a.complete()}})})},e.filter=function(r){var i=this;if(typeof r!="function")throw new TypeError(r+" is not a function");var s=y(this);return new s(function(a){return i.subscribe({next:function(o){try{if(!r(o))return}catch(l){return a.error(l)}a.next(o)},error:function(o){a.error(o)},complete:function(){a.complete()}})})},e.reduce=function(r){var i=this;if(typeof r!="function")throw new TypeError(r+" is not a function");var s=y(this),a=arguments.length>1,o=!1,l=arguments[1],u=l;return new s(function(c){return i.subscribe({next:function(d){var f=!o;if(o=!0,!f||a)try{u=r(u,d)}catch(p){return c.error(p)}else u=d},error:function(d){c.error(d)},complete:function(){if(!o&&!a)return c.error(new TypeError("Cannot reduce an empty sequence"));c.next(u),c.complete()}})})},e.concat=function(){for(var r=this,i=arguments.length,s=new Array(i),a=0;a<i;a++)s[a]=arguments[a];var o=y(this);return new o(function(l){var u,c=0;function d(f){u=f.subscribe({next:function(p){l.next(p)},error:function(p){l.error(p)},complete:function(){c===s.length?(u=void 0,l.complete()):d(o.from(s[c++]))}})}return d(r),function(){u&&(u.unsubscribe(),u=void 0)}})},e.flatMap=function(r){var i=this;if(typeof r!="function")throw new TypeError(r+" is not a function");var s=y(this);return new s(function(a){var o=[],l=i.subscribe({next:function(c){if(r)try{c=r(c)}catch(f){return a.error(f)}var d=s.from(c).subscribe({next:function(f){a.next(f)},error:function(f){a.error(f)},complete:function(){var f=o.indexOf(d);f>=0&&o.splice(f,1),u()}});o.push(d)},error:function(c){a.error(c)},complete:function(){u()}});function u(){l.closed&&o.length===0&&a.complete()}return function(){o.forEach(function(c){return c.unsubscribe()}),l.unsubscribe()}})},e[$]=function(){return this},n.from=function(r){var i=typeof this=="function"?this:n;if(r==null)throw new TypeError(r+" is not an object");var s=P(r,$);if(s){var a=s.call(r);if(Object(a)!==a)throw new TypeError(a+" is not an object");return We(a)&&a.constructor===i?a:new i(function(o){return a.subscribe(o)})}if(Q("iterator")&&(s=P(r,_e),s))return new i(function(o){C(function(){if(!o.closed){for(var l=Oe(s.call(r)),u;!(u=l()).done;){var c=u.value;if(o.next(c),o.closed)return}o.complete()}})});if(Array.isArray(r))return new i(function(o){C(function(){if(!o.closed){for(var l=0;l<r.length;++l)if(o.next(r[l]),o.closed)return;o.complete()}})});throw new TypeError(r+" is not observable")},n.of=function(){for(var r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];var a=typeof this=="function"?this:n;return new a(function(o){C(function(){if(!o.closed){for(var l=0;l<i.length;++l)if(o.next(i[l]),o.closed)return;o.complete()}})})},z(n,null,[{key:le,get:function(){return this}}]),n}();J()&&Object.defineProperty(b,Symbol("extensions"),{value:{symbol:$,hostReportError:w},configurable:!0});function de(n){n=n.replace("#","");let e=parseInt(n.substr(0,2),16),t=parseInt(n.substr(2,2),16),r=parseInt(n.substr(4,2),16);return{decimal:(e<<16)+(t<<8)+r,r:e,g:t,b:r,hex:n}}function h(n){let e=n.trim();return e.substring(0,e.length-1)}function g(n){return n.trim()+"/"}function Y(n){return n.endsWith("/")}function fe(n,e){let t=/\[\[([^\]\|]+\/)[^\]]*\]\]/g,r;for(;(r=t.exec(n))!==null;)if(e>=r.index&&e<=r.index+r[0].length)return r[1];return null}function pe(n,e){return new b(t=>{let r=null,i=n.subscribe({next(s){r&&clearTimeout(r),r=setTimeout(()=>{t.next(s)},e)},error(s){t.error(s)},complete(){t.complete()}});return()=>{r&&clearTimeout(r),i.unsubscribe()}})}function he(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ve=O.ViewPlugin.fromClass(class{constructor(n){this.decorations=this.buildDecorations(n)}update(n){(n.docChanged||n.viewportChanged||n.state.field(S)!==n.startState.field(S))&&(this.decorations=this.buildDecorations(n.view))}buildDecorations(n){let e=new ge.RangeSetBuilder,t=n.state.field(S),r=null,i=null,s=!1;for(let{from:a,to:o}of n.visibleRanges)(0,me.syntaxTree)(n.state).iterate({from:a,to:o,enter(l){let u=l.type.name.includes("hmd-internal-link");if(!r&&!i&&u)r=l.from,i=l.to,s=l.type.name.includes("link-has-alias");else if(r&&u)i=l.to;else if(r&&i&&!u){let c=n.state.doc.sliceString(r,i),d=c;if(s){let f=c.split("|");d=f[0],c=f[1]}if(d.trim().endsWith("/")){let f=h(d.trim()),p=t.asPathes.includes(f)?"is-resolved":"is-unresolved";e.add(r,i,O.Decoration.mark({class:p+" folder-link",attributes:{"data-folder-link":d}}))}r=null,i=null,s=!1}}});return e.finish()}},{decorations:n=>n.decorations});var be=require("obsidian"),F=class extends Error{};function Z(n){new be.Notice(`FolderLinks: Error: ${n}`)}var Se=require("obsidian");var m=class extends Se.MarkdownRenderChild{constructor(t,r){super(t);this.targets=r}onload(){this.render()}render(){this.targets.forEach(t=>{if(!t.dataset.href&&!t.dataset.folderLink||!m.folders)return;let r;if(t.dataset.href)r=h(t.dataset.href),t.dataset.folderLink=t.dataset.href;else if(t.dataset.folderLink)r=h(t.dataset.folderLink);else return;m.folders.asPathes.includes(r)?(t.addClass(G),t.removeClass(j),t.removeAttribute("data-href"),t.removeAttribute("href"),t.removeAttribute("target")):(t.addClass(j),t.removeClass(G))})}};var ee=class{constructor(e){this.folderObs=e;this.folderLinkViews=[];this.folderObs.subscribe(t=>{m.folders=t,this.folderLinkViews.forEach(r=>{r.render()})})}create(){return(e,t)=>{let r=e.findAll(".internal-link").filter(i=>i.dataset.href&&i.dataset.href.endsWith("/"));if(r&&r.length){let i=new m(e,r);t.addChild(i),this.folderLinkViews.push(i)}}}},we=n=>new ee(n).create();var te=class{constructor(e,t,r,i,s=!1){this.id=e;this.initCb=t;this.cleanupCb=r;this.updateCb=i;this.allowMultiple=s;this.instances=new Set}addInstance(e){if(this.instances.has(e))this.updateCb&&this.updateCb(e);else if(this.instances.add(e),this.initCb){this.initCb(e);return}}removeInstance(e){this.instances.has(e)&&(this.cleanupCb&&this.cleanupCb(e),this.instances.delete(e))}getInstances(){return this.instances}clearInstances(){for(let e of this.instances)this.cleanupCb&&this.cleanupCb(e);this.instances.clear()}setInstance(e){this.addInstance(e)}getInstance(){return this.instances.size===1?this.instances.entries().next().value:void 0}clearInstance(){this.clearInstances()}},E=class{constructor(e){this.workspace=e;this.watchers=new Map;this.workspace.on("active-leaf-change",t=>{this.watchers.forEach(r=>{let i=this.workspace.getLeavesOfType(r.id);if(i&&i.length===1)r.setInstance(i[0]);else if(i.length===0)r.clearInstance();else if(r.allowMultiple)i.forEach(s=>{r.addInstance(s)});else throw Error(`More than one instance of ${r.id} available!`)})})}getInstancesImmediate(e){return this.workspace.getLeavesOfType(e)}getInstanceImmediate(e){let t=this.workspace.getLeavesOfType(e);if(t&&t.length===1)return t[0]}getInstance(e){var t;return(t=this.watchers.get(e))==null?void 0:t.getInstance()}getInstances(e){var t,r;return(r=(t=this.watchers.get(e))==null?void 0:t.getInstances())!=null?r:new Set}registerWatcher(e,t,r,i,s){let a=this.getInstancesImmediate(e),o=new te(e,t,r,i,s);a&&a.length>0&&t&&a.forEach(l=>o.addInstance(l)),this.watchers.set(e,o)}unregisterWatcher(e){this.watchers.delete(e)}};var x=class{constructor(e){this.plugin=e}onVaultEvent(e,t){this.plugin.registerEvent(this.plugin.app.vault.on(e,t))}onLayoutReady(e){this.plugin.app.workspace.onLayoutReady(e)}async waitForLayoutReady(){return this.plugin.app.workspace.layoutReady?Promise.resolve():new Promise(e=>{this.onLayoutReady(()=>e())})}onDOMEvent(e,t,r,i,s){this.plugin.registerDomEvent(e,t,a=>{let o=a.target.closest(r);o&&i(o,a)},s)}};var T=class{constructor(e,t,r){this.vault=e;this.metadataCache=t;this.eventService=r;this.currentValue=this.loadAll(),this.setupObservable(),this.observable.subscribe(i=>{this.currentValue=i})}createFolder(e){this.vault.createFolder(e)}findExistingFolderRaw(e){return this.currentValue.raw.find(t=>t===e)}loadAll(){let e=this.vault.getAllFolders();return{raw:e,asPathes:e.map(t=>t.path)}}setupObservable(){this.observable=pe(new b(e=>{e.next(this.loadAll()),this.eventService.onVaultEvent("create",()=>{e.next(this.loadAll())}),this.eventService.onVaultEvent("rename",()=>{e.next(this.loadAll())}),this.eventService.onVaultEvent("delete",()=>{e.next(this.loadAll())})}),50)}getLinkedFiles(e){let t=new Set;return Object.entries(this.metadataCache.unresolvedLinks).forEach(([r,i])=>{Object.keys(i).includes(g(e))&&t.add(r)}),Array.from(t).map(r=>this.vault.getFileByPath(r)).filter(r=>r!==null)}getFolderLinkCountInFile(e,t){return this.metadataCache.unresolvedLinks[e.path][g(t)]||0}getFolderLinkCountInFiles(e,t){return e.reduce((r,i)=>r+this.getFolderLinkCountInFile(i,t),0)}};var M=class{constructor(e,t,r){this.folderService=e;this.fileExplorer=t;this.settingsService=r;this.instances=new Set;this.update()}addInstance(e){var t;(t=e.view.dataEngine)!=null&&t.renderer&&(this.instances.add(e),this.updateInstance(e))}removeInstance(e){this.instances.delete(e)}update(){this.instances.forEach(e=>{this.updateInstance(e)})}updateInstance(e){var s,a;if(!((s=e.view.dataEngine)!=null&&s.renderer))return;let t=e.view.dataEngine.renderer.onNodeClick;e.view.dataEngine.renderer.onNodeClick=(o,l)=>{var u,c,d;if(Y(l)){let f=e.view.dataEngine.renderer.nodes.filter(p=>p.id===l)[0];f._folderLink?((c=(u=this.fileExplorer.view).revealInFolder)==null||c.call(u,f._folderLink),this.settingsService.getSetting("expandOnReveal")&&((d=this.fileExplorer.view.fileItems[f._folderLink.path])==null||d.setCollapsed(!1))):this.folderService.createFolder(l)}else t(o,l)};let r=getComputedStyle(document.body).getPropertyValue("--graph-node").trim(),i=Object.keys(e.view.dataEngine.renderer.nodeLookup);for(let o of i)if(Y(o)){let l=this.folderService.currentValue.raw.filter(d=>d.path===h(o))[0],u=h(o),c=((a=u.split("/").pop())!=null?a:u)+"/";if(e.view.dataEngine.renderer.nodeLookup[o].text&&(e.view.dataEngine.renderer.nodeLookup[o].text.text=c),l){e.view.dataEngine.renderer.nodeLookup[o]._folderLink=l;let d=e.view.dataEngine.renderer.nodeLookup[o],f=e.view.renderer;e.view.dataEngine.renderer.nodeLookup[o].getFillColor=()=>{var p;return d.type==="unresolved"&&((p=f==null?void 0:f.getHighlightNode())==null?void 0:p.id)!=d.id?{a:1,rgb:de(r).decimal}:d.__proto__.getFillColor.call(d)}}else e.view.dataEngine.renderer.nodeLookup[o].getFillColor=e.view.dataEngine.renderer.nodeLookup[o].__proto__.getFillColor,e.view.dataEngine.renderer.nodeLookup[o]._folderLink=null;e.onResize()}}};var re=require("obsidian");var _=class{constructor(e,t,r,i){this.translationService=e;this.folderService=t;this.outgoingLink=r;this.settings=i;this.isUpdating=!1;this.debouncedUpdateFolderLinks=this.debounce(()=>this.updateFolderLinks(),100),this.setupMutationObserver(),this.update()}debounce(e,t){let r;return()=>{r&&clearTimeout(r),r=window.setTimeout(e,t)}}setupMutationObserver(){let e=this.outgoingLink.view.containerEl;e&&(this.mutationObserver=new MutationObserver(this.mutationHandler.bind(this)),this.mutationObserver.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0}))}mutationHandler(e){if(e.some(r=>r.type==="childList"||r.type==="attributes"&&r.attributeName==="data-folder-link"||r.type==="characterData")&&!this.isUpdating){this.isUpdating=!0;try{this.update()}finally{this.isUpdating=!1}}}update(){this.settings.showInBackLinks?this.debouncedUpdateFolderLinks():this.removeFolderLinks()}removeFolderLinks(){this.outgoingLink.view.containerEl.querySelectorAll(".outgoing-link-item").forEach(t=>{var r;(r=t.textContent)!=null&&r.endsWith("/")&&t.remove()})}updateFolderLinks(){var t;(t=this.mutationObserver)==null||t.disconnect(),this.outgoingLink.view.containerEl.querySelectorAll(".outgoing-link-item").forEach(r=>{let i=r.textContent;if(i!=null&&i.endsWith("/")&&this.folderService.currentValue){let s=this.folderService.currentValue.raw.find(o=>o.path===h(i));r.dataset.folderLink!==i&&(r.dataset.folderLink=i);let a=r.querySelector(".tree-item-icon");if(s){let o=this.translationService.getTranslation("plugins.file-explorer.action-reveal-file");r.ariaLabel!==o&&(r.ariaLabel=o),a&&a.getAttribute("data-icon")!=="link"&&(0,re.setIcon)(a,"link")}else{let o=this.translationService.getTranslation("plugins.outgoing-links.tooltip-not-created");r.ariaLabel!==o&&(r.ariaLabel=o),a&&a.getAttribute("data-icon")!=="folder-plus"&&(0,re.setIcon)(a,"folder-plus")}}}),this.setupMutationObserver()}disconnect(){var e;(e=this.mutationObserver)==null||e.disconnect()}};var ke={showInBackLinks:!0,alwaysUpdate:!1,expandOnReveal:!0};var k=require("obsidian"),W=class extends k.PluginSettingTab{constructor(t,r,i){super(t,r);this.app=t;this.plugin=r;this.settings=i}display(){let{containerEl:t}=this;t.empty(),new k.Setting(t).setName("Show Folder Links in Outgoing Links Tab").addToggle(r=>r.setValue(this.settings.showInBackLinks).onChange(async i=>{this.settings.showInBackLinks=i,await this.plugin.saveSettings()})),new k.Setting(t).setName("Automatically update folder links").setDesc("Turn off to be prompted to update links after renaming a folder.").addToggle(r=>r.setValue(this.settings.alwaysUpdate).onChange(async i=>{this.settings.alwaysUpdate=i,await this.plugin.saveSettings()})),new k.Setting(t).setName("Expand folder").setDesc("When clicking a link, expand the folder in the file pane.").addToggle(r=>r.setValue(this.settings.expandOnReveal).onChange(async i=>{this.settings.expandOnReveal=i,await this.plugin.saveSettings()}))}};var v=require("obsidian"),A=class{constructor(e,t,r,i,s,a,o,l){this.vault=e;this.workspace=t;this.settingsService=r;this.translationService=i;this.eventService=s;this.modalService=a;this.folderService=o;this.fileExplorer=l;this.pendingFolderLink=null;this.setupClickListener(),this.eventService.onVaultEvent("rename",this.renameAfterUpdateCb.bind(this))}handleFolderLinkAction(e){var r,i,s;let t=this.folderService.currentValue.raw.filter(a=>a.path===h(e))[0];t?(this.workspace.revealLeaf(this.fileExplorer),(i=(r=this.fileExplorer.view).revealInFolder)==null||i.call(r,t),this.settingsService.getSetting("expandOnReveal")&&((s=this.fileExplorer.view.fileItems[t.path])==null||s.setCollapsed(!1))):this.folderService.createFolder(h(e))}getFolderLinkAtCursor(){let e=this.workspace.getActiveViewOfType(v.MarkdownView);if(!e)return null;let t=e.editor.getCursor();return fe(e.editor.getLine(t.line),t.ch)}setupClickListener(){this.eventService.onDOMEvent(window,"pointerdown","[data-folder-link]",e=>{this.pendingFolderLink=e.dataset.folderLink},!0),this.eventService.onDOMEvent(window,"click",".follow-link-popover",(e,t)=>{var i;let r=(i=this.pendingFolderLink)!=null?i:this.getFolderLinkAtCursor();this.pendingFolderLink=null,r&&(t.stopPropagation(),t.preventDefault(),this.handleFolderLinkAction(r))},!0),this.eventService.onDOMEvent(window,"click","[data-folder-link]",(e,t)=>{t.stopPropagation(),this.handleFolderLinkAction(e.dataset.folderLink)},!0),this.eventService.onDOMEvent(window,"contextmenu","[data-folder-link]",(e,t)=>{t.stopPropagation(),t.preventDefault();let r=e.dataset.folderLink,i=this.folderService.currentValue.raw.find(a=>a.path===h(r));if(!i)return;let s=new v.Menu;this.workspace.trigger("file-menu",s,i,"link-context-menu"),s.showAtMouseEvent(t)},!0)}renameAfterUpdateCb(e,t){var r;if(e instanceof v.TFolder){let i=this.folderService.getLinkedFiles(t),s=this.folderService.getFolderLinkCountInFiles(i,t);if(i.length)if(this.settingsService.getSetting("alwaysUpdate"))this.renameFolderLinksInFiles(i,g(e.path),g(t),s,i.length);else{let a,o=new DocumentFragment,l=document.createElement("p"),u=document.createElement("p");l.textContent=this.translationService.getTranslation("dialogue.label-confirm-update-link-to-file").replace(this.translationService.getTranslation("plugins.bases.label-file-prop-file"),this.translationService.getTranslation("plugins.bases.label-file-prop-folder")),u.textContent=this.translationService.getTranslation("dialogue.label-link-affected",{links:this.translationService.getTranslation("nouns.link-with-count_plural",{count:s.toString()}),files:this.translationService.getTranslation("nouns.file-with-count_plural",{count:i.length.toString()})});let c=document.createElement("div");c.classList.add("modal-button-container");let d=document.createElement("button");d.textContent="Always update",d.onclick=async()=>{await this.renameFolderLinksInFiles(i,g(e.path),g(t),s,i.length),await this.settingsService.setSetting("alwaysUpdate",!0),a.close()},c.appendChild(d);let f=document.createElement("button");f.textContent="Just once",f.onclick=async()=>{await this.renameFolderLinksInFiles(i,g(e.path),g(t),s,i.length),a.close()},c.appendChild(f);let p=document.createElement("button");p.textContent="Do not update",p.onclick=async()=>{a.close()},c.appendChild(p),o.append(l,u),a=this.modalService.createModal(this.translationService.getTranslation("dialogue.label-update-links"),o),(r=a.contentEl.parentElement)==null||r.appendChild(c),a.open()}}}async renameFolderLinksInFiles(e,t,r,i,s){for(let a of e)try{let o=await this.vault.read(a),l=new RegExp(`(\\s*\\[\\[\\s*)${he(r)}([^\\]]*\\]\\]\\s*)`,"g"),u=o.replace(l,`$1${t}$2`);o!==u&&await this.vault.modify(a,u)}catch(o){throw new Error(`Failed to update links in ${a.path}:`)}new v.Notice(this.translationService.getTranslation("dialogue.msg-updated-links",{links:this.translationService.getTranslation("nouns.link-with-count_plural",{count:i.toString()}),files:this.translationService.getTranslation("nouns.file-with-count_plural",{count:s.toString()})}))}};var Le=require("obsidian"),V=class{constructor(e){this.app=e}createModal(e,t){let r=new Le.Modal(this.app);return r.setTitle(e).setContent(t),r}};var D=class{constructor(e){this.i18next=e;if(!e)throw Error("No translations found")}getTranslation(e,t){return this.i18next.t(e,t)}};var R=class{constructor(e,t){this.plugin=e;this.settings=t}getSetting(e){return this.settings[e]}async setSetting(e,t){this.settings[e]=t,this.saveSettings()}async saveSettings(){this.plugin.saveSettings()}};var N=class{constructor(e,t){this.workspace=e;this.metadataCache=t}getActiveEditor(){return this.workspace.activeEditor}folderLinksinActiveEditor(){let e=this.getActiveEditor();if(!e||!e.file)return;let t=this.metadataCache.unresolvedLinks[e.file.path];return Object.keys(t).filter(r=>r.trim().endsWith("/")).length}};var U=class extends ye.Plugin{onload(){try{this.setup()}catch(t){t instanceof F?Z(t.message):Z("An internal error occured.")}}async setup(){await this.setupSettings(),this.initServices(),await this.eventService.waitForLayoutReady(),this.setupFileExplorer(),this.initServices(),this.initDependentServices(),this.setupCorePluginWatchers(),this.registerMarkdownPostProcessor(we(this.folderService.observable)),this.registerEditorExtension([oe(this.folderService.observable),S,ve]),this.folderService.observable.subscribe(()=>{this.graphViewManager&&this.graphViewManager.update()})}async setupSettings(){await this.loadSettings(),this.addSettingTab(new W(this.app,this,this.settings))}async loadSettings(){this.settings=Object.assign({},ke,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}initServices(){this.settingsService=new R(this,this.settings),this.workspaceService=new N(this.app.workspace,this.app.metadataCache),this.translationService=new D(window.i18next),this.eventService=new x(this),this.modalService=new V(this.app),this.corePluginService=new E(this.app.workspace),this.folderService=new T(this.app.vault,this.app.metadataCache,this.eventService)}setupFileExplorer(){let t=this.corePluginService.getInstancesImmediate("file-explorer");if(t.length===0)throw new F("No file explorer plugin found. Is the core plugin enabled?");if(t.length>1)throw new Error("More than one file explorer plugin found. Undefined state.");this.obsidianFileExplorer=t[0]}initDependentServices(){this.folderLinkManager=new A(this.app.vault,this.app.workspace,this.settingsService,this.translationService,this.eventService,this.modalService,this.folderService,this.obsidianFileExplorer),this.graphViewManager=new M(this.folderService,this.obsidianFileExplorer,this.settingsService)}setupCorePluginWatchers(){this.corePluginService.registerWatcher("outgoing-link",t=>{this.obsidianOutgoingLink=t,this.outgoingLinkManager=new _(this.translationService,this.folderService,this.obsidianOutgoingLink,this.settings)},()=>{var t;this.obsidianOutgoingLink=void 0,(t=this.outgoingLinkManager)==null||t.disconnect(),this.outgoingLinkManager=void 0}),this.corePluginService.registerWatcher("graph",t=>{this.graphViewManager.addInstance(t)},t=>{this.graphViewManager.removeInstance(t)},t=>{this.graphViewManager.updateInstance(t)},!0)}};
/* nosourcemap */