Files
waypoint/main.js
T
olivier e0c3deee86 fix: drag onto file makes dragged item a child of that file
Dragging B onto A:
  ▶ File A
      File B

A becomes the parent, B becomes its child. No new group created.
2026-06-12 14:52:04 -04:00

22 lines
44 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
*/
var z=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var U=(b,u)=>{for(var t in u)z(b,t,{get:u[t],enumerable:!0})},X=(b,u,t,i)=>{if(u&&typeof u=="object"||typeof u=="function")for(let s of j(u))!H.call(b,s)&&s!==t&&z(b,s,{get:()=>u[s],enumerable:!(i=Q(u,s))||i.enumerable});return b};var K=b=>X(z({},"__esModule",{value:!0}),b);var ee={};U(ee,{default:()=>O});module.exports=K(ee);var y=require("obsidian");var W={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:[]},display:{rowSize:26,rowSpacing:2,indentSize:16,fontSize:13,iconSize:16,calendarCellSize:32}};var w=require("obsidian");var $=class extends w.PluginSettingTab{constructor(t,i,s,a){super(t,i);this.activeTab="calendar";this.plugin=i,this.settings=s,this.onSettingsChange=a}display(){let{containerEl:t}=this;t.empty();let i=t.createDiv({cls:"waypoint-settings-tabs"}),s=[{key:"calendar",label:"Calendar"},{key:"periodic",label:"Periodic Notes"},{key:"recent",label:"Recent Files"},{key:"display",label:"Display"}];for(let e of s)i.createEl("button",{cls:`waypoint-settings-tab${this.activeTab===e.key?" is-active":""}`,text:e.label}).addEventListener("click",()=>{this.activeTab=e.key,this.display()});let a=t.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}}renderCalendarTab(t){new w.Setting(t).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(t).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(t){this.addPeriodNoteSettings(t,"Daily",this.settings.daily),this.addPeriodNoteSettings(t,"Weekly",this.settings.weekly),this.addPeriodNoteSettings(t,"Monthly",this.settings.monthly),this.addPeriodNoteSettings(t,"Quarterly",this.settings.quarterly),this.addPeriodNoteSettings(t,"Yearly",this.settings.yearly)}addPeriodNoteSettings(t,i,s){new w.Setting(t).setHeading().setName(i),new w.Setting(t).setName("Folder").setDesc(`Folder path for ${i.toLowerCase()} notes.`).addText(a=>{a.setPlaceholder("periodic/daily"),a.setValue(s.folder),a.onChange(e=>{s.folder=e,this.saveAndRefresh()})}),new w.Setting(t).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(e=>{s.nameFormat=e,this.saveAndRefresh()})}),new w.Setting(t).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(e=>{s.templateFile=e,this.saveAndRefresh()})}),new w.Setting(t).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(a=>{a.setPlaceholder("daily-note"),a.setValue(s.typeProperty),a.onChange(e=>{s.typeProperty=e,this.saveAndRefresh()})})}renderRecentTab(t){new w.Setting(t).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 e=parseInt(a.getValue(),10);!isNaN(e)&&e>0&&(this.settings.recentFiles.maxItems=e,this.saveAndRefresh())}}),new w.Setting(t).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(e=>{this.settings.recentFiles.updateOn=e,this.saveAndRefresh()})});let i=new DocumentFragment;i.appendText("Regex patterns for paths to exclude. One per line."),new w.Setting(t).setName("Omitted paths").setDesc(i).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(e=>e.trim()),this.saveAndRefresh()}});let s=new DocumentFragment;s.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new w.Setting(t).setName("Omitted tags").setDesc(s).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(e=>e.trim()),this.saveAndRefresh()}})}renderDisplayTab(t){new w.Setting(t).setHeading().setName("Bookmarks"),this.addSliderSetting(t,"Row size","Height of bookmark items.",this.settings.display,"rowSize",18,40,1,"px"),this.addSliderSetting(t,"Row spacing","Gap between bookmark items.",this.settings.display,"rowSpacing",0,12,1,"px"),this.addSliderSetting(t,"Indent size","Indent per nesting depth.",this.settings.display,"indentSize",8,32,2,"px"),this.addSliderSetting(t,"Font size","Label font size.",this.settings.display,"fontSize",10,18,1,"px"),this.addSliderSetting(t,"Icon size","Bookmark icon size.",this.settings.display,"iconSize",12,24,1,"px"),new w.Setting(t).setHeading().setName("Calendar"),this.addSliderSetting(t,"Cell size","Height of calendar day cells.",this.settings.display,"calendarCellSize",20,48,2,"px"),new w.Setting(t).addButton(i=>i.setButtonText("Reset to defaults").onClick(()=>{this.settings.display={...W.display},this.saveAndRefresh(),this.display()}))}addSliderSetting(t,i,s,a,e,r,o,d,n){let l=new w.Setting(t).setName(i).setDesc(`${s} (${a[e]}${n})`);l.addSlider(c=>{c.setLimits(r,o,d).setValue(a[e]).setDynamicTooltip().onChange(h=>{a[e]=h,l.setDesc(`${s} (${h}${n})`),this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var p=require("obsidian");var L=require("obsidian");function _(b,u,t){let i=(0,L.moment)({year:b,month:u,day:1}),s=(0,L.moment)(i).endOf("month"),a=(0,L.moment)(i).subtract((i.day()-t+7)%7,"days"),e=(0,L.moment)().startOf("day"),r=[],o=(0,L.moment)(a);for(;o.isBefore(s)||o.month()===u;){let d=[];for(let n=0;n<7;n++)d.push({date:(0,L.moment)(o),dayOfMonth:o.date(),isToday:o.isSame(e,"day"),isCurrentMonth:o.month()===u,isoWeekNumber:o.isoWeek()}),o.add(1,"day");if(r.push({weekNumber:d[0].isoWeekNumber,days:d}),r.length>=6)break}return r}var C="waypoint-view",A=class extends p.ItemView{constructor(t,i){super(t);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view");let t=this.plugin.settings.display;this.contentEl.style.setProperty("--wp-row-size",t.rowSize+"px"),this.contentEl.style.setProperty("--wp-row-spacing",t.rowSpacing+"px"),this.contentEl.style.setProperty("--wp-indent-size",t.indentSize+"px"),this.contentEl.style.setProperty("--wp-font-size",t.fontSize+"px"),this.contentEl.style.setProperty("--wp-icon-size",t.iconSize+"px"),this.contentEl.style.setProperty("--wp-cal-cell-size",t.calendarCellSize+"px"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,p.moment)().month();this.currentDisplayYear=(0,p.moment)().year();this.dragId=null;this.recentFilesFilter=null;this.plugin=i}getViewType(){return C}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let t=this.contentEl.createDiv({cls:"waypoint-section"});t.createDiv({cls:"waypoint-section-header",text:"Calendar"});let i=t.createDiv({cls:"waypoint-calendar"}),s=(0,p.moment)(),a=(0,p.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),e=i.createDiv({cls:"waypoint-calendar-top"}),r=e.createDiv({cls:"waypoint-calendar-breadcrumb"}),o=a.format("[Q]Q"),d=r.createSpan({cls:"waypoint-clickable",text:o});d.addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",a)}),d.addEventListener("mousedown",f=>{f.button===1&&(f.preventDefault(),this.plugin.openPeriodNoteInLeaf("quarter",a,this.app.workspace.getLeaf("tab")))});let n=a.format("MMMM"),l=r.createSpan({cls:"waypoint-clickable",text:n});l.addEventListener("click",()=>{this.plugin.openPeriodNote("month",a)}),l.addEventListener("mousedown",f=>{f.button===1&&(f.preventDefault(),this.plugin.openPeriodNoteInLeaf("month",a,this.app.workspace.getLeaf("tab")))});let c=a.format("YYYY"),h=r.createSpan({cls:"waypoint-clickable",text:c});h.addEventListener("click",()=>{this.plugin.openPeriodNote("year",a)}),h.addEventListener("mousedown",f=>{f.button===1&&(f.preventDefault(),this.plugin.openPeriodNoteInLeaf("year",a,this.app.workspace.getLeaf("tab")))});let m=e.createDiv({cls:"waypoint-calendar-today-group"}),g=m.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,p.setIcon)(g,"chevron-left"),g.addEventListener("click",()=>this.navigateMonth(-1)),m.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,p.moment)().month(),this.currentDisplayYear=(0,p.moment)().year(),this.redraw()});let F=m.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,p.setIcon)(F,"chevron-right"),F.addEventListener("click",()=>this.navigateMonth(1));let x=i.createEl("table"),S=x.createEl("thead").createEl("tr");S.createEl("th",{text:""});let k=["sun","mon","tue","wed","thu","fri","sat"],R=this.plugin.settings.calendar.firstDayOfWeek;for(let f=0;f<7;f++){let M=(R+f)%7;S.createEl("th",{text:k[M]})}let D=x.createEl("tbody"),I=_(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let f of I){let M=D.createEl("tr"),Y=M.createEl("td",{cls:"waypoint-weeknum"});Y.setText(String(f.weekNumber)),Y.addEventListener("click",()=>{let E=f.days[0].date;this.plugin.openPeriodNote("week",E)}),Y.addEventListener("mousedown",E=>{if(E.button===1){E.preventDefault();let P=this.app.workspace.getLeaf("tab");this.plugin.openPeriodNoteInLeaf("week",monday,P)}});for(let E of f.days){let P=M.createEl("td",{cls:"waypoint-day"});if(P.setText(String(E.dayOfMonth)),E.isCurrentMonth||P.addClass("other-month"),E.isToday&&P.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let B=E.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(G=>G.extension==="md"&&G.basename===B)&&P.addClass("has-note")}P.addEventListener("click",()=>{this.plugin.openPeriodNote("day",E.date)}),P.addEventListener("mousedown",B=>{if(B.button===1){B.preventDefault();let T=this.app.workspace.getLeaf("tab");this.plugin.openPeriodNoteInLeaf("day",E.date,T)}})}}}navigateMonth(t){let i=(0,p.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(t,"month");this.currentDisplayMonth=i.month(),this.currentDisplayYear=i.year(),this.redraw()}renderRecentFiles(){var o;let t=this.contentEl.createDiv({cls:"waypoint-section waypoint-recent-files"});if(t.createDiv({cls:"waypoint-section-header",text:"Recent Files"}),this.plugin.recentFiles.length===0){t.createDiv({cls:"nav-file",text:"No recent files"});return}let i={};for(let d of this.plugin.recentFiles){let n=this.app.vault.getAbstractFileByPath(d.path);if(n instanceof p.TFile){let l=this.app.metadataCache.getFileCache(n),c=(o=l==null?void 0:l.frontmatter)==null?void 0:o.type;c&&typeof c=="string"&&(i[c]=(i[c]||0)+1)}}if(Object.keys(i).length>0){let d=t.createDiv({cls:"waypoint-recent-filter"});d.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter?"":" is-active"}`,text:"all"}).addEventListener("click",()=>{this.recentFilesFilter=null,this.redraw()});let l=Object.entries(i).sort(([,c],[,h])=>h-c);for(let[c,h]of l){let m=d.createSpan({cls:`waypoint-recent-pill${this.recentFilesFilter===c?" is-active":""}`});m.setText(`${c} ${h}`),m.addEventListener("click",()=>{this.recentFilesFilter=this.recentFilesFilter===c?null:c,this.redraw()})}}let s=this.plugin.recentFiles;this.recentFilesFilter&&(s=this.plugin.recentFiles.filter(d=>{var l;let n=this.app.vault.getAbstractFileByPath(d.path);if(n instanceof p.TFile){let c=this.app.metadataCache.getFileCache(n);return((l=c==null?void 0:c.frontmatter)==null?void 0:l.type)===this.recentFilesFilter}return!1}));let a=this.app.workspace.getActiveFile(),e=t.createDiv({cls:"nav-folder mod-root"}),r=e.createDiv({cls:"nav-folder-children"});for(let d of s){let n=r.createDiv({cls:"tree-item nav-file"}),l=n.createDiv({cls:"tree-item-self is-clickable nav-file-title"});l.createDiv({cls:"tree-item-inner nav-file-title-content"}).setText(d.basename);let h=l.createDiv({cls:"tree-item-spacer"}),m=l.createDiv({cls:"waypoint-recent-remove"});(0,p.setIcon)(m,"x"),m.addEventListener("click",g=>{g.stopPropagation(),this.plugin.recentFiles=this.plugin.recentFiles.filter(v=>v.path!==d.path),this.plugin.saveSettings(),this.redraw()}),(0,p.setTooltip)(n,d.path),a&&d.path===a.path&&l.addClass("is-active"),l.setAttr("draggable","true"),l.addEventListener("dragstart",g=>{let v=this.app.metadataCache.getFirstLinkpathDest(d.path,"");v&&(this.app.dragManager.dragFile(g,v),this.app.dragManager.onDragStart(g,this.app.dragManager.dragFile(g,v)))}),l.addEventListener("mouseover",g=>{this.app.workspace.trigger("hover-link",{event:g,source:C,hoverParent:e,targetEl:n,linktext:d.path})}),l.addEventListener("contextmenu",g=>{let v=new p.Menu;v.addItem(x=>x.setSection("action").setTitle("Open in new tab").setIcon("file-plus").onClick(()=>this.focusFile(d,"tab"))),v.addItem(x=>x.setSection("action").setTitle("Add to bookmarks").setIcon("bookmark").onClick(()=>{this.plugin.addBookmark(d.path,d.basename,"file"),new p.Notice(`Bookmarked: ${d.basename}`)}));let F=this.app.vault.getAbstractFileByPath(d.path);F&&this.app.workspace.trigger("file-menu",v,F,"link-context-menu"),v.showAtPosition({x:g.clientX,y:g.clientY})}),l.addEventListener("click",g=>{let v=p.Keymap.isModEvent(g);this.focusFile(d,v)}),l.addEventListener("mousedown",g=>{g.button===1&&(g.preventDefault(),this.focusFile(d,"tab"))})}}focusFile(t,i){let s=this.app.vault.getFiles().find(a=>a.path===t.path);s?this.app.workspace.getLeaf(i).openFile(s):(new p.Notice("Cannot find file"),this.plugin.recentFiles=this.plugin.recentFiles.filter(a=>a.path!==t.path),this.plugin.saveSettings(),this.redraw())}renderFavorites(){let t=this.contentEl.createDiv({cls:"waypoint-section waypoint-favorites"}),i=t.createDiv({cls:"waypoint-section-header"});i.setText("Waypoint Bookmarks");let s=i.createEl("button",{cls:"waypoint-header-more"});if((0,p.setIcon)(s,"more-horizontal"),(0,p.setTooltip)(s,"Add bookmark"),s.addEventListener("click",a=>{let e=new p.Menu;e.addItem(r=>{r.setTitle("Add current file").setIcon("file-plus").onClick(()=>{let o=this.app.workspace.getActiveFile();o&&this.plugin.addBookmark(o.path,o.basename,"file")})}),e.addItem(r=>{r.setTitle("Add as parent note").setIcon("folder-plus").onClick(()=>{let o=this.app.workspace.getActiveFile();if(!o)return;let d=this.plugin.addBookmark(o.path,o.basename,"group","");d.filePath=o.path,this.plugin.saveWaypointData(),this.redraw()})}),e.addItem(r=>{r.setTitle("New group").setIcon("folder-plus").onClick(()=>{this.plugin.addBookmark("","New Group","group","")})}),e.addSeparator(),e.addItem(r=>{r.setTitle("Add separator").setIcon("minus").onClick(()=>{this.plugin.addBookmark("","","separator")})}),e.addItem(r=>{r.setTitle("Add spacer").setIcon("space").onClick(()=>{this.plugin.addBookmark("","","spacer")})}),e.showAtPosition({x:a.clientX,y:a.clientY})}),this.plugin.waypointData.bookmarks.length===0){t.createDiv({cls:"waypoint-bookmark-item",text:"No bookmarks"});return}this.renderBookmarkList(t,this.plugin.waypointData.bookmarks,0)}renderBookmarkList(t,i,s){for(let a=0;a<i.length;a++){let e=i[a];if(e.type==="separator"){let n=t.createDiv({cls:"waypoint-bookmark-item waypoint-bookmark-separator"});n.setAttr("draggable","true"),n.setAttr("data-bm-id",e.id),n.style.paddingLeft=`${8+s*16}px`,n.style.cursor="grab",n.addEventListener("dragstart",l=>{this.dragId=e.id,l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",e.id),n.addClass("waypoint-bm-dragging")}),n.addEventListener("dragend",()=>{this.dragId=null,t.querySelectorAll(".waypoint-bm-dragging, .waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(l=>{l.removeClass("waypoint-bm-dragging"),l.removeClass("waypoint-bm-drop-line"),l.removeClass("waypoint-bm-drop-below")})}),n.addEventListener("dragenter",l=>{l.preventDefault(),!(!this.dragId||this.dragId===e.id)&&this.showDropIndicator(n,l,!1)}),n.addEventListener("dragover",l=>{l.preventDefault(),!(!this.dragId||this.dragId===e.id)&&this.showDropIndicator(n,l,!1)}),n.addEventListener("dragleave",()=>{n.removeClass("waypoint-bm-drop-line"),n.removeClass("waypoint-bm-drop-below"),n.removeClass("waypoint-bm-drop-into")}),n.addEventListener("drop",l=>{var m;l.preventDefault(),this.dragId=null,n.removeClass("waypoint-bm-drop-line"),n.removeClass("waypoint-bm-drop-below");let c=(m=l.dataTransfer)==null?void 0:m.getData("text/plain");if(!c||c===e.id)return;let h=n.__dropAbove;this.moveBookmarkToPosition(c,e.id,h)}),n.addEventListener("contextmenu",l=>{l.stopPropagation(),l.preventDefault(),this.showBookmarkContextMenu(l,e)});continue}if(e.type==="spacer"){let n=t.createDiv({cls:"waypoint-bookmark-item waypoint-bookmark-spacer"});n.setAttr("draggable","true"),n.setAttr("data-bm-id",e.id),n.style.paddingLeft=`${8+s*16}px`,n.style.cursor="grab",n.addEventListener("dragstart",l=>{this.dragId=e.id,l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",e.id),n.addClass("waypoint-bm-dragging")}),n.addEventListener("dragend",()=>{this.dragId=null,t.querySelectorAll(".waypoint-bm-dragging, .waypoint-bm-drop-line, .waypoint-bm-drop-below, .waypoint-bm-drop-into").forEach(l=>{l.removeClass("waypoint-bm-dragging"),l.removeClass("waypoint-bm-drop-line"),l.removeClass("waypoint-bm-drop-below")})}),n.addEventListener("dragenter",l=>{l.preventDefault(),!(!this.dragId||this.dragId===e.id)&&this.showDropIndicator(n,l,!1)}),n.addEventListener("dragover",l=>{l.preventDefault(),!(!this.dragId||this.dragId===e.id)&&this.showDropIndicator(n,l,!1)}),n.addEventListener("dragleave",()=>{n.removeClass("waypoint-bm-drop-line"),n.removeClass("waypoint-bm-drop-below"),n.removeClass("waypoint-bm-drop-into")}),n.addEventListener("drop",l=>{var m;l.preventDefault(),this.dragId=null,n.removeClass("waypoint-bm-drop-line"),n.removeClass("waypoint-bm-drop-below");let c=(m=l.dataTransfer)==null?void 0:m.getData("text/plain");if(!c||c===e.id)return;let h=n.__dropAbove;this.moveBookmarkToPosition(c,e.id,h)}),n.addEventListener("contextmenu",l=>{l.stopPropagation(),l.preventDefault(),this.showBookmarkContextMenu(l,e)});continue}let r=e.type==="group",o=t.createDiv({cls:`waypoint-bookmark-item${r?" waypoint-bookmark-group":""}${e.collapsed?" collapsed":""}`});o.setAttr("draggable","true"),o.setAttr("data-bm-id",e.id),r||(o.style.paddingLeft=`${8+s*16}px`),o.addEventListener("dragstart",n=>{this.dragId=e.id,n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",e.id),o.addClass("waypoint-bm-dragging")});let d=!0;if(o.addEventListener("dragend",()=>{this.dragId=null,t.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")})}),o.addEventListener("dragenter",n=>{n.preventDefault(),!(!this.dragId||this.dragId===e.id)&&this.showDropIndicator(o,n,d)}),o.addEventListener("dragover",n=>{n.preventDefault(),!(!this.dragId||this.dragId===e.id)&&this.showDropIndicator(o,n,d)}),o.addEventListener("dragleave",()=>{o.removeClass("waypoint-bm-drop-line"),o.removeClass("waypoint-bm-drop-below"),o.removeClass("waypoint-bm-drop-into")}),o.addEventListener("drop",n=>{var h;n.preventDefault(),this.dragId=null,o.removeClass("waypoint-bm-drop-line"),o.removeClass("waypoint-bm-drop-below"),o.removeClass("waypoint-bm-drop-into");let l=(h=n.dataTransfer)==null?void 0:h.getData("text/plain");if(!l||l===e.id)return;if(o.__dropInto&&d)r?this.moveBookmarkToGroup(l,e.id):this.createParentNoteAndMove(l,e.id);else{let m=o.__dropAbove;this.moveBookmarkToPosition(l,e.id,m)}}),r){let n=o.createDiv({cls:"waypoint-bm-icon"});e.icon&&(0,p.setIcon)(n,e.icon);let l=o.createDiv({cls:"waypoint-bm-label",text:e.label}),c=o.createDiv({cls:"waypoint-bm-chevron"});(0,p.setIcon)(c,"chevron-down"),c.addEventListener("click",m=>{m.stopPropagation(),this.plugin.updateBookmark(e.id,{collapsed:!e.collapsed})}),o.addEventListener("click",m=>{if(e.filePath){let g=this.app.vault.getFileByPath(e.filePath);if(g){let v=p.Keymap.isModEvent(m);this.app.workspace.getLeaf(v).openFile(g);return}}this.plugin.updateBookmark(e.id,{collapsed:!e.collapsed})}),o.addEventListener("mousedown",m=>{if(m.button===1&&e.filePath){m.preventDefault();let g=this.app.vault.getFileByPath(e.filePath);g&&this.app.workspace.getLeaf("tab").openFile(g)}});let h=t.createDiv({cls:`waypoint-bookmark-children${e.collapsed?" collapsed":""}`});e.children&&e.children.length>0&&this.renderBookmarkList(h,e.children,s+1)}else{let n=o.createDiv({cls:"waypoint-bm-icon"});e.icon&&(0,p.setIcon)(n,e.icon);let l=o.createDiv({cls:"waypoint-bm-label",text:e.label});if(e.children&&e.children.length>0){let c=o.createDiv({cls:"waypoint-bm-chevron"});(0,p.setIcon)(c,"chevron-down"),c.addEventListener("click",h=>{h.stopPropagation(),this.plugin.updateBookmark(e.id,{collapsed:!e.collapsed})}),e.collapsed&&(o.addClass("collapsed"),c.style.transform="rotate(-90deg)")}if((0,p.setTooltip)(o,e.filePath),o.addEventListener("click",c=>{if(e.filePath){let h=this.app.vault.getFileByPath(e.filePath);if(h){let m=p.Keymap.isModEvent(c);this.app.workspace.getLeaf(m).openFile(h)}else new p.Notice("File not found"),this.plugin.removeBookmark(e.id)}}),o.addEventListener("mousedown",c=>{if(c.button===1&&e.filePath){c.preventDefault();let h=this.app.vault.getFileByPath(e.filePath);h&&this.app.workspace.getLeaf("tab").openFile(h)}}),e.children&&e.children.length>0){let c=t.createDiv({cls:`waypoint-bookmark-children${e.collapsed?" collapsed":""}`});this.renderBookmarkList(c,e.children,s+1)}}o.addEventListener("contextmenu",n=>{n.stopPropagation(),n.preventDefault(),this.showBookmarkContextMenu(n,e)})}}showBookmarkContextMenu(t,i){let s=new p.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:t.clientX,y:t.clientY});return}i.type==="file"?(s.addItem(a=>a.setTitle("Open in new tab").setIcon("file-plus").onClick(()=>{let e=this.app.vault.getFileByPath(i.filePath);e&&this.app.workspace.getLeaf("tab").openFile(e)})),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 e=this.app.vault.getFileByPath(i.filePath);e&&this.app.workspace.getLeaf("tab").openFile(e)})),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 e=this.app.workspace.getActiveFile();if(!e){new p.Notice("No active file");return}let r={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"file",label:e.basename,filePath:e.path,icon:"",children:[],collapsed:!1,indent:i.indent+1};i.children.push(r),this.plugin.saveWaypointData(),this.redraw()})),s.addItem(a=>a.setTitle("Add child note").setIcon("folder-plus").onClick(()=>{let e=this.app.workspace.getActiveFile();if(!e){new p.Notice("No active file");return}let r={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"group",label:e.basename,filePath:e.path,icon:"",children:[],collapsed:!1,indent:i.indent+1};i.children.push(r),this.plugin.saveWaypointData(),this.redraw()})),s.addItem(a=>a.setTitle("New sub-group").setIcon("folder-plus").onClick(()=>{let e={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(e),this.plugin.saveWaypointData(),this.redraw()})),s.addSeparator(),s.addItem(a=>a.setTitle("Remove").setIcon("trash").onClick(()=>this.plugin.removeBookmark(i.id)))),s.showAtPosition({x:t.clientX,y:t.clientY})}showDropIndicator(t,i,s){let a=t.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 e=t.getBoundingClientRect(),r=i.clientY;if(s){let o=e.top+e.height*.25,d=e.top+e.height*.75;r<o?(t.addClass("waypoint-bm-drop-line"),t.__dropAbove=!0,t.__dropInto=!1):r>d?(t.addClass("waypoint-bm-drop-line"),t.addClass("waypoint-bm-drop-below"),t.__dropAbove=!1,t.__dropInto=!1):(t.addClass("waypoint-bm-drop-into"),t.__dropAbove=!1,t.__dropInto=!0)}else{let o=r<e.top+e.height/2;t.addClass("waypoint-bm-drop-line"),o||t.addClass("waypoint-bm-drop-below"),t.__dropAbove=o,t.__dropInto=!1}}moveBookmarkToGroup(t,i){let s=e=>{let r=e.findIndex(o=>o.id===t);if(r>=0){let[o]=e.splice(r,1);return o}for(let o of e){let d=s(o.children);if(d)return d}return null},a=s(this.plugin.waypointData.bookmarks);if(a){if(i){let e=(r,o)=>r.id===o?!0:r.children.some(d=>e(d,o));if(a.id===i||e(a,i))return}if(i){let e=o=>{for(let d of o){if(d.id===i)return d;let n=e(d.children);if(n)return n}return null},r=e(this.plugin.waypointData.bookmarks);r&&(a.indent=r.indent+1,r.children.push(a))}else a.indent=0,this.plugin.waypointData.bookmarks.push(a);this.plugin.saveWaypointData(),this.redraw()}}createParentNoteAndMove(t,i){let s=o=>{let d=o.findIndex(n=>n.id===t);if(d>=0){let[n]=o.splice(d,1);return n}for(let n of o)if(n.children){let l=s(n.children);if(l)return l}return null},a=s(this.plugin.waypointData.bookmarks);if(!a)return;let e=o=>{for(let d of o){if(d.id===i)return d;if(d.children){let n=e(d.children);if(n)return n}}return null},r=e(this.plugin.waypointData.bookmarks);r&&(a.indent=r.indent+1,r.children.push(a),this.plugin.saveWaypointData(),this.redraw())}moveBookmarkToPosition(t,i,s){let a=d=>{let n=d.findIndex(l=>l.id===t);if(n>=0){let[l]=d.splice(n,1);return{item:l,parent:d}}for(let l of d)if(l.children){let c=a(l.children);if(c.item)return c}return{item:null,parent:[]}},{item:e}=a(this.plugin.waypointData.bookmarks);if(!e)return;let r=d=>{let n=d.findIndex(l=>l.id===i);if(n>=0)return{parent:d,idx:n};for(let l of d)if(l.children){let c=r(l.children);if(c)return c}return null},o=r(this.plugin.waypointData.bookmarks);if(!o)e.indent=0,this.plugin.waypointData.bookmarks.push(e);else{let d=s?o.idx:o.idx+1;o.parent.splice(d,0,e)}this.plugin.saveWaypointData(),this.redraw()}promptRename(t){new q(this.app,t.label,i=>{i&&i.trim()&&this.plugin.updateBookmark(t.id,{label:i.trim()})}).open()}promptIcon(t){new V(this.app,t.icon,i=>{i&&this.plugin.updateBookmark(t.id,{icon:i})}).open()}},q=class extends p.Modal{constructor(u,t,i){super(u),this.currentValue=t,this.onSubmit=i}onOpen(){this.titleEl.setText("Rename bookmark");let u=this.contentEl.createEl("input",{type:"text",value:this.currentValue});u.style.width="100%",u.style.marginBottom="12px",u.focus(),u.select();let t=this.contentEl.createDiv({cls:"modal-button-container"}),i=t.createEl("button",{text:"Cancel",cls:"mod-cta"});i.style.marginRight="8px",i.addEventListener("click",()=>this.close()),t.createEl("button",{text:"Save",cls:"mod-cta"}).addEventListener("click",()=>{this.onSubmit(u.value),this.close()}),u.addEventListener("keydown",a=>{a.key==="Enter"&&(this.onSubmit(u.value),this.close())})}onClose(){this.contentEl.empty()}},V=class extends p.Modal{constructor(t,i,s){super(t);this.allIcons=[];this.tagsMap={};this.loaded=!1;this.selected=i,this.onSubmit=s}async onOpen(){let t=this.contentEl;t.style.display="flex",t.style.flexDirection="column",t.style.gap="10px",this.titleEl.setText("Change icon");let i=t.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,p.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 e=t.createEl("input",{type:"text",placeholder:"Type to search (e.g. arrow, chart, home)..."});Object.assign(e.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)"}),e.focus();let r=t.createDiv({cls:"waypoint-icon-grid"});r.style.display="grid",r.style.gridTemplateColumns="repeat(auto-fill, minmax(52px, 1fr))",r.style.gap="4px",r.style.maxHeight="320px",r.style.overflowY="auto",r.style.padding="2px 0";let o=t.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 d=o.createSpan();d.setText("Loading\u2026");let n=o.createSpan();n.style.cursor="var(--cursor)",n.style.color="var(--text-accent)",n.setText("No icon"),n.addEventListener("click",()=>{this.onSubmit(""),this.close()}),this.loadIcons().then(()=>{this.loaded=!0,d.setText(this.allIcons.length+" icons"),c(e.value)});let l=null,c=v=>{if(r.empty(),!this.loaded){r.createDiv({text:"Loading\u2026"});return}let F=v.toLowerCase().trim(),x=F?this.allIcons.filter(D=>{if(D.includes(F))return!0;let I=this.tagsMap[D];return I?I.some(f=>f.includes(F)):!1}).slice(0,80):this.allIcons.slice(0,80);if(x.length===0){let D=r.createDiv();D.style.gridColumn="1 / -1",D.style.textAlign="center",D.style.color="var(--text-muted)",D.style.padding="20px",D.setText('No icons match "'+v+'"');return}for(var N=0;N<x.length;N++){var S=x[N],k=r.createDiv();k.setAttr("data-icon",S),k.style.display="flex",k.style.alignItems="center",k.style.justifyContent="center",k.style.aspectRatio="1",k.style.borderRadius="6px",k.style.cursor="var(--cursor)",k.style.transition="background 80ms",k.setAttr("title",S),S===this.selected?(k.style.background="var(--interactive-accent)",k.style.color="var(--text-on-accent)"):k.style.color="var(--text-muted)";var R=k.createSpan();R.style.display="flex",(0,p.setIcon)(R,S),(function(D,I,f,M,Y,E,P){I.addEventListener("mouseenter",function(){f!==D.selected&&(I.style.background="var(--background-modifier-hover)")}),I.addEventListener("mouseleave",function(){f!==D.selected&&(I.style.background="")}),I.addEventListener("click",function(){D.selected=f,c(M),E.empty(),(0,p.setIcon)(E,f),P.setText(f),Y.querySelectorAll("div[data-icon]").forEach(function(B){var T=B;T.getAttr("data-icon")===f?(T.style.background="var(--interactive-accent)",T.style.color="var(--text-on-accent)"):(T.style.background="",T.style.color="var(--text-muted)")})})})(this,k,S,v,r,s,a)}d.setText(x.length+" of "+this.allIcons.length+" icons")};e.addEventListener("input",function(){l!==null&&clearTimeout(l),l=setTimeout(function(){c(e.value)},60)}),e.addEventListener("keydown",function(v){v.key==="Escape"&&this.close()}.bind(this));var h=t.createDiv({cls:"modal-button-container"}),m=h.createEl("button",{text:"Cancel"});m.addEventListener("click",function(){this.close()}.bind(this));var g=h.createEl("button",{text:"Save",cls:"mod-cta"});g.style.marginLeft="8px",g.addEventListener("click",function(){this.onSubmit(this.selected),this.close()}.bind(this))}onClose(){this.contentEl.empty()}async loadIcons(){try{var t=await fetch("https://cdn.jsdelivr.net/npm/lucide-static@0.517.0/tags.json"),i=await t.json();this.tagsMap=i,this.allIcons=Object.keys(i).sort()}catch(e){try{var s=await fetch("https://lucide.dev/api/tags"),a=await s.json();this.tagsMap=a,this.allIcons=Object.keys(a).sort()}catch(r){this.tagsMap={},this.allIcons=Object.keys(J).sort()}}}},J={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:[]};var Z={bookmarks:[]},O=class extends y.Plugin{constructor(){super(...arguments);this.recentFiles=[]}async onload(){console.debug("Waypoint: loading plugin v"+this.manifest.version),await this.loadSettings(),await this.loadWaypointData(),this.registerView(C,e=>new A(e,this)),this.addSettingTab(new $(this.app,this,this.settings,()=>this.redrawAll())),this.addCommand({id:"waypoint-open-view",name:"Open Waypoint sidebar",callback:async()=>{let e=this.app.workspace.getLeavesOfType(C);if(e.length>0)await this.app.workspace.revealLeaf(e[0]);else{let r=this.app.workspace.getLeftLeaf(!1);r&&(await r.setViewState({type:C}),await this.app.workspace.revealLeaf(r))}}}),this.addCommand({id:"waypoint-add-bookmark",name:"Add current file as Waypoint bookmark",callback:async()=>{let e=this.app.workspace.getActiveFile();if(!e){new y.Notice("No active file");return}this.addBookmark(e.path,e.basename,"file"),new y.Notice(`Bookmarked: ${e.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,y.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,y.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,y.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,y.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,y.moment)())}});let t=["next","prev"],i=["daily","weekly","monthly","quarterly","yearly"],s={next:"Next",prev:"Previous"};for(let e of i)for(let r of t){let o=`waypoint-go-to-${r}-${e}`,d=`${s[r]} ${e} note`;this.addCommand({id:o,name:d,callback:async()=>{await this.navigatePeriodNote(r)}})}this.registerEvent(this.app.workspace.on("file-open",e=>{e&&this.onFileOpen(e)})),this.registerEvent(this.app.vault.on("create",()=>this.onVaultChange())),this.registerEvent(this.app.vault.on("delete",()=>this.onVaultChange())),this.registerEvent(this.app.vault.on("rename",(e,r)=>this.onRename(e,r))),this.app.workspace.onLayoutReady(()=>{if(this.app.workspace.getLeavesOfType(C).length===0){let r=this.app.workspace.getLeftLeaf(!1);r&&r.setViewState({type:C})}});let a=new Date().toDateString();this.registerInterval(window.setInterval(()=>{let e=new Date().toDateString();e!==a&&(a=e,this.redrawAll())},6e5))}async onunload(){this.app.workspace.detachLeavesOfType(C)}async loadSettings(){let t=await this.loadData(),i=(t==null?void 0:t.settings)||{};this.settings=Object.assign({},W,i)}async saveSettings(){let t=await this.loadData()||{};t.settings=this.settings,await this.saveData(t)}async loadWaypointData(){let t=await this.loadData(),i=(t==null?void 0:t.waypointData)||{};this.waypointData=Object.assign({},Z,i)}async saveWaypointData(){let t=await this.loadData()||{};t.waypointData=this.waypointData,await this.saveData(t)}onFileOpen(t){this.settings.recentFiles.updateOn!=="file-edit"&&this.addToRecentFiles(t)}addToRecentFiles(t){this.recentFiles=this.recentFiles.filter(i=>i.path!==t.path),this.recentFiles.unshift({path:t.path,basename:t.basename}),this.recentFiles.length>this.settings.recentFiles.maxItems&&(this.recentFiles=this.recentFiles.slice(0,this.settings.recentFiles.maxItems)),this.broadcastRedraw()}onRename(t,i){let s=this.recentFiles.find(a=>a.path===i);s&&(s.path=t.path,s.basename=t.basename||t.name.replace(/\.[^/.]+$/,""),this.broadcastRedraw()),this.updateBookmarkPath(i,t.path)}onVaultChange(){this.broadcastRedraw()}addBookmark(t,i,s="file",a=""){let r={id:`bm-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:s,label:i,filePath:s==="file"?t:"",icon:a,children:[],collapsed:!1,indent:0};return this.waypointData.bookmarks.push(r),this.saveWaypointData(),this.broadcastRedraw(),r}removeBookmark(t){let i=s=>{let a=s.findIndex(e=>e.id===t);if(a>=0)return s.splice(a,1),!0;for(let e of s)if(e.children&&i(e.children))return!0;return!1};i(this.waypointData.bookmarks),this.saveWaypointData(),this.broadcastRedraw()}updateBookmark(t,i){let s=e=>{for(let r of e){if(r.id===t)return r;if(r.children){let o=s(r.children);if(o)return o}}return null},a=s(this.waypointData.bookmarks);a&&(Object.assign(a,i),this.saveWaypointData(),this.broadcastRedraw())}updateBookmarkPath(t,i){let s=a=>{for(let e of a)e.filePath===t&&(e.filePath=i),e.children&&s(e.children)};s(this.waypointData.bookmarks)}async openPeriodNote(t,i){let a={day:{settings:this.settings.daily,label:"Daily"},week:{settings:this.settings.weekly,label:"Weekly"},month:{settings:this.settings.monthly,label:"Monthly"},quarter:{settings:this.settings.quarterly,label:"Quarterly"},year:{settings:this.settings.yearly,label:"Yearly"}}[t];if(!a)return;let{settings:e}=a,r=i.format(e.nameFormat)+".md",o=e.folder?`${e.folder}/${r}`:r,d=this.app.vault.getFileByPath(o);if(!d){try{let n=e.templateFile+".md",l=this.app.vault.getFileByPath(n);if(l){let c=await this.app.vault.read(l);d=await this.app.vault.create(o,c)}else{let c=`---
type: ${e.typeProperty}
date: ${i.format("YYYY-MM-DD")}
---
`;d=await this.app.vault.create(o,c)}}catch(n){new y.Notice(`Failed to create ${a.label.toLowerCase()} note: ${n.message}`);return}new y.Notice(`Created ${a.label.toLowerCase()} note: ${r}`)}d&&await this.app.workspace.getLeaf(!1).openFile(d)}async openPeriodNoteInLeaf(t,i,s){let e={day:{settings:this.settings.daily,label:"Daily"},week:{settings:this.settings.weekly,label:"Weekly"},month:{settings:this.settings.monthly,label:"Monthly"},quarter:{settings:this.settings.quarterly,label:"Quarterly"},year:{settings:this.settings.yearly,label:"Yearly"}}[t];if(!e)return;let{settings:r}=e,o=i.format(r.nameFormat)+".md",d=r.folder?`${r.folder}/${o}`:o,n=this.app.vault.getFileByPath(d);if(!n)try{let l=r.templateFile+".md",c=this.app.vault.getFileByPath(l);if(c){let h=await this.app.vault.read(c);n=await this.app.vault.create(d,h)}else{let h=`---
type: ${r.typeProperty}
date: ${i.format("YYYY-MM-DD")}
---
`;n=await this.app.vault.create(d,h)}}catch(l){new y.Notice(`Failed to create ${e.label.toLowerCase()} note: ${l.message}`);return}n&&await s.openFile(n)}detectPeriodType(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?{period:"day",date:(0,y.moment)(t,"YYYY-MM-DD")}:/^\d{4}-W\d{2}$/.test(t)?{period:"week",date:(0,y.moment)(t,"GGGG-[W]WW")}:/^\d{4}-\d{2}$/.test(t)?{period:"month",date:(0,y.moment)(t,"YYYY-MM")}:/^\d{4}-Q[1-4]$/.test(t)?{period:"quarter",date:(0,y.moment)(t,"YYYY-[Q]Q")}:/^\d{4}$/.test(t)?{period:"year",date:(0,y.moment)(t,"YYYY")}:null}async navigatePeriodNote(t){let i=this.app.workspace.getActiveFile();if(!i){new y.Notice("No active file");return}let s=this.detectPeriodType(i.basename);if(!s){new y.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:a,date:e}=s;if(!e.isValid()){new y.Notice(`Could not parse date from filename: ${i.basename}`);return}let r=t==="next"?1:-1,o=a==="quarter"?e.clone().add(r*3,"months"):e.clone().add(r,`${a}s`);await this.openPeriodNote(a,o)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(C);for(let i of t)i.view instanceof A&&i.view.redraw()}async getNotesForDate(t){return this.app.vault.getFiles().filter(i=>i.extension==="md"&&i.basename===t)}async hasNoteForDate(t){return this.app.vault.getFiles().some(i=>i.extension==="md"&&i.basename===t)}};