feat: add date systems menu to calendar days
Right-clicking a calendar day now lists every configured date-prefixed note system. Journal notes are singletons; {title} formats support multiple notes per date, such as meetings.\n\nAdds default Journal and Meeting systems, configurable settings UI, safe filename/title handling, one shared dated-note creation path, and a compiled menu smoke test fixture in the test vault.
This commit is contained in:
1 parent
b617c275eb
commit
26a1a481ac
10 files changed
+731
-76
No files matched your search
+139
-2
@@ -1,12 +1,13 @@
|
||||
import { Setting, PluginSettingTab, App, setIcon } from 'obsidian';
|
||||
import type WaypointPlugin from 'src/main';
|
||||
import { WaypointSettings, DEFAULT_SETTINGS, PeriodNoteSettings } from 'src/settings';
|
||||
import { WaypointSettings, DEFAULT_SETTINGS, DEFAULT_DATE_SYSTEM, PeriodNoteSettings } from 'src/settings';
|
||||
import { formatHasDateToken } from 'src/utils/date-systems';
|
||||
|
||||
export class WaypointSettingTab extends PluginSettingTab {
|
||||
private plugin: WaypointPlugin;
|
||||
private settings: WaypointSettings;
|
||||
private onSettingsChange: () => void;
|
||||
private activeTab: 'calendar' | 'periodic' | 'recent' | 'display' | 'about' = 'calendar';
|
||||
private activeTab: 'calendar' | 'periodic' | 'systems' | 'recent' | 'display' | 'about' = 'calendar';
|
||||
|
||||
constructor(app: App, plugin: WaypointPlugin, settings: WaypointSettings, onSettingsChange: () => void) {
|
||||
super(app, plugin);
|
||||
@@ -24,6 +25,7 @@ export class WaypointSettingTab extends PluginSettingTab {
|
||||
const tabs = [
|
||||
{ key: 'calendar' as const, label: 'Calendar' },
|
||||
{ key: 'periodic' as const, label: 'Periodic Notes' },
|
||||
{ key: 'systems' as const, label: 'Date systems' },
|
||||
{ key: 'recent' as const, label: 'Recent Files' },
|
||||
{ key: 'display' as const, label: 'Display' },
|
||||
{ key: 'about' as const, label: 'About' },
|
||||
@@ -49,6 +51,9 @@ export class WaypointSettingTab extends PluginSettingTab {
|
||||
case 'periodic':
|
||||
this.renderPeriodicTab(tabContent);
|
||||
break;
|
||||
case 'systems':
|
||||
this.renderSystemsTab(tabContent);
|
||||
break;
|
||||
case 'recent':
|
||||
this.renderRecentTab(tabContent);
|
||||
break;
|
||||
@@ -157,6 +162,138 @@ export class WaypointSettingTab extends PluginSettingTab {
|
||||
});
|
||||
}
|
||||
|
||||
// ═══════════════════════════════
|
||||
// Date systems tab
|
||||
// ═══════════════════════════════
|
||||
|
||||
private renderSystemsTab(container: HTMLElement): void {
|
||||
const intro = new DocumentFragment();
|
||||
intro.createDiv({ text: 'A date system is a folder of notes whose filenames start with a date. Each one appears in the calendar\'s right-click menu for that day.' });
|
||||
intro.createDiv({ text: 'The daily note is configured under Periodic Notes and always comes first in that menu.' });
|
||||
intro.createDiv({ text: 'Name format is a moment.js format. Literal words need bracket escaping, e.g. YYYY-MM-DD - [Journal].' });
|
||||
intro.createDiv({ text: 'Include {title} for systems that hold many notes per date, such as meetings: the text before the token finds the existing notes, and the token marks where a typed title goes. Without it, a date has exactly one note.' });
|
||||
|
||||
new Setting(container)
|
||||
.setHeading()
|
||||
.setName('Date systems')
|
||||
.setDesc(intro);
|
||||
|
||||
this.settings.dateSystems.forEach((system, i, arr) => {
|
||||
new Setting(container)
|
||||
.setHeading()
|
||||
.setName(system.name || 'Untitled system')
|
||||
.addExtraButton((btn) => {
|
||||
btn
|
||||
.setIcon('arrow-up')
|
||||
.setTooltip('Move up')
|
||||
.setDisabled(i === 0)
|
||||
.onClick(async () => {
|
||||
if (i === 0) return;
|
||||
const above = arr[i - 1];
|
||||
arr[i - 1] = arr[i];
|
||||
arr[i] = above;
|
||||
await this.saveAndRefresh();
|
||||
this.display();
|
||||
});
|
||||
})
|
||||
.addExtraButton((btn) => {
|
||||
btn
|
||||
.setIcon('arrow-down')
|
||||
.setTooltip('Move down')
|
||||
.setDisabled(i === arr.length - 1)
|
||||
.onClick(async () => {
|
||||
if (i === arr.length - 1) return;
|
||||
const below = arr[i + 1];
|
||||
arr[i + 1] = arr[i];
|
||||
arr[i] = below;
|
||||
await this.saveAndRefresh();
|
||||
this.display();
|
||||
});
|
||||
})
|
||||
.addExtraButton((btn) => {
|
||||
btn
|
||||
.setIcon('trash')
|
||||
.setTooltip('Delete this date system')
|
||||
.onClick(async () => {
|
||||
arr.splice(i, 1);
|
||||
await this.saveAndRefresh();
|
||||
this.display();
|
||||
});
|
||||
});
|
||||
|
||||
this.addSystemTextSetting(container,
|
||||
'Name', 'Label shown in the calendar right-click menu.',
|
||||
system, 'name', 'Journal',
|
||||
);
|
||||
this.addSystemTextSetting(container,
|
||||
'Folder', 'Folder these notes live in.',
|
||||
system, 'folder', 'periodic/journal',
|
||||
);
|
||||
|
||||
const formatSetting = this.addSystemTextSetting(container,
|
||||
'Name format', 'Filename format (moment.js format). Include {title} for many notes per date.',
|
||||
system, 'nameFormat', 'YYYY-MM-DD - {title}',
|
||||
);
|
||||
// A blank row is still being filled in, so only warn once something was typed.
|
||||
if (system.nameFormat && !formatHasDateToken(system.nameFormat)) {
|
||||
formatSetting.descEl.createDiv({
|
||||
cls: 'waypoint-settings-warning',
|
||||
text: 'This name format has no date placeholder, so it will never match or create dated notes.',
|
||||
});
|
||||
}
|
||||
|
||||
this.addSystemTextSetting(container,
|
||||
'Template file', 'Path to the template file. The .md extension is optional.',
|
||||
system, 'templateFile', 'resources/template/journal',
|
||||
);
|
||||
this.addSystemTextSetting(container,
|
||||
'Type property', `Fallback value for the 'type' frontmatter property, used when no template is found.`,
|
||||
system, 'typeProperty', 'journal-note',
|
||||
);
|
||||
this.addSystemTextSetting(container,
|
||||
'Icon', 'Lucide icon name for the menu item. Browse names at lucide.dev.',
|
||||
system, 'icon', 'book-open',
|
||||
);
|
||||
});
|
||||
|
||||
new Setting(container)
|
||||
.addButton((btn) =>
|
||||
btn
|
||||
.setButtonText('Add date system')
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
this.settings.dateSystems.push(Object.assign(
|
||||
{ id: `ds-${Date.now()}-${Math.random().toString(36).slice(2, 6)}` },
|
||||
DEFAULT_DATE_SYSTEM,
|
||||
));
|
||||
await this.saveAndRefresh();
|
||||
this.display();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/** Returns the Setting so callers can append validation notices to its description. */
|
||||
private addSystemTextSetting<K extends string>(
|
||||
container: HTMLElement,
|
||||
name: string,
|
||||
desc: string,
|
||||
obj: Record<K, string>,
|
||||
key: K,
|
||||
placeholder: string,
|
||||
): Setting {
|
||||
return new Setting(container)
|
||||
.setName(name)
|
||||
.setDesc(desc)
|
||||
.addText((text) => {
|
||||
text.setPlaceholder(placeholder);
|
||||
text.setValue(obj[key]);
|
||||
text.onChange((value) => {
|
||||
obj[key] = value;
|
||||
this.saveAndRefresh();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ═══════════════════════════════
|
||||
// Recent Files tab
|
||||
// ═══════════════════════════════
|
||||
|
||||
Reference in new issue
Block a user