Absolue-Necessite/.obsidian/plugins/homepage/main.js

4 lines
53 KiB
JavaScript
Raw Normal View History

2023-07-18 10:43:49 +00:00
"use strict";var tn=Object.create;var et=Object.defineProperty;var on=Object.getOwnPropertyDescriptor;var nn=Object.getOwnPropertyNames;var rn=Object.getPrototypeOf,an=Object.prototype.hasOwnProperty;var sn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ln=(t,e)=>{for(var o in e)et(t,o,{get:e[o],enumerable:!0})},to=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nn(e))!an.call(t,i)&&i!==o&&et(t,i,{get:()=>e[i],enumerable:!(n=on(e,i))||n.enumerable});return t};var pn=(t,e,o)=>(o=t!=null?tn(rn(t)):{},to(e||!t||!t.__esModule?et(o,"default",{value:t,enumerable:!0}):o,t)),cn=t=>to(et({},"__esModule",{value:!0}),t);var xo=sn(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});var T=require("obsidian"),yt="YYYY-MM-DD",bt="gggg-[W]ww",so="YYYY-MM",lo="YYYY-[Q]Q",po="YYYY";function Fe(t){let e=window.app.plugins.getPlugin("periodic-notes");return e&&e.settings?.[t]?.enabled}function Ce(){try{let{internalPlugins:t,plugins:e}=window.app;if(Fe("daily")){let{format:r,folder:p,template:s}=e.getPlugin("periodic-notes")?.settings?.daily||{};return{format:r||yt,folder:p?.trim()||"",template:s?.trim()||""}}let{folder:o,format:n,template:i}=t.getPluginById("daily-notes")?.instance?.options||{};return{format:n||yt,folder:o?.trim()||"",template:i?.trim()||""}}catch(t){console.info("No custom daily note settings found!",t)}}function He(){try{let t=window.app.plugins,e=t.getPlugin("calendar")?.options,o=t.getPlugin("periodic-notes")?.settings?.weekly;if(Fe("weekly"))return{format:o.format||bt,folder:o.folder?.trim()||"",template:o.template?.trim()||""};let n=e||{};return{format:n.weeklyNoteFormat||bt,folder:n.weeklyNoteFolder?.trim()||"",template:n.weeklyNoteTemplate?.trim()||""}}catch(t){console.info("No custom weekly note settings found!",t)}}function Re(){let t=window.app.plugins;try{let e=Fe("monthly")&&t.getPlugin("periodic-notes")?.settings?.monthly||{};return{format:e.format||so,folder:e.folder?.trim()||"",template:e.template?.trim()||""}}catch(e){console.info("No custom monthly note settings found!",e)}}function Ie(){let t=window.app.plugins;try{let e=Fe("quarterly")&&t.getPlugin("periodic-notes")?.settings?.quarterly||{};return{format:e.format||lo,folder:e.folder?.trim()||"",template:e.template?.trim()||""}}catch(e){console.info("No custom quarterly note settings found!",e)}}function Ve(){let t=window.app.plugins;try{let e=Fe("yearly")&&t.getPlugin("periodic-notes")?.settings?.yearly||{};return{format:e.format||po,folder:e.folder?.trim()||"",template:e.template?.trim()||""}}catch(e){console.info("No custom yearly note settings found!",e)}}function co(...t){let e=[];for(let n=0,i=t.length;n<i;n++)e=e.concat(t[n].split("/"));let o=[];for(let n=0,i=e.length;n<i;n++){let r=e[n];!r||r==="."||o.push(r)}return e[0]===""&&o.unshift(""),o.join("/")}function dn(t){let e=t.substring(t.lastIndexOf("/")+1);return e.lastIndexOf(".")!=-1&&(e=e.substring(0,e.lastIndexOf("."))),e}async function un(t){let e=t.replace(/\\/g,"/").split("/");if(e.pop(),e.length){let o=co(...e);window.app.vault.getAbstractFileByPath(o)||await window.app.vault.createFolder(o)}}async function We(t,e){e.endsWith(".md")||(e+=".md");let o=T.normalizePath(co(t,e));return await un(o),o}async function Pe(t){let{metadataCache:e,vault:o}=window.app,n=T.normalizePath(t);if(n==="/")return Promise.resolve(["",null]);try{let i=e.getFirstLinkpathDest(n,""),r=await o.cachedRead(i),p=window.app.foldManager.load(i);return[r,p]}catch(i){return console.error(`Failed to read the daily note template '${n}'`,i),new T.Notice("Failed to read the daily note template"),["",null]}}function Q(t,e="day"){let o=t.clone().startOf(e).format();return`${e}-${o}`}function uo(t){return t.replace(/\[[^\]]*\]/g,"")}function mn(t,e){if(e==="week"){let o=uo(t);return/w{1,2}/i.test(o)&&(/M{1,4}/.test(o)||/D{1,4}/.test(o))}return!1}function Oe(t,e){return mo(t.basename,e)}function fn(t,e){return mo(dn(t),e)}function mo(t,e){let n={day:Ce,week:He,month:Re,quarter:Ie,year:Ve}[e]().format.split("/").pop(),i=window.moment(t,n,!0);if(!i.isValid())return null;if(mn(n,e)&&e=
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>.<small> Surround words in <code>[brackets]</code> to include them unmodified.
<br> Currently, your specification will produce: </small>`;break;case"Random file":r.innerHTML="A random note or canvas from your Obsidian folder will be selected.";break;case"Daily Note":r.innerHTML="Your Daily Note or Periodic Daily Note will be used.";break;case"Weekly Note":case"Monthly Note":case"Yearly Note":r.innerHTML=`Your Periodic ${this.plugin.homepage.data.kind} will be used.`;break}if(i&&r.createDiv({text:"The plugin required for this homepage type isn't available.",attr:{class:"mod-warning"}}),this.plugin.homepage.data.kind=="Date-dependent file"){let a=r.lastChild.createEl("b",{attr:{class:"u-pop"}});s.addMomentFormat(l=>l.setDefaultFormat("YYYY-MM-DD").setValue(this.plugin.homepage.data.value).onChange(async c=>{this.plugin.homepage.data.value=c,await this.plugin.homepage.save()}).setSampleEl(a))}else di.includes(this.plugin.homepage.data.kind)?s.addText(a=>{a.setDisabled(!0)}):s.addText(a=>{new p(this.app,a.inputEl),a.setPlaceholder($t.value),a.setValue($t.value==this.plugin.homepage.data.value?"":this.plugin.homepage.data.value),a.onChange(async l=>{this.plugin.homepage.data.value=this.sanitiseNote(l)||$t.value,await this.plugin.homepage.save()})});this.addToggle("Open on startup","When launching Obsidian, open the homepage.","openOnStartup",a=>this.display()),n&&(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"),this.addToggle("Use ribbon icon","Show a little house on the ribbon, allowing you to quickly access the homepage.","hasRibbonIcon",a=>this.plugin.setIcon(a)),new W.Setting(this.containerEl).setName("Separate mobile homepage").setDesc("For mobile devices, store the homepage and its settings separately.").addToggle(a=>a.setValue(this.plugin.settings.separateMobile).onChange(async l=>{this.plugin.settings.separateMobile=l,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",nt),this.addDropdown("Manual opening method","Determine how extant tabs and views are affected when opening with commands or the ribbon button.","manualOpenMode",nt),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.addHeading("Opened view","paneHeading"),this.addDropdown("Homepage view","Choose what view to open the homepage in.","view",Tt),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"}})),W.Platform.isMobile||new W.ButtonComponent(this.containerEl).setButtonText("Copy debug info").setClass("nv-debug-button").onClick(async()=>await this.copyDebugInfo()),o&&this.disableSettings("openWhenEmpty","alwaysApply","vaultHeading","openMode","manualOpenMode","autoCreate","