From ef1256aec0f8a60811a0d8ff9663b7c1fd1cf22d Mon Sep 17 00:00:00 2001 From: Quorafind Date: Sat, 28 Nov 2026 16:31:34 +0800 Subject: [PATCH] fix: clear Obsidian review action errors in library code Task Genius bundles this library into its Obsidian plugin, and the Obsidian review action (obsidianmd/obsidian-workflows) fails strict runs on these error-level findings. - DateFnsAdapter: replace `type DateFns = any` (and its restricted eslint-disable for no-explicit-any) with a structural DateFnsFunctions interface for the date-fns functions the adapter calls. Nothing is imported, so date-fns stays an optional peer; date-fns 2.30, 3.6 and 4.1 modules all satisfy it. - MonthRenderer: describe the two no-unused-vars disables. - DragController: toggle body.tg-is-dragging instead of writing body.style.cursor; hide the drag proxy with setStyles, matching the visibility: visible that onMove sets. - Month/Time renderers: mark clickable popover items with .tg-is-clickable instead of style.cursor = "pointer". - TimeRenderer: apply the slot-based column height through .tg-day-column.tg-has-slot-height instead of an inline height. --- src/adapters/DateFnsAdapter.ts | 56 ++++++++++++++++++++++++++++++++-- src/core/DragController.ts | 7 +++-- src/renderers/MonthRenderer.ts | 6 ++-- src/renderers/TimeRenderer.ts | 4 +-- src/styles/base.css | 10 ++++++ src/styles/time.css | 5 +++ 6 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/adapters/DateFnsAdapter.ts b/src/adapters/DateFnsAdapter.ts index 266cce3..92f5d01 100644 --- a/src/adapters/DateFnsAdapter.ts +++ b/src/adapters/DateFnsAdapter.ts @@ -1,9 +1,59 @@ import type { DateAdapter, TimeUnit } from "../types"; -// Type-only imports to avoid bundling date-fns if not used type DateFnsDate = Date; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type DateFns = any; + +/** + * The date-fns functions this adapter calls, typed structurally so date-fns + * stays an optional peer dependency (nothing is imported or bundled). + * Pass the date-fns module itself: `new DateFnsAdapter(dateFns)`. + */ +export interface DateFnsFunctions { + parseISO(dateStr: string): Date; + parse(dateStr: string, formatStr: string, referenceDate: Date): Date; + format(date: Date, formatStr: string): string; + + getYear(date: Date): number; + getMonth(date: Date): number; + getDate(date: Date): number; + getDay(date: Date): number; + getHours(date: Date): number; + getMinutes(date: Date): number; + setHours(date: Date, hours: number): Date; + setMinutes(date: Date, minutes: number): Date; + + addYears(date: Date, amount: number): Date; + addMonths(date: Date, amount: number): Date; + addWeeks(date: Date, amount: number): Date; + addDays(date: Date, amount: number): Date; + addHours(date: Date, amount: number): Date; + addMinutes(date: Date, amount: number): Date; + + differenceInYears(dateLeft: Date, dateRight: Date): number; + differenceInMonths(dateLeft: Date, dateRight: Date): number; + differenceInWeeks(dateLeft: Date, dateRight: Date): number; + differenceInDays(dateLeft: Date, dateRight: Date): number; + differenceInHours(dateLeft: Date, dateRight: Date): number; + differenceInMinutes(dateLeft: Date, dateRight: Date): number; + + startOfYear(date: Date): Date; + startOfMonth(date: Date): Date; + startOfWeek(date: Date): Date; + startOfDay(date: Date): Date; + startOfHour(date: Date): Date; + startOfMinute(date: Date): Date; + endOfYear(date: Date): Date; + endOfMonth(date: Date): Date; + endOfWeek(date: Date): Date; + endOfDay(date: Date): Date; + endOfHour(date: Date): Date; + endOfMinute(date: Date): Date; + + isBefore(date: Date, dateToCompare: Date): boolean; + isAfter(date: Date, dateToCompare: Date): boolean; + isEqual(dateLeft: Date, dateRight: Date): boolean; +} + +type DateFns = DateFnsFunctions; /** * date-fns adapter implementation diff --git a/src/core/DragController.ts b/src/core/DragController.ts index 887a46e..78c7839 100644 --- a/src/core/DragController.ts +++ b/src/core/DragController.ts @@ -230,7 +230,7 @@ export class DragController { private startDrag(stateData: DragState): void { this.state = stateData; - document.body.style.cursor = "grabbing"; + document.body.classList.add("tg-is-dragging"); // Mark source element querySelectorAll(`[data-eid="${stateData.event.id}"]`).forEach((el) => { @@ -268,7 +268,8 @@ export class DragController { private removeProxy(): void { if (this.proxyElement) { - this.proxyElement.style.visibility = "hidden"; + // Mirrors the `visibility: "visible"` that onMove sets on each move + setStyles(this.proxyElement, { visibility: "hidden" }); } } @@ -781,7 +782,7 @@ export class DragController { const s = this.state; // Cleanup - document.body.style.cursor = ""; + document.body.classList.remove("tg-is-dragging"); this.removeProxy(); querySelectorAll(".tg-ghost-event").forEach((el) => el.remove()); diff --git a/src/renderers/MonthRenderer.ts b/src/renderers/MonthRenderer.ts index 1565dfe..30c4ba9 100644 --- a/src/renderers/MonthRenderer.ts +++ b/src/renderers/MonthRenderer.ts @@ -31,14 +31,14 @@ export class MonthRenderer { private adapter: DateAdapter, // theme parameter kept for API consistency // Theme values now applied via CSS variables (--tg-primary-color, etc.) - // eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- kept for API consistency with other renderers _theme: Required & { fontSize: Required>; }, private showEventCounts: boolean = false, // dateFormats parameter kept for API consistency with other renderers // Currently unused as formats are handled by engines/adapters - // eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- kept for API consistency with other renderers _dateFormats: Required, private onRenderDateCell?: ( ctx: import("../types").DateCellContext, @@ -636,7 +636,7 @@ export class MonthRenderer { this.closePopover(); onEventClick(event); }); - item.style.cursor = "pointer"; + item.classList.add("tg-is-clickable"); } list.appendChild(item); diff --git a/src/renderers/TimeRenderer.ts b/src/renderers/TimeRenderer.ts index af20757..d89225a 100644 --- a/src/renderers/TimeRenderer.ts +++ b/src/renderers/TimeRenderer.ts @@ -573,7 +573,7 @@ export class TimeRenderer { this.closePopover(); onEventClick(event); }); - item.style.cursor = "pointer"; + item.classList.add("tg-is-clickable"); } list.appendChild(item); @@ -698,7 +698,7 @@ export class TimeRenderer { if (timeSlots && timeSlots.length > 0) { const height = timeSlots.length * this.theme.cellHeight; col.style.setProperty("--tg-column-height", `${height}px`); - col.style.height = "var(--tg-column-height)"; + col.classList.add("tg-has-slot-height"); } // Calculate layout for events on this day diff --git a/src/styles/base.css b/src/styles/base.css index ef73203..93607c8 100644 --- a/src/styles/base.css +++ b/src/styles/base.css @@ -136,3 +136,13 @@ pointer-events: none; cursor: not-allowed; } + +/* Set on while an event is dragged (DragController) */ +body.tg-is-dragging { + cursor: grabbing; +} + +/* Popover event items that open the event on click */ +.tg-is-clickable { + cursor: pointer; +} diff --git a/src/styles/time.css b/src/styles/time.css index a55ee08..9ee127a 100644 --- a/src/styles/time.css +++ b/src/styles/time.css @@ -96,6 +96,11 @@ ); } +/* Column height from the configured time slots (TimeRenderer) */ +.tg-day-column.tg-has-slot-height { + height: var(--tg-column-height); +} + /* Range preview for time view */ .tg-time-range-preview { position: absolute;