feat: parent notes (file bookmarks with children) + no default icon
- File bookmarks can now have children, rendered with a chevron - Group bookmarks can have an associated filePath; clicking opens the file, clicking chevron toggles collapse - 'Add as parent note' option in header context menu creates a group with the current file linked - 'Add child note' option in group context menu creates a sub-group with the current file linked (parent note pattern) - Default icon changed from 'file'/'folder' to '' (no icon) - Chevron click always toggles collapse regardless of type
This commit is contained in:
1 parent
4278507ae2
commit
3c4fc2d91c
3 files changed
+84
-17
No files matched your search
@@ -2,15 +2,15 @@
|
|||||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var $=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var U=(y,c)=>{for(var t in c)$(y,t,{get:c[t],enumerable:!0})},K=(y,c,t,e)=>{if(c&&typeof c=="object"||typeof c=="function")for(let n of H(c))!_.call(y,n)&&n!==t&&$(y,n,{get:()=>c[n],enumerable:!(e=z(c,n))||e.enumerable});return y};var X=y=>K($({},"__esModule",{value:!0}),y);var ee={};U(ee,{default:()=>R});module.exports=X(ee);var u=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 g=require("obsidian"),W=class extends g.PluginSettingTab{constructor(c,t,e,n){super(c,t),this.plugin=t,this.settings=e,this.onSettingsChange=n}display(){let{containerEl:c}=this;c.empty(),new g.Setting(c).setHeading().setName("Calendar"),new g.Setting(c).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(r=>{this.settings.calendar.firstDayOfWeek=parseInt(r,10),this.saveAndRefresh()})}),new g.Setting(c).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(n=>{n.setValue(this.settings.calendar.showNoteIndicators).onChange(r=>{this.settings.calendar.showNoteIndicators=r,this.saveAndRefresh()})}),new g.Setting(c).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 g.Setting(c).setHeading().setName("Recent Files"),new g.Setting(c).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 r=parseInt(n.getValue(),10);!isNaN(r)&&r>0&&(this.settings.recentFiles.maxItems=r,this.saveAndRefresh())}}),new g.Setting(c).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(r=>{this.settings.recentFiles.updateOn=r,this.saveAndRefresh()})});let t=new DocumentFragment;t.appendText("Regex patterns for paths to exclude. One per line."),new g.Setting(c).setName("Omitted paths").setDesc(t).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`^archives/
|
var $=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var U=(y,p)=>{for(var a in p)$(y,a,{get:p[a],enumerable:!0})},K=(y,p,a,t)=>{if(p&&typeof p=="object"||typeof p=="function")for(let n of H(p))!_.call(y,n)&&n!==a&&$(y,n,{get:()=>p[n],enumerable:!(t=z(p,n))||t.enumerable});return y};var X=y=>K($({},"__esModule",{value:!0}),y);var ee={};U(ee,{default:()=>R});module.exports=X(ee);var u=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 g=require("obsidian"),W=class extends g.PluginSettingTab{constructor(p,a,t,n){super(p,a),this.plugin=a,this.settings=t,this.onSettingsChange=n}display(){let{containerEl:p}=this;p.empty(),new g.Setting(p).setHeading().setName("Calendar"),new g.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(s=>{this.settings.calendar.firstDayOfWeek=parseInt(s,10),this.saveAndRefresh()})}),new g.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(s=>{this.settings.calendar.showNoteIndicators=s,this.saveAndRefresh()})}),new g.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 g.Setting(p).setHeading().setName("Recent Files"),new g.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 s=parseInt(n.getValue(),10);!isNaN(s)&&s>0&&(this.settings.recentFiles.maxItems=s,this.saveAndRefresh())}}),new g.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(s=>{this.settings.recentFiles.updateOn=s,this.saveAndRefresh()})});let a=new DocumentFragment;a.appendText("Regex patterns for paths to exclude. One per line."),new g.Setting(p).setName("Omitted paths").setDesc(a).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`^archives/
|
||||||
\\.png$`),n.setValue(this.settings.recentFiles.omittedPaths.join(`
|
\\.png$`),n.setValue(this.settings.recentFiles.omittedPaths.join(`
|
||||||
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=n.getValue().split(`
|
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=n.getValue().split(`
|
||||||
`).filter(r=>r.trim()),this.saveAndRefresh()}});let e=new DocumentFragment;e.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new g.Setting(c).setName("Omitted tags").setDesc(e).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`ignore
|
`).filter(s=>s.trim()),this.saveAndRefresh()}});let t=new DocumentFragment;t.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new g.Setting(p).setName("Omitted tags").setDesc(t).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`ignore
|
||||||
archive`),n.setValue(this.settings.recentFiles.omittedTags.join(`
|
archive`),n.setValue(this.settings.recentFiles.omittedTags.join(`
|
||||||
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=n.getValue().split(`
|
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=n.getValue().split(`
|
||||||
`).filter(r=>r.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(c,t){new g.Setting(this.containerEl).setHeading().setName(c),new g.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${c.toLowerCase()} notes.`).addText(e=>{e.setPlaceholder("periodic/daily"),e.setValue(t.folder),e.onChange(n=>{t.folder=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${c.toLowerCase()} note filenames (moment.js format).`).addText(e=>{e.setPlaceholder("yyyy-MM-dd"),e.setValue(t.nameFormat),e.onChange(n=>{t.nameFormat=n,this.saveAndRefresh()})}),new g.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(n=>{t.templateFile=n,this.saveAndRefresh()})}),new g.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(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(y,c,t){let e=(0,T.moment)({year:y,month:c,day:1}),n=(0,T.moment)(e).endOf("month"),r=(0,T.moment)(e).subtract((e.day()-t+7)%7,"days"),a=(0,T.moment)().startOf("day"),s=[],o=(0,T.moment)(r);for(;o.isBefore(n)||o.month()===c;){let i=[];for(let l=0;l<7;l++)i.push({date:(0,T.moment)(o),dayOfMonth:o.date(),isToday:o.isSame(a,"day"),isCurrentMonth:o.month()===c,isoWeekNumber:o.isoWeek()}),o.add(1,"day");if(s.push({weekNumber:i[0].isoWeekNumber,days:i}),s.length>=6)break}return s}var D="waypoint-view",Y=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 D}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"}),n=(0,h.moment)(),r=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),a=e.createDiv({cls:"waypoint-calendar-top"}),s=a.createDiv({cls:"waypoint-calendar-breadcrumb"}),o=r.format("[Q]Q");s.createSpan({cls:"waypoint-clickable",text:o}).addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",r)});let l=r.format("MMMM");s.createSpan({cls:"waypoint-clickable",text:l}).addEventListener("click",()=>{this.plugin.openPeriodNote("month",r)});let d=r.format("YYYY");s.createSpan({cls:"waypoint-clickable",text:d}).addEventListener("click",()=>{this.plugin.openPeriodNote("year",r)});let v=a.createDiv({cls:"waypoint-calendar-today-group"}),I=v.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(I,"chevron-left"),I.addEventListener("click",()=>this.navigateMonth(-1)),v.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 S=v.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(S,"chevron-right"),S.addEventListener("click",()=>this.navigateMonth(1));let E=e.createEl("table"),x=E.createEl("thead").createEl("tr");x.createEl("th",{text:""});let f=["sun","mon","tue","wed","thu","fri","sat"],N=this.plugin.settings.calendar.firstDayOfWeek;for(let w=0;w<7;w++){let L=(N+w)%7;x.createEl("th",{text:f[L]})}let k=E.createEl("tbody"),P=Q(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let w of P){let L=k.createEl("tr"),B=L.createEl("td",{cls:"waypoint-weeknum"});B.setText(String(w.weekNumber)),B.addEventListener("click",()=>{let b=w.days[0].date;this.plugin.openPeriodNote("week",b)});for(let b of w.days){let C=L.createEl("td",{cls:"waypoint-day"});if(C.setText(String(b.dayOfMonth)),b.isCurrentMonth||C.addClass("other-month"),b.isToday&&C.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let O=b.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(V=>V.extension==="md"&&V.basename===O)&&C.addClass("has-note")}C.addEventListener("click",()=>{this.plugin.openPeriodNote("day",b.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
|
`).filter(s=>s.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(p,a){new g.Setting(this.containerEl).setHeading().setName(p),new g.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${p.toLowerCase()} notes.`).addText(t=>{t.setPlaceholder("periodic/daily"),t.setValue(a.folder),t.onChange(n=>{a.folder=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${p.toLowerCase()} note filenames (moment.js format).`).addText(t=>{t.setPlaceholder("yyyy-MM-dd"),t.setValue(a.nameFormat),t.onChange(n=>{a.nameFormat=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(t=>{t.setPlaceholder("Templates/Daily note"),t.setValue(a.templateFile),t.onChange(n=>{a.templateFile=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(t=>{t.setPlaceholder("daily-note"),t.setValue(a.typeProperty),t.onChange(n=>{a.typeProperty=n,this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var h=require("obsidian");var T=require("obsidian");function Q(y,p,a){let t=(0,T.moment)({year:y,month:p,day:1}),n=(0,T.moment)(t).endOf("month"),s=(0,T.moment)(t).subtract((t.day()-a+7)%7,"days"),e=(0,T.moment)().startOf("day"),r=[],o=(0,T.moment)(s);for(;o.isBefore(n)||o.month()===p;){let i=[];for(let l=0;l<7;l++)i.push({date:(0,T.moment)(o),dayOfMonth:o.date(),isToday:o.isSame(e,"day"),isCurrentMonth:o.month()===p,isoWeekNumber:o.isoWeek()}),o.add(1,"day");if(r.push({weekNumber:i[0].isoWeekNumber,days:i}),r.length>=6)break}return r}var D="waypoint-view",Y=class extends h.ItemView{constructor(a,t){super(a);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=t}getViewType(){return D}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let a=this.contentEl.createDiv({cls:"waypoint-section"});a.createDiv({cls:"waypoint-section-header",text:"Calendar"});let t=a.createDiv({cls:"waypoint-calendar"}),n=(0,h.moment)(),s=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),e=t.createDiv({cls:"waypoint-calendar-top"}),r=e.createDiv({cls:"waypoint-calendar-breadcrumb"}),o=s.format("[Q]Q");r.createSpan({cls:"waypoint-clickable",text:o}).addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",s)});let l=s.format("MMMM");r.createSpan({cls:"waypoint-clickable",text:l}).addEventListener("click",()=>{this.plugin.openPeriodNote("month",s)});let d=s.format("YYYY");r.createSpan({cls:"waypoint-clickable",text:d}).addEventListener("click",()=>{this.plugin.openPeriodNote("year",s)});let v=e.createDiv({cls:"waypoint-calendar-today-group"}),I=v.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(I,"chevron-left"),I.addEventListener("click",()=>this.navigateMonth(-1)),v.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 S=v.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(S,"chevron-right"),S.addEventListener("click",()=>this.navigateMonth(1));let E=t.createEl("table"),x=E.createEl("thead").createEl("tr");x.createEl("th",{text:""});let f=["sun","mon","tue","wed","thu","fri","sat"],B=this.plugin.settings.calendar.firstDayOfWeek;for(let k=0;k<7;k++){let L=(B+k)%7;x.createEl("th",{text:f[L]})}let w=E.createEl("tbody"),P=Q(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let k of P){let L=w.createEl("tr"),N=L.createEl("td",{cls:"waypoint-weeknum"});N.setText(String(k.weekNumber)),N.addEventListener("click",()=>{let b=k.days[0].date;this.plugin.openPeriodNote("week",b)});for(let b of k.days){let C=L.createEl("td",{cls:"waypoint-day"});if(C.setText(String(b.dayOfMonth)),b.isCurrentMonth||C.addClass("other-month"),b.isToday&&C.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let O=b.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(V=>V.extension==="md"&&V.basename===O)&&C.addClass("has-note")}C.addEventListener("click",()=>{this.plugin.openPeriodNote("day",b.date)})}}}navigateMonth(a){let t=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(a,"month");this.currentDisplayMonth=t.month(),this.currentDisplayYear=t.year(),this.redraw()}renderRecentFiles(){let a=this.contentEl.createDiv({cls:"waypoint-section waypoint-recent-files"});if(a.createDiv({cls:"waypoint-section-header",text:"Recent Files"}),this.plugin.recentFiles.length===0){
Line truncated
|
||||||
type: ${a.typeProperty}
|
type: ${e.typeProperty}
|
||||||
date: ${e.format("YYYY-MM-DD")}
|
date: ${t.format("YYYY-MM-DD")}
|
||||||
---
|
---
|
||||||
|
|
||||||
`;i=await this.app.vault.create(o,d)}}catch(l){new u.Notice(`Failed to create ${r.label.toLowerCase()} note: ${l.message}`);return}new u.Notice(`Created ${r.label.toLowerCase()} note: ${s}`)}i&&await this.app.workspace.getLeaf(!1).openFile(i)}detectPeriodType(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?{period:"day",date:(0,u.moment)(t,"YYYY-MM-DD")}:/^\d{4}-W\d{2}$/.test(t)?{period:"week",date:(0,u.moment)(t,"GGGG-[W]WW")}:/^\d{4}-\d{2}$/.test(t)?{period:"month",date:(0,u.moment)(t,"YYYY-MM")}:/^\d{4}-Q[1-4]$/.test(t)?{period:"quarter",date:(0,u.moment)(t,"YYYY-[Q]Q")}:/^\d{4}$/.test(t)?{period:"year",date:(0,u.moment)(t,"YYYY")}:null}async navigatePeriodNote(t){let e=this.app.workspace.getActiveFile();if(!e){new u.Notice("No active file");return}let n=this.detectPeriodType(e.basename);if(!n){new u.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:r,date:a}=n;if(!a.isValid()){new u.Notice(`Could not parse date from filename: ${e.basename}`);return}let s=t==="next"?1:-1,o=r==="quarter"?a.clone().add(s*3,"months"):a.clone().add(s,`${r}s`);await this.openPeriodNote(r,o)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(D);for(let e of t)e.view instanceof Y&&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)}};
|
`;i=await this.app.vault.create(o,d)}}catch(l){new u.Notice(`Failed to create ${s.label.toLowerCase()} note: ${l.message}`);return}new u.Notice(`Created ${s.label.toLowerCase()} note: ${r}`)}i&&await this.app.workspace.getLeaf(!1).openFile(i)}detectPeriodType(a){return/^\d{4}-\d{2}-\d{2}$/.test(a)?{period:"day",date:(0,u.moment)(a,"YYYY-MM-DD")}:/^\d{4}-W\d{2}$/.test(a)?{period:"week",date:(0,u.moment)(a,"GGGG-[W]WW")}:/^\d{4}-\d{2}$/.test(a)?{period:"month",date:(0,u.moment)(a,"YYYY-MM")}:/^\d{4}-Q[1-4]$/.test(a)?{period:"quarter",date:(0,u.moment)(a,"YYYY-[Q]Q")}:/^\d{4}$/.test(a)?{period:"year",date:(0,u.moment)(a,"YYYY")}:null}async navigatePeriodNote(a){let t=this.app.workspace.getActiveFile();if(!t){new u.Notice("No active file");return}let n=this.detectPeriodType(t.basename);if(!n){new u.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:s,date:e}=n;if(!e.isValid()){new u.Notice(`Could not parse date from filename: ${t.basename}`);return}let r=a==="next"?1:-1,o=s==="quarter"?e.clone().add(r*3,"months"):e.clone().add(r,`${s}s`);await this.openPeriodNote(s,o)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let a=this.app.workspace.getLeavesOfType(D);for(let t of a)t.view instanceof Y&&t.view.redraw()}async getNotesForDate(a){return this.app.vault.getFiles().filter(t=>t.extension==="md"&&t.basename===a)}async hasNoteForDate(a){return this.app.vault.getFiles().some(t=>t.extension==="md"&&t.basename===a)}};
|
||||||
+1
-1
@@ -254,7 +254,7 @@ export default class WaypointPlugin extends Plugin {
|
|||||||
|
|
||||||
// ── Bookmarks ──
|
// ── Bookmarks ──
|
||||||
|
|
||||||
addBookmark(filePath: string, label: string, type: 'file' | 'group' | 'separator' | 'spacer' = 'file', icon = 'file'): BookmarkItem {
|
addBookmark(filePath: string, label: string, type: 'file' | 'group' | 'separator' | 'spacer' = 'file', icon = ''): BookmarkItem {
|
||||||
const id = `bm-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
const id = `bm-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
||||||
const item: BookmarkItem = {
|
const item: BookmarkItem = {
|
||||||
id,
|
id,
|
||||||
|
|||||||
+77
-10
@@ -316,12 +316,25 @@ export class WaypointView extends ItemView {
|
|||||||
this.plugin.addBookmark(file.path, file.basename, 'file');
|
this.plugin.addBookmark(file.path, file.basename, 'file');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
menu.addItem((item) => {
|
||||||
|
item
|
||||||
|
.setTitle('Add as parent note')
|
||||||
|
.setIcon('folder-plus')
|
||||||
|
.onClick(() => {
|
||||||
|
const file = this.app.workspace.getActiveFile();
|
||||||
|
if (!file) return;
|
||||||
|
const bm = this.plugin.addBookmark(file.path, file.basename, 'group', '');
|
||||||
|
bm.filePath = file.path;
|
||||||
|
this.plugin.saveWaypointData();
|
||||||
|
this.redraw();
|
||||||
|
});
|
||||||
|
});
|
||||||
menu.addItem((item) => {
|
menu.addItem((item) => {
|
||||||
item
|
item
|
||||||
.setTitle('New group')
|
.setTitle('New group')
|
||||||
.setIcon('folder-plus')
|
.setIcon('folder-plus')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
this.plugin.addBookmark('', 'New Group', 'group', 'folder');
|
this.plugin.addBookmark('', 'New Group', 'group', '');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
menu.addItem((item) => {
|
menu.addItem((item) => {
|
||||||
@@ -534,23 +547,30 @@ export class WaypointView extends ItemView {
|
|||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
const chevron = rowEl.createDiv({ cls: 'waypoint-bm-chevron' });
|
const chevron = rowEl.createDiv({ cls: 'waypoint-bm-chevron' });
|
||||||
setIcon(chevron, 'chevron-down');
|
setIcon(chevron, 'chevron-down');
|
||||||
|
chevron.addEventListener('click', (event: MouseEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
this.plugin.updateBookmark(item.id, { collapsed: !item.collapsed });
|
||||||
|
});
|
||||||
|
|
||||||
const iconEl = rowEl.createDiv({ cls: 'waypoint-bm-icon' });
|
const iconEl = rowEl.createDiv({ cls: 'waypoint-bm-icon' });
|
||||||
setIcon(iconEl, item.icon || 'folder');
|
if (item.icon) setIcon(iconEl, item.icon);
|
||||||
|
|
||||||
const labelEl = rowEl.createDiv({ cls: 'waypoint-bm-label', text: item.label });
|
const labelEl = rowEl.createDiv({ cls: 'waypoint-bm-label', text: item.label });
|
||||||
|
|
||||||
|
// Click group row → open linked file (if any), otherwise toggle collapse
|
||||||
rowEl.addEventListener('click', (event: MouseEvent) => {
|
rowEl.addEventListener('click', (event: MouseEvent) => {
|
||||||
// Mod+click opens group's linked file
|
if (item.filePath) {
|
||||||
if (item.filePath && Keymap.isModEvent(event)) {
|
|
||||||
const tfile = this.app.vault.getFileByPath(item.filePath);
|
const tfile = this.app.vault.getFileByPath(item.filePath);
|
||||||
if (tfile) this.app.workspace.getLeaf(false).openFile(tfile);
|
if (tfile) {
|
||||||
|
const newLeaf = Keymap.isModEvent(event);
|
||||||
|
this.app.workspace.getLeaf(newLeaf as any).openFile(tfile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.plugin.updateBookmark(item.id, { collapsed: !item.collapsed });
|
this.plugin.updateBookmark(item.id, { collapsed: !item.collapsed });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Middle click on group header → open group's linked file in new tab
|
// Middle click on group → open in new tab
|
||||||
rowEl.addEventListener('mousedown', (event: MouseEvent) => {
|
rowEl.addEventListener('mousedown', (event: MouseEvent) => {
|
||||||
if (event.button === 1 && item.filePath) {
|
if (event.button === 1 && item.filePath) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -570,8 +590,22 @@ export class WaypointView extends ItemView {
|
|||||||
|
|
||||||
// ── File: icon + label ──
|
// ── File: icon + label ──
|
||||||
} else {
|
} else {
|
||||||
|
// Chevron for file bookmarks that have children
|
||||||
|
if (item.children && item.children.length > 0) {
|
||||||
|
const chevron = rowEl.createDiv({ cls: 'waypoint-bm-chevron' });
|
||||||
|
setIcon(chevron, 'chevron-down');
|
||||||
|
chevron.addEventListener('click', (event: MouseEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
this.plugin.updateBookmark(item.id, { collapsed: !item.collapsed });
|
||||||
|
});
|
||||||
|
if (item.collapsed) {
|
||||||
|
rowEl.addClass('collapsed');
|
||||||
|
chevron.style.transform = 'rotate(-90deg)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const iconEl = rowEl.createDiv({ cls: 'waypoint-bm-icon' });
|
const iconEl = rowEl.createDiv({ cls: 'waypoint-bm-icon' });
|
||||||
setIcon(iconEl, item.icon || 'file');
|
if (item.icon) setIcon(iconEl, item.icon);
|
||||||
|
|
||||||
const labelEl = rowEl.createDiv({ cls: 'waypoint-bm-label', text: item.label });
|
const labelEl = rowEl.createDiv({ cls: 'waypoint-bm-label', text: item.label });
|
||||||
setTooltip(rowEl, item.filePath);
|
setTooltip(rowEl, item.filePath);
|
||||||
@@ -599,6 +633,14 @@ export class WaypointView extends ItemView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Children container for file bookmarks with children
|
||||||
|
if (item.children && item.children.length > 0) {
|
||||||
|
const childrenContainer = container.createDiv({
|
||||||
|
cls: `waypoint-bookmark-children${item.collapsed ? ' collapsed' : ''}`,
|
||||||
|
});
|
||||||
|
this.renderBookmarkList(childrenContainer, item.children, depth + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Right-click context menu (both types) ──
|
// ── Right-click context menu (both types) ──
|
||||||
@@ -687,7 +729,7 @@ export class WaypointView extends ItemView {
|
|||||||
menu.addItem((i) =>
|
menu.addItem((i) =>
|
||||||
i
|
i
|
||||||
.setTitle('Add bookmark here')
|
.setTitle('Add bookmark here')
|
||||||
.setIcon('plus')
|
.setIcon('file-plus')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
const file = this.app.workspace.getActiveFile();
|
const file = this.app.workspace.getActiveFile();
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -699,7 +741,32 @@ export class WaypointView extends ItemView {
|
|||||||
type: 'file',
|
type: 'file',
|
||||||
label: file.basename,
|
label: file.basename,
|
||||||
filePath: file.path,
|
filePath: file.path,
|
||||||
icon: 'file',
|
icon: '',
|
||||||
|
children: [],
|
||||||
|
collapsed: false,
|
||||||
|
indent: item.indent + 1,
|
||||||
|
};
|
||||||
|
item.children.push(child);
|
||||||
|
this.plugin.saveWaypointData();
|
||||||
|
this.redraw();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
menu.addItem((i) =>
|
||||||
|
i
|
||||||
|
.setTitle('Add child note')
|
||||||
|
.setIcon('file-plus')
|
||||||
|
.onClick(() => {
|
||||||
|
const file = this.app.workspace.getActiveFile();
|
||||||
|
if (!file) {
|
||||||
|
new Notice('No active file');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const child: BookmarkItem = {
|
||||||
|
id: `bm-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
||||||
|
type: 'group',
|
||||||
|
label: file.basename,
|
||||||
|
filePath: file.path,
|
||||||
|
icon: '',
|
||||||
children: [],
|
children: [],
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
indent: item.indent + 1,
|
indent: item.indent + 1,
|
||||||
@@ -719,7 +786,7 @@ export class WaypointView extends ItemView {
|
|||||||
type: 'group',
|
type: 'group',
|
||||||
label: 'New Group',
|
label: 'New Group',
|
||||||
filePath: '',
|
filePath: '',
|
||||||
icon: 'folder',
|
icon: '',
|
||||||
children: [],
|
children: [],
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
indent: item.indent + 1,
|
indent: item.indent + 1,
|
||||||
|
|||||||
Reference in new issue
Block a user