8 lines
No EOL
13 KiB
JavaScript
8 lines
No EOL
13 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 b=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var U=(a,e)=>{for(var t in e)b(a,t,{get:e[t],enumerable:!0})},R=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!$.call(a,n)&&n!==t&&b(a,n,{get:()=>e[n],enumerable:!(i=I(e,n))||i.enumerable});return a};var z=a=>R(b({},"__esModule",{value:!0}),a);var G={};U(G,{default:()=>C});module.exports=z(G);var S=require("obsidian");var O=require("obsidian"),j="list",T="dynamic-outline-button",d=class{constructor(e){this._hideTimeout=null;this._plugin=e}_createButtonHTML(){let e=createEl("button",{cls:`clickable-icon view-action ${T}`,attr:{"aria-label":"Toggle Dynamic Outline"}});return(0,O.setIcon)(e,j),e}_handleButtonClick(){let e=this._plugin.getActiveMarkdownView();if(!e)return;let t=this._plugin.windowManager.getWindowFromView(e);if(t){if(this._plugin.settings.toggleOnHover){if(t.hasAttribute("pinned"))this.clearHideTimeout();else{t.setAttribute("pinned","");return}t.removeAttribute("pinned")}this._plugin.windowManager.hideWindowFromView(e)}else{let i=this._plugin.windowManager.createWindowForView(e,this._plugin.headingsManager.getHeadingsForView(e));this._plugin.settings.toggleOnHover&&(this._plugin.registerDomEvent(i,"mouseenter",()=>this.clearHideTimeout()),i.setAttribute("pinned",""))}}_handleMouseEnter(){let e=this._plugin.getActiveMarkdownView();if(!e)return;if(!this._plugin.windowManager.getWindowFromView(e)){let i=this._plugin.windowManager.createWindowForView(e,this._plugin.headingsManager.getHeadingsForView(e));this._plugin.settings.toggleOnHover&&(this._plugin.registerDomEvent(i,"mouseenter",()=>this.clearHideTimeout()),this._plugin.registerDomEvent(i,"mouseleave",()=>this._handleMouseLeave()))}this._plugin.settings.toggleOnHover&&this.clearHideTimeout()}_handleMouseLeave(){let e=this._plugin.getActiveMarkdownView();if(!e)return;let t=this._plugin.windowManager.getWindowFromView(e);t&&(t.hasAttribute("pinned")||(this._hideTimeout=setTimeout(()=>{this._plugin.windowManager.hideWindowFromView(e)},100)))}clearHideTimeout(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null)}addButtonToLeaf(e){if(this.getButtonFromLeaf(e))return;let t=e.view.containerEl.querySelector("div.view-actions");if(!t)return;let i=this._createButtonHTML();return t.insertBefore(i,t.firstChild),this._plugin.registerDomEvent(i,"click",n=>this._handleButtonClick()),this._plugin.settings.toggleOnHover&&(this._plugin.registerDomEvent(i,"mouseenter",()=>this._handleMouseEnter()),this._plugin.registerDomEvent(i,"mouseleave",()=>this._handleMouseLeave())),i}addButtonToLeaves(){this._plugin.app.workspace.onLayoutReady(()=>{this._plugin.getAllMarkdownLeaves().forEach(t=>{this.addButtonToLeaf(t)})})}getButtonFromLeaf(e){return e.view.containerEl.querySelector(`button.${T}`)}removeButtonFromLeaf(e){var t;(t=this.getButtonFromLeaf(e))==null||t.remove()}removeButtonFromLeaves(){this._plugin.getAllMarkdownLeaves().forEach(t=>{this.removeButtonFromLeaf(t)})}};var V=require("obsidian");var h=class{constructor(e,t){this.plugin=t,this.searchContainer=e,this.inputField=this.searchContainer.createEl("input",{attr:{placeholder:"Search headings...",type:"search"}}),this.clearButton=this.searchContainer.createEl("div",{cls:"search-input-clear-button dynamic-outline-search-clear-button",attr:{"aria-label":"Clear search"}}),this.setupEventListeners()}setupEventListeners(){this.plugin.registerDomEvent(this.searchContainer,"input",()=>{this.toggleClearButton()}),this.plugin.registerDomEvent(this.clearButton,"click",()=>{this.clearInput()})}toggleClearButton(){this.inputField.value.length>0?(this.clearButton.classList.add("visible"),this.inputField.classList.add("has-content")):(this.clearButton.classList.remove("visible"),this.inputField.classList.remove("has-content"))}clearInput(){this.inputField.value="";let e=new Event("input",{bubbles:!0,cancelable:!0});this.inputField.dispatchEvent(e),this.inputField.focus()}};var m=class{constructor(e){this.plugin=e}handleFileOpen(){let e=this.plugin.app.workspace.getActiveViewOfType(V.MarkdownView);if(!e)return;let t=this.getWindowFromView(e),i=this.plugin.headingsManager.getHeadingsForView(e);!i||i.length<this.plugin.settings.minimumHeadings?t&&(this.plugin.settings.toggleOnHover&&t.removeAttribute("pinned"),this.hideWindowFromView(e)):t||setTimeout(()=>{let n=this.createWindowForView(e,i);this.plugin.settings.toggleOnHover&&n.setAttribute("pinned","")},50)}_createWindowHTML(){let e=createEl("div",{attr:{id:"dynamic-outline"}}),t=e.createEl("div",{cls:"dynamic-outline-search-container"});return new h(t,this.plugin),e.createEl("div",{cls:"dynamic-outline-content-container"}).createEl("ul",{}),e}_createWindowListElement(e){let t=createEl("li",{attr:{"data-heading-line":e.position.start.line}}),i=createEl("a",{cls:`heading-level-${e.level}`,text:e.heading});return t.append(i),t}createWindowForView(e,t){let i=this._createWindowHTML();this.updateWindowWithHeadings(i,t,e);let n=i.querySelector("input");n&&this.plugin.registerDomEvent(n,"input",()=>{let o=n.value.toLowerCase(),u=i.querySelectorAll("li");u==null||u.forEach(c=>{var r;(r=c.textContent)!=null&&r.toLowerCase().includes(o)?c.classList.remove("outline-item-hidden"):c.classList.add("outline-item-hidden")})}),e.contentEl.append(i),this.plugin.settings.autofocusSearchOnOpen&&(n==null||n.focus()),this.plugin.settings.highlightCurrentHeading&&this.plugin.highlightCurrentHeading("start");let s=this.plugin.buttonManager.getButtonFromLeaf(e.leaf);return s==null||s.classList.add("button-active"),this.checkForAbstructions(i),i}checkForAbstructions(e){let t=document.getElementById("cMenuToolbarModalBar");t!=null&&t.classList.contains("top")&&e.classList.add("obstruction-top")}updateWindowWithHeadings(e,t,i){let n=e.querySelector("ul");n&&(n.empty(),t==null||t.forEach(s=>{let o=this._createWindowListElement(s);n.append(o),o.onclick=()=>{if(i.leaf.openFile(i.file,{eState:{line:s.position.start.line}}),setTimeout(()=>{i==null||i.currentMode.applyScroll(s.position.start.line)},0),this.plugin.settings.resetSearchFieldOnHeadingClick){let u=e.querySelector("input");if(u){u.value="";let c=new Event("input",{bubbles:!0,cancelable:!0});u.dispatchEvent(c),u.focus()}}}}))}getWindowFromView(e){return e==null?void 0:e.contentEl.querySelector("#dynamic-outline")}hideWindowFromView(e){let t=this.getWindowFromView(e),i=e==null?void 0:e.containerEl.querySelector(`button.${T}`);this._hideWindow(t,i)}_hideWindow(e,t){this.plugin.settings.toggleOnHover&&e&&e.hasAttribute("pinned")||(e==null||e.remove(),t==null||t.classList.remove("button-active"))}};var F=require("obsidian"),p=class{constructor(e){this.plugin=e}_cleanupHeadings(e){let t=s=>(0,F.htmlToMarkdown)(s).replaceAll("*","").replaceAll("_","").replaceAll("`","").replaceAll("==","").replaceAll("~~",""),i=s=>s.replace(/\[([^\]]+)\]\(.*?\)/g,"$1").replace(/\[\[([^\]]+)\|([^\]]+)\]\]/g,"$2").replace(/\[\[([^\]]+)\]\]/g,"$1"),n=e;return n.forEach(s=>{let o=s.heading;o=t(o),o=i(o),s.heading=o}),n}getHeadingsForView(e){var o;let t=e==null?void 0:e.file;if(!t)return[];let n=(o=(this.plugin.app.metadataCache.getFileCache(t)||{}).headings)!=null?o:[];return this._cleanupHeadings(n)}};var k=require("obsidian");var _=require("obsidian");var l=class{constructor(e,t){this.plugin=e,this.containerEl=t}};var w=class extends l{display(){new _.Setting(this.containerEl).setName("Autofocus search field on open").setDesc("Focus the search field immediately after the outline is opened.").addToggle(e=>{e.setValue(this.plugin.settings.autofocusSearchOnOpen).onChange(async t=>{this.plugin.settings.autofocusSearchOnOpen=t,await this.plugin.saveSettings()})})}};var A=require("obsidian");var f=class extends l{display(){new A.Setting(this.containerEl).setName("Highlight active heading").setDesc(g('Highlight the current outline heading when scrolling the file.<br><span style="color: var(--text-accent)">Requires a restart to take effect.</span>')).addToggle(e=>{e.setValue(this.plugin.settings.highlightCurrentHeading).onChange(async t=>{this.plugin.settings.highlightCurrentHeading=t,await this.plugin.saveSettings()})})}};var W=require("obsidian");var v=class extends l{display(){new W.Setting(this.containerEl).setName("Style customizations").setDesc(g('Please use the <a href="https://obsidian.md/plugins?id=obsidian-style-settings">Style Settings</a> plugin to apply custom font size, opacity, alignment, etc.'))}};var B=require("obsidian");var H=class extends l{display(){new B.Setting(this.containerEl).setName("Reset search field").setDesc("Erase the search field contents after jumping to a heading.").addToggle(e=>{e.setValue(this.plugin.settings.resetSearchFieldOnHeadingClick).onChange(async t=>{this.plugin.settings.resetSearchFieldOnHeadingClick=t,await this.plugin.saveSettings()})})}};var D=require("obsidian");var M=class extends l{display(){new D.Setting(this.containerEl).setName("Toggle automatically").setDesc(g('Show and hide the outline automatically based on the number of headings in the file.<br><span style="color: var(--text-accent)">Requires a restart to take effect.</span>')).addToggle(t=>{t.setValue(this.plugin.settings.toggleAutomatically).onChange(async i=>{this.plugin.settings.toggleAutomatically=i,await this.plugin.saveSettings(),e.setDisabled(!i)})});let e=new D.Setting(this.containerEl).setName("Minimum headings").setDesc(g("The minimum number of headings in the file to trigger the outline.")).addSlider(t=>{t.setLimits(1,10,1).setDynamicTooltip().setValue(this.plugin.settings.minimumHeadings).onChange(async i=>{this.plugin.settings.minimumHeadings=i,await this.plugin.saveSettings()})}).setDisabled(!this.plugin.settings.toggleAutomatically)}};var P=require("obsidian");var E=class extends l{display(){new P.Setting(this.containerEl).setName("Toggle on hover").setDesc(g("Show and hide on mouse hover. Pin the outline on mouse click.")).addToggle(e=>{e.setValue(this.plugin.settings.toggleOnHover).onChange(async t=>{this.plugin.settings.toggleOnHover=t,await this.plugin.saveSettings()})})}};var x={autofocusSearchOnOpen:!0,highlightCurrentHeading:!0,minimumHeadings:1,resetSearchFieldOnHeadingClick:!0,toggleAutomatically:!1,toggleOnHover:!1};function g(a){return(0,k.sanitizeHTMLToDom)(a)}var y=class extends k.PluginSettingTab{constructor(t,i){super(t,i);this.plugin=i}display(){let{containerEl:t}=this;t.empty(),new M(this.plugin,t).display(),new E(this.plugin,t).display(),new f(this.plugin,t).display(),new H(this.plugin,t).display(),new w(this.plugin,t).display(),new v(this.plugin,t).display()}};var C=class extends S.Plugin{constructor(){super(...arguments);this.headingsManager=new p(this);this.buttonManager=new d(this);this.windowManager=new m(this);this.getAllMarkdownLeaves=()=>this.app.workspace.getLeavesOfType("markdown");this.getActiveMarkdownView=()=>this.app.workspace.getActiveViewOfType(S.MarkdownView);this.handleMetadataChanged=()=>{let t=this.getActiveMarkdownView(),i=this.windowManager.getWindowFromView(t);if(!i)return;let n=this.headingsManager.getHeadingsForView(t);this.windowManager.updateWindowWithHeadings(i,n,t)};this.highlightCurrentHeading=(t="nearest")=>{let i=this.getActiveMarkdownView(),n=this.windowManager.getWindowFromView(i);if(!n)return;let s=this.headingsManager.getHeadingsForView(i),o=i==null?void 0:i.currentMode.getScroll(),u=s.reduce((r,L)=>o!==void 0&&L.position.start.line<=o+1&&(!r||r.position.start.line<L.position.start.line)?L:r,null);if(u){let r=n.querySelector(`li[data-heading-line="${u.position.start.line}"]`);r&&(n.querySelectorAll("li").forEach(q=>q.classList.remove("highlight")),r.classList.add("highlight"))}else{let r=n.querySelector("li");r&&r.classList.add("highlight")}let c=n.querySelector("li.highlight");c&&c.scrollIntoView({behavior:"instant",block:t})}}async onload(){await this.loadSettings(),this.addSettingTab(new y(this.app,this)),this.app.workspace.trigger("parse-style-settings"),this.buttonManager.addButtonToLeaves(),this.registerEvent(this.app.workspace.on("layout-change",()=>{this.buttonManager.addButtonToLeaves()})),this.settings.toggleAutomatically&&this.registerEvent(this.app.workspace.on("file-open",()=>{this.windowManager.handleFileOpen()})),this.registerEvent(this.app.workspace.on("active-leaf-change",()=>{this.handleMetadataChanged()})),this.registerEvent(this.app.metadataCache.on("changed",()=>{this.handleMetadataChanged()})),this.settings.highlightCurrentHeading&&(activeWindow.document.addEventListener("scroll",t=>{let i=t.target;i!=null&&i.classList.contains("dynamic-outline-content-container")||this.highlightCurrentHeading()},!0),this.registerEvent(this.app.metadataCache.on("changed",()=>{this.highlightCurrentHeading()}))),this.addCommand({id:"toggle-dynamic-outline",name:"Toggle for current file",checkCallback:t=>{let i=this.getActiveMarkdownView();if(i){if(!t){let n=this.windowManager.getWindowFromView(i);if(n)this.settings.toggleOnHover&&n.removeAttribute("pinned"),this.windowManager.hideWindowFromView(i);else{let s=this.windowManager.createWindowForView(i,this.headingsManager.getHeadingsForView(i));this.settings.toggleOnHover&&s.setAttribute("pinned","")}}return!0}return!1}})}onunload(){this.buttonManager.removeButtonFromLeaves()}async loadSettings(){this.settings=Object.assign({},x,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};
|
|
|
|
/* nosourcemap */ |