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

3 lines
35 KiB
JavaScript
Raw Normal View History

2024-07-13 19:25:17 +03:00
"use strict";var We=Object.create;var Y=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var je=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),qe=(n,t)=>{for(var e in t)Y(n,e,{get:t[e],enumerable:!0})},me=(n,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ue(t))!Ke.call(n,i)&&i!==e&&Y(n,i,{get:()=>t[i],enumerable:!(a=Ye(t,i))||a.enumerable});return n};var ze=(n,t,e)=>(e=n!=null?We(Be(n)):{},me(t||!n||!n.__esModule?Y(e,"default",{value:n,enumerable:!0}):e,n)),$e=n=>me(Y({},"__esModule",{value:!0}),n);var xe=je(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});var g=require("obsidian"),te="YYYY-MM-DD",ae="gggg-[W]ww",Ne="YYYY-MM",be="YYYY-[Q]Q",ke="YYYY";function F(n){let t=window.app.plugins.getPlugin("periodic-notes");return t&&t.settings?.[n]?.enabled}function O(){try{let{internalPlugins:n,plugins:t}=window.app;if(F("daily")){let{format:o,folder:s,template:c}=t.getPlugin("periodic-notes")?.settings?.daily||{};return{format:o||te,folder:s?.trim()||"",template:c?.trim()||""}}let{folder:e,format:a,template:i}=n.getPluginById("daily-notes")?.instance?.options||{};return{format:a||te,folder:e?.trim()||"",template:i?.trim()||""}}catch(n){console.info("No custom daily note settings found!",n)}}function L(){try{let n=window.app.plugins,t=n.getPlugin("calendar")?.options,e=n.getPlugin("periodic-notes")?.settings?.weekly;if(F("weekly"))return{format:e.format||ae,folder:e.folder?.trim()||"",template:e.template?.trim()||""};let a=t||{};return{format:a.weeklyNoteFormat||ae,folder:a.weeklyNoteFolder?.trim()||"",template:a.weeklyNoteTemplate?.trim()||""}}catch(n){console.info("No custom weekly note settings found!",n)}}function x(){let n=window.app.plugins;try{let t=F("monthly")&&n.getPlugin("periodic-notes")?.settings?.monthly||{};return{format:t.format||Ne,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom monthly note settings found!",t)}}function H(){let n=window.app.plugins;try{let t=F("quarterly")&&n.getPlugin("periodic-notes")?.settings?.quarterly||{};return{format:t.format||be,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom quarterly note settings found!",t)}}function C(){let n=window.app.plugins;try{let t=F("yearly")&&n.getPlugin("periodic-notes")?.settings?.yearly||{};return{format:t.format||ke,folder:t.folder?.trim()||"",template:t.template?.trim()||""}}catch(t){console.info("No custom yearly note settings found!",t)}}function Te(...n){let t=[];for(let a=0,i=n.length;a<i;a++)t=t.concat(n[a].split("/"));let e=[];for(let a=0,i=t.length;a<i;a++){let o=t[a];!o||o==="."||e.push(o)}return t[0]===""&&e.unshift(""),e.join("/")}function Ge(n){let t=n.substring(n.lastIndexOf("/")+1);return t.lastIndexOf(".")!=-1&&(t=t.substring(0,t.lastIndexOf("."))),t}async function Qe(n){let t=n.replace(/\\/g,"/").split("/");if(t.pop(),t.length){let e=Te(...t);window.app.vault.getAbstractFileByPath(e)||await window.app.vault.createFolder(e)}}async function R(n,t){t.endsWith(".md")||(t+=".md");let e=g.normalizePath(Te(n,t));return await Qe(e),e}async function A(n){let{metadataCache:t,vault:e}=window.app,a=g.normalizePath(n);if(a==="/")return Promise.resolve(["",null]);try{let i=t.getFirstLinkpathDest(a,""),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 '${a}'`,i),new g.Notice("Failed to read the daily note template"),["",null]}}function T(n,t="day"){let e=n.clone().startOf(t).format();return`${t}-${e}`}function Pe(n){return n.replace(/\[[^\]]*\]/g,"")}function Je(n,t){if(t==="week"){let e=Pe(n);return/w{1,2}/i.test(e)&&(/M{1,4}/.test(e)||/D{1,4}/.test(e))}return!1}function E(n,t){return De(n.basename,t)}function Ze(n,t){return De(Ge(n),t)}function De(n,t){let a={day:O,week:L,month:x,quarter:H,year:C}[t]().format.split("/").pop(),i=window.moment(n,a,!0);if(!i.isValid())return null;if(Je(a,t)&&t==="week"){let o=Pe(a);if
${d} devices. To edit ${d} settings, use a ${d} device.`,r.settingEl.append(p)}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=new z(this),this.addHeading("Vault environment","vaultHeading"),this.addDropdown("Opening method","Determine how extant tabs and views are affected on startup.","openMode",Q),this.addDropdown("Manual opening method","Determine how extant tabs and views are affected when opening with commands or the ribbon button.","manualOpenMode",Q),this.addToggle("Pin","Pin the homepage when opening.","pin"),this.addToggle("Hide release notes","Never display release notes when Obsidian updates.","hideReleaseNotes"),this.addToggle("Auto-create","When the homepage doesn't exist, create a note with its name.","autoCreate"),this.elements.autoCreate.descEl.createDiv({text:"If this vault is synced using unofficial services, this may lead to content being overwritten.",cls:"mod-warning"}),this.addHeading("Opened view","paneHeading"),this.addDropdown("Homepage view","Choose what view to open the homepage in.","view",ue),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"}})),y.Platform.isMobile||new y.ButtonComponent(this.containerEl).setButtonText("Copy debug info").setClass("nv-debug-button").onClick(async()=>await this.copyDebugInfo()),(e||a==="Nothing")&&this.disableSettings("openWhenEmpty","alwaysApply","vaultHeading","openMode","manualOpenMode","autoCreate","pin"),(e||["Nothing","Graph view"].includes(a))&&this.disableSettings("paneHeading","view","revertView","autoScroll","refreshDataview"),(!this.plugin.homepage.data.openOnStartup||i)&&this.disableSetting("openMode"),B.includes(this.plugin.homepage.data.kind)&&this.disableSetting("autoCreate")}disableSetting(e){this.elements[e]?.settingEl.setAttribute("nv-greyed","")}disableSettings(...e){e.forEach(a=>this.disableSetting(a))}addHeading(e,a){let i=new y.Setting(this.containerEl).setHeading().setName(e);this.elements[a]=i}addDropdown(e,a,i,o,s){let c=new y.Setting(this.containerEl).setName(e).setDesc(a).addDropdown(async m=>{for(let r of Object.values(o))m.addOption(r,r);m.setValue(this.plugin.homepage.data[i]),m.onChange(async r=>{this.plugin.homepage.data[i]=r,await this.plugin.homepage.save(),s&&s(r)})});return this.elements[i]=c,c}addToggle(e,a,i,o){let s=new y.Setting(this.containerEl).setName(e).setDesc(a).addToggle(c=>c.setValue(this.plugin.homepage.data[i]).onChange(async m=>{this.plugin.homepage.data[i]=m,await this.plugin.homepage.save(),o&&o(m)}));return this.elements[i]=s,s}async copyDebugInfo(){let e=this.app.vault.config,a={...this.settings,_defaultViewMode:e.defaultViewMode||"default",_livePreview:e.livePreview!==void 0?e.livePreview:"default",_focusNewTab:e.focusNewTab!==void 0?e.focusNewTab:"default",_plugins:Object.keys(this.plugin.communityPlugins),_internalPlugins:Object.values(this.plugin.internalPlugins).flatMap(i=>i.enabled?[i.instance.id]:[]),_obsidianVersion:window.electron.ipcRenderer.sendSync("version")};await navigator.clipboard.writeText(JSON.stringify(a)),new y.Notice("Copied homepage debug information to clipboard")}};var Ve=["markdown","canvas","kanban"],wt=[...Ve,"audio","graph","image","pdf","video"],V="Main Homepage",W="Mobile Homepage",Q=(a=>(a.ReplaceAll="Replace all open notes",a.ReplaceLast="Replace last note",a.Retain="Keep open notes",a))(Q||{}),ue=(i=>(i.Default="Default view",i.Reading="Reading view",i.Source="Editing view (Source)",i.LivePreview="Editing view (Live Preview)",i))(ue||