feat: add bookmark from recent files + calendar middle-click

- Recent files right-click now has 'Add to bookmarks' option
- Calendar: middle-click on day/week/quarter/month/year opens in new tab
- Added openPeriodNoteInLeaf() method for opening period notes in a specific leaf
This commit is contained in:
olivier committed 2026-06-11 10:46:57 -04:00
1 parent eeb6059fe5
commit a36c8ab6f4
3 files changed
+88 -5

No files matched your search

+9 -4
View File
@@ -2,15 +2,20 @@
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
*/
var $=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var U=(w,p)=>{for(var t in p)$(w,t,{get:p[t],enumerable:!0})},X=(w,p,t,a)=>{if(p&&typeof p=="object"||typeof p=="function")for(let n of z(p))!H.call(w,n)&&n!==t&&$(w,n,{get:()=>p[n],enumerable:!(a=j(p,n))||a.enumerable});return w};var K=w=>X($({},"__esModule",{value:!0}),w);var ee={};U(ee,{default:()=>R});module.exports=K(ee);var g=require("obsidian");var _={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:[]}};var f=require("obsidian"),W=class extends f.PluginSettingTab{constructor(p,t,a,n){super(p,t),this.plugin=t,this.settings=a,this.onSettingsChange=n}display(){let{containerEl:p}=this;p.empty(),new f.Setting(p).setHeading().setName("Calendar"),new f.Setting(p).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(n=>{n.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(o=>{this.settings.calendar.firstDayOfWeek=parseInt(o,10),this.saveAndRefresh()})}),new f.Setting(p).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(n=>{n.setValue(this.settings.calendar.showNoteIndicators).onChange(o=>{this.settings.calendar.showNoteIndicators=o,this.saveAndRefresh()})}),new f.Setting(p).setHeading().setName("Periodic Note Paths"),this.addPeriodNoteSettings("Daily",this.settings.daily),this.addPeriodNoteSettings("Weekly",this.settings.weekly),this.addPeriodNoteSettings("Monthly",this.settings.monthly),this.addPeriodNoteSettings("Quarterly",this.settings.quarterly),this.addPeriodNoteSettings("Yearly",this.settings.yearly),new f.Setting(p).setHeading().setName("Recent Files"),new f.Setting(p).setName("Max items").setDesc("Maximum number of recent files to track.").addText(n=>{n.inputEl.setAttr("type","number"),n.inputEl.setAttr("placeholder","50"),n.setValue(String(this.settings.recentFiles.maxItems)),n.inputEl.onblur=()=>{let o=parseInt(n.getValue(),10);!isNaN(o)&&o>0&&(this.settings.recentFiles.maxItems=o,this.saveAndRefresh())}}),new f.Setting(p).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(n=>{n.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(o=>{this.settings.recentFiles.updateOn=o,this.saveAndRefresh()})});let t=new DocumentFragment;t.appendText("Regex patterns for paths to exclude. One per line."),new f.Setting(p).setName("Omitted paths").setDesc(t).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`^archives/
var $=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var U=(k,p)=>{for(var t in p)$(k,t,{get:p[t],enumerable:!0})},X=(k,p,t,a)=>{if(p&&typeof p=="object"||typeof p=="function")for(let n of z(p))!H.call(k,n)&&n!==t&&$(k,n,{get:()=>p[n],enumerable:!(a=j(p,n))||a.enumerable});return k};var K=k=>X($({},"__esModule",{value:!0}),k);var ee={};U(ee,{default:()=>O});module.exports=K(ee);var f=require("obsidian");var _={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:[]}};var y=require("obsidian"),R=class extends y.PluginSettingTab{constructor(p,t,a,n){super(p,t),this.plugin=t,this.settings=a,this.onSettingsChange=n}display(){let{containerEl:p}=this;p.empty(),new y.Setting(p).setHeading().setName("Calendar"),new y.Setting(p).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(n=>{n.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(o=>{this.settings.calendar.firstDayOfWeek=parseInt(o,10),this.saveAndRefresh()})}),new y.Setting(p).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(n=>{n.setValue(this.settings.calendar.showNoteIndicators).onChange(o=>{this.settings.calendar.showNoteIndicators=o,this.saveAndRefresh()})}),new y.Setting(p).setHeading().setName("Periodic Note Paths"),this.addPeriodNoteSettings("Daily",this.settings.daily),this.addPeriodNoteSettings("Weekly",this.settings.weekly),this.addPeriodNoteSettings("Monthly",this.settings.monthly),this.addPeriodNoteSettings("Quarterly",this.settings.quarterly),this.addPeriodNoteSettings("Yearly",this.settings.yearly),new y.Setting(p).setHeading().setName("Recent Files"),new y.Setting(p).setName("Max items").setDesc("Maximum number of recent files to track.").addText(n=>{n.inputEl.setAttr("type","number"),n.inputEl.setAttr("placeholder","50"),n.setValue(String(this.settings.recentFiles.maxItems)),n.inputEl.onblur=()=>{let o=parseInt(n.getValue(),10);!isNaN(o)&&o>0&&(this.settings.recentFiles.maxItems=o,this.saveAndRefresh())}}),new y.Setting(p).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(n=>{n.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(o=>{this.settings.recentFiles.updateOn=o,this.saveAndRefresh()})});let t=new DocumentFragment;t.appendText("Regex patterns for paths to exclude. One per line."),new y.Setting(p).setName("Omitted paths").setDesc(t).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`^archives/
\\.png$`),n.setValue(this.settings.recentFiles.omittedPaths.join(`
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=n.getValue().split(`
`).filter(o=>o.trim()),this.saveAndRefresh()}});let a=new DocumentFragment;a.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new f.Setting(p).setName("Omitted tags").setDesc(a).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`ignore
`).filter(o=>o.trim()),this.saveAndRefresh()}});let a=new DocumentFragment;a.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new y.Setting(p).setName("Omitted tags").setDesc(a).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`ignore
archive`),n.setValue(this.settings.recentFiles.omittedTags.join(`
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=n.getValue().split(`
`).filter(o=>o.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(p,t){new f.Setting(this.containerEl).setHeading().setName(p),new f.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${p.toLowerCase()} notes.`).addText(a=>{a.setPlaceholder("periodic/daily"),a.setValue(t.folder),a.onChange(n=>{t.folder=n,this.saveAndRefresh()})}),new f.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${p.toLowerCase()} note filenames (moment.js format).`).addText(a=>{a.setPlaceholder("yyyy-MM-dd"),a.setValue(t.nameFormat),a.onChange(n=>{t.nameFormat=n,this.saveAndRefresh()})}),new f.Setting(this.containerEl).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(a=>{a.setPlaceholder("Templates/Daily note"),a.setValue(t.templateFile),a.onChange(n=>{t.templateFile=n,this.saveAndRefresh()})}),new f.Setting(this.containerEl).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(a=>{a.setPlaceholder("daily-note"),a.setValue(t.typeProperty),a.onChange(n=>{t.typeProperty=n,this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var h=require("obsidian");var F=require("obsidian");function Q(w,p,t){let a=(0,F.moment)({year:w,month:p,day:1}),n=(0,F.moment)(a).endOf("month"),o=(0,F.moment)(a).subtract((a.day()-t+7)%7,"days"),e=(0,F.moment)().startOf("day"),r=[],i=(0,F.moment)(o);for(;i.isBefore(n)||i.month()===p;){let c=[];for(let s=0;s<7;s++)c.push({date:(0,F.moment)(i),dayOfMonth:i.date(),isToday:i.isSame(e,"day"),isCurrentMonth:i.month()===p,isoWeekNumber:i.isoWeek()}),i.add(1,"day");if(r.push({weekNumber:c[0].isoWeekNumber,days:c}),r.length>=6)break}return r}var x="waypoint-view",Y=class extends h.ItemView{constructor(t,a){super(t);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,h.moment)().month();this.currentDisplayYear=(0,h.moment)().year();this.dragId=null;this.plugin=a}getViewType(){return x}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 a=t.createDiv({cls:"waypoint-calendar"}),n=(0,h.moment)(),o=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),e=a.createDiv({cls:"waypoint-calendar-top"}),r=e.createDiv({cls:"waypoint-calendar-breadcrumb"}),i=o.format("[Q]Q");r.createSpan({cls:"waypoint-clickable",text:i}).addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",o)});let s=o.format("MMMM");r.createSpan({cls:"waypoint-clickable",text:s}).addEventListener("click",()=>{this.plugin.openPeriodNote("month",o)});let d=o.format("YYYY");r.createSpan({cls:"waypoint-clickable",text:d}).addEventListener("click",()=>{this.plugin.openPeriodNote("year",o)});let u=e.createDiv({cls:"waypoint-calendar-today-group"}),b=u.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(b,"chevron-left"),b.addEventListener("click",()=>this.navigateMonth(-1)),u.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,h.moment)().month(),this.currentDisplayYear=(0,h.moment)().year(),this.redraw()});let L=u.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(L,"chevron-right"),L.addEventListener("click",()=>this.navigateMonth(1));let P=a.createEl("table"),C=P.createEl("thead").createEl("tr");C.createEl("th",{text:""});let y=["sun","mon","tue","wed","thu","fri","sat"],B=this.plugin.settings.calendar.firstDayOfWeek;for(let v=0;v<7;v++){let M=(B+v)%7;C.createEl("th",{text:y[M]})}let k=P.createEl("tbody"),D=Q(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let v of D){let M=k.createEl("tr"),N=M.createEl("td",{cls:"waypoint-weeknum"});N.setText(String(v.weekNumber)),N.addEventListener("click",()=>{let E=v.days[0].date;this.plugin.openPeriodNote("week",E)});for(let E of v.days){let T=M.createEl("td",{cls:"waypoint-day"});if(T.setText(String(E.dayOfMonth)),E.isCurrentMonth||T.addClass("other-month"),E.isToday&&T.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let O=E.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(G=>G.extension==="md"&&G.basename===O)&&T.addClass("has-note")}T.addEventListener("click",()=>{this.plugin.openPeriodNote("day",E.date)})}}}navigateMonth(t){let a=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(t,"month");this.currentDisplayMonth=a.month(),this.currentDisplayYear=a.year(),this.redraw()}renderRecentFiles(){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){ Line truncated
`).filter(o=>o.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(p,t){new y.Setting(this.containerEl).setHeading().setName(p),new y.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${p.toLowerCase()} notes.`).addText(a=>{a.setPlaceholder("periodic/daily"),a.setValue(t.folder),a.onChange(n=>{t.folder=n,this.saveAndRefresh()})}),new y.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${p.toLowerCase()} note filenames (moment.js format).`).addText(a=>{a.setPlaceholder("yyyy-MM-dd"),a.setValue(t.nameFormat),a.onChange(n=>{t.nameFormat=n,this.saveAndRefresh()})}),new y.Setting(this.containerEl).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(a=>{a.setPlaceholder("Templates/Daily note"),a.setValue(t.templateFile),a.onChange(n=>{t.templateFile=n,this.saveAndRefresh()})}),new y.Setting(this.containerEl).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(a=>{a.setPlaceholder("daily-note"),a.setValue(t.typeProperty),a.onChange(n=>{t.typeProperty=n,this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var h=require("obsidian");var T=require("obsidian");function Q(k,p,t){let a=(0,T.moment)({year:k,month:p,day:1}),n=(0,T.moment)(a).endOf("month"),o=(0,T.moment)(a).subtract((a.day()-t+7)%7,"days"),e=(0,T.moment)().startOf("day"),r=[],i=(0,T.moment)(o);for(;i.isBefore(n)||i.month()===p;){let c=[];for(let s=0;s<7;s++)c.push({date:(0,T.moment)(i),dayOfMonth:i.date(),isToday:i.isSame(e,"day"),isCurrentMonth:i.month()===p,isoWeekNumber:i.isoWeek()}),i.add(1,"day");if(r.push({weekNumber:c[0].isoWeekNumber,days:c}),r.length>=6)break}return r}var I="waypoint-view",N=class extends h.ItemView{constructor(t,a){super(t);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,h.moment)().month();this.currentDisplayYear=(0,h.moment)().year();this.dragId=null;this.plugin=a}getViewType(){return I}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 a=t.createDiv({cls:"waypoint-calendar"}),n=(0,h.moment)(),o=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),e=a.createDiv({cls:"waypoint-calendar-top"}),r=e.createDiv({cls:"waypoint-calendar-breadcrumb"}),i=o.format("[Q]Q"),c=r.createSpan({cls:"waypoint-clickable",text:i});c.addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",o)}),c.addEventListener("mousedown",g=>{g.button===1&&(g.preventDefault(),this.plugin.openPeriodNoteInLeaf("quarter",o,this.app.workspace.getLeaf("tab")))});let s=o.format("MMMM"),l=r.createSpan({cls:"waypoint-clickable",text:s});l.addEventListener("click",()=>{this.plugin.openPeriodNote("month",o)}),l.addEventListener("mousedown",g=>{g.button===1&&(g.preventDefault(),this.plugin.openPeriodNoteInLeaf("month",o,this.app.workspace.getLeaf("tab")))});let d=o.format("YYYY"),m=r.createSpan({cls:"waypoint-clickable",text:d});m.addEventListener("click",()=>{this.plugin.openPeriodNote("year",o)}),m.addEventListener("mousedown",g=>{g.button===1&&(g.preventDefault(),this.plugin.openPeriodNoteInLeaf("year",o,this.app.workspace.getLeaf("tab")))});let u=e.createDiv({cls:"waypoint-calendar-today-group"}),w=u.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(w,"chevron-left"),w.addEventListener("click",()=>this.navigateMonth(-1)),u.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,h.moment)().month(),this.currentDisplayYear=(0,h.moment)().year(),this.redraw()});let M=u.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(M,"chevron-right"),M.addEventListener("click",()=>this.navigateMonth(1));let L=a.createEl("table"),C=L.createEl("thead").createEl("tr");C.createEl("th",{text:""});let v=["sun","mon","tue","wed","thu","fri","sat"],W=this.plugin.settings.calendar.firstDayOfWeek;for(let g=0;g<7;g++){let S=(W+g)%7;C.createEl("th",{text:v[S]})}let b=L.createEl("tbody"),E=Q(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let g of E){let S=b.createEl("tr"),A=S.createEl("td",{cls:"waypoint-weeknum"});A.setText(String(g.weekNumber)),A.addEventListener("click",()=>{let D=g.days[0].date;this.plugin.openPeriodNote("week",D)}),A.addEventListener("mousedown",D=>{if(D.button===1){D.preventDefault();let x=this.app.workspace.getLeaf("tab");this.plugin.openPeriodNoteInLeaf("week",monday,x)}});for(let D of g.days){let x=S.createEl("td",{cls:"waypoint-day"});if(x.setText(String(D.dayOfMonth)),D.isCurrentMonth||x.addClass("other-month"),D.isToday&&x.addClass("today"),this.plugin.settings.calendar.show Line truncated
type: ${e.typeProperty}
date: ${a.format("YYYY-MM-DD")}
---
`;c=await this.app.vault.create(i,d)}}catch(s){new g.Notice(`Failed to create ${o.label.toLowerCase()} note: ${s.message}`);return}new g.Notice(`Created ${o.label.toLowerCase()} note: ${r}`)}c&&await this.app.workspace.getLeaf(!1).openFile(c)}detectPeriodType(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?{period:"day",date:(0,g.moment)(t,"YYYY-MM-DD")}:/^\d{4}-W\d{2}$/.test(t)?{period:"week",date:(0,g.moment)(t,"GGGG-[W]WW")}:/^\d{4}-\d{2}$/.test(t)?{period:"month",date:(0,g.moment)(t,"YYYY-MM")}:/^\d{4}-Q[1-4]$/.test(t)?{period:"quarter",date:(0,g.moment)(t,"YYYY-[Q]Q")}:/^\d{4}$/.test(t)?{period:"year",date:(0,g.moment)(t,"YYYY")}:null}async navigatePeriodNote(t){let a=this.app.workspace.getActiveFile();if(!a){new g.Notice("No active file");return}let n=this.detectPeriodType(a.basename);if(!n){new g.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:o,date:e}=n;if(!e.isValid()){new g.Notice(`Could not parse date from filename: ${a.basename}`);return}let r=t==="next"?1:-1,i=o==="quarter"?e.clone().add(r*3,"months"):e.clone().add(r,`${o}s`);await this.openPeriodNote(o,i)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(x);for(let a of t)a.view instanceof Y&&a.view.redraw()}async getNotesForDate(t){return this.app.vault.getFiles().filter(a=>a.extension==="md"&&a.basename===t)}async hasNoteForDate(t){return this.app.vault.getFiles().some(a=>a.extension==="md"&&a.basename===t)}};
`;c=await this.app.vault.create(i,d)}}catch(s){new f.Notice(`Failed to create ${o.label.toLowerCase()} note: ${s.message}`);return}new f.Notice(`Created ${o.label.toLowerCase()} note: ${r}`)}c&&await this.app.workspace.getLeaf(!1).openFile(c)}async openPeriodNoteInLeaf(t,a,n){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,i=a.format(r.nameFormat)+".md",c=r.folder?`${r.folder}/${i}`:i,s=this.app.vault.getFileByPath(c);if(!s)try{let l=r.templateFile+".md",d=this.app.vault.getFileByPath(l);if(d){let m=await this.app.vault.read(d);s=await this.app.vault.create(c,m)}else{let m=`---
type: ${r.typeProperty}
date: ${a.format("YYYY-MM-DD")}
---
`;s=await this.app.vault.create(c,m)}}catch(l){new f.Notice(`Failed to create ${e.label.toLowerCase()} note: ${l.message}`);return}s&&await n.openFile(s)}detectPeriodType(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?{period:"day",date:(0,f.moment)(t,"YYYY-MM-DD")}:/^\d{4}-W\d{2}$/.test(t)?{period:"week",date:(0,f.moment)(t,"GGGG-[W]WW")}:/^\d{4}-\d{2}$/.test(t)?{period:"month",date:(0,f.moment)(t,"YYYY-MM")}:/^\d{4}-Q[1-4]$/.test(t)?{period:"quarter",date:(0,f.moment)(t,"YYYY-[Q]Q")}:/^\d{4}$/.test(t)?{period:"year",date:(0,f.moment)(t,"YYYY")}:null}async navigatePeriodNote(t){let a=this.app.workspace.getActiveFile();if(!a){new f.Notice("No active file");return}let n=this.detectPeriodType(a.basename);if(!n){new f.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:o,date:e}=n;if(!e.isValid()){new f.Notice(`Could not parse date from filename: ${a.basename}`);return}let r=t==="next"?1:-1,i=o==="quarter"?e.clone().add(r*3,"months"):e.clone().add(r,`${o}s`);await this.openPeriodNote(o,i)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(I);for(let a of t)a.view instanceof N&&a.view.redraw()}async getNotesForDate(t){return this.app.vault.getFiles().filter(a=>a.extension==="md"&&a.basename===t)}async hasNoteForDate(t){return this.app.vault.getFiles().some(a=>a.extension==="md"&&a.basename===t)}};
+37
View File
@@ -376,6 +376,43 @@ export default class WaypointPlugin extends Plugin {
}
}
// ── Open period note in a specific leaf (for middle-click) ──
async openPeriodNoteInLeaf(period: 'day' | 'week' | 'month' | 'quarter' | 'year', date: moment.Moment, leaf: any): Promise<void> {
type PeriodConfig = { settings: PeriodNoteSettings; label: string };
const configs: Record<string, PeriodConfig> = {
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' },
};
const config = configs[period];
if (!config) return;
const { settings: periodSettings } = config;
const filename = date.format(periodSettings.nameFormat) + '.md';
const fullPath = periodSettings.folder ? `${periodSettings.folder}/${filename}` : filename;
let file = this.app.vault.getFileByPath(fullPath);
if (!file) {
try {
const templatePath = periodSettings.templateFile + '.md';
const templateFile = this.app.vault.getFileByPath(templatePath);
if (templateFile) {
const templateContent = await this.app.vault.read(templateFile);
file = await this.app.vault.create(fullPath, templateContent);
} else {
const content = `---\ntype: ${periodSettings.typeProperty}\ndate: ${date.format('YYYY-MM-DD')}\n---\n\n`;
file = await this.app.vault.create(fullPath, content);
}
} catch (err) {
new Notice(`Failed to create ${config.label.toLowerCase()} note: ${err.message}`);
return;
}
}
if (file) {
await leaf.openFile(file);
}
}
// ── Period note navigation (next/prev from current file) ──
/**
+42 -1
View File
@@ -84,18 +84,36 @@ export class WaypointView extends ItemView {
qEl.addEventListener('click', () => {
this.plugin.openPeriodNote('quarter', displayDate);
});
qEl.addEventListener('mousedown', (event: MouseEvent) => {
if (event.button === 1) {
event.preventDefault();
this.plugin.openPeriodNoteInLeaf('quarter', displayDate, this.app.workspace.getLeaf('tab'));
}
});
const mLabel = displayDate.format('MMMM');
const mEl = breadcrumb.createSpan({ cls: 'waypoint-clickable', text: mLabel });
mEl.addEventListener('click', () => {
this.plugin.openPeriodNote('month', displayDate);
});
mEl.addEventListener('mousedown', (event: MouseEvent) => {
if (event.button === 1) {
event.preventDefault();
this.plugin.openPeriodNoteInLeaf('month', displayDate, this.app.workspace.getLeaf('tab'));
}
});
const yLabel = displayDate.format('YYYY');
const yEl = breadcrumb.createSpan({ cls: 'waypoint-clickable', text: yLabel });
yEl.addEventListener('click', () => {
this.plugin.openPeriodNote('year', displayDate);
});
yEl.addEventListener('mousedown', (event: MouseEvent) => {
if (event.button === 1) {
event.preventDefault();
this.plugin.openPeriodNoteInLeaf('year', displayDate, this.app.workspace.getLeaf('tab'));
}
});
// Right: ◀ Today ▶
const todayGroup = topRow.createDiv({ cls: 'waypoint-calendar-today-group' });
@@ -148,6 +166,13 @@ export class WaypointView extends ItemView {
const monday = week.days[0].date;
this.plugin.openPeriodNote('week', monday);
});
wnCell.addEventListener('mousedown', (event: MouseEvent) => {
if (event.button === 1) {
event.preventDefault();
const file = this.app.workspace.getLeaf('tab');
this.plugin.openPeriodNoteInLeaf('week', monday, file);
}
});
for (const day of week.days) {
const cell = row.createEl('td', { cls: 'waypoint-day' });
@@ -173,6 +198,13 @@ export class WaypointView extends ItemView {
cell.addEventListener('click', () => {
this.plugin.openPeriodNote('day', day.date);
});
cell.addEventListener('mousedown', (event: MouseEvent) => {
if (event.button === 1) {
event.preventDefault();
const file = this.app.workspace.getLeaf('tab');
this.plugin.openPeriodNoteInLeaf('day', day.date, file);
}
});
}
}
@@ -258,13 +290,22 @@ export class WaypointView extends ItemView {
.setIcon('file-plus')
.onClick(() => this.focusFile(file, 'tab')),
);
menu.addItem((item) =>
item
.setSection('action')
.setTitle('Add to bookmarks')
.setIcon('bookmark')
.onClick(() => {
this.plugin.addBookmark(file.path, file.basename, 'file');
new Notice(`Bookmarked: ${file.basename}`);
}),
);
const tfile = this.app.vault.getAbstractFileByPath(file.path);
if (tfile) {
this.app.workspace.trigger('file-menu', menu, tfile, 'link-context-menu');
}
menu.showAtPosition({ x: event.clientX, y: event.clientY });
});
// Left click
navFileTitle.addEventListener('click', (event: MouseEvent) => {
const newLeaf = Keymap.isModEvent(event);