feat: add coloured calendar system indicators

Add a selectable single-dot or per-system indicator mode. Date systems now carry configurable colours; results are cached per displayed month and invalidated when paths/settings change. Refine calendar hierarchy, spacing, hover, and today states.
This commit is contained in:
olivier committed 2026-09-07 21:43:21 -04:00
1 parent 12209155dc
commit 069456799e
9 files changed
+305 -72

No files matched your search

+97 -3
View File
@@ -42,6 +42,13 @@ export interface DateSystemNotes {
multiple: boolean;
}
/** One coloured calendar marker for a date system that has a note on a day. */
export interface DateSystemIndicator {
id: string;
name: string;
color: string;
}
export default class WaypointPlugin extends Plugin {
public settings: WaypointSettings;
public waypointData: WaypointData;
@@ -51,6 +58,9 @@ export default class WaypointPlugin extends Plugin {
private savePromise: Promise<void> = Promise.resolve();
/** Basenames of every markdown file in the vault, for O(1) calendar lookups. */
private markdownBasenames: Set<string> = new Set();
/** Results for the displayed month; invalidated by markdown-file changes. */
private dateSystemIndicators: Map<string, DateSystemIndicator[]> | null = null;
private dateSystemIndicatorKey = '';
async onload(): Promise<void> {
console.debug('Waypoint: loading plugin v' + this.manifest.version);
@@ -73,6 +83,7 @@ export default class WaypointPlugin extends Plugin {
this.settings,
() => {
this.enforceRecentFilesLimit();
this.invalidateDateSystemIndicators();
this.redrawAll();
},
));
@@ -247,10 +258,14 @@ export default class WaypointPlugin extends Plugin {
}
// Cloned, not Object.assign'd in: the defaults array would otherwise be
// aliased into the live settings and the settings UI would edit
// DEFAULT_SETTINGS itself. Saved entries merge over
// DEFAULT_DATE_SYSTEM so older configs pick up fields added since.
// DEFAULT_DATE_SYSTEM so older configs pick up fields added since. Known
// built-ins use their own defaults too, preserving Journal/Meeting colours
// when this field is first introduced.
this.settings.dateSystems = Array.isArray(s.dateSystems)
? s.dateSystems.map(sys => Object.assign({}, DEFAULT_DATE_SYSTEM, sys))
? s.dateSystems.map(sys => {
const builtIn = DEFAULT_SETTINGS.dateSystems.find(defaultSystem => defaultSystem.id === sys.id);
return Object.assign({}, builtIn || DEFAULT_DATE_SYSTEM, sys);
})
: DEFAULT_SETTINGS.dateSystems.map(sys => Object.assign({}, sys));
}
@@ -392,6 +407,7 @@ export default class WaypointPlugin extends Plugin {
* inside a renamed folder.
*/
private onRename(file: TAbstractFile, oldPath: string): void {
this.invalidateDateSystemIndicators();
const indexChanged = this.syncIndexForRename(file, oldPath);
let dataChanged = false;
@@ -427,6 +443,7 @@ export default class WaypointPlugin extends Plugin {
private onVaultCreate(file: TAbstractFile): void {
if (file instanceof TFile && file.extension === 'md') {
this.markdownBasenames.add(file.basename);
this.invalidateDateSystemIndicators();
}
this.broadcastRedraw();
}
@@ -434,6 +451,7 @@ export default class WaypointPlugin extends Plugin {
private onVaultDelete(file: TAbstractFile): void {
if (file instanceof TFile && file.extension === 'md') {
this.removeFromMarkdownIndex(file.basename, file.path);
this.invalidateDateSystemIndicators();
}
this.broadcastRedraw();
}
@@ -447,6 +465,12 @@ export default class WaypointPlugin extends Plugin {
}
}
/** Forget a month result when markdown paths or date-system settings change. */
private invalidateDateSystemIndicators(): void {
this.dateSystemIndicators = null;
this.dateSystemIndicatorKey = '';
}
/**
* Drop a basename from the index, unless another markdown file still
* carries it. `path` is excluded from that check because the vault may not
@@ -555,6 +579,7 @@ export default class WaypointPlugin extends Plugin {
templateFile: periodSettings.templateFile,
typeProperty: periodSettings.typeProperty,
icon: 'calendar',
indicatorColor: this.settings.calendar.dailyIndicatorColor,
};
}
@@ -609,6 +634,75 @@ export default class WaypointPlugin extends Plugin {
.map(bucket => bucket.result);
}
/**
* Return one coloured indicator per system with a note on each requested day.
*
* The day grid calls this once per render. Its result is cached by the
* displayed dates and system settings, then invalidated by file changes, so
* a 42-cell calendar never repeats the vault scan per cell or per redraw.
*/
getDateSystemIndicators(dates: moment.Moment[]): Map<string, DateSystemIndicator[]> {
const dateStrings = dates.map(date => date.format('YYYY-MM-DD'));
const systems = this.dateSystems()
.filter(system => formatHasDateToken(system.nameFormat))
.map(system => {
const parts = splitNameFormat(system.nameFormat);
return {
system,
hasTitle: parts.hasTitle,
dates: dates.map((date, index) => ({
dateStr: dateStrings[index],
before: formatDatePart(date, parts.before),
after: formatDatePart(date, parts.after),
})),
};
});
const key = JSON.stringify({
dates: dateStrings,
systems: systems.map(({ system }) => [
system.id,
system.name,
system.folder,
system.nameFormat,
system.indicatorColor,
]),
});
if (this.dateSystemIndicators && this.dateSystemIndicatorKey === key) {
return this.dateSystemIndicators;
}
const matchingIds = new Map<string, Set<string>>();
for (const dateStr of dateStrings) matchingIds.set(dateStr, new Set());
// The only vault traversal: filter a file by system folder first, then
// test it against the month's at-most-42 formatted day patterns.
for (const file of this.app.vault.getMarkdownFiles()) {
for (const entry of systems) {
if (!isInFolder(file.path, entry.system.folder)) continue;
for (const match of entry.dates) {
if (matchesSystemName(file.basename, match.before, match.after, entry.hasTitle)) {
matchingIds.get(match.dateStr)?.add(entry.system.id);
}
}
}
}
const result = new Map<string, DateSystemIndicator[]>();
for (const dateStr of dateStrings) {
const ids = matchingIds.get(dateStr);
result.set(dateStr, systems
.filter(({ system }) => ids?.has(system.id))
.map(({ system }) => ({
id: system.id,
name: system.name,
color: system.indicatorColor,
})));
}
this.dateSystemIndicatorKey = key;
this.dateSystemIndicators = result;
return result;
}
/**
* Open (creating if needed) the note `system` holds for `date`.
*