tech-tips/.obsidian/plugins/homepage/main.js

3 lines
31 KiB
JavaScript
Raw Normal View History

"use strict";var He=Object.create;var _=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Re=(a,t)=>()=>(t||a((t={exports:{}}).exports,t),t.exports),Ie=(a,t)=>{for(var e in t)_(a,e,{get:t[e],enumerable:!0})},le=(a,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of xe(t))!Ce.call(a,i)&&i!==e&&_(a,i,{get:()=>t[i],enumerable:!(n=Le(t,i))||n.enumerable});return a};var _e=(a,t,e)=>(e=a!=null?He(Ve(a)):{},le(t||!a||!a.__esModule?_(e,"default",{value:a,enumerable:!0}):e,a)),We=a=>le(_({},"__esModule",{value:!0}),a);var Me=Re(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});var g=require("obsidian"),Q="YYYY-MM-DD",J="gggg-[W]ww",ge="YYYY-MM",me="YYYY-[Q]Q",he="YYYY";function S(a){let t=window.app.plugins.getPlugin("periodic-notes");return t&&t.settings?.[a]?.enabled}function E(){try{let{internalPlugins:a,plugins:t}=window.app;if(S("daily")){let{format:o,folder:s,template:p}=t.getPlugin("periodic-notes")?.settings?.daily||{};return{format:o||Q,folder:s?.trim()||"",template:p?.trim()||""}}let{folder:e,format:n,template:i}=a.getPluginById("daily-notes")?.instance?.options||{};return{format:n||Q,folder:e?.trim()||"",template:i?.trim()||""}}catch(a){console.info("No custom daily note settings found!",a)}}function H(){try{let a=window.app.plugins,t=a.getPlugin("calendar")?.options,e=a.getPlugin("periodic-notes")?.settings?.weekly;if(S("weekly"))return{format:e.format||J,folder:e.folder?.trim()||"",template:e.template?.trim()||""};let n=t||{};return{format:n.weeklyNoteFormat||J,folder:n.weeklyNoteFolder?.trim()||"",template:n.weeklyNoteTemplate?.trim()||""}}catch(a){console.info("No custom weekly note settings found!",a)}}function L(){let a=window.app.plugins;try{let t=S("monthly")&&a.getPlugin("periodic-notes")?.settings?.monthly||{};return{format:t.format||ge,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom monthly note settings found!",t)}}function x(){let a=window.app.plugins;try{let t=S("quarterly")&&a.getPlugin("periodic-notes")?.settings?.quarterly||{};return{format:t.format||me,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom quarterly note settings found!",t)}}function V(){let a=window.app.plugins;try{let t=S("yearly")&&a.getPlugin("periodic-notes")?.settings?.yearly||{};return{format:t.format||he,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom yearly note settings found!",t)}}function fe(...a){let t=[];for(let n=0,i=a.length;n<i;n++)t=t.concat(a[n].split("/"));let e=[];for(let n=0,i=t.length;n<i;n++){let o=t[n];!o||o==="."||e.push(o)}return t[0]===""&&e.unshift(""),e.join("/")}function Ye(a){let t=a.substring(a.lastIndexOf("/")+1);return t.lastIndexOf(".")!=-1&&(t=t.substring(0,t.lastIndexOf("."))),t}async function Ue(a){let t=a.replace(/\\/g,"/").split("/");if(t.pop(),t.length){let e=fe(...t);window.app.vault.getAbstractFileByPath(e)||await window.app.vault.createFolder(e)}}async function C(a,t){t.endsWith(".md")||(t+=".md");let e=g.normalizePath(fe(a,t));return await Ue(e),e}async function A(a){let{metadataCache:t,vault:e}=window.app,n=g.normalizePath(a);if(n==="/")return Promise.resolve(["",null]);try{let i=t.getFirstLinkpathDest(n,""),o=await e.cachedRead(i),s=window.app.foldManager.load(i);return[o,s]}catch(i){return console.error(`Failed to read the daily note template '${n}'`,i),new g.Notice("Failed to read the daily note template"),["",null]}}function b(a,t="day"){let e=a.clone().startOf(t).format();return`${t}-${e}`}function we(a){return a.replace(/\[[^\]]*\]/g,"")}function qe(a,t){if(t==="week"){let e=we(a);return/w{1,2}/i.test(e)&&(/M{1,4}/.test(e)||/D{1,4}/.test(e))}return!1}function O(a,t){return ye(a.basename,t)}function Be(a,t){return ye(Ye(a),t)}function ye(a,t){let n={day:E,week:H,month:L,quarter:x,year:V}[t]().format.split("/").pop(),i=window.moment(a,n,!0);if(!i.isValid())return null;if(qe(n,t)&&t==="week"){let o=we(n);if(/w{1,
Enter a note or canvas to use based on <a href="https://momentjs.com/docs/#/displaying/format/" target="_blank" rel="noopener">Moment date formatting</a>.`;break;case"Random file":s.innerHTML="A random note or canvas from your Obsidian folder will be selected.";break;case"Daily Note":s.innerHTML="Your Daily Note or Periodic Daily Note will be used.";break;case"Weekly Note":case"Monthly Note":case"Yearly Note":s.innerHTML=`Your Periodic ${this.plugin.homepage.data.kind} will be used.`;break}o&&s.createDiv({text:"The plugin required for this homepage type isn't available.",attr:{class:"mod-warning"}}),lt.includes(n)?d.addText(r=>{r.setDisabled(!0)}):d.addText(r=>{new p(this.app,r.inputEl),r.setPlaceholder(se.value),r.setValue(se.value==this.plugin.homepage.data.value?"":this.plugin.homepage.data.value),r.onChange(async c=>{this.plugin.homepage.data.value=this.sanitiseNote(c)||se.value,await this.plugin.homepage.save()})}),this.addToggle("Open on startup","When launching Obsidian, open the homepage.","openOnStartup",r=>this.display()),i&&(this.elements.openOnStartup.descEl.createDiv({text:`This setting has been disabled, as it isn't compatible with Daily Notes' "Open daily note on startup" functionality. To use it, disable the Daily Notes setting.`,attr:{class:"mod-warning"}}),this.disableSetting("openOnStartup")),this.addToggle("Open when empty","When there are no tabs open, open the homepage.","openWhenEmpty"),this.addToggle("Use when opening normally","Use homepage settings when opening it normally, such as from a link or the file browser.","alwaysApply"),new h.Setting(this.containerEl).setName("Separate mobile homepage").setDesc("For mobile devices, store the homepage and its settings separately.").addToggle(r=>r.setValue(this.plugin.settings.separateMobile).onChange(async c=>{this.plugin.settings.separateMobile=c,this.plugin.homepage=this.plugin.getHomepage(),await this.plugin.saveSettings(),this.display()})),this.addHeading("Commands","commandsHeading"),this.containerEl.createDiv({cls:"nv-command-desc setting-item-description",text:"Select commands that will be executed when opening the homepage."}),this.commandBox=this.containerEl.createDiv({cls:"nv-command-box"}),this.updateCommandBox(),this.addHeading("Vault environment","vaultHeading"),this.addDropdown("Opening method","Determine how extant tabs and views are affected on startup.","openMode",U),this.addDropdown("Manual opening method","Determine how extant tabs and views are affected when opening with commands or the ribbon button.","manualOpenMode",U),this.addToggle("Auto-create","If the homepage doesn't exist, create a note with the specified name.","autoCreate"),this.addToggle("Pin","Pin the homepage when opening.","pin"),this.addToggle("Hide release notes","Never display release notes when Obsidian updates.","hideReleaseNotes"),this.addHeading("Opened view","paneHeading"),this.addDropdown("Homepage view","Choose what view to open the homepage in.","view",oe),this.addToggle("Revert view on close","When navigating away from the homepage, restore the default view.","revertView"),this.addToggle("Auto-scroll","When opening the homepage, scroll to the bottom and focus on the last line.","autoScroll"),"dataview"in this.plugin.communityPlugins&&(this.addToggle("Refresh Dataview","Always attempt to reload Dataview views when opening the homepage.","refreshDataview"),this.elements.refreshDataview.descEl.createDiv({text:"Requires Dataview auto-refresh to be enabled.",attr:{class:"mod-warning"}})),h.Platform.isMobile||new h.ButtonComponent(this.containerEl).setButtonText("Copy debug info").setClass("nv-debug-button").onClick(async()=>await this.copyDebugInfo()),(e||n==="Nothing")&&this.disableSettings("openWhenEmpty","alwaysApply","vaultHeading","openMode","manualOpenMode","autoCreate","pin"),(e||["Nothing","Graph view"].includes(n))&&this.disableSettings("paneHeading","view","revertView","autoScroll","refreshDataview"),(!this.plugin.homepage.data.openOnStartup||i)&&this.disableSetting("openMode"),ie.includes(this.plugin.homepage.data.kind)&&this.disableSetting("auto