mirror of
https://github.com/kuboon/daily-nav.git
synced 2026-07-22 06:57:03 +00:00
fix view height
This commit is contained in:
parent
26a2e5fcba
commit
7dabef2028
4 changed files with 39 additions and 5 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<void> {
|
||||
// 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<void> {
|
|||
return new Promise((r) => requestAnimationFrame(() => r()));
|
||||
}
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise((r) => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
function el(tag: string, cls: string): HTMLElement {
|
||||
const e = document.createElement(tag);
|
||||
e.className = cls;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue