From 984a0ab44f0344cf3109551169d4d9832d0f9d3c Mon Sep 17 00:00:00 2001 From: Olivier Date: Thu, 8 Oct 2026 16:36:47 -0400 Subject: [PATCH] release v1.8.0: reuse open tabs for periodic notes --- DOCUMENTATION.md | 9 +++++---- QA.md | 11 +++++++++++ README.md | 2 ++ main.js | 38 +++++++++++++++++++------------------- manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/main.ts | 25 ++++++++++++++++++++----- src/settings-tab.ts | 11 +++++++++++ src/settings.ts | 3 +++ 10 files changed, 75 insertions(+), 32 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 3fc22d7..888f4b5 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -53,6 +53,7 @@ Detaches all leaves of `WAYPOINT_VIEW_TYPE`. interface WaypointSettings { calendar: CalendarSettings; // week start, indicator visibility/style, daily indicator colour daily: PeriodNoteSettings; + reusePeriodicNoteTabs: boolean; // defaults to false; all periodic-note openers reuse an open tab weekly: PeriodNoteSettings; monthly: PeriodNoteSettings; quarterly: PeriodNoteSettings; @@ -132,7 +133,7 @@ The bookmark tree is stored under `waypointData.bookmarks` and rendered recursiv | `waypoint-go-to-quarterly` | Go to quarterly note | `Mod+Shift+Alt+Q` | | `waypoint-go-to-yearly` | Go to yearly note | `Mod+Shift+Alt+Y` | -All call `openPeriodNote(period, moment())` — opens or creates the current period's note. +All five commands call `openPeriodNote(period, moment())` — opening or creating the current period's note. **Periodic Notes → Use existing tabs** defaults to off. When enabled, the shared opener focuses a Markdown tab for the exact configured file path, including in another pane or window, without reopening the file or resetting its editor position. This also applies to next/previous navigation and regular calendar clicks. With no matching tab, normal note creation/opening is unchanged. Explicit open-in-new-tab actions still win; existing duplicate tabs are not closed. ### Next/Previous period (no default hotkeys) @@ -237,7 +238,7 @@ getDateSystemIndicators(dates: moment.Moment[]): Map ``` @@ -252,7 +253,7 @@ openDateSystemNote( 1. **Filename** — `splitNameFormat(system.nameFormat)`, format `before` and `after` against `date`, and for a many-per-date system join `sanitizeTitle(opts.title)` between them. Append `.md`; prepend `system.folder` when it is set. 2. **Existing note** — a `vault.getFileByPath()` hit is opened as-is, never overwritten. A date that already has notes can still gain another in a many-per-date system, because the title makes the filename unique. 3. **Missing note** — created via `createDatedNote`, then opened. -4. **Leaf** — `opts.leaf` when supplied (middle-click and Ctrl/Cmd-click pass an explicit tab leaf), otherwise `workspace.getLeaf(false)`. +4. **Leaf** — an explicit `opts.leaf` always wins (middle-click and Ctrl/Cmd-click pass a tab leaf). Otherwise, when `opts.reuseExistingLeaf` is true, scan Markdown leaves by `getViewState().state.file` so deferred tabs also match; compare the complete file path, not the basename. Await `workspace.revealLeaf(existing)` to reveal/load the tab, then call `workspace.setActiveLeaf(existing, { focus: true })` to activate it and focus its editor. Return without calling `openFile`, preserving editor position. With no matching tab, or when reuse is disabled, open in `workspace.getLeaf(false)` as before. ### Note creation (`createDatedNote`) @@ -273,7 +274,7 @@ openPeriodNote( ): Promise ``` -Single unified opener — there is no separate `openPeriodNoteInLeaf`, and since the date-systems refactor there is no separate creation path either. `openPeriodNote` synthesizes the period's `PeriodNoteSettings` into a `DateSystemSettings` (`folder`, `nameFormat`, `templateFile` and `typeProperty` carry over verbatim; a period format never contains `{title}`, so a period maps to exactly one filename) and delegates to `openDateSystemNote(system, date, { leaf })`. +Single unified opener — there is no separate `openPeriodNoteInLeaf`, and since the date-systems refactor there is no separate creation path either. `openPeriodNote` synthesizes the period's `PeriodNoteSettings` into a `DateSystemSettings` (`folder`, `nameFormat`, `templateFile` and `typeProperty` carry over verbatim; a period format never contains `{title}`, so a period maps to exactly one filename) and delegates to `openDateSystemNote(system, date, { leaf, reuseExistingLeaf: settings.reusePeriodicNoteTabs })`. All five periodic-note types therefore share the same tab-reuse policy, with an explicit `leaf` taking precedence. Filename building, the existence check, template-or-frontmatter creation and leaf selection are therefore documented once, under Date Systems above. diff --git a/QA.md b/QA.md index 45977a0..47d5bb2 100644 --- a/QA.md +++ b/QA.md @@ -58,6 +58,17 @@ - [ ] Bookmarks persist across vault reload - [ ] Move a folder containing bookmarked files to a new location → those bookmarks survive and still open the moved files +## Periodic Notes: Reuse Existing Tabs + +- [ ] An existing configuration without `reusePeriodicNoteTabs` loads with the toggle off +- [ ] Enable **Periodic Notes → Use existing tabs**, reload the plugin, and verify it stays enabled +- [ ] For each of daily, weekly, monthly, quarterly, and yearly: open the current note in another pane, run its **Go to…** command repeatedly → that tab becomes active, its editor position is preserved, and no duplicate opens +- [ ] For each type, a note with the same basename in another folder is not reused; the configured path opens or is created normally +- [ ] Regular calendar clicks and next/previous navigation focus existing periodic-note tabs when enabled +- [ ] With the toggle off, all five commands retain their original active-leaf opening behaviour +- [ ] With the toggle on, an explicit open-in-new-tab action still creates a new tab +- [ ] A deferred periodic-note tab or a periodic-note tab in a pop-out window is revealed and focused instead of duplicated + ## Calendar (Regression) - [ ] Calendar renders with correct month grid diff --git a/README.md b/README.md index b6f1ebd..2952cd7 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ Calendar, recent files, and custom bookmarks sidebar for Obsidian. | Go to yearly note | `Ctrl+Shift+Alt+Y` | | Next/Previous daily/weekly/monthly/quarterly/yearly note | — | +Under **Settings → Waypoint Sidebar → Periodic Notes**, turn on **Use existing tabs** to switch to a daily, weekly, monthly, quarterly, or yearly note's tab if it is already open. This works with the five **Go to…** commands, next/previous navigation, and regular calendar clicks. If the note is not open, it opens or is created as usual. The setting is off by default. It keeps your place in the note and leaves existing duplicate tabs alone. Choosing to open a new tab still opens a new tab. + ## Date systems Right-click any calendar day to open its **date systems** menu. The daily note always appears first; left-click behaviour is unchanged. The included defaults match this vault's common layouts: diff --git a/main.js b/main.js index 61ef0e4..5c6d0a3 100644 --- a/main.js +++ b/main.js @@ -2,26 +2,26 @@ THIS IS A GENERATED/BUNDLED FILE BY ESBUILD */ -var Q=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var ge=Object.prototype.hasOwnProperty;var fe=(p,d)=>{for(var e in d)Q(p,e,{get:d[e],enumerable:!0})},ye=(p,d,e,n)=>{if(d&&typeof d=="object"||typeof d=="function")for(let a of ue(d))!ge.call(p,a)&&a!==e&&Q(p,a,{get:()=>d[a],enumerable:!(n=he(d,a))||n.enumerable});return p};var ve=p=>ye(Q({},"__esModule",{value:!0}),p);var Fe={};fe(Fe,{default:()=>G});module.exports=ve(Fe);var f=require("obsidian");var $={name:"",folder:"",nameFormat:"YYYY-MM-DD - {title}",templateFile:"",typeProperty:"",icon:"file",indicatorColor:"#64748b"},T={calendar:{firstDayOfWeek:1,showNoteIndicators:!0,indicatorMode:"systems",dailyIndicatorColor:"#3b82f6"},daily:{folder:"periodic/daily",templateFile:"Templates/Daily note",nameFormat:"YYYY-MM-DD",typeProperty:"daily-note"},weekly:{folder:"periodic/weekly",templateFile:"Templates/Weekly note",nameFormat:"GGGG-[W]WW",typeProperty:"weekly-note"},monthly:{folder:"periodic/monthly",templateFile:"Templates/Monthly note",nameFormat:"YYYY-MM",typeProperty:"monthly-note"},quarterly:{folder:"periodic/quarterly",templateFile:"Templates/Quarterly note",nameFormat:"YYYY-[Q]Q",typeProperty:"quarterly-note"},yearly:{folder:"periodic/yearly",templateFile:"Templates/Yearly note",nameFormat:"YYYY",typeProperty:"yearly-note"},dateSystems:[{id:"journal",name:"Journal",folder:"periodic/journal",nameFormat:"YYYY-MM-DD - [Journal]",templateFile:"",typeProperty:"journal",icon:"book-open",indicatorColor:"#22c55e"},{id:"meetings",name:"Meeting",folder:"periodic/meetings",nameFormat:"YYYY-MM-DD - {title}",templateFile:"",typeProperty:"meeting",icon:"users",indicatorColor:"#a855f7"}],recentFiles:{maxItems:50,updateOn:"file-open",omittedPaths:[],omittedTags:[],filterTags:[]},display:{rowSize:26,rowSpacing:2,indentSize:16,fontSize:13,iconSize:16,calendarCellSize:32}};var v=require("obsidian");var oe="{title}";function R(p){let d=p.indexOf(oe);return d<0?{before:p,after:"",hasTitle:!1}:{before:p.slice(0,d),after:p.slice(d+oe.length),hasTitle:!0}}function U(p,d){if(!d)return!0;let e=d.endsWith("/")?d:`${d}/`;return p.startsWith(e)}function Z(p,d,e,n){return n?!d||p.length|#^[\]]/g;function le(p){return p.replace(ke,"-").replace(/\s+/g," ").trim()}function A(p){let{before:d}=R(p),e=d.replace(/\[[^\]]*\]/g,"");return/[YMDQGWEwdgeo]/.test(e)}var z=class extends v.AbstractInputSuggest{constructor(e,n){super(e,n);this.inputEl=n}getSuggestions(e){let n=e.toLowerCase();return this.app.vault.getMarkdownFiles().filter(a=>a.path.toLowerCase().includes(n)).slice(0,200)}renderSuggestion(e,n){n.setText(e.path.replace(/\.md$/,""))}selectSuggestion(e){this.setValue(e.path.replace(/\.md$/,"")),this.inputEl.trigger("input"),this.close()}},V=class extends v.PluginSettingTab{constructor(e,n,a,t){super(e,n);this.activeTab="calendar";this.plugin=n,this.settings=a,this.onSettingsChange=t}display(){let{containerEl:e}=this;e.empty();let n=e.createDiv({cls:"waypoint-settings-tabs"}),a=[{key:"calendar",label:"Calendar"},{key:"periodic",label:"Periodic Notes"},{key:"systems",label:"Date systems"},{key:"recent",label:"Recent Files"},{key:"display",label:"Display"},{key:"about",label:"About"}];for(let i of a)n.createEl("button",{cls:`waypoint-settings-tab${this.activeTab===i.key?" is-active":""}`,text:i.label}).addEventListener("click",()=>{this.activeTab=i.key,this.display()});let t=e.createDiv({cls:"waypoint-settings-content"});switch(this.activeTab){case"calendar":this.renderCalendarTab(t);break;case"periodic":this.renderPeriodicTab(t);break;case"systems":this.renderSystemsTab(t);break;case"recent":this.renderRecentTab(t);break;case"display":this.renderDisplayTab(t);break;case"about":this.renderAboutTab(t);break}}renderCalendarTab(e){new v.Setting(e).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(n=>{n.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(a=>{this.settings.calendar.firstDayOfWeek=parseInt(a,10),this.saveAndRefresh()})}),new v.Setting(e).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(n=>{n.setValue(this.settings.calendar.showNoteIndicators).onChange(a=>{this.settings.calendar.showNoteIndicators=a,this.saveAndRefresh()})}),new v.Setting(e).setName("Indicator style").setDesc("Show one neutral dot for any dated note, or one coloured dot for each configured date system.").addDropdown(n=>{n.addOption("any","Single dot").addOption("systems","Colour by note system").setValue(this.settings.calendar.indicatorMode).onChange(a=>{this.settings.calendar.indicatorMode=a,this.saveAndRefresh()})}),new v.Setting(e).setName("Daily indicator colour").setDesc("Colour for daily-note dots when using \u201CColour by note system\u201D.").addColorPicker(n=>{n.setValue(this.settings.calendar.dailyIndicatorColor).onChange(a=>{this.settings.calendar.dailyIndicatorColor=a,this.saveAndRefresh()})})}renderPeriodicTab(e){this.addPeriodNoteSettings(e,"Daily",this.settings.daily),this.addPeriodNoteSettings(e,"Weekly",this.settings.weekly),this.addPeriodNoteSettings(e,"Monthly",this.settings.monthly),this.addPeriodNoteSettings(e,"Quarterly",this.settings.quarterly),this.addPeriodNoteSettings(e,"Yearly",this.settings.yearly)}addPeriodNoteSettings(e,n,a){new v.Setting(e).setHeading().setName(n),new v.Setting(e).setName("Folder").setDesc(`Folder path for ${n.toLowerCase()} notes.`).addText(t=>{t.setPlaceholder("periodic/daily"),t.setValue(a.folder),t.onChange(i=>{a.folder=i,this.saveAndRefresh()})}),new v.Setting(e).setName("Name format").setDesc(`Date format for ${n.toLowerCase()} note filenames (moment.js format).`).addText(t=>{t.setPlaceholder("yyyy-MM-dd"),t.setValue(a.nameFormat),t.onChange(i=>{a.nameFormat=i,this.saveAndRefresh()})}),new v.Setting(e).setName("Template file").setDesc("Path to the template file. The .md extension is optional.").addText(t=>{t.setPlaceholder("Templates/Daily note"),t.setValue(a.templateFile),new z(this.app,t.inputEl),t.onChange(i=>{a.templateFile=i,this.saveAndRefresh()})}),new v.Setting(e).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(t=>{t.setPlaceholder("daily-note"),t.setValue(a.typeProperty),t.onChange(i=>{a.typeProperty=i,this.saveAndRefresh()})})}renderSystemsTab(e){let n=new DocumentFragment;n.createDiv({text:"A date system is a folder of notes whose filenames start with a date. Each one appears in the calendar's right-click menu for that day."}),n.createDiv({text:"The daily note is configured under Periodic Notes and always comes first in that menu."}),n.createDiv({text:"Name format is a moment.js format. Literal words need bracket escaping, e.g. YYYY-MM-DD - [Journal]."}),n.createDiv({text:"Include {title} for systems that hold many notes per date, such as meetings: the text before the token finds the existing notes, and the token marks where a typed title goes. Without it, a date has exactly one note."}),new v.Setting(e).setHeading().setName("Date systems").setDesc(n),this.settings.dateSystems.forEach((a,t,i)=>{new v.Setting(e).setHeading().setName(a.name||"Untitled system").addExtraButton(s=>{s.setIcon("arrow-up").setTooltip("Move up").setDisabled(t===0).onClick(async()=>{if(t===0)return;let r=i[t-1];i[t-1]=i[t],i[t]=r,await this.saveAndRefresh(),this.display()})}).addExtraButton(s=>{s.setIcon("arrow-down").setTooltip("Move down").setDisabled(t===i.length-1).onClick(async()=>{if(t===i.length-1)return;let r=i[t+1];i[t+1]=i[t],i[t]=r,await this.saveAndRefresh(),this.display()})}).addExtraButton(s=>{s.setIcon("trash").setTooltip("Delete this date system").onClick(async()=>{i.splice(t,1),await this.saveAndRefresh(),this.display()})}),this.addSystemTextSetting(e,"Name","Label shown in the calendar right-click menu.",a,"name","Journal"),this.addSystemTextSetting(e,"Folder","Folder these notes live in.",a,"folder","periodic/journal");let o=this.addSystemTextSetting(e,"Name format","Filename format (moment.js format). Include {title} for many notes per date.",a,"nameFormat","YYYY-MM-DD - {title}");a.nameFormat&&!A(a.nameFormat)&&o.descEl.createDiv({cls:"waypoint-settings-warning",text:"This name format has no date placeholder, so it will never match or create dated notes."}),this.addSystemTextSetting(e,"Template file","Path to the template file. The .md extension is optional.",a,"templateFile","resources/template/journal",!0),this.addSystemTextSetting(e,"Type property","Fallback value for the 'type' frontmatter property, used when no template is found.",a,"typeProperty","journal-note"),this.addSystemTextSetting(e,"Icon","Lucide icon name for the menu item. Browse names at lucide.dev.",a,"icon","book-open"),new v.Setting(e).setName("Indicator colour").setDesc("Colour for this system\u2019s dot when using \u201CColour by note system\u201D.").addColorPicker(s=>{s.setValue(a.indicatorColor).onChange(r=>{a.indicatorColor=r,this.saveAndRefresh()})})}),new v.Setting(e).addButton(a=>a.setButtonText("Add date system").setCta().onClick(async()=>{this.settings.dateSystems.push(Object.assign({id:`ds-${Date.now()}-${Math.random().toString(36).slice(2,6)}`},$)),await this.saveAndRefresh(),this.display()}))}addSystemTextSetting(e,n,a,t,i,o,s){return new v.Setting(e).setName(n).setDesc(a).addText(r=>{r.setPlaceholder(o),r.setValue(t[i]),s&&new z(this.app,r.inputEl),r.onChange(c=>{t[i]=c,this.saveAndRefresh()})})}renderRecentTab(e){new v.Setting(e).setName("Max items").setDesc("Maximum number of recent files to track.").addText(i=>{i.inputEl.setAttr("type","number"),i.inputEl.setAttr("placeholder","50"),i.setValue(String(this.settings.recentFiles.maxItems)),i.inputEl.onblur=()=>{let o=parseInt(i.getValue(),10);!isNaN(o)&&o>0&&(this.settings.recentFiles.maxItems=o,this.saveAndRefresh())}}),new v.Setting(e).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(i=>{i.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(o=>{this.settings.recentFiles.updateOn=o,this.saveAndRefresh()})});let n=new DocumentFragment;n.appendText("Regex patterns for paths to exclude. One per line."),new v.Setting(e).setName("Omitted paths").setDesc(n).addTextArea(i=>{i.inputEl.setAttr("rows",4),i.setPlaceholder(`^archives/ -\\.png$`),i.setValue(this.settings.recentFiles.omittedPaths.join(` -`)),i.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=i.getValue().split(` -`).filter(o=>o.trim()),this.saveAndRefresh()}});let a=new DocumentFragment;a.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new v.Setting(e).setName("Omitted tags").setDesc(a).addTextArea(i=>{i.inputEl.setAttr("rows",4),i.setPlaceholder(`ignore -archive`),i.setValue(this.settings.recentFiles.omittedTags.join(` -`)),i.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=i.getValue().split(` -`).filter(o=>o.trim()),this.saveAndRefresh()}});let t=new DocumentFragment;t.appendText("Tags to show as filter pills above the file list. One per line. Leave empty to auto-detect from frontmatter `type` property."),new v.Setting(e).setName("Filter tags").setDesc(t).addTextArea(i=>{i.inputEl.setAttr("rows",4),i.setPlaceholder(`meeting +var Q=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var ge=Object.prototype.hasOwnProperty;var fe=(p,d)=>{for(var e in d)Q(p,e,{get:d[e],enumerable:!0})},ye=(p,d,e,n)=>{if(d&&typeof d=="object"||typeof d=="function")for(let i of ue(d))!ge.call(p,i)&&i!==e&&Q(p,i,{get:()=>d[i],enumerable:!(n=he(d,i))||n.enumerable});return p};var ve=p=>ye(Q({},"__esModule",{value:!0}),p);var Fe={};fe(Fe,{default:()=>G});module.exports=ve(Fe);var f=require("obsidian");var $={name:"",folder:"",nameFormat:"YYYY-MM-DD - {title}",templateFile:"",typeProperty:"",icon:"file",indicatorColor:"#64748b"},T={calendar:{firstDayOfWeek:1,showNoteIndicators:!0,indicatorMode:"systems",dailyIndicatorColor:"#3b82f6"},daily:{folder:"periodic/daily",templateFile:"Templates/Daily note",nameFormat:"YYYY-MM-DD",typeProperty:"daily-note"},reusePeriodicNoteTabs:!1,weekly:{folder:"periodic/weekly",templateFile:"Templates/Weekly note",nameFormat:"GGGG-[W]WW",typeProperty:"weekly-note"},monthly:{folder:"periodic/monthly",templateFile:"Templates/Monthly note",nameFormat:"YYYY-MM",typeProperty:"monthly-note"},quarterly:{folder:"periodic/quarterly",templateFile:"Templates/Quarterly note",nameFormat:"YYYY-[Q]Q",typeProperty:"quarterly-note"},yearly:{folder:"periodic/yearly",templateFile:"Templates/Yearly note",nameFormat:"YYYY",typeProperty:"yearly-note"},dateSystems:[{id:"journal",name:"Journal",folder:"periodic/journal",nameFormat:"YYYY-MM-DD - [Journal]",templateFile:"",typeProperty:"journal",icon:"book-open",indicatorColor:"#22c55e"},{id:"meetings",name:"Meeting",folder:"periodic/meetings",nameFormat:"YYYY-MM-DD - {title}",templateFile:"",typeProperty:"meeting",icon:"users",indicatorColor:"#a855f7"}],recentFiles:{maxItems:50,updateOn:"file-open",omittedPaths:[],omittedTags:[],filterTags:[]},display:{rowSize:26,rowSpacing:2,indentSize:16,fontSize:13,iconSize:16,calendarCellSize:32}};var y=require("obsidian");var oe="{title}";function R(p){let d=p.indexOf(oe);return d<0?{before:p,after:"",hasTitle:!1}:{before:p.slice(0,d),after:p.slice(d+oe.length),hasTitle:!0}}function U(p,d){if(!d)return!0;let e=d.endsWith("/")?d:`${d}/`;return p.startsWith(e)}function Z(p,d,e,n){return n?!d||p.length|#^[\]]/g;function le(p){return p.replace(ke,"-").replace(/\s+/g," ").trim()}function A(p){let{before:d}=R(p),e=d.replace(/\[[^\]]*\]/g,"");return/[YMDQGWEwdgeo]/.test(e)}var z=class extends y.AbstractInputSuggest{constructor(e,n){super(e,n);this.inputEl=n}getSuggestions(e){let n=e.toLowerCase();return this.app.vault.getMarkdownFiles().filter(i=>i.path.toLowerCase().includes(n)).slice(0,200)}renderSuggestion(e,n){n.setText(e.path.replace(/\.md$/,""))}selectSuggestion(e){this.setValue(e.path.replace(/\.md$/,"")),this.inputEl.trigger("input"),this.close()}},V=class extends y.PluginSettingTab{constructor(e,n,i,t){super(e,n);this.activeTab="calendar";this.plugin=n,this.settings=i,this.onSettingsChange=t}display(){let{containerEl:e}=this;e.empty();let n=e.createDiv({cls:"waypoint-settings-tabs"}),i=[{key:"calendar",label:"Calendar"},{key:"periodic",label:"Periodic Notes"},{key:"systems",label:"Date systems"},{key:"recent",label:"Recent Files"},{key:"display",label:"Display"},{key:"about",label:"About"}];for(let a of i)n.createEl("button",{cls:`waypoint-settings-tab${this.activeTab===a.key?" is-active":""}`,text:a.label}).addEventListener("click",()=>{this.activeTab=a.key,this.display()});let t=e.createDiv({cls:"waypoint-settings-content"});switch(this.activeTab){case"calendar":this.renderCalendarTab(t);break;case"periodic":this.renderPeriodicTab(t);break;case"systems":this.renderSystemsTab(t);break;case"recent":this.renderRecentTab(t);break;case"display":this.renderDisplayTab(t);break;case"about":this.renderAboutTab(t);break}}renderCalendarTab(e){new y.Setting(e).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(n=>{n.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(i=>{this.settings.calendar.firstDayOfWeek=parseInt(i,10),this.saveAndRefresh()})}),new y.Setting(e).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(n=>{n.setValue(this.settings.calendar.showNoteIndicators).onChange(i=>{this.settings.calendar.showNoteIndicators=i,this.saveAndRefresh()})}),new y.Setting(e).setName("Indicator style").setDesc("Show one neutral dot for any dated note, or one coloured dot for each configured date system.").addDropdown(n=>{n.addOption("any","Single dot").addOption("systems","Colour by note system").setValue(this.settings.calendar.indicatorMode).onChange(i=>{this.settings.calendar.indicatorMode=i,this.saveAndRefresh()})}),new y.Setting(e).setName("Daily indicator colour").setDesc("Colour for daily-note dots when using \u201CColour by note system\u201D.").addColorPicker(n=>{n.setValue(this.settings.calendar.dailyIndicatorColor).onChange(i=>{this.settings.calendar.dailyIndicatorColor=i,this.saveAndRefresh()})})}renderPeriodicTab(e){new y.Setting(e).setName("Use existing tabs").setDesc("If a periodic note is already open, switch to its tab instead of opening it again.").addToggle(n=>{n.setValue(this.settings.reusePeriodicNoteTabs).onChange(i=>{this.settings.reusePeriodicNoteTabs=i,this.saveAndRefresh()})}),this.addPeriodNoteSettings(e,"Daily",this.settings.daily),this.addPeriodNoteSettings(e,"Weekly",this.settings.weekly),this.addPeriodNoteSettings(e,"Monthly",this.settings.monthly),this.addPeriodNoteSettings(e,"Quarterly",this.settings.quarterly),this.addPeriodNoteSettings(e,"Yearly",this.settings.yearly)}addPeriodNoteSettings(e,n,i){new y.Setting(e).setHeading().setName(n),new y.Setting(e).setName("Folder").setDesc(`Folder path for ${n.toLowerCase()} notes.`).addText(t=>{t.setPlaceholder("periodic/daily"),t.setValue(i.folder),t.onChange(a=>{i.folder=a,this.saveAndRefresh()})}),new y.Setting(e).setName("Name format").setDesc(`Date format for ${n.toLowerCase()} note filenames (moment.js format).`).addText(t=>{t.setPlaceholder("yyyy-MM-dd"),t.setValue(i.nameFormat),t.onChange(a=>{i.nameFormat=a,this.saveAndRefresh()})}),new y.Setting(e).setName("Template file").setDesc("Path to the template file. The .md extension is optional.").addText(t=>{t.setPlaceholder("Templates/Daily note"),t.setValue(i.templateFile),new z(this.app,t.inputEl),t.onChange(a=>{i.templateFile=a,this.saveAndRefresh()})}),new y.Setting(e).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(t=>{t.setPlaceholder("daily-note"),t.setValue(i.typeProperty),t.onChange(a=>{i.typeProperty=a,this.saveAndRefresh()})})}renderSystemsTab(e){let n=new DocumentFragment;n.createDiv({text:"A date system is a folder of notes whose filenames start with a date. Each one appears in the calendar's right-click menu for that day."}),n.createDiv({text:"The daily note is configured under Periodic Notes and always comes first in that menu."}),n.createDiv({text:"Name format is a moment.js format. Literal words need bracket escaping, e.g. YYYY-MM-DD - [Journal]."}),n.createDiv({text:"Include {title} for systems that hold many notes per date, such as meetings: the text before the token finds the existing notes, and the token marks where a typed title goes. Without it, a date has exactly one note."}),new y.Setting(e).setHeading().setName("Date systems").setDesc(n),this.settings.dateSystems.forEach((i,t,a)=>{new y.Setting(e).setHeading().setName(i.name||"Untitled system").addExtraButton(s=>{s.setIcon("arrow-up").setTooltip("Move up").setDisabled(t===0).onClick(async()=>{if(t===0)return;let r=a[t-1];a[t-1]=a[t],a[t]=r,await this.saveAndRefresh(),this.display()})}).addExtraButton(s=>{s.setIcon("arrow-down").setTooltip("Move down").setDisabled(t===a.length-1).onClick(async()=>{if(t===a.length-1)return;let r=a[t+1];a[t+1]=a[t],a[t]=r,await this.saveAndRefresh(),this.display()})}).addExtraButton(s=>{s.setIcon("trash").setTooltip("Delete this date system").onClick(async()=>{a.splice(t,1),await this.saveAndRefresh(),this.display()})}),this.addSystemTextSetting(e,"Name","Label shown in the calendar right-click menu.",i,"name","Journal"),this.addSystemTextSetting(e,"Folder","Folder these notes live in.",i,"folder","periodic/journal");let o=this.addSystemTextSetting(e,"Name format","Filename format (moment.js format). Include {title} for many notes per date.",i,"nameFormat","YYYY-MM-DD - {title}");i.nameFormat&&!A(i.nameFormat)&&o.descEl.createDiv({cls:"waypoint-settings-warning",text:"This name format has no date placeholder, so it will never match or create dated notes."}),this.addSystemTextSetting(e,"Template file","Path to the template file. The .md extension is optional.",i,"templateFile","resources/template/journal",!0),this.addSystemTextSetting(e,"Type property","Fallback value for the 'type' frontmatter property, used when no template is found.",i,"typeProperty","journal-note"),this.addSystemTextSetting(e,"Icon","Lucide icon name for the menu item. Browse names at lucide.dev.",i,"icon","book-open"),new y.Setting(e).setName("Indicator colour").setDesc("Colour for this system\u2019s dot when using \u201CColour by note system\u201D.").addColorPicker(s=>{s.setValue(i.indicatorColor).onChange(r=>{i.indicatorColor=r,this.saveAndRefresh()})})}),new y.Setting(e).addButton(i=>i.setButtonText("Add date system").setCta().onClick(async()=>{this.settings.dateSystems.push(Object.assign({id:`ds-${Date.now()}-${Math.random().toString(36).slice(2,6)}`},$)),await this.saveAndRefresh(),this.display()}))}addSystemTextSetting(e,n,i,t,a,o,s){return new y.Setting(e).setName(n).setDesc(i).addText(r=>{r.setPlaceholder(o),r.setValue(t[a]),s&&new z(this.app,r.inputEl),r.onChange(c=>{t[a]=c,this.saveAndRefresh()})})}renderRecentTab(e){new y.Setting(e).setName("Max items").setDesc("Maximum number of recent files to track.").addText(a=>{a.inputEl.setAttr("type","number"),a.inputEl.setAttr("placeholder","50"),a.setValue(String(this.settings.recentFiles.maxItems)),a.inputEl.onblur=()=>{let o=parseInt(a.getValue(),10);!isNaN(o)&&o>0&&(this.settings.recentFiles.maxItems=o,this.saveAndRefresh())}}),new y.Setting(e).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(a=>{a.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(o=>{this.settings.recentFiles.updateOn=o,this.saveAndRefresh()})});let n=new DocumentFragment;n.appendText("Regex patterns for paths to exclude. One per line."),new y.Setting(e).setName("Omitted paths").setDesc(n).addTextArea(a=>{a.inputEl.setAttr("rows",4),a.setPlaceholder(`^archives/ +\\.png$`),a.setValue(this.settings.recentFiles.omittedPaths.join(` +`)),a.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=a.getValue().split(` +`).filter(o=>o.trim()),this.saveAndRefresh()}});let i=new DocumentFragment;i.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new y.Setting(e).setName("Omitted tags").setDesc(i).addTextArea(a=>{a.inputEl.setAttr("rows",4),a.setPlaceholder(`ignore +archive`),a.setValue(this.settings.recentFiles.omittedTags.join(` +`)),a.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=a.getValue().split(` +`).filter(o=>o.trim()),this.saveAndRefresh()}});let t=new DocumentFragment;t.appendText("Tags to show as filter pills above the file list. One per line. Leave empty to auto-detect from frontmatter `type` property."),new y.Setting(e).setName("Filter tags").setDesc(t).addTextArea(a=>{a.inputEl.setAttr("rows",4),a.setPlaceholder(`meeting person -project`),i.setValue(this.settings.recentFiles.filterTags.join(` -`)),i.inputEl.onblur=()=>{this.settings.recentFiles.filterTags=i.getValue().split(` -`).filter(o=>o.trim()),this.saveAndRefresh()}})}renderDisplayTab(e){new v.Setting(e).setHeading().setName("Bookmarks"),this.addSliderSetting(e,"Row size","Height of bookmark items.",this.settings.display,"rowSize",18,40,1,"px"),this.addSliderSetting(e,"Row spacing","Gap between bookmark items.",this.settings.display,"rowSpacing",0,12,1,"px"),this.addSliderSetting(e,"Indent size","Indent per nesting depth.",this.settings.display,"indentSize",8,32,2,"px"),this.addSliderSetting(e,"Font size","Label font size.",this.settings.display,"fontSize",10,18,1,"px"),this.addSliderSetting(e,"Icon size","Bookmark icon size.",this.settings.display,"iconSize",12,24,1,"px"),new v.Setting(e).setHeading().setName("Calendar"),this.addSliderSetting(e,"Cell size","Height of calendar day cells.",this.settings.display,"calendarCellSize",20,48,2,"px"),new v.Setting(e).addButton(n=>n.setButtonText("Reset to defaults").onClick(()=>{this.settings.display={...T.display},this.saveAndRefresh(),this.display()}))}addSliderSetting(e,n,a,t,i,o,s,r,c){let l=new v.Setting(e).setName(n).setDesc(`${a} (${t[i]}${c})`);l.addSlider(h=>{h.setLimits(o,s,r).setValue(t[i]).setDynamicTooltip().onChange(u=>{t[i]=u,l.setDesc(`${a} (${u}${c})`),this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveSettings(),this.onSettingsChange()}renderAboutTab(e){let n=this.plugin.manifest.version,a=e.createDiv();a.style.display="flex",a.style.alignItems="center",a.style.gap="12px",a.style.marginBottom="16px";let t=a.createDiv();t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.width="48px",t.style.height="48px",t.style.borderRadius="12px",t.style.background="var(--interactive-accent)",t.style.color="var(--text-on-accent)",t.style.fontSize="24px",(0,v.setIcon)(t,"compass");let i=a.createDiv(),o=i.createEl("h2",{text:"Waypoint Sidebar"});o.style.margin="0",o.style.lineHeight="1.2";let s=i.createDiv({text:`v${n}`});s.style.color="var(--text-muted)",s.style.fontSize="var(--font-ui-small)";let r=e.createDiv();r.style.marginBottom="20px",r.style.lineHeight="1.6",r.style.color="var(--text-normal)",r.innerHTML=["

Waypoint is a sidebar plugin that brings three essential panels into one view:

",'
    ',"
  • Calendar \u2014 a monthly grid for your periodic notes (daily, weekly, monthly, quarterly, yearly). Click any day, week, or month to open or create the corresponding note.
  • ","
  • Recent Files \u2014 a list of recently opened files with type filtering, drag-and-drop, and right-click actions.
  • ","
  • Bookmarks \u2014 custom bookmarks with icons, groups, nesting, and drag-and-drop reordering. Separate from Obsidian's native bookmarks.
  • ","
",'

Made by Olivier. Licensed under MIT.

'].join(` -`)}};var m=require("obsidian");var C=require("obsidian");function ce(p,d,e){let n=(0,C.moment)({year:p,month:d,day:1}),a=(0,C.moment)(n).endOf("month"),t=(0,C.moment)(n).subtract((n.day()-e+7)%7,"days"),i=(0,C.moment)().startOf("day"),o=[],s=(0,C.moment)(t);for(;s.isBefore(a)||s.month()===d;){let r=[];for(let c=0;c<7;c++)r.push({date:(0,C.moment)(s),dayOfMonth:s.date(),isToday:s.isSame(i,"day"),isCurrentMonth:s.month()===d,isoWeekNumber:s.isoWeek()}),s.add(1,"day");if(o.push({weekNumber:r[0].isoWeekNumber,days:r}),o.length>=6)break}return o}var E="waypoint-view";function we(p){return p.dragManager}var W=class extends m.ItemView{constructor(e,n){super(e);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view");let e=this.plugin.settings.display;this.contentEl.style.setProperty("--wp-row-size",e.rowSize+"px"),this.contentEl.style.setProperty("--wp-row-spacing",e.rowSpacing+"px"),this.contentEl.style.setProperty("--wp-indent-size",e.indentSize+"px"),this.contentEl.style.setProperty("--wp-font-size",e.fontSize+"px"),this.contentEl.style.setProperty("--wp-icon-size",e.iconSize+"px"),this.contentEl.style.setProperty("--wp-cal-cell-size",e.calendarCellSize+"px"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,m.moment)().month();this.currentDisplayYear=(0,m.moment)().year();this.dragId=null;this.dropZones=new WeakMap;this.recentFilesFilter=null;this.plugin=n}getViewType(){return E}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let n=this.contentEl.createDiv({cls:"waypoint-section"}).createDiv({cls:"waypoint-calendar"}),a=(0,m.moment)(),t=(0,m.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),i=n.createDiv({cls:"waypoint-calendar-top"}),o=i.createDiv({cls:"waypoint-calendar-breadcrumb"}),s=t.format("[Q]Q"),r=o.createSpan({cls:"waypoint-clickable",text:s});r.addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",t)}),r.addEventListener("mousedown",D=>{D.button===1&&(D.preventDefault(),this.plugin.openPeriodNote("quarter",t,this.app.workspace.getLeaf("tab")))});let c=t.format("MMMM"),l=o.createSpan({cls:"waypoint-clickable",text:c});l.addEventListener("click",()=>{this.plugin.openPeriodNote("month",t)}),l.addEventListener("mousedown",D=>{D.button===1&&(D.preventDefault(),this.plugin.openPeriodNote("month",t,this.app.workspace.getLeaf("tab")))});let h=t.format("YYYY"),u=o.createSpan({cls:"waypoint-clickable",text:h});u.addEventListener("click",()=>{this.plugin.openPeriodNote("year",t)}),u.addEventListener("mousedown",D=>{D.button===1&&(D.preventDefault(),this.plugin.openPeriodNote("year",t,this.app.workspace.getLeaf("tab")))});let g=i.createDiv({cls:"waypoint-calendar-today-group"}),S=g.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,m.setIcon)(S,"chevron-left"),S.addEventListener("click",()=>this.navigateMonth(-1)),g.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,m.moment)().month(),this.currentDisplayYear=(0,m.moment)().year(),this.redraw()});let w=g.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,m.setIcon)(w,"chevron-right"),w.addEventListener("click",()=>this.navigateMonth(1));let b=n.createEl("table"),y=b.createEl("thead").createEl("tr");y.createEl("th",{text:""});let L=["sun","mon","tue","wed","thu","fri","sat"],K=this.plugin.settings.calendar.firstDayOfWeek;for(let D=0;D<7;D++){let N=(K+D)%7;y.createEl("th",{text:L[N]})}let P=b.createEl("tbody"),te=ce(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek),_=this.plugin.settings.calendar.showNoteIndicators&&this.plugin.settings.calendar.indicatorMode==="systems"?this.plugin.getDateSystemIndicators(te.reduce((D,N)=>D.concat(N.days.map(Y=>Y.date)),[])):null;for(let D of te){let N=P.createEl("tr"),Y=N.createEl("td",{cls:"waypoint-weeknum"});Y.setText(String(D.weekNumber));let ie=D.days[0].date;Y.addEventListener("click",()=>{this.plugin.openPeriodNote("week",ie)}),Y.addEventListener("mousedown",x=>{x.button===1&&(x.preventDefault(),this.plugin.openPeriodNote("week",ie,this.app.workspace.getLeaf("tab")))});for(let x of D.days){let I=N.createEl("td",{cls:"waypoint-day"});if(I.setText(String(x.dayOfMonth)),x.isCurrentMonth||I.addClass("other-month"),x.isToday&&I.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let M=x.date.format("YYYY-MM-DD");if(this.plugin.settings.calendar.indicatorMode==="any")this.plugin.hasNoteForDate(M)&&I.addClass("has-note");else{let ne=(_==null?void 0:_.get(M))||[];if(ne.length>0){let me=I.createDiv({cls:"waypoint-day-indicators"});for(let ae of ne){let se=me.createSpan({cls:"waypoint-day-indicator"});se.style.setProperty("--waypoint-indicator-color",ae.color),(0,m.setTooltip)(se,ae.name)}}}}I.addEventListener("click",()=>{this.plugin.openPeriodNote("day",x.date)}),I.addEventListener("mousedown",M=>{M.button===1&&(M.preventDefault(),this.plugin.openPeriodNote("day",x.date,this.app.workspace.getLeaf("tab")))}),I.addEventListener("contextmenu",M=>{M.preventDefault(),M.stopPropagation(),this.showDayContextMenu(M,x.date)})}}}navigateMonth(e){let n=(0,m.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(e,"month");this.currentDisplayMonth=n.month(),this.currentDisplayYear=n.year(),this.redraw()}showDayContextMenu(e,n){let a=new m.Menu;a.addItem(t=>t.setTitle(n.format("dddd, MMMM D, YYYY")).setIsLabel(!0));for(let t of this.plugin.findDateSystemNotes(n)){let i=t.multiple||t.notes.length===0;if(t.notes.length+(i?1:0)===0)continue;a.addSeparator();for(let s of t.notes)a.addItem(r=>r.setTitle(s.label).setIcon(t.system.icon).onClick(c=>this.focusFile(s.file,m.Keymap.isModEvent(c))));if(!i)continue;let o=t.system.name.toLowerCase();a.addItem(s=>s.setTitle(t.multiple?`New ${o} note\u2026`:`New ${o} note`).setIcon("plus").onClick(r=>this.createDateSystemNote(t,n,m.Keymap.isModEvent(r))))}a.showAtPosition({x:e.clientX,y:e.clientY})}createDateSystemNote(e,n,a){if(!e.multiple){this.plugin.openDateSystemNote(e.system,n,{leaf:a?this.app.workspace.getLeaf(a):void 0});return}let t=e.system.name;new q(this.app,{title:`New ${t.toLowerCase()} note`,placeholder:`${t} with\u2026`,cta:"Create"},i=>{this.plugin.openDateSystemNote(e.system,n,{title:i,leaf:a?this.app.workspace.getLeaf(a):void 0})}).open()}renderRecentFiles(){var r,c;let e=this.contentEl.createDiv({cls:"waypoint-section waypoint-recent-files"});if(e.createDiv({cls:"waypoint-section-header",text:"Recent Files"}),this.plugin.recentFiles.length===0){e.createDiv({cls:"nav-file",text:"No recent files"});return}let n=this.plugin.settings.recentFiles.filterTags||[],a={};if(n.length>0){for(let l of n)a[l]=0;for(let l of this.plugin.recentFiles){let h=this.app.vault.getAbstractFileByPath(l.path);if(h instanceof m.TFile){let u=this.app.metadataCache.getFileCache(h),g=(r=u==null?void 0:u.frontmatter)==null?void 0:r.type;g&&typeof g=="string"&&a.hasOwnProperty(g)&&a[g]++}}}else for(let l of this.plugin.recentFiles){let h=this.app.vault.getAbstractFileByPath(l.path);if(h instanceof m.TFile){let u=this.app.metadataCache.getFileCache(h),g=(c=u==null?void 0:u.frontmatter)==null?void 0:c.type;g&&typeof g=="string"&&(a[g]=(a[g]||0)+1)}}if(Object.keys(a).length>0){let l=e.createDiv({cls:"waypoint-recent-filter"});l.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter?"":" is-active"}`,text:"all"}).addEventListener("click",()=>{this.recentFilesFilter=null,this.redraw()});let u=n.length>0?Object.entries(a):Object.entries(a).sort((g,S)=>S[1]-g[1]);for(let[g,S]of u){let F=l.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter===g?" is-active":""}`});F.setText(`${g} ${S}`),F.addEventListener("click",()=>{this.recentFilesFilter=this.recentFilesFilter===g?null:g,this.redraw()})}}let t=this.plugin.recentFiles;this.recentFilesFilter&&(t=this.plugin.recentFiles.filter(l=>{var u;let h=this.app.vault.getAbstractFileByPath(l.path);if(h instanceof m.TFile){let g=this.app.metadataCache.getFileCache(h);return((u=g==null?void 0:g.frontmatter)==null?void 0:u.type)===this.recentFilesFilter}return!1}));let i=this.app.workspace.getActiveFile(),o=e.createDiv({cls:"nav-folder mod-root"}),s=o.createDiv({cls:"nav-folder-children"});for(let l of t){let h=s.createDiv({cls:"tree-item nav-file"}),u=h.createDiv({cls:"tree-item-self is-clickable nav-file-title"});u.createDiv({cls:"tree-item-inner nav-file-title-content"}).setText(l.basename);let S=u.createDiv({cls:"tree-item-spacer"}),F=u.createDiv({cls:"waypoint-recent-remove"});(0,m.setIcon)(F,"x"),F.addEventListener("click",w=>{w.stopPropagation(),this.plugin.recentFiles=this.plugin.recentFiles.filter(b=>b.path!==l.path),this.plugin.persistRecentFiles(),this.redraw()}),(0,m.setTooltip)(h,l.path),i&&l.path===i.path&&u.addClass("is-active"),u.setAttr("draggable","true"),u.addEventListener("dragstart",w=>{let b=this.app.metadataCache.getFirstLinkpathDest(l.path,"");if(b){let k=we(this.app),y=k.dragFile(w,b);k.onDragStart(w,y)}}),u.addEventListener("mouseover",w=>{this.app.workspace.trigger("hover-link",{event:w,source:E,hoverParent:o,targetEl:h,linktext:l.path})}),u.addEventListener("contextmenu",w=>{let b=new m.Menu;b.addItem(y=>y.setSection("action").setTitle("Open in new tab").setIcon("file-plus").onClick(()=>this.focusFile(l,"tab"))),b.addItem(y=>y.setSection("action").setTitle("Add to bookmarks").setIcon("bookmark").onClick(()=>{this.plugin.addBookmark(l.path,l.basename,"file"),new m.Notice(`Bookmarked: ${l.basename}`)}));let k=this.app.vault.getAbstractFileByPath(l.path);k&&this.app.workspace.trigger("file-menu",b,k,"link-context-menu"),b.showAtPosition({x:w.clientX,y:w.clientY})}),u.addEventListener("click",w=>{let b=m.Keymap.isModEvent(w);this.focusFile(l,b)}),u.addEventListener("mousedown",w=>{w.button===1&&(w.preventDefault(),this.focusFile(l,"tab"))})}}focusFile(e,n){let a=this.app.vault.getFiles().find(t=>t.path===e.path);a?this.app.workspace.getLeaf(n).openFile(a):(new m.Notice("Cannot find file"),this.plugin.recentFiles=this.plugin.recentFiles.filter(t=>t.path!==e.path),this.plugin.persistRecentFiles(),this.redraw())}renderFavorites(){let e=this.contentEl.createDiv({cls:"waypoint-section waypoint-favorites"}),n=e.createDiv({cls:"waypoint-section-header"});n.setText("Waypoint Bookmarks");let a=n.createEl("button",{cls:"waypoint-header-more"});if((0,m.setIcon)(a,"more-horizontal"),(0,m.setTooltip)(a,"Add bookmark"),a.addEventListener("click",t=>{let i=new m.Menu;i.addItem(o=>{o.setTitle("Add current file").setIcon("file-plus").onClick(()=>{let s=this.app.workspace.getActiveFile();s&&this.plugin.addBookmark(s.path,s.basename,"file")})}),i.addItem(o=>{o.setTitle("Add as parent note").setIcon("folder-plus").onClick(()=>{let s=this.app.workspace.getActiveFile();if(!s)return;let r=this.plugin.addBookmark(s.path,s.basename,"group","");r.filePath=s.path,this.plugin.saveWaypointData(),this.redraw()})}),i.addItem(o=>{o.setTitle("New group").setIcon("folder-plus").onClick(()=>{this.plugin.addBookmark("","New Group","group","")})}),i.addSeparator(),i.addItem(o=>{o.setTitle("Add separator").setIcon("minus").onClick(()=>{this.plugin.addBookmark("","","separator")})}),i.addItem(o=>{o.setTitle("Add spacer").setIcon("space").onClick(()=>{this.plugin.addBookmark("","","spacer")})}),i.showAtPosition({x:t.clientX,y:t.clientY})}),this.plugin.waypointData.bookmarks.length===0){e.createDiv({cls:"waypoint-bookmark-item",text:"No bookmarks"});return}this.renderBookmarkList(e,this.plugin.waypointData.bookmarks,0)}renderBookmarkList(e,n,a){for(let t=0;t{c.stopPropagation(),c.preventDefault(),this.showBookmarkContextMenu(c,i)});continue}if(i.type==="spacer"){let r=e.createDiv({cls:"waypoint-bookmark-item waypoint-bookmark-spacer"});r.setAttr("draggable","true"),r.setAttr("data-bm-id",i.id),r.style.paddingLeft=`${8+a*16}px`,r.style.cursor="grab",this.attachBookmarkDragHandlers(r,e,i,!1),r.addEventListener("contextmenu",c=>{c.stopPropagation(),c.preventDefault(),this.showBookmarkContextMenu(c,i)});continue}let o=i.type==="group",s=e.createDiv({cls:`waypoint-bookmark-item${o?" waypoint-bookmark-group":""}${i.collapsed?" collapsed":""}`});if(s.setAttr("draggable","true"),s.setAttr("data-bm-id",i.id),o||(s.style.paddingLeft=`${8+a*16}px`),this.attachBookmarkDragHandlers(s,e,i,!0),o){let r=s.createDiv({cls:"waypoint-bm-icon"});i.icon&&(0,m.setIcon)(r,i.icon);let c=s.createDiv({cls:"waypoint-bm-label",text:i.label}),l=s.createDiv({cls:"waypoint-bm-chevron"});(0,m.setIcon)(l,"chevron-down"),l.addEventListener("click",u=>{u.stopPropagation(),this.plugin.updateBookmark(i.id,{collapsed:!i.collapsed})}),s.addEventListener("click",u=>{if(i.filePath){let g=this.app.vault.getFileByPath(i.filePath);if(g){let S=m.Keymap.isModEvent(u);this.app.workspace.getLeaf(S).openFile(g);return}}this.plugin.updateBookmark(i.id,{collapsed:!i.collapsed})}),s.addEventListener("mousedown",u=>{if(u.button===1&&i.filePath){u.preventDefault();let g=this.app.vault.getFileByPath(i.filePath);g&&this.app.workspace.getLeaf("tab").openFile(g)}});let h=e.createDiv({cls:`waypoint-bookmark-children${i.collapsed?" collapsed":""}`});i.children&&i.children.length>0&&this.renderBookmarkList(h,i.children,a+1)}else{let r=s.createDiv({cls:"waypoint-bm-icon"});i.icon&&(0,m.setIcon)(r,i.icon);let c=s.createDiv({cls:"waypoint-bm-label",text:i.label});if(i.children&&i.children.length>0){let l=s.createDiv({cls:"waypoint-bm-chevron"});(0,m.setIcon)(l,"chevron-down"),l.addEventListener("click",h=>{h.stopPropagation(),this.plugin.updateBookmark(i.id,{collapsed:!i.collapsed})}),i.collapsed&&(s.addClass("collapsed"),l.style.transform="rotate(-90deg)")}if((0,m.setTooltip)(s,i.filePath),s.addEventListener("click",l=>{if(i.filePath){let h=this.app.vault.getFileByPath(i.filePath);if(h){let u=m.Keymap.isModEvent(l);this.app.workspace.getLeaf(u).openFile(h)}else new m.Notice("File not found"),this.plugin.removeBookmark(i.id)}}),s.addEventListener("mousedown",l=>{if(l.button===1&&i.filePath){l.preventDefault();let h=this.app.vault.getFileByPath(i.filePath);h&&this.app.workspace.getLeaf("tab").openFile(h)}}),i.children&&i.children.length>0){let l=e.createDiv({cls:`waypoint-bookmark-children${i.collapsed?" collapsed":""}`});this.renderBookmarkList(l,i.children,a+1)}}s.addEventListener("contextmenu",r=>{r.stopPropagation(),r.preventDefault(),this.showBookmarkContextMenu(r,i)})}}showBookmarkContextMenu(e,n){let a=new m.Menu;if(n.type==="separator"||n.type==="spacer"){a.addItem(t=>t.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(n.id))),a.showAtPosition({x:e.clientX,y:e.clientY});return}n.type==="file"?(a.addItem(t=>t.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let i=this.app.vault.getFileByPath(n.filePath);i&&this.app.workspace.getLeaf("tab").openFile(i)})),a.addSeparator(),a.addItem(t=>t.setTitle("Rename").setIcon("pencil").onClick(()=>this.promptRename(n))),a.addItem(t=>t.setTitle("Change icon").setIcon("image").onClick(()=>this.promptIcon(n))),a.addSeparator(),a.addItem(t=>t.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(n.id)))):n.type==="group"&&(n.filePath&&(a.addItem(t=>t.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let i=this.app.vault.getFileByPath(n.filePath);i&&this.app.workspace.getLeaf("tab").openFile(i)})),a.addSeparator()),a.addItem(t=>t.setTitle("Rename").setIcon("pencil").onClick(()=>this.promptRename(n))),a.addItem(t=>t.setTitle("Change icon").setIcon("image").onClick(()=>this.promptIcon(n))),a.addSeparator(),a.addItem(t=>t.setTitle("Add child bookmark").setIcon("file-plus").onClick(()=>{let i=this.app.workspace.getActiveFile();if(!i){new m.Notice("No active file");return}let o={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"file",label:i.basename,filePath:i.path,icon:"",children:[],collapsed:!1,indent:n.indent+1};n.children.push(o),this.plugin.saveWaypointData(),this.redraw()})),a.addItem(t=>t.setTitle("Add child note").setIcon("folder-plus").onClick(()=>{let i=this.app.workspace.getActiveFile();if(!i){new m.Notice("No active file");return}let o={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:i.basename,filePath:i.path,icon:"",children:[],collapsed:!1,indent:n.indent+1};n.children.push(o),this.plugin.saveWaypointData(),this.redraw()})),a.addItem(t=>t.setTitle("New sub-group").setIcon("folder-plus").onClick(()=>{let i={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:"New Group",filePath:"",icon:"",children:[],collapsed:!1,indent:n.indent+1};n.children.push(i),this.plugin.saveWaypointData(),this.redraw()})),a.addSeparator(),a.addItem(t=>t.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(n.id)))),a.showAtPosition({x:e.clientX,y:e.clientY})}attachBookmarkDragHandlers(e,n,a,t){let i=()=>{e.removeClass("waypoint-bm-drop-line"),e.removeClass("waypoint-bm-drop-below"),e.removeClass("waypoint-bm-drop-into")};e.addEventListener("dragstart",o=>{this.dragId=a.id,o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",a.id),e.addClass("waypoint-bm-dragging")}),e.addEventListener("dragend",()=>{this.dragId=null,n.querySelectorAll(".waypoint-bm-dragging, .waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(o=>{o.removeClass("waypoint-bm-dragging"),o.removeClass("waypoint-bm-drop-line"),o.removeClass("waypoint-bm-drop-below"),o.removeClass("waypoint-bm-drop-into")})}),e.addEventListener("dragenter",o=>{o.preventDefault(),!(!this.dragId||this.dragId===a.id)&&this.showDropIndicator(e,o,t)}),e.addEventListener("dragover",o=>{o.preventDefault(),!(!this.dragId||this.dragId===a.id)&&this.showDropIndicator(e,o,t)}),e.addEventListener("dragleave",i),e.addEventListener("drop",o=>{var c,l;o.preventDefault(),this.dragId=null,i();let s=(c=o.dataTransfer)==null?void 0:c.getData("text/plain");if(!s||s===a.id)return;let r=this.dropZones.get(e);t&&(r!=null&&r.into)?a.type==="group"?this.moveBookmarkToGroup(s,a.id):this.createParentNoteAndMove(s,a.id):this.moveBookmarkToPosition(s,a.id,(l=r==null?void 0:r.above)!=null?l:!1)})}showDropIndicator(e,n,a){let t=e.parentElement;t&&t.querySelectorAll(".waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(s=>{s.removeClass("waypoint-bm-drop-line"),s.removeClass("waypoint-bm-drop-below"),s.removeClass("waypoint-bm-drop-into")});let i=e.getBoundingClientRect(),o=n.clientY;if(a){let s=i.top+i.height*.25,r=i.top+i.height*.75;or?(e.addClass("waypoint-bm-drop-line"),e.addClass("waypoint-bm-drop-below"),this.dropZones.set(e,{above:!1,into:!1})):(e.addClass("waypoint-bm-drop-into"),this.dropZones.set(e,{above:!1,into:!0}))}else{let s=o{let o=i.findIndex(s=>s.id===e);if(o>=0){let[s]=i.splice(o,1);return s}for(let s of i){let r=a(s.children);if(r)return r}return null},t=a(this.plugin.waypointData.bookmarks);if(t){if(n){let i=(o,s)=>o.id===s?!0:o.children.some(r=>i(r,s));if(t.id===n||i(t,n))return}if(n){let i=s=>{for(let r of s){if(r.id===n)return r;let c=i(r.children);if(c)return c}return null},o=i(this.plugin.waypointData.bookmarks);o&&(t.indent=o.indent+1,o.children.push(t))}else t.indent=0,this.plugin.waypointData.bookmarks.push(t);this.plugin.saveWaypointData(),this.redraw()}}createParentNoteAndMove(e,n){let a=s=>{let r=s.findIndex(c=>c.id===e);if(r>=0){let[c]=s.splice(r,1);return c}for(let c of s)if(c.children){let l=a(c.children);if(l)return l}return null},t=a(this.plugin.waypointData.bookmarks);if(!t)return;let i=s=>{for(let r of s){if(r.id===n)return r;if(r.children){let c=i(r.children);if(c)return c}}return null},o=i(this.plugin.waypointData.bookmarks);o&&(t.indent=o.indent+1,o.children.push(t),this.plugin.saveWaypointData(),this.redraw())}moveBookmarkToPosition(e,n,a){let t=r=>{let c=r.findIndex(l=>l.id===e);if(c>=0){let[l]=r.splice(c,1);return{item:l,parent:r}}for(let l of r)if(l.children){let h=t(l.children);if(h.item)return h}return{item:null,parent:[]}},{item:i}=t(this.plugin.waypointData.bookmarks);if(!i)return;let o=r=>{let c=r.findIndex(l=>l.id===n);if(c>=0)return{parent:r,idx:c};for(let l of r)if(l.children){let h=o(l.children);if(h)return h}return null},s=o(this.plugin.waypointData.bookmarks);if(!s)i.indent=0,this.plugin.waypointData.bookmarks.push(i);else{let r=a?s.idx:s.idx+1;s.parent.splice(r,0,i)}this.plugin.saveWaypointData(),this.redraw()}promptRename(e){new q(this.app,{title:"Rename bookmark",initialValue:e.label},n=>{n&&n.trim()&&this.plugin.updateBookmark(e.id,{label:n.trim()})}).open()}promptIcon(e){new J(this.app,e.icon,n=>{this.plugin.updateBookmark(e.id,{icon:n})}).open()}},q=class extends m.Modal{constructor(d,e,n){super(d),this.options=e,this.onSubmit=n}onOpen(){var t,i,o;this.titleEl.setText(this.options.title);let d=this.contentEl.createEl("input",{type:"text",value:(t=this.options.initialValue)!=null?t:"",placeholder:(i=this.options.placeholder)!=null?i:""});d.style.width="100%",d.style.marginBottom="12px",d.focus(),d.select();let e=this.contentEl.createDiv({cls:"modal-button-container"}),n=e.createEl("button",{text:"Cancel",cls:"mod-cta"});n.style.marginRight="8px",n.addEventListener("click",()=>this.close()),e.createEl("button",{text:(o=this.options.cta)!=null?o:"Save",cls:"mod-cta"}).addEventListener("click",()=>{this.onSubmit(d.value),this.close()}),d.addEventListener("keydown",s=>{s.key==="Enter"&&(this.onSubmit(d.value),this.close())})}onClose(){this.contentEl.empty()}},H=null;function be(){return H||(H=(async()=>{try{return await(await fetch("https://cdn.jsdelivr.net/npm/lucide-static@0.517.0/tags.json")).json()}catch(p){try{return await(await fetch("https://lucide.dev/api/tags")).json()}catch(d){return H=null,De}}})()),H}var J=class extends m.Modal{constructor(e,n,a){super(e);this.allIcons=[];this.tagsMap={};this.loaded=!1;this.selected=n,this.onSubmit=a}async onOpen(){let e=this.contentEl;e.style.display="flex",e.style.flexDirection="column",e.style.gap="10px",this.titleEl.setText("Change icon");let n=e.createDiv({cls:"waypoint-icon-preview"});n.style.display="flex",n.style.alignItems="center",n.style.gap="10px",n.style.padding="12px 16px",n.style.borderRadius="8px",n.style.background="var(--background-secondary)",n.style.minHeight="48px";let a=n.createSpan();a.style.display="flex",this.selected&&(0,m.setIcon)(a,this.selected);let t=n.createSpan();t.style.fontWeight="var(--font-medium)",t.style.fontSize="var(--font-ui-medium)",t.setText(this.selected||"No icon");let i=e.createEl("input",{type:"text",placeholder:"Type to search (e.g. arrow, chart, home)..."});Object.assign(i.style,{width:"100%",boxSizing:"border-box",padding:"8px 10px",borderRadius:"6px",border:"1px solid var(--background-modifier-border)",background:"var(--background-primary)",color:"var(--text-normal)",fontSize:"var(--font-ui-medium)"}),i.focus();let o=e.createDiv({cls:"waypoint-icon-grid"});o.style.display="grid",o.style.gridTemplateColumns="repeat(auto-fill, minmax(52px, 1fr))",o.style.gap="4px",o.style.maxHeight="320px",o.style.overflowY="auto",o.style.padding="2px 0";let s=e.createDiv();s.style.display="flex",s.style.justifyContent="space-between",s.style.alignItems="center",s.style.fontSize="var(--font-ui-smaller)",s.style.color="var(--text-muted)",s.style.padding="0 4px";let r=s.createSpan();r.setText("Loading\u2026"),this.loadIcons().then(()=>{this.loaded=!0,r.setText(this.allIcons.length+" icons"),l(i.value)});let c,l=F=>{if(o.empty(),!this.loaded){o.createDiv({text:"Loading\u2026"});return}let w=F.toLowerCase().trim(),b=w?this.allIcons.filter(k=>{if(k.includes(w))return!0;let y=this.tagsMap[k];return y?y.some(L=>L.includes(w)):!1}).slice(0,80):this.allIcons.slice(0,80);if(b.length===0){let k=o.createDiv();k.style.gridColumn="1 / -1",k.style.textAlign="center",k.style.color="var(--text-muted)",k.style.padding="20px",k.setText('No icons match "'+F+'"');return}for(let k of b){let y=o.createDiv();y.setAttr("data-icon",k),y.style.display="flex",y.style.alignItems="center",y.style.justifyContent="center",y.style.aspectRatio="1",y.style.borderRadius="6px",y.style.cursor="var(--cursor-link, pointer)",y.style.transition="background 80ms",y.setAttr("title",k),k===this.selected?(y.style.background="var(--interactive-accent)",y.style.color="var(--text-on-accent)"):y.style.color="var(--text-muted)";let L=y.createSpan();L.style.display="flex",(0,m.setIcon)(L,k),y.addEventListener("mouseenter",()=>{k!==this.selected&&(y.style.background="var(--background-modifier-hover)")}),y.addEventListener("mouseleave",()=>{k!==this.selected&&(y.style.background="")}),y.addEventListener("click",()=>{this.selected=k,l(F),a.empty(),(0,m.setIcon)(a,k),t.setText(k),o.querySelectorAll("div[data-icon]").forEach(K=>{let P=K;P.getAttr("data-icon")===k?(P.style.background="var(--interactive-accent)",P.style.color="var(--text-on-accent)"):(P.style.background="",P.style.color="var(--text-muted)")})})}r.setText(b.length+" of "+this.allIcons.length+" icons")};i.addEventListener("input",()=>{window.clearTimeout(c),c=window.setTimeout(()=>l(i.value),60)}),i.addEventListener("keydown",F=>{F.key==="Escape"&&this.close()});let h=e.createDiv({cls:"modal-button-container"});h.createEl("button",{text:"No icon",cls:"waypoint-icon-clear"}).addEventListener("click",()=>{this.onSubmit(""),this.close()}),h.createEl("button",{text:"Cancel"}).addEventListener("click",()=>this.close());let S=h.createEl("button",{text:"Save",cls:"mod-cta"});S.style.marginLeft="8px",S.addEventListener("click",()=>{this.onSubmit(this.selected),this.close()})}onClose(){this.contentEl.empty()}async loadIcons(){let e=await be();this.tagsMap=e,this.allIcons=Object.keys(e).sort()}},De={file:[],folder:[],star:[],heart:[],bookmark:[],flag:[],pin:[],tag:[],book:[],"book-open":[],library:[],calendar:[],"calendar-days":[],clock:[],home:[],inbox:[],mail:[],search:[],settings:[],cog:[],user:[],users:[],zap:[],sparkles:[],target:[],link:[],globe:[],edit:[],pencil:[],anchor:[],award:[],bell:[],"bell-ring":[],brain:[],briefcase:[],camera:[],"chart-bar":[],"chart-line":[],"chart-pie":[],check:[],"check-circle":[],"chevron-down":[],"chevron-left":[],"chevron-right":[],"chevron-up":[],circle:[],clipboard:[],code:[],command:[],compass:[],copy:[],"credit-card":[],crown:[],database:[],download:[],"external-link":[],eye:[],"eye-off":[],"file-text":[],filter:[],fingerprint:[],flashlight:[],"folder-open":[],"folder-plus":[],gift:[],"git-branch":[],"git-commit":[],"git-merge":[],"git-pull-request":[],github:[],grid:[],hash:[],headphones:[],image:[],info:[],key:[],layers:[],layout:[],"life-buoy":[],"link-2":[],list:[],loader:[],lock:[],"log-in":[],"log-out":[],map:[],"map-pin":[],maximize:[],megaphone:[],menu:[],"message-circle":[],"message-square":[],mic:[],minimize:[],moon:[],"more-horizontal":[],"more-vertical":[],"mouse-pointer":[],move:[],music:[],navigation:[],"navigation-2":[],package:[],palette:[],paperclip:[],pause:[],phone:[],play:[],plus:[],"plus-circle":[],power:[],printer:[],radio:[],"refresh-cw":[],repeat:[],"rotate-ccw":[],"rotate-cw":[],rss:[],save:[],scissors:[],screen:[],send:[],server:[],share:[],"share-2":[],shield:[],"shield-off":[],"shopping-bag":[],"shopping-cart":[],shuffle:[],sidebar:[],slack:[],slash:[],sliders:[],smartphone:[],smile:[],speaker:[],square:[],"stop-circle":[],sun:[],sunrise:[],sunset:[],swords:[],table:[],tablet:[],terminal:[],thermometer:[],"thumbs-down":[],"thumbs-up":[],"toggle-left":[],"toggle-right":[],tool:[],trash:[],"trash-2":[],trello:[],"trending-down":[],"trending-up":[],triangle:[],truck:[],tv:[],twitter:[],type:[],umbrella:[],unlock:[],upload:[],"user-check":[],"user-minus":[],"user-plus":[],"user-x":[],video:[],"video-off":[],voicemail:[],volume:[],"volume-1":[],"volume-2":[],"volume-x":[],watch:[],wifi:[],"wifi-off":[],wind:[],x:[],"x-circle":[],"x-square":[],youtube:[],"zap-off":[],"zoom-in":[],"zoom-out":[],"arrow-down":[],"arrow-left":[],"arrow-right":[],"arrow-up":[],airplay:[],"alarm-clock":[],archive:[],armchair:[],atom:[],baby:[],backpack:[],badge:[],"badge-check":[],ban:[],banknote:[],barcode:[],bath:[],battery:[],"battery-charging":[],beer:[],bike:[],bird:[],bluetooth:[],bolt:[],bone:[],"bookmark-plus":[],bot:[],box:[],bug:[],building:[],bus:[],cake:[],calculator:[],car:[],"clipboard-check":[],cloud:[],"cloud-download":[],"cloud-lightning":[],"cloud-rain":[],"cloud-sun":[],"cloud-upload":[],clover:[],coffee:[],coins:[],contact:[],cookie:[],"corner-down-left":[],"corner-down-right":[],"corner-up-left":[],"corner-up-right":[],crosshair:[],"dice-1":[],"dice-6":[],"dollar-sign":[],"door-open":[],drama:[],droplet:[],drum:[],egg:[],equal:[],euro:[],factory:[],fan:[],feather:[],film:[],fish:[],flame:[],flask:[],flower:[],frown:[],fuel:[],gamepad:[],gauge:[],gem:[],ghost:[],glasses:[],"graduation-cap":[],hammer:[],"hard-drive":[],haze:[],"help-circle":[],"ice-cream":[],infinity:[],italic:[],"japanese-yen":[],keyboard:[],knife:[],lamp:[],landmark:[],languages:[],laptop:[],laugh:[],leaf:[],lightbulb:[],"list-plus":[],magnet:[],"mail-plus":[],meh:[],microscope:[],milestone:[],"minimize-2":[],monitor:[],mountain:[],mouse:[],network:[],newspaper:[],"package-check":[],"package-search":[],"paint-bucket":[],parking:[],"party-popper":[],"pen-tool":[],percent:[],"person-standing":[],"picture-in-picture-2":[],plane:[],plug:[],podcast:[],pointer:[],"pound-sterling":[],puzzle:[],"qr-code":[],rabbit:[],radar:[],rainbow:[],rocket:[],"roller-coaster":[],route:[],ruler:[],sailboat:[],scale:[],scan:[],school:[],ship:[],shirt:[],"shopping-basket":[],shovel:[],sigma:[],siren:[],skull:[],snowflake:[],soup:[],space:[],sparkle:[],stamp:[],store:[],subscript:[],superscript:[],syringe:[],tent:[],"tent-tree":[],"test-tube":[],theater:[],timer:[],train:[],"tree-deciduous":[],"tree-pine":[],trophy:[],typing:[],utensils:[],vibrate:[],wallet:[],wand:[],warehouse:[],waves:[],webcam:[],wheat:[],wine:[],wrench:[]};function X(p,d,e){return!p||!d?null:p===d?e:p.startsWith(d+"/")?e+p.slice(d.length):null}var G=class extends f.Plugin{constructor(){super(...arguments);this.recentFiles=[];this.savePromise=Promise.resolve();this.markdownBasenames=new Set;this.dateSystemIndicators=null;this.dateSystemIndicatorKey="";this.indicatorModeMigrated=!1}async onload(){console.debug("Waypoint: loading plugin v"+this.manifest.version);let e=await this.loadData(),n=this.applySettings(e);this.applyWaypointData(e),n&&this.persistAll(),this.registerView(E,s=>new W(s,this)),this.addSettingTab(new V(this.app,this,this.settings,()=>{this.enforceRecentFilesLimit(),this.invalidateDateSystemIndicators(),this.redrawAll()})),this.addCommand({id:"waypoint-open-view",name:"Open Waypoint sidebar",callback:async()=>{let s=this.app.workspace.getLeavesOfType(E);if(s.length>0)await this.app.workspace.revealLeaf(s[0]);else{let r=this.app.workspace.getLeftLeaf(!1);r&&(await r.setViewState({type:E}),await this.app.workspace.revealLeaf(r))}}}),this.addCommand({id:"waypoint-add-bookmark",name:"Add current file as Waypoint bookmark",callback:async()=>{let s=this.app.workspace.getActiveFile();if(!s){new f.Notice("No active file");return}this.addBookmark(s.path,s.basename,"file"),new f.Notice(`Bookmarked: ${s.basename}`)}}),this.addCommand({id:"waypoint-go-to-daily",name:"Go to daily note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"d"}],callback:async()=>{await this.openPeriodNote("day",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-weekly",name:"Go to weekly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"w"}],callback:async()=>{await this.openPeriodNote("week",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-monthly",name:"Go to monthly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"m"}],callback:async()=>{await this.openPeriodNote("month",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-quarterly",name:"Go to quarterly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"q"}],callback:async()=>{await this.openPeriodNote("quarter",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-yearly",name:"Go to yearly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"y"}],callback:async()=>{await this.openPeriodNote("year",(0,f.moment)())}});let a=["next","prev"],t=["daily","weekly","monthly","quarterly","yearly"],i={next:"Next",prev:"Previous"};for(let s of t)for(let r of a){let c=`waypoint-go-to-${r}-${s}`,l=`${i[r]} ${s} note`;this.addCommand({id:c,name:l,callback:async()=>{await this.navigatePeriodNote(r)}})}this.registerEvent(this.app.workspace.on("file-open",s=>{s&&this.onFileOpen(s)})),this.registerEvent(this.app.vault.on("create",s=>this.onVaultCreate(s))),this.registerEvent(this.app.vault.on("delete",s=>this.onVaultDelete(s))),this.registerEvent(this.app.vault.on("rename",(s,r)=>this.onRename(s,r))),this.registerEvent(this.app.vault.on("modify",s=>this.onFileModify(s))),this.app.workspace.onLayoutReady(()=>{if(this.buildMarkdownIndex(),this.app.workspace.getLeavesOfType(E).length===0){let r=this.app.workspace.getLeftLeaf(!1);r&&r.setViewState({type:E})}else this.broadcastRedraw()});let o=new Date().toDateString();this.registerInterval(window.setInterval(()=>{let s=new Date().toDateString();s!==o&&(o=s,this.redrawAll())},6e5))}async onunload(){this.app.workspace.detachLeavesOfType(E)}applySettings(e){var i;let n=(e==null?void 0:e.settings)||{};this.settings=Object.assign({},T,n),this.settings.recentFiles=Object.assign({},T.recentFiles,n.recentFiles||{}),this.settings.calendar=Object.assign({},T.calendar,n.calendar||{}),this.settings.display=Object.assign({},T.display,n.display||{});for(let o of Se)this.settings[o]=Object.assign({},T[o],n[o]||{});this.settings.dateSystems=Array.isArray(n.dateSystems)?n.dateSystems.map(o=>{let s=T.dateSystems.find(r=>r.id===o.id);return Object.assign({},s||$,o)}):T.dateSystems.map(o=>Object.assign({},o));let a=(e==null?void 0:e.indicatorModeMigrated)===!0,t=!1;return!a&&((i=n.calendar)==null?void 0:i.indicatorMode)==="any"&&(this.settings.calendar.indicatorMode="systems",t=!0),this.indicatorModeMigrated=!0,t}applyWaypointData(e){let n=(e==null?void 0:e.waypointData)||{};this.waypointData={bookmarks:Array.isArray(n.bookmarks)?n.bookmarks:[],recentFiles:Array.isArray(n.recentFiles)?n.recentFiles:[]},this.recentFiles=this.waypointData.recentFiles,this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems),this.waypointData.recentFiles=this.recentFiles)}persistAll(){let e=this.savePromise.then(()=>(this.waypointData.recentFiles=this.recentFiles,this.saveData({settings:this.settings,waypointData:this.waypointData,indicatorModeMigrated:this.indicatorModeMigrated})));return this.savePromise=e.catch(()=>{}),e}async saveSettings(){await this.persistAll()}async saveWaypointData(){await this.persistAll()}enforceRecentFilesLimit(){this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems),this.persistRecentFiles())}persistRecentFiles(){this.waypointData.recentFiles=this.recentFiles,window.clearTimeout(this.recentFilesSaveTimer),this.recentFilesSaveTimer=window.setTimeout(()=>{this.saveWaypointData()},300)}onFileOpen(e){this.settings.recentFiles.updateOn==="file-open"&&this.addToRecentFiles(e)}onFileModify(e){this.settings.recentFiles.updateOn==="file-edit"&&e instanceof f.TFile&&(this.recentFiles.length>0&&this.recentFiles[0].path===e.path||this.addToRecentFiles(e))}addToRecentFiles(e){this.isOmittedFromRecentFiles(e)||(this.recentFiles=this.recentFiles.filter(n=>n.path!==e.path),this.recentFiles.unshift({path:e.path,basename:e.basename}),this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems)),this.persistRecentFiles(),this.broadcastRedraw())}isOmittedFromRecentFiles(e){for(let o of this.settings.recentFiles.omittedPaths)try{if(new RegExp(o).test(e.path))return!0}catch(s){}let n=this.settings.recentFiles.omittedTags;if(n.length===0)return!1;let a=this.app.metadataCache.getFileCache(e),t=(a?(0,f.getAllTags)(a):null)||[];if(t.length===0)return!1;let i=t.map(o=>o.replace(/^#/,""));for(let o of n)try{let s=new RegExp(o);if(i.some(r=>s.test(r)))return!0}catch(s){}return!1}onRename(e,n){this.invalidateDateSystemIndicators();let a=this.syncIndexForRename(e,n),t=!1;for(let o of this.recentFiles){let s=X(o.path,n,e.path);s!==null&&(o.path=s,o.basename=pe(s),t=!0)}let i=o=>{for(let s of o){if(s.filePath){let r=X(s.filePath,n,e.path);r!==null&&(s.filePath=r,t=!0)}s.children&&i(s.children)}};i(this.waypointData.bookmarks),t&&(this.waypointData.recentFiles=this.recentFiles,this.persistAll()),(t||a)&&this.broadcastRedraw()}onVaultCreate(e){e instanceof f.TFile&&e.extension==="md"&&(this.markdownBasenames.add(e.basename),this.invalidateDateSystemIndicators()),this.broadcastRedraw()}onVaultDelete(e){e instanceof f.TFile&&e.extension==="md"&&(this.removeFromMarkdownIndex(e.basename,e.path),this.invalidateDateSystemIndicators()),this.broadcastRedraw()}buildMarkdownIndex(){this.markdownBasenames.clear();for(let e of this.app.vault.getMarkdownFiles())this.markdownBasenames.add(e.basename)}invalidateDateSystemIndicators(){this.dateSystemIndicators=null,this.dateSystemIndicatorKey=""}removeFromMarkdownIndex(e,n){return!this.markdownBasenames.has(e)||this.app.vault.getMarkdownFiles().some(t=>t.basename===e&&t.path!==n)?!1:(this.markdownBasenames.delete(e),!0)}syncIndexForRename(e,n){if(!(e instanceof f.TFile))return!1;let a=!1,t=pe(n);return n.toLowerCase().endsWith(".md")&&(t!==e.basename||e.extension!=="md")&&(a=this.removeFromMarkdownIndex(t,n)),e.extension==="md"&&!this.markdownBasenames.has(e.basename)&&(this.markdownBasenames.add(e.basename),a=!0),a}hasNoteForDate(e){return this.markdownBasenames.has(e)}addBookmark(e,n,a="file",t=""){let o={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:a,label:n,filePath:a==="file"?e:"",icon:t,children:[],collapsed:!1,indent:0};return this.waypointData.bookmarks.push(o),this.saveWaypointData(),this.broadcastRedraw(),o}removeBookmark(e){let n=a=>{let t=a.findIndex(i=>i.id===e);if(t>=0)return a.splice(t,1),!0;for(let i of a)if(i.children&&n(i.children))return!0;return!1};n(this.waypointData.bookmarks),this.saveWaypointData(),this.broadcastRedraw()}updateBookmark(e,n){let a=i=>{for(let o of i){if(o.id===e)return o;if(o.children){let s=a(o.children);if(s)return s}}return null},t=a(this.waypointData.bookmarks);t&&(Object.assign(t,n),this.saveWaypointData(),this.broadcastRedraw())}periodAsDateSystem(e){let n=j[e],a=this.settings[n.key];return{id:n.key,name:n.label,folder:a.folder,nameFormat:a.nameFormat,templateFile:a.templateFile,typeProperty:a.typeProperty,icon:"calendar",indicatorColor:this.settings.calendar.dailyIndicatorColor}}dateSystems(){return[this.periodAsDateSystem("day"),...this.settings.dateSystems]}findDateSystemNotes(e){let n=this.dateSystems().map(a=>{let t=R(a.nameFormat);return{result:{system:a,notes:[],multiple:t.hasTitle},before:B(e,t.before),after:B(e,t.after),hasTitle:t.hasTitle,skip:!A(a.nameFormat)}});for(let a of this.app.vault.getMarkdownFiles())for(let t of n){if(t.skip)continue;let i=t.result.system;U(a.path,i.folder)&&Z(a.basename,t.before,t.after,t.hasTitle)&&t.result.notes.push({file:a,label:t.hasTitle?re(a.basename,t.before,t.after):i.name})}for(let a of n)a.result.notes.sort((t,i)=>t.file.basename.localeCompare(i.file.basename));return n.filter(a=>!a.skip).map(a=>a.result)}getDateSystemIndicators(e){var s;let n=e.map(r=>r.format("YYYY-MM-DD")),a=this.dateSystems().filter(r=>A(r.nameFormat)).map(r=>{let c=R(r.nameFormat);return{system:r,hasTitle:c.hasTitle,dates:e.map((l,h)=>({dateStr:n[h],before:B(l,c.before),after:B(l,c.after)}))}}),t=JSON.stringify({dates:n,systems:a.map(({system:r})=>[r.id,r.name,r.folder,r.nameFormat,r.indicatorColor])});if(this.dateSystemIndicators&&this.dateSystemIndicatorKey===t)return this.dateSystemIndicators;let i=new Map;for(let r of n)i.set(r,new Set);for(let r of this.app.vault.getMarkdownFiles())for(let c of a)if(U(r.path,c.system.folder))for(let l of c.dates)Z(r.basename,l.before,l.after,c.hasTitle)&&((s=i.get(l.dateStr))==null||s.add(c.system.id));let o=new Map;for(let r of n){let c=i.get(r);o.set(r,a.filter(({system:l})=>c==null?void 0:c.has(l.id)).map(({system:l})=>({id:l.id,name:l.name,color:l.indicatorColor})))}return this.dateSystemIndicatorKey=t,this.dateSystemIndicators=o,o}async openDateSystemNote(e,n,a){if(!A(e.nameFormat)){new f.Notice(`Waypoint: ${e.name||"This"} name format needs a date placeholder.`);return}let t=R(e.nameFormat),i=B(n,t.before),o=B(n,t.after),s;if(t.hasTitle){let h=le((a==null?void 0:a.title)||"");if(!h){new f.Notice(`Waypoint: a ${e.name.toLowerCase()} note needs a title.`);return}s=i+h+o}else s=i+o;let r=e.folder?`${e.folder}/${s}.md`:`${s}.md`,c=this.app.vault.getFileByPath(r);if(!c&&(c=await this.createDatedNote(r,e,n),!c))return;await((a==null?void 0:a.leaf)||this.app.workspace.getLeaf(!1)).openFile(c)}async openPeriodNote(e,n,a){await this.openDateSystemNote(this.periodAsDateSystem(e),n,{leaf:a})}async createDatedNote(e,n,a){let t=n.name.toLowerCase(),i=e.lastIndexOf("/"),o=i<0?"":e.slice(0,i);try{await this.ensureFolderExists(o)}catch(h){return new f.Notice(`Waypoint: could not create the folder "${o}" for the ${t} note. -${ee(h)} -Check Settings \u2192 Waypoint Sidebar \u2192 Periodic Notes.`,O),null}let s=n.templateFile,r=this.resolveTemplateFile(s),c;if(r)try{c=await this.app.vault.read(r)}catch(h){return new f.Notice(`Waypoint: could not read the template "${r.path}" for the ${t} note. -`+ee(h),O),null}else c=`--- +project`),a.setValue(this.settings.recentFiles.filterTags.join(` +`)),a.inputEl.onblur=()=>{this.settings.recentFiles.filterTags=a.getValue().split(` +`).filter(o=>o.trim()),this.saveAndRefresh()}})}renderDisplayTab(e){new y.Setting(e).setHeading().setName("Bookmarks"),this.addSliderSetting(e,"Row size","Height of bookmark items.",this.settings.display,"rowSize",18,40,1,"px"),this.addSliderSetting(e,"Row spacing","Gap between bookmark items.",this.settings.display,"rowSpacing",0,12,1,"px"),this.addSliderSetting(e,"Indent size","Indent per nesting depth.",this.settings.display,"indentSize",8,32,2,"px"),this.addSliderSetting(e,"Font size","Label font size.",this.settings.display,"fontSize",10,18,1,"px"),this.addSliderSetting(e,"Icon size","Bookmark icon size.",this.settings.display,"iconSize",12,24,1,"px"),new y.Setting(e).setHeading().setName("Calendar"),this.addSliderSetting(e,"Cell size","Height of calendar day cells.",this.settings.display,"calendarCellSize",20,48,2,"px"),new y.Setting(e).addButton(n=>n.setButtonText("Reset to defaults").onClick(()=>{this.settings.display={...T.display},this.saveAndRefresh(),this.display()}))}addSliderSetting(e,n,i,t,a,o,s,r,c){let l=new y.Setting(e).setName(n).setDesc(`${i} (${t[a]}${c})`);l.addSlider(m=>{m.setLimits(o,s,r).setValue(t[a]).setDynamicTooltip().onChange(u=>{t[a]=u,l.setDesc(`${i} (${u}${c})`),this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveSettings(),this.onSettingsChange()}renderAboutTab(e){let n=this.plugin.manifest.version,i=e.createDiv();i.style.display="flex",i.style.alignItems="center",i.style.gap="12px",i.style.marginBottom="16px";let t=i.createDiv();t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.width="48px",t.style.height="48px",t.style.borderRadius="12px",t.style.background="var(--interactive-accent)",t.style.color="var(--text-on-accent)",t.style.fontSize="24px",(0,y.setIcon)(t,"compass");let a=i.createDiv(),o=a.createEl("h2",{text:"Waypoint Sidebar"});o.style.margin="0",o.style.lineHeight="1.2";let s=a.createDiv({text:`v${n}`});s.style.color="var(--text-muted)",s.style.fontSize="var(--font-ui-small)";let r=e.createDiv();r.style.marginBottom="20px",r.style.lineHeight="1.6",r.style.color="var(--text-normal)",r.innerHTML=["

Waypoint is a sidebar plugin that brings three essential panels into one view:

",'
    ',"
  • Calendar \u2014 a monthly grid for your periodic notes (daily, weekly, monthly, quarterly, yearly). Click any day, week, or month to open or create the corresponding note.
  • ","
  • Recent Files \u2014 a list of recently opened files with type filtering, drag-and-drop, and right-click actions.
  • ","
  • Bookmarks \u2014 custom bookmarks with icons, groups, nesting, and drag-and-drop reordering. Separate from Obsidian's native bookmarks.
  • ","
",'

Made by Olivier. Licensed under MIT.

'].join(` +`)}};var h=require("obsidian");var C=require("obsidian");function ce(p,d,e){let n=(0,C.moment)({year:p,month:d,day:1}),i=(0,C.moment)(n).endOf("month"),t=(0,C.moment)(n).subtract((n.day()-e+7)%7,"days"),a=(0,C.moment)().startOf("day"),o=[],s=(0,C.moment)(t);for(;s.isBefore(i)||s.month()===d;){let r=[];for(let c=0;c<7;c++)r.push({date:(0,C.moment)(s),dayOfMonth:s.date(),isToday:s.isSame(a,"day"),isCurrentMonth:s.month()===d,isoWeekNumber:s.isoWeek()}),s.add(1,"day");if(o.push({weekNumber:r[0].isoWeekNumber,days:r}),o.length>=6)break}return o}var E="waypoint-view";function we(p){return p.dragManager}var W=class extends h.ItemView{constructor(e,n){super(e);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view");let e=this.plugin.settings.display;this.contentEl.style.setProperty("--wp-row-size",e.rowSize+"px"),this.contentEl.style.setProperty("--wp-row-spacing",e.rowSpacing+"px"),this.contentEl.style.setProperty("--wp-indent-size",e.indentSize+"px"),this.contentEl.style.setProperty("--wp-font-size",e.fontSize+"px"),this.contentEl.style.setProperty("--wp-icon-size",e.iconSize+"px"),this.contentEl.style.setProperty("--wp-cal-cell-size",e.calendarCellSize+"px"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,h.moment)().month();this.currentDisplayYear=(0,h.moment)().year();this.dragId=null;this.dropZones=new WeakMap;this.recentFilesFilter=null;this.plugin=n}getViewType(){return E}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let n=this.contentEl.createDiv({cls:"waypoint-section"}).createDiv({cls:"waypoint-calendar"}),i=(0,h.moment)(),t=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),a=n.createDiv({cls:"waypoint-calendar-top"}),o=a.createDiv({cls:"waypoint-calendar-breadcrumb"}),s=t.format("[Q]Q"),r=o.createSpan({cls:"waypoint-clickable",text:s});r.addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",t)}),r.addEventListener("mousedown",D=>{D.button===1&&(D.preventDefault(),this.plugin.openPeriodNote("quarter",t,this.app.workspace.getLeaf("tab")))});let c=t.format("MMMM"),l=o.createSpan({cls:"waypoint-clickable",text:c});l.addEventListener("click",()=>{this.plugin.openPeriodNote("month",t)}),l.addEventListener("mousedown",D=>{D.button===1&&(D.preventDefault(),this.plugin.openPeriodNote("month",t,this.app.workspace.getLeaf("tab")))});let m=t.format("YYYY"),u=o.createSpan({cls:"waypoint-clickable",text:m});u.addEventListener("click",()=>{this.plugin.openPeriodNote("year",t)}),u.addEventListener("mousedown",D=>{D.button===1&&(D.preventDefault(),this.plugin.openPeriodNote("year",t,this.app.workspace.getLeaf("tab")))});let g=a.createDiv({cls:"waypoint-calendar-today-group"}),S=g.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(S,"chevron-left"),S.addEventListener("click",()=>this.navigateMonth(-1)),g.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,h.moment)().month(),this.currentDisplayYear=(0,h.moment)().year(),this.redraw()});let w=g.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(w,"chevron-right"),w.addEventListener("click",()=>this.navigateMonth(1));let b=n.createEl("table"),v=b.createEl("thead").createEl("tr");v.createEl("th",{text:""});let L=["sun","mon","tue","wed","thu","fri","sat"],K=this.plugin.settings.calendar.firstDayOfWeek;for(let D=0;D<7;D++){let N=(K+D)%7;v.createEl("th",{text:L[N]})}let P=b.createEl("tbody"),te=ce(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek),_=this.plugin.settings.calendar.showNoteIndicators&&this.plugin.settings.calendar.indicatorMode==="systems"?this.plugin.getDateSystemIndicators(te.reduce((D,N)=>D.concat(N.days.map(Y=>Y.date)),[])):null;for(let D of te){let N=P.createEl("tr"),Y=N.createEl("td",{cls:"waypoint-weeknum"});Y.setText(String(D.weekNumber));let ie=D.days[0].date;Y.addEventListener("click",()=>{this.plugin.openPeriodNote("week",ie)}),Y.addEventListener("mousedown",x=>{x.button===1&&(x.preventDefault(),this.plugin.openPeriodNote("week",ie,this.app.workspace.getLeaf("tab")))});for(let x of D.days){let I=N.createEl("td",{cls:"waypoint-day"});if(I.setText(String(x.dayOfMonth)),x.isCurrentMonth||I.addClass("other-month"),x.isToday&&I.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let M=x.date.format("YYYY-MM-DD");if(this.plugin.settings.calendar.indicatorMode==="any")this.plugin.hasNoteForDate(M)&&I.addClass("has-note");else{let ne=(_==null?void 0:_.get(M))||[];if(ne.length>0){let me=I.createDiv({cls:"waypoint-day-indicators"});for(let ae of ne){let se=me.createSpan({cls:"waypoint-day-indicator"});se.style.setProperty("--waypoint-indicator-color",ae.color),(0,h.setTooltip)(se,ae.name)}}}}I.addEventListener("click",()=>{this.plugin.openPeriodNote("day",x.date)}),I.addEventListener("mousedown",M=>{M.button===1&&(M.preventDefault(),this.plugin.openPeriodNote("day",x.date,this.app.workspace.getLeaf("tab")))}),I.addEventListener("contextmenu",M=>{M.preventDefault(),M.stopPropagation(),this.showDayContextMenu(M,x.date)})}}}navigateMonth(e){let n=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(e,"month");this.currentDisplayMonth=n.month(),this.currentDisplayYear=n.year(),this.redraw()}showDayContextMenu(e,n){let i=new h.Menu;i.addItem(t=>t.setTitle(n.format("dddd, MMMM D, YYYY")).setIsLabel(!0));for(let t of this.plugin.findDateSystemNotes(n)){let a=t.multiple||t.notes.length===0;if(t.notes.length+(a?1:0)===0)continue;i.addSeparator();for(let s of t.notes)i.addItem(r=>r.setTitle(s.label).setIcon(t.system.icon).onClick(c=>this.focusFile(s.file,h.Keymap.isModEvent(c))));if(!a)continue;let o=t.system.name.toLowerCase();i.addItem(s=>s.setTitle(t.multiple?`New ${o} note\u2026`:`New ${o} note`).setIcon("plus").onClick(r=>this.createDateSystemNote(t,n,h.Keymap.isModEvent(r))))}i.showAtPosition({x:e.clientX,y:e.clientY})}createDateSystemNote(e,n,i){if(!e.multiple){this.plugin.openDateSystemNote(e.system,n,{leaf:i?this.app.workspace.getLeaf(i):void 0});return}let t=e.system.name;new q(this.app,{title:`New ${t.toLowerCase()} note`,placeholder:`${t} with\u2026`,cta:"Create"},a=>{this.plugin.openDateSystemNote(e.system,n,{title:a,leaf:i?this.app.workspace.getLeaf(i):void 0})}).open()}renderRecentFiles(){var r,c;let e=this.contentEl.createDiv({cls:"waypoint-section waypoint-recent-files"});if(e.createDiv({cls:"waypoint-section-header",text:"Recent Files"}),this.plugin.recentFiles.length===0){e.createDiv({cls:"nav-file",text:"No recent files"});return}let n=this.plugin.settings.recentFiles.filterTags||[],i={};if(n.length>0){for(let l of n)i[l]=0;for(let l of this.plugin.recentFiles){let m=this.app.vault.getAbstractFileByPath(l.path);if(m instanceof h.TFile){let u=this.app.metadataCache.getFileCache(m),g=(r=u==null?void 0:u.frontmatter)==null?void 0:r.type;g&&typeof g=="string"&&i.hasOwnProperty(g)&&i[g]++}}}else for(let l of this.plugin.recentFiles){let m=this.app.vault.getAbstractFileByPath(l.path);if(m instanceof h.TFile){let u=this.app.metadataCache.getFileCache(m),g=(c=u==null?void 0:u.frontmatter)==null?void 0:c.type;g&&typeof g=="string"&&(i[g]=(i[g]||0)+1)}}if(Object.keys(i).length>0){let l=e.createDiv({cls:"waypoint-recent-filter"});l.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter?"":" is-active"}`,text:"all"}).addEventListener("click",()=>{this.recentFilesFilter=null,this.redraw()});let u=n.length>0?Object.entries(i):Object.entries(i).sort((g,S)=>S[1]-g[1]);for(let[g,S]of u){let F=l.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter===g?" is-active":""}`});F.setText(`${g} ${S}`),F.addEventListener("click",()=>{this.recentFilesFilter=this.recentFilesFilter===g?null:g,this.redraw()})}}let t=this.plugin.recentFiles;this.recentFilesFilter&&(t=this.plugin.recentFiles.filter(l=>{var u;let m=this.app.vault.getAbstractFileByPath(l.path);if(m instanceof h.TFile){let g=this.app.metadataCache.getFileCache(m);return((u=g==null?void 0:g.frontmatter)==null?void 0:u.type)===this.recentFilesFilter}return!1}));let a=this.app.workspace.getActiveFile(),o=e.createDiv({cls:"nav-folder mod-root"}),s=o.createDiv({cls:"nav-folder-children"});for(let l of t){let m=s.createDiv({cls:"tree-item nav-file"}),u=m.createDiv({cls:"tree-item-self is-clickable nav-file-title"});u.createDiv({cls:"tree-item-inner nav-file-title-content"}).setText(l.basename);let S=u.createDiv({cls:"tree-item-spacer"}),F=u.createDiv({cls:"waypoint-recent-remove"});(0,h.setIcon)(F,"x"),F.addEventListener("click",w=>{w.stopPropagation(),this.plugin.recentFiles=this.plugin.recentFiles.filter(b=>b.path!==l.path),this.plugin.persistRecentFiles(),this.redraw()}),(0,h.setTooltip)(m,l.path),a&&l.path===a.path&&u.addClass("is-active"),u.setAttr("draggable","true"),u.addEventListener("dragstart",w=>{let b=this.app.metadataCache.getFirstLinkpathDest(l.path,"");if(b){let k=we(this.app),v=k.dragFile(w,b);k.onDragStart(w,v)}}),u.addEventListener("mouseover",w=>{this.app.workspace.trigger("hover-link",{event:w,source:E,hoverParent:o,targetEl:m,linktext:l.path})}),u.addEventListener("contextmenu",w=>{let b=new h.Menu;b.addItem(v=>v.setSection("action").setTitle("Open in new tab").setIcon("file-plus").onClick(()=>this.focusFile(l,"tab"))),b.addItem(v=>v.setSection("action").setTitle("Add to bookmarks").setIcon("bookmark").onClick(()=>{this.plugin.addBookmark(l.path,l.basename,"file"),new h.Notice(`Bookmarked: ${l.basename}`)}));let k=this.app.vault.getAbstractFileByPath(l.path);k&&this.app.workspace.trigger("file-menu",b,k,"link-context-menu"),b.showAtPosition({x:w.clientX,y:w.clientY})}),u.addEventListener("click",w=>{let b=h.Keymap.isModEvent(w);this.focusFile(l,b)}),u.addEventListener("mousedown",w=>{w.button===1&&(w.preventDefault(),this.focusFile(l,"tab"))})}}focusFile(e,n){let i=this.app.vault.getFiles().find(t=>t.path===e.path);i?this.app.workspace.getLeaf(n).openFile(i):(new h.Notice("Cannot find file"),this.plugin.recentFiles=this.plugin.recentFiles.filter(t=>t.path!==e.path),this.plugin.persistRecentFiles(),this.redraw())}renderFavorites(){let e=this.contentEl.createDiv({cls:"waypoint-section waypoint-favorites"}),n=e.createDiv({cls:"waypoint-section-header"});n.setText("Waypoint Bookmarks");let i=n.createEl("button",{cls:"waypoint-header-more"});if((0,h.setIcon)(i,"more-horizontal"),(0,h.setTooltip)(i,"Add bookmark"),i.addEventListener("click",t=>{let a=new h.Menu;a.addItem(o=>{o.setTitle("Add current file").setIcon("file-plus").onClick(()=>{let s=this.app.workspace.getActiveFile();s&&this.plugin.addBookmark(s.path,s.basename,"file")})}),a.addItem(o=>{o.setTitle("Add as parent note").setIcon("folder-plus").onClick(()=>{let s=this.app.workspace.getActiveFile();if(!s)return;let r=this.plugin.addBookmark(s.path,s.basename,"group","");r.filePath=s.path,this.plugin.saveWaypointData(),this.redraw()})}),a.addItem(o=>{o.setTitle("New group").setIcon("folder-plus").onClick(()=>{this.plugin.addBookmark("","New Group","group","")})}),a.addSeparator(),a.addItem(o=>{o.setTitle("Add separator").setIcon("minus").onClick(()=>{this.plugin.addBookmark("","","separator")})}),a.addItem(o=>{o.setTitle("Add spacer").setIcon("space").onClick(()=>{this.plugin.addBookmark("","","spacer")})}),a.showAtPosition({x:t.clientX,y:t.clientY})}),this.plugin.waypointData.bookmarks.length===0){e.createDiv({cls:"waypoint-bookmark-item",text:"No bookmarks"});return}this.renderBookmarkList(e,this.plugin.waypointData.bookmarks,0)}renderBookmarkList(e,n,i){for(let t=0;t{c.stopPropagation(),c.preventDefault(),this.showBookmarkContextMenu(c,a)});continue}if(a.type==="spacer"){let r=e.createDiv({cls:"waypoint-bookmark-item waypoint-bookmark-spacer"});r.setAttr("draggable","true"),r.setAttr("data-bm-id",a.id),r.style.paddingLeft=`${8+i*16}px`,r.style.cursor="grab",this.attachBookmarkDragHandlers(r,e,a,!1),r.addEventListener("contextmenu",c=>{c.stopPropagation(),c.preventDefault(),this.showBookmarkContextMenu(c,a)});continue}let o=a.type==="group",s=e.createDiv({cls:`waypoint-bookmark-item${o?" waypoint-bookmark-group":""}${a.collapsed?" collapsed":""}`});if(s.setAttr("draggable","true"),s.setAttr("data-bm-id",a.id),o||(s.style.paddingLeft=`${8+i*16}px`),this.attachBookmarkDragHandlers(s,e,a,!0),o){let r=s.createDiv({cls:"waypoint-bm-icon"});a.icon&&(0,h.setIcon)(r,a.icon);let c=s.createDiv({cls:"waypoint-bm-label",text:a.label}),l=s.createDiv({cls:"waypoint-bm-chevron"});(0,h.setIcon)(l,"chevron-down"),l.addEventListener("click",u=>{u.stopPropagation(),this.plugin.updateBookmark(a.id,{collapsed:!a.collapsed})}),s.addEventListener("click",u=>{if(a.filePath){let g=this.app.vault.getFileByPath(a.filePath);if(g){let S=h.Keymap.isModEvent(u);this.app.workspace.getLeaf(S).openFile(g);return}}this.plugin.updateBookmark(a.id,{collapsed:!a.collapsed})}),s.addEventListener("mousedown",u=>{if(u.button===1&&a.filePath){u.preventDefault();let g=this.app.vault.getFileByPath(a.filePath);g&&this.app.workspace.getLeaf("tab").openFile(g)}});let m=e.createDiv({cls:`waypoint-bookmark-children${a.collapsed?" collapsed":""}`});a.children&&a.children.length>0&&this.renderBookmarkList(m,a.children,i+1)}else{let r=s.createDiv({cls:"waypoint-bm-icon"});a.icon&&(0,h.setIcon)(r,a.icon);let c=s.createDiv({cls:"waypoint-bm-label",text:a.label});if(a.children&&a.children.length>0){let l=s.createDiv({cls:"waypoint-bm-chevron"});(0,h.setIcon)(l,"chevron-down"),l.addEventListener("click",m=>{m.stopPropagation(),this.plugin.updateBookmark(a.id,{collapsed:!a.collapsed})}),a.collapsed&&(s.addClass("collapsed"),l.style.transform="rotate(-90deg)")}if((0,h.setTooltip)(s,a.filePath),s.addEventListener("click",l=>{if(a.filePath){let m=this.app.vault.getFileByPath(a.filePath);if(m){let u=h.Keymap.isModEvent(l);this.app.workspace.getLeaf(u).openFile(m)}else new h.Notice("File not found"),this.plugin.removeBookmark(a.id)}}),s.addEventListener("mousedown",l=>{if(l.button===1&&a.filePath){l.preventDefault();let m=this.app.vault.getFileByPath(a.filePath);m&&this.app.workspace.getLeaf("tab").openFile(m)}}),a.children&&a.children.length>0){let l=e.createDiv({cls:`waypoint-bookmark-children${a.collapsed?" collapsed":""}`});this.renderBookmarkList(l,a.children,i+1)}}s.addEventListener("contextmenu",r=>{r.stopPropagation(),r.preventDefault(),this.showBookmarkContextMenu(r,a)})}}showBookmarkContextMenu(e,n){let i=new h.Menu;if(n.type==="separator"||n.type==="spacer"){i.addItem(t=>t.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(n.id))),i.showAtPosition({x:e.clientX,y:e.clientY});return}n.type==="file"?(i.addItem(t=>t.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let a=this.app.vault.getFileByPath(n.filePath);a&&this.app.workspace.getLeaf("tab").openFile(a)})),i.addSeparator(),i.addItem(t=>t.setTitle("Rename").setIcon("pencil").onClick(()=>this.promptRename(n))),i.addItem(t=>t.setTitle("Change icon").setIcon("image").onClick(()=>this.promptIcon(n))),i.addSeparator(),i.addItem(t=>t.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(n.id)))):n.type==="group"&&(n.filePath&&(i.addItem(t=>t.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let a=this.app.vault.getFileByPath(n.filePath);a&&this.app.workspace.getLeaf("tab").openFile(a)})),i.addSeparator()),i.addItem(t=>t.setTitle("Rename").setIcon("pencil").onClick(()=>this.promptRename(n))),i.addItem(t=>t.setTitle("Change icon").setIcon("image").onClick(()=>this.promptIcon(n))),i.addSeparator(),i.addItem(t=>t.setTitle("Add child bookmark").setIcon("file-plus").onClick(()=>{let a=this.app.workspace.getActiveFile();if(!a){new h.Notice("No active file");return}let o={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"file",label:a.basename,filePath:a.path,icon:"",children:[],collapsed:!1,indent:n.indent+1};n.children.push(o),this.plugin.saveWaypointData(),this.redraw()})),i.addItem(t=>t.setTitle("Add child note").setIcon("folder-plus").onClick(()=>{let a=this.app.workspace.getActiveFile();if(!a){new h.Notice("No active file");return}let o={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:a.basename,filePath:a.path,icon:"",children:[],collapsed:!1,indent:n.indent+1};n.children.push(o),this.plugin.saveWaypointData(),this.redraw()})),i.addItem(t=>t.setTitle("New sub-group").setIcon("folder-plus").onClick(()=>{let a={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:"New Group",filePath:"",icon:"",children:[],collapsed:!1,indent:n.indent+1};n.children.push(a),this.plugin.saveWaypointData(),this.redraw()})),i.addSeparator(),i.addItem(t=>t.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(n.id)))),i.showAtPosition({x:e.clientX,y:e.clientY})}attachBookmarkDragHandlers(e,n,i,t){let a=()=>{e.removeClass("waypoint-bm-drop-line"),e.removeClass("waypoint-bm-drop-below"),e.removeClass("waypoint-bm-drop-into")};e.addEventListener("dragstart",o=>{this.dragId=i.id,o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",i.id),e.addClass("waypoint-bm-dragging")}),e.addEventListener("dragend",()=>{this.dragId=null,n.querySelectorAll(".waypoint-bm-dragging, .waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(o=>{o.removeClass("waypoint-bm-dragging"),o.removeClass("waypoint-bm-drop-line"),o.removeClass("waypoint-bm-drop-below"),o.removeClass("waypoint-bm-drop-into")})}),e.addEventListener("dragenter",o=>{o.preventDefault(),!(!this.dragId||this.dragId===i.id)&&this.showDropIndicator(e,o,t)}),e.addEventListener("dragover",o=>{o.preventDefault(),!(!this.dragId||this.dragId===i.id)&&this.showDropIndicator(e,o,t)}),e.addEventListener("dragleave",a),e.addEventListener("drop",o=>{var c,l;o.preventDefault(),this.dragId=null,a();let s=(c=o.dataTransfer)==null?void 0:c.getData("text/plain");if(!s||s===i.id)return;let r=this.dropZones.get(e);t&&(r!=null&&r.into)?i.type==="group"?this.moveBookmarkToGroup(s,i.id):this.createParentNoteAndMove(s,i.id):this.moveBookmarkToPosition(s,i.id,(l=r==null?void 0:r.above)!=null?l:!1)})}showDropIndicator(e,n,i){let t=e.parentElement;t&&t.querySelectorAll(".waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(s=>{s.removeClass("waypoint-bm-drop-line"),s.removeClass("waypoint-bm-drop-below"),s.removeClass("waypoint-bm-drop-into")});let a=e.getBoundingClientRect(),o=n.clientY;if(i){let s=a.top+a.height*.25,r=a.top+a.height*.75;or?(e.addClass("waypoint-bm-drop-line"),e.addClass("waypoint-bm-drop-below"),this.dropZones.set(e,{above:!1,into:!1})):(e.addClass("waypoint-bm-drop-into"),this.dropZones.set(e,{above:!1,into:!0}))}else{let s=o{let o=a.findIndex(s=>s.id===e);if(o>=0){let[s]=a.splice(o,1);return s}for(let s of a){let r=i(s.children);if(r)return r}return null},t=i(this.plugin.waypointData.bookmarks);if(t){if(n){let a=(o,s)=>o.id===s?!0:o.children.some(r=>a(r,s));if(t.id===n||a(t,n))return}if(n){let a=s=>{for(let r of s){if(r.id===n)return r;let c=a(r.children);if(c)return c}return null},o=a(this.plugin.waypointData.bookmarks);o&&(t.indent=o.indent+1,o.children.push(t))}else t.indent=0,this.plugin.waypointData.bookmarks.push(t);this.plugin.saveWaypointData(),this.redraw()}}createParentNoteAndMove(e,n){let i=s=>{let r=s.findIndex(c=>c.id===e);if(r>=0){let[c]=s.splice(r,1);return c}for(let c of s)if(c.children){let l=i(c.children);if(l)return l}return null},t=i(this.plugin.waypointData.bookmarks);if(!t)return;let a=s=>{for(let r of s){if(r.id===n)return r;if(r.children){let c=a(r.children);if(c)return c}}return null},o=a(this.plugin.waypointData.bookmarks);o&&(t.indent=o.indent+1,o.children.push(t),this.plugin.saveWaypointData(),this.redraw())}moveBookmarkToPosition(e,n,i){let t=r=>{let c=r.findIndex(l=>l.id===e);if(c>=0){let[l]=r.splice(c,1);return{item:l,parent:r}}for(let l of r)if(l.children){let m=t(l.children);if(m.item)return m}return{item:null,parent:[]}},{item:a}=t(this.plugin.waypointData.bookmarks);if(!a)return;let o=r=>{let c=r.findIndex(l=>l.id===n);if(c>=0)return{parent:r,idx:c};for(let l of r)if(l.children){let m=o(l.children);if(m)return m}return null},s=o(this.plugin.waypointData.bookmarks);if(!s)a.indent=0,this.plugin.waypointData.bookmarks.push(a);else{let r=i?s.idx:s.idx+1;s.parent.splice(r,0,a)}this.plugin.saveWaypointData(),this.redraw()}promptRename(e){new q(this.app,{title:"Rename bookmark",initialValue:e.label},n=>{n&&n.trim()&&this.plugin.updateBookmark(e.id,{label:n.trim()})}).open()}promptIcon(e){new J(this.app,e.icon,n=>{this.plugin.updateBookmark(e.id,{icon:n})}).open()}},q=class extends h.Modal{constructor(d,e,n){super(d),this.options=e,this.onSubmit=n}onOpen(){var t,a,o;this.titleEl.setText(this.options.title);let d=this.contentEl.createEl("input",{type:"text",value:(t=this.options.initialValue)!=null?t:"",placeholder:(a=this.options.placeholder)!=null?a:""});d.style.width="100%",d.style.marginBottom="12px",d.focus(),d.select();let e=this.contentEl.createDiv({cls:"modal-button-container"}),n=e.createEl("button",{text:"Cancel",cls:"mod-cta"});n.style.marginRight="8px",n.addEventListener("click",()=>this.close()),e.createEl("button",{text:(o=this.options.cta)!=null?o:"Save",cls:"mod-cta"}).addEventListener("click",()=>{this.onSubmit(d.value),this.close()}),d.addEventListener("keydown",s=>{s.key==="Enter"&&(this.onSubmit(d.value),this.close())})}onClose(){this.contentEl.empty()}},H=null;function be(){return H||(H=(async()=>{try{return await(await fetch("https://cdn.jsdelivr.net/npm/lucide-static@0.517.0/tags.json")).json()}catch(p){try{return await(await fetch("https://lucide.dev/api/tags")).json()}catch(d){return H=null,De}}})()),H}var J=class extends h.Modal{constructor(e,n,i){super(e);this.allIcons=[];this.tagsMap={};this.loaded=!1;this.selected=n,this.onSubmit=i}async onOpen(){let e=this.contentEl;e.style.display="flex",e.style.flexDirection="column",e.style.gap="10px",this.titleEl.setText("Change icon");let n=e.createDiv({cls:"waypoint-icon-preview"});n.style.display="flex",n.style.alignItems="center",n.style.gap="10px",n.style.padding="12px 16px",n.style.borderRadius="8px",n.style.background="var(--background-secondary)",n.style.minHeight="48px";let i=n.createSpan();i.style.display="flex",this.selected&&(0,h.setIcon)(i,this.selected);let t=n.createSpan();t.style.fontWeight="var(--font-medium)",t.style.fontSize="var(--font-ui-medium)",t.setText(this.selected||"No icon");let a=e.createEl("input",{type:"text",placeholder:"Type to search (e.g. arrow, chart, home)..."});Object.assign(a.style,{width:"100%",boxSizing:"border-box",padding:"8px 10px",borderRadius:"6px",border:"1px solid var(--background-modifier-border)",background:"var(--background-primary)",color:"var(--text-normal)",fontSize:"var(--font-ui-medium)"}),a.focus();let o=e.createDiv({cls:"waypoint-icon-grid"});o.style.display="grid",o.style.gridTemplateColumns="repeat(auto-fill, minmax(52px, 1fr))",o.style.gap="4px",o.style.maxHeight="320px",o.style.overflowY="auto",o.style.padding="2px 0";let s=e.createDiv();s.style.display="flex",s.style.justifyContent="space-between",s.style.alignItems="center",s.style.fontSize="var(--font-ui-smaller)",s.style.color="var(--text-muted)",s.style.padding="0 4px";let r=s.createSpan();r.setText("Loading\u2026"),this.loadIcons().then(()=>{this.loaded=!0,r.setText(this.allIcons.length+" icons"),l(a.value)});let c,l=F=>{if(o.empty(),!this.loaded){o.createDiv({text:"Loading\u2026"});return}let w=F.toLowerCase().trim(),b=w?this.allIcons.filter(k=>{if(k.includes(w))return!0;let v=this.tagsMap[k];return v?v.some(L=>L.includes(w)):!1}).slice(0,80):this.allIcons.slice(0,80);if(b.length===0){let k=o.createDiv();k.style.gridColumn="1 / -1",k.style.textAlign="center",k.style.color="var(--text-muted)",k.style.padding="20px",k.setText('No icons match "'+F+'"');return}for(let k of b){let v=o.createDiv();v.setAttr("data-icon",k),v.style.display="flex",v.style.alignItems="center",v.style.justifyContent="center",v.style.aspectRatio="1",v.style.borderRadius="6px",v.style.cursor="var(--cursor-link, pointer)",v.style.transition="background 80ms",v.setAttr("title",k),k===this.selected?(v.style.background="var(--interactive-accent)",v.style.color="var(--text-on-accent)"):v.style.color="var(--text-muted)";let L=v.createSpan();L.style.display="flex",(0,h.setIcon)(L,k),v.addEventListener("mouseenter",()=>{k!==this.selected&&(v.style.background="var(--background-modifier-hover)")}),v.addEventListener("mouseleave",()=>{k!==this.selected&&(v.style.background="")}),v.addEventListener("click",()=>{this.selected=k,l(F),i.empty(),(0,h.setIcon)(i,k),t.setText(k),o.querySelectorAll("div[data-icon]").forEach(K=>{let P=K;P.getAttr("data-icon")===k?(P.style.background="var(--interactive-accent)",P.style.color="var(--text-on-accent)"):(P.style.background="",P.style.color="var(--text-muted)")})})}r.setText(b.length+" of "+this.allIcons.length+" icons")};a.addEventListener("input",()=>{window.clearTimeout(c),c=window.setTimeout(()=>l(a.value),60)}),a.addEventListener("keydown",F=>{F.key==="Escape"&&this.close()});let m=e.createDiv({cls:"modal-button-container"});m.createEl("button",{text:"No icon",cls:"waypoint-icon-clear"}).addEventListener("click",()=>{this.onSubmit(""),this.close()}),m.createEl("button",{text:"Cancel"}).addEventListener("click",()=>this.close());let S=m.createEl("button",{text:"Save",cls:"mod-cta"});S.style.marginLeft="8px",S.addEventListener("click",()=>{this.onSubmit(this.selected),this.close()})}onClose(){this.contentEl.empty()}async loadIcons(){let e=await be();this.tagsMap=e,this.allIcons=Object.keys(e).sort()}},De={file:[],folder:[],star:[],heart:[],bookmark:[],flag:[],pin:[],tag:[],book:[],"book-open":[],library:[],calendar:[],"calendar-days":[],clock:[],home:[],inbox:[],mail:[],search:[],settings:[],cog:[],user:[],users:[],zap:[],sparkles:[],target:[],link:[],globe:[],edit:[],pencil:[],anchor:[],award:[],bell:[],"bell-ring":[],brain:[],briefcase:[],camera:[],"chart-bar":[],"chart-line":[],"chart-pie":[],check:[],"check-circle":[],"chevron-down":[],"chevron-left":[],"chevron-right":[],"chevron-up":[],circle:[],clipboard:[],code:[],command:[],compass:[],copy:[],"credit-card":[],crown:[],database:[],download:[],"external-link":[],eye:[],"eye-off":[],"file-text":[],filter:[],fingerprint:[],flashlight:[],"folder-open":[],"folder-plus":[],gift:[],"git-branch":[],"git-commit":[],"git-merge":[],"git-pull-request":[],github:[],grid:[],hash:[],headphones:[],image:[],info:[],key:[],layers:[],layout:[],"life-buoy":[],"link-2":[],list:[],loader:[],lock:[],"log-in":[],"log-out":[],map:[],"map-pin":[],maximize:[],megaphone:[],menu:[],"message-circle":[],"message-square":[],mic:[],minimize:[],moon:[],"more-horizontal":[],"more-vertical":[],"mouse-pointer":[],move:[],music:[],navigation:[],"navigation-2":[],package:[],palette:[],paperclip:[],pause:[],phone:[],play:[],plus:[],"plus-circle":[],power:[],printer:[],radio:[],"refresh-cw":[],repeat:[],"rotate-ccw":[],"rotate-cw":[],rss:[],save:[],scissors:[],screen:[],send:[],server:[],share:[],"share-2":[],shield:[],"shield-off":[],"shopping-bag":[],"shopping-cart":[],shuffle:[],sidebar:[],slack:[],slash:[],sliders:[],smartphone:[],smile:[],speaker:[],square:[],"stop-circle":[],sun:[],sunrise:[],sunset:[],swords:[],table:[],tablet:[],terminal:[],thermometer:[],"thumbs-down":[],"thumbs-up":[],"toggle-left":[],"toggle-right":[],tool:[],trash:[],"trash-2":[],trello:[],"trending-down":[],"trending-up":[],triangle:[],truck:[],tv:[],twitter:[],type:[],umbrella:[],unlock:[],upload:[],"user-check":[],"user-minus":[],"user-plus":[],"user-x":[],video:[],"video-off":[],voicemail:[],volume:[],"volume-1":[],"volume-2":[],"volume-x":[],watch:[],wifi:[],"wifi-off":[],wind:[],x:[],"x-circle":[],"x-square":[],youtube:[],"zap-off":[],"zoom-in":[],"zoom-out":[],"arrow-down":[],"arrow-left":[],"arrow-right":[],"arrow-up":[],airplay:[],"alarm-clock":[],archive:[],armchair:[],atom:[],baby:[],backpack:[],badge:[],"badge-check":[],ban:[],banknote:[],barcode:[],bath:[],battery:[],"battery-charging":[],beer:[],bike:[],bird:[],bluetooth:[],bolt:[],bone:[],"bookmark-plus":[],bot:[],box:[],bug:[],building:[],bus:[],cake:[],calculator:[],car:[],"clipboard-check":[],cloud:[],"cloud-download":[],"cloud-lightning":[],"cloud-rain":[],"cloud-sun":[],"cloud-upload":[],clover:[],coffee:[],coins:[],contact:[],cookie:[],"corner-down-left":[],"corner-down-right":[],"corner-up-left":[],"corner-up-right":[],crosshair:[],"dice-1":[],"dice-6":[],"dollar-sign":[],"door-open":[],drama:[],droplet:[],drum:[],egg:[],equal:[],euro:[],factory:[],fan:[],feather:[],film:[],fish:[],flame:[],flask:[],flower:[],frown:[],fuel:[],gamepad:[],gauge:[],gem:[],ghost:[],glasses:[],"graduation-cap":[],hammer:[],"hard-drive":[],haze:[],"help-circle":[],"ice-cream":[],infinity:[],italic:[],"japanese-yen":[],keyboard:[],knife:[],lamp:[],landmark:[],languages:[],laptop:[],laugh:[],leaf:[],lightbulb:[],"list-plus":[],magnet:[],"mail-plus":[],meh:[],microscope:[],milestone:[],"minimize-2":[],monitor:[],mountain:[],mouse:[],network:[],newspaper:[],"package-check":[],"package-search":[],"paint-bucket":[],parking:[],"party-popper":[],"pen-tool":[],percent:[],"person-standing":[],"picture-in-picture-2":[],plane:[],plug:[],podcast:[],pointer:[],"pound-sterling":[],puzzle:[],"qr-code":[],rabbit:[],radar:[],rainbow:[],rocket:[],"roller-coaster":[],route:[],ruler:[],sailboat:[],scale:[],scan:[],school:[],ship:[],shirt:[],"shopping-basket":[],shovel:[],sigma:[],siren:[],skull:[],snowflake:[],soup:[],space:[],sparkle:[],stamp:[],store:[],subscript:[],superscript:[],syringe:[],tent:[],"tent-tree":[],"test-tube":[],theater:[],timer:[],train:[],"tree-deciduous":[],"tree-pine":[],trophy:[],typing:[],utensils:[],vibrate:[],wallet:[],wand:[],warehouse:[],waves:[],webcam:[],wheat:[],wine:[],wrench:[]};function X(p,d,e){return!p||!d?null:p===d?e:p.startsWith(d+"/")?e+p.slice(d.length):null}var G=class extends f.Plugin{constructor(){super(...arguments);this.recentFiles=[];this.savePromise=Promise.resolve();this.markdownBasenames=new Set;this.dateSystemIndicators=null;this.dateSystemIndicatorKey="";this.indicatorModeMigrated=!1}async onload(){console.debug("Waypoint: loading plugin v"+this.manifest.version);let e=await this.loadData(),n=this.applySettings(e);this.applyWaypointData(e),n&&this.persistAll(),this.registerView(E,s=>new W(s,this)),this.addSettingTab(new V(this.app,this,this.settings,()=>{this.enforceRecentFilesLimit(),this.invalidateDateSystemIndicators(),this.redrawAll()})),this.addCommand({id:"waypoint-open-view",name:"Open Waypoint sidebar",callback:async()=>{let s=this.app.workspace.getLeavesOfType(E);if(s.length>0)await this.app.workspace.revealLeaf(s[0]);else{let r=this.app.workspace.getLeftLeaf(!1);r&&(await r.setViewState({type:E}),await this.app.workspace.revealLeaf(r))}}}),this.addCommand({id:"waypoint-add-bookmark",name:"Add current file as Waypoint bookmark",callback:async()=>{let s=this.app.workspace.getActiveFile();if(!s){new f.Notice("No active file");return}this.addBookmark(s.path,s.basename,"file"),new f.Notice(`Bookmarked: ${s.basename}`)}}),this.addCommand({id:"waypoint-go-to-daily",name:"Go to daily note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"d"}],callback:async()=>{await this.openPeriodNote("day",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-weekly",name:"Go to weekly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"w"}],callback:async()=>{await this.openPeriodNote("week",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-monthly",name:"Go to monthly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"m"}],callback:async()=>{await this.openPeriodNote("month",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-quarterly",name:"Go to quarterly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"q"}],callback:async()=>{await this.openPeriodNote("quarter",(0,f.moment)())}}),this.addCommand({id:"waypoint-go-to-yearly",name:"Go to yearly note",hotkeys:[{modifiers:["Mod","Shift","Alt"],key:"y"}],callback:async()=>{await this.openPeriodNote("year",(0,f.moment)())}});let i=["next","prev"],t=["daily","weekly","monthly","quarterly","yearly"],a={next:"Next",prev:"Previous"};for(let s of t)for(let r of i){let c=`waypoint-go-to-${r}-${s}`,l=`${a[r]} ${s} note`;this.addCommand({id:c,name:l,callback:async()=>{await this.navigatePeriodNote(r)}})}this.registerEvent(this.app.workspace.on("file-open",s=>{s&&this.onFileOpen(s)})),this.registerEvent(this.app.vault.on("create",s=>this.onVaultCreate(s))),this.registerEvent(this.app.vault.on("delete",s=>this.onVaultDelete(s))),this.registerEvent(this.app.vault.on("rename",(s,r)=>this.onRename(s,r))),this.registerEvent(this.app.vault.on("modify",s=>this.onFileModify(s))),this.app.workspace.onLayoutReady(()=>{if(this.buildMarkdownIndex(),this.app.workspace.getLeavesOfType(E).length===0){let r=this.app.workspace.getLeftLeaf(!1);r&&r.setViewState({type:E})}else this.broadcastRedraw()});let o=new Date().toDateString();this.registerInterval(window.setInterval(()=>{let s=new Date().toDateString();s!==o&&(o=s,this.redrawAll())},6e5))}async onunload(){this.app.workspace.detachLeavesOfType(E)}applySettings(e){var a;let n=(e==null?void 0:e.settings)||{};this.settings=Object.assign({},T,n),this.settings.recentFiles=Object.assign({},T.recentFiles,n.recentFiles||{}),this.settings.calendar=Object.assign({},T.calendar,n.calendar||{}),this.settings.display=Object.assign({},T.display,n.display||{});for(let o of Se)this.settings[o]=Object.assign({},T[o],n[o]||{});this.settings.dateSystems=Array.isArray(n.dateSystems)?n.dateSystems.map(o=>{let s=T.dateSystems.find(r=>r.id===o.id);return Object.assign({},s||$,o)}):T.dateSystems.map(o=>Object.assign({},o));let i=(e==null?void 0:e.indicatorModeMigrated)===!0,t=!1;return!i&&((a=n.calendar)==null?void 0:a.indicatorMode)==="any"&&(this.settings.calendar.indicatorMode="systems",t=!0),this.indicatorModeMigrated=!0,t}applyWaypointData(e){let n=(e==null?void 0:e.waypointData)||{};this.waypointData={bookmarks:Array.isArray(n.bookmarks)?n.bookmarks:[],recentFiles:Array.isArray(n.recentFiles)?n.recentFiles:[]},this.recentFiles=this.waypointData.recentFiles,this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems),this.waypointData.recentFiles=this.recentFiles)}persistAll(){let e=this.savePromise.then(()=>(this.waypointData.recentFiles=this.recentFiles,this.saveData({settings:this.settings,waypointData:this.waypointData,indicatorModeMigrated:this.indicatorModeMigrated})));return this.savePromise=e.catch(()=>{}),e}async saveSettings(){await this.persistAll()}async saveWaypointData(){await this.persistAll()}enforceRecentFilesLimit(){this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems),this.persistRecentFiles())}persistRecentFiles(){this.waypointData.recentFiles=this.recentFiles,window.clearTimeout(this.recentFilesSaveTimer),this.recentFilesSaveTimer=window.setTimeout(()=>{this.saveWaypointData()},300)}onFileOpen(e){this.settings.recentFiles.updateOn==="file-open"&&this.addToRecentFiles(e)}onFileModify(e){this.settings.recentFiles.updateOn==="file-edit"&&e instanceof f.TFile&&(this.recentFiles.length>0&&this.recentFiles[0].path===e.path||this.addToRecentFiles(e))}addToRecentFiles(e){this.isOmittedFromRecentFiles(e)||(this.recentFiles=this.recentFiles.filter(n=>n.path!==e.path),this.recentFiles.unshift({path:e.path,basename:e.basename}),this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems)),this.persistRecentFiles(),this.broadcastRedraw())}isOmittedFromRecentFiles(e){for(let o of this.settings.recentFiles.omittedPaths)try{if(new RegExp(o).test(e.path))return!0}catch(s){}let n=this.settings.recentFiles.omittedTags;if(n.length===0)return!1;let i=this.app.metadataCache.getFileCache(e),t=(i?(0,f.getAllTags)(i):null)||[];if(t.length===0)return!1;let a=t.map(o=>o.replace(/^#/,""));for(let o of n)try{let s=new RegExp(o);if(a.some(r=>s.test(r)))return!0}catch(s){}return!1}onRename(e,n){this.invalidateDateSystemIndicators();let i=this.syncIndexForRename(e,n),t=!1;for(let o of this.recentFiles){let s=X(o.path,n,e.path);s!==null&&(o.path=s,o.basename=pe(s),t=!0)}let a=o=>{for(let s of o){if(s.filePath){let r=X(s.filePath,n,e.path);r!==null&&(s.filePath=r,t=!0)}s.children&&a(s.children)}};a(this.waypointData.bookmarks),t&&(this.waypointData.recentFiles=this.recentFiles,this.persistAll()),(t||i)&&this.broadcastRedraw()}onVaultCreate(e){e instanceof f.TFile&&e.extension==="md"&&(this.markdownBasenames.add(e.basename),this.invalidateDateSystemIndicators()),this.broadcastRedraw()}onVaultDelete(e){e instanceof f.TFile&&e.extension==="md"&&(this.removeFromMarkdownIndex(e.basename,e.path),this.invalidateDateSystemIndicators()),this.broadcastRedraw()}buildMarkdownIndex(){this.markdownBasenames.clear();for(let e of this.app.vault.getMarkdownFiles())this.markdownBasenames.add(e.basename)}invalidateDateSystemIndicators(){this.dateSystemIndicators=null,this.dateSystemIndicatorKey=""}removeFromMarkdownIndex(e,n){return!this.markdownBasenames.has(e)||this.app.vault.getMarkdownFiles().some(t=>t.basename===e&&t.path!==n)?!1:(this.markdownBasenames.delete(e),!0)}syncIndexForRename(e,n){if(!(e instanceof f.TFile))return!1;let i=!1,t=pe(n);return n.toLowerCase().endsWith(".md")&&(t!==e.basename||e.extension!=="md")&&(i=this.removeFromMarkdownIndex(t,n)),e.extension==="md"&&!this.markdownBasenames.has(e.basename)&&(this.markdownBasenames.add(e.basename),i=!0),i}hasNoteForDate(e){return this.markdownBasenames.has(e)}addBookmark(e,n,i="file",t=""){let o={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:i,label:n,filePath:i==="file"?e:"",icon:t,children:[],collapsed:!1,indent:0};return this.waypointData.bookmarks.push(o),this.saveWaypointData(),this.broadcastRedraw(),o}removeBookmark(e){let n=i=>{let t=i.findIndex(a=>a.id===e);if(t>=0)return i.splice(t,1),!0;for(let a of i)if(a.children&&n(a.children))return!0;return!1};n(this.waypointData.bookmarks),this.saveWaypointData(),this.broadcastRedraw()}updateBookmark(e,n){let i=a=>{for(let o of a){if(o.id===e)return o;if(o.children){let s=i(o.children);if(s)return s}}return null},t=i(this.waypointData.bookmarks);t&&(Object.assign(t,n),this.saveWaypointData(),this.broadcastRedraw())}periodAsDateSystem(e){let n=j[e],i=this.settings[n.key];return{id:n.key,name:n.label,folder:i.folder,nameFormat:i.nameFormat,templateFile:i.templateFile,typeProperty:i.typeProperty,icon:"calendar",indicatorColor:this.settings.calendar.dailyIndicatorColor}}dateSystems(){return[this.periodAsDateSystem("day"),...this.settings.dateSystems]}findDateSystemNotes(e){let n=this.dateSystems().map(i=>{let t=R(i.nameFormat);return{result:{system:i,notes:[],multiple:t.hasTitle},before:B(e,t.before),after:B(e,t.after),hasTitle:t.hasTitle,skip:!A(i.nameFormat)}});for(let i of this.app.vault.getMarkdownFiles())for(let t of n){if(t.skip)continue;let a=t.result.system;U(i.path,a.folder)&&Z(i.basename,t.before,t.after,t.hasTitle)&&t.result.notes.push({file:i,label:t.hasTitle?re(i.basename,t.before,t.after):a.name})}for(let i of n)i.result.notes.sort((t,a)=>t.file.basename.localeCompare(a.file.basename));return n.filter(i=>!i.skip).map(i=>i.result)}getDateSystemIndicators(e){var s;let n=e.map(r=>r.format("YYYY-MM-DD")),i=this.dateSystems().filter(r=>A(r.nameFormat)).map(r=>{let c=R(r.nameFormat);return{system:r,hasTitle:c.hasTitle,dates:e.map((l,m)=>({dateStr:n[m],before:B(l,c.before),after:B(l,c.after)}))}}),t=JSON.stringify({dates:n,systems:i.map(({system:r})=>[r.id,r.name,r.folder,r.nameFormat,r.indicatorColor])});if(this.dateSystemIndicators&&this.dateSystemIndicatorKey===t)return this.dateSystemIndicators;let a=new Map;for(let r of n)a.set(r,new Set);for(let r of this.app.vault.getMarkdownFiles())for(let c of i)if(U(r.path,c.system.folder))for(let l of c.dates)Z(r.basename,l.before,l.after,c.hasTitle)&&((s=a.get(l.dateStr))==null||s.add(c.system.id));let o=new Map;for(let r of n){let c=a.get(r);o.set(r,i.filter(({system:l})=>c==null?void 0:c.has(l.id)).map(({system:l})=>({id:l.id,name:l.name,color:l.indicatorColor})))}return this.dateSystemIndicatorKey=t,this.dateSystemIndicators=o,o}async openDateSystemNote(e,n,i){if(!A(e.nameFormat)){new f.Notice(`Waypoint: ${e.name||"This"} name format needs a date placeholder.`);return}let t=R(e.nameFormat),a=B(n,t.before),o=B(n,t.after),s;if(t.hasTitle){let m=le((i==null?void 0:i.title)||"");if(!m){new f.Notice(`Waypoint: a ${e.name.toLowerCase()} note needs a title.`);return}s=a+m+o}else s=a+o;let r=e.folder?`${e.folder}/${s}.md`:`${s}.md`,c=this.app.vault.getFileByPath(r);if(!c&&(c=await this.createDatedNote(r,e,n),!c))return;if(i!=null&&i.reuseExistingLeaf&&!i.leaf){let m=this.app.workspace.getLeavesOfType("markdown").find(u=>{var g;return((g=u.getViewState().state)==null?void 0:g.file)===c.path});if(m){await this.app.workspace.revealLeaf(m),this.app.workspace.setActiveLeaf(m,{focus:!0});return}}await((i==null?void 0:i.leaf)||this.app.workspace.getLeaf(!1)).openFile(c)}async openPeriodNote(e,n,i){await this.openDateSystemNote(this.periodAsDateSystem(e),n,{leaf:i,reuseExistingLeaf:this.settings.reusePeriodicNoteTabs})}async createDatedNote(e,n,i){let t=n.name.toLowerCase(),a=e.lastIndexOf("/"),o=a<0?"":e.slice(0,a);try{await this.ensureFolderExists(o)}catch(m){return new f.Notice(`Waypoint: could not create the folder "${o}" for the ${t} note. +${ee(m)} +Check Settings \u2192 Waypoint Sidebar \u2192 Periodic Notes.`,O),null}let s=n.templateFile,r=this.resolveTemplateFile(s),c;if(r)try{c=await this.app.vault.read(r)}catch(m){return new f.Notice(`Waypoint: could not read the template "${r.path}" for the ${t} note. +`+ee(m),O),null}else c=`--- type: ${n.typeProperty} -date: ${a.format("YYYY-MM-DD")} +date: ${i.format("YYYY-MM-DD")} --- -`;let l;try{l=await this.app.vault.create(e,c)}catch(h){return new f.Notice(`Waypoint: could not create the ${t} note at "${e}". -${ee(h)}`,O),null}return s&&!r?new f.Notice(`Created ${t} note: ${l.basename} -Template "${s}" was not found, so a basic note was created instead.`,O):new f.Notice(`Created ${t} note: ${l.basename}`),l}async ensureFolderExists(e){if(!e||this.app.vault.getAbstractFileByPath(e)instanceof f.TFolder)return;let n="";for(let a of e.split("/"))if(a&&(n=n?`${n}/${a}`:a,!(this.app.vault.getAbstractFileByPath(n)instanceof f.TFolder)))try{await this.app.vault.createFolder(n)}catch(t){if(!(this.app.vault.getAbstractFileByPath(n)instanceof f.TFolder))throw t}}resolveTemplateFile(e){if(!e)return null;let n=e.toLowerCase().endsWith(".md")?e:`${e}.md`;return this.app.vault.getFileByPath(n)}detectPeriodType(e){for(let n of de){let a=this.settings[j[n].key].nameFormat;if(!a)continue;let t=(0,f.moment)(e,a,!0);if(t.isValid())return{period:n,date:t}}return null}async navigatePeriodNote(e){let n=this.app.workspace.getActiveFile();if(!n){new f.Notice("No active file");return}let a=this.detectPeriodType(n.basename);if(!a){let r=de.map(c=>`${j[c].label.toLowerCase()} "${this.settings[j[c].key].nameFormat}"`).join(", ");new f.Notice(`Waypoint: "${n.basename}" does not match any configured periodic note format. -Expected one of: ${r}.`,O);return}let{period:t,date:i}=a,o=e==="next"?1:-1,s=t==="quarter"?i.clone().add(o*3,"months"):i.clone().add(o,`${t}s`);await this.openPeriodNote(t,s)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let e=this.app.workspace.getLeavesOfType(E);for(let n of e)n.view instanceof W&&n.view.redraw()}},Se=["daily","weekly","monthly","quarterly","yearly"],j={day:{key:"daily",label:"Daily"},week:{key:"weekly",label:"Weekly"},month:{key:"monthly",label:"Monthly"},quarter:{key:"quarterly",label:"Quarterly"},year:{key:"yearly",label:"Yearly"}},de=["day","week","month","quarter","year"];function pe(p){return p.slice(p.lastIndexOf("/")+1).replace(/\.[^/.]+$/,"")}var O=1e4;function ee(p){return p instanceof Error?p.message:String(p)}function B(p,d){return d?p.format(d):""} +`;let l;try{l=await this.app.vault.create(e,c)}catch(m){return new f.Notice(`Waypoint: could not create the ${t} note at "${e}". +${ee(m)}`,O),null}return s&&!r?new f.Notice(`Created ${t} note: ${l.basename} +Template "${s}" was not found, so a basic note was created instead.`,O):new f.Notice(`Created ${t} note: ${l.basename}`),l}async ensureFolderExists(e){if(!e||this.app.vault.getAbstractFileByPath(e)instanceof f.TFolder)return;let n="";for(let i of e.split("/"))if(i&&(n=n?`${n}/${i}`:i,!(this.app.vault.getAbstractFileByPath(n)instanceof f.TFolder)))try{await this.app.vault.createFolder(n)}catch(t){if(!(this.app.vault.getAbstractFileByPath(n)instanceof f.TFolder))throw t}}resolveTemplateFile(e){if(!e)return null;let n=e.toLowerCase().endsWith(".md")?e:`${e}.md`;return this.app.vault.getFileByPath(n)}detectPeriodType(e){for(let n of de){let i=this.settings[j[n].key].nameFormat;if(!i)continue;let t=(0,f.moment)(e,i,!0);if(t.isValid())return{period:n,date:t}}return null}async navigatePeriodNote(e){let n=this.app.workspace.getActiveFile();if(!n){new f.Notice("No active file");return}let i=this.detectPeriodType(n.basename);if(!i){let r=de.map(c=>`${j[c].label.toLowerCase()} "${this.settings[j[c].key].nameFormat}"`).join(", ");new f.Notice(`Waypoint: "${n.basename}" does not match any configured periodic note format. +Expected one of: ${r}.`,O);return}let{period:t,date:a}=i,o=e==="next"?1:-1,s=t==="quarter"?a.clone().add(o*3,"months"):a.clone().add(o,`${t}s`);await this.openPeriodNote(t,s)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let e=this.app.workspace.getLeavesOfType(E);for(let n of e)n.view instanceof W&&n.view.redraw()}},Se=["daily","weekly","monthly","quarterly","yearly"],j={day:{key:"daily",label:"Daily"},week:{key:"weekly",label:"Weekly"},month:{key:"monthly",label:"Monthly"},quarter:{key:"quarterly",label:"Quarterly"},year:{key:"yearly",label:"Yearly"}},de=["day","week","month","quarter","year"];function pe(p){return p.slice(p.lastIndexOf("/")+1).replace(/\.[^/.]+$/,"")}var O=1e4;function ee(p){return p instanceof Error?p.message:String(p)}function B(p,d){return d?p.format(d):""} diff --git a/manifest.json b/manifest.json index dc73f85..12f56c3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "waypoint-sidebar", "name": "Waypoint Sidebar", - "version": "1.7.1", + "version": "1.8.0", "minAppVersion": "1.4.10", "description": "Calendar, recent files, and custom bookmarks sidebar.", "author": "Olivier", diff --git a/package-lock.json b/package-lock.json index e1ab169..d2a77b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "waypoint", - "version": "1.5.1", + "version": "1.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "waypoint", - "version": "1.5.1", + "version": "1.8.0", "license": "MIT", "devDependencies": { "builtin-modules": "4.0.0", diff --git a/package.json b/package.json index 05715f9..47ff0a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waypoint", - "version": "1.7.1", + "version": "1.8.0", "description": "Calendar, recent files, and custom bookmarks sidebar.", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index a2a2443..f1aa892 100644 --- a/src/main.ts +++ b/src/main.ts @@ -738,13 +738,14 @@ export default class WaypointPlugin extends Plugin { * Open (creating if needed) the note `system` holds for `date`. * * `opts.title` fills the `{title}` token of a many-per-date system and is - * ignored by systems without one. Opens in `opts.leaf` when given, - * otherwise in the active leaf. + * ignored by systems without one. An explicit `opts.leaf` takes precedence; + * otherwise `opts.reuseExistingLeaf` reveals an open Markdown tab for the + * exact file path, falling back to the active leaf when none is open. */ async openDateSystemNote( system: DateSystemSettings, date: moment.Moment, - opts?: { title?: string; leaf?: WorkspaceLeaf }, + opts?: { title?: string; leaf?: WorkspaceLeaf; reuseExistingLeaf?: boolean }, ): Promise { if (!formatHasDateToken(system.nameFormat)) { @@ -777,16 +778,30 @@ export default class WaypointPlugin extends Plugin { if (!file) return; } + if (opts?.reuseExistingLeaf && !opts.leaf) { + // View state also identifies deferred tabs whose view is not loaded yet. + const existing = this.app.workspace.getLeavesOfType('markdown') + .find(leaf => leaf.getViewState().state?.file === file.path); + if (existing) { + await this.app.workspace.revealLeaf(existing); + this.app.workspace.setActiveLeaf(existing, { focus: true }); + return; + } + } + const target = opts?.leaf || this.app.workspace.getLeaf(false); await target.openFile(file); } /** * Open (creating if needed) the period note for `date`. - * Opens in `leaf` when given, otherwise in the active leaf. + * An explicit `leaf` wins; otherwise reuse an open tab when enabled. */ async openPeriodNote(period: PeriodKey, date: moment.Moment, leaf?: WorkspaceLeaf): Promise { - await this.openDateSystemNote(this.periodAsDateSystem(period), date, { leaf }); + await this.openDateSystemNote(this.periodAsDateSystem(period), date, { + leaf, + reuseExistingLeaf: this.settings.reusePeriodicNoteTabs, + }); } /** diff --git a/src/settings-tab.ts b/src/settings-tab.ts index 6494d2a..c79adc9 100644 --- a/src/settings-tab.ts +++ b/src/settings-tab.ts @@ -157,6 +157,17 @@ export class WaypointSettingTab extends PluginSettingTab { // ═══════════════════════════════ private renderPeriodicTab(container: HTMLElement): void { + new Setting(container) + .setName('Use existing tabs') + .setDesc('If a periodic note is already open, switch to its tab instead of opening it again.') + .addToggle((toggle) => { + toggle + .setValue(this.settings.reusePeriodicNoteTabs) + .onChange((value) => { + this.settings.reusePeriodicNoteTabs = value; + this.saveAndRefresh(); + }); + }); this.addPeriodNoteSettings(container, 'Daily', this.settings.daily); this.addPeriodNoteSettings(container, 'Weekly', this.settings.weekly); this.addPeriodNoteSettings(container, 'Monthly', this.settings.monthly); diff --git a/src/settings.ts b/src/settings.ts index 36857a7..624fa1f 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -71,6 +71,8 @@ export interface DisplaySettings { export interface WaypointSettings { calendar: CalendarSettings; daily: PeriodNoteSettings; + /** Focus an open tab when opening a periodic note without an explicit leaf. */ + reusePeriodicNoteTabs: boolean; weekly: PeriodNoteSettings; monthly: PeriodNoteSettings; quarterly: PeriodNoteSettings; @@ -94,6 +96,7 @@ export const DEFAULT_SETTINGS: WaypointSettings = { nameFormat: 'YYYY-MM-DD', typeProperty: 'daily-note', }, + reusePeriodicNoteTabs: false, weekly: { folder: 'periodic/weekly', templateFile: 'Templates/Weekly note',