/** * @file Vues semaine et mois de l'outil Calendrier : occurrences des événements, sélection et ligne de l'heure * courante. * * Utilisé par : CalendarContent.jsx. * Dépend de : calendarUtils.js (semaines, mois, occurrences). * @see docs/STORAGE_SCHEMA.md */ import { Tooltip } from "../../../components/Tooltip.jsx"; import { WEEK_SLOT_MINUTES, addDays, formatLocalDateKey, getCalendarColorValue, getCalendarEventSurfaceVariant, minutesToTimeValue, pad2 } from "./calendarUtils.js"; import { HOUR_HALF_SLOT_COUNT, WEEK_COMPACT_EVENT_HEIGHT, WEEKDAY_LABELS, getMonthOccurrenceSegments, getWeekMinutePosition, layoutConcurrentOccurrences } from "./calendarLayout.js"; function formatDayLabel(day) { return day.toLocaleDateString(undefined, { weekday: "long" }); } function formatHourLabel(hourIndex) { const minutes = hourIndex * 60; return `${pad2(Math.floor(minutes / 60))}:${pad2(minutes % 60)}`; } function getSelectionRange(selection) { if (!selection) return null; const startSlot = Math.min(selection.startSlot, selection.endSlot); const endSlot = Math.max(selection.startSlot, selection.endSlot); return { dayIndex: selection.dayIndex, startSlot, endSlot }; } function isSlotSelected(selection, dayIndex, slotIndex) { const range = getSelectionRange(selection); return Boolean(range && range.dayIndex === dayIndex && slotIndex >= range.startSlot && slotIndex <= range.endSlot); } function getMonthSelectionRange(selection) { if (!selection) return null; const startDate = selection.startDate <= selection.endDate ? selection.startDate : selection.endDate; const endDate = selection.startDate <= selection.endDate ? selection.endDate : selection.startDate; return { startDate, endDate }; } function isMonthDateSelected(selection, dateKey) { const range = getMonthSelectionRange(selection); return Boolean(range && dateKey >= range.startDate && dateKey <= range.endDate); } function formatMonthTitle(dateLike) { return new Date(dateLike).toLocaleDateString(undefined, { month: "long", year: "numeric" }); } export function CalendarWeekGrid({ days, occurrences, textContent, activeEventId, formOpen, draftSelection, selection, weekGridLayout, nowDayIndex, nowMinutes, onSlotPointerDown, onSlotPointerEnter, onSlotPointerUp, onEditEvent }) { return (
{days.map((day) =>
{formatDayLabel(day)}
)}
{weekGridLayout.rows.map((row) => ( row.type === "hidden" ? ... : {formatHourLabel(row.hourIndex)} ))}
{days.map((day, dayIndex) => { const dayOccurrences = layoutConcurrentOccurrences(occurrences.filter((occurrence) => occurrence.event.dayIndex === dayIndex)); const isToday = dayIndex === nowDayIndex; return (
{weekGridLayout.rows.map((row) => ( row.type === "hidden" ? ( ) : (
{Array.from({ length: HOUR_HALF_SLOT_COUNT }, (_, halfIndex) => { const slotIndex = row.hourIndex * HOUR_HALF_SLOT_COUNT + halfIndex; const slotLabel = minutesToTimeValue(slotIndex * WEEK_SLOT_MINUTES); return (
) ))}
{dayOccurrences.map((occurrence) => ( onEditEvent(occurrence.event)} /> ))}
{isToday && (
{minutesToTimeValue(nowMinutes)}
)}
); })}
); } function CalendarOccurrence({ occurrence, layout, active, onEdit }) { const durationMinutes = Math.max(WEEK_SLOT_MINUTES, (occurrence.endMs - occurrence.startMs) / 60000 || WEEK_SLOT_MINUTES); const startMinutes = occurrence.event.startMinutes; const timeLabel = `${minutesToTimeValue(occurrence.event.startMinutes)}${occurrence.event.endMinutes ? ` - ${minutesToTimeValue(occurrence.event.endMinutes)}` : ""}`; const top = getWeekMinutePosition(layout, startMinutes); const bottom = getWeekMinutePosition(layout, Math.min(24 * 60, startMinutes + durationMinutes)); const naturalHeight = bottom - top; const eventSurfaceSize = naturalHeight < WEEK_COMPACT_EVENT_HEIGHT ? "xs" : naturalHeight < 44 ? "sm" : "md"; const height = eventSurfaceSize === "xs" ? 10 : eventSurfaceSize === "sm" ? WEEK_COMPACT_EVENT_HEIGHT : Math.max(44, naturalHeight); const color = occurrence.event.color || "violet"; return (
{occurrence.event.title}{timeLabel}} onClick={onEdit} > {occurrence.event.title} {timeLabel}
); } export function CalendarMonthView({ monthStart, monthGridDays, occurrences, textContent, activeEventId, selectedRange, dragSelection, todayDate, nowLabel, onPreviousMonth, onCurrentMonth, onNextMonth, onPointerDown, onPointerEnter, onPointerUp, onEditEvent }) { return ( <>
{formatMonthTitle(monthStart)}
); } function CalendarMonthGrid({ days, occurrences, textContent, activeEventId, selectedRange, dragSelection, todayDate, nowLabel, onPointerDown, onPointerEnter, onPointerUp, onEditEvent }) { const monthBars = getMonthOccurrenceSegments(days, occurrences); const weekRowCount = Math.ceil(days.length / WEEKDAY_LABELS.length); return (
{WEEKDAY_LABELS.map((day) =>
{day}
)} {days.map((day) => { const dateKey = formatLocalDateKey(day.date); const isToday = todayDate === dateKey; return (
day.inMonth && onPointerDown(dateKey)} onPointerEnter={(event) => day.inMonth && onPointerEnter(event, dateKey)} onPointerUp={() => day.inMonth && onPointerUp()} onKeyDown={(event) => { if (!day.inMonth || (event.key !== "Enter" && event.key !== " ")) return; event.preventDefault(); onPointerDown(dateKey); onPointerUp(); }} aria-label={day.inMonth ? `${textContent.dayLabel || "Jour"} ${day.dayNumber}` : undefined} > {day.inMonth && ( <> {day.dayNumber} {isToday && {nowLabel}} )}
); })}
{monthBars.map((segment, index) => ( { event.stopPropagation(); onEditEvent(segment.occurrence.event, segment.occurrence); }} /> ))}
); } function CalendarMonthBar({ segment, active, onEdit }) { const gridRow = Math.floor(segment.startIndex / WEEKDAY_LABELS.length) + 2; const startColumn = segment.startIndex % WEEKDAY_LABELS.length + 1; const endColumn = segment.endIndex % WEEKDAY_LABELS.length + 2; const laneCount = Math.max(1, Math.min(3, segment.laneCount || 1)); const barHeight = laneCount <= 2 ? 22 : 10; const barGap = laneCount === 3 ? 2 : 4; const eventSurfaceSize = barHeight <= 10 ? "xs" : barHeight <= 22 ? "sm" : "md"; const startLabel = new Date(segment.occurrence.startMs).toLocaleDateString(undefined, { day: "2-digit", month: "short", year: "numeric" }); const endDate = addDays(new Date(segment.occurrence.endMs), -1); const endLabel = endDate.toLocaleDateString(undefined, { day: "2-digit", month: "short", year: "numeric" }); const dateLabel = startLabel === endLabel ? startLabel : `${startLabel} - ${endLabel}`; const color = segment.occurrence.event.color || "violet"; return (
{segment.occurrence.event.title}{dateLabel}} onPointerDown={(event) => event.stopPropagation()} onClick={onEdit} > {segment.occurrence.event.title}
); }