@super-calendar/native 2.17.0 → 2.19.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 +23 -1
- package/dist/{DefaultMonthEvent-C3C30hfV.d.mts → DefaultMonthEvent-DzgQFuVp.d.mts} +47 -10
- package/dist/{DefaultMonthEvent-Dx3lD7ig.d.ts → DefaultMonthEvent-joYl8Tu2.d.ts} +47 -10
- package/dist/{MonthList-N1GVDIE4.mjs → MonthList-BGl1gTDr.mjs} +603 -97
- package/dist/{MonthList-B2TSGYp7.js → MonthList-DeO-x5VW.js} +601 -95
- package/dist/index.d.mts +40 -15
- package/dist/index.d.ts +40 -15
- package/dist/index.js +189 -63
- package/dist/index.mjs +161 -65
- 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 +19 -3
- package/src/components/AllDayLane.tsx +64 -37
- package/src/components/Calendar.tsx +104 -30
- package/src/components/MonthCellProbe.tsx +201 -0
- package/src/components/MonthList.tsx +4 -2
- package/src/components/MonthPager.tsx +41 -4
- package/src/components/MonthView.tsx +597 -118
- package/src/components/ResourceTimeline.tsx +11 -2
- package/src/components/TimeGrid.tsx +82 -24
- package/src/components/YearView.tsx +12 -3
- package/src/index.tsx +11 -2
- package/src/types.ts +20 -2
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
1
2
|
import { addDays, startOfDay } from "date-fns";
|
|
2
3
|
import { type LayoutChangeEvent, StyleSheet, View } from "react-native";
|
|
3
4
|
import { useCalendarTheme } from "../theme";
|
|
4
5
|
import type { CalendarEvent, CalendarMode, EventKeyExtractor, RenderEvent } from "../types";
|
|
5
6
|
import { useSlots } from "../utils/slots";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isAllDayEvent,
|
|
9
|
+
isBackgroundEvent,
|
|
10
|
+
layoutMonthWeek,
|
|
11
|
+
type MonthEventSegment,
|
|
12
|
+
} from "@super-calendar/core";
|
|
7
13
|
|
|
8
14
|
// The lane's slots are a subset of the TimeGrid slot union; typed locally so
|
|
9
15
|
// this file doesn't import the full TimeGrid type.
|
|
@@ -25,7 +31,7 @@ type AllDayLaneProps<T> = {
|
|
|
25
31
|
/**
|
|
26
32
|
* The all-day lane of one page, pinned above the scrolling hours. All-day
|
|
27
33
|
* events are excluded from the timed columns (see `layoutDayEvents`) and shown
|
|
28
|
-
* here, stacked
|
|
34
|
+
* here as continuous spans, stacked only when their dates overlap. Always rendered so every page reports a
|
|
29
35
|
* height, zero when the week has none, which the band above the grid follows
|
|
30
36
|
* live as you swipe; the "all-day" label lives in the hour column.
|
|
31
37
|
*/
|
|
@@ -44,60 +50,81 @@ export function AllDayLane<T>({
|
|
|
44
50
|
const slot = useSlots<AllDayLaneSlot>();
|
|
45
51
|
const RenderEventComponent = renderEvent;
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const spans = useMemo(() => {
|
|
54
|
+
const allDay = events.filter(
|
|
55
|
+
(event) =>
|
|
56
|
+
isAllDayEvent(event) &&
|
|
57
|
+
!isBackgroundEvent(event) &&
|
|
58
|
+
days.some(
|
|
59
|
+
(day) => event.start < addDays(startOfDay(day), 1) && event.end > startOfDay(day),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
const { segments, laneCount } = layoutMonthWeek(days, allDay);
|
|
63
|
+
const lanes: MonthEventSegment<T>[][] = Array.from({ length: laneCount }, () => []);
|
|
64
|
+
for (const segment of segments) lanes[segment.lane].push(segment);
|
|
65
|
+
return lanes.flat();
|
|
66
|
+
}, [days, events]);
|
|
54
67
|
|
|
55
68
|
return (
|
|
56
69
|
<View
|
|
57
70
|
{...slot("allDayLane", {
|
|
58
|
-
base: styles.lane,
|
|
71
|
+
base: [styles.lane, spans.length > 0 && { paddingVertical: 2 }],
|
|
59
72
|
themed: theme.containers.allDayLane,
|
|
60
73
|
})}
|
|
61
74
|
onLayout={onLayout}
|
|
62
75
|
>
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
{spans.map((segment, index) => {
|
|
77
|
+
const { event, startCol, endCol, lane, continuesBefore, continuesAfter } = segment;
|
|
78
|
+
const previous = spans[index - 1];
|
|
79
|
+
const previousEnd = previous?.lane === lane ? previous.endCol : -1;
|
|
80
|
+
const lastInLane = spans[index + 1]?.lane !== lane;
|
|
81
|
+
const remaining = lastInLane ? days.length - endCol - 1 : 0;
|
|
82
|
+
// Yoga wraps before pixel rounding. Leave subpixel slack at the row end
|
|
83
|
+
// so float32 accumulation cannot push a bar onto the following line.
|
|
84
|
+
const wrapSlack = lastInLane ? Math.min(0.5, dayWidth / 4) : 0;
|
|
85
|
+
return (
|
|
86
|
+
<View
|
|
87
|
+
key={keyExtractor(event, index)}
|
|
88
|
+
{...slot("allDayColumn", {
|
|
89
|
+
base: [
|
|
90
|
+
styles.column,
|
|
91
|
+
{
|
|
92
|
+
width: dayWidth * (endCol - startCol + 1),
|
|
93
|
+
marginLeft: dayWidth * (startCol - previousEnd - 1),
|
|
94
|
+
marginRight: dayWidth * remaining - wrapSlack,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
themed: theme.containers.allDayColumn,
|
|
98
|
+
})}
|
|
99
|
+
>
|
|
100
|
+
<View {...slot("allDayEvent", { base: styles.chip })}>
|
|
101
|
+
<RenderEventComponent
|
|
102
|
+
event={event}
|
|
103
|
+
mode={mode}
|
|
104
|
+
isAllDay
|
|
105
|
+
continuesBefore={continuesBefore}
|
|
106
|
+
continuesAfter={continuesAfter}
|
|
107
|
+
onPress={() => onPressEvent(event)}
|
|
108
|
+
onLongPress={onLongPressEvent ? () => onLongPressEvent(event) : undefined}
|
|
109
|
+
/>
|
|
87
110
|
</View>
|
|
88
|
-
|
|
111
|
+
</View>
|
|
112
|
+
);
|
|
113
|
+
})}
|
|
89
114
|
</View>
|
|
90
115
|
);
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
const styles = StyleSheet.create({
|
|
94
119
|
lane: {
|
|
120
|
+
// Keep keyed events as siblings so changing lanes preserves renderer state.
|
|
95
121
|
flexDirection: "row",
|
|
122
|
+
flexWrap: "wrap",
|
|
123
|
+
alignItems: "flex-start",
|
|
124
|
+
rowGap: 2,
|
|
96
125
|
},
|
|
97
126
|
column: {
|
|
98
|
-
paddingVertical: 2,
|
|
99
127
|
paddingHorizontal: 1,
|
|
100
|
-
gap: 2,
|
|
101
128
|
},
|
|
102
129
|
chip: {
|
|
103
130
|
minHeight: 18,
|
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
CalendarMode,
|
|
34
34
|
CreateGhostArgs,
|
|
35
35
|
EventKeyExtractor,
|
|
36
|
+
MonthDateInfo,
|
|
36
37
|
RenderEvent,
|
|
37
38
|
RenderEventArgs,
|
|
38
39
|
WeekStartsOn,
|
|
@@ -42,11 +43,13 @@ import {
|
|
|
42
43
|
type DateRange,
|
|
43
44
|
type EventAccessibilityLabeler,
|
|
44
45
|
eventsInTimeZone,
|
|
46
|
+
fromZonedRange,
|
|
47
|
+
fromZonedTime,
|
|
48
|
+
zonedDragBounds,
|
|
49
|
+
zonedEventSource,
|
|
45
50
|
expandRecurringEvents,
|
|
46
51
|
type WeekdayFormat,
|
|
47
52
|
getViewDays,
|
|
48
|
-
} from "@super-calendar/core";
|
|
49
|
-
import {
|
|
50
53
|
type CalendarHandle,
|
|
51
54
|
type CalendarLabels,
|
|
52
55
|
resolveCalendarLabels,
|
|
@@ -143,8 +146,9 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
143
146
|
*/
|
|
144
147
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
145
148
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
149
|
+
* Content inside the drag-to-create preview in time grids, month, and multiweek.
|
|
150
|
+
* Month grids receive an all-day range with an exclusive end, repeated for
|
|
151
|
+
* each row the span covers. Requires `onCreateEvent`.
|
|
148
152
|
*/
|
|
149
153
|
renderCreateGhost?: ComponentType<CreateGhostArgs>;
|
|
150
154
|
/**
|
|
@@ -196,9 +200,10 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
196
200
|
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
197
201
|
hiddenDays?: number[];
|
|
198
202
|
/**
|
|
199
|
-
* Fixed "now" instant for the current-time indicator (doesn't tick)
|
|
200
|
-
*
|
|
201
|
-
*
|
|
203
|
+
* Fixed "now" instant for the current-time indicator (doesn't tick) and for
|
|
204
|
+
* the day highlighted as today in every mode, e.g. a server-synced clock.
|
|
205
|
+
* Defaults to the device clock, shifted into `timeZone` when one is set so
|
|
206
|
+
* both match the displayed events.
|
|
202
207
|
*/
|
|
203
208
|
now?: Date;
|
|
204
209
|
/** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
@@ -347,7 +352,9 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
347
352
|
/**
|
|
348
353
|
* Display events in this IANA time zone (e.g. `"America/New_York"`), DST-correct
|
|
349
354
|
* and independent of the device zone. Display-only: it shifts the wall-clock the
|
|
350
|
-
* grid lays out from, it doesn't change your `Date`s
|
|
355
|
+
* grid lays out from, it doesn't change your `Date`s, and callbacks report your
|
|
356
|
+
* own events and real instants. All-day events stay on their days. Uses
|
|
357
|
+
* `eventsInTimeZone`.
|
|
351
358
|
*/
|
|
352
359
|
timeZone?: string;
|
|
353
360
|
/** Highlight this date (header/cell/agenda) instead of the real "today". */
|
|
@@ -370,10 +377,11 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
|
|
|
370
377
|
renderHeaderForMonthView?: (weekDays: Date[]) => React.ReactNode;
|
|
371
378
|
/**
|
|
372
379
|
* Month mode only: replace the default date badge in each day cell. Receives
|
|
373
|
-
* the day
|
|
380
|
+
* the day and its state (`isCurrentMonth`, `isToday`, `isSelected`,
|
|
381
|
+
* `isDisabled`); return your own date label (e.g. a number with a dot or badge).
|
|
374
382
|
* Event chips and the "+N more" label still render below it.
|
|
375
383
|
*/
|
|
376
|
-
renderCustomDateForMonth?: (date: Date) => React.ReactNode;
|
|
384
|
+
renderCustomDateForMonth?: (date: Date, info: MonthDateInfo) => React.ReactNode;
|
|
377
385
|
/** Drawn between rows of the `schedule` (agenda) list. */
|
|
378
386
|
itemSeparatorComponent?: React.ComponentType<unknown> | null;
|
|
379
387
|
};
|
|
@@ -609,7 +617,7 @@ function CalendarInner<T>(
|
|
|
609
617
|
const displayEvents = useMemo(() => {
|
|
610
618
|
let out = events;
|
|
611
619
|
if (out.some((e) => e.recurrence)) {
|
|
612
|
-
|
|
620
|
+
const [start, end] = expansionRange(
|
|
613
621
|
mode,
|
|
614
622
|
date,
|
|
615
623
|
weekStartsOn,
|
|
@@ -617,13 +625,13 @@ function CalendarInner<T>(
|
|
|
617
625
|
weekEndsOn,
|
|
618
626
|
numberOfWeeks,
|
|
619
627
|
);
|
|
620
|
-
//
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
628
|
+
// The range is the days on screen, which under a display zone are that
|
|
629
|
+
// zone's days: expand on its clock, over the instants those days cover.
|
|
630
|
+
out = timeZone
|
|
631
|
+
? expandRecurringEvents(out, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone), {
|
|
632
|
+
timeZone,
|
|
633
|
+
})
|
|
634
|
+
: expandRecurringEvents(out, start, end);
|
|
627
635
|
}
|
|
628
636
|
if (timeZone) out = eventsInTimeZone(out, timeZone);
|
|
629
637
|
return out;
|
|
@@ -640,22 +648,81 @@ function CalendarInner<T>(
|
|
|
640
648
|
]);
|
|
641
649
|
|
|
642
650
|
// Swallow presses on disabled events once, so every view inherits the guard.
|
|
651
|
+
// With a display zone the views hold wall-clock copies of the events, so hand
|
|
652
|
+
// back the consumer's own event. Without one, events pass through untouched,
|
|
653
|
+
// including copies the consumer zoned themselves.
|
|
643
654
|
const handlePressEvent = useCallback(
|
|
644
655
|
(event: CalendarEvent<T>) => {
|
|
645
|
-
if (!event.disabled) onPressEvent(event);
|
|
656
|
+
if (!event.disabled) onPressEvent(timeZone ? zonedEventSource(event) : event);
|
|
646
657
|
},
|
|
647
|
-
[onPressEvent],
|
|
658
|
+
[onPressEvent, timeZone],
|
|
648
659
|
);
|
|
649
660
|
const handleLongPressEvent = useMemo(
|
|
650
661
|
() =>
|
|
651
662
|
onLongPressEvent
|
|
652
663
|
? (event: CalendarEvent<T>) => {
|
|
653
|
-
if (!event.disabled) onLongPressEvent(event);
|
|
664
|
+
if (!event.disabled) onLongPressEvent(timeZone ? zonedEventSource(event) : event);
|
|
654
665
|
}
|
|
655
666
|
: undefined,
|
|
656
|
-
[onLongPressEvent],
|
|
667
|
+
[onLongPressEvent, timeZone],
|
|
657
668
|
);
|
|
658
669
|
|
|
670
|
+
// The views also report wall-clock dates under a display zone. Convert them to
|
|
671
|
+
// real instants. Whole days (`onPressDay`, a month sweep, ...) stay
|
|
672
|
+
// device-local dates, as `date` is, so only the time grid's cell callbacks
|
|
673
|
+
// convert.
|
|
674
|
+
// A time-grid move keeps the event's elapsed duration; a month drop keeps the
|
|
675
|
+
// clock time of both edges.
|
|
676
|
+
const timeGridMode = mode !== "month" && mode !== "multiweek";
|
|
677
|
+
const zoned = useMemo(() => {
|
|
678
|
+
if (!timeZone) {
|
|
679
|
+
return {
|
|
680
|
+
onDragStart,
|
|
681
|
+
onDragEvent,
|
|
682
|
+
onPressMore,
|
|
683
|
+
onPressTime: onPressCell,
|
|
684
|
+
onLongPressTime: onLongPressCell,
|
|
685
|
+
onCreateTimed: onCreateEvent,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const instant = (wallClock: Date) => fromZonedTime(wallClock, timeZone);
|
|
689
|
+
return {
|
|
690
|
+
onDragStart:
|
|
691
|
+
onDragStart && ((event: CalendarEvent<T>) => onDragStart(zonedEventSource(event))),
|
|
692
|
+
onDragEvent:
|
|
693
|
+
onDragEvent &&
|
|
694
|
+
((event: CalendarEvent<T>, start: Date, end: Date) => {
|
|
695
|
+
const bounds = zonedDragBounds(event, start, end, { keepDuration: timeGridMode });
|
|
696
|
+
// An edge dropped into an hour the zone's clock skips can leave no
|
|
697
|
+
// usable span; reject the drop, so the event snaps back.
|
|
698
|
+
if (!bounds) return false;
|
|
699
|
+
return onDragEvent(zonedEventSource(event), bounds.start, bounds.end);
|
|
700
|
+
}),
|
|
701
|
+
onPressMore:
|
|
702
|
+
onPressMore &&
|
|
703
|
+
((dayEvents: CalendarEvent<T>[], day: Date) =>
|
|
704
|
+
onPressMore(dayEvents.map(zonedEventSource), day)),
|
|
705
|
+
onPressTime: onPressCell && ((time: Date) => onPressCell(instant(time))),
|
|
706
|
+
onLongPressTime: onLongPressCell && ((time: Date) => onLongPressCell(instant(time))),
|
|
707
|
+
onCreateTimed:
|
|
708
|
+
onCreateEvent &&
|
|
709
|
+
((start: Date, end: Date) => {
|
|
710
|
+
// A sweep that collapses inside a skipped hour creates nothing.
|
|
711
|
+
const range = fromZonedRange(start, end, timeZone);
|
|
712
|
+
if (range) onCreateEvent(range.start, range.end);
|
|
713
|
+
}),
|
|
714
|
+
};
|
|
715
|
+
}, [
|
|
716
|
+
timeZone,
|
|
717
|
+
timeGridMode,
|
|
718
|
+
onDragStart,
|
|
719
|
+
onDragEvent,
|
|
720
|
+
onPressMore,
|
|
721
|
+
onPressCell,
|
|
722
|
+
onLongPressCell,
|
|
723
|
+
onCreateEvent,
|
|
724
|
+
]);
|
|
725
|
+
|
|
659
726
|
// Echo every date change and, when asked, the full visible range derived from it.
|
|
660
727
|
const handleChangeDate = useCallback(
|
|
661
728
|
(next: Date) => {
|
|
@@ -760,6 +827,8 @@ function CalendarInner<T>(
|
|
|
760
827
|
hiddenDays={hiddenDays}
|
|
761
828
|
weekdayFormat={weekdayFormat}
|
|
762
829
|
locale={locale}
|
|
830
|
+
now={now}
|
|
831
|
+
timeZone={timeZone}
|
|
763
832
|
labels={labels}
|
|
764
833
|
sortedMonthView={sortedMonthView}
|
|
765
834
|
moreLabel={moreLabel}
|
|
@@ -778,11 +847,12 @@ function CalendarInner<T>(
|
|
|
778
847
|
onPressCell={onPressCell}
|
|
779
848
|
onPressEvent={handlePressEvent}
|
|
780
849
|
onLongPressEvent={handleLongPressEvent}
|
|
781
|
-
onPressMore={onPressMore}
|
|
850
|
+
onPressMore={zoned.onPressMore}
|
|
782
851
|
onCreateEvent={onCreateEvent}
|
|
852
|
+
renderCreateGhost={renderCreateGhost}
|
|
783
853
|
onSelectDrag={onSelectDrag}
|
|
784
|
-
onDragEvent={onDragEvent}
|
|
785
|
-
onDragStart={onDragStart}
|
|
854
|
+
onDragEvent={zoned.onDragEvent}
|
|
855
|
+
onDragStart={zoned.onDragStart}
|
|
786
856
|
eventStartEditable={eventStartEditable}
|
|
787
857
|
eventOverlap={eventOverlap}
|
|
788
858
|
selectedDates={selectedDates}
|
|
@@ -805,6 +875,8 @@ function CalendarInner<T>(
|
|
|
805
875
|
weekStartsOn={weekStartsOn}
|
|
806
876
|
hiddenDays={hiddenDays}
|
|
807
877
|
locale={locale}
|
|
878
|
+
now={now}
|
|
879
|
+
timeZone={timeZone}
|
|
808
880
|
labels={labels}
|
|
809
881
|
activeDate={activeDate}
|
|
810
882
|
selectedDates={selectedDates}
|
|
@@ -823,6 +895,8 @@ function CalendarInner<T>(
|
|
|
823
895
|
<Agenda
|
|
824
896
|
events={displayEvents}
|
|
825
897
|
locale={locale}
|
|
898
|
+
now={now}
|
|
899
|
+
timeZone={timeZone}
|
|
826
900
|
renderEvent={resolvedRenderEvent}
|
|
827
901
|
keyExtractor={keyExtractor}
|
|
828
902
|
onPressEvent={handlePressEvent}
|
|
@@ -888,14 +962,14 @@ function CalendarInner<T>(
|
|
|
888
962
|
swipeEnabled={swipeEnabled}
|
|
889
963
|
onPressEvent={handlePressEvent}
|
|
890
964
|
onLongPressEvent={handleLongPressEvent}
|
|
891
|
-
onDragEvent={onDragEvent}
|
|
965
|
+
onDragEvent={zoned.onDragEvent}
|
|
892
966
|
showDragHandle={showDragHandle}
|
|
893
|
-
onDragStart={onDragStart}
|
|
967
|
+
onDragStart={zoned.onDragStart}
|
|
894
968
|
dragStepMinutes={dragStepMinutes}
|
|
895
|
-
onPressCell={
|
|
969
|
+
onPressCell={zoned.onPressTime}
|
|
896
970
|
resetPageOnPressCell={resetPageOnPressCell}
|
|
897
|
-
onLongPressCell={
|
|
898
|
-
onCreateEvent={
|
|
971
|
+
onLongPressCell={zoned.onLongPressTime}
|
|
972
|
+
onCreateEvent={zoned.onCreateTimed}
|
|
899
973
|
renderCreateGhost={renderCreateGhost}
|
|
900
974
|
onPressDateHeader={onPressDateHeader}
|
|
901
975
|
onChangeDate={handleChangeDate}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { memo, useCallback, useLayoutEffect, useRef, type ComponentRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
type LayoutChangeEvent,
|
|
4
|
+
type LayoutRectangle,
|
|
5
|
+
Platform,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
View,
|
|
9
|
+
type StyleProp,
|
|
10
|
+
type ViewStyle,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import type { ResolvedSlot } from "../utils/slots";
|
|
13
|
+
|
|
14
|
+
export interface MonthCellGeometry {
|
|
15
|
+
minimumHeight: number;
|
|
16
|
+
top: number;
|
|
17
|
+
bottom: number;
|
|
18
|
+
gap: number;
|
|
19
|
+
overlayTop: number;
|
|
20
|
+
weekMargin: number;
|
|
21
|
+
weekMarginTop: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type ProbeView = ComponentRef<typeof View>;
|
|
25
|
+
type Part = "frame" | "row" | "cell" | "date" | "lane" | "overlay";
|
|
26
|
+
const MARKER_HEIGHT = 1;
|
|
27
|
+
const hiddenProbeProps = {
|
|
28
|
+
pointerEvents: "none",
|
|
29
|
+
accessible: false,
|
|
30
|
+
accessibilityElementsHidden: true,
|
|
31
|
+
importantForAccessibility: "no-hide-descendants",
|
|
32
|
+
...(Platform.OS === "web" ? { "aria-hidden": true, inert: "inert" } : {}),
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
// Zero-height weeks leave only the grid's padding, borders and gaps. The outer
|
|
36
|
+
// box also includes its margins. Neither measurement depends on the drawn rows.
|
|
37
|
+
export const MonthGridSpacingProbe = memo(function MonthGridSpacingProbe({
|
|
38
|
+
grid,
|
|
39
|
+
weeks,
|
|
40
|
+
onInnerHeight,
|
|
41
|
+
onOuterHeight,
|
|
42
|
+
}: {
|
|
43
|
+
grid: ResolvedSlot<ViewStyle>;
|
|
44
|
+
weeks: number;
|
|
45
|
+
onInnerHeight: (height: number) => void;
|
|
46
|
+
onOuterHeight: (height: number) => void;
|
|
47
|
+
}) {
|
|
48
|
+
return (
|
|
49
|
+
<View
|
|
50
|
+
{...hiddenProbeProps}
|
|
51
|
+
style={styles.frame}
|
|
52
|
+
onLayout={(e) => onOuterHeight(e.nativeEvent.layout.height)}
|
|
53
|
+
>
|
|
54
|
+
<View
|
|
55
|
+
{...grid}
|
|
56
|
+
style={[grid.style, styles.gridSpacing]}
|
|
57
|
+
onLayout={(e) => onInnerHeight(e.nativeEvent.layout.height)}
|
|
58
|
+
>
|
|
59
|
+
{Array.from({ length: weeks }, (_, index) => (
|
|
60
|
+
<View key={index} style={styles.emptyWeek} />
|
|
61
|
+
))}
|
|
62
|
+
</View>
|
|
63
|
+
</View>
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// The two markers take the place of the date and the first event. Their natural
|
|
68
|
+
// positions include spacing applied by a class, including on the enclosing week.
|
|
69
|
+
// The probe has no fixed height, so measuring it cannot grow the visible rows.
|
|
70
|
+
export const MonthCellProbe = memo(function MonthCellProbe({
|
|
71
|
+
id,
|
|
72
|
+
week,
|
|
73
|
+
day,
|
|
74
|
+
cellStyle,
|
|
75
|
+
dayWidth,
|
|
76
|
+
weekWidth,
|
|
77
|
+
onMeasure,
|
|
78
|
+
}: {
|
|
79
|
+
id: string;
|
|
80
|
+
week: ResolvedSlot<ViewStyle>;
|
|
81
|
+
day: ResolvedSlot<ViewStyle>;
|
|
82
|
+
cellStyle: StyleProp<ViewStyle>;
|
|
83
|
+
dayWidth: number;
|
|
84
|
+
weekWidth: number;
|
|
85
|
+
onMeasure: (id: string, geometry: MonthCellGeometry) => void;
|
|
86
|
+
}) {
|
|
87
|
+
const layouts = useRef<Partial<Record<Part, LayoutRectangle>>>({});
|
|
88
|
+
const nodes = useRef<Partial<Record<Part, ProbeView | null>>>({});
|
|
89
|
+
const report = useCallback(
|
|
90
|
+
(
|
|
91
|
+
height: number,
|
|
92
|
+
row: Pick<LayoutRectangle, "y" | "height">,
|
|
93
|
+
top: number,
|
|
94
|
+
laneTop: number,
|
|
95
|
+
laneHeight: number,
|
|
96
|
+
overlayTop: number,
|
|
97
|
+
) => {
|
|
98
|
+
if (height > 0)
|
|
99
|
+
onMeasure(id, {
|
|
100
|
+
minimumHeight: height,
|
|
101
|
+
top,
|
|
102
|
+
gap: Math.max(0, laneTop - top - MARKER_HEIGHT),
|
|
103
|
+
bottom: height - laneTop - laneHeight,
|
|
104
|
+
overlayTop,
|
|
105
|
+
weekMargin: height - row.height,
|
|
106
|
+
weekMarginTop: row.y,
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
[id, onMeasure],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// React Native Web's onLayout observes resizing. Changing padding can move both
|
|
113
|
+
// markers without resizing them. Read their layout offsets before ancestor transforms.
|
|
114
|
+
const readWeb = useCallback(() => {
|
|
115
|
+
if (Platform.OS !== "web" || typeof HTMLElement === "undefined") return false;
|
|
116
|
+
const frame = nodes.current.frame;
|
|
117
|
+
if (!(frame instanceof HTMLElement)) return false;
|
|
118
|
+
const layout = (part: Part) => {
|
|
119
|
+
const node = nodes.current[part];
|
|
120
|
+
if (!(node instanceof HTMLElement)) return;
|
|
121
|
+
let y = 0;
|
|
122
|
+
let current: HTMLElement = node;
|
|
123
|
+
while (current !== frame) {
|
|
124
|
+
const parent = current.offsetParent;
|
|
125
|
+
if (!(parent instanceof HTMLElement)) return;
|
|
126
|
+
y += current.offsetTop + parent.clientTop;
|
|
127
|
+
current = parent;
|
|
128
|
+
}
|
|
129
|
+
return { y, height: node.offsetHeight };
|
|
130
|
+
};
|
|
131
|
+
const row = layout("row"),
|
|
132
|
+
date = layout("date"),
|
|
133
|
+
lane = layout("lane"),
|
|
134
|
+
overlay = layout("overlay");
|
|
135
|
+
if (!row || !date || !lane || !overlay) return false;
|
|
136
|
+
report(frame.offsetHeight, row, date.y, lane.y, lane.height, overlay.y);
|
|
137
|
+
return true;
|
|
138
|
+
}, [report]);
|
|
139
|
+
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
readWeb();
|
|
142
|
+
}, [readWeb, week, day, cellStyle, dayWidth, weekWidth]);
|
|
143
|
+
|
|
144
|
+
function observe(part: Part) {
|
|
145
|
+
return {
|
|
146
|
+
...(Platform.OS === "web" && {
|
|
147
|
+
ref: (node: ProbeView | null) => {
|
|
148
|
+
nodes.current[part] = node;
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
onLayout: (event: LayoutChangeEvent) => {
|
|
152
|
+
if (readWeb()) return;
|
|
153
|
+
layouts.current[part] = event.nativeEvent.layout;
|
|
154
|
+
const { frame, row, cell, date, lane, overlay } = layouts.current;
|
|
155
|
+
if (!frame || !row || !cell || !date || !lane || !overlay) return;
|
|
156
|
+
const cellTop = row.y + cell.y;
|
|
157
|
+
report(
|
|
158
|
+
frame.height,
|
|
159
|
+
row,
|
|
160
|
+
cellTop + date.y,
|
|
161
|
+
cellTop + lane.y,
|
|
162
|
+
lane.height,
|
|
163
|
+
row.y + overlay.y,
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return (
|
|
169
|
+
<View {...observe("frame")} style={styles.frame} collapsable={false} {...hiddenProbeProps}>
|
|
170
|
+
<View
|
|
171
|
+
{...observe("row")}
|
|
172
|
+
{...week}
|
|
173
|
+
style={[week.style, styles.intrinsic, { width: weekWidth }]}
|
|
174
|
+
collapsable={false}
|
|
175
|
+
>
|
|
176
|
+
<TouchableOpacity
|
|
177
|
+
{...day}
|
|
178
|
+
style={[day.style, cellStyle, styles.measuredDay, { width: dayWidth }]}
|
|
179
|
+
disabled
|
|
180
|
+
onLayout={observe("cell").onLayout}
|
|
181
|
+
>
|
|
182
|
+
<View {...observe("date")} style={styles.marker} collapsable={false} />
|
|
183
|
+
<View {...observe("lane")} style={styles.laneMarker} collapsable={false} />
|
|
184
|
+
</TouchableOpacity>
|
|
185
|
+
<View {...observe("overlay")} style={StyleSheet.absoluteFill} collapsable={false} />
|
|
186
|
+
</View>
|
|
187
|
+
</View>
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const styles = StyleSheet.create({
|
|
192
|
+
frame: { position: "absolute", top: 0, left: 0, right: 0, opacity: 0 },
|
|
193
|
+
gridSpacing: { height: "auto", minHeight: 0, maxHeight: "auto", flex: 0 },
|
|
194
|
+
emptyWeek: { height: 0 },
|
|
195
|
+
intrinsic: { height: "auto", minHeight: 0 },
|
|
196
|
+
// The visible cell supplies the width, including changes from gaps and hidden days.
|
|
197
|
+
measuredDay: { justifyContent: "flex-start", alignSelf: "stretch", flex: 0, flexBasis: "auto" },
|
|
198
|
+
marker: { height: MARKER_HEIGHT },
|
|
199
|
+
// Fill space reserved by the day height so it does not count as bottom padding.
|
|
200
|
+
laneMarker: { height: MARKER_HEIGHT, flexGrow: 1 },
|
|
201
|
+
});
|
|
@@ -44,9 +44,11 @@ import {
|
|
|
44
44
|
type EventAccessibilityLabeler,
|
|
45
45
|
type WeekdayFormat,
|
|
46
46
|
isDateSelectable,
|
|
47
|
+
type CalendarLabels,
|
|
48
|
+
buildMonthWeeks,
|
|
49
|
+
getWeekDays,
|
|
50
|
+
weekdayFormatToken,
|
|
47
51
|
} from "@super-calendar/core";
|
|
48
|
-
import type { CalendarLabels } from "@super-calendar/core";
|
|
49
|
-
import { buildMonthWeeks, getWeekDays, weekdayFormatToken } from "@super-calendar/core";
|
|
50
52
|
import { createSlots, type SlotStyleProps } from "../utils/slots";
|
|
51
53
|
import { DefaultMonthEvent } from "./DefaultMonthEvent";
|
|
52
54
|
import { MonthView, type MonthViewSlot } from "./MonthView";
|