@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,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentType, ReactElement, ReactNode } from "react";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import {
|
|
4
4
|
type AccessibilityActionEvent,
|
|
5
5
|
type GestureResponderEvent,
|
|
@@ -20,6 +20,7 @@ import Animated, {
|
|
|
20
20
|
import {
|
|
21
21
|
backgroundBandsForDay,
|
|
22
22
|
type CalendarEvent,
|
|
23
|
+
type CreateGhostArgs,
|
|
23
24
|
cellRangeFromDrag,
|
|
24
25
|
isSameCalendarDay,
|
|
25
26
|
useNow,
|
|
@@ -148,6 +149,17 @@ export interface ResourceTimelineProps<T = unknown> {
|
|
|
148
149
|
* event; called with the swept start/end and the lane's resource.
|
|
149
150
|
*/
|
|
150
151
|
onCreateEvent?: (start: Date, end: Date, resource: Resource) => void;
|
|
152
|
+
/**
|
|
153
|
+
* A component that draws content inside the drag-to-create preview, such as a
|
|
154
|
+
* draft title and the live time range. It receives the snapped `start` and
|
|
155
|
+
* `end` that `onCreateEvent` would get if the sweep ended now, plus the lane's
|
|
156
|
+
* resource, and re-renders when the sweep crosses a snap step. The board keeps
|
|
157
|
+
* positioning, sizing and styling the preview on the UI thread and clips the
|
|
158
|
+
* content to it; the content is non-interactive and hidden from screen
|
|
159
|
+
* readers. Renders only while a sweep can create, so it needs `onCreateEvent`
|
|
160
|
+
* and does not enable creation itself. Applies to both orientations.
|
|
161
|
+
*/
|
|
162
|
+
renderCreateGhost?: ComponentType<CreateGhostArgs & { resource: Resource }>;
|
|
151
163
|
/**
|
|
152
164
|
* Shade the hours outside this window, per lane. Same shape as the Calendar's
|
|
153
165
|
* `businessHours` plus the lane's resource, so per-resource opening hours work
|
|
@@ -557,6 +569,7 @@ type LaneInteractionLayerProps = {
|
|
|
557
569
|
onPressCell?: (at: Date, resource: Resource) => void;
|
|
558
570
|
onLongPressCell?: (at: Date, resource: Resource) => void;
|
|
559
571
|
onCreateEvent?: (start: Date, end: Date, resource: Resource) => void;
|
|
572
|
+
renderCreateGhost?: ComponentType<CreateGhostArgs & { resource: Resource }>;
|
|
560
573
|
theme: ReturnType<typeof useCalendarTheme>;
|
|
561
574
|
};
|
|
562
575
|
|
|
@@ -575,12 +588,99 @@ function LaneInteractionLayer({
|
|
|
575
588
|
onPressCell,
|
|
576
589
|
onLongPressCell,
|
|
577
590
|
onCreateEvent,
|
|
591
|
+
renderCreateGhost: RenderCreateGhost,
|
|
578
592
|
theme,
|
|
579
593
|
}: LaneInteractionLayerProps): ReactElement {
|
|
580
594
|
const ghostStart = useSharedValue(0);
|
|
581
595
|
const ghostSize = useSharedValue(0);
|
|
582
596
|
const ghostVisible = useSharedValue(0);
|
|
583
597
|
|
|
598
|
+
// Custom preview content. The sweep reports its raw endpoints to JS only when a
|
|
599
|
+
// custom renderer is set, and only when one of them crosses a snap step, so the
|
|
600
|
+
// default preview and in-step movement stay on the UI thread.
|
|
601
|
+
const liveCreate = onCreateEvent != null && RenderCreateGhost != null;
|
|
602
|
+
const [createRange, setCreateRange] = useState<CreateGhostArgs | null>(null);
|
|
603
|
+
// The last endpoints sent to JS, in snap steps from midnight; NaN when none is shown.
|
|
604
|
+
const sentFrom = useSharedValue(Number.NaN);
|
|
605
|
+
const sentTo = useSharedValue(Number.NaN);
|
|
606
|
+
const resolveRange = useCallback(
|
|
607
|
+
(fromPx: number, toPx: number) =>
|
|
608
|
+
cellRangeFromDrag(date, fromPx, toPx, hourSize, startHour, snapMinutes),
|
|
609
|
+
[date, hourSize, startHour, snapMinutes],
|
|
610
|
+
);
|
|
611
|
+
const applyRange = useCallback((next: CreateGhostArgs | null) => {
|
|
612
|
+
setCreateRange((previous) =>
|
|
613
|
+
previous &&
|
|
614
|
+
next &&
|
|
615
|
+
previous.start.getTime() === next.start.getTime() &&
|
|
616
|
+
previous.end.getTime() === next.end.getTime()
|
|
617
|
+
? previous
|
|
618
|
+
: next,
|
|
619
|
+
);
|
|
620
|
+
}, []);
|
|
621
|
+
const currentResolver = useRef<typeof resolveRange | null>(null);
|
|
622
|
+
const showRange = useCallback(() => {
|
|
623
|
+
const resolve = currentResolver.current;
|
|
624
|
+
if (!ghostVisible.value || !resolve) return;
|
|
625
|
+
// A queued UI notification may arrive after props or the pointer changed.
|
|
626
|
+
applyRange(resolve(ghostStart.value, ghostStart.value + ghostSize.value));
|
|
627
|
+
}, [applyRange, ghostVisible, ghostStart, ghostSize]);
|
|
628
|
+
const clearRange = useCallback(() => {
|
|
629
|
+
setCreateRange(null);
|
|
630
|
+
}, []);
|
|
631
|
+
const dayKey = date.toDateString();
|
|
632
|
+
const createDay = useRef(dayKey);
|
|
633
|
+
useLayoutEffect(() => {
|
|
634
|
+
currentResolver.current = liveCreate ? resolveRange : null;
|
|
635
|
+
if (createDay.current !== dayKey) {
|
|
636
|
+
createDay.current = dayKey;
|
|
637
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
638
|
+
ghostVisible.value = 0;
|
|
639
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
640
|
+
sentFrom.value = Number.NaN;
|
|
641
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
642
|
+
sentTo.value = Number.NaN;
|
|
643
|
+
clearRange();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (liveCreate && ghostVisible.value)
|
|
647
|
+
applyRange(resolveRange(ghostStart.value, ghostStart.value + ghostSize.value));
|
|
648
|
+
}, [
|
|
649
|
+
applyRange,
|
|
650
|
+
resolveRange,
|
|
651
|
+
liveCreate,
|
|
652
|
+
dayKey,
|
|
653
|
+
ghostVisible,
|
|
654
|
+
ghostStart,
|
|
655
|
+
ghostSize,
|
|
656
|
+
sentFrom,
|
|
657
|
+
sentTo,
|
|
658
|
+
clearRange,
|
|
659
|
+
]);
|
|
660
|
+
// Removing the renderer (or `onCreateEvent`) drops any content still shown.
|
|
661
|
+
useEffect(() => {
|
|
662
|
+
if (liveCreate) return;
|
|
663
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
664
|
+
sentFrom.value = Number.NaN;
|
|
665
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
666
|
+
sentTo.value = Number.NaN;
|
|
667
|
+
if (!onCreateEvent) {
|
|
668
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
669
|
+
ghostVisible.value = 0;
|
|
670
|
+
}
|
|
671
|
+
clearRange();
|
|
672
|
+
}, [liveCreate, onCreateEvent, sentFrom, sentTo, clearRange, ghostVisible]);
|
|
673
|
+
// Which snap step from midnight a position falls on, as `cellRangeFromDrag`
|
|
674
|
+
// rounds it, so the sweep can tell on the UI thread when its range changes.
|
|
675
|
+
const snapStep = useCallback(
|
|
676
|
+
(px: number) => {
|
|
677
|
+
"worklet";
|
|
678
|
+
if (hourSize <= 0 || snapMinutes <= 0) return 0;
|
|
679
|
+
return Math.round(((startHour + px / hourSize) * MINUTES_PER_HOUR) / snapMinutes);
|
|
680
|
+
},
|
|
681
|
+
[hourSize, startHour, snapMinutes],
|
|
682
|
+
);
|
|
683
|
+
|
|
584
684
|
const timeAt = useCallback(
|
|
585
685
|
(px: number) => cellRangeFromDrag(date, px, px, hourSize, startHour, snapMinutes)?.start,
|
|
586
686
|
[date, hourSize, startHour, snapMinutes],
|
|
@@ -612,18 +712,40 @@ function LaneInteractionLayer({
|
|
|
612
712
|
ghostStart.value = vertical ? e.y : e.x;
|
|
613
713
|
ghostSize.value = 0;
|
|
614
714
|
ghostVisible.value = 1;
|
|
715
|
+
if (liveCreate) {
|
|
716
|
+
const step = snapStep(ghostStart.value);
|
|
717
|
+
sentFrom.value = step;
|
|
718
|
+
sentTo.value = step;
|
|
719
|
+
runOnJS(showRange)();
|
|
720
|
+
}
|
|
615
721
|
})
|
|
616
722
|
.onUpdate((e) => {
|
|
617
|
-
|
|
723
|
+
const at = vertical ? e.y : e.x;
|
|
724
|
+
ghostSize.value = at - ghostStart.value;
|
|
725
|
+
if (liveCreate) {
|
|
726
|
+
const fromStep = snapStep(ghostStart.value);
|
|
727
|
+
const toStep = snapStep(at);
|
|
728
|
+
if (fromStep !== sentFrom.value || toStep !== sentTo.value) {
|
|
729
|
+
sentFrom.value = fromStep;
|
|
730
|
+
sentTo.value = toStep;
|
|
731
|
+
runOnJS(showRange)();
|
|
732
|
+
}
|
|
733
|
+
}
|
|
618
734
|
})
|
|
619
735
|
// `success` is false when the gesture is cancelled/failed after it
|
|
620
736
|
// activated (RNGH still calls onEnd); only a real end should create.
|
|
621
737
|
.onEnd((e, success) => {
|
|
738
|
+
const active = ghostVisible.value;
|
|
622
739
|
ghostVisible.value = 0;
|
|
623
|
-
if (success) runOnJS(commitCreate)(ghostStart.value, vertical ? e.y : e.x);
|
|
740
|
+
if (success && active) runOnJS(commitCreate)(ghostStart.value, vertical ? e.y : e.x);
|
|
624
741
|
})
|
|
625
742
|
.onFinalize(() => {
|
|
626
743
|
ghostVisible.value = 0;
|
|
744
|
+
// Every touch finalizes; only a sweep that showed content goes back to JS.
|
|
745
|
+
if (!liveCreate || Number.isNaN(sentTo.value)) return;
|
|
746
|
+
sentFrom.value = Number.NaN;
|
|
747
|
+
sentTo.value = Number.NaN;
|
|
748
|
+
runOnJS(clearRange)();
|
|
627
749
|
})
|
|
628
750
|
: null;
|
|
629
751
|
const activatedPan = pan
|
|
@@ -650,6 +772,12 @@ function LaneInteractionLayer({
|
|
|
650
772
|
ghostStart,
|
|
651
773
|
ghostSize,
|
|
652
774
|
ghostVisible,
|
|
775
|
+
liveCreate,
|
|
776
|
+
snapStep,
|
|
777
|
+
showRange,
|
|
778
|
+
clearRange,
|
|
779
|
+
sentFrom,
|
|
780
|
+
sentTo,
|
|
653
781
|
]);
|
|
654
782
|
|
|
655
783
|
const ghostStyle = useAnimatedStyle(() => {
|
|
@@ -702,9 +830,25 @@ function LaneInteractionLayer({
|
|
|
702
830
|
backgroundColor: theme.colors.eventBackground,
|
|
703
831
|
borderColor: theme.colors.todayBackground,
|
|
704
832
|
},
|
|
833
|
+
liveCreate ? styles.createGhostContent : null,
|
|
705
834
|
ghostStyle,
|
|
706
835
|
]}
|
|
707
|
-
|
|
836
|
+
// Pointer-only preview: its content stays out of screen-reader traversal.
|
|
837
|
+
{...(liveCreate
|
|
838
|
+
? {
|
|
839
|
+
accessibilityElementsHidden: true,
|
|
840
|
+
importantForAccessibility: "no-hide-descendants" as const,
|
|
841
|
+
}
|
|
842
|
+
: null)}
|
|
843
|
+
>
|
|
844
|
+
{liveCreate && createRange && RenderCreateGhost ? (
|
|
845
|
+
<RenderCreateGhost
|
|
846
|
+
start={createRange.start}
|
|
847
|
+
end={createRange.end}
|
|
848
|
+
resource={resource}
|
|
849
|
+
/>
|
|
850
|
+
) : null}
|
|
851
|
+
</Animated.View>
|
|
708
852
|
) : null}
|
|
709
853
|
</>
|
|
710
854
|
);
|
|
@@ -750,6 +894,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
750
894
|
onPressCell,
|
|
751
895
|
onLongPressCell,
|
|
752
896
|
onCreateEvent,
|
|
897
|
+
renderCreateGhost,
|
|
753
898
|
businessHours,
|
|
754
899
|
renderBusinessHours,
|
|
755
900
|
renderResourceHeader,
|
|
@@ -959,6 +1104,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
959
1104
|
onPressCell={onPressCell}
|
|
960
1105
|
onLongPressCell={onLongPressCell}
|
|
961
1106
|
onCreateEvent={onCreateEvent}
|
|
1107
|
+
renderCreateGhost={renderCreateGhost}
|
|
962
1108
|
theme={theme}
|
|
963
1109
|
/>
|
|
964
1110
|
) : null}
|
|
@@ -1142,6 +1288,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
1142
1288
|
onPressCell={onPressCell}
|
|
1143
1289
|
onLongPressCell={onLongPressCell}
|
|
1144
1290
|
onCreateEvent={onCreateEvent}
|
|
1291
|
+
renderCreateGhost={renderCreateGhost}
|
|
1145
1292
|
theme={theme}
|
|
1146
1293
|
/>
|
|
1147
1294
|
) : null}
|
|
@@ -1281,6 +1428,8 @@ const styles = StyleSheet.create({
|
|
|
1281
1428
|
opacity: 0,
|
|
1282
1429
|
zIndex: 2,
|
|
1283
1430
|
},
|
|
1431
|
+
// Clips custom preview content to the ghost.
|
|
1432
|
+
createGhostContent: { overflow: "hidden" },
|
|
1284
1433
|
hshadeBand: { position: "absolute", top: 0, bottom: 0 },
|
|
1285
1434
|
vshadeBand: { position: "absolute", left: 0, right: 0 },
|
|
1286
1435
|
});
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "date-fns";
|
|
18
18
|
import {
|
|
19
19
|
type ComponentRef,
|
|
20
|
+
type ComponentType,
|
|
20
21
|
createContext,
|
|
21
22
|
type Dispatch,
|
|
22
23
|
type ForwardedRef,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
useContext,
|
|
30
31
|
useEffect,
|
|
31
32
|
useImperativeHandle,
|
|
33
|
+
useLayoutEffect,
|
|
32
34
|
useMemo,
|
|
33
35
|
useRef,
|
|
34
36
|
useState,
|
|
@@ -69,6 +71,7 @@ import type {
|
|
|
69
71
|
BusinessHoursBand,
|
|
70
72
|
CalendarEvent,
|
|
71
73
|
CalendarMode,
|
|
74
|
+
CreateGhostArgs,
|
|
72
75
|
EventDragHandler,
|
|
73
76
|
EventDragStartHandler,
|
|
74
77
|
EventKeyExtractor,
|
|
@@ -1608,6 +1611,7 @@ type TimetablePageProps<T> = {
|
|
|
1608
1611
|
onPressCell?: (date: Date) => void;
|
|
1609
1612
|
onLongPressCell?: (date: Date) => void;
|
|
1610
1613
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
1614
|
+
renderCreateGhost?: ComponentType<CreateGhostArgs>;
|
|
1611
1615
|
onEdgeAdvance?: (dir: number) => void;
|
|
1612
1616
|
/** This page's index in the pager: the key its all-day lane height is reported under. */
|
|
1613
1617
|
pageIndex: number;
|
|
@@ -1676,6 +1680,7 @@ function TimetablePageInner<T>({
|
|
|
1676
1680
|
onPressCell,
|
|
1677
1681
|
onLongPressCell,
|
|
1678
1682
|
onCreateEvent,
|
|
1683
|
+
renderCreateGhost: RenderCreateGhost,
|
|
1679
1684
|
onEdgeAdvance,
|
|
1680
1685
|
pageIndex,
|
|
1681
1686
|
laneHeight,
|
|
@@ -1817,6 +1822,7 @@ function TimetablePageInner<T>({
|
|
|
1817
1822
|
const createLeft = useSharedValue(0);
|
|
1818
1823
|
const createWidth = useSharedValue(0);
|
|
1819
1824
|
const createStartY = useSharedValue(0);
|
|
1825
|
+
const createEndY = useSharedValue(0);
|
|
1820
1826
|
const createDayIndex = useSharedValue(0);
|
|
1821
1827
|
// Set when the sweep is cancelled mid-drag (Escape on web); the gesture then
|
|
1822
1828
|
// bails instead of committing.
|
|
@@ -1832,6 +1838,109 @@ function TimetablePageInner<T>({
|
|
|
1832
1838
|
[days, heightSource, minHour, snapMinutes, onCreateEvent],
|
|
1833
1839
|
);
|
|
1834
1840
|
|
|
1841
|
+
// Custom preview content. The sweep reports its raw endpoints to JS only when a
|
|
1842
|
+
// custom renderer is set, and only when one of them crosses a snap step, so the
|
|
1843
|
+
// default preview and in-step movement stay on the UI thread.
|
|
1844
|
+
const liveCreate = createEnabled && RenderCreateGhost != null;
|
|
1845
|
+
const [createRange, setCreateRange] = useState<CreateGhostArgs | null>(null);
|
|
1846
|
+
// The last endpoints sent to JS, in snap steps from midnight; NaN when none is shown.
|
|
1847
|
+
const createSentStart = useSharedValue(Number.NaN);
|
|
1848
|
+
const createSentEnd = useSharedValue(Number.NaN);
|
|
1849
|
+
const resolveCreateRange = useCallback(
|
|
1850
|
+
(startY: number, endY: number, dayIndex: number) => {
|
|
1851
|
+
const day = days[dayIndex];
|
|
1852
|
+
return day
|
|
1853
|
+
? cellRangeFromDrag(day, startY, endY, heightSource.value, minHour, snapMinutes)
|
|
1854
|
+
: null;
|
|
1855
|
+
},
|
|
1856
|
+
[days, heightSource, minHour, snapMinutes],
|
|
1857
|
+
);
|
|
1858
|
+
const applyCreateRange = useCallback((next: CreateGhostArgs | null) => {
|
|
1859
|
+
setCreateRange((previous) =>
|
|
1860
|
+
previous &&
|
|
1861
|
+
next &&
|
|
1862
|
+
previous.start.getTime() === next.start.getTime() &&
|
|
1863
|
+
previous.end.getTime() === next.end.getTime()
|
|
1864
|
+
? previous
|
|
1865
|
+
: next,
|
|
1866
|
+
);
|
|
1867
|
+
}, []);
|
|
1868
|
+
const currentCreateResolver = useRef<typeof resolveCreateRange | null>(null);
|
|
1869
|
+
const showCreateRange = useCallback(() => {
|
|
1870
|
+
const resolve = currentCreateResolver.current;
|
|
1871
|
+
if (!createActive.value || !resolve) return;
|
|
1872
|
+
// A queued UI notification may arrive after props or the pointer changed.
|
|
1873
|
+
applyCreateRange(resolve(createStartY.value, createEndY.value, createDayIndex.value));
|
|
1874
|
+
}, [applyCreateRange, createActive, createStartY, createEndY, createDayIndex]);
|
|
1875
|
+
const clearCreateRange = useCallback(() => {
|
|
1876
|
+
setCreateRange(null);
|
|
1877
|
+
}, []);
|
|
1878
|
+
const previousCreateDays = useRef(days);
|
|
1879
|
+
useLayoutEffect(() => {
|
|
1880
|
+
currentCreateResolver.current = liveCreate ? resolveCreateRange : null;
|
|
1881
|
+
const previousDay = previousCreateDays.current[createDayIndex.value];
|
|
1882
|
+
const currentDay = days[createDayIndex.value];
|
|
1883
|
+
previousCreateDays.current = days;
|
|
1884
|
+
if (createActive.value && previousDay?.getTime() !== currentDay?.getTime()) {
|
|
1885
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1886
|
+
createCancelled.value = 1;
|
|
1887
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1888
|
+
createActive.value = 0;
|
|
1889
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1890
|
+
createHeight.value = 0;
|
|
1891
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1892
|
+
createSentStart.value = Number.NaN;
|
|
1893
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1894
|
+
createSentEnd.value = Number.NaN;
|
|
1895
|
+
clearCreateRange();
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
if (liveCreate && createActive.value)
|
|
1899
|
+
applyCreateRange(
|
|
1900
|
+
resolveCreateRange(createStartY.value, createEndY.value, createDayIndex.value),
|
|
1901
|
+
);
|
|
1902
|
+
}, [
|
|
1903
|
+
applyCreateRange,
|
|
1904
|
+
resolveCreateRange,
|
|
1905
|
+
days,
|
|
1906
|
+
liveCreate,
|
|
1907
|
+
createActive,
|
|
1908
|
+
createStartY,
|
|
1909
|
+
createEndY,
|
|
1910
|
+
createDayIndex,
|
|
1911
|
+
createCancelled,
|
|
1912
|
+
createHeight,
|
|
1913
|
+
createSentStart,
|
|
1914
|
+
createSentEnd,
|
|
1915
|
+
clearCreateRange,
|
|
1916
|
+
]);
|
|
1917
|
+
// Removing the renderer (or `onCreateEvent`) drops any content still shown.
|
|
1918
|
+
useEffect(() => {
|
|
1919
|
+
if (liveCreate) return;
|
|
1920
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1921
|
+
createSentStart.value = Number.NaN;
|
|
1922
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1923
|
+
createSentEnd.value = Number.NaN;
|
|
1924
|
+
if (!createEnabled) {
|
|
1925
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1926
|
+
createCancelled.value = 1;
|
|
1927
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1928
|
+
createActive.value = 0;
|
|
1929
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1930
|
+
createHeight.value = 0;
|
|
1931
|
+
}
|
|
1932
|
+
clearCreateRange();
|
|
1933
|
+
}, [
|
|
1934
|
+
liveCreate,
|
|
1935
|
+
createEnabled,
|
|
1936
|
+
createSentStart,
|
|
1937
|
+
createSentEnd,
|
|
1938
|
+
clearCreateRange,
|
|
1939
|
+
createCancelled,
|
|
1940
|
+
createActive,
|
|
1941
|
+
createHeight,
|
|
1942
|
+
]);
|
|
1943
|
+
|
|
1835
1944
|
// Web taps fall through to here: react-native-web doesn't fire the background
|
|
1836
1945
|
// Pressable's onPress, so a click on empty space reports the cell via a Tap
|
|
1837
1946
|
// gesture instead. Mirrors cellDateFromTouch.
|
|
@@ -1849,6 +1958,32 @@ function TimetablePageInner<T>({
|
|
|
1849
1958
|
[days, dayWidth, minHour, heightSource, onPressCell],
|
|
1850
1959
|
);
|
|
1851
1960
|
|
|
1961
|
+
// Which snap step from midnight a y offset falls on, as `cellRangeFromDrag`
|
|
1962
|
+
// rounds it. Plain numbers, so the sweep can tell on the UI thread when the
|
|
1963
|
+
// range it would create changes.
|
|
1964
|
+
const snapStep = useCallback(
|
|
1965
|
+
(y: number) => {
|
|
1966
|
+
"worklet";
|
|
1967
|
+
const h = heightSource.value;
|
|
1968
|
+
return h > 0 ? Math.round(((minHour + y / h) * MINUTES_PER_HOUR) / snapMinutes) : 0;
|
|
1969
|
+
},
|
|
1970
|
+
[minHour, heightSource, snapMinutes],
|
|
1971
|
+
);
|
|
1972
|
+
|
|
1973
|
+
// Zoom can change the candidate range without another pointer update.
|
|
1974
|
+
useAnimatedReaction(
|
|
1975
|
+
() => (liveCreate && createActive.value ? heightSource.value : null),
|
|
1976
|
+
(height, previous) => {
|
|
1977
|
+
if (height === null || previous === null || height === previous) return;
|
|
1978
|
+
const fromStep = snapStep(createStartY.value);
|
|
1979
|
+
const toStep = snapStep(createEndY.value);
|
|
1980
|
+
if (fromStep === createSentStart.value && toStep === createSentEnd.value) return;
|
|
1981
|
+
createSentStart.value = fromStep;
|
|
1982
|
+
createSentEnd.value = toStep;
|
|
1983
|
+
runOnJS(showCreateRange)();
|
|
1984
|
+
},
|
|
1985
|
+
);
|
|
1986
|
+
|
|
1852
1987
|
const createGesture = useMemo(() => {
|
|
1853
1988
|
const pan = Gesture.Pan()
|
|
1854
1989
|
.enabled(createEnabled)
|
|
@@ -1856,31 +1991,59 @@ function TimetablePageInner<T>({
|
|
|
1856
1991
|
const idx = dayCount === 1 ? 0 : Math.floor(event.x / dayWidth);
|
|
1857
1992
|
createDayIndex.value = idx;
|
|
1858
1993
|
createStartY.value = event.y;
|
|
1994
|
+
createEndY.value = event.y;
|
|
1859
1995
|
createLeft.value = idx * dayWidth;
|
|
1860
1996
|
createWidth.value = dayWidth;
|
|
1861
1997
|
createTop.value = event.y;
|
|
1862
1998
|
createHeight.value = 0;
|
|
1863
1999
|
createActive.value = 1;
|
|
1864
2000
|
createCancelled.value = 0;
|
|
2001
|
+
if (liveCreate) {
|
|
2002
|
+
const step = snapStep(event.y);
|
|
2003
|
+
createSentStart.value = step;
|
|
2004
|
+
createSentEnd.value = step;
|
|
2005
|
+
runOnJS(showCreateRange)();
|
|
2006
|
+
}
|
|
1865
2007
|
})
|
|
1866
2008
|
.onUpdate((event) => {
|
|
1867
2009
|
if (createCancelled.value) return;
|
|
2010
|
+
createEndY.value = createStartY.value + event.translationY;
|
|
1868
2011
|
const stepPx = (snapMinutes / MINUTES_PER_HOUR) * heightSource.value;
|
|
1869
2012
|
const snap = (y: number) => (stepPx > 0 ? Math.round(y / stepPx) * stepPx : y);
|
|
1870
2013
|
const startSnap = snap(createStartY.value);
|
|
1871
2014
|
const endSnap = snap(createStartY.value + event.translationY);
|
|
1872
2015
|
createTop.value = Math.min(startSnap, endSnap);
|
|
1873
2016
|
createHeight.value = Math.max(Math.abs(endSnap - startSnap), stepPx);
|
|
2017
|
+
if (liveCreate) {
|
|
2018
|
+
const startY = createStartY.value;
|
|
2019
|
+
const endY = startY + event.translationY;
|
|
2020
|
+
const fromStep = snapStep(startY);
|
|
2021
|
+
const toStep = snapStep(endY);
|
|
2022
|
+
if (fromStep !== createSentStart.value || toStep !== createSentEnd.value) {
|
|
2023
|
+
createSentStart.value = fromStep;
|
|
2024
|
+
createSentEnd.value = toStep;
|
|
2025
|
+
runOnJS(showCreateRange)();
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
1874
2028
|
})
|
|
1875
|
-
.onEnd((event) => {
|
|
2029
|
+
.onEnd((event, success) => {
|
|
1876
2030
|
createActive.value = 0;
|
|
1877
2031
|
createHeight.value = 0;
|
|
1878
|
-
if (createCancelled.value) return;
|
|
2032
|
+
if (!success || createCancelled.value) return;
|
|
1879
2033
|
runOnJS(commitCreate)(
|
|
1880
2034
|
createStartY.value,
|
|
1881
2035
|
createStartY.value + event.translationY,
|
|
1882
2036
|
createDayIndex.value,
|
|
1883
2037
|
);
|
|
2038
|
+
})
|
|
2039
|
+
.onFinalize(() => {
|
|
2040
|
+
createActive.value = 0;
|
|
2041
|
+
createHeight.value = 0;
|
|
2042
|
+
// Every touch finalizes; only a sweep that showed content goes back to JS.
|
|
2043
|
+
if (!liveCreate || Number.isNaN(createSentEnd.value)) return;
|
|
2044
|
+
createSentStart.value = Number.NaN;
|
|
2045
|
+
createSentEnd.value = Number.NaN;
|
|
2046
|
+
runOnJS(clearCreateRange)();
|
|
1884
2047
|
});
|
|
1885
2048
|
// Native: hold to start. Web: activate past a small vertical drag so a plain
|
|
1886
2049
|
// tap still falls through to onPressCell.
|
|
@@ -1900,8 +2063,15 @@ function TimetablePageInner<T>({
|
|
|
1900
2063
|
createLeft,
|
|
1901
2064
|
createWidth,
|
|
1902
2065
|
createStartY,
|
|
2066
|
+
createEndY,
|
|
1903
2067
|
createDayIndex,
|
|
1904
2068
|
createCancelled,
|
|
2069
|
+
liveCreate,
|
|
2070
|
+
snapStep,
|
|
2071
|
+
showCreateRange,
|
|
2072
|
+
clearCreateRange,
|
|
2073
|
+
createSentStart,
|
|
2074
|
+
createSentEnd,
|
|
1905
2075
|
]);
|
|
1906
2076
|
|
|
1907
2077
|
// Compose with a Tap so a plain web click reports the cell (onPressCell);
|
|
@@ -1931,10 +2101,23 @@ function TimetablePageInner<T>({
|
|
|
1931
2101
|
createActive.value = 0;
|
|
1932
2102
|
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1933
2103
|
createHeight.value = 0;
|
|
2104
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
2105
|
+
createSentStart.value = Number.NaN;
|
|
2106
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
2107
|
+
createSentEnd.value = Number.NaN;
|
|
2108
|
+
clearCreateRange();
|
|
1934
2109
|
};
|
|
1935
2110
|
doc.addEventListener("keydown", handler);
|
|
1936
2111
|
return () => doc.removeEventListener("keydown", handler);
|
|
1937
|
-
}, [
|
|
2112
|
+
}, [
|
|
2113
|
+
createEnabled,
|
|
2114
|
+
createActive,
|
|
2115
|
+
createCancelled,
|
|
2116
|
+
createHeight,
|
|
2117
|
+
createSentStart,
|
|
2118
|
+
createSentEnd,
|
|
2119
|
+
clearCreateRange,
|
|
2120
|
+
]);
|
|
1938
2121
|
|
|
1939
2122
|
const createGhostStyle = useAnimatedStyle(() => ({
|
|
1940
2123
|
top: createTop.value,
|
|
@@ -2229,7 +2412,21 @@ function TimetablePageInner<T>({
|
|
|
2229
2412
|
) : null}
|
|
2230
2413
|
|
|
2231
2414
|
{createEnabled ? (
|
|
2232
|
-
|
|
2415
|
+
liveCreate ? (
|
|
2416
|
+
<Animated.View
|
|
2417
|
+
{...ghostSlot}
|
|
2418
|
+
style={[ghostSlot.style, styles.createGhostContent, createGhostStyle]}
|
|
2419
|
+
// Pointer-only preview: its content stays out of screen-reader traversal.
|
|
2420
|
+
accessibilityElementsHidden
|
|
2421
|
+
importantForAccessibility="no-hide-descendants"
|
|
2422
|
+
>
|
|
2423
|
+
{createRange ? (
|
|
2424
|
+
<RenderCreateGhost start={createRange.start} end={createRange.end} />
|
|
2425
|
+
) : null}
|
|
2426
|
+
</Animated.View>
|
|
2427
|
+
) : (
|
|
2428
|
+
<Animated.View {...ghostSlot} style={[ghostSlot.style, createGhostStyle]} />
|
|
2429
|
+
)
|
|
2233
2430
|
) : null}
|
|
2234
2431
|
</Animated.View>
|
|
2235
2432
|
</View>
|
|
@@ -2402,6 +2599,17 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
|
|
|
2402
2599
|
onPressCell?: (date: Date) => void;
|
|
2403
2600
|
onLongPressCell?: (date: Date) => void;
|
|
2404
2601
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
2602
|
+
/**
|
|
2603
|
+
* A component that draws content inside the drag-to-create preview, such as a
|
|
2604
|
+
* draft title and the live time range. It receives the snapped `start` and
|
|
2605
|
+
* `end` that `onCreateEvent` would get if the sweep ended now, and re-renders
|
|
2606
|
+
* when the sweep crosses a snap step. The grid keeps positioning, sizing and
|
|
2607
|
+
* styling the preview on the UI thread and clips the content to it; the
|
|
2608
|
+
* content is non-interactive and hidden from screen readers. Renders only
|
|
2609
|
+
* while a sweep can create, so it needs `onCreateEvent` and does not enable
|
|
2610
|
+
* creation itself.
|
|
2611
|
+
*/
|
|
2612
|
+
renderCreateGhost?: ComponentType<CreateGhostArgs>;
|
|
2405
2613
|
/** Tap a day's column header (default header only). */
|
|
2406
2614
|
onPressDateHeader?: (date: Date) => void;
|
|
2407
2615
|
onChangeDate: (date: Date) => void;
|
|
@@ -2471,6 +2679,7 @@ function TimeGridInner<T>(
|
|
|
2471
2679
|
onPressCell,
|
|
2472
2680
|
onLongPressCell,
|
|
2473
2681
|
onCreateEvent,
|
|
2682
|
+
renderCreateGhost,
|
|
2474
2683
|
onPressDateHeader,
|
|
2475
2684
|
onChangeDate,
|
|
2476
2685
|
renderHeader,
|
|
@@ -3216,6 +3425,7 @@ function TimeGridInner<T>(
|
|
|
3216
3425
|
onPressCell={handlePressCell}
|
|
3217
3426
|
onLongPressCell={onLongPressCell}
|
|
3218
3427
|
onCreateEvent={onCreateEvent}
|
|
3428
|
+
renderCreateGhost={renderCreateGhost}
|
|
3219
3429
|
onEdgeAdvance={goToPage}
|
|
3220
3430
|
pageIndex={index}
|
|
3221
3431
|
laneHeight={laneHeight}
|
|
@@ -3277,6 +3487,7 @@ function TimeGridInner<T>(
|
|
|
3277
3487
|
handlePressCell,
|
|
3278
3488
|
onLongPressCell,
|
|
3279
3489
|
onCreateEvent,
|
|
3490
|
+
renderCreateGhost,
|
|
3280
3491
|
goToPage,
|
|
3281
3492
|
hiddenDays,
|
|
3282
3493
|
now,
|
|
@@ -3290,10 +3501,31 @@ function TimeGridInner<T>(
|
|
|
3290
3501
|
// `isActive` updates as you swipe). Without `activeIndex`, a page that pages in
|
|
3291
3502
|
// never learns it became active, so its zoom source and now line would lag.
|
|
3292
3503
|
// `columnsWidth` resizes the mounted pages when the grid is re-measured.
|
|
3293
|
-
// `showDragHandle` refreshes grips without requiring an event-data change
|
|
3504
|
+
// `showDragHandle` refreshes grips without requiring an event-data change, and
|
|
3505
|
+
// `renderCreateGhost` swaps the preview content of mounted pages.
|
|
3294
3506
|
const listExtraData = useMemo(
|
|
3295
|
-
() => ({
|
|
3296
|
-
|
|
3507
|
+
() => ({
|
|
3508
|
+
events,
|
|
3509
|
+
activeIndex,
|
|
3510
|
+
columnsWidth,
|
|
3511
|
+
showDragHandle,
|
|
3512
|
+
renderCreateGhost,
|
|
3513
|
+
onCreateEvent,
|
|
3514
|
+
dragStepMinutes,
|
|
3515
|
+
minHour,
|
|
3516
|
+
maxHour,
|
|
3517
|
+
}),
|
|
3518
|
+
[
|
|
3519
|
+
events,
|
|
3520
|
+
activeIndex,
|
|
3521
|
+
columnsWidth,
|
|
3522
|
+
showDragHandle,
|
|
3523
|
+
renderCreateGhost,
|
|
3524
|
+
onCreateEvent,
|
|
3525
|
+
dragStepMinutes,
|
|
3526
|
+
minHour,
|
|
3527
|
+
maxHour,
|
|
3528
|
+
],
|
|
3297
3529
|
);
|
|
3298
3530
|
|
|
3299
3531
|
return (
|
|
@@ -3752,6 +3984,8 @@ const styles = StyleSheet.create({
|
|
|
3752
3984
|
borderRadius: 6,
|
|
3753
3985
|
borderWidth: StyleSheet.hairlineWidth,
|
|
3754
3986
|
},
|
|
3987
|
+
// Clips custom preview content to the ghost.
|
|
3988
|
+
createGhostContent: { overflow: "hidden" },
|
|
3755
3989
|
weekendColumn: {
|
|
3756
3990
|
position: "absolute",
|
|
3757
3991
|
top: 0,
|
package/src/index.tsx
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
export { Calendar, type CalendarProps, type CalendarSlot } from "./components/Calendar";
|
|
24
24
|
export { Agenda, type AgendaProps, type AgendaSlot } from "./components/Agenda";
|
|
25
25
|
export { MonthView, type MonthViewProps, type MonthViewSlot } from "./components/MonthView";
|
|
26
|
+
export { MultiWeekView, type MultiWeekViewProps } from "./components/MultiWeekView";
|
|
26
27
|
export { YearView, type YearViewProps, type YearViewSlot } from "./components/YearView";
|
|
27
28
|
export { type ResolvedSlot, type SlotDefault, type SlotStyleProps } from "./utils/slots";
|
|
28
29
|
export { MonthPager, type MonthPagerProps } from "./components/MonthPager";
|
|
@@ -59,6 +60,7 @@ export type {
|
|
|
59
60
|
CalendarEvent,
|
|
60
61
|
CalendarHandle,
|
|
61
62
|
CalendarMode,
|
|
63
|
+
CreateGhostArgs,
|
|
62
64
|
EventAccessibilityLabelContext,
|
|
63
65
|
EventAccessibilityLabeler,
|
|
64
66
|
EventKeyExtractor,
|
|
@@ -88,6 +90,7 @@ export {
|
|
|
88
90
|
} from "@super-calendar/core";
|
|
89
91
|
export {
|
|
90
92
|
buildMonthGrid,
|
|
93
|
+
buildMultiWeekGrid,
|
|
91
94
|
layoutMonthWeek,
|
|
92
95
|
type MonthEventSegment,
|
|
93
96
|
type MonthGrid,
|
|
@@ -95,6 +98,11 @@ export {
|
|
|
95
98
|
type MonthGridWeek,
|
|
96
99
|
type MonthGridWeekday,
|
|
97
100
|
type MonthWeekEvents,
|
|
101
|
+
type MultiWeekGrid,
|
|
102
|
+
type MultiWeekGridDay,
|
|
103
|
+
type MultiWeekGridInterval,
|
|
104
|
+
type MultiWeekGridOptions,
|
|
105
|
+
type MultiWeekGridWeek,
|
|
98
106
|
type UseMonthGridOptions,
|
|
99
107
|
useMonthGrid,
|
|
100
108
|
weekdayFormatToken,
|