@super-calendar/native 2.7.0 → 2.8.1
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/dist/{DefaultMonthEvent-DCPDsnvq.d.ts → DefaultMonthEvent-CjwX3Nt1.d.ts} +14 -6
- package/dist/{DefaultMonthEvent-DMOC5aNL.d.mts → DefaultMonthEvent-VgJarTO_.d.mts} +14 -6
- package/dist/{MonthList-CJs1vq5T.js → MonthList-C-vBotP0.js} +94 -28
- package/dist/{MonthList-Dn37Ezj0.mjs → MonthList-DjAz4xoi.mjs} +95 -29
- package/dist/index.d.mts +27 -6
- package/dist/index.d.ts +27 -6
- package/dist/index.js +121 -47
- package/dist/index.mjs +117 -49
- 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 +13 -0
- package/src/components/MonthList.tsx +4 -0
- package/src/components/MonthPager.tsx +3 -0
- package/src/components/MonthView.tsx +148 -36
- package/src/components/ResourceTimeline.tsx +32 -15
- package/src/components/TimeGrid.tsx +155 -29
- package/src/index.tsx +3 -0
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
cellRangeFromDrag,
|
|
75
75
|
useNow,
|
|
76
76
|
closedHourBands,
|
|
77
|
+
overlapsOtherEvents,
|
|
77
78
|
pageStepDays,
|
|
78
79
|
resolveDraggedBounds,
|
|
79
80
|
snapDeltaMinutes,
|
|
@@ -265,6 +266,10 @@ type AnimatedEventBoxProps<T> = {
|
|
|
265
266
|
onDragEvent?: EventDragHandler<T>;
|
|
266
267
|
onDragStart?: EventDragStartHandler<T>;
|
|
267
268
|
showDragHandle: boolean;
|
|
269
|
+
// Grid-level defaults for move/resize, overridden per event by
|
|
270
|
+
// `startEditable`/`durationEditable`.
|
|
271
|
+
eventStartEditable: boolean;
|
|
272
|
+
eventDurationEditable: boolean;
|
|
268
273
|
// Page the view one period (dir -1/+1) when the event is dragged past the
|
|
269
274
|
// visible columns and held there. Absent disables edge auto-advance.
|
|
270
275
|
onEdgeAdvance?: (dir: number) => void;
|
|
@@ -290,6 +295,8 @@ function AnimatedEventBox<T>({
|
|
|
290
295
|
onDragStart,
|
|
291
296
|
onEdgeAdvance,
|
|
292
297
|
showDragHandle,
|
|
298
|
+
eventStartEditable,
|
|
299
|
+
eventDurationEditable,
|
|
293
300
|
}: AnimatedEventBoxProps<T>) {
|
|
294
301
|
const RenderEventComponent = renderEvent;
|
|
295
302
|
const theme = useCalendarTheme();
|
|
@@ -308,17 +315,29 @@ function AnimatedEventBox<T>({
|
|
|
308
315
|
// Drag-to-move/resize. Native picks the event up on long-press (so a tap or
|
|
309
316
|
// scroll isn't hijacked); web activates after a small drag threshold, so a
|
|
310
317
|
// plain click still selects and a right-click still opens a context menu.
|
|
311
|
-
// `draggable: false` locks a single event (keeps taps, blocks move/resize)
|
|
312
|
-
|
|
318
|
+
// `draggable: false` locks a single event (keeps taps, blocks move/resize);
|
|
319
|
+
// `startEditable`/`durationEditable` (per event, falling back to the grid
|
|
320
|
+
// defaults) split whether it can be moved vs resized.
|
|
321
|
+
const editable =
|
|
313
322
|
onDragEvent != null && !positioned.event.disabled && positioned.event.draggable !== false;
|
|
323
|
+
const canMove = editable && (positioned.event.startEditable ?? eventStartEditable);
|
|
324
|
+
const canResize = editable && (positioned.event.durationEditable ?? eventDurationEditable);
|
|
314
325
|
// Only the segment that owns the real end may be resized.
|
|
315
|
-
const resizable =
|
|
326
|
+
const resizable = canResize && !positioned.continuesAfter;
|
|
327
|
+
// Only the segment that owns the real start may be resized from the top edge.
|
|
328
|
+
// Disabled on react-native-web: moving the box's top during its own child
|
|
329
|
+
// gesture drops the gesture there (a web-only gesture-handler quirk); on a
|
|
330
|
+
// device the top grip wins over the long-press move as usual. The dom renderer
|
|
331
|
+
// provides top-edge resize on the web.
|
|
332
|
+
const resizableFromStart = canResize && !positioned.continuesBefore && !isWeb;
|
|
316
333
|
|
|
317
334
|
// Live preview offsets (px), reset to 0 once the committed change re-renders.
|
|
318
335
|
// moveOffsetX shifts the box across day columns during a cross-day drag.
|
|
319
336
|
const moveOffset = useSharedValue(0);
|
|
320
337
|
const moveOffsetX = useSharedValue(0);
|
|
338
|
+
// Bottom-edge resize (changes the end) and top-edge resize (changes the start).
|
|
321
339
|
const resizeDelta = useSharedValue(0);
|
|
340
|
+
const resizeStartDelta = useSharedValue(0);
|
|
322
341
|
// Raised to DRAG_EVENT_Z while a gesture is active so the dragged event floats
|
|
323
342
|
// above all the others, then back to 0 when it settles.
|
|
324
343
|
const dragZ = useSharedValue(0);
|
|
@@ -347,13 +366,18 @@ function AnimatedEventBox<T>({
|
|
|
347
366
|
// renderers can reveal detail progressively as the grid zooms, without
|
|
348
367
|
// re-rendering. Explicit deps so the worklet re-captures the event's geometry.
|
|
349
368
|
const boxHeight = useDerivedValue(
|
|
350
|
-
() =>
|
|
369
|
+
() =>
|
|
370
|
+
Math.max(
|
|
371
|
+
durationHours * cellHeight.value + resizeDelta.value - resizeStartDelta.value,
|
|
372
|
+
MIN_EVENT_HEIGHT,
|
|
373
|
+
),
|
|
351
374
|
[durationHours],
|
|
352
375
|
);
|
|
353
376
|
|
|
354
377
|
const boxStyle = useAnimatedStyle(
|
|
355
378
|
() => ({
|
|
356
|
-
|
|
379
|
+
// A top-edge resize pushes the box down and shortens it (start moves later).
|
|
380
|
+
top: (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value,
|
|
357
381
|
height: boxHeight.value,
|
|
358
382
|
transform: [{ translateX: moveOffsetX.value }],
|
|
359
383
|
zIndex: dragZ.value,
|
|
@@ -372,7 +396,16 @@ function AnimatedEventBox<T>({
|
|
|
372
396
|
moveOffsetX.value = 0;
|
|
373
397
|
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
374
398
|
resizeDelta.value = 0;
|
|
375
|
-
|
|
399
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
400
|
+
resizeStartDelta.value = 0;
|
|
401
|
+
}, [
|
|
402
|
+
positioned.startHours,
|
|
403
|
+
positioned.durationHours,
|
|
404
|
+
moveOffset,
|
|
405
|
+
moveOffsetX,
|
|
406
|
+
resizeDelta,
|
|
407
|
+
resizeStartDelta,
|
|
408
|
+
]);
|
|
376
409
|
|
|
377
410
|
// Keep the latest event/handler in a ref so the gestures stay memoized but
|
|
378
411
|
// never call into a stale closure.
|
|
@@ -387,7 +420,9 @@ function AnimatedEventBox<T>({
|
|
|
387
420
|
moveOffsetX.value = 0;
|
|
388
421
|
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
389
422
|
resizeDelta.value = 0;
|
|
390
|
-
|
|
423
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
424
|
+
resizeStartDelta.value = 0;
|
|
425
|
+
}, [moveOffset, moveOffsetX, resizeDelta, resizeStartDelta]);
|
|
391
426
|
|
|
392
427
|
const commitDrag = useCallback(
|
|
393
428
|
(deltaStartMin: number, deltaEndMin: number) => {
|
|
@@ -480,7 +515,7 @@ function AnimatedEventBox<T>({
|
|
|
480
515
|
|
|
481
516
|
const moveGesture = useMemo(() => {
|
|
482
517
|
const pan = Gesture.Pan()
|
|
483
|
-
.enabled(
|
|
518
|
+
.enabled(canMove)
|
|
484
519
|
.onStart((event) => {
|
|
485
520
|
dragZ.value = DRAG_EVENT_Z;
|
|
486
521
|
edgeDir.value = 0;
|
|
@@ -569,7 +604,7 @@ function AnimatedEventBox<T>({
|
|
|
569
604
|
.activeOffsetY([-DRAG_ACTIVATE_PX, DRAG_ACTIVATE_PX])
|
|
570
605
|
: pan.activateAfterLongPress(MOVE_ACTIVATE_MS);
|
|
571
606
|
}, [
|
|
572
|
-
|
|
607
|
+
canMove,
|
|
573
608
|
snapMinutes,
|
|
574
609
|
cellHeight,
|
|
575
610
|
moveOffset,
|
|
@@ -625,11 +660,46 @@ function AnimatedEventBox<T>({
|
|
|
625
660
|
[resizable, snapMinutes, cellHeight, resizeDelta, dragZ, commitDrag, notifyDragStart],
|
|
626
661
|
);
|
|
627
662
|
|
|
663
|
+
// Top-edge resize: dragging the top changes the start (end fixed). Mirrors the
|
|
664
|
+
// bottom resize but commits a start-delta and previews via resizeStartDelta.
|
|
665
|
+
const resizeStartGesture = useMemo(
|
|
666
|
+
() =>
|
|
667
|
+
Gesture.Pan()
|
|
668
|
+
.enabled(resizableFromStart)
|
|
669
|
+
.onStart(() => {
|
|
670
|
+
dragZ.value = DRAG_EVENT_Z;
|
|
671
|
+
runOnJS(notifyDragStart)();
|
|
672
|
+
})
|
|
673
|
+
.onUpdate((event) => {
|
|
674
|
+
resizeStartDelta.value = event.translationY;
|
|
675
|
+
})
|
|
676
|
+
.onEnd((event) => {
|
|
677
|
+
const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
|
|
678
|
+
if (delta === 0) {
|
|
679
|
+
resizeStartDelta.value = 0;
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
resizeStartDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
|
|
683
|
+
runOnJS(commitDrag)(delta, 0);
|
|
684
|
+
})
|
|
685
|
+
.onFinalize(() => {
|
|
686
|
+
dragZ.value = 0;
|
|
687
|
+
}),
|
|
688
|
+
[
|
|
689
|
+
resizableFromStart,
|
|
690
|
+
snapMinutes,
|
|
691
|
+
cellHeight,
|
|
692
|
+
resizeStartDelta,
|
|
693
|
+
dragZ,
|
|
694
|
+
commitDrag,
|
|
695
|
+
notifyDragStart,
|
|
696
|
+
],
|
|
697
|
+
);
|
|
698
|
+
|
|
628
699
|
const handlePress = () => onPress(positioned.event);
|
|
629
|
-
// When
|
|
700
|
+
// When movable, a long press grabs the event to move it, so don't also fire
|
|
630
701
|
// the consumer's long-press handler.
|
|
631
|
-
const handleLongPress =
|
|
632
|
-
!draggable && onLongPress ? () => onLongPress(positioned.event) : undefined;
|
|
702
|
+
const handleLongPress = !canMove && onLongPress ? () => onLongPress(positioned.event) : undefined;
|
|
633
703
|
|
|
634
704
|
// Dragging is gesture-only, so expose the same move/resize commit path as
|
|
635
705
|
// discrete screen-reader actions (VoiceOver/TalkBack invoke them from the
|
|
@@ -642,21 +712,28 @@ function AnimatedEventBox<T>({
|
|
|
642
712
|
: daysPerPage === 1
|
|
643
713
|
? "day"
|
|
644
714
|
: `${daysPerPage} day${daysPerPage === 1 ? "" : "s"}`;
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
:
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
]
|
|
658
|
-
|
|
659
|
-
|
|
715
|
+
const dragActions = [
|
|
716
|
+
...(canMove
|
|
717
|
+
? [
|
|
718
|
+
{ name: "move-later", label: `Move ${unit(snapMinutes)} later` },
|
|
719
|
+
{ name: "move-earlier", label: `Move ${unit(snapMinutes)} earlier` },
|
|
720
|
+
]
|
|
721
|
+
: []),
|
|
722
|
+
...(resizable
|
|
723
|
+
? [
|
|
724
|
+
{ name: "extend", label: `Extend by ${unit(snapMinutes)}` },
|
|
725
|
+
{ name: "shrink", label: `Shorten by ${unit(snapMinutes)}` },
|
|
726
|
+
]
|
|
727
|
+
: []),
|
|
728
|
+
...(canMove
|
|
729
|
+
? [
|
|
730
|
+
{ name: "move-next-page", label: `Move to next ${pageUnit}` },
|
|
731
|
+
{ name: "move-previous-page", label: `Move to previous ${pageUnit}` },
|
|
732
|
+
]
|
|
733
|
+
: []),
|
|
734
|
+
];
|
|
735
|
+
const accessibilityActions = dragActions.length ? dragActions : undefined;
|
|
736
|
+
const handleAccessibilityAction = accessibilityActions
|
|
660
737
|
? (e: AccessibilityActionEvent) => {
|
|
661
738
|
switch (e.nativeEvent.actionName) {
|
|
662
739
|
case "move-later":
|
|
@@ -698,6 +775,15 @@ function AnimatedEventBox<T>({
|
|
|
698
775
|
onPress={handlePress}
|
|
699
776
|
onLongPress={handleLongPress}
|
|
700
777
|
/>
|
|
778
|
+
{resizableFromStart ? (
|
|
779
|
+
<GestureDetector gesture={resizeStartGesture}>
|
|
780
|
+
<Animated.View style={styles.resizeHandleTop}>
|
|
781
|
+
{showDragHandle ? (
|
|
782
|
+
<View style={[styles.resizeGrip, { backgroundColor: theme.colors.eventText }]} />
|
|
783
|
+
) : null}
|
|
784
|
+
</Animated.View>
|
|
785
|
+
</GestureDetector>
|
|
786
|
+
) : null}
|
|
701
787
|
{resizable ? (
|
|
702
788
|
<GestureDetector gesture={resizeGesture}>
|
|
703
789
|
<Animated.View style={styles.resizeHandle}>
|
|
@@ -712,7 +798,9 @@ function AnimatedEventBox<T>({
|
|
|
712
798
|
</Animated.View>
|
|
713
799
|
);
|
|
714
800
|
|
|
715
|
-
|
|
801
|
+
// Only wrap in the move gesture when movable; the resize grips inside `box`
|
|
802
|
+
// carry their own gestures, so a resize-only event still works.
|
|
803
|
+
if (!canMove) return box;
|
|
716
804
|
return <GestureDetector gesture={moveGesture}>{box}</GestureDetector>;
|
|
717
805
|
}
|
|
718
806
|
|
|
@@ -927,6 +1015,8 @@ type TimetablePageProps<T> = {
|
|
|
927
1015
|
keyExtractor: EventKeyExtractor<T>;
|
|
928
1016
|
snapMinutes: number;
|
|
929
1017
|
showDragHandle: boolean;
|
|
1018
|
+
eventStartEditable: boolean;
|
|
1019
|
+
eventDurationEditable: boolean;
|
|
930
1020
|
onPressEvent: (event: CalendarEvent<T>) => void;
|
|
931
1021
|
onLongPressEvent?: (event: CalendarEvent<T>) => void;
|
|
932
1022
|
onDragEvent?: EventDragHandler<T>;
|
|
@@ -982,6 +1072,8 @@ function TimetablePageInner<T>({
|
|
|
982
1072
|
keyExtractor,
|
|
983
1073
|
snapMinutes,
|
|
984
1074
|
showDragHandle,
|
|
1075
|
+
eventStartEditable,
|
|
1076
|
+
eventDurationEditable,
|
|
985
1077
|
onPressEvent,
|
|
986
1078
|
onLongPressEvent,
|
|
987
1079
|
onDragEvent,
|
|
@@ -1536,6 +1628,8 @@ function TimetablePageInner<T>({
|
|
|
1536
1628
|
renderEvent={renderEvent}
|
|
1537
1629
|
snapMinutes={snapMinutes}
|
|
1538
1630
|
showDragHandle={showDragHandle}
|
|
1631
|
+
eventStartEditable={eventStartEditable}
|
|
1632
|
+
eventDurationEditable={eventDurationEditable}
|
|
1539
1633
|
onPress={onPressEvent}
|
|
1540
1634
|
onLongPress={onLongPressEvent}
|
|
1541
1635
|
onDragEvent={onDragEvent}
|
|
@@ -1692,6 +1786,13 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
|
|
|
1692
1786
|
* drag-to-move and drag-to-resize working while hiding the visible indicator.
|
|
1693
1787
|
*/
|
|
1694
1788
|
showDragHandle?: boolean;
|
|
1789
|
+
/** Allow moving events by default (per-event `startEditable` overrides). Default true. */
|
|
1790
|
+
eventStartEditable?: boolean;
|
|
1791
|
+
/** Allow resizing events by default (per-event `durationEditable` overrides). Default true. */
|
|
1792
|
+
eventDurationEditable?: boolean;
|
|
1793
|
+
/** Allow a dragged/resized event to overlap another (default true). Set false to
|
|
1794
|
+
* reject a drop that would collide, snapping the event back. */
|
|
1795
|
+
eventOverlap?: boolean;
|
|
1695
1796
|
onPressEvent: (event: CalendarEvent<T>) => void;
|
|
1696
1797
|
onLongPressEvent?: (event: CalendarEvent<T>) => void;
|
|
1697
1798
|
/**
|
|
@@ -1756,9 +1857,12 @@ function TimeGridInner<T>({
|
|
|
1756
1857
|
resetPageOnPressCell = false,
|
|
1757
1858
|
dragStepMinutes = DEFAULT_DRAG_STEP_MINUTES,
|
|
1758
1859
|
showDragHandle = true,
|
|
1860
|
+
eventStartEditable = true,
|
|
1861
|
+
eventDurationEditable = true,
|
|
1862
|
+
eventOverlap = true,
|
|
1759
1863
|
onPressEvent,
|
|
1760
1864
|
onLongPressEvent,
|
|
1761
|
-
onDragEvent,
|
|
1865
|
+
onDragEvent: onDragEventProp,
|
|
1762
1866
|
onDragStart,
|
|
1763
1867
|
onPressCell,
|
|
1764
1868
|
onLongPressCell,
|
|
@@ -1783,6 +1887,15 @@ function TimeGridInner<T>({
|
|
|
1783
1887
|
[renderEvent, eventAccessibilityLabel, ampm],
|
|
1784
1888
|
);
|
|
1785
1889
|
|
|
1890
|
+
// Reject a drop that would overlap another event when `eventOverlap` is false,
|
|
1891
|
+
// so every commit path (drag, resize, cross-week, screen-reader actions) enforces
|
|
1892
|
+
// it without the consumer wiring it in `onDragEvent`.
|
|
1893
|
+
const onDragEvent = useMemo(() => {
|
|
1894
|
+
if (!onDragEventProp || eventOverlap !== false) return onDragEventProp;
|
|
1895
|
+
return (event: CalendarEvent<T>, start: Date, end: Date) =>
|
|
1896
|
+
overlapsOtherEvents(events, event, start, end) ? false : onDragEventProp(event, start, end);
|
|
1897
|
+
}, [onDragEventProp, eventOverlap, events]);
|
|
1898
|
+
|
|
1786
1899
|
const { width, height } = useWindowDimensions();
|
|
1787
1900
|
const listRef = useRef<LegendListRef>(null);
|
|
1788
1901
|
// The pager's own view; measured in the window so an event drag can locate the
|
|
@@ -2215,6 +2328,8 @@ function TimeGridInner<T>({
|
|
|
2215
2328
|
keyExtractor={keyExtractor}
|
|
2216
2329
|
snapMinutes={Math.max(1, dragStepMinutes)}
|
|
2217
2330
|
showDragHandle={showDragHandle}
|
|
2331
|
+
eventStartEditable={eventStartEditable}
|
|
2332
|
+
eventDurationEditable={eventDurationEditable}
|
|
2218
2333
|
onPressEvent={onPressEvent}
|
|
2219
2334
|
onLongPressEvent={onLongPressEvent}
|
|
2220
2335
|
onDragEvent={onDragEvent}
|
|
@@ -2263,6 +2378,8 @@ function TimeGridInner<T>({
|
|
|
2263
2378
|
keyExtractor,
|
|
2264
2379
|
dragStepMinutes,
|
|
2265
2380
|
showDragHandle,
|
|
2381
|
+
eventStartEditable,
|
|
2382
|
+
eventDurationEditable,
|
|
2266
2383
|
onPressEvent,
|
|
2267
2384
|
onLongPressEvent,
|
|
2268
2385
|
onDragEvent,
|
|
@@ -2656,6 +2773,15 @@ const styles = StyleSheet.create({
|
|
|
2656
2773
|
alignItems: "center",
|
|
2657
2774
|
justifyContent: "center",
|
|
2658
2775
|
},
|
|
2776
|
+
resizeHandleTop: {
|
|
2777
|
+
position: "absolute",
|
|
2778
|
+
left: 0,
|
|
2779
|
+
right: 0,
|
|
2780
|
+
top: 0,
|
|
2781
|
+
height: RESIZE_HANDLE_HEIGHT,
|
|
2782
|
+
alignItems: "center",
|
|
2783
|
+
justifyContent: "center",
|
|
2784
|
+
},
|
|
2659
2785
|
resizeGrip: {
|
|
2660
2786
|
width: 24,
|
|
2661
2787
|
height: 3,
|
package/src/index.tsx
CHANGED
|
@@ -86,10 +86,13 @@ export {
|
|
|
86
86
|
} from "@super-calendar/core";
|
|
87
87
|
export {
|
|
88
88
|
buildMonthGrid,
|
|
89
|
+
layoutMonthWeek,
|
|
90
|
+
type MonthEventSegment,
|
|
89
91
|
type MonthGrid,
|
|
90
92
|
type MonthGridDay,
|
|
91
93
|
type MonthGridWeek,
|
|
92
94
|
type MonthGridWeekday,
|
|
95
|
+
type MonthWeekEvents,
|
|
93
96
|
type UseMonthGridOptions,
|
|
94
97
|
useMonthGrid,
|
|
95
98
|
weekdayFormatToken,
|