Initial commit: Waypoint Obsidian plugin with calendar, recent files, and bookmarks
This commit is contained in:
commit
fbdc42b4a3
16 files changed
+3400
No files matched your search
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
*/
|
||||
|
||||
var V=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var U=(f,d)=>{for(var t in d)V(f,t,{get:d[t],enumerable:!0})},K=(f,d,t,e)=>{if(d&&typeof d=="object"||typeof d=="function")for(let a of H(d))!_.call(f,a)&&a!==t&&V(f,a,{get:()=>d[a],enumerable:!(e=Q(d,a))||e.enumerable});return f};var X=f=>K(V({},"__esModule",{value:!0}),f);var ee={};U(ee,{default:()=>R});module.exports=X(ee);var b=require("obsidian");var j={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 u=require("obsidian"),W=class extends u.PluginSettingTab{constructor(d,t,e,a){super(d,t),this.plugin=t,this.settings=e,this.onSettingsChange=a}display(){let{containerEl:d}=this;d.empty(),new u.Setting(d).setHeading().setName("Calendar"),new u.Setting(d).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(a=>{a.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(s=>{this.settings.calendar.firstDayOfWeek=parseInt(s,10),this.saveAndRefresh()})}),new u.Setting(d).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(a=>{a.setValue(this.settings.calendar.showNoteIndicators).onChange(s=>{this.settings.calendar.showNoteIndicators=s,this.saveAndRefresh()})}),new u.Setting(d).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 u.Setting(d).setHeading().setName("Recent Files"),new u.Setting(d).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 s=parseInt(a.getValue(),10);!isNaN(s)&&s>0&&(this.settings.recentFiles.maxItems=s,this.saveAndRefresh())}}),new u.Setting(d).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(s=>{this.settings.recentFiles.updateOn=s,this.saveAndRefresh()})});let t=new DocumentFragment;t.appendText("Regex patterns for paths to exclude. One per line."),new u.Setting(d).setName("Omitted paths").setDesc(t).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(s=>s.trim()),this.saveAndRefresh()}});let e=new DocumentFragment;e.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new u.Setting(d).setName("Omitted tags").setDesc(e).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(s=>s.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(d,t){new u.Setting(this.containerEl).setHeading().setName(d),new u.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${d.toLowerCase()} notes.`).addText(e=>{e.setPlaceholder("periodic/daily"),e.setValue(t.folder),e.onChange(a=>{t.folder=a,this.saveAndRefresh()})}),new u.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${d.toLowerCase()} note filenames (moment.js format).`).addText(e=>{e.setPlaceholder("yyyy-MM-dd"),e.setValue(t.nameFormat),e.onChange(a=>{t.nameFormat=a,this.saveAndRefresh()})}),new u.Setting(this.containerEl).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(e=>{e.setPlaceholder("Templates/Daily note"),e.setValue(t.templateFile),e.onChange(a=>{t.templateFile=a,this.saveAndRefresh()})}),new u.Setting(this.containerEl).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(e=>{e.setPlaceholder("daily-note"),e.setValue(t.typeProperty),e.onChange(a=>{t.typeProperty=a,this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var h=require("obsidian");var F=require("obsidian");function z(f,d,t){let e=(0,F.moment)({year:f,month:d,day:1}),a=(0,F.moment)(e).endOf("month"),s=(0,F.moment)(e).subtract((e.day()-t+7)%7,"days"),o=(0,F.moment)().startOf("day"),l=[],n=(0,F.moment)(s);for(;n.isBefore(a)||n.month()===d;){let i=[];for(let r=0;r<7;r++)i.push({date:(0,F.moment)(n),dayOfMonth:n.date(),isToday:n.isSame(o,"day"),isCurrentMonth:n.month()===d,isoWeekNumber:n.isoWeek()}),n.add(1,"day");if(l.push({weekNumber:i[0].isoWeekNumber,days:i}),l.length>=6)break}return l}var w="waypoint-view",A=class extends h.ItemView{constructor(t,e){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=e}getViewType(){return w}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 e=t.createDiv({cls:"waypoint-calendar"}),a=(0,h.moment)(),s=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),o=e.createDiv({cls:"waypoint-calendar-top"}),l=o.createDiv({cls:"waypoint-calendar-breadcrumb"}),n=s.format("[Q]Q");l.createSpan({cls:"waypoint-clickable",text:n}).addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",s)});let r=s.format("MMMM");l.createSpan({cls:"waypoint-clickable",text:r}).addEventListener("click",()=>{this.plugin.openPeriodNote("month",s)});let c=s.format("YYYY");l.createSpan({cls:"waypoint-clickable",text:c}).addEventListener("click",()=>{this.plugin.openPeriodNote("year",s)});let D=o.createDiv({cls:"waypoint-calendar-today-group"}),x=D.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(x,"chevron-left"),x.addEventListener("click",()=>this.navigateMonth(-1)),D.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=D.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(M,"chevron-right"),M.addEventListener("click",()=>this.navigateMonth(1));let E=e.createEl("table"),I=E.createEl("thead").createEl("tr");I.createEl("th",{text:""});let g=["sun","mon","tue","wed","thu","fri","sat"],Y=this.plugin.settings.calendar.firstDayOfWeek;for(let y=0;y<7;y++){let S=(Y+y)%7;I.createEl("th",{text:g[S]})}let v=E.createEl("tbody"),T=z(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let y of T){let S=v.createEl("tr"),N=S.createEl("td",{cls:"waypoint-weeknum"});N.setText(String(y.weekNumber)),N.addEventListener("click",()=>{let k=y.days[0].date;this.plugin.openPeriodNote("week",k)});for(let k of y.days){let C=S.createEl("td",{cls:"waypoint-day"});if(C.setText(String(k.dayOfMonth)),k.isCurrentMonth||C.addClass("other-month"),k.isToday&&C.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let O=k.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(q=>q.extension==="md"&&q.basename===O)&&C.addClass("has-note")}C.addEventListener("click",()=>{this.plugin.openPeriodNote("day",k.date)})}}}navigateMonth(t){let e=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(t,"month");this.currentDisplayMonth=e.month(),this.currentDisplayYear=e.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
|
||||
type: ${o.typeProperty}
|
||||
date: ${e.format("YYYY-MM-DD")}
|
||||
---
|
||||
|
||||
`;i=await this.app.vault.create(n,c)}}catch(r){new b.Notice(`Failed to create ${s.label.toLowerCase()} note: ${r.message}`);return}new b.Notice(`Created ${s.label.toLowerCase()} note: ${l}`)}i&&await this.app.workspace.getLeaf(!1).openFile(i)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(w);for(let e of t)e.view instanceof A&&e.view.redraw()}async getNotesForDate(t){return this.app.vault.getFiles().filter(e=>e.extension==="md"&&e.basename===t)}async hasNoteForDate(t){return this.app.vault.getFiles().some(e=>e.extension==="md"&&e.basename===t)}};
|
||||
Reference in new issue
Block a user