Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions src/adapters/DateFnsAdapter.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/core/DragController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class DragController<T> {

private startDrag(stateData: DragState<T>): 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) => {
Expand Down Expand Up @@ -268,7 +268,8 @@ export class DragController<T> {

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" });
}
}

Expand Down Expand Up @@ -781,7 +782,7 @@ export class DragController<T> {
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());
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/MonthRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export class MonthRenderer<T> {
private adapter: DateAdapter<T>,
// 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<ThemeConfig> & {
fontSize: Required<NonNullable<ThemeConfig["fontSize"]>>;
},
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<DateFormatConfig>,
private onRenderDateCell?: (
ctx: import("../types").DateCellContext,
Expand Down Expand Up @@ -636,7 +636,7 @@ export class MonthRenderer<T> {
this.closePopover();
onEventClick(event);
});
item.style.cursor = "pointer";
item.classList.add("tg-is-clickable");
}

list.appendChild(item);
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/TimeRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export class TimeRenderer<T> {
this.closePopover();
onEventClick(event);
});
item.style.cursor = "pointer";
item.classList.add("tg-is-clickable");
}

list.appendChild(item);
Expand Down Expand Up @@ -698,7 +698,7 @@ export class TimeRenderer<T> {
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
Expand Down
10 changes: 10 additions & 0 deletions src/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@
pointer-events: none;
cursor: not-allowed;
}

/* Set on <body> 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;
}
5 changes: 5 additions & 0 deletions src/styles/time.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading