@super-calendar/native 2.8.1 → 2.9.0
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.
- package/README.md +1 -0
- package/dist/{DefaultMonthEvent-CjwX3Nt1.d.ts → DefaultMonthEvent--9Jg6w-x.d.ts} +98 -10
- package/dist/{DefaultMonthEvent-VgJarTO_.d.mts → DefaultMonthEvent-BlnKHaq2.d.mts} +98 -10
- package/dist/{MonthList-DjAz4xoi.mjs → MonthList-CjKhzOJX.mjs} +356 -102
- package/dist/{MonthList-C-vBotP0.js → MonthList-DNT1LJkk.js} +355 -101
- package/dist/index.d.mts +85 -37
- package/dist/index.d.ts +85 -37
- package/dist/index.js +377 -60
- package/dist/index.mjs +378 -61
- package/dist/picker.d.mts +1 -1
- package/dist/picker.d.ts +1 -1
- package/dist/picker.js +1 -1
- package/dist/picker.mjs +1 -1
- package/package.json +2 -2
- package/src/components/Agenda.tsx +3 -3
- package/src/components/AllDayLane.tsx +2 -2
- package/src/components/Calendar.tsx +79 -16
- package/src/components/MonthList.tsx +3 -2
- package/src/components/MonthPager.tsx +152 -63
- package/src/components/MonthView.tsx +422 -80
- package/src/components/TimeGrid.tsx +247 -35
- package/src/components/YearView.tsx +371 -83
- package/src/types.ts +19 -0
- package/src/utils/slots.ts +33 -9
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import { format, type Locale, isSameMonth, startOfDay } from "date-fns";
|
|
2
|
-
import { memo, type ReactElement, useMemo, useState } from "react";
|
|
2
|
+
import { memo, type ReactElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import {
|
|
4
4
|
type DimensionValue,
|
|
5
5
|
type LayoutChangeEvent,
|
|
6
6
|
Modal,
|
|
7
7
|
Platform,
|
|
8
|
+
type PointerEvent as RNPointerEvent,
|
|
8
9
|
Pressable,
|
|
9
10
|
ScrollView,
|
|
10
11
|
StyleSheet,
|
|
11
12
|
type StyleProp,
|
|
12
13
|
Text,
|
|
14
|
+
type TextStyle,
|
|
13
15
|
TouchableOpacity,
|
|
14
16
|
View,
|
|
15
17
|
type ViewStyle,
|
|
16
18
|
} from "react-native";
|
|
19
|
+
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
17
20
|
|
|
18
21
|
// Web drag-to-select relays cell pointer events up to MonthList; native drag is
|
|
19
22
|
// driven by a list-level pan there instead.
|
|
20
23
|
const isWeb = Platform.OS === "web";
|
|
21
24
|
import { useCalendarTheme } from "../theme";
|
|
22
|
-
import type {
|
|
25
|
+
import type {
|
|
26
|
+
CalendarEvent,
|
|
27
|
+
EventDragHandler,
|
|
28
|
+
EventDragStartHandler,
|
|
29
|
+
EventKeyExtractor,
|
|
30
|
+
RenderEvent,
|
|
31
|
+
WeekStartsOn,
|
|
32
|
+
} from "../types";
|
|
23
33
|
import { createSlots, type SlotStyleProps } from "../utils/slots";
|
|
24
34
|
import { withEventAccessibilityLabel } from "../utils/withEventAccessibilityLabel";
|
|
25
35
|
import {
|
|
@@ -27,6 +37,7 @@ import {
|
|
|
27
37
|
type EventAccessibilityLabeler,
|
|
28
38
|
type WeekdayFormat,
|
|
29
39
|
daySelectionState,
|
|
40
|
+
isDateSelectable,
|
|
30
41
|
useCalendarSelection,
|
|
31
42
|
weekdayFormatToken,
|
|
32
43
|
} from "@super-calendar/core";
|
|
@@ -41,6 +52,7 @@ import {
|
|
|
41
52
|
} from "@super-calendar/core";
|
|
42
53
|
import { monthEventCapacity, monthVisibleCount } from "@super-calendar/core";
|
|
43
54
|
import { layoutMonthWeek, type MonthWeekEvents } from "@super-calendar/core";
|
|
55
|
+
import { monthCreateRange, monthDropBounds, overlapsOtherEvents } from "@super-calendar/core";
|
|
44
56
|
import {
|
|
45
57
|
compareDayEvents,
|
|
46
58
|
groupEventsByDay,
|
|
@@ -64,6 +76,12 @@ const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
|
|
|
64
76
|
const CHIP_INSET_H = 4;
|
|
65
77
|
// Pre-measure fallback so the first paint isn't empty or overflowing.
|
|
66
78
|
const FALLBACK_VISIBLE_COUNT = 3;
|
|
79
|
+
// Hold this long to start a month drag. Shorter than TouchableOpacity's own
|
|
80
|
+
// 500ms long-press so the pan wins the race and the cell's `onLongPressDay`
|
|
81
|
+
// doesn't also fire.
|
|
82
|
+
const DRAG_LONG_PRESS_MS = 400;
|
|
83
|
+
// Opacity of an event bar while it is being dragged to another day.
|
|
84
|
+
const DRAGGED_BAR_OPACITY = 0.4;
|
|
67
85
|
|
|
68
86
|
const numericStyle = (value: number | string | undefined, fallback: number) =>
|
|
69
87
|
typeof value === "number" ? value : fallback;
|
|
@@ -91,6 +109,21 @@ function collectRowEvents<T>(
|
|
|
91
109
|
|
|
92
110
|
const pct = (n: number): DimensionValue => `${n}%` as DimensionValue;
|
|
93
111
|
|
|
112
|
+
// An in-progress month drag: either a day span being swept out for a new event,
|
|
113
|
+
// or an existing event being carried to another day.
|
|
114
|
+
type MonthDrag<T> =
|
|
115
|
+
| { kind: "create"; anchor: Date; hover: Date }
|
|
116
|
+
| { kind: "move"; event: CalendarEvent<T>; from: Date; to: Date };
|
|
117
|
+
|
|
118
|
+
// True when `day` falls inside the span swept out so far (either direction).
|
|
119
|
+
function isInCreateSpan<T>(drag: MonthDrag<T> | null, day: Date): boolean {
|
|
120
|
+
if (drag?.kind !== "create") return false;
|
|
121
|
+
const time = startOfDay(day).getTime();
|
|
122
|
+
const a = startOfDay(drag.anchor).getTime();
|
|
123
|
+
const b = startOfDay(drag.hover).getTime();
|
|
124
|
+
return time >= Math.min(a, b) && time <= Math.max(a, b);
|
|
125
|
+
}
|
|
126
|
+
|
|
94
127
|
/**
|
|
95
128
|
* The styleable parts of {@link MonthView}. Mirrors the dom renderer's slot
|
|
96
129
|
* names where the structure matches; `dayBadgeText` is native-only (React
|
|
@@ -181,9 +214,47 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
|
|
|
181
214
|
keyExtractor: EventKeyExtractor<T>;
|
|
182
215
|
onPressDay?: (date: Date) => void;
|
|
183
216
|
onLongPressDay?: (date: Date) => void;
|
|
217
|
+
/**
|
|
218
|
+
* Tap an empty day cell. Fires alongside `onPressDay` with the same day at
|
|
219
|
+
* midnight, so one handler can create events across month and week/day modes.
|
|
220
|
+
*/
|
|
221
|
+
onPressCell?: (date: Date) => void;
|
|
184
222
|
onPressEvent: (event: CalendarEvent<T>) => void;
|
|
185
223
|
onLongPressEvent?: (event: CalendarEvent<T>) => void;
|
|
186
224
|
onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Enable drag-to-create: **long-press an empty day** and sweep across others
|
|
227
|
+
* (**press and drag** on the web), then release to fire this with the **all-day**
|
|
228
|
+
* range — `start` at midnight of the first day, `end` at midnight after the last
|
|
229
|
+
* (exclusive). A sweep that never leaves its day still yields that one day. A
|
|
230
|
+
* plain tap fires `onPressDay`/`onPressCell` instead.
|
|
231
|
+
*/
|
|
232
|
+
onCreateEvent?: (start: Date, end: Date) => void;
|
|
233
|
+
/**
|
|
234
|
+
* Reports the day span of a create sweep **as it happens**, as the ordered
|
|
235
|
+
* inclusive `[start, end]` days (both at midnight), so a selection highlight can
|
|
236
|
+
* follow the drag instead of appearing only on release. Pair it with
|
|
237
|
+
* `useDateRange`'s `selectRange` to drive `selectedRange`. Enables the sweep on
|
|
238
|
+
* its own, so it works without `onCreateEvent`.
|
|
239
|
+
*/
|
|
240
|
+
onSelectDrag?: (start: Date, end: Date) => void;
|
|
241
|
+
/**
|
|
242
|
+
* Enable drag-to-reschedule: **long-press an event bar** and drag it onto
|
|
243
|
+
* another day (**press and drag** on the web). Called on release with the event
|
|
244
|
+
* and its new `start`/`end`, both shifted by the whole days dragged, so the time
|
|
245
|
+
* of day and duration are preserved. Return `false` to reject the drop. Update
|
|
246
|
+
* your own event state in response.
|
|
247
|
+
*/
|
|
248
|
+
onDragEvent?: EventDragHandler<T>;
|
|
249
|
+
/**
|
|
250
|
+
* Fired the instant an event is picked up for a month drag, before anything is
|
|
251
|
+
* committed. Use it for haptic feedback. Inert unless `onDragEvent` is also set.
|
|
252
|
+
*/
|
|
253
|
+
onDragStart?: EventDragStartHandler<T>;
|
|
254
|
+
/** Allow moving events by default (per-event `startEditable` overrides). Default true. */
|
|
255
|
+
eventStartEditable?: boolean;
|
|
256
|
+
/** Reject a drop that would overlap another event (default true = allowed). */
|
|
257
|
+
eventOverlap?: boolean;
|
|
187
258
|
/**
|
|
188
259
|
* Replace the default date badge in each day cell. Receives the day; return
|
|
189
260
|
* your own date label. Event chips and the "+N more" label still render below.
|
|
@@ -221,9 +292,16 @@ function MonthViewInner<T>({
|
|
|
221
292
|
keyExtractor,
|
|
222
293
|
onPressDay,
|
|
223
294
|
onLongPressDay,
|
|
295
|
+
onPressCell,
|
|
224
296
|
onPressEvent,
|
|
225
297
|
onLongPressEvent,
|
|
226
298
|
onPressMore,
|
|
299
|
+
onCreateEvent,
|
|
300
|
+
onSelectDrag,
|
|
301
|
+
onDragEvent,
|
|
302
|
+
onDragStart,
|
|
303
|
+
eventStartEditable = true,
|
|
304
|
+
eventOverlap = true,
|
|
227
305
|
renderCustomDateForMonth,
|
|
228
306
|
onDayPointerDown,
|
|
229
307
|
onDayPointerEnter,
|
|
@@ -245,8 +323,10 @@ function MonthViewInner<T>({
|
|
|
245
323
|
() => withEventAccessibilityLabel(renderEvent, eventAccessibilityLabel, false),
|
|
246
324
|
[renderEvent, eventAccessibilityLabel],
|
|
247
325
|
);
|
|
248
|
-
// Measured grid
|
|
249
|
-
|
|
326
|
+
// Measured grid box: the height auto-fits the event chips per cell, and both
|
|
327
|
+
// dimensions map a drag's position onto a day cell.
|
|
328
|
+
const [gridSize, setGridSize] = useState({ width: 0, height: 0 });
|
|
329
|
+
const gridHeight = gridSize.height;
|
|
250
330
|
// Web-only hover highlight on the day badge (mouse pointers); stays null on
|
|
251
331
|
// touch/native, so it never re-renders there. Mirrors the dom renderer.
|
|
252
332
|
const [hoveredKey, setHoveredKey] = useState<string | null>(null);
|
|
@@ -325,6 +405,202 @@ function MonthViewInner<T>({
|
|
|
325
405
|
[showGrid, weeks, eventsByDay],
|
|
326
406
|
);
|
|
327
407
|
|
|
408
|
+
// ---- drag to create a day span / reschedule an event ----------------------
|
|
409
|
+
const dragEnabled = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
410
|
+
const gridRef = useRef<View>(null);
|
|
411
|
+
// The live drag drives the preview; the ref is what the gesture and the web
|
|
412
|
+
// pointer listeners read, so neither has to be rebuilt as the hover day moves
|
|
413
|
+
// (rebuilding the gesture mid-drag would cancel it).
|
|
414
|
+
const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
|
|
415
|
+
const dragRef = useRef<MonthDrag<T> | null>(null);
|
|
416
|
+
// Whether the pointer has reached a different day than it started on. The web
|
|
417
|
+
// has no long-press to disambiguate, so a create only commits once it moves.
|
|
418
|
+
const movedRef = useRef(false);
|
|
419
|
+
// Web only: a committed drag has to swallow the click the browser fires next,
|
|
420
|
+
// so a reschedule doesn't also open the day (or the event) it landed on.
|
|
421
|
+
const suppressPressRef = useRef(false);
|
|
422
|
+
|
|
423
|
+
const applyDrag = useCallback((next: MonthDrag<T> | null) => {
|
|
424
|
+
dragRef.current = next;
|
|
425
|
+
setDrag(next);
|
|
426
|
+
}, []);
|
|
427
|
+
|
|
428
|
+
// True when this press is the click trailing a just-committed web drag, which
|
|
429
|
+
// the caller should swallow. Clears the flag so only that one press is eaten.
|
|
430
|
+
const consumeSuppressedPress = useCallback(() => {
|
|
431
|
+
if (!suppressPressRef.current) return false;
|
|
432
|
+
suppressPressRef.current = false;
|
|
433
|
+
return true;
|
|
434
|
+
}, []);
|
|
435
|
+
|
|
436
|
+
// `disabled` and `draggable: false` lock an event outright; `startEditable`
|
|
437
|
+
// (per event, falling back to the grid default) allows or blocks a move.
|
|
438
|
+
const canMoveEvent = useCallback(
|
|
439
|
+
(event: CalendarEvent<T>) =>
|
|
440
|
+
!event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable),
|
|
441
|
+
[eventStartEditable],
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
// The day under a grid-relative point, plus the event bar drawn there (if any).
|
|
445
|
+
// Returns null for a point on a blanked adjacent-month cell or an unselectable
|
|
446
|
+
// day, so neither can be a drag's origin or its drop target.
|
|
447
|
+
const hitTest = useCallback(
|
|
448
|
+
(x: number, y: number): { day: Date; event: CalendarEvent<T> | null } | null => {
|
|
449
|
+
const { width, height } = gridSize;
|
|
450
|
+
if (width <= 0 || height <= 0 || weeks.length === 0) return null;
|
|
451
|
+
const rowHeight = height / weeks.length;
|
|
452
|
+
const row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
|
|
453
|
+
const cols = weeks[row].length;
|
|
454
|
+
const col = Math.min(cols - 1, Math.max(0, Math.floor(x / (width / cols))));
|
|
455
|
+
const day = weeks[row][col];
|
|
456
|
+
if (!day) return null;
|
|
457
|
+
if (!showAdjacentMonths && !isSameMonth(day, date)) return null;
|
|
458
|
+
if (!isDateSelectable(day, { minDate, maxDate, isDateDisabled })) return null;
|
|
459
|
+
// Which lane row the point lands on, mirroring the bar overlay's geometry.
|
|
460
|
+
const rowLayout = weekLayouts[row] ?? EMPTY_LAYOUT;
|
|
461
|
+
const lane = Math.floor((y - row * rowHeight - BADGE_AREA) / chipMetrics.chipRowHeight);
|
|
462
|
+
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
463
|
+
const segment =
|
|
464
|
+
lane >= 0 && lane < visibleLanes
|
|
465
|
+
? rowLayout.segments.find((s) => s.lane === lane && s.startCol <= col && s.endCol >= col)
|
|
466
|
+
: undefined;
|
|
467
|
+
return { day, event: segment?.event ?? null };
|
|
468
|
+
},
|
|
469
|
+
[
|
|
470
|
+
gridSize,
|
|
471
|
+
weeks,
|
|
472
|
+
weekLayouts,
|
|
473
|
+
capacity,
|
|
474
|
+
chipMetrics,
|
|
475
|
+
showAdjacentMonths,
|
|
476
|
+
date,
|
|
477
|
+
minDate,
|
|
478
|
+
maxDate,
|
|
479
|
+
isDateDisabled,
|
|
480
|
+
],
|
|
481
|
+
);
|
|
482
|
+
|
|
483
|
+
const beginDrag = useCallback(
|
|
484
|
+
(x: number, y: number) => {
|
|
485
|
+
// A fresh press starts a new interaction, so any guard left over from the
|
|
486
|
+
// previous one (a drag whose trailing click never reached a cell) is stale.
|
|
487
|
+
suppressPressRef.current = false;
|
|
488
|
+
movedRef.current = false;
|
|
489
|
+
const hit = hitTest(x, y);
|
|
490
|
+
if (!hit) return;
|
|
491
|
+
if (hit.event) {
|
|
492
|
+
if (!onDragEvent || !canMoveEvent(hit.event)) return;
|
|
493
|
+
applyDrag({ kind: "move", event: hit.event, from: hit.day, to: hit.day });
|
|
494
|
+
onDragStart?.(hit.event);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (onCreateEvent || onSelectDrag) {
|
|
498
|
+
applyDrag({ kind: "create", anchor: hit.day, hover: hit.day });
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
[hitTest, onDragEvent, onCreateEvent, onSelectDrag, onDragStart, canMoveEvent, applyDrag],
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
const extendDrag = useCallback(
|
|
505
|
+
(x: number, y: number) => {
|
|
506
|
+
const current = dragRef.current;
|
|
507
|
+
if (!current) return;
|
|
508
|
+
const hit = hitTest(x, y);
|
|
509
|
+
if (!hit) return;
|
|
510
|
+
const previous = current.kind === "create" ? current.hover : current.to;
|
|
511
|
+
if (startOfDay(hit.day).getTime() === startOfDay(previous).getTime()) return;
|
|
512
|
+
movedRef.current = true;
|
|
513
|
+
applyDrag(
|
|
514
|
+
current.kind === "create" ? { ...current, hover: hit.day } : { ...current, to: hit.day },
|
|
515
|
+
);
|
|
516
|
+
// A sweep reports its span live, so a selection can track the drag; a move
|
|
517
|
+
// has nothing to report until it is dropped.
|
|
518
|
+
if (current.kind === "create") {
|
|
519
|
+
const a = startOfDay(current.anchor);
|
|
520
|
+
const b = startOfDay(hit.day);
|
|
521
|
+
const [lo, hi] = a.getTime() <= b.getTime() ? [a, b] : [b, a];
|
|
522
|
+
onSelectDrag?.(lo, hi);
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
[hitTest, applyDrag, onSelectDrag],
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
const endDrag = useCallback(() => {
|
|
529
|
+
const current = dragRef.current;
|
|
530
|
+
applyDrag(null);
|
|
531
|
+
if (!current) return;
|
|
532
|
+
if (isWeb) suppressPressRef.current = movedRef.current;
|
|
533
|
+
if (current.kind === "create") {
|
|
534
|
+
// A stationary hold is a deliberate one-day create on native, where the
|
|
535
|
+
// gesture only starts after a long press; on the web it is just a click.
|
|
536
|
+
if (isWeb && !movedRef.current) return;
|
|
537
|
+
const range = monthCreateRange(current.anchor, current.hover);
|
|
538
|
+
onCreateEvent?.(range.start, range.end);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
const next = monthDropBounds(current.event, current.from, current.to);
|
|
542
|
+
if (!next) return;
|
|
543
|
+
// Reject a drop that would land the event on top of another when
|
|
544
|
+
// `eventOverlap` is off, before the consumer's handler ever sees it.
|
|
545
|
+
if (
|
|
546
|
+
eventOverlap === false &&
|
|
547
|
+
overlapsOtherEvents(events, current.event, next.start, next.end)
|
|
548
|
+
) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
onDragEvent?.(current.event, next.start, next.end);
|
|
552
|
+
}, [applyDrag, onCreateEvent, onDragEvent, eventOverlap, events]);
|
|
553
|
+
|
|
554
|
+
// Native: a pan over the grid, held first so it doesn't hijack a tap or the
|
|
555
|
+
// pager's own horizontal swipe.
|
|
556
|
+
const dragGesture = useMemo(() => {
|
|
557
|
+
if (!dragEnabled || isWeb) return undefined;
|
|
558
|
+
return Gesture.Pan()
|
|
559
|
+
.activateAfterLongPress(DRAG_LONG_PRESS_MS)
|
|
560
|
+
.runOnJS(true)
|
|
561
|
+
.onStart((event) => beginDrag(event.x, event.y))
|
|
562
|
+
.onUpdate((event) => extendDrag(event.x, event.y))
|
|
563
|
+
.onEnd((_event, success) => {
|
|
564
|
+
if (success) endDrag();
|
|
565
|
+
})
|
|
566
|
+
.onFinalize(() => {
|
|
567
|
+
if (dragRef.current) applyDrag(null);
|
|
568
|
+
});
|
|
569
|
+
}, [dragEnabled, beginDrag, extendDrag, endDrag, applyDrag]);
|
|
570
|
+
|
|
571
|
+
// Web: the cell touchables swallow the pan above, so drive the same three steps
|
|
572
|
+
// from pointer events on the grid instead. Positions come from the grid's own
|
|
573
|
+
// box, so they line up with the hit test's grid-relative coordinates.
|
|
574
|
+
const gridPoint = useCallback((clientX: number, clientY: number) => {
|
|
575
|
+
const node = gridRef.current as unknown as {
|
|
576
|
+
getBoundingClientRect?: () => { left: number; top: number };
|
|
577
|
+
} | null;
|
|
578
|
+
const rect = node?.getBoundingClientRect?.();
|
|
579
|
+
return rect ? { x: clientX - rect.left, y: clientY - rect.top } : null;
|
|
580
|
+
}, []);
|
|
581
|
+
useEffect(() => {
|
|
582
|
+
if (!isWeb || !dragEnabled) return;
|
|
583
|
+
// A drag can be released anywhere, so commit on the window rather than the grid.
|
|
584
|
+
const up = () => {
|
|
585
|
+
if (dragRef.current) endDrag();
|
|
586
|
+
};
|
|
587
|
+
const target = globalThis as unknown as {
|
|
588
|
+
addEventListener?: (type: string, cb: () => void) => void;
|
|
589
|
+
removeEventListener?: (type: string, cb: () => void) => void;
|
|
590
|
+
};
|
|
591
|
+
target.addEventListener?.("pointerup", up);
|
|
592
|
+
// Let a touch drag sketch a span instead of scrolling the page under it, and
|
|
593
|
+
// stop a sweep from text-selecting the day numbers it passes over.
|
|
594
|
+
const node = gridRef.current as unknown as {
|
|
595
|
+
style?: { touchAction?: string; userSelect?: string };
|
|
596
|
+
} | null;
|
|
597
|
+
if (node?.style) {
|
|
598
|
+
node.style.touchAction = "none";
|
|
599
|
+
node.style.userSelect = "none";
|
|
600
|
+
}
|
|
601
|
+
return () => target.removeEventListener?.("pointerup", up);
|
|
602
|
+
}, [dragEnabled, endDrag]);
|
|
603
|
+
|
|
328
604
|
const renderDay = (
|
|
329
605
|
day: Date,
|
|
330
606
|
dayCol: number,
|
|
@@ -380,6 +656,13 @@ function MonthViewInner<T>({
|
|
|
380
656
|
const hasBand =
|
|
381
657
|
rangeBandKind({ isInRange, isRangeStart, isRangeEnd }, fillCellOnSelection) !== "none";
|
|
382
658
|
const dayKey = day.toISOString();
|
|
659
|
+
// Tint the days a drag is currently over: every day of a create sweep, or the
|
|
660
|
+
// one an event would land on.
|
|
661
|
+
const isDragPreview =
|
|
662
|
+
isInCreateSpan(drag, day) ||
|
|
663
|
+
(drag?.kind === "move" &&
|
|
664
|
+
isSameCalendarDay(day, drag.to) &&
|
|
665
|
+
!isSameCalendarDay(day, drag.from));
|
|
383
666
|
// A hovered, non-filled day gets the subtle badge highlight on the web, but only
|
|
384
667
|
// in the events-free picker. The events calendar (month and list views) has no
|
|
385
668
|
// hover, matching the dom renderer (its events-mode cell omits it).
|
|
@@ -395,7 +678,16 @@ function MonthViewInner<T>({
|
|
|
395
678
|
: theme.colors.textDisabled;
|
|
396
679
|
|
|
397
680
|
// Disabled days ignore taps; pass the guards through so a press never fires.
|
|
398
|
-
|
|
681
|
+
// `onPressCell` receives the same day at midnight, so one handler covers both
|
|
682
|
+
// the month grid and the week/day grid's empty slots.
|
|
683
|
+
const handlePressDay =
|
|
684
|
+
isDisabled || (!onPressDay && !onPressCell)
|
|
685
|
+
? undefined
|
|
686
|
+
: () => {
|
|
687
|
+
if (consumeSuppressedPress()) return;
|
|
688
|
+
onPressDay?.(day);
|
|
689
|
+
onPressCell?.(startOfDay(day));
|
|
690
|
+
};
|
|
399
691
|
const handleLongPressDay =
|
|
400
692
|
isDisabled || !onLongPressDay ? undefined : () => onLongPressDay(day);
|
|
401
693
|
|
|
@@ -416,6 +708,9 @@ function MonthViewInner<T>({
|
|
|
416
708
|
borderColor: theme.colors.gridLine,
|
|
417
709
|
},
|
|
418
710
|
highlightWeekends && isWeekend(day) && { backgroundColor: theme.colors.weekendBackground },
|
|
711
|
+
// The drag preview sits on top of the weekend tint: the span being swept
|
|
712
|
+
// out, or the day an event is about to land on.
|
|
713
|
+
isDragPreview && { backgroundColor: theme.colors.rangeBackground },
|
|
419
714
|
theme.containers.dayCell,
|
|
420
715
|
],
|
|
421
716
|
});
|
|
@@ -440,7 +735,7 @@ function MonthViewInner<T>({
|
|
|
440
735
|
})}
|
|
441
736
|
onPress={handlePressDay}
|
|
442
737
|
onLongPress={handleLongPressDay}
|
|
443
|
-
disabled={isDisabled || (!onPressDay && !onLongPressDay)}
|
|
738
|
+
disabled={isDisabled || (!onPressDay && !onLongPressDay && !onPressCell)}
|
|
444
739
|
// Web only: track hover for the badge highlight, and (when drag-select is
|
|
445
740
|
// wired) relay pointer down/enter so MonthList can extend a range as the
|
|
446
741
|
// pressed pointer sweeps across cells. Native uses a pan, no hover.
|
|
@@ -531,7 +826,9 @@ function MonthViewInner<T>({
|
|
|
531
826
|
})}
|
|
532
827
|
>
|
|
533
828
|
<Text
|
|
534
|
-
{...slot("dayBadgeText", {
|
|
829
|
+
{...slot<TextStyle>("dayBadgeText", {
|
|
830
|
+
themed: [theme.text.dateCell, { color: dateColor }],
|
|
831
|
+
})}
|
|
535
832
|
allowFontScaling={false}
|
|
536
833
|
>
|
|
537
834
|
{format(day, "d")}
|
|
@@ -549,7 +846,7 @@ function MonthViewInner<T>({
|
|
|
549
846
|
))}
|
|
550
847
|
{hiddenCount > 0 ? (
|
|
551
848
|
<Text
|
|
552
|
-
{...slot("more", {
|
|
849
|
+
{...slot<TextStyle>("more", {
|
|
553
850
|
base: styles.moreLabel,
|
|
554
851
|
themed: [theme.text.more, { color: theme.colors.textMuted }],
|
|
555
852
|
})}
|
|
@@ -570,15 +867,17 @@ function MonthViewInner<T>({
|
|
|
570
867
|
};
|
|
571
868
|
|
|
572
869
|
const handleLayout = (event: LayoutChangeEvent) => {
|
|
573
|
-
const
|
|
574
|
-
|
|
870
|
+
const { width, height } = event.nativeEvent.layout;
|
|
871
|
+
setGridSize((prev) =>
|
|
872
|
+
prev.width === width && prev.height === height ? prev : { width, height },
|
|
873
|
+
);
|
|
575
874
|
};
|
|
576
875
|
|
|
577
876
|
return (
|
|
578
877
|
<View style={styles.root}>
|
|
579
878
|
{showTitle ? (
|
|
580
879
|
<Text
|
|
581
|
-
{...slot("title", {
|
|
880
|
+
{...slot<TextStyle>("title", {
|
|
582
881
|
base: styles.title,
|
|
583
882
|
themed: [theme.text.monthTitle, { color: theme.colors.text }],
|
|
584
883
|
})}
|
|
@@ -597,7 +896,7 @@ function MonthViewInner<T>({
|
|
|
597
896
|
{weekdayLabels.map((day) => (
|
|
598
897
|
<Text
|
|
599
898
|
key={day.toISOString()}
|
|
600
|
-
{...slot("weekday", {
|
|
899
|
+
{...slot<TextStyle>("weekday", {
|
|
601
900
|
base: styles.weekdayLabel,
|
|
602
901
|
themed: [theme.text.weekday, { color: theme.colors.textMuted }],
|
|
603
902
|
})}
|
|
@@ -652,79 +951,122 @@ function MonthViewInner<T>({
|
|
|
652
951
|
</Pressable>
|
|
653
952
|
</Modal>
|
|
654
953
|
) : null}
|
|
655
|
-
<
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
954
|
+
<MonthGridSurface gesture={dragGesture}>
|
|
955
|
+
<View
|
|
956
|
+
ref={gridRef}
|
|
957
|
+
testID="month-grid"
|
|
958
|
+
{...slot("grid", { base: styles.container })}
|
|
959
|
+
onLayout={handleLayout}
|
|
960
|
+
{...(isWeb && dragEnabled
|
|
961
|
+
? {
|
|
962
|
+
onPointerDown: (event: RNPointerEvent) => {
|
|
963
|
+
const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
|
|
964
|
+
if (point) beginDrag(point.x, point.y);
|
|
965
|
+
},
|
|
966
|
+
onPointerMove: (event: RNPointerEvent) => {
|
|
967
|
+
if (!dragRef.current) return;
|
|
968
|
+
const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
|
|
969
|
+
if (point) extendDrag(point.x, point.y);
|
|
970
|
+
},
|
|
971
|
+
}
|
|
972
|
+
: null)}
|
|
973
|
+
>
|
|
974
|
+
{weeks.map((week, weekIndex) => {
|
|
975
|
+
// Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
|
|
976
|
+
// event is one bar across its columns, stacked into lanes; the bars render
|
|
977
|
+
// in an overlay so they can span cells, and the cells reserve the lane rows
|
|
978
|
+
// so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
|
|
979
|
+
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
980
|
+
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
981
|
+
const cols = week.length;
|
|
982
|
+
// With adjacent months hidden, clamp bars to the current-month columns so
|
|
983
|
+
// none draw over the blank leading/trailing cells.
|
|
984
|
+
let firstVisCol = 0;
|
|
985
|
+
let lastVisCol = cols - 1;
|
|
986
|
+
if (showGrid && !showAdjacentMonths) {
|
|
987
|
+
const first = week.findIndex((d) => isSameMonth(d, date));
|
|
988
|
+
if (first !== -1) {
|
|
989
|
+
firstVisCol = first;
|
|
990
|
+
lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
|
|
991
|
+
}
|
|
673
992
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
993
|
+
return (
|
|
994
|
+
<View
|
|
995
|
+
{...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
|
|
996
|
+
key={week[0].toISOString()}
|
|
997
|
+
>
|
|
998
|
+
{week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
|
|
999
|
+
{showGrid ? (
|
|
1000
|
+
<View style={[StyleSheet.absoluteFill, { pointerEvents: "box-none" }]}>
|
|
1001
|
+
{rowLayout.segments
|
|
1002
|
+
.filter((seg) => seg.lane < visibleLanes)
|
|
1003
|
+
.map((seg) => {
|
|
1004
|
+
const startCol = Math.max(seg.startCol, firstVisCol);
|
|
1005
|
+
const endCol = Math.min(seg.endCol, lastVisCol);
|
|
1006
|
+
if (startCol > endCol) return null;
|
|
1007
|
+
// Fade the bar being carried, so the tinted drop target reads
|
|
1008
|
+
// as where it is going and this as where it came from.
|
|
1009
|
+
const isDragged = drag?.kind === "move" && drag.event === seg.event;
|
|
1010
|
+
return (
|
|
1011
|
+
<View
|
|
1012
|
+
key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
|
|
1013
|
+
style={{
|
|
1014
|
+
position: "absolute",
|
|
1015
|
+
left: pct((startCol / cols) * 100),
|
|
1016
|
+
width: pct(((endCol - startCol + 1) / cols) * 100),
|
|
1017
|
+
top: BADGE_AREA + seg.lane * chipMetrics.chipRowHeight,
|
|
1018
|
+
height: chipMetrics.chipHeight,
|
|
1019
|
+
paddingHorizontal: CHIP_INSET_H,
|
|
1020
|
+
// Let a sweep in progress reach the cells underneath.
|
|
1021
|
+
pointerEvents: drag ? "none" : "box-none",
|
|
1022
|
+
opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
|
|
1023
|
+
}}
|
|
1024
|
+
>
|
|
1025
|
+
<RenderEventComponent
|
|
1026
|
+
event={seg.event}
|
|
1027
|
+
mode="month"
|
|
1028
|
+
isAllDay={isAllDayEvent(seg.event)}
|
|
1029
|
+
onPress={
|
|
1030
|
+
disableMonthEventCellPress
|
|
1031
|
+
? () => {}
|
|
1032
|
+
: () => {
|
|
1033
|
+
if (consumeSuppressedPress()) return;
|
|
1034
|
+
onPressEvent(seg.event);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
onLongPress={
|
|
1038
|
+
disableMonthEventCellPress || !onLongPressEvent
|
|
1039
|
+
? undefined
|
|
1040
|
+
: () => onLongPressEvent(seg.event)
|
|
1041
|
+
}
|
|
1042
|
+
/>
|
|
1043
|
+
</View>
|
|
1044
|
+
);
|
|
1045
|
+
})}
|
|
1046
|
+
</View>
|
|
1047
|
+
) : null}
|
|
1048
|
+
</View>
|
|
1049
|
+
);
|
|
1050
|
+
})}
|
|
1051
|
+
</View>
|
|
1052
|
+
</MonthGridSurface>
|
|
724
1053
|
</View>
|
|
725
1054
|
);
|
|
726
1055
|
}
|
|
727
1056
|
|
|
1057
|
+
// The grid, wrapped in a GestureDetector only when a month drag is wired up, so
|
|
1058
|
+
// the picker (and any month without drag handlers) mounts no gesture at all.
|
|
1059
|
+
function MonthGridSurface({
|
|
1060
|
+
gesture,
|
|
1061
|
+
children,
|
|
1062
|
+
}: {
|
|
1063
|
+
gesture?: ReturnType<typeof Gesture.Pan>;
|
|
1064
|
+
children: ReactElement;
|
|
1065
|
+
}): ReactElement {
|
|
1066
|
+
if (!gesture) return children;
|
|
1067
|
+
return <GestureDetector gesture={gesture}>{children}</GestureDetector>;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
728
1070
|
/**
|
|
729
1071
|
* A single month rendered as a 7-column grid of day cells, each showing its
|
|
730
1072
|
* event chips with a "+N more" overflow. Render it on its own for a static
|