Files
waypoint/main.js
T
olivier d22b53253e chore: rebuild bundle
Regenerated main.js from the fixed sources (this is what BRAT and manual
installs ship). The bare 'monday' global reference is gone from the bundle.
2026-09-07 20:04:01 -04:00

22 lines
47 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
*/
var z=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var X=(f,m)=>{for(var e in m)z(f,e,{get:m[e],enumerable:!0})},J=(f,m,e,i)=>{if(m&&typeof m=="object"||typeof m=="function")for(let s of Z(m))!U.call(f,s)&&s!==e&&z(f,s,{get:()=>m[s],enumerable:!(i=_(m,s))||i.enumerable});return f};var ee=f=>J(z({},"__esModule",{value:!0}),f);var oe={};X(oe,{default:()=>Y});module.exports=ee(oe);var v=require("obsidian");var P={calendar:{firstDayOfWeek:1,showNoteIndicators:!0},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"},recentFiles:{maxItems:50,updateOn:"file-open",omittedPaths:[],omittedTags:[],filterTags:[]},display:{rowSize:26,rowSpacing:2,indentSize:16,fontSize:13,iconSize:16,calendarCellSize:32}};var w=require("obsidian");var N=class extends w.PluginSettingTab{constructor(e,i,s,a){super(e,i);this.activeTab="calendar";this.plugin=i,this.settings=s,this.onSettingsChange=a}display(){let{containerEl:e}=this;e.empty();let i=e.createDiv({cls:"waypoint-settings-tabs"}),s=[{key:"calendar",label:"Calendar"},{key:"periodic",label:"Periodic Notes"},{key:"recent",label:"Recent Files"},{key:"display",label:"Display"},{key:"about",label:"About"}];for(let t of s)i.createEl("button",{cls:`waypoint-settings-tab${this.activeTab===t.key?" is-active":""}`,text:t.label}).addEventListener("click",()=>{this.activeTab=t.key,this.display()});let a=e.createDiv({cls:"waypoint-settings-content"});switch(this.activeTab){case"calendar":this.renderCalendarTab(a);break;case"periodic":this.renderPeriodicTab(a);break;case"recent":this.renderRecentTab(a);break;case"display":this.renderDisplayTab(a);break;case"about":this.renderAboutTab(a);break}}renderCalendarTab(e){new w.Setting(e).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(i=>{i.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(s=>{this.settings.calendar.firstDayOfWeek=parseInt(s,10),this.saveAndRefresh()})}),new w.Setting(e).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(i=>{i.setValue(this.settings.calendar.showNoteIndicators).onChange(s=>{this.settings.calendar.showNoteIndicators=s,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,i,s){new w.Setting(e).setHeading().setName(i),new w.Setting(e).setName("Folder").setDesc(`Folder path for ${i.toLowerCase()} notes.`).addText(a=>{a.setPlaceholder("periodic/daily"),a.setValue(s.folder),a.onChange(t=>{s.folder=t,this.saveAndRefresh()})}),new w.Setting(e).setName("Name format").setDesc(`Date format for ${i.toLowerCase()} note filenames (moment.js format).`).addText(a=>{a.setPlaceholder("yyyy-MM-dd"),a.setValue(s.nameFormat),a.onChange(t=>{s.nameFormat=t,this.saveAndRefresh()})}),new w.Setting(e).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(a=>{a.setPlaceholder("Templates/Daily note"),a.setValue(s.templateFile),a.onChange(t=>{s.templateFile=t,this.saveAndRefresh()})}),new w.Setting(e).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(a=>{a.setPlaceholder("daily-note"),a.setValue(s.typeProperty),a.onChange(t=>{s.typeProperty=t,this.saveAndRefresh()})})}renderRecentTab(e){new w.Setting(e).setName("Max items").setDesc("Maximum number of recent files to track.").addText(t=>{t.inputEl.setAttr("type","number"),t.inputEl.setAttr("placeholder","50"),t.setValue(String(this.settings.recentFiles.maxItems)),t.inputEl.onblur=()=>{let n=parseInt(t.getValue(),10);!isNaN(n)&&n>0&&(this.settings.recentFiles.maxItems=n,this.saveAndRefresh())}}),new w.Setting(e).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(t=>{t.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(n=>{this.settings.recentFiles.updateOn=n,this.saveAndRefresh()})});let i=new DocumentFragment;i.appendText("Regex patterns for paths to exclude. One per line."),new w.Setting(e).setName("Omitted paths").setDesc(i).addTextArea(t=>{t.inputEl.setAttr("rows",4),t.setPlaceholder(`^archives/
\\.png$`),t.setValue(this.settings.recentFiles.omittedPaths.join(`
`)),t.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=t.getValue().split(`
`).filter(n=>n.trim()),this.saveAndRefresh()}});let s=new DocumentFragment;s.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new w.Setting(e).setName("Omitted tags").setDesc(s).addTextArea(t=>{t.inputEl.setAttr("rows",4),t.setPlaceholder(`ignore
archive`),t.setValue(this.settings.recentFiles.omittedTags.join(`
`)),t.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=t.getValue().split(`
`).filter(n=>n.trim()),this.saveAndRefresh()}});let a=new DocumentFragment;a.appendText("Tags to show as filter pills above the file list. One per line. Leave empty to auto-detect from frontmatter `type` property."),new w.Setting(e).setName("Filter tags").setDesc(a).addTextArea(t=>{t.inputEl.setAttr("rows",4),t.setPlaceholder(`meeting
person
project`),t.setValue(this.settings.recentFiles.filterTags.join(`
`)),t.inputEl.onblur=()=>{this.settings.recentFiles.filterTags=t.getValue().split(`
`).filter(n=>n.trim()),this.saveAndRefresh()}})}renderDisplayTab(e){new w.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 w.Setting(e).setHeading().setName("Calendar"),this.addSliderSetting(e,"Cell size","Height of calendar day cells.",this.settings.display,"calendarCellSize",20,48,2,"px"),new w.Setting(e).addButton(i=>i.setButtonText("Reset to defaults").onClick(()=>{this.settings.display={...P.display},this.saveAndRefresh(),this.display()}))}addSliderSetting(e,i,s,a,t,n,o,r,c){let l=new w.Setting(e).setName(i).setDesc(`${s} (${a[t]}${c})`);l.addSlider(h=>{h.setLimits(n,o,r).setValue(a[t]).setDynamicTooltip().onChange(p=>{a[t]=p,l.setDesc(`${s} (${p}${c})`),this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveSettings(),this.onSettingsChange()}renderAboutTab(e){let i=this.plugin.manifest.version,s=e.createDiv();s.style.display="flex",s.style.alignItems="center",s.style.gap="12px",s.style.marginBottom="16px";let a=s.createDiv();a.style.display="flex",a.style.alignItems="center",a.style.justifyContent="center",a.style.width="48px",a.style.height="48px",a.style.borderRadius="12px",a.style.background="var(--interactive-accent)",a.style.color="var(--text-on-accent)",a.style.fontSize="24px",(0,w.setIcon)(a,"compass");let t=s.createDiv(),n=t.createEl("h2",{text:"Waypoint Sidebar"});n.style.margin="0",n.style.lineHeight="1.2";let o=t.createDiv({text:`v${i}`});o.style.color="var(--text-muted)",o.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=["<p><strong>Waypoint</strong> is a sidebar plugin that brings three essential panels into one view:</p>",'<ul style="padding-left: 20px; margin: 8px 0;">',"<li><strong>Calendar</strong> \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.</li>","<li><strong>Recent Files</strong> \u2014 a list of recently opened files with type filtering, drag-and-drop, and right-click actions.</li>","<li><strong>Bookmarks</strong> \u2014 custom bookmarks with icons, groups, nesting, and drag-and-drop reordering. Separate from Obsidian's native bookmarks.</li>","</ul>",'<p style="color: var(--text-muted); font-size: var(--font-ui-small);">Made by Olivier. Licensed under MIT.</p>'].join(`
`)}};var d=require("obsidian");var I=require("obsidian");function G(f,m,e){let i=(0,I.moment)({year:f,month:m,day:1}),s=(0,I.moment)(i).endOf("month"),a=(0,I.moment)(i).subtract((i.day()-e+7)%7,"days"),t=(0,I.moment)().startOf("day"),n=[],o=(0,I.moment)(a);for(;o.isBefore(s)||o.month()===m;){let r=[];for(let c=0;c<7;c++)r.push({date:(0,I.moment)(o),dayOfMonth:o.date(),isToday:o.isSame(t,"day"),isCurrentMonth:o.month()===m,isoWeekNumber:o.isoWeek()}),o.add(1,"day");if(n.push({weekNumber:r[0].isoWeekNumber,days:r}),n.length>=6)break}return n}var T="waypoint-view";function te(f){return f.dragManager}var L=class extends d.ItemView{constructor(e,i){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,d.moment)().month();this.currentDisplayYear=(0,d.moment)().year();this.dragId=null;this.dropZones=new WeakMap;this.recentFilesFilter=null;this.plugin=i}getViewType(){return T}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let e=this.contentEl.createDiv({cls:"waypoint-section"});e.createDiv({cls:"waypoint-section-header",text:"Calendar"});let i=e.createDiv({cls:"waypoint-calendar"}),s=(0,d.moment)(),a=(0,d.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),t=i.createDiv({cls:"waypoint-calendar-top"}),n=t.createDiv({cls:"waypoint-calendar-breadcrumb"}),o=a.format("[Q]Q"),r=n.createSpan({cls:"waypoint-clickable",text:o});r.addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",a)}),r.addEventListener("mousedown",F=>{F.button===1&&(F.preventDefault(),this.plugin.openPeriodNote("quarter",a,this.app.workspace.getLeaf("tab")))});let c=a.format("MMMM"),l=n.createSpan({cls:"waypoint-clickable",text:c});l.addEventListener("click",()=>{this.plugin.openPeriodNote("month",a)}),l.addEventListener("mousedown",F=>{F.button===1&&(F.preventDefault(),this.plugin.openPeriodNote("month",a,this.app.workspace.getLeaf("tab")))});let h=a.format("YYYY"),p=n.createSpan({cls:"waypoint-clickable",text:h});p.addEventListener("click",()=>{this.plugin.openPeriodNote("year",a)}),p.addEventListener("mousedown",F=>{F.button===1&&(F.preventDefault(),this.plugin.openPeriodNote("year",a,this.app.workspace.getLeaf("tab")))});let u=t.createDiv({cls:"waypoint-calendar-today-group"}),D=u.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,d.setIcon)(D,"chevron-left"),D.addEventListener("click",()=>this.navigateMonth(-1)),u.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,d.moment)().month(),this.currentDisplayYear=(0,d.moment)().year(),this.redraw()});let k=u.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,d.setIcon)(k,"chevron-right"),k.addEventListener("click",()=>this.navigateMonth(1));let b=i.createEl("table"),g=b.createEl("thead").createEl("tr");g.createEl("th",{text:""});let C=["sun","mon","tue","wed","thu","fri","sat"],W=this.plugin.settings.calendar.firstDayOfWeek;for(let F=0;F<7;F++){let B=(W+F)%7;g.createEl("th",{text:C[B]})}let S=b.createEl("tbody"),Q=G(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let F of Q){let B=S.createEl("tr"),O=B.createEl("td",{cls:"waypoint-weeknum"});O.setText(String(F.weekNumber));let H=F.days[0].date;O.addEventListener("click",()=>{this.plugin.openPeriodNote("week",H)}),O.addEventListener("mousedown",E=>{E.button===1&&(E.preventDefault(),this.plugin.openPeriodNote("week",H,this.app.workspace.getLeaf("tab")))});for(let E of F.days){let M=B.createEl("td",{cls:"waypoint-day"});if(M.setText(String(E.dayOfMonth)),E.isCurrentMonth||M.addClass("other-month"),E.isToday&&M.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let A=E.date.format("YYYY-MM-DD");this.plugin.hasNoteForDate(A)&&M.addClass("has-note")}M.addEventListener("click",()=>{this.plugin.openPeriodNote("day",E.date)}),M.addEventListener("mousedown",A=>{A.button===1&&(A.preventDefault(),this.plugin.openPeriodNote("day",E.date,this.app.workspace.getLeaf("tab")))})}}}navigateMonth(e){let i=(0,d.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(e,"month");this.currentDisplayMonth=i.month(),this.currentDisplayYear=i.year(),this.redraw()}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 i=this.plugin.settings.recentFiles.filterTags||[],s={};if(i.length>0){for(let l of i)s[l]=0;for(let l of this.plugin.recentFiles){let h=this.app.vault.getAbstractFileByPath(l.path);if(h instanceof d.TFile){let p=this.app.metadataCache.getFileCache(h),u=(r=p==null?void 0:p.frontmatter)==null?void 0:r.type;u&&typeof u=="string"&&s.hasOwnProperty(u)&&s[u]++}}}else for(let l of this.plugin.recentFiles){let h=this.app.vault.getAbstractFileByPath(l.path);if(h instanceof d.TFile){let p=this.app.metadataCache.getFileCache(h),u=(c=p==null?void 0:p.frontmatter)==null?void 0:c.type;u&&typeof u=="string"&&(s[u]=(s[u]||0)+1)}}if(Object.keys(s).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 p=i.length>0?Object.entries(s):Object.entries(s).sort((u,D)=>D[1]-u[1]);for(let[u,D]of p){let x=l.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter===u?" is-active":""}`});x.setText(`${u} ${D}`),x.addEventListener("click",()=>{this.recentFilesFilter=this.recentFilesFilter===u?null:u,this.redraw()})}}let a=this.plugin.recentFiles;this.recentFilesFilter&&(a=this.plugin.recentFiles.filter(l=>{var p;let h=this.app.vault.getAbstractFileByPath(l.path);if(h instanceof d.TFile){let u=this.app.metadataCache.getFileCache(h);return((p=u==null?void 0:u.frontmatter)==null?void 0:p.type)===this.recentFilesFilter}return!1}));let t=this.app.workspace.getActiveFile(),n=e.createDiv({cls:"nav-folder mod-root"}),o=n.createDiv({cls:"nav-folder-children"});for(let l of a){let h=o.createDiv({cls:"tree-item nav-file"}),p=h.createDiv({cls:"tree-item-self is-clickable nav-file-title"});p.createDiv({cls:"tree-item-inner nav-file-title-content"}).setText(l.basename);let D=p.createDiv({cls:"tree-item-spacer"}),x=p.createDiv({cls:"waypoint-recent-remove"});(0,d.setIcon)(x,"x"),x.addEventListener("click",k=>{k.stopPropagation(),this.plugin.recentFiles=this.plugin.recentFiles.filter(b=>b.path!==l.path),this.plugin.persistRecentFiles(),this.redraw()}),(0,d.setTooltip)(h,l.path),t&&l.path===t.path&&p.addClass("is-active"),p.setAttr("draggable","true"),p.addEventListener("dragstart",k=>{let b=this.app.metadataCache.getFirstLinkpathDest(l.path,"");if(b){let y=te(this.app),g=y.dragFile(k,b);y.onDragStart(k,g)}}),p.addEventListener("mouseover",k=>{this.app.workspace.trigger("hover-link",{event:k,source:T,hoverParent:n,targetEl:h,linktext:l.path})}),p.addEventListener("contextmenu",k=>{let b=new d.Menu;b.addItem(g=>g.setSection("action").setTitle("Open in new tab").setIcon("file-plus").onClick(()=>this.focusFile(l,"tab"))),b.addItem(g=>g.setSection("action").setTitle("Add to bookmarks").setIcon("bookmark").onClick(()=>{this.plugin.addBookmark(l.path,l.basename,"file"),new d.Notice(`Bookmarked: ${l.basename}`)}));let y=this.app.vault.getAbstractFileByPath(l.path);y&&this.app.workspace.trigger("file-menu",b,y,"link-context-menu"),b.showAtPosition({x:k.clientX,y:k.clientY})}),p.addEventListener("click",k=>{let b=d.Keymap.isModEvent(k);this.focusFile(l,b)}),p.addEventListener("mousedown",k=>{k.button===1&&(k.preventDefault(),this.focusFile(l,"tab"))})}}focusFile(e,i){let s=this.app.vault.getFiles().find(a=>a.path===e.path);s?this.app.workspace.getLeaf(i).openFile(s):(new d.Notice("Cannot find file"),this.plugin.recentFiles=this.plugin.recentFiles.filter(a=>a.path!==e.path),this.plugin.persistRecentFiles(),this.redraw())}renderFavorites(){let e=this.contentEl.createDiv({cls:"waypoint-section waypoint-favorites"}),i=e.createDiv({cls:"waypoint-section-header"});i.setText("Waypoint Bookmarks");let s=i.createEl("button",{cls:"waypoint-header-more"});if((0,d.setIcon)(s,"more-horizontal"),(0,d.setTooltip)(s,"Add bookmark"),s.addEventListener("click",a=>{let t=new d.Menu;t.addItem(n=>{n.setTitle("Add current file").setIcon("file-plus").onClick(()=>{let o=this.app.workspace.getActiveFile();o&&this.plugin.addBookmark(o.path,o.basename,"file")})}),t.addItem(n=>{n.setTitle("Add as parent note").setIcon("folder-plus").onClick(()=>{let o=this.app.workspace.getActiveFile();if(!o)return;let r=this.plugin.addBookmark(o.path,o.basename,"group","");r.filePath=o.path,this.plugin.saveWaypointData(),this.redraw()})}),t.addItem(n=>{n.setTitle("New group").setIcon("folder-plus").onClick(()=>{this.plugin.addBookmark("","New Group","group","")})}),t.addSeparator(),t.addItem(n=>{n.setTitle("Add separator").setIcon("minus").onClick(()=>{this.plugin.addBookmark("","","separator")})}),t.addItem(n=>{n.setTitle("Add spacer").setIcon("space").onClick(()=>{this.plugin.addBookmark("","","spacer")})}),t.showAtPosition({x:a.clientX,y:a.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,i,s){for(let a=0;a<i.length;a++){let t=i[a];if(t.type==="separator"){let r=e.createDiv({cls:"waypoint-bookmark-item waypoint-bookmark-separator"});r.setAttr("draggable","true"),r.setAttr("data-bm-id",t.id),r.style.paddingLeft=`${8+s*16}px`,r.style.cursor="grab",this.attachBookmarkDragHandlers(r,e,t,!1),r.addEventListener("contextmenu",c=>{c.stopPropagation(),c.preventDefault(),this.showBookmarkContextMenu(c,t)});continue}if(t.type==="spacer"){let r=e.createDiv({cls:"waypoint-bookmark-item waypoint-bookmark-spacer"});r.setAttr("draggable","true"),r.setAttr("data-bm-id",t.id),r.style.paddingLeft=`${8+s*16}px`,r.style.cursor="grab",this.attachBookmarkDragHandlers(r,e,t,!1),r.addEventListener("contextmenu",c=>{c.stopPropagation(),c.preventDefault(),this.showBookmarkContextMenu(c,t)});continue}let n=t.type==="group",o=e.createDiv({cls:`waypoint-bookmark-item${n?" waypoint-bookmark-group":""}${t.collapsed?" collapsed":""}`});if(o.setAttr("draggable","true"),o.setAttr("data-bm-id",t.id),n||(o.style.paddingLeft=`${8+s*16}px`),this.attachBookmarkDragHandlers(o,e,t,!0),n){let r=o.createDiv({cls:"waypoint-bm-icon"});t.icon&&(0,d.setIcon)(r,t.icon);let c=o.createDiv({cls:"waypoint-bm-label",text:t.label}),l=o.createDiv({cls:"waypoint-bm-chevron"});(0,d.setIcon)(l,"chevron-down"),l.addEventListener("click",p=>{p.stopPropagation(),this.plugin.updateBookmark(t.id,{collapsed:!t.collapsed})}),o.addEventListener("click",p=>{if(t.filePath){let u=this.app.vault.getFileByPath(t.filePath);if(u){let D=d.Keymap.isModEvent(p);this.app.workspace.getLeaf(D).openFile(u);return}}this.plugin.updateBookmark(t.id,{collapsed:!t.collapsed})}),o.addEventListener("mousedown",p=>{if(p.button===1&&t.filePath){p.preventDefault();let u=this.app.vault.getFileByPath(t.filePath);u&&this.app.workspace.getLeaf("tab").openFile(u)}});let h=e.createDiv({cls:`waypoint-bookmark-children${t.collapsed?" collapsed":""}`});t.children&&t.children.length>0&&this.renderBookmarkList(h,t.children,s+1)}else{let r=o.createDiv({cls:"waypoint-bm-icon"});t.icon&&(0,d.setIcon)(r,t.icon);let c=o.createDiv({cls:"waypoint-bm-label",text:t.label});if(t.children&&t.children.length>0){let l=o.createDiv({cls:"waypoint-bm-chevron"});(0,d.setIcon)(l,"chevron-down"),l.addEventListener("click",h=>{h.stopPropagation(),this.plugin.updateBookmark(t.id,{collapsed:!t.collapsed})}),t.collapsed&&(o.addClass("collapsed"),l.style.transform="rotate(-90deg)")}if((0,d.setTooltip)(o,t.filePath),o.addEventListener("click",l=>{if(t.filePath){let h=this.app.vault.getFileByPath(t.filePath);if(h){let p=d.Keymap.isModEvent(l);this.app.workspace.getLeaf(p).openFile(h)}else new d.Notice("File not found"),this.plugin.removeBookmark(t.id)}}),o.addEventListener("mousedown",l=>{if(l.button===1&&t.filePath){l.preventDefault();let h=this.app.vault.getFileByPath(t.filePath);h&&this.app.workspace.getLeaf("tab").openFile(h)}}),t.children&&t.children.length>0){let l=e.createDiv({cls:`waypoint-bookmark-children${t.collapsed?" collapsed":""}`});this.renderBookmarkList(l,t.children,s+1)}}o.addEventListener("contextmenu",r=>{r.stopPropagation(),r.preventDefault(),this.showBookmarkContextMenu(r,t)})}}showBookmarkContextMenu(e,i){let s=new d.Menu;if(i.type==="separator"||i.type==="spacer"){s.addItem(a=>a.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(i.id))),s.showAtPosition({x:e.clientX,y:e.clientY});return}i.type==="file"?(s.addItem(a=>a.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let t=this.app.vault.getFileByPath(i.filePath);t&&this.app.workspace.getLeaf("tab").openFile(t)})),s.addSeparator(),s.addItem(a=>a.setTitle("Rename").setIcon("pencil").onClick(()=>this.promptRename(i))),s.addItem(a=>a.setTitle("Change icon").setIcon("image").onClick(()=>this.promptIcon(i))),s.addSeparator(),s.addItem(a=>a.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(i.id)))):i.type==="group"&&(i.filePath&&(s.addItem(a=>a.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let t=this.app.vault.getFileByPath(i.filePath);t&&this.app.workspace.getLeaf("tab").openFile(t)})),s.addSeparator()),s.addItem(a=>a.setTitle("Rename").setIcon("pencil").onClick(()=>this.promptRename(i))),s.addItem(a=>a.setTitle("Change icon").setIcon("image").onClick(()=>this.promptIcon(i))),s.addSeparator(),s.addItem(a=>a.setTitle("Add child bookmark").setIcon("file-plus").onClick(()=>{let t=this.app.workspace.getActiveFile();if(!t){new d.Notice("No active file");return}let n={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"file",label:t.basename,filePath:t.path,icon:"",children:[],collapsed:!1,indent:i.indent+1};i.children.push(n),this.plugin.saveWaypointData(),this.redraw()})),s.addItem(a=>a.setTitle("Add child note").setIcon("folder-plus").onClick(()=>{let t=this.app.workspace.getActiveFile();if(!t){new d.Notice("No active file");return}let n={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:t.basename,filePath:t.path,icon:"",children:[],collapsed:!1,indent:i.indent+1};i.children.push(n),this.plugin.saveWaypointData(),this.redraw()})),s.addItem(a=>a.setTitle("New sub-group").setIcon("folder-plus").onClick(()=>{let t={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:"New Group",filePath:"",icon:"",children:[],collapsed:!1,indent:i.indent+1};i.children.push(t),this.plugin.saveWaypointData(),this.redraw()})),s.addSeparator(),s.addItem(a=>a.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(i.id)))),s.showAtPosition({x:e.clientX,y:e.clientY})}attachBookmarkDragHandlers(e,i,s,a){let t=()=>{e.removeClass("waypoint-bm-drop-line"),e.removeClass("waypoint-bm-drop-below"),e.removeClass("waypoint-bm-drop-into")};e.addEventListener("dragstart",n=>{this.dragId=s.id,n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",s.id),e.addClass("waypoint-bm-dragging")}),e.addEventListener("dragend",()=>{this.dragId=null,i.querySelectorAll(".waypoint-bm-dragging, .waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(n=>{n.removeClass("waypoint-bm-dragging"),n.removeClass("waypoint-bm-drop-line"),n.removeClass("waypoint-bm-drop-below"),n.removeClass("waypoint-bm-drop-into")})}),e.addEventListener("dragenter",n=>{n.preventDefault(),!(!this.dragId||this.dragId===s.id)&&this.showDropIndicator(e,n,a)}),e.addEventListener("dragover",n=>{n.preventDefault(),!(!this.dragId||this.dragId===s.id)&&this.showDropIndicator(e,n,a)}),e.addEventListener("dragleave",t),e.addEventListener("drop",n=>{var c,l;n.preventDefault(),this.dragId=null,t();let o=(c=n.dataTransfer)==null?void 0:c.getData("text/plain");if(!o||o===s.id)return;let r=this.dropZones.get(e);a&&(r!=null&&r.into)?s.type==="group"?this.moveBookmarkToGroup(o,s.id):this.createParentNoteAndMove(o,s.id):this.moveBookmarkToPosition(o,s.id,(l=r==null?void 0:r.above)!=null?l:!1)})}showDropIndicator(e,i,s){let a=e.parentElement;a&&a.querySelectorAll(".waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(o=>{o.removeClass("waypoint-bm-drop-line"),o.removeClass("waypoint-bm-drop-below"),o.removeClass("waypoint-bm-drop-into")});let t=e.getBoundingClientRect(),n=i.clientY;if(s){let o=t.top+t.height*.25,r=t.top+t.height*.75;n<o?(e.addClass("waypoint-bm-drop-line"),this.dropZones.set(e,{above:!0,into:!1})):n>r?(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 o=n<t.top+t.height/2;e.addClass("waypoint-bm-drop-line"),o||e.addClass("waypoint-bm-drop-below"),this.dropZones.set(e,{above:o,into:!1})}}moveBookmarkToGroup(e,i){let s=t=>{let n=t.findIndex(o=>o.id===e);if(n>=0){let[o]=t.splice(n,1);return o}for(let o of t){let r=s(o.children);if(r)return r}return null},a=s(this.plugin.waypointData.bookmarks);if(a){if(i){let t=(n,o)=>n.id===o?!0:n.children.some(r=>t(r,o));if(a.id===i||t(a,i))return}if(i){let t=o=>{for(let r of o){if(r.id===i)return r;let c=t(r.children);if(c)return c}return null},n=t(this.plugin.waypointData.bookmarks);n&&(a.indent=n.indent+1,n.children.push(a))}else a.indent=0,this.plugin.waypointData.bookmarks.push(a);this.plugin.saveWaypointData(),this.redraw()}}createParentNoteAndMove(e,i){let s=o=>{let r=o.findIndex(c=>c.id===e);if(r>=0){let[c]=o.splice(r,1);return c}for(let c of o)if(c.children){let l=s(c.children);if(l)return l}return null},a=s(this.plugin.waypointData.bookmarks);if(!a)return;let t=o=>{for(let r of o){if(r.id===i)return r;if(r.children){let c=t(r.children);if(c)return c}}return null},n=t(this.plugin.waypointData.bookmarks);n&&(a.indent=n.indent+1,n.children.push(a),this.plugin.saveWaypointData(),this.redraw())}moveBookmarkToPosition(e,i,s){let a=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=a(l.children);if(h.item)return h}return{item:null,parent:[]}},{item:t}=a(this.plugin.waypointData.bookmarks);if(!t)return;let n=r=>{let c=r.findIndex(l=>l.id===i);if(c>=0)return{parent:r,idx:c};for(let l of r)if(l.children){let h=n(l.children);if(h)return h}return null},o=n(this.plugin.waypointData.bookmarks);if(!o)t.indent=0,this.plugin.waypointData.bookmarks.push(t);else{let r=s?o.idx:o.idx+1;o.parent.splice(r,0,t)}this.plugin.saveWaypointData(),this.redraw()}promptRename(e){new $(this.app,e.label,i=>{i&&i.trim()&&this.plugin.updateBookmark(e.id,{label:i.trim()})}).open()}promptIcon(e){new q(this.app,e.icon,i=>{this.plugin.updateBookmark(e.id,{icon:i})}).open()}},$=class extends d.Modal{constructor(m,e,i){super(m),this.currentValue=e,this.onSubmit=i}onOpen(){this.titleEl.setText("Rename bookmark");let m=this.contentEl.createEl("input",{type:"text",value:this.currentValue});m.style.width="100%",m.style.marginBottom="12px",m.focus(),m.select();let e=this.contentEl.createDiv({cls:"modal-button-container"}),i=e.createEl("button",{text:"Cancel",cls:"mod-cta"});i.style.marginRight="8px",i.addEventListener("click",()=>this.close()),e.createEl("button",{text:"Save",cls:"mod-cta"}).addEventListener("click",()=>{this.onSubmit(m.value),this.close()}),m.addEventListener("keydown",a=>{a.key==="Enter"&&(this.onSubmit(m.value),this.close())})}onClose(){this.contentEl.empty()}},R=null;function ie(){return R||(R=(async()=>{try{return await(await fetch("https://cdn.jsdelivr.net/npm/lucide-static@0.517.0/tags.json")).json()}catch(f){try{return await(await fetch("https://lucide.dev/api/tags")).json()}catch(m){return R=null,ae}}})()),R}var q=class extends d.Modal{constructor(e,i,s){super(e);this.allIcons=[];this.tagsMap={};this.loaded=!1;this.selected=i,this.onSubmit=s}async onOpen(){let e=this.contentEl;e.style.display="flex",e.style.flexDirection="column",e.style.gap="10px",this.titleEl.setText("Change icon");let i=e.createDiv({cls:"waypoint-icon-preview"});i.style.display="flex",i.style.alignItems="center",i.style.gap="10px",i.style.padding="12px 16px",i.style.borderRadius="8px",i.style.background="var(--background-secondary)",i.style.minHeight="48px";let s=i.createSpan();s.style.display="flex",this.selected&&(0,d.setIcon)(s,this.selected);let a=i.createSpan();a.style.fontWeight="var(--font-medium)",a.style.fontSize="var(--font-ui-medium)",a.setText(this.selected||"No icon");let t=e.createEl("input",{type:"text",placeholder:"Type to search (e.g. arrow, chart, home)..."});Object.assign(t.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)"}),t.focus();let n=e.createDiv({cls:"waypoint-icon-grid"});n.style.display="grid",n.style.gridTemplateColumns="repeat(auto-fill, minmax(52px, 1fr))",n.style.gap="4px",n.style.maxHeight="320px",n.style.overflowY="auto",n.style.padding="2px 0";let o=e.createDiv();o.style.display="flex",o.style.justifyContent="space-between",o.style.alignItems="center",o.style.fontSize="var(--font-ui-smaller)",o.style.color="var(--text-muted)",o.style.padding="0 4px";let r=o.createSpan();r.setText("Loading\u2026");let c=o.createSpan();c.style.cursor="var(--cursor)",c.style.color="var(--text-accent)",c.setText("No icon"),c.addEventListener("click",()=>{this.onSubmit(""),this.close()}),this.loadIcons().then(()=>{this.loaded=!0,r.setText(this.allIcons.length+" icons"),h(t.value)});let l,h=x=>{if(n.empty(),!this.loaded){n.createDiv({text:"Loading\u2026"});return}let k=x.toLowerCase().trim(),b=k?this.allIcons.filter(y=>{if(y.includes(k))return!0;let g=this.tagsMap[y];return g?g.some(C=>C.includes(k)):!1}).slice(0,80):this.allIcons.slice(0,80);if(b.length===0){let y=n.createDiv();y.style.gridColumn="1 / -1",y.style.textAlign="center",y.style.color="var(--text-muted)",y.style.padding="20px",y.setText('No icons match "'+x+'"');return}for(let y of b){let g=n.createDiv();g.setAttr("data-icon",y),g.style.display="flex",g.style.alignItems="center",g.style.justifyContent="center",g.style.aspectRatio="1",g.style.borderRadius="6px",g.style.cursor="var(--cursor)",g.style.transition="background 80ms",g.setAttr("title",y),y===this.selected?(g.style.background="var(--interactive-accent)",g.style.color="var(--text-on-accent)"):g.style.color="var(--text-muted)";let C=g.createSpan();C.style.display="flex",(0,d.setIcon)(C,y),g.addEventListener("mouseenter",()=>{y!==this.selected&&(g.style.background="var(--background-modifier-hover)")}),g.addEventListener("mouseleave",()=>{y!==this.selected&&(g.style.background="")}),g.addEventListener("click",()=>{this.selected=y,h(x),s.empty(),(0,d.setIcon)(s,y),a.setText(y),n.querySelectorAll("div[data-icon]").forEach(W=>{let S=W;S.getAttr("data-icon")===y?(S.style.background="var(--interactive-accent)",S.style.color="var(--text-on-accent)"):(S.style.background="",S.style.color="var(--text-muted)")})})}r.setText(b.length+" of "+this.allIcons.length+" icons")};t.addEventListener("input",()=>{window.clearTimeout(l),l=window.setTimeout(()=>h(t.value),60)}),t.addEventListener("keydown",x=>{x.key==="Escape"&&this.close()});let p=e.createDiv({cls:"modal-button-container"});p.createEl("button",{text:"Cancel"}).addEventListener("click",()=>this.close());let D=p.createEl("button",{text:"Save",cls:"mod-cta"});D.style.marginLeft="8px",D.addEventListener("click",()=>{this.onSubmit(this.selected),this.close()})}onClose(){this.contentEl.empty()}async loadIcons(){let e=await ie();this.tagsMap=e,this.allIcons=Object.keys(e).sort()}},ae={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 V(f,m,e){return!f||!m?null:f===m?e:f.startsWith(m+"/")?e+f.slice(m.length):null}var Y=class extends v.Plugin{constructor(){super(...arguments);this.recentFiles=[];this.savePromise=Promise.resolve();this.markdownBasenames=new Set}async onload(){console.debug("Waypoint: loading plugin v"+this.manifest.version);let e=await this.loadData();this.applySettings(e),this.applyWaypointData(e),this.registerView(T,n=>new L(n,this)),this.addSettingTab(new N(this.app,this,this.settings,()=>{this.enforceRecentFilesLimit(),this.redrawAll()})),this.addCommand({id:"waypoint-open-view",name:"Open Waypoint sidebar",callback:async()=>{let n=this.app.workspace.getLeavesOfType(T);if(n.length>0)await this.app.workspace.revealLeaf(n[0]);else{let o=this.app.workspace.getLeftLeaf(!1);o&&(await o.setViewState({type:T}),await this.app.workspace.revealLeaf(o))}}}),this.addCommand({id:"waypoint-add-bookmark",name:"Add current file as Waypoint bookmark",callback:async()=>{let n=this.app.workspace.getActiveFile();if(!n){new v.Notice("No active file");return}this.addBookmark(n.path,n.basename,"file"),new v.Notice(`Bookmarked: ${n.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,v.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,v.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,v.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,v.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,v.moment)())}});let i=["next","prev"],s=["daily","weekly","monthly","quarterly","yearly"],a={next:"Next",prev:"Previous"};for(let n of s)for(let o of i){let r=`waypoint-go-to-${o}-${n}`,c=`${a[o]} ${n} note`;this.addCommand({id:r,name:c,callback:async()=>{await this.navigatePeriodNote(o)}})}this.registerEvent(this.app.workspace.on("file-open",n=>{n&&this.onFileOpen(n)})),this.registerEvent(this.app.vault.on("create",n=>this.onVaultCreate(n))),this.registerEvent(this.app.vault.on("delete",n=>this.onVaultDelete(n))),this.registerEvent(this.app.vault.on("rename",(n,o)=>this.onRename(n,o))),this.registerEvent(this.app.vault.on("modify",n=>this.onFileModify(n))),this.app.workspace.onLayoutReady(()=>{if(this.buildMarkdownIndex(),this.app.workspace.getLeavesOfType(T).length===0){let o=this.app.workspace.getLeftLeaf(!1);o&&o.setViewState({type:T})}else this.broadcastRedraw()});let t=new Date().toDateString();this.registerInterval(window.setInterval(()=>{let n=new Date().toDateString();n!==t&&(t=n,this.redrawAll())},6e5))}async onunload(){this.app.workspace.detachLeavesOfType(T)}applySettings(e){let i=(e==null?void 0:e.settings)||{};this.settings=Object.assign({},P,i),this.settings.recentFiles=Object.assign({},P.recentFiles,i.recentFiles||{}),this.settings.calendar=Object.assign({},P.calendar,i.calendar||{}),this.settings.display=Object.assign({},P.display,i.display||{});for(let s of ne)this.settings[s]=Object.assign({},P[s],i[s]||{})}applyWaypointData(e){let i=(e==null?void 0:e.waypointData)||{};this.waypointData={bookmarks:Array.isArray(i.bookmarks)?i.bookmarks:[],recentFiles:Array.isArray(i.recentFiles)?i.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})));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 v.TFile&&(this.recentFiles.length>0&&this.recentFiles[0].path===e.path||this.addToRecentFiles(e))}addToRecentFiles(e){this.isOmittedFromRecentFiles(e)||(this.recentFiles=this.recentFiles.filter(i=>i.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 n of this.settings.recentFiles.omittedPaths)try{if(new RegExp(n).test(e.path))return!0}catch(o){}let i=this.settings.recentFiles.omittedTags;if(i.length===0)return!1;let s=this.app.metadataCache.getFileCache(e),a=(s?(0,v.getAllTags)(s):null)||[];if(a.length===0)return!1;let t=a.map(n=>n.replace(/^#/,""));for(let n of i)try{let o=new RegExp(n);if(t.some(r=>o.test(r)))return!0}catch(o){}return!1}onRename(e,i){let s=this.syncIndexForRename(e,i),a=!1;for(let n of this.recentFiles){let o=V(n.path,i,e.path);o!==null&&(n.path=o,n.basename=K(o),a=!0)}let t=n=>{for(let o of n){if(o.filePath){let r=V(o.filePath,i,e.path);r!==null&&(o.filePath=r,a=!0)}o.children&&t(o.children)}};t(this.waypointData.bookmarks),a&&(this.waypointData.recentFiles=this.recentFiles,this.persistAll()),(a||s)&&this.broadcastRedraw()}onVaultCreate(e){e instanceof v.TFile&&e.extension==="md"&&this.markdownBasenames.add(e.basename),this.broadcastRedraw()}onVaultDelete(e){e instanceof v.TFile&&e.extension==="md"&&this.removeFromMarkdownIndex(e.basename,e.path),this.broadcastRedraw()}buildMarkdownIndex(){this.markdownBasenames.clear();for(let e of this.app.vault.getMarkdownFiles())this.markdownBasenames.add(e.basename)}removeFromMarkdownIndex(e,i){return!this.markdownBasenames.has(e)||this.app.vault.getMarkdownFiles().some(a=>a.basename===e&&a.path!==i)?!1:(this.markdownBasenames.delete(e),!0)}syncIndexForRename(e,i){if(!(e instanceof v.TFile))return!1;let s=!1,a=K(i);return i.toLowerCase().endsWith(".md")&&(a!==e.basename||e.extension!=="md")&&(s=this.removeFromMarkdownIndex(a,i)),e.extension==="md"&&!this.markdownBasenames.has(e.basename)&&(this.markdownBasenames.add(e.basename),s=!0),s}hasNoteForDate(e){return this.markdownBasenames.has(e)}addBookmark(e,i,s="file",a=""){let n={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:s,label:i,filePath:s==="file"?e:"",icon:a,children:[],collapsed:!1,indent:0};return this.waypointData.bookmarks.push(n),this.saveWaypointData(),this.broadcastRedraw(),n}removeBookmark(e){let i=s=>{let a=s.findIndex(t=>t.id===e);if(a>=0)return s.splice(a,1),!0;for(let t of s)if(t.children&&i(t.children))return!0;return!1};i(this.waypointData.bookmarks),this.saveWaypointData(),this.broadcastRedraw()}updateBookmark(e,i){let s=t=>{for(let n of t){if(n.id===e)return n;if(n.children){let o=s(n.children);if(o)return o}}return null},a=s(this.waypointData.bookmarks);a&&(Object.assign(a,i),this.saveWaypointData(),this.broadcastRedraw())}async openPeriodNote(e,i,s){let a=j[e],t=this.settings[a.key],n=i.format(t.nameFormat)+".md",o=t.folder?`${t.folder}/${n}`:n,r=this.app.vault.getFileByPath(o);if(!r){if(r=await this.createPeriodNote(o,t,i,a.label),!r)return;new v.Notice(`Created ${a.label.toLowerCase()} note: ${n}`)}await(s||this.app.workspace.getLeaf(!1)).openFile(r)}async createPeriodNote(e,i,s,a){try{let t=this.resolveTemplateFile(i.templateFile),n=t?await this.app.vault.read(t):`---
type: ${i.typeProperty}
date: ${s.format("YYYY-MM-DD")}
---
`;return await this.app.vault.create(e,n)}catch(t){let n=t instanceof Error?t.message:String(t);return new v.Notice(`Failed to create ${a.toLowerCase()} note: ${n}`),null}}resolveTemplateFile(e){if(!e)return null;let i=e.toLowerCase().endsWith(".md")?e:`${e}.md`;return this.app.vault.getFileByPath(i)}detectPeriodType(e){for(let i of se){let s=this.settings[j[i].key].nameFormat;if(!s)continue;let a=(0,v.moment)(e,s,!0);if(a.isValid())return{period:i,date:a}}return null}async navigatePeriodNote(e){let i=this.app.workspace.getActiveFile();if(!i){new v.Notice("No active file");return}let s=this.detectPeriodType(i.basename);if(!s){new v.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:a,date:t}=s;if(!t.isValid()){new v.Notice(`Could not parse date from filename: ${i.basename}`);return}let n=e==="next"?1:-1,o=a==="quarter"?t.clone().add(n*3,"months"):t.clone().add(n,`${a}s`);await this.openPeriodNote(a,o)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let e=this.app.workspace.getLeavesOfType(T);for(let i of e)i.view instanceof L&&i.view.redraw()}},ne=["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"}},se=["day","week","month","quarter","year"];function K(f){return f.slice(f.lastIndexOf("/")+1).replace(/\.[^/.]+$/,"")}