8 lines
4.3 KiB
JavaScript
8 lines
4.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
|
|
*/
|
|
|
|
"use strict";var b=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var D=(i,e)=>{for(var r in e)b(i,r,{get:e[r],enumerable:!0})},F=(i,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of P(e))!k.call(i,t)&&t!==r&&b(i,t,{get:()=>e[t],enumerable:!(n=T(e,t))||n.enumerable});return i};var A=i=>F(b({},"__esModule",{value:!0}),i);var q={};D(q,{default:()=>g});module.exports=A(q);var h=require("obsidian");var c=class i{constructor(e){this.name=e,this.nameParts=this.name.split(".")}getPath(){return this.name+".md"}getDegree(){return this.nameParts.length}getShortName(){return this.nameParts[this.nameParts.length-1]}getRootName(){return this.nameParts[0]}truncateToDegree(e){return this.nameParts.slice(0,e).join(".")}isRoot(){return this.getDegree()===1}getParent(){if(this.isRoot())return;let e=this.nameParts.slice(0,-1).join(".");return new i(e)}getSiblings(e){if(this.isRoot())return[];let r=this.getParent();if(!r)return[];let n=this.getDegree(),t=r.name+".";return e.map(s=>s.truncateToDegree(n)).filter(s=>s!==this.name&&s!==r.name&&s.startsWith(t)).filter((s,o,a)=>a.indexOf(s)===o).map(s=>new i(s))}getChildren(e){let r=this.getDegree()+1,n=this.name+".";return e.map(t=>t.truncateToDegree(r)).filter(t=>t.startsWith(n)).filter((t,s,o)=>o.indexOf(t)===s).map(t=>new i(t))}};var w=(i,e)=>{let r=new c(i.basename),n=r.getRootName(),t=e.filter(l=>l.basename.startsWith(n)),s=new Set(t.map(l=>l.basename)),o=t.map(l=>new c(l.basename)),a=i.basename.split("."),m=r.getChildren(o);if(a.length===1&&m.length===0)return null;let u=l=>({shortName:l.getShortName(),fullName:l.name,exists:s.has(l.name)});return{segments:a.map((l,N)=>{let C=a.slice(0,N+1).join("."),p=new c(C);return{shortName:p.getShortName(),fullName:p.name,isCurrent:p.name===r.name,exists:s.has(p.name),siblings:p.getSiblings(o).map(u)}}),children:m.map(u)}};var d=require("obsidian"),y=(i,e,r)=>{let n=i.createDiv({cls:"crumbs-bar"});if(e.segments.forEach((t,s)=>{s>0&&n.createSpan({cls:"crumbs-separator",text:"/"}),L(n,t,r)}),e.children.length>0){n.createSpan({cls:"crumbs-separator",text:"/"});let t=n.createDiv({cls:"crumbs-children"});E(t,e.children,r,"Show children")}},L=(i,e,r)=>{let n=i.createDiv({cls:"crumbs-segment"}),t=["crumbs-segment-name"];e.isCurrent&&t.push("is-current"),e.exists||t.push("is-missing"),e.isCurrent?n.createSpan({cls:t.join(" "),text:e.shortName}):n.createEl("a",{cls:t.join(" "),text:e.shortName,href:e.fullName}).addEventListener("click",o=>{o.preventDefault(),M(e.fullName,r,o)}),e.siblings.length>0&&E(n,e.siblings,r,`Show siblings of ${e.shortName}`)},E=(i,e,r,n)=>{let t=i.createEl("button",{cls:"crumbs-chevron clickable-icon",attr:{type:"button","aria-label":n}});(0,d.setIcon)(t,"chevron-down"),t.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),V(s,e,r)})},V=(i,e,r)=>{let n=new d.Menu;for(let t of e)n.addItem(s=>{let o=t.exists?t.shortName:createFragment(a=>{a.createSpan({cls:"crumbs-menu-item-missing-title",text:t.shortName})});s.setTitle(o).onClick(a=>{M(t.fullName,r,a)})});n.showAtMouseEvent(i)},M=(i,e,r)=>{let n=r.ctrlKey||r.metaKey;e.workspace.openLinkText(i,"",n)};var x=(i,e,r,n)=>{let t=w(e,r);t&&y(i,t,n)};var f="crumbs-container",g=class extends h.Plugin{async onload(){this.app.workspace.onLayoutReady(async()=>{await S(this),this.registerEvent(this.app.workspace.on("file-open",async()=>{await S(this)}))})}onunload(){var r;let e=this.app.workspace.getActiveViewOfType(h.MarkdownView);e&&((r=e.containerEl.querySelectorAll(`.${f}`))==null||r.forEach(n=>n.remove()))}},S=async i=>{var a,m,u;let e=i.app.workspace.getActiveViewOfType(h.MarkdownView);if(!e)return;(a=e.containerEl.querySelectorAll(`.${f}`))==null||a.forEach(v=>v.remove());let r=e.getMode(),n=r==="preview"?e.previewMode.containerEl.querySelector("div.markdown-preview-view"):e.contentEl.querySelector("div.markdown-source-view");if(!n)return;let{file:t}=e;if(!t)return;let s=i.app.vault.getMarkdownFiles(),o=createDiv({cls:f});x(o,t,s,i.app),r==="preview"?(m=n.querySelector("div.markdown-preview-sizer"))==null||m.before(o):(u=n.querySelector("div.cm-contentContainer"))==null||u.before(o)};
|
|
|
|
/* nosourcemap */ |