From 7dabef2028f3f7cac031ffd99a95469bd8aaa1ce Mon Sep 17 00:00:00 2001 From: Ohkubo KOHEI Date: Sat, 4 Apr 2026 02:32:17 +0000 Subject: [PATCH] fix view height --- manifest.json | 2 +- styles.css | 2 +- ui/calendar-renderer.ts | 38 ++++++++++++++++++++++++++++++++++++-- ui/daily-calendar-view.ts | 2 +- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 34dd220..99c57f3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "daily-nav", "name": "Daily Nav", - "version": "1.1.3", + "version": "1.1.4", "minAppVersion": "1.12.0", "description": "Open prev/next note based on explorer sorting order", "author": "kuboon", diff --git a/styles.css b/styles.css index ccbb24f..2eb4bbf 100644 --- a/styles.css +++ b/styles.css @@ -65,7 +65,7 @@ .daily-calendar-grid { display: grid; - grid-template-columns: auto repeat(7, minmax(0, 1fr)); + grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 1px; text-align: center; position: relative; diff --git a/ui/calendar-renderer.ts b/ui/calendar-renderer.ts index 7796daa..26f4dc4 100644 --- a/ui/calendar-renderer.ts +++ b/ui/calendar-renderer.ts @@ -94,9 +94,17 @@ export class CalendarRenderer { // First render to measure row height await this.buildWeeks(20); // render 20 weeks to measure - await frame(); + + // Wait for layout to settle (Obsidian may need extra frames) + await this.waitForLayout(); this.measureRow(); + // If row height looks too small, retry after a short delay + if (this.rowHeight < 20) { + await delay(100); + this.measureRow(); + } + // Now re-render with correct 3x buffer await this.renderGrid(); @@ -106,6 +114,28 @@ export class CalendarRenderer { // ── Internal ── + /** Wait until the viewport has a non-zero size (handles deferred layout in Obsidian) */ + private async waitForLayout(): Promise { + // Double rAF to ensure paint + layout cycle completes + await frame(); + await frame(); + if (this.viewport && this.viewport.clientHeight > 0) { + return; + } + return new Promise((resolve) => { + const observer = new ResizeObserver((entries) => { + for (const entry of entries) { + if (entry.contentRect.height > 0) { + observer.disconnect(); + resolve(); + return; + } + } + }); + observer.observe(this.viewport!); + }); + } + private measureRow(): void { if (!this.viewport || !this.grid) return; // Find first week cell to measure row height @@ -183,7 +213,7 @@ export class CalendarRenderer { for (let w = 0; w < totalWeeks; w++) { // Week number cell const [isoYear, isoWeek] = isoWeekOfDate(cursor); - const weekEl = elText("div", `W${isoWeek}`, "daily-calendar-week"); + const weekEl = elText("div", `W${pad2(isoWeek)}`, "daily-calendar-week"); weekEl.setAttribute("aria-label", `${isoYear}-W${pad2(isoWeek)}`); weekEl.addEventListener( "click", @@ -330,6 +360,10 @@ function frame(): Promise { return new Promise((r) => requestAnimationFrame(() => r())); } +function delay(ms: number): Promise { + return new Promise((r) => setTimeout(r, ms)); +} + function el(tag: string, cls: string): HTMLElement { const e = document.createElement(tag); e.className = cls; diff --git a/ui/daily-calendar-view.ts b/ui/daily-calendar-view.ts index 30b9ba9..90df663 100644 --- a/ui/daily-calendar-view.ts +++ b/ui/daily-calendar-view.ts @@ -122,7 +122,7 @@ class ObsidianDataSource implements CalendarDataSource { } onWeekClick(isoYear: number, isoWeek: number): void { - const filename = `${isoYear}W${(`0${isoWeek}`).slice(-2)}`; + const filename = `${isoYear}-W${(`0${isoWeek}`).slice(-2)}`; const file = this.app.vault.getAbstractFileByPath(`${filename}.md`); if (file) { this.app.workspace.getLeaf(true).openFile(file as TFile);