@super-calendar/native 2.15.0 → 2.17.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 +63 -0
- package/dist/{DefaultMonthEvent-BDD7GgL8.d.mts → DefaultMonthEvent-C3C30hfV.d.mts} +7 -21
- package/dist/{DefaultMonthEvent-ggwYo7Fy.d.ts → DefaultMonthEvent-Dx3lD7ig.d.ts} +7 -21
- package/dist/{MonthList-D4_LBnbU.js → MonthList-B2TSGYp7.js} +409 -109
- package/dist/{MonthList-DWCH3GT5.mjs → MonthList-N1GVDIE4.mjs} +400 -112
- package/dist/index.d.mts +50 -16
- package/dist/index.d.ts +50 -16
- package/dist/index.js +375 -46
- package/dist/index.mjs +370 -47
- 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/Calendar.tsx +83 -9
- package/src/components/MonthPager.tsx +175 -20
- package/src/components/MonthView.tsx +332 -116
- package/src/components/MultiWeekView.tsx +34 -0
- package/src/components/ResourceTimeline.tsx +153 -4
- package/src/components/TimeGrid.tsx +241 -7
- package/src/index.tsx +8 -0
- package/src/types.ts +1 -0
- package/src/utils/holdWebDateDrag.ts +63 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { format, type Locale, isSameMonth, startOfDay } from "date-fns";
|
|
1
|
+
import { addDays, format, type Locale, isSameMonth, startOfDay } from "date-fns";
|
|
2
2
|
import {
|
|
3
3
|
type ComponentRef,
|
|
4
4
|
memo,
|
|
@@ -41,6 +41,7 @@ import type {
|
|
|
41
41
|
} from "../types";
|
|
42
42
|
import { createSlots, type SlotStyleProps } from "../utils/slots";
|
|
43
43
|
import { withEventAccessibilityLabel } from "../utils/withEventAccessibilityLabel";
|
|
44
|
+
import { holdWebDateDrag } from "../utils/holdWebDateDrag";
|
|
44
45
|
import { CalendarLabelsContext } from "../utils/labels";
|
|
45
46
|
import {
|
|
46
47
|
type CalendarLabels,
|
|
@@ -57,6 +58,7 @@ import {
|
|
|
57
58
|
import { dayBadgeKind, rangeBandKind } from "@super-calendar/core";
|
|
58
59
|
import {
|
|
59
60
|
buildMonthWeeks,
|
|
61
|
+
buildMultiWeekGrid,
|
|
60
62
|
getIsToday,
|
|
61
63
|
filterHiddenDays,
|
|
62
64
|
getWeekDays,
|
|
@@ -279,8 +281,41 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
|
|
|
279
281
|
renderCustomDateForMonth?: (date: Date) => React.ReactNode;
|
|
280
282
|
};
|
|
281
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Which rows a {@link DateRows} grid shows. Internal to the package: the public
|
|
286
|
+
* views and pagers adapt their own props to it.
|
|
287
|
+
*/
|
|
288
|
+
export type DateRowsSource =
|
|
289
|
+
| {
|
|
290
|
+
kind: "month";
|
|
291
|
+
/** Any day within the month to render. */
|
|
292
|
+
date: Date;
|
|
293
|
+
showAdjacentMonths: boolean;
|
|
294
|
+
showSixWeeks: boolean;
|
|
295
|
+
}
|
|
296
|
+
| { kind: "multiweek"; date: Date; numberOfWeeks: number };
|
|
297
|
+
|
|
298
|
+
/** Props for the private {@link DateRows} grid shared by the public row views. */
|
|
299
|
+
export type DateRowsProps<T> = Omit<
|
|
300
|
+
MonthViewProps<T>,
|
|
301
|
+
"date" | "showAdjacentMonths" | "showSixWeeks"
|
|
302
|
+
> & { source: DateRowsSource };
|
|
303
|
+
|
|
282
304
|
function MonthViewInner<T>({
|
|
283
305
|
date,
|
|
306
|
+
showAdjacentMonths = true,
|
|
307
|
+
showSixWeeks = false,
|
|
308
|
+
...rest
|
|
309
|
+
}: MonthViewProps<T>): ReactElement {
|
|
310
|
+
const source = useMemo<DateRowsSource>(
|
|
311
|
+
() => ({ kind: "month", date, showAdjacentMonths, showSixWeeks }),
|
|
312
|
+
[date, showAdjacentMonths, showSixWeeks],
|
|
313
|
+
);
|
|
314
|
+
return <DateRows<T> {...rest} source={source} />;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function DateRowsInner<T>({
|
|
318
|
+
source,
|
|
284
319
|
events,
|
|
285
320
|
maxVisibleEventCount,
|
|
286
321
|
chipHeight,
|
|
@@ -292,11 +327,9 @@ function MonthViewInner<T>({
|
|
|
292
327
|
sortedMonthView = true,
|
|
293
328
|
moreLabel = "{moreCount} More",
|
|
294
329
|
labels: labelsProp,
|
|
295
|
-
showAdjacentMonths = true,
|
|
296
330
|
highlightWeekends = true,
|
|
297
331
|
disableMonthEventCellPress = false,
|
|
298
332
|
isRTL = false,
|
|
299
|
-
showSixWeeks = false,
|
|
300
333
|
showTitle = true,
|
|
301
334
|
showWeekdays = true,
|
|
302
335
|
activeDate,
|
|
@@ -327,7 +360,12 @@ function MonthViewInner<T>({
|
|
|
327
360
|
onDayPointerEnter,
|
|
328
361
|
classNames,
|
|
329
362
|
styles: styleOverrides,
|
|
330
|
-
}:
|
|
363
|
+
}: DateRowsProps<T>): ReactElement {
|
|
364
|
+
const { date } = source;
|
|
365
|
+
const multiWeek = source.kind === "multiweek";
|
|
366
|
+
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
367
|
+
const showSixWeeks = source.kind === "month" ? source.showSixWeeks : false;
|
|
368
|
+
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : undefined;
|
|
331
369
|
const theme = useCalendarTheme();
|
|
332
370
|
const badgeArea = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT + chipGap;
|
|
333
371
|
const slot = createSlots<MonthViewSlot>({ classNames, styles: styleOverrides });
|
|
@@ -362,10 +400,26 @@ function MonthViewInner<T>({
|
|
|
362
400
|
events: CalendarEvent<T>[];
|
|
363
401
|
} | null>(null);
|
|
364
402
|
|
|
403
|
+
const multiWeekGrid = useMemo(
|
|
404
|
+
() =>
|
|
405
|
+
numberOfWeeks === undefined
|
|
406
|
+
? null
|
|
407
|
+
: buildMultiWeekGrid(date, { numberOfWeeks, weekStartsOn, isRTL, hiddenDays }),
|
|
408
|
+
[date, numberOfWeeks, weekStartsOn, isRTL, hiddenDays],
|
|
409
|
+
);
|
|
365
410
|
const weeks = useMemo(
|
|
366
|
-
() =>
|
|
367
|
-
|
|
411
|
+
() =>
|
|
412
|
+
multiWeekGrid
|
|
413
|
+
? multiWeekGrid.weeks.map((week) => week.days.map((day) => day.date))
|
|
414
|
+
: buildMonthWeeks(date, weekStartsOn, { showSixWeeks, isRTL, hiddenDays }),
|
|
415
|
+
[multiWeekGrid, date, weekStartsOn, isRTL, showSixWeeks, hiddenDays],
|
|
368
416
|
);
|
|
417
|
+
const title = multiWeekGrid
|
|
418
|
+
? `${format(multiWeekGrid.visibleRange.start, "PP", { locale })} – ${format(addDays(multiWeekGrid.visibleRange.endExclusive, -1), "PP", { locale })}`
|
|
419
|
+
: format(date, "MMMM yyyy", { locale });
|
|
420
|
+
const windowKey = multiWeekGrid
|
|
421
|
+
? `${multiWeekGrid.period.start.getTime()}:${numberOfWeeks}:${hiddenDays?.join(",")}:${isRTL}`
|
|
422
|
+
: null;
|
|
369
423
|
|
|
370
424
|
// Weekday labels for the header row (any week works; reuse this month). Reversed
|
|
371
425
|
// in RTL so they line up with the mirrored day columns.
|
|
@@ -383,6 +437,9 @@ function MonthViewInner<T>({
|
|
|
383
437
|
const height = chipHeight ?? lineHeight + CHIP_PADDING_V * 2;
|
|
384
438
|
return { chipHeight: height, chipRowHeight: height + chipGap };
|
|
385
439
|
}, [theme, chipHeight, chipGap]);
|
|
440
|
+
const minimumRowHeight =
|
|
441
|
+
badgeArea +
|
|
442
|
+
Math.max(1, maxVisibleEventCount ?? FALLBACK_VISIBLE_COUNT) * chipMetrics.chipRowHeight;
|
|
386
443
|
|
|
387
444
|
// How many chips fit per cell: a fixed cap when `maxVisibleEventCount` is set,
|
|
388
445
|
// else derived from the measured cell height and the (default) chip metrics.
|
|
@@ -416,7 +473,7 @@ function MonthViewInner<T>({
|
|
|
416
473
|
|
|
417
474
|
// Draw the day-cell grid only for an events calendar; the events-free date
|
|
418
475
|
// picker reads cleaner without it (matching the dom renderer).
|
|
419
|
-
const showGrid = events.length > 0;
|
|
476
|
+
const showGrid = multiWeek || events.length > 0;
|
|
420
477
|
|
|
421
478
|
// Lay out each week row's spanning bars once per data change, not per render.
|
|
422
479
|
const weekLayouts = useMemo(
|
|
@@ -430,11 +487,23 @@ function MonthViewInner<T>({
|
|
|
430
487
|
// ---- drag to create a day span / reschedule an event ----------------------
|
|
431
488
|
const dragEnabled = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
432
489
|
const gridRef = useRef<ComponentRef<typeof View>>(null);
|
|
490
|
+
const heldTouch = useRef<(() => void) | null>(null);
|
|
491
|
+
const heldOrigin = useRef<{ day: Date; event: CalendarEvent<T> | null } | null>(null);
|
|
433
492
|
// The live drag drives the preview; the ref is what the gesture and the web
|
|
434
493
|
// pointer listeners read, so neither has to be rebuilt as the hover day moves
|
|
435
494
|
// (rebuilding the gesture mid-drag would cancel it).
|
|
436
495
|
const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
|
|
437
496
|
const dragRef = useRef<MonthDrag<T> | null>(null);
|
|
497
|
+
const interactionWindow = useRef(windowKey);
|
|
498
|
+
interactionWindow.current = windowKey;
|
|
499
|
+
const mounted = useRef(true);
|
|
500
|
+
useEffect(() => {
|
|
501
|
+
mounted.current = true;
|
|
502
|
+
return () => {
|
|
503
|
+
mounted.current = false;
|
|
504
|
+
dragRef.current = null;
|
|
505
|
+
};
|
|
506
|
+
}, []);
|
|
438
507
|
// Whether the pointer has reached a different day than it started on. The web
|
|
439
508
|
// has no long-press to disambiguate, so a create only commits once it moves.
|
|
440
509
|
const movedRef = useRef(false);
|
|
@@ -446,6 +515,20 @@ function MonthViewInner<T>({
|
|
|
446
515
|
dragRef.current = next;
|
|
447
516
|
setDrag(next);
|
|
448
517
|
}, []);
|
|
518
|
+
useEffect(() => {
|
|
519
|
+
if (windowKey === null) return;
|
|
520
|
+
applyDrag(null);
|
|
521
|
+
setMoreOpenFor(null);
|
|
522
|
+
return () => {
|
|
523
|
+
dragRef.current = null;
|
|
524
|
+
};
|
|
525
|
+
}, [windowKey, applyDrag]);
|
|
526
|
+
useEffect(
|
|
527
|
+
() => () => {
|
|
528
|
+
heldTouch.current?.();
|
|
529
|
+
},
|
|
530
|
+
[windowKey],
|
|
531
|
+
);
|
|
449
532
|
|
|
450
533
|
// True when this press is the click trailing a just-committed web drag, which
|
|
451
534
|
// the caller should swallow. Clears the flag so only that one press is eaten.
|
|
@@ -462,6 +545,28 @@ function MonthViewInner<T>({
|
|
|
462
545
|
!event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable),
|
|
463
546
|
[eventStartEditable],
|
|
464
547
|
);
|
|
548
|
+
// Live selection can rerender its parent during a held web gesture. Callback
|
|
549
|
+
// identity changes do not invalidate a still-selectable day or movable event.
|
|
550
|
+
useEffect(() => {
|
|
551
|
+
const origin = heldOrigin.current;
|
|
552
|
+
if (!origin) return;
|
|
553
|
+
const current = dragRef.current;
|
|
554
|
+
const destination = current
|
|
555
|
+
? current.kind === "create"
|
|
556
|
+
? current.hover
|
|
557
|
+
: current.to
|
|
558
|
+
: origin.day;
|
|
559
|
+
const constraints = { minDate, maxDate, isDateDisabled };
|
|
560
|
+
if (
|
|
561
|
+
!isDateSelectable(origin.day, constraints) ||
|
|
562
|
+
!isDateSelectable(destination, constraints) ||
|
|
563
|
+
(origin.event
|
|
564
|
+
? !onDragEvent || !events.includes(origin.event) || !canMoveEvent(origin.event)
|
|
565
|
+
: !onCreateEvent && !onSelectDrag)
|
|
566
|
+
) {
|
|
567
|
+
heldTouch.current?.();
|
|
568
|
+
}
|
|
569
|
+
});
|
|
465
570
|
|
|
466
571
|
// The day under a grid-relative point, plus the event bar drawn there (if any).
|
|
467
572
|
// Returns null for a point on a blanked adjacent-month cell or an unselectable
|
|
@@ -504,12 +609,19 @@ function MonthViewInner<T>({
|
|
|
504
609
|
);
|
|
505
610
|
|
|
506
611
|
const beginDrag = useCallback(
|
|
507
|
-
(x: number, y: number) => {
|
|
612
|
+
(x: number, y: number, origin?: { day: Date; event: CalendarEvent<T> | null }) => {
|
|
613
|
+
if (!mounted.current || (multiWeek && interactionWindow.current !== windowKey)) return;
|
|
614
|
+
if (
|
|
615
|
+
origin &&
|
|
616
|
+
(!isDateSelectable(origin.day, { minDate, maxDate, isDateDisabled }) ||
|
|
617
|
+
(origin.event && !events.includes(origin.event)))
|
|
618
|
+
)
|
|
619
|
+
return;
|
|
508
620
|
// A fresh press starts a new interaction, so any guard left over from the
|
|
509
621
|
// previous one (a drag whose trailing click never reached a cell) is stale.
|
|
510
622
|
suppressPressRef.current = false;
|
|
511
623
|
movedRef.current = false;
|
|
512
|
-
const hit = hitTest(x, y);
|
|
624
|
+
const hit = origin ?? hitTest(x, y);
|
|
513
625
|
if (!hit) return;
|
|
514
626
|
if (hit.event) {
|
|
515
627
|
if (!onDragEvent || !canMoveEvent(hit.event)) return;
|
|
@@ -521,7 +633,21 @@ function MonthViewInner<T>({
|
|
|
521
633
|
applyDrag({ kind: "create", anchor: hit.day, hover: hit.day });
|
|
522
634
|
}
|
|
523
635
|
},
|
|
524
|
-
[
|
|
636
|
+
[
|
|
637
|
+
hitTest,
|
|
638
|
+
onDragEvent,
|
|
639
|
+
onCreateEvent,
|
|
640
|
+
onSelectDrag,
|
|
641
|
+
onDragStart,
|
|
642
|
+
canMoveEvent,
|
|
643
|
+
applyDrag,
|
|
644
|
+
multiWeek,
|
|
645
|
+
windowKey,
|
|
646
|
+
minDate,
|
|
647
|
+
maxDate,
|
|
648
|
+
isDateDisabled,
|
|
649
|
+
events,
|
|
650
|
+
],
|
|
525
651
|
);
|
|
526
652
|
|
|
527
653
|
const extendDrag = useCallback(
|
|
@@ -612,17 +738,63 @@ function MonthViewInner<T>({
|
|
|
612
738
|
removeEventListener?: (type: string, cb: () => void) => void;
|
|
613
739
|
};
|
|
614
740
|
target.addEventListener?.("pointerup", up);
|
|
615
|
-
//
|
|
616
|
-
// stop a sweep from text-selecting the day numbers it passes over.
|
|
741
|
+
// Multi-week touch input scrolls until a hold takes ownership of the drag.
|
|
617
742
|
const node = gridRef.current as unknown as {
|
|
618
743
|
style?: { touchAction?: string; userSelect?: string };
|
|
619
744
|
} | null;
|
|
620
745
|
if (node?.style) {
|
|
621
|
-
node.style.touchAction = "none";
|
|
746
|
+
node.style.touchAction = multiWeek ? "pan-y" : "none";
|
|
622
747
|
node.style.userSelect = "none";
|
|
623
748
|
}
|
|
624
749
|
return () => target.removeEventListener?.("pointerup", up);
|
|
625
|
-
}, [dragEnabled, endDrag]);
|
|
750
|
+
}, [dragEnabled, endDrag, multiWeek]);
|
|
751
|
+
|
|
752
|
+
const webDragHandlers = useRef({ beginDrag, extendDrag });
|
|
753
|
+
webDragHandlers.current = { beginDrag, extendDrag };
|
|
754
|
+
const pressWebGrid = (event: RNPointerEvent) => {
|
|
755
|
+
const pointer = event.nativeEvent;
|
|
756
|
+
if (multiWeek && (pointer.button !== 0 || pointer.isPrimary === false || heldTouch.current))
|
|
757
|
+
return;
|
|
758
|
+
if (multiWeek) suppressPressRef.current = false;
|
|
759
|
+
const start = () => {
|
|
760
|
+
const point = gridPoint(pointer.clientX, pointer.clientY);
|
|
761
|
+
if (point) webDragHandlers.current.beginDrag(point.x, point.y);
|
|
762
|
+
};
|
|
763
|
+
if (!multiWeek || !pointer.pointerType || pointer.pointerType === "mouse") {
|
|
764
|
+
start();
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
// A native View ref is the host HTMLElement only on react-native-web.
|
|
768
|
+
const node = gridRef.current as unknown as HTMLElement | null;
|
|
769
|
+
if (!node) return;
|
|
770
|
+
const point = gridPoint(pointer.clientX, pointer.clientY);
|
|
771
|
+
if (!point) return;
|
|
772
|
+
const origin = hitTest(point.x, point.y);
|
|
773
|
+
if (!origin) return;
|
|
774
|
+
heldOrigin.current = origin;
|
|
775
|
+
heldTouch.current = holdWebDateDrag(
|
|
776
|
+
node,
|
|
777
|
+
pointer,
|
|
778
|
+
() => {
|
|
779
|
+
// Lane layout can change during the delay without removing the pressed
|
|
780
|
+
// event. Keep the original day/event instead of hit-testing again.
|
|
781
|
+
if (interactionWindow.current === windowKey)
|
|
782
|
+
webDragHandlers.current.beginDrag(point.x, point.y, origin);
|
|
783
|
+
},
|
|
784
|
+
(x, y) => {
|
|
785
|
+
const point = gridPoint(x, y);
|
|
786
|
+
if (point) webDragHandlers.current.extendDrag(point.x, point.y);
|
|
787
|
+
},
|
|
788
|
+
() => {
|
|
789
|
+
applyDrag(null);
|
|
790
|
+
movedRef.current = false;
|
|
791
|
+
},
|
|
792
|
+
() => {
|
|
793
|
+
heldTouch.current = null;
|
|
794
|
+
heldOrigin.current = null;
|
|
795
|
+
},
|
|
796
|
+
);
|
|
797
|
+
};
|
|
626
798
|
|
|
627
799
|
const renderDay = (
|
|
628
800
|
day: Date,
|
|
@@ -630,7 +802,7 @@ function MonthViewInner<T>({
|
|
|
630
802
|
rowLayout: MonthWeekEvents<T>,
|
|
631
803
|
visibleLanes: number,
|
|
632
804
|
) => {
|
|
633
|
-
const isCurrentMonth = isSameMonth(day, date);
|
|
805
|
+
const isCurrentMonth = multiWeek || isSameMonth(day, date);
|
|
634
806
|
|
|
635
807
|
// Blank out adjacent-month days when they're hidden, keeping the grid shape.
|
|
636
808
|
if (!isCurrentMonth && !showAdjacentMonths) {
|
|
@@ -914,7 +1086,7 @@ function MonthViewInner<T>({
|
|
|
914
1086
|
})}
|
|
915
1087
|
allowFontScaling={false}
|
|
916
1088
|
>
|
|
917
|
-
{
|
|
1089
|
+
{title}
|
|
918
1090
|
</Text>
|
|
919
1091
|
) : null}
|
|
920
1092
|
{showWeekdays ? (
|
|
@@ -973,7 +1145,7 @@ function MonthViewInner<T>({
|
|
|
973
1145
|
<View key={keyExtractor(event, index)} style={styles.moreCardRow}>
|
|
974
1146
|
<RenderEventComponent
|
|
975
1147
|
event={event}
|
|
976
|
-
mode="month"
|
|
1148
|
+
mode={multiWeek ? "multiweek" : "month"}
|
|
977
1149
|
isAllDay={isAllDayEvent(event)}
|
|
978
1150
|
onPress={() => {
|
|
979
1151
|
setMoreOpenFor(null);
|
|
@@ -987,111 +1159,146 @@ function MonthViewInner<T>({
|
|
|
987
1159
|
</Pressable>
|
|
988
1160
|
</Modal>
|
|
989
1161
|
) : null}
|
|
990
|
-
<
|
|
991
|
-
<
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1162
|
+
<DateRowsViewport scrollable={multiWeek}>
|
|
1163
|
+
<MonthGridSurface gesture={dragGesture}>
|
|
1164
|
+
<View
|
|
1165
|
+
ref={gridRef}
|
|
1166
|
+
testID={multiWeek ? "multiweek-grid" : "month-grid"}
|
|
1167
|
+
accessibilityLabel={multiWeek ? title : undefined}
|
|
1168
|
+
{...slot("grid", {
|
|
1169
|
+
base: [
|
|
1170
|
+
styles.container,
|
|
1171
|
+
multiWeek ? { minHeight: minimumRowHeight * weeks.length } : undefined,
|
|
1172
|
+
],
|
|
1173
|
+
})}
|
|
1174
|
+
onLayout={handleLayout}
|
|
1175
|
+
{...(isWeb && dragEnabled
|
|
1176
|
+
? {
|
|
1177
|
+
onPointerDown: pressWebGrid,
|
|
1178
|
+
onPointerMove: (event: RNPointerEvent) => {
|
|
1179
|
+
if (heldTouch.current) return;
|
|
1180
|
+
if (!dragRef.current) return;
|
|
1181
|
+
const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
|
|
1182
|
+
if (point) extendDrag(point.x, point.y);
|
|
1183
|
+
},
|
|
1184
|
+
}
|
|
1185
|
+
: null)}
|
|
1186
|
+
>
|
|
1187
|
+
{weeks.map((week, weekIndex) => {
|
|
1188
|
+
// Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
|
|
1189
|
+
// event is one bar across its columns, stacked into lanes; the bars render
|
|
1190
|
+
// in an overlay so they can span cells, and the cells reserve the lane rows
|
|
1191
|
+
// so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
|
|
1192
|
+
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
1193
|
+
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
1194
|
+
const cols = week.length;
|
|
1195
|
+
// With adjacent months hidden, clamp bars to the current-month columns so
|
|
1196
|
+
// none draw over the blank leading/trailing cells.
|
|
1197
|
+
let firstVisCol = 0;
|
|
1198
|
+
let lastVisCol = cols - 1;
|
|
1199
|
+
if (showGrid && !showAdjacentMonths) {
|
|
1200
|
+
const first = week.findIndex((d) => isSameMonth(d, date));
|
|
1201
|
+
if (first !== -1) {
|
|
1202
|
+
firstVisCol = first;
|
|
1203
|
+
lastVisCol =
|
|
1204
|
+
cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
|
|
1205
|
+
}
|
|
1028
1206
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
?
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1207
|
+
return (
|
|
1208
|
+
<View
|
|
1209
|
+
{...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
|
|
1210
|
+
key={multiWeekGrid?.weeks[weekIndex].id ?? week[0].toISOString()}
|
|
1211
|
+
>
|
|
1212
|
+
{week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
|
|
1213
|
+
{showGrid ? (
|
|
1214
|
+
<View
|
|
1215
|
+
style={[
|
|
1216
|
+
StyleSheet.absoluteFill,
|
|
1217
|
+
multiWeek
|
|
1218
|
+
? styles.childrenOnlyPointerEvents
|
|
1219
|
+
: { pointerEvents: "box-none" },
|
|
1220
|
+
]}
|
|
1221
|
+
>
|
|
1222
|
+
{rowLayout.segments
|
|
1223
|
+
.filter((seg) => seg.lane < visibleLanes)
|
|
1224
|
+
.map((seg) => {
|
|
1225
|
+
const startCol = Math.max(seg.startCol, firstVisCol);
|
|
1226
|
+
const endCol = Math.min(seg.endCol, lastVisCol);
|
|
1227
|
+
if (startCol > endCol) return null;
|
|
1228
|
+
// Fade the bar being carried, so the tinted drop target reads
|
|
1229
|
+
// as where it is going and this as where it came from.
|
|
1230
|
+
const isDragged = drag?.kind === "move" && drag.event === seg.event;
|
|
1231
|
+
return (
|
|
1232
|
+
<View
|
|
1233
|
+
key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
|
|
1234
|
+
style={[
|
|
1235
|
+
{
|
|
1236
|
+
position: "absolute",
|
|
1237
|
+
left: pct((startCol / cols) * 100),
|
|
1238
|
+
width: pct(((endCol - startCol + 1) / cols) * 100),
|
|
1239
|
+
top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
|
|
1240
|
+
height: chipMetrics.chipHeight,
|
|
1241
|
+
paddingHorizontal: CHIP_INSET_H,
|
|
1242
|
+
// Let a sweep in progress reach the cells underneath.
|
|
1243
|
+
opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
|
|
1244
|
+
},
|
|
1245
|
+
multiWeek
|
|
1246
|
+
? drag
|
|
1247
|
+
? styles.noPointerEvents
|
|
1248
|
+
: styles.childrenOnlyPointerEvents
|
|
1249
|
+
: { pointerEvents: drag ? "none" : "box-none" },
|
|
1250
|
+
]}
|
|
1251
|
+
>
|
|
1252
|
+
<RenderEventComponent
|
|
1253
|
+
event={seg.event}
|
|
1254
|
+
mode={multiWeek ? "multiweek" : "month"}
|
|
1255
|
+
isAllDay={isAllDayEvent(seg.event)}
|
|
1256
|
+
onPress={
|
|
1257
|
+
disableMonthEventCellPress
|
|
1258
|
+
? () => {}
|
|
1259
|
+
: () => {
|
|
1260
|
+
if (consumeSuppressedPress()) return;
|
|
1261
|
+
onPressEvent(seg.event);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
onLongPress={
|
|
1265
|
+
disableMonthEventCellPress || !onLongPressEvent
|
|
1266
|
+
? undefined
|
|
1267
|
+
: () => onLongPressEvent(seg.event)
|
|
1268
|
+
}
|
|
1269
|
+
/>
|
|
1270
|
+
</View>
|
|
1271
|
+
);
|
|
1272
|
+
})}
|
|
1273
|
+
</View>
|
|
1274
|
+
) : null}
|
|
1275
|
+
</View>
|
|
1276
|
+
);
|
|
1277
|
+
})}
|
|
1278
|
+
</View>
|
|
1279
|
+
</MonthGridSurface>
|
|
1280
|
+
</DateRowsViewport>
|
|
1090
1281
|
</View>
|
|
1091
1282
|
</CalendarLabelsContext.Provider>
|
|
1092
1283
|
);
|
|
1093
1284
|
}
|
|
1094
1285
|
|
|
1286
|
+
function DateRowsViewport({
|
|
1287
|
+
scrollable,
|
|
1288
|
+
children,
|
|
1289
|
+
}: {
|
|
1290
|
+
scrollable: boolean;
|
|
1291
|
+
children: ReactElement;
|
|
1292
|
+
}): ReactElement {
|
|
1293
|
+
return scrollable ? (
|
|
1294
|
+
<ScrollView style={styles.container} contentContainerStyle={{ flexGrow: 1 }}>
|
|
1295
|
+
{children}
|
|
1296
|
+
</ScrollView>
|
|
1297
|
+
) : (
|
|
1298
|
+
children
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1095
1302
|
// The grid, wrapped in a GestureDetector only when a month drag is wired up, so
|
|
1096
1303
|
// the picker (and any month without drag handlers) mounts no gesture at all.
|
|
1097
1304
|
function MonthGridSurface({
|
|
@@ -1123,6 +1330,12 @@ function MonthGridSurface({
|
|
|
1123
1330
|
*/
|
|
1124
1331
|
export const MonthView = memo(MonthViewInner) as typeof MonthViewInner;
|
|
1125
1332
|
|
|
1333
|
+
/**
|
|
1334
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
1335
|
+
* spanning event bars, overflow, selection, and drag handling.
|
|
1336
|
+
*/
|
|
1337
|
+
export const DateRows = memo(DateRowsInner) as typeof DateRowsInner;
|
|
1338
|
+
|
|
1126
1339
|
const styles = StyleSheet.create({
|
|
1127
1340
|
root: {
|
|
1128
1341
|
flex: 1,
|
|
@@ -1144,6 +1357,9 @@ const styles = StyleSheet.create({
|
|
|
1144
1357
|
container: {
|
|
1145
1358
|
flex: 1,
|
|
1146
1359
|
},
|
|
1360
|
+
// react-native-web needs registered styles to expand the child rules for box-none.
|
|
1361
|
+
childrenOnlyPointerEvents: { pointerEvents: "box-none" },
|
|
1362
|
+
noPointerEvents: { pointerEvents: "none" },
|
|
1147
1363
|
weekRow: {
|
|
1148
1364
|
flex: 1,
|
|
1149
1365
|
flexDirection: "row",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactElement, useMemo } from "react";
|
|
2
|
+
import { type WeekStartsOn } from "@super-calendar/core";
|
|
3
|
+
import { DateRows, type DateRowsSource, type MonthViewProps } from "./MonthView";
|
|
4
|
+
|
|
5
|
+
/** Props for the consecutive full-week event grid. */
|
|
6
|
+
export type MultiWeekViewProps<T = unknown> = Omit<
|
|
7
|
+
MonthViewProps<T>,
|
|
8
|
+
"date" | "weekStartsOn" | "showSixWeeks" | "showAdjacentMonths"
|
|
9
|
+
> & {
|
|
10
|
+
/** Any day in the first displayed week. */
|
|
11
|
+
date: Date;
|
|
12
|
+
/** Positive whole number of week rows (default 2). Invalid values throw RangeError. */
|
|
13
|
+
numberOfWeeks?: number;
|
|
14
|
+
/** First weekday, Sunday = 0 (default). */
|
|
15
|
+
weekStartsOn?: WeekStartsOn;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Consecutive full weeks with event bars and no hourly slots. Rows scroll
|
|
20
|
+
* vertically when they cannot fit. Expand recurring events before passing them,
|
|
21
|
+
* or use Calendar with mode="multiweek" for recurrence and swipe paging.
|
|
22
|
+
*/
|
|
23
|
+
export function MultiWeekView<T = unknown>({
|
|
24
|
+
date,
|
|
25
|
+
numberOfWeeks = 2,
|
|
26
|
+
weekStartsOn = 0,
|
|
27
|
+
...rest
|
|
28
|
+
}: MultiWeekViewProps<T>): ReactElement {
|
|
29
|
+
const source = useMemo<DateRowsSource>(
|
|
30
|
+
() => ({ kind: "multiweek", date, numberOfWeeks }),
|
|
31
|
+
[date, numberOfWeeks],
|
|
32
|
+
);
|
|
33
|
+
return <DateRows {...rest} source={source} weekStartsOn={weekStartsOn} />;
|
|
34
|
+
}
|