digital-garden/.obsidian/plugins/homepage/main.js

3 lines
32 KiB
JavaScript
Raw Normal View History

2024-06-13 21:01:37 +03:00
"use strict";var Re=Object.create;var I=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty;var We=(a,t)=>()=>(t||a((t={exports:{}}).exports,t),t.exports),Ye=(a,t)=>{for(var e in t)I(a,e,{get:t[e],enumerable:!0})},pe=(a,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ve(t))!Ie.call(a,i)&&i!==e&&I(a,i,{get:()=>t[i],enumerable:!(n=Ce(t,i))||n.enumerable});return a};var Ue=(a,t,e)=>(e=a!=null?Re(_e(a)):{},pe(t||!a||!a.__esModule?I(e,"default",{value:a,enumerable:!0}):e,a)),Be=a=>pe(I({},"__esModule",{value:!0}),a);var Oe=We(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});var g=require("obsidian"),X="YYYY-MM-DD",ee="gggg-[W]ww",fe="YYYY-MM",we="YYYY-[Q]Q",ye="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||X,folder:s?.trim()||"",template:p?.trim()||""}}let{folder:e,format:n,template:i}=a.getPluginById("daily-notes")?.instance?.options||{};return{format:n||X,folder:e?.trim()||"",template:i?.trim()||""}}catch(a){console.info("No custom daily note settings found!",a)}}function L(){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||ee,folder:e.folder?.trim()||"",template:e.template?.trim()||""};let n=t||{};return{format:n.weeklyNoteFormat||ee,folder:n.weeklyNoteFolder?.trim()||"",template:n.weeklyNoteTemplate?.trim()||""}}catch(a){console.info("No custom weekly note settings found!",a)}}function H(){let a=window.app.plugins;try{let t=S("monthly")&&a.getPlugin("periodic-notes")?.settings?.monthly||{};return{format:t.format||fe,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||we,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom quarterly note settings found!",t)}}function R(){let a=window.app.plugins;try{let t=S("yearly")&&a.getPlugin("periodic-notes")?.settings?.yearly||{};return{format:t.format||ye,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom yearly note settings found!",t)}}function ve(...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 qe(a){let t=a.substring(a.lastIndexOf("/")+1);return t.lastIndexOf(".")!=-1&&(t=t.substring(0,t.lastIndexOf("."))),t}async function Ke(a){let t=a.replace(/\\/g,"/").split("/");if(t.pop(),t.length){let e=ve(...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(ve(a,t));return await Ke(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 Ne(a){return a.replace(/\[[^\]]*\]/g,"")}function je(a,t){if(t==="week"){let e=Ne(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 be(a.basename,t)}function $e(a,t){return be(qe(a),t)}function be(a,t){let n={day:E,week:L,month:H,quarter:x,year:R}[t]().format.split("/").pop(),i=window.moment(a,n,!0);if(!i.isValid())return null;if(je(n,t)&&t==="week"){let o=Ne(n);if(/w
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"}}),le.includes(n)?d.addText(r=>{r.setDisabled(!0)}):d.addText(r=>{new p(this.app,r.inputEl),r.setPlaceholder(ce.value),r.setValue(ce.value==this.plugin.homepage.data.value?"":this.plugin.homepage.data.value),r.onChange(async c=>{this.plugin.homepage.data.value=this.sanitiseNote(c)||ce.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",B),this.addDropdown("Manual opening method","Determine how extant tabs and views are affected when opening with commands or the ribbon button.","manualOpenMode",B),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",re),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"),W.includes(this.plugin.homepage.data.kind)&&this.disableSetting("autoC