@jsb188/calendar 1.1.10 → 1.1.11

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.
@@ -23,7 +23,13 @@ import {
23
23
  startCalendarGesture,
24
24
  type CalendarGestureRange,
25
25
  } from '../libs/calendar-gesture.ts';
26
- import { getCalendarRange, getDayLengthMinutes, getMinutesFromDayStart } from '../libs/calendar-range.ts';
26
+ import {
27
+ getCalendarDateKey,
28
+ getCalendarRange,
29
+ getDayLengthMinutes,
30
+ getMinutesFromDayStart,
31
+ normalizeCalendarWeekStartsOn,
32
+ } from '../libs/calendar-range.ts';
27
33
  import {
28
34
  applyCalendarOptimisticOverlays,
29
35
  createCalendarStateAtoms,
@@ -31,7 +37,10 @@ import {
31
37
  type CalendarStateAtoms,
32
38
  } from '../libs/calendar-state.ts';
33
39
  import type { CalendarEventObj } from '../types/calendar.d.ts';
34
- import { CalendarAgendaUI, type CalendarAgendaDayObj } from '../ui/CalendarAgendaUI.tsx';
40
+ import {
41
+ CalendarAgendaUI,
42
+ type CalendarAgendaDayObj,
43
+ } from '../ui/CalendarAgendaUI.tsx';
35
44
  import { CalendarMonthUI } from '../ui/CalendarMonthUI.tsx';
36
45
  import {
37
46
  CalendarAllDayBandUI,
@@ -42,7 +51,10 @@ import {
42
51
  CalendarNowLineUI,
43
52
  CalendarTimeGutterUI,
44
53
  } from '../ui/CalendarUI.tsx';
45
- import { CalendarYearUI, type CalendarYearMonthObj } from '../ui/CalendarYearUI.tsx';
54
+ import {
55
+ CalendarYearUI,
56
+ type CalendarYearMonthObj,
57
+ } from '../ui/CalendarYearUI.tsx';
46
58
 
47
59
  /**
48
60
  * The calendar surface.
@@ -96,7 +108,9 @@ export function Calendar(p: CalendarProps) {
96
108
  // Created in a ref, never inline in the render body: creating atoms inline
97
109
  // would hand every render a fresh bag and reset all state
98
110
  if (!stateAtomsRef.current) {
99
- stateAtomsRef.current = createCalendarStateAtoms(getCalendarStateScopeKey());
111
+ stateAtomsRef.current = createCalendarStateAtoms(
112
+ getCalendarStateScopeKey(),
113
+ );
100
114
  }
101
115
 
102
116
  return <CalendarContent {...p} stateAtoms={stateAtomsRef.current} />;
@@ -106,16 +120,28 @@ type CalendarContentProps = CalendarProps & {
106
120
  stateAtoms: CalendarStateAtoms;
107
121
  };
108
122
 
123
+ /*
124
+ * Render the default month overflow label when the caller supplies no formatter.
125
+ */
126
+
127
+ function getDefaultCalendarMoreLabel(count: number): string {
128
+ return `+${count}`;
129
+ }
130
+
109
131
  /*
110
132
  * Format the hour labels once per locale rather than per hour per render.
111
133
  */
112
134
 
113
135
  function useCalendarHourLabels(timeZone: string, locale?: string | null) {
114
136
  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'));
137
+ const base = DateTime.fromObject(
138
+ { year: 2026, month: 1, day: 1 },
139
+ { zone: timeZone },
140
+ ).setLocale(locale || 'en');
141
+
142
+ return Array.from({ length: 24 }, (_unused, hour) =>
143
+ base.set({ hour }).toFormat('h a'),
144
+ );
119
145
  }, [timeZone, locale]);
120
146
  }
121
147
 
@@ -147,16 +173,31 @@ const CalendarContent = memo((p: CalendarContentProps) => {
147
173
 
148
174
  const [popoverState, setPopoverState] = useAtom(stateAtoms.popoverStateAtom);
149
175
  const optimisticEvents = useAtomValue(stateAtoms.optimisticEventsAtom);
150
- const removedEventIds = useAtomValue(stateAtoms.optimisticallyRemovedEventIdsAtom);
176
+ const removedEventIds = useAtomValue(
177
+ stateAtoms.optimisticallyRemovedEventIdsAtom,
178
+ );
151
179
 
180
+ // "now" ticks every minute to move the now line, but the range only uses it
181
+ // to decide which column is today — so the memo keys on the local DATE
182
+ // rather than the instant. Keying on the instant would rebuild the day
183
+ // objects every minute, and every layout pass hanging off range.days with
184
+ // them, to redraw a line that moved one pixel.
185
+ const nowDateKey = getCalendarDateKey(now, timeZone);
152
186
  const range = useMemo(
187
+ // "now" is read inside but "nowDateKey" is the dependency: the range only
188
+ // changes when the local date does
153
189
  () => getCalendarRange({ view, anchorDate, now, timeZone, weekStartsOn }),
154
- [view, anchorDate, now, timeZone, weekStartsOn],
190
+ [view, anchorDate, nowDateKey, timeZone, weekStartsOn],
155
191
  );
156
192
 
157
193
  // One pass over the week per data change, not per subscriber
158
194
  const visibleEvents = useMemo(
159
- () => applyCalendarOptimisticOverlays(events, optimisticEvents, removedEventIds),
195
+ () =>
196
+ applyCalendarOptimisticOverlays(
197
+ events,
198
+ optimisticEvents,
199
+ removedEventIds,
200
+ ),
160
201
  [events, optimisticEvents, removedEventIds],
161
202
  );
162
203
 
@@ -170,11 +211,19 @@ const CalendarContent = memo((p: CalendarContentProps) => {
170
211
  [isTimeGrid, visibleEvents, range.days],
171
212
  );
172
213
  const allDayBars = useMemo(
173
- () => (isTimeGrid ? getCalendarAllDayLayout(visibleEvents, range.days) : []),
214
+ () =>
215
+ isTimeGrid ? getCalendarAllDayLayout(visibleEvents, range.days) : [],
174
216
  [isTimeGrid, visibleEvents, range.days],
175
217
  );
176
218
  const monthCells = useMemo(
177
- () => (view === 'MONTH' ? getCalendarMonthCells(visibleEvents, range.days, CALENDAR_MONTH_CELL_MAX_EVENTS) : []),
219
+ () =>
220
+ view === 'MONTH'
221
+ ? getCalendarMonthCells(
222
+ visibleEvents,
223
+ range.days,
224
+ CALENDAR_MONTH_CELL_MAX_EVENTS,
225
+ )
226
+ : [],
178
227
  [view, visibleEvents, range.days],
179
228
  );
180
229
 
@@ -183,7 +232,9 @@ const CalendarContent = memo((p: CalendarContentProps) => {
183
232
  const dayLabels = useMemo(
184
233
  () =>
185
234
  range.days.map((day) => {
186
- const local = DateTime.fromJSDate(day.startAt, { zone: range.timeZone }).setLocale(locale || 'en');
235
+ const local = DateTime.fromJSDate(day.startAt, {
236
+ zone: range.timeZone,
237
+ }).setLocale(locale || 'en');
187
238
 
188
239
  return {
189
240
  weekday: local.toFormat('ccc'),
@@ -199,17 +250,20 @@ const CalendarContent = memo((p: CalendarContentProps) => {
199
250
  */
200
251
 
201
252
  const weekdayLabels = useMemo(() => {
202
- const weekStart = Number.isInteger(weekStartsOn) ? Number(weekStartsOn) : 0;
253
+ const weekStart = normalizeCalendarWeekStartsOn(weekStartsOn);
203
254
  // 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'));
255
+ const sunday = DateTime.fromObject(
256
+ { year: 2026, month: 1, day: 4 },
257
+ { zone: range.timeZone },
258
+ ).setLocale(locale || 'en');
259
+
260
+ return Array.from({ length: 7 }, (_unused, index) =>
261
+ sunday.plus({ days: index + weekStart }).toFormat('ccc'),
262
+ );
208
263
  }, [range.timeZone, locale, weekStartsOn]);
209
-
210
- const weekdayInitials = useMemo(
211
- () => weekdayLabels.map((label) => label.slice(0, 1)),
212
- [weekdayLabels],
264
+ const dayNumberLabels = useMemo(
265
+ () => dayLabels.map((label) => label.dayNumber),
266
+ [dayLabels],
213
267
  );
214
268
 
215
269
  const timeLabelByEventId = useMemo(() => {
@@ -231,17 +285,30 @@ const CalendarContent = memo((p: CalendarContentProps) => {
231
285
  return labels;
232
286
  }, [timedLayout, range.timeZone, locale]);
233
287
 
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
- ));
288
+ const handleSelectEvent = useCallback(
289
+ (eventId: string) => {
290
+ setPopoverState((current) =>
291
+ // Clicking the open event again closes it, and returning the same
292
+ // reference on a no-op keeps subscribers from re-rendering
293
+ current?.eventId === eventId
294
+ ? null
295
+ : { eventId, anchorRect: { top: 0, left: 0, width: 0, height: 0 } },
296
+ );
297
+
298
+ onSelectEvent?.(eventId);
299
+ },
300
+ [onSelectEvent, setPopoverState],
301
+ );
242
302
 
243
- onSelectEvent?.(eventId);
244
- }, [onSelectEvent, setPopoverState]);
303
+ /*
304
+ * Forward day selection with one stable callback for every calendar view.
305
+ */
306
+ const handleSelectDay = useCallback(
307
+ (dateKey: string) => {
308
+ onSelectDay?.(dateKey);
309
+ },
310
+ [onSelectDay],
311
+ );
245
312
 
246
313
  const layoutByDayIndex = useMemo(() => {
247
314
  const byDay: Array<typeof timedLayout> = range.days.map(() => []);
@@ -256,13 +323,19 @@ const CalendarContent = memo((p: CalendarContentProps) => {
256
323
  // A DST day is 23 or 25 hours long; drawing 24 would put every event after
257
324
  // the transition an hour out
258
325
  const gridHeight = useMemo(
259
- () => (Math.max(...range.days.map(getDayLengthMinutes)) / 60) * CALENDAR_HOUR_HEIGHT,
326
+ () =>
327
+ (Math.max(...range.days.map(getDayLengthMinutes)) / 60) *
328
+ CALENDAR_HOUR_HEIGHT,
260
329
  [range.days],
261
330
  );
331
+ const gridContentStyle = useMemo(
332
+ () => ({ height: gridHeight, touchAction: 'manipulation' as const }),
333
+ [gridHeight],
334
+ );
262
335
 
263
336
  /*
264
- * Group the year's days into twelve mini grids, each padded so the 1st
265
- * lands under its own weekday column.
337
+ * The twelve months the year view draws. Each mini grid builds its own days
338
+ * from the month it is given, so this only has to name them.
266
339
  */
267
340
 
268
341
  const yearMonths = useMemo<CalendarYearMonthObj[]>(() => {
@@ -270,29 +343,21 @@ const CalendarContent = memo((p: CalendarContentProps) => {
270
343
  return [];
271
344
  }
272
345
 
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');
346
+ const yearStart = DateTime.fromJSDate(range.anchorDate, {
347
+ zone: range.timeZone,
348
+ })
349
+ .setLocale(locale || 'en')
350
+ .startOf('year');
278
351
 
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
- }
352
+ return Array.from({ length: 12 }, (_unused, index) => {
353
+ const monthStart = yearStart.plus({ months: index });
288
354
 
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]);
355
+ return {
356
+ label: monthStart.toFormat('LLLL'),
357
+ monthDate: monthStart.toJSDate(),
358
+ };
359
+ });
360
+ }, [view, range.anchorDate, range.timeZone, locale]);
296
361
 
297
362
  /*
298
363
  * Build the agenda list, omitting days with nothing on them.
@@ -338,9 +403,11 @@ const CalendarContent = memo((p: CalendarContentProps) => {
338
403
 
339
404
  labels.set(
340
405
  event.id,
341
- event.allDay ? (allDayText || '') : DateTime.fromJSDate(event.startAt, { zone: range.timeZone })
342
- .setLocale(locale || 'en')
343
- .toFormat('h:mm a'),
406
+ event.allDay
407
+ ? allDayText || ''
408
+ : DateTime.fromJSDate(event.startAt, { zone: range.timeZone })
409
+ .setLocale(locale || 'en')
410
+ .toFormat('h:mm a'),
344
411
  );
345
412
  }
346
413
  }
@@ -359,7 +426,9 @@ const CalendarContent = memo((p: CalendarContentProps) => {
359
426
 
360
427
  const gridContentRef = useRef<HTMLDivElement | null>(null);
361
428
  const cancelGestureRef = useRef<(() => void) | null>(null);
362
- const [draftRange, setDraftRange] = useState<CalendarGestureRange | null>(null);
429
+ const [draftRange, setDraftRange] = useState<CalendarGestureRange | null>(
430
+ null,
431
+ );
363
432
 
364
433
  // Everything the resolver needs, read at pointer time rather than captured
365
434
  // at pointerdown, so a scroll mid-drag does not use a stale layout
@@ -379,7 +448,8 @@ const CalendarContent = memo((p: CalendarContentProps) => {
379
448
  // Returning the same reference on an unchanged range is what keeps a
380
449
  // slow drag from re-rendering the grid on every frame
381
450
  if (
382
- current && next &&
451
+ current &&
452
+ next &&
383
453
  current.dayIndex === next.dayIndex &&
384
454
  current.startAt.getTime() === next.startAt.getTime() &&
385
455
  current.endAt.getTime() === next.endAt.getTime()
@@ -391,126 +461,143 @@ const CalendarContent = memo((p: CalendarContentProps) => {
391
461
  });
392
462
  }, []);
393
463
 
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;
464
+ const handleGridPointerDown = useCallback(
465
+ (event: React.PointerEvent<HTMLDivElement>) => {
466
+ // Only the primary button, and never a second finger mid-gesture
467
+ if (!editable || event.button !== 0 || cancelGestureRef.current) {
468
+ return;
469
+ }
452
470
 
453
- resolveRange = (clientX, clientY) => {
454
- const slot = resolveSlot(clientX, clientY);
471
+ const content = gridContentRef.current;
472
+ if (!content) {
473
+ return;
474
+ }
455
475
 
456
- return getCalendarMoveRange({
476
+ const target = event.target as HTMLElement;
477
+ const blockElement = target.closest(
478
+ '[data-calendar-event-id]',
479
+ ) as HTMLElement | null;
480
+ const edge = (
481
+ target.closest('[data-calendar-edge]') as HTMLElement | null
482
+ )?.dataset.calendarEdge;
483
+
484
+ /*
485
+ * Translate a client position into the day column and snapped minute
486
+ * under it, measured against the CONTENT box so scrolling is accounted
487
+ * for without tracking scrollTop separately.
488
+ */
489
+
490
+ const resolveSlot = (clientX: number, clientY: number) => {
491
+ const contentRect = content.getBoundingClientRect();
492
+
493
+ return getCalendarPointerSlot({
494
+ offsetX: clientX - contentRect.left - CALENDAR_GUTTER_WIDTH,
495
+ offsetY: clientY - contentRect.top,
496
+ contentWidth: contentRect.width - CALENDAR_GUTTER_WIDTH,
497
+ hourHeight: CALENDAR_HOUR_HEIGHT,
457
498
  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
499
  });
464
500
  };
465
- } else {
466
- resolveRange = (clientX, clientY, moved) => {
467
- const slot = resolveSlot(clientX, clientY);
468
501
 
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
- }
502
+ const anchorSlot = resolveSlot(event.clientX, event.clientY);
503
+ const eventId = blockElement?.dataset.calendarEventId || null;
504
+ const grabbed = eventId
505
+ ? gestureContextRef.current.timedLayout.find(
506
+ (entry) => entry.event.id === eventId,
507
+ )
508
+ : null;
509
+
510
+ let resolveRange: (
511
+ clientX: number,
512
+ clientY: number,
513
+ moved: boolean,
514
+ ) => CalendarGestureRange | null;
515
+
516
+ if (grabbed && edge) {
517
+ resolveRange = (clientX, clientY) => {
518
+ const slot = resolveSlot(clientX, clientY);
519
+
520
+ return getCalendarResizeRange({
521
+ days: gestureContextRef.current.range.days,
522
+ dayIndex: grabbed.dayIndex,
523
+ startAt: grabbed.event.startAt,
524
+ endAt: grabbed.event.endAt,
525
+ edge: edge === 'START' ? 'START' : 'END',
526
+ currentMinute: slot.minute,
527
+ });
528
+ };
529
+ } else if (grabbed) {
530
+ // Where in the block it was grabbed, so it does not jump under the
531
+ // pointer on the first pixel of movement
532
+ const grabOffsetMinutes = anchorSlot.minute - grabbed.startMinute;
533
+
534
+ resolveRange = (clientX, clientY) => {
535
+ const slot = resolveSlot(clientX, clientY);
536
+
537
+ return getCalendarMoveRange({
538
+ days: gestureContextRef.current.range.days,
539
+ startAt: grabbed.event.startAt,
540
+ endAt: grabbed.event.endAt,
541
+ grabOffsetMinutes,
542
+ currentDayIndex: slot.dayIndex,
543
+ currentMinute: slot.minute,
544
+ });
545
+ };
546
+ } else {
547
+ resolveRange = (clientX, clientY, moved) => {
548
+ const slot = resolveSlot(clientX, clientY);
549
+
550
+ return getCalendarCreateRange({
551
+ days: gestureContextRef.current.range.days,
552
+ anchorDayIndex: anchorSlot.dayIndex,
553
+ anchorMinute: anchorSlot.minute,
554
+ currentDayIndex: slot.dayIndex,
555
+ currentMinute: slot.minute,
556
+ moved,
557
+ });
558
+ };
559
+ }
479
560
 
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
- });
561
+ cancelGestureRef.current = startCalendarGesture({
562
+ pointerId: event.pointerId,
563
+ originClientX: event.clientX,
564
+ originClientY: event.clientY,
565
+ resolveRange,
566
+ onPreview: applyDraft,
567
+ onCommit: (committed, moved) => {
568
+ if (grabbed) {
569
+ // A press that never moved is somebody opening the block, not
570
+ // asking to move it by zero minutes
571
+ if (moved) {
572
+ onMoveEvent?.({
573
+ eventId: grabbed.event.id,
574
+ startAt: committed.startAt,
575
+ endAt: committed.endAt,
576
+ });
577
+ }
578
+
579
+ return;
497
580
  }
498
581
 
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]);
582
+ onCreateRange?.({
583
+ startAt: committed.startAt,
584
+ endAt: committed.endAt,
585
+ });
586
+ },
587
+ onFinish: () => {
588
+ cancelGestureRef.current = null;
589
+ },
590
+ });
591
+ },
592
+ [editable, applyDraft, onCreateRange, onMoveEvent],
593
+ );
509
594
 
510
595
  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;
596
+ const nowOffset =
597
+ todayIndex >= 0
598
+ ? (getMinutesFromDayStart(now, range.days[todayIndex].startAt) / 60) *
599
+ CALENDAR_HOUR_HEIGHT
600
+ : -1;
514
601
 
515
602
  const selectedEventId = popoverState?.eventId || null;
516
603
 
@@ -522,8 +609,12 @@ const CalendarContent = memo((p: CalendarContentProps) => {
522
609
  }
523
610
 
524
611
  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');
612
+ const start = DateTime.fromJSDate(draftRange.startAt, { zone }).setLocale(
613
+ locale || 'en',
614
+ );
615
+ const end = DateTime.fromJSDate(draftRange.endAt, { zone }).setLocale(
616
+ locale || 'en',
617
+ );
527
618
 
528
619
  return `${start.toFormat('h:mm a')} – ${end.toFormat('h:mm a')}`;
529
620
  }, [draftRange, range.timeZone, locale]);
@@ -534,115 +625,118 @@ const CalendarContent = memo((p: CalendarContentProps) => {
534
625
 
535
626
  {/* Only the time grid has day columns to label and an all-day band
536
627
  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)}
628
+ {isTimeGrid ? (
629
+ <>
630
+ <CalendarDayHeaderUI
631
+ days={range.days}
632
+ dayLabels={dayLabels}
633
+ onSelectDay={onSelectDay}
567
634
  />
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
635
 
581
- {view === 'AGENDA'
582
- ? (
583
- <CalendarAgendaUI
584
- days={agendaDays}
636
+ <CalendarAllDayBandUI
637
+ bars={allDayBars}
638
+ dayCount={range.days.length}
585
639
  selectedEventId={selectedEventId}
586
- timeLabelByEventId={agendaTimeLabels}
587
- emptyText={agendaEmptyText || ''}
588
- onSelectEvent={handleSelectEvent}
640
+ onSelect={handleSelectEvent}
589
641
  />
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)}
642
+ </>
643
+ ) : null}
644
+
645
+ {view === 'MONTH' ? (
646
+ <CalendarMonthUI
647
+ cells={monthCells}
648
+ weekdayLabels={weekdayLabels}
649
+ dayNumberLabels={dayNumberLabels}
650
+ selectedEventId={selectedEventId}
651
+ moreLabel={moreLabel || getDefaultCalendarMoreLabel}
652
+ onSelectEvent={handleSelectEvent}
653
+ onSelectDay={handleSelectDay}
654
+ onSelectOverflow={handleSelectDay}
655
+ />
656
+ ) : null}
657
+
658
+ {view === 'YEAR' ? (
659
+ <CalendarYearUI
660
+ months={yearMonths}
661
+ timeZone={range.timeZone}
662
+ locale={locale}
663
+ weekStartsOn={weekStartsOn}
664
+ todayDateKey={nowDateKey}
665
+ onSelectDay={handleSelectDay}
666
+ />
667
+ ) : null}
668
+
669
+ {view === 'AGENDA' ? (
670
+ <CalendarAgendaUI
671
+ days={agendaDays}
672
+ selectedEventId={selectedEventId}
673
+ timeLabelByEventId={agendaTimeLabels}
674
+ emptyText={agendaEmptyText || ''}
675
+ onSelectEvent={handleSelectEvent}
676
+ />
677
+ ) : null}
678
+
679
+ {isTimeGrid ? (
680
+ <div className="f h_0 app_scr auto_y rel">
681
+ <div
682
+ ref={gridContentRef}
683
+ className="h_stretch rel"
684
+ style={gridContentStyle}
685
+ onPointerDown={handleGridPointerDown}
686
+ >
687
+ <CalendarTimeGutterUI
688
+ hourHeight={CALENDAR_HOUR_HEIGHT}
689
+ hourLabels={hourLabels}
690
+ />
691
+
692
+ {range.days.map((day, dayIndex) => (
693
+ <div
694
+ key={day.dateKey}
695
+ className={cn(
696
+ 'f rel bd_l_1 bd_l_bd',
697
+ day.isWeekend ? 'bg_alt' : '',
698
+ )}
699
+ >
700
+ <CalendarHourLinesUI
701
+ hourCount={Math.ceil(getDayLengthMinutes(day) / 60)}
702
+ hourHeight={CALENDAR_HOUR_HEIGHT}
703
+ />
704
+
705
+ {dayIndex === todayIndex && nowOffset >= 0 ? (
706
+ <CalendarNowLineUI topOffset={nowOffset} />
707
+ ) : null}
708
+
709
+ {layoutByDayIndex[dayIndex]?.map((entry) => (
710
+ <CalendarEventUI
711
+ key={entry.event.id}
712
+ editable={!!editable}
713
+ layout={entry}
611
714
  hourHeight={CALENDAR_HOUR_HEIGHT}
715
+ selected={selectedEventId === entry.event.id}
716
+ timeLabel={timeLabelByEventId.get(entry.event.id) || ''}
717
+ onSelect={handleSelectEvent}
612
718
  />
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>
719
+ ))}
720
+
721
+ {draftRange?.dayIndex === dayIndex ? (
722
+ <CalendarDraftBlockUI
723
+ startMinute={getMinutesFromDayStart(
724
+ draftRange.startAt,
725
+ day.startAt,
726
+ )}
727
+ endMinute={getMinutesFromDayStart(
728
+ draftRange.endAt,
729
+ day.startAt,
730
+ )}
731
+ hourHeight={CALENDAR_HOUR_HEIGHT}
732
+ label={draftTimeLabel}
733
+ />
734
+ ) : null}
735
+ </div>
736
+ ))}
643
737
  </div>
644
- )
645
- : null}
738
+ </div>
739
+ ) : null}
646
740
  </div>
647
741
  );
648
742
  });