@jsb188/calendar 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,648 @@
1
+ import { cn } from '@jsb188/app/utils/string.ts';
2
+ import { DateTime } from 'luxon';
3
+ import { useAtom, useAtomValue } from 'jotai';
4
+ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
+ import {
6
+ CALENDAR_GUTTER_WIDTH,
7
+ CALENDAR_HOUR_HEIGHT,
8
+ CALENDAR_MONTH_CELL_MAX_EVENTS,
9
+ CALENDAR_VIEW_DAY_COUNTS,
10
+ type CalendarViewEnum,
11
+ } from '../constants/calendar.ts';
12
+ import {
13
+ getCalendarAllDayLayout,
14
+ getCalendarEventsByDateKey,
15
+ getCalendarMonthCells,
16
+ getCalendarTimedLayout,
17
+ } from '../libs/calendar-geometry.ts';
18
+ import {
19
+ getCalendarCreateRange,
20
+ getCalendarMoveRange,
21
+ getCalendarPointerSlot,
22
+ getCalendarResizeRange,
23
+ startCalendarGesture,
24
+ type CalendarGestureRange,
25
+ } from '../libs/calendar-gesture.ts';
26
+ import { getCalendarRange, getDayLengthMinutes, getMinutesFromDayStart } from '../libs/calendar-range.ts';
27
+ import {
28
+ applyCalendarOptimisticOverlays,
29
+ createCalendarStateAtoms,
30
+ getCalendarStateScopeKey,
31
+ type CalendarStateAtoms,
32
+ } from '../libs/calendar-state.ts';
33
+ import type { CalendarEventObj } from '../types/calendar.d.ts';
34
+ import { CalendarAgendaUI, type CalendarAgendaDayObj } from '../ui/CalendarAgendaUI.tsx';
35
+ import { CalendarMonthUI } from '../ui/CalendarMonthUI.tsx';
36
+ import {
37
+ CalendarAllDayBandUI,
38
+ CalendarDayHeaderUI,
39
+ CalendarDraftBlockUI,
40
+ CalendarEventUI,
41
+ CalendarHourLinesUI,
42
+ CalendarNowLineUI,
43
+ CalendarTimeGutterUI,
44
+ } from '../ui/CalendarUI.tsx';
45
+ import { CalendarYearUI, type CalendarYearMonthObj } from '../ui/CalendarYearUI.tsx';
46
+
47
+ /**
48
+ * The calendar surface.
49
+ *
50
+ * This is the container: it owns the atom bag, derives the visible range, runs
51
+ * the layout pass, and hands finished geometry to the dumb components in
52
+ * /ui/. It does not fetch — the page above it does, and passes events down —
53
+ * so the same grid draws a daycare's shifts, an off-site, and a network event
54
+ * without knowing which it is looking at.
55
+ *
56
+ * View and anchor date arrive as props from the URL rather than living here,
57
+ * because the app shell remounts a route on every pathname change but not on a
58
+ * search change. Keeping them in the URL is what lets somebody page through
59
+ * months without the calendar being destroyed and rebuilt each time.
60
+ */
61
+
62
+ export interface CalendarProps {
63
+ className?: string;
64
+ events: CalendarEventObj[];
65
+ view: CalendarViewEnum;
66
+ anchorDate: Date;
67
+ now: Date;
68
+ timeZone?: string | null;
69
+ weekStartsOn?: number;
70
+ locale?: string | null;
71
+ // Rendered as the first row, so the page chooses its own toolbar
72
+ children?: React.ReactNode;
73
+ // Display strings. The package holds no copy of its own: the app owns
74
+ // i18n, so every user-visible word is passed in rather than translated
75
+ // here, and this package stays usable by any surface.
76
+ allDayText?: string;
77
+ agendaEmptyText?: string;
78
+ moreLabel?: (count: number) => string;
79
+ // Without this the grid is read-only: no create, no move, no resize
80
+ editable?: boolean;
81
+ onSelectEvent?: (eventId: string) => void;
82
+ onSelectDay?: (dateKey: string) => void;
83
+ // A range the user drew; the page turns it into a create form
84
+ onCreateRange?: (range: { startAt: Date; endAt: Date }) => void;
85
+ // An existing event the user moved or resized
86
+ onMoveEvent?: (p: { eventId: string; startAt: Date; endAt: Date }) => void;
87
+ }
88
+
89
+ /**
90
+ * Render one Calendar inside an isolated local calendar state store.
91
+ */
92
+
93
+ export function Calendar(p: CalendarProps) {
94
+ const stateAtomsRef = useRef<CalendarStateAtoms | null>(null);
95
+
96
+ // Created in a ref, never inline in the render body: creating atoms inline
97
+ // would hand every render a fresh bag and reset all state
98
+ if (!stateAtomsRef.current) {
99
+ stateAtomsRef.current = createCalendarStateAtoms(getCalendarStateScopeKey());
100
+ }
101
+
102
+ return <CalendarContent {...p} stateAtoms={stateAtomsRef.current} />;
103
+ }
104
+
105
+ type CalendarContentProps = CalendarProps & {
106
+ stateAtoms: CalendarStateAtoms;
107
+ };
108
+
109
+ /*
110
+ * Format the hour labels once per locale rather than per hour per render.
111
+ */
112
+
113
+ function useCalendarHourLabels(timeZone: string, locale?: string | null) {
114
+ return useMemo(() => {
115
+ const base = DateTime.fromObject({ year: 2026, month: 1, day: 1 }, { zone: timeZone })
116
+ .setLocale(locale || 'en');
117
+
118
+ return Array.from({ length: 24 }, (_unused, hour) => base.set({ hour }).toFormat('h a'));
119
+ }, [timeZone, locale]);
120
+ }
121
+
122
+ /*
123
+ * Render the time grid: gutter, hour lines, day columns, and events.
124
+ */
125
+
126
+ const CalendarContent = memo((p: CalendarContentProps) => {
127
+ const {
128
+ className,
129
+ events,
130
+ view,
131
+ anchorDate,
132
+ now,
133
+ timeZone,
134
+ weekStartsOn,
135
+ locale,
136
+ children,
137
+ allDayText,
138
+ agendaEmptyText,
139
+ moreLabel,
140
+ editable,
141
+ onSelectEvent,
142
+ onSelectDay,
143
+ onCreateRange,
144
+ onMoveEvent,
145
+ stateAtoms,
146
+ } = p;
147
+
148
+ const [popoverState, setPopoverState] = useAtom(stateAtoms.popoverStateAtom);
149
+ const optimisticEvents = useAtomValue(stateAtoms.optimisticEventsAtom);
150
+ const removedEventIds = useAtomValue(stateAtoms.optimisticallyRemovedEventIdsAtom);
151
+
152
+ const range = useMemo(
153
+ () => getCalendarRange({ view, anchorDate, now, timeZone, weekStartsOn }),
154
+ [view, anchorDate, now, timeZone, weekStartsOn],
155
+ );
156
+
157
+ // One pass over the week per data change, not per subscriber
158
+ const visibleEvents = useMemo(
159
+ () => applyCalendarOptimisticOverlays(events, optimisticEvents, removedEventIds),
160
+ [events, optimisticEvents, removedEventIds],
161
+ );
162
+
163
+ const isTimeGrid = !!CALENDAR_VIEW_DAY_COUNTS[view];
164
+
165
+ // Each view runs only its own layout pass. A year is 365 day objects, and
166
+ // running the overlap sweep over it to draw a grid that shows no events
167
+ // would be pure waste on every render.
168
+ const timedLayout = useMemo(
169
+ () => (isTimeGrid ? getCalendarTimedLayout(visibleEvents, range.days) : []),
170
+ [isTimeGrid, visibleEvents, range.days],
171
+ );
172
+ const allDayBars = useMemo(
173
+ () => (isTimeGrid ? getCalendarAllDayLayout(visibleEvents, range.days) : []),
174
+ [isTimeGrid, visibleEvents, range.days],
175
+ );
176
+ const monthCells = useMemo(
177
+ () => (view === 'MONTH' ? getCalendarMonthCells(visibleEvents, range.days, CALENDAR_MONTH_CELL_MAX_EVENTS) : []),
178
+ [view, visibleEvents, range.days],
179
+ );
180
+
181
+ const hourLabels = useCalendarHourLabels(range.timeZone, locale);
182
+
183
+ const dayLabels = useMemo(
184
+ () =>
185
+ range.days.map((day) => {
186
+ const local = DateTime.fromJSDate(day.startAt, { zone: range.timeZone }).setLocale(locale || 'en');
187
+
188
+ return {
189
+ weekday: local.toFormat('ccc'),
190
+ dayNumber: local.toFormat('d'),
191
+ };
192
+ }),
193
+ [range.days, range.timeZone, locale],
194
+ );
195
+
196
+ /*
197
+ * Weekday column headings, built from a real week so they honour the
198
+ * locale and the configured week start rather than a hardcoded list.
199
+ */
200
+
201
+ const weekdayLabels = useMemo(() => {
202
+ const weekStart = Number.isInteger(weekStartsOn) ? Number(weekStartsOn) : 0;
203
+ // Any Sunday; 2026-01-04 is one
204
+ const sunday = DateTime.fromObject({ year: 2026, month: 1, day: 4 }, { zone: range.timeZone })
205
+ .setLocale(locale || 'en');
206
+
207
+ return Array.from({ length: 7 }, (_unused, index) => sunday.plus({ days: index + weekStart }).toFormat('ccc'));
208
+ }, [range.timeZone, locale, weekStartsOn]);
209
+
210
+ const weekdayInitials = useMemo(
211
+ () => weekdayLabels.map((label) => label.slice(0, 1)),
212
+ [weekdayLabels],
213
+ );
214
+
215
+ const timeLabelByEventId = useMemo(() => {
216
+ const labels = new Map<string, string>();
217
+
218
+ for (const entry of timedLayout) {
219
+ if (labels.has(entry.event.id)) {
220
+ continue;
221
+ }
222
+
223
+ labels.set(
224
+ entry.event.id,
225
+ DateTime.fromJSDate(entry.event.startAt, { zone: range.timeZone })
226
+ .setLocale(locale || 'en')
227
+ .toFormat('h:mm a'),
228
+ );
229
+ }
230
+
231
+ return labels;
232
+ }, [timedLayout, range.timeZone, locale]);
233
+
234
+ const handleSelectEvent = useCallback((eventId: string) => {
235
+ setPopoverState((current) => (
236
+ // Clicking the open event again closes it, and returning the same
237
+ // reference on a no-op keeps subscribers from re-rendering
238
+ current?.eventId === eventId
239
+ ? null
240
+ : { eventId, anchorRect: { top: 0, left: 0, width: 0, height: 0 } }
241
+ ));
242
+
243
+ onSelectEvent?.(eventId);
244
+ }, [onSelectEvent, setPopoverState]);
245
+
246
+ const layoutByDayIndex = useMemo(() => {
247
+ const byDay: Array<typeof timedLayout> = range.days.map(() => []);
248
+
249
+ for (const entry of timedLayout) {
250
+ byDay[entry.dayIndex]?.push(entry);
251
+ }
252
+
253
+ return byDay;
254
+ }, [timedLayout, range.days]);
255
+
256
+ // A DST day is 23 or 25 hours long; drawing 24 would put every event after
257
+ // the transition an hour out
258
+ const gridHeight = useMemo(
259
+ () => (Math.max(...range.days.map(getDayLengthMinutes)) / 60) * CALENDAR_HOUR_HEIGHT,
260
+ [range.days],
261
+ );
262
+
263
+ /*
264
+ * Group the year's days into twelve mini grids, each padded so the 1st
265
+ * lands under its own weekday column.
266
+ */
267
+
268
+ const yearMonths = useMemo<CalendarYearMonthObj[]>(() => {
269
+ if (view !== 'YEAR') {
270
+ return [];
271
+ }
272
+
273
+ const weekStart = Number.isInteger(weekStartsOn) ? Number(weekStartsOn) : 0;
274
+ const months: CalendarYearMonthObj[] = [];
275
+
276
+ for (const day of range.days) {
277
+ const local = DateTime.fromJSDate(day.startAt, { zone: range.timeZone }).setLocale(locale || 'en');
278
+
279
+ if (local.day === 1) {
280
+ months.push({
281
+ label: local.toFormat('LLLL'),
282
+ // luxon: 1 = Monday .. 7 = Sunday; normalize to 0 = Sunday
283
+ leadingBlankCount: ((local.weekday % 7) - weekStart + 7) % 7,
284
+ days: [],
285
+ dayNumberLabels: [],
286
+ });
287
+ }
288
+
289
+ const month = months[months.length - 1];
290
+ month?.days.push(day);
291
+ month?.dayNumberLabels.push(local.toFormat('d'));
292
+ }
293
+
294
+ return months;
295
+ }, [view, range.days, range.timeZone, locale, weekStartsOn]);
296
+
297
+ /*
298
+ * Build the agenda list, omitting days with nothing on them.
299
+ *
300
+ * A month of empty headings is scrolling, not information — but the list
301
+ * being wholly empty is surfaced by the component so it never reads as a
302
+ * failed load.
303
+ */
304
+
305
+ const agendaDays = useMemo<CalendarAgendaDayObj[]>(() => {
306
+ if (view !== 'AGENDA') {
307
+ return [];
308
+ }
309
+
310
+ const byDateKey = getCalendarEventsByDateKey(visibleEvents, range.days);
311
+
312
+ return range.days
313
+ .filter((day) => (byDateKey.get(day.dateKey) || []).length > 0)
314
+ .map((day) => ({
315
+ dateKey: day.dateKey,
316
+ label: DateTime.fromJSDate(day.startAt, { zone: range.timeZone })
317
+ .setLocale(locale || 'en')
318
+ .toFormat('ccc, LLL d'),
319
+ isToday: day.isToday,
320
+ events: byDateKey.get(day.dateKey) || [],
321
+ }));
322
+ }, [view, visibleEvents, range.days, range.timeZone, locale]);
323
+
324
+ /*
325
+ * Time ranges for the agenda's left column. Built from the events rather
326
+ * than the grid layout, because the agenda also lists all-day entries the
327
+ * time grid excludes.
328
+ */
329
+
330
+ const agendaTimeLabels = useMemo(() => {
331
+ const labels = new Map<string, string>();
332
+
333
+ for (const day of agendaDays) {
334
+ for (const event of day.events) {
335
+ if (labels.has(event.id)) {
336
+ continue;
337
+ }
338
+
339
+ labels.set(
340
+ event.id,
341
+ event.allDay ? (allDayText || '') : DateTime.fromJSDate(event.startAt, { zone: range.timeZone })
342
+ .setLocale(locale || 'en')
343
+ .toFormat('h:mm a'),
344
+ );
345
+ }
346
+ }
347
+
348
+ return labels;
349
+ }, [agendaDays, range.timeZone, locale, allDayText]);
350
+
351
+ /*
352
+ * Pointer interaction.
353
+ *
354
+ * The in-flight gesture lives in a ref and the window listeners it
355
+ * installs; only the resulting ghost range reaches React state, and only
356
+ * when it actually changes. A pointermove that wrote state directly would
357
+ * re-render every block in the week at pointer frequency.
358
+ */
359
+
360
+ const gridContentRef = useRef<HTMLDivElement | null>(null);
361
+ const cancelGestureRef = useRef<(() => void) | null>(null);
362
+ const [draftRange, setDraftRange] = useState<CalendarGestureRange | null>(null);
363
+
364
+ // Everything the resolver needs, read at pointer time rather than captured
365
+ // at pointerdown, so a scroll mid-drag does not use a stale layout
366
+ const gestureContextRef = useRef({ range, timedLayout });
367
+ gestureContextRef.current = { range, timedLayout };
368
+
369
+ // A gesture in flight when the component unmounts would leave window
370
+ // listeners behind and keep the whole subtree alive
371
+ useEffect(() => () => cancelGestureRef.current?.(), []);
372
+
373
+ const applyDraft = useCallback((next: CalendarGestureRange | null) => {
374
+ setDraftRange((current) => {
375
+ if (current === next) {
376
+ return current;
377
+ }
378
+
379
+ // Returning the same reference on an unchanged range is what keeps a
380
+ // slow drag from re-rendering the grid on every frame
381
+ if (
382
+ current && next &&
383
+ current.dayIndex === next.dayIndex &&
384
+ current.startAt.getTime() === next.startAt.getTime() &&
385
+ current.endAt.getTime() === next.endAt.getTime()
386
+ ) {
387
+ return current;
388
+ }
389
+
390
+ return next;
391
+ });
392
+ }, []);
393
+
394
+ const handleGridPointerDown = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
395
+ // Only the primary button, and never a second finger mid-gesture
396
+ if (!editable || event.button !== 0 || cancelGestureRef.current) {
397
+ return;
398
+ }
399
+
400
+ const content = gridContentRef.current;
401
+ if (!content) {
402
+ return;
403
+ }
404
+
405
+ const target = event.target as HTMLElement;
406
+ const blockElement = target.closest('[data-calendar-event-id]') as HTMLElement | null;
407
+ const edge = (target.closest('[data-calendar-edge]') as HTMLElement | null)?.dataset.calendarEdge;
408
+
409
+ /*
410
+ * Translate a client position into the day column and snapped minute
411
+ * under it, measured against the CONTENT box so scrolling is accounted
412
+ * for without tracking scrollTop separately.
413
+ */
414
+
415
+ const resolveSlot = (clientX: number, clientY: number) => {
416
+ const contentRect = content.getBoundingClientRect();
417
+
418
+ return getCalendarPointerSlot({
419
+ offsetX: clientX - contentRect.left - CALENDAR_GUTTER_WIDTH,
420
+ offsetY: clientY - contentRect.top,
421
+ contentWidth: contentRect.width - CALENDAR_GUTTER_WIDTH,
422
+ hourHeight: CALENDAR_HOUR_HEIGHT,
423
+ days: gestureContextRef.current.range.days,
424
+ });
425
+ };
426
+
427
+ const anchorSlot = resolveSlot(event.clientX, event.clientY);
428
+ const eventId = blockElement?.dataset.calendarEventId || null;
429
+ const grabbed = eventId
430
+ ? gestureContextRef.current.timedLayout.find((entry) => entry.event.id === eventId)
431
+ : null;
432
+
433
+ let resolveRange: (clientX: number, clientY: number, moved: boolean) => CalendarGestureRange | null;
434
+
435
+ if (grabbed && edge) {
436
+ resolveRange = (clientX, clientY) => {
437
+ const slot = resolveSlot(clientX, clientY);
438
+
439
+ return getCalendarResizeRange({
440
+ days: gestureContextRef.current.range.days,
441
+ dayIndex: grabbed.dayIndex,
442
+ startAt: grabbed.event.startAt,
443
+ endAt: grabbed.event.endAt,
444
+ edge: edge === 'START' ? 'START' : 'END',
445
+ currentMinute: slot.minute,
446
+ });
447
+ };
448
+ } else if (grabbed) {
449
+ // Where in the block it was grabbed, so it does not jump under the
450
+ // pointer on the first pixel of movement
451
+ const grabOffsetMinutes = anchorSlot.minute - grabbed.startMinute;
452
+
453
+ resolveRange = (clientX, clientY) => {
454
+ const slot = resolveSlot(clientX, clientY);
455
+
456
+ return getCalendarMoveRange({
457
+ days: gestureContextRef.current.range.days,
458
+ startAt: grabbed.event.startAt,
459
+ endAt: grabbed.event.endAt,
460
+ grabOffsetMinutes,
461
+ currentDayIndex: slot.dayIndex,
462
+ currentMinute: slot.minute,
463
+ });
464
+ };
465
+ } else {
466
+ resolveRange = (clientX, clientY, moved) => {
467
+ const slot = resolveSlot(clientX, clientY);
468
+
469
+ return getCalendarCreateRange({
470
+ days: gestureContextRef.current.range.days,
471
+ anchorDayIndex: anchorSlot.dayIndex,
472
+ anchorMinute: anchorSlot.minute,
473
+ currentDayIndex: slot.dayIndex,
474
+ currentMinute: slot.minute,
475
+ moved,
476
+ });
477
+ };
478
+ }
479
+
480
+ cancelGestureRef.current = startCalendarGesture({
481
+ kind: grabbed ? (edge ? 'RESIZE_END' : 'MOVE') : 'CREATE',
482
+ pointerId: event.pointerId,
483
+ originClientX: event.clientX,
484
+ originClientY: event.clientY,
485
+ resolveRange,
486
+ onPreview: applyDraft,
487
+ onCommit: (committed, moved) => {
488
+ if (grabbed) {
489
+ // A press that never moved is somebody opening the block, not
490
+ // asking to move it by zero minutes
491
+ if (moved) {
492
+ onMoveEvent?.({
493
+ eventId: grabbed.event.id,
494
+ startAt: committed.startAt,
495
+ endAt: committed.endAt,
496
+ });
497
+ }
498
+
499
+ return;
500
+ }
501
+
502
+ onCreateRange?.({ startAt: committed.startAt, endAt: committed.endAt });
503
+ },
504
+ onFinish: () => {
505
+ cancelGestureRef.current = null;
506
+ },
507
+ });
508
+ }, [editable, applyDraft, onCreateRange, onMoveEvent]);
509
+
510
+ const todayIndex = range.days.findIndex((day) => day.isToday);
511
+ const nowOffset = todayIndex >= 0
512
+ ? (getMinutesFromDayStart(now, range.days[todayIndex].startAt) / 60) * CALENDAR_HOUR_HEIGHT
513
+ : -1;
514
+
515
+ const selectedEventId = popoverState?.eventId || null;
516
+
517
+ // The ghost's own label, so a drag reads as a time range while it is being
518
+ // drawn rather than as an unlabelled rectangle
519
+ const draftTimeLabel = useMemo(() => {
520
+ if (!draftRange) {
521
+ return '';
522
+ }
523
+
524
+ const zone = range.timeZone;
525
+ const start = DateTime.fromJSDate(draftRange.startAt, { zone }).setLocale(locale || 'en');
526
+ const end = DateTime.fromJSDate(draftRange.endAt, { zone }).setLocale(locale || 'en');
527
+
528
+ return `${start.toFormat('h:mm a')} – ${end.toFormat('h:mm a')}`;
529
+ }, [draftRange, range.timeZone, locale]);
530
+
531
+ return (
532
+ <div className={cn('v_stretch h_f w_f rel bg', className)}>
533
+ {children}
534
+
535
+ {/* Only the time grid has day columns to label and an all-day band
536
+ to hang above them */}
537
+ {isTimeGrid
538
+ ? (
539
+ <>
540
+ <CalendarDayHeaderUI
541
+ days={range.days}
542
+ dayLabels={dayLabels}
543
+ onSelectDay={onSelectDay}
544
+ />
545
+
546
+ <CalendarAllDayBandUI
547
+ bars={allDayBars}
548
+ dayCount={range.days.length}
549
+ selectedEventId={selectedEventId}
550
+ onSelect={handleSelectEvent}
551
+ />
552
+ </>
553
+ )
554
+ : null}
555
+
556
+ {view === 'MONTH'
557
+ ? (
558
+ <CalendarMonthUI
559
+ cells={monthCells}
560
+ weekdayLabels={weekdayLabels}
561
+ dayNumberLabels={dayLabels.map((label) => label.dayNumber)}
562
+ selectedEventId={selectedEventId}
563
+ moreLabel={moreLabel || ((count) => `+${count}`)}
564
+ onSelectEvent={handleSelectEvent}
565
+ onSelectDay={(dateKey) => onSelectDay?.(dateKey)}
566
+ onSelectOverflow={(dateKey) => onSelectDay?.(dateKey)}
567
+ />
568
+ )
569
+ : null}
570
+
571
+ {view === 'YEAR'
572
+ ? (
573
+ <CalendarYearUI
574
+ months={yearMonths}
575
+ weekdayInitials={weekdayInitials}
576
+ onSelectDay={(dateKey) => onSelectDay?.(dateKey)}
577
+ />
578
+ )
579
+ : null}
580
+
581
+ {view === 'AGENDA'
582
+ ? (
583
+ <CalendarAgendaUI
584
+ days={agendaDays}
585
+ selectedEventId={selectedEventId}
586
+ timeLabelByEventId={agendaTimeLabels}
587
+ emptyText={agendaEmptyText || ''}
588
+ onSelectEvent={handleSelectEvent}
589
+ />
590
+ )
591
+ : null}
592
+
593
+ {isTimeGrid
594
+ ? (
595
+ <div className='f h_0 app_scr auto_y rel'>
596
+ <div
597
+ ref={gridContentRef}
598
+ className='h_stretch rel'
599
+ style={{ height: gridHeight, touchAction: 'manipulation' }}
600
+ onPointerDown={handleGridPointerDown}
601
+ >
602
+ <CalendarTimeGutterUI hourHeight={CALENDAR_HOUR_HEIGHT} hourLabels={hourLabels} />
603
+
604
+ {range.days.map((day, dayIndex) => (
605
+ <div
606
+ key={day.dateKey}
607
+ className={cn('f rel bd_l_1 bd_l_bd', day.isWeekend ? 'bg_alt' : '')}
608
+ >
609
+ <CalendarHourLinesUI
610
+ hourCount={Math.ceil(getDayLengthMinutes(day) / 60)}
611
+ hourHeight={CALENDAR_HOUR_HEIGHT}
612
+ />
613
+
614
+ {dayIndex === todayIndex && nowOffset >= 0
615
+ ? <CalendarNowLineUI topOffset={nowOffset} />
616
+ : null}
617
+
618
+ {layoutByDayIndex[dayIndex]?.map((entry) => (
619
+ <CalendarEventUI
620
+ key={entry.event.id}
621
+ editable={!!editable}
622
+ layout={entry}
623
+ hourHeight={CALENDAR_HOUR_HEIGHT}
624
+ selected={selectedEventId === entry.event.id}
625
+ timeLabel={timeLabelByEventId.get(entry.event.id) || ''}
626
+ onSelect={handleSelectEvent}
627
+ />
628
+ ))}
629
+
630
+ {draftRange?.dayIndex === dayIndex
631
+ ? (
632
+ <CalendarDraftBlockUI
633
+ startMinute={getMinutesFromDayStart(draftRange.startAt, day.startAt)}
634
+ endMinute={getMinutesFromDayStart(draftRange.endAt, day.startAt)}
635
+ hourHeight={CALENDAR_HOUR_HEIGHT}
636
+ label={draftTimeLabel}
637
+ />
638
+ )
639
+ : null}
640
+ </div>
641
+ ))}
642
+ </div>
643
+ </div>
644
+ )
645
+ : null}
646
+ </div>
647
+ );
648
+ });