@super-calendar/native 2.0.0 → 2.1.3

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/index.d.mts CHANGED
@@ -1,11 +1,12 @@
1
- import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, _ as TimeGridMode, a as MonthPagerProps, b as CalendarThemeProvider, c as BusinessHours, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, m as RecurrenceRule, n as MonthList, o as MonthView, p as RecurrenceFrequency, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-CpRoOloh.mjs";
1
+ import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, _ as TimeGridMode, a as MonthPagerProps, b as CalendarThemeProvider, c as BusinessHours, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, m as RecurrenceRule, n as MonthList, o as MonthView, p as RecurrenceFrequency, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-D2s0x2Bn.mjs";
2
2
  import { Locale } from "date-fns";
3
- import { ComponentType } from "react";
3
+ import { ComponentType, ReactElement } from "react";
4
4
  import { SharedValue, useSharedValue } from "react-native-reanimated";
5
5
  import { DateRange, DateSelectionConstraints, DaySelectionState, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, UseDateRangeOptions, UseMonthGridOptions, buildMonthGrid, buildMonthWeeks, daySelectionState, eventsInTimeZone, expandRecurringEvents, getIsToday, getViewDays, getWeekDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, minutesIntoDay, nextDateRange, toZonedTime, useDateRange, useMonthGrid } from "@super-calendar/core";
6
6
  import { StyleProp, ViewStyle } from "react-native";
7
7
 
8
8
  //#region src/components/TimeGrid.d.ts
9
+ /** Default height in pixels of one hour row on the time grid. */
9
10
  declare const DEFAULT_HOUR_HEIGHT = 48;
10
11
  /**
11
12
  * Called when an event is dragged (moved or resized) to new start/end times.
@@ -22,6 +23,7 @@ type EventDragHandler<T> = (event: CalendarEvent<T>, start: Date, end: Date) =>
22
23
  type EventDragStartHandler<T> = (event: CalendarEvent<T>) => void;
23
24
  /** Replace the hour-axis label. Receives the hour (0–23) and the `ampm` flag. */
24
25
  type HourRenderer = (hour: number, ampm: boolean) => React.ReactNode;
26
+ /** Props for {@link TimeGrid}, the day/week timetable view. */
25
27
  type TimeGridProps<T> = {
26
28
  mode: TimeGridMode; /** Day columns to show in `custom` mode. Ignored by day/3days/week. Default 1. */
27
29
  numberOfDays?: number;
@@ -132,10 +134,30 @@ declare function TimeGridInner<T>({
132
134
  onPressDateHeader,
133
135
  onChangeDate,
134
136
  renderHeader
135
- }: TimeGridProps<T>): import("react").JSX.Element;
137
+ }: TimeGridProps<T>): ReactElement;
138
+ /**
139
+ * The timetable view used in day, 3days, week, and custom modes: an
140
+ * hour-by-hour grid with positioned event boxes, an all-day lane, pinch-to-zoom
141
+ * density, and optional drag-to-move/resize/create. Pages horizontally between
142
+ * date ranges, reporting the committed range through `onChangeDate`.
143
+ *
144
+ * @example
145
+ * ```tsx
146
+ * import { TimeGrid } from "react-native-super-calendar";
147
+ *
148
+ * <TimeGrid
149
+ * mode="week"
150
+ * date={date}
151
+ * events={events}
152
+ * onChangeDate={setDate}
153
+ * onPressEvent={(e) => console.log(e.title)}
154
+ * />
155
+ * ```
156
+ */
136
157
  declare const TimeGrid: typeof TimeGridInner;
137
158
  //#endregion
138
159
  //#region src/components/Calendar.d.ts
160
+ /** Props for the {@link Calendar} component. */
139
161
  type CalendarProps<T> = {
140
162
  events: CalendarEvent<T>[];
141
163
  mode: CalendarMode;
@@ -263,6 +285,32 @@ type CalendarProps<T> = {
263
285
  renderCustomDateForMonth?: (date: Date) => React.ReactNode; /** Drawn between rows of the `schedule` (agenda) list. */
264
286
  itemSeparatorComponent?: React.ComponentType<unknown> | null;
265
287
  };
288
+ /**
289
+ * The top-level calendar. Switches between month, week, day, 3days, custom, and
290
+ * schedule modes, and is gesture-driven and virtualized. It is a controlled
291
+ * component: pass `date` and `mode` and update them from `onChangeDate`.
292
+ *
293
+ * @example
294
+ * ```tsx
295
+ * import { Calendar, type CalendarEvent } from "react-native-super-calendar";
296
+ *
297
+ * function MyCalendar() {
298
+ * const [date, setDate] = useState(new Date());
299
+ * const events: CalendarEvent[] = [
300
+ * { title: "Standup", start: new Date(), end: new Date() },
301
+ * ];
302
+ * return (
303
+ * <Calendar
304
+ * mode="week"
305
+ * date={date}
306
+ * events={events}
307
+ * onChangeDate={setDate}
308
+ * onPressEvent={(e) => console.log(e.title)}
309
+ * />
310
+ * );
311
+ * }
312
+ * ```
313
+ */
266
314
  declare function Calendar<T>({
267
315
  events,
268
316
  mode,
@@ -329,9 +377,10 @@ declare function Calendar<T>({
329
377
  renderHeaderForMonthView,
330
378
  renderCustomDateForMonth,
331
379
  itemSeparatorComponent
332
- }: CalendarProps<T>): import("react").JSX.Element;
380
+ }: CalendarProps<T>): ReactElement;
333
381
  //#endregion
334
382
  //#region src/components/Agenda.d.ts
383
+ /** Props for {@link Agenda}, the day-grouped list view of events. */
335
384
  type AgendaProps<T> = {
336
385
  events: CalendarEvent<T>[];
337
386
  locale?: Locale;
@@ -358,7 +407,7 @@ declare function Agenda<T>({
358
407
  onPressDay,
359
408
  activeDate,
360
409
  itemSeparatorComponent
361
- }: AgendaProps<T>): import("react").JSX.Element;
410
+ }: AgendaProps<T>): ReactElement;
362
411
  //#endregion
363
412
  //#region src/components/DefaultEvent.d.ts
364
413
  /**
@@ -381,6 +430,6 @@ declare function DefaultEvent<T>({
381
430
  cellStyle,
382
431
  onPress,
383
432
  onLongPress
384
- }: RenderEventArgs<T>): import("react").JSX.Element;
433
+ }: RenderEventArgs<T>): ReactElement;
385
434
  //#endregion
386
435
  export { Agenda, type AgendaProps, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarTheme, CalendarThemeProvider, DEFAULT_HOUR_HEIGHT, type DateRange, type DateSelectionConstraints, type DaySelectionState, DefaultEvent, DefaultMonthEvent, type EventDragHandler, type EventDragStartHandler, type EventKeyExtractor, type HourRenderer, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type PositionedEvent, type RecurrenceFrequency, type RecurrenceRule, type RenderEvent, type RenderEventArgs, TimeGrid, type TimeGridMode, type TimeGridProps, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, eventsInTimeZone, expandRecurringEvents, getIsToday, getViewDays, getWeekDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, mergeTheme, minutesIntoDay, nextDateRange, toZonedTime, useCalendarTheme, useDateRange, useMonthGrid };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, _ as TimeGridMode, a as MonthPagerProps, b as CalendarThemeProvider, c as BusinessHours, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, m as RecurrenceRule, n as MonthList, o as MonthView, p as RecurrenceFrequency, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-86XCNCge.js";
1
+ import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, _ as TimeGridMode, a as MonthPagerProps, b as CalendarThemeProvider, c as BusinessHours, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, m as RecurrenceRule, n as MonthList, o as MonthView, p as RecurrenceFrequency, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-DaTEIcRs.js";
2
2
  import { Locale } from "date-fns";
3
+ import { ComponentType, ReactElement } from "react";
3
4
  import { StyleProp, ViewStyle } from "react-native";
4
5
  import { SharedValue, useSharedValue } from "react-native-reanimated";
5
6
  import { DateRange, DateSelectionConstraints, DaySelectionState, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, UseDateRangeOptions, UseMonthGridOptions, buildMonthGrid, buildMonthWeeks, daySelectionState, eventsInTimeZone, expandRecurringEvents, getIsToday, getViewDays, getWeekDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, minutesIntoDay, nextDateRange, toZonedTime, useDateRange, useMonthGrid } from "@super-calendar/core";
6
- import { ComponentType } from "react";
7
7
 
8
8
  //#region src/components/TimeGrid.d.ts
9
+ /** Default height in pixels of one hour row on the time grid. */
9
10
  declare const DEFAULT_HOUR_HEIGHT = 48;
10
11
  /**
11
12
  * Called when an event is dragged (moved or resized) to new start/end times.
@@ -22,6 +23,7 @@ type EventDragHandler<T> = (event: CalendarEvent<T>, start: Date, end: Date) =>
22
23
  type EventDragStartHandler<T> = (event: CalendarEvent<T>) => void;
23
24
  /** Replace the hour-axis label. Receives the hour (0–23) and the `ampm` flag. */
24
25
  type HourRenderer = (hour: number, ampm: boolean) => React.ReactNode;
26
+ /** Props for {@link TimeGrid}, the day/week timetable view. */
25
27
  type TimeGridProps<T> = {
26
28
  mode: TimeGridMode; /** Day columns to show in `custom` mode. Ignored by day/3days/week. Default 1. */
27
29
  numberOfDays?: number;
@@ -132,10 +134,30 @@ declare function TimeGridInner<T>({
132
134
  onPressDateHeader,
133
135
  onChangeDate,
134
136
  renderHeader
135
- }: TimeGridProps<T>): import("react").JSX.Element;
137
+ }: TimeGridProps<T>): ReactElement;
138
+ /**
139
+ * The timetable view used in day, 3days, week, and custom modes: an
140
+ * hour-by-hour grid with positioned event boxes, an all-day lane, pinch-to-zoom
141
+ * density, and optional drag-to-move/resize/create. Pages horizontally between
142
+ * date ranges, reporting the committed range through `onChangeDate`.
143
+ *
144
+ * @example
145
+ * ```tsx
146
+ * import { TimeGrid } from "react-native-super-calendar";
147
+ *
148
+ * <TimeGrid
149
+ * mode="week"
150
+ * date={date}
151
+ * events={events}
152
+ * onChangeDate={setDate}
153
+ * onPressEvent={(e) => console.log(e.title)}
154
+ * />
155
+ * ```
156
+ */
136
157
  declare const TimeGrid: typeof TimeGridInner;
137
158
  //#endregion
138
159
  //#region src/components/Calendar.d.ts
160
+ /** Props for the {@link Calendar} component. */
139
161
  type CalendarProps<T> = {
140
162
  events: CalendarEvent<T>[];
141
163
  mode: CalendarMode;
@@ -263,6 +285,32 @@ type CalendarProps<T> = {
263
285
  renderCustomDateForMonth?: (date: Date) => React.ReactNode; /** Drawn between rows of the `schedule` (agenda) list. */
264
286
  itemSeparatorComponent?: React.ComponentType<unknown> | null;
265
287
  };
288
+ /**
289
+ * The top-level calendar. Switches between month, week, day, 3days, custom, and
290
+ * schedule modes, and is gesture-driven and virtualized. It is a controlled
291
+ * component: pass `date` and `mode` and update them from `onChangeDate`.
292
+ *
293
+ * @example
294
+ * ```tsx
295
+ * import { Calendar, type CalendarEvent } from "react-native-super-calendar";
296
+ *
297
+ * function MyCalendar() {
298
+ * const [date, setDate] = useState(new Date());
299
+ * const events: CalendarEvent[] = [
300
+ * { title: "Standup", start: new Date(), end: new Date() },
301
+ * ];
302
+ * return (
303
+ * <Calendar
304
+ * mode="week"
305
+ * date={date}
306
+ * events={events}
307
+ * onChangeDate={setDate}
308
+ * onPressEvent={(e) => console.log(e.title)}
309
+ * />
310
+ * );
311
+ * }
312
+ * ```
313
+ */
266
314
  declare function Calendar<T>({
267
315
  events,
268
316
  mode,
@@ -329,9 +377,10 @@ declare function Calendar<T>({
329
377
  renderHeaderForMonthView,
330
378
  renderCustomDateForMonth,
331
379
  itemSeparatorComponent
332
- }: CalendarProps<T>): import("react").JSX.Element;
380
+ }: CalendarProps<T>): ReactElement;
333
381
  //#endregion
334
382
  //#region src/components/Agenda.d.ts
383
+ /** Props for {@link Agenda}, the day-grouped list view of events. */
335
384
  type AgendaProps<T> = {
336
385
  events: CalendarEvent<T>[];
337
386
  locale?: Locale;
@@ -358,7 +407,7 @@ declare function Agenda<T>({
358
407
  onPressDay,
359
408
  activeDate,
360
409
  itemSeparatorComponent
361
- }: AgendaProps<T>): import("react").JSX.Element;
410
+ }: AgendaProps<T>): ReactElement;
362
411
  //#endregion
363
412
  //#region src/components/DefaultEvent.d.ts
364
413
  /**
@@ -381,6 +430,6 @@ declare function DefaultEvent<T>({
381
430
  cellStyle,
382
431
  onPress,
383
432
  onLongPress
384
- }: RenderEventArgs<T>): import("react").JSX.Element;
433
+ }: RenderEventArgs<T>): ReactElement;
385
434
  //#endregion
386
435
  export { Agenda, type AgendaProps, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarTheme, CalendarThemeProvider, DEFAULT_HOUR_HEIGHT, type DateRange, type DateSelectionConstraints, type DaySelectionState, DefaultEvent, DefaultMonthEvent, type EventDragHandler, type EventDragStartHandler, type EventKeyExtractor, type HourRenderer, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type PositionedEvent, type RecurrenceFrequency, type RecurrenceRule, type RenderEvent, type RenderEventArgs, TimeGrid, type TimeGridMode, type TimeGridProps, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, eventsInTimeZone, expandRecurringEvents, getIsToday, getViewDays, getWeekDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, mergeTheme, minutesIntoDay, nextDateRange, toZonedTime, useCalendarTheme, useDateRange, useMonthGrid };
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
- const require_MonthList = require("./MonthList-BCfN-UGz.js");
24
+ const require_MonthList = require("./MonthList-oXiArmbu.js");
25
25
  let date_fns = require("date-fns");
26
26
  let react = require("react");
27
27
  let react_native_reanimated = require("react-native-reanimated");
@@ -368,6 +368,7 @@ const HOURS_PER_DAY = 24;
368
368
  const MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY;
369
369
  const PAGE_WINDOW = 180;
370
370
  const PAGE_VIEWABILITY = { itemVisiblePercentThreshold: 90 };
371
+ /** Default height in pixels of one hour row on the time grid. */
371
372
  const DEFAULT_HOUR_HEIGHT = 48;
372
373
  const DEFAULT_MIN_HOUR_HEIGHT = 32;
373
374
  const DEFAULT_MAX_HOUR_HEIGHT = 160;
@@ -399,14 +400,16 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
399
400
  const moveOffset = (0, react_native_reanimated.useSharedValue)(0);
400
401
  const moveOffsetX = (0, react_native_reanimated.useSharedValue)(0);
401
402
  const resizeDelta = (0, react_native_reanimated.useSharedValue)(0);
402
- const boxHeight = (0, react_native_reanimated.useDerivedValue)(() => Math.max(positioned.durationHours * cellHeight.value + resizeDelta.value, MIN_EVENT_HEIGHT), [positioned.durationHours]);
403
+ const startHours = positioned.startHours;
404
+ const durationHours = positioned.durationHours;
405
+ const boxHeight = (0, react_native_reanimated.useDerivedValue)(() => Math.max(durationHours * cellHeight.value + resizeDelta.value, MIN_EVENT_HEIGHT), [durationHours]);
403
406
  const boxStyle = (0, react_native_reanimated.useAnimatedStyle)(() => ({
404
- top: (positioned.startHours - minHour) * cellHeight.value + moveOffset.value,
407
+ top: (startHours - minHour) * cellHeight.value + moveOffset.value,
405
408
  height: boxHeight.value,
406
409
  transform: [{ translateX: moveOffsetX.value }]
407
410
  }), [
408
- positioned.startHours,
409
- positioned.durationHours,
411
+ startHours,
412
+ durationHours,
410
413
  minHour
411
414
  ]);
412
415
  (0, react.useEffect)(() => {
@@ -663,7 +666,8 @@ function TimetablePageInner({ mode, numberOfDays, date, events, cellHeight, hour
663
666
  isRTL,
664
667
  weekEndsOn
665
668
  ]);
666
- const dayWidth = (width - hourColumnWidth) / days.length;
669
+ const dayCount = days.length;
670
+ const dayWidth = (width - hourColumnWidth) / dayCount;
667
671
  const dayLeft = (dayIndex) => hourColumnWidth + dayIndex * dayWidth;
668
672
  const dayLayouts = (0, react.useMemo)(() => days.map((day) => (0, _super_calendar_core.layoutDayEvents)(events, day)), [days, events]);
669
673
  const cellDateFromTouch = (event) => {
@@ -749,7 +753,7 @@ function TimetablePageInner({ mode, numberOfDays, date, events, cellHeight, hour
749
753
  ]);
750
754
  const createGesture = (0, react.useMemo)(() => {
751
755
  const pan = react_native_gesture_handler.Gesture.Pan().enabled(createEnabled).onStart((event) => {
752
- const idx = days.length === 1 ? 0 : Math.floor(event.x / dayWidth);
756
+ const idx = dayCount === 1 ? 0 : Math.floor(event.x / dayWidth);
753
757
  createDayIndex.value = idx;
754
758
  createStartY.value = event.y;
755
759
  createLeft.value = hourColumnWidth + idx * dayWidth;
@@ -775,7 +779,7 @@ function TimetablePageInner({ mode, numberOfDays, date, events, cellHeight, hour
775
779
  return isWeb ? pan.activeOffsetY([-8, DRAG_ACTIVATE_PX]) : pan.activateAfterLongPress(DRAG_ACTIVATE_MS);
776
780
  }, [
777
781
  createEnabled,
778
- days.length,
782
+ dayCount,
779
783
  dayWidth,
780
784
  hourColumnWidth,
781
785
  heightSource,
@@ -1268,6 +1272,25 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
1268
1272
  ]
1269
1273
  });
1270
1274
  }
1275
+ /**
1276
+ * The timetable view used in day, 3days, week, and custom modes: an
1277
+ * hour-by-hour grid with positioned event boxes, an all-day lane, pinch-to-zoom
1278
+ * density, and optional drag-to-move/resize/create. Pages horizontally between
1279
+ * date ranges, reporting the committed range through `onChangeDate`.
1280
+ *
1281
+ * @example
1282
+ * ```tsx
1283
+ * import { TimeGrid } from "react-native-super-calendar";
1284
+ *
1285
+ * <TimeGrid
1286
+ * mode="week"
1287
+ * date={date}
1288
+ * events={events}
1289
+ * onChangeDate={setDate}
1290
+ * onPressEvent={(e) => console.log(e.title)}
1291
+ * />
1292
+ * ```
1293
+ */
1271
1294
  const TimeGrid = (0, react.memo)(TimeGridInner);
1272
1295
  const DefaultHeader = ({ days, mode, width, hourColumnWidth, showWeekNumber, weekNumberPrefix = "W", locale, activeDate, onPressDateHeader }) => {
1273
1296
  const theme = require_MonthList.useCalendarTheme();
@@ -1431,6 +1454,32 @@ function visibleRange(mode, date, weekStartsOn, numberOfDays, weekEndsOn) {
1431
1454
  const days = (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays, false, weekEndsOn);
1432
1455
  return [(0, date_fns.startOfDay)(days[0]), (0, date_fns.endOfDay)(days[days.length - 1])];
1433
1456
  }
1457
+ /**
1458
+ * The top-level calendar. Switches between month, week, day, 3days, custom, and
1459
+ * schedule modes, and is gesture-driven and virtualized. It is a controlled
1460
+ * component: pass `date` and `mode` and update them from `onChangeDate`.
1461
+ *
1462
+ * @example
1463
+ * ```tsx
1464
+ * import { Calendar, type CalendarEvent } from "react-native-super-calendar";
1465
+ *
1466
+ * function MyCalendar() {
1467
+ * const [date, setDate] = useState(new Date());
1468
+ * const events: CalendarEvent[] = [
1469
+ * { title: "Standup", start: new Date(), end: new Date() },
1470
+ * ];
1471
+ * return (
1472
+ * <Calendar
1473
+ * mode="week"
1474
+ * date={date}
1475
+ * events={events}
1476
+ * onChangeDate={setDate}
1477
+ * onPressEvent={(e) => console.log(e.title)}
1478
+ * />
1479
+ * );
1480
+ * }
1481
+ * ```
1482
+ */
1434
1483
  function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPressEvent, onLongPressEvent, onDragEvent, onDragStart, dragStepMinutes, showDragHandle, onPressDay, onLongPressDay, onPressMore, onPressCell, resetPageOnPressCell, onLongPressCell, onCreateEvent, onPressDateHeader, maxVisibleEventCount, sortedMonthView, moreLabel, showAdjacentMonths, disableMonthEventCellPress, weekStartsOn = 0, numberOfDays, weekEndsOn, renderEvent = DefaultEvent, eventCellStyle, calendarCellStyle, businessHours, keyExtractor = defaultKeyExtractor, theme, cellHeight: cellHeightProp, hourHeight = 48, minHourHeight, maxHourHeight, hourColumnWidth, hideHours, timeslots, showAllDayEventCell, showWeekNumber, weekNumberPrefix, hourComponent, showSixWeeks, swipeEnabled, showVerticalScrollIndicator, verticalScrollEnabled, headerComponent, minHour, maxHour, ampm, showTime, ellipsizeTitle, allDayLabel, scrollOffsetMinutes, showNowIndicator, locale, activeDate, isRTL, freeSwipe, renderTimeGridHeader, renderHeaderForMonthView, renderCustomDateForMonth, itemSeparatorComponent }) {
1435
1484
  const mergedTheme = (0, react.useMemo)(() => require_MonthList.mergeTheme(theme), [theme]);
1436
1485
  const internalCellHeight = (0, react_native_reanimated.useSharedValue)(hourHeight);
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as useWebPagerKeys, c as defaultTheme, i as MonthView, l as mergeTheme, n as DefaultMonthEvent, o as CalendarThemeProvider, r as MonthPager, s as darkTheme, t as MonthList, u as useCalendarTheme } from "./MonthList-CyrEJ_U6.mjs";
1
+ import { a as useWebPagerKeys, c as defaultTheme, i as MonthView, l as mergeTheme, n as DefaultMonthEvent, o as CalendarThemeProvider, r as MonthPager, s as darkTheme, t as MonthList, u as useCalendarTheme } from "./MonthList-DXvjxiyu.mjs";
2
2
  import { addDays, differenceInCalendarDays, endOfDay, endOfMonth, endOfWeek, format, getHours, getISOWeek, getMinutes, isSameDay, startOfDay, startOfMonth, startOfWeek } from "date-fns";
3
3
  import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import Animated, { runOnJS, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useSharedValue } from "react-native-reanimated";
@@ -344,6 +344,7 @@ const HOURS_PER_DAY = 24;
344
344
  const MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY;
345
345
  const PAGE_WINDOW = 180;
346
346
  const PAGE_VIEWABILITY = { itemVisiblePercentThreshold: 90 };
347
+ /** Default height in pixels of one hour row on the time grid. */
347
348
  const DEFAULT_HOUR_HEIGHT = 48;
348
349
  const DEFAULT_MIN_HOUR_HEIGHT = 32;
349
350
  const DEFAULT_MAX_HOUR_HEIGHT = 160;
@@ -375,14 +376,16 @@ function AnimatedEventBox({ positioned, cellHeight, minHour, left, width, dayWid
375
376
  const moveOffset = useSharedValue(0);
376
377
  const moveOffsetX = useSharedValue(0);
377
378
  const resizeDelta = useSharedValue(0);
378
- const boxHeight = useDerivedValue(() => Math.max(positioned.durationHours * cellHeight.value + resizeDelta.value, MIN_EVENT_HEIGHT), [positioned.durationHours]);
379
+ const startHours = positioned.startHours;
380
+ const durationHours = positioned.durationHours;
381
+ const boxHeight = useDerivedValue(() => Math.max(durationHours * cellHeight.value + resizeDelta.value, MIN_EVENT_HEIGHT), [durationHours]);
379
382
  const boxStyle = useAnimatedStyle(() => ({
380
- top: (positioned.startHours - minHour) * cellHeight.value + moveOffset.value,
383
+ top: (startHours - minHour) * cellHeight.value + moveOffset.value,
381
384
  height: boxHeight.value,
382
385
  transform: [{ translateX: moveOffsetX.value }]
383
386
  }), [
384
- positioned.startHours,
385
- positioned.durationHours,
387
+ startHours,
388
+ durationHours,
386
389
  minHour
387
390
  ]);
388
391
  useEffect(() => {
@@ -639,7 +642,8 @@ function TimetablePageInner({ mode, numberOfDays, date, events, cellHeight, hour
639
642
  isRTL,
640
643
  weekEndsOn
641
644
  ]);
642
- const dayWidth = (width - hourColumnWidth) / days.length;
645
+ const dayCount = days.length;
646
+ const dayWidth = (width - hourColumnWidth) / dayCount;
643
647
  const dayLeft = (dayIndex) => hourColumnWidth + dayIndex * dayWidth;
644
648
  const dayLayouts = useMemo(() => days.map((day) => layoutDayEvents$1(events, day)), [days, events]);
645
649
  const cellDateFromTouch = (event) => {
@@ -725,7 +729,7 @@ function TimetablePageInner({ mode, numberOfDays, date, events, cellHeight, hour
725
729
  ]);
726
730
  const createGesture = useMemo(() => {
727
731
  const pan = Gesture.Pan().enabled(createEnabled).onStart((event) => {
728
- const idx = days.length === 1 ? 0 : Math.floor(event.x / dayWidth);
732
+ const idx = dayCount === 1 ? 0 : Math.floor(event.x / dayWidth);
729
733
  createDayIndex.value = idx;
730
734
  createStartY.value = event.y;
731
735
  createLeft.value = hourColumnWidth + idx * dayWidth;
@@ -751,7 +755,7 @@ function TimetablePageInner({ mode, numberOfDays, date, events, cellHeight, hour
751
755
  return isWeb ? pan.activeOffsetY([-8, DRAG_ACTIVATE_PX]) : pan.activateAfterLongPress(DRAG_ACTIVATE_MS);
752
756
  }, [
753
757
  createEnabled,
754
- days.length,
758
+ dayCount,
755
759
  dayWidth,
756
760
  hourColumnWidth,
757
761
  heightSource,
@@ -1244,6 +1248,25 @@ function TimeGridInner({ mode, numberOfDays = 1, weekEndsOn, date, events, cellH
1244
1248
  ]
1245
1249
  });
1246
1250
  }
1251
+ /**
1252
+ * The timetable view used in day, 3days, week, and custom modes: an
1253
+ * hour-by-hour grid with positioned event boxes, an all-day lane, pinch-to-zoom
1254
+ * density, and optional drag-to-move/resize/create. Pages horizontally between
1255
+ * date ranges, reporting the committed range through `onChangeDate`.
1256
+ *
1257
+ * @example
1258
+ * ```tsx
1259
+ * import { TimeGrid } from "react-native-super-calendar";
1260
+ *
1261
+ * <TimeGrid
1262
+ * mode="week"
1263
+ * date={date}
1264
+ * events={events}
1265
+ * onChangeDate={setDate}
1266
+ * onPressEvent={(e) => console.log(e.title)}
1267
+ * />
1268
+ * ```
1269
+ */
1247
1270
  const TimeGrid = memo(TimeGridInner);
1248
1271
  const DefaultHeader = ({ days, mode, width, hourColumnWidth, showWeekNumber, weekNumberPrefix = "W", locale, activeDate, onPressDateHeader }) => {
1249
1272
  const theme = useCalendarTheme();
@@ -1407,6 +1430,32 @@ function visibleRange(mode, date, weekStartsOn, numberOfDays, weekEndsOn) {
1407
1430
  const days = getViewDays$1(mode, date, weekStartsOn, numberOfDays, false, weekEndsOn);
1408
1431
  return [startOfDay(days[0]), endOfDay(days[days.length - 1])];
1409
1432
  }
1433
+ /**
1434
+ * The top-level calendar. Switches between month, week, day, 3days, custom, and
1435
+ * schedule modes, and is gesture-driven and virtualized. It is a controlled
1436
+ * component: pass `date` and `mode` and update them from `onChangeDate`.
1437
+ *
1438
+ * @example
1439
+ * ```tsx
1440
+ * import { Calendar, type CalendarEvent } from "react-native-super-calendar";
1441
+ *
1442
+ * function MyCalendar() {
1443
+ * const [date, setDate] = useState(new Date());
1444
+ * const events: CalendarEvent[] = [
1445
+ * { title: "Standup", start: new Date(), end: new Date() },
1446
+ * ];
1447
+ * return (
1448
+ * <Calendar
1449
+ * mode="week"
1450
+ * date={date}
1451
+ * events={events}
1452
+ * onChangeDate={setDate}
1453
+ * onPressEvent={(e) => console.log(e.title)}
1454
+ * />
1455
+ * );
1456
+ * }
1457
+ * ```
1458
+ */
1410
1459
  function Calendar({ events, mode, date, onChangeDate, onChangeDateRange, onPressEvent, onLongPressEvent, onDragEvent, onDragStart, dragStepMinutes, showDragHandle, onPressDay, onLongPressDay, onPressMore, onPressCell, resetPageOnPressCell, onLongPressCell, onCreateEvent, onPressDateHeader, maxVisibleEventCount, sortedMonthView, moreLabel, showAdjacentMonths, disableMonthEventCellPress, weekStartsOn = 0, numberOfDays, weekEndsOn, renderEvent = DefaultEvent, eventCellStyle, calendarCellStyle, businessHours, keyExtractor = defaultKeyExtractor, theme, cellHeight: cellHeightProp, hourHeight = 48, minHourHeight, maxHourHeight, hourColumnWidth, hideHours, timeslots, showAllDayEventCell, showWeekNumber, weekNumberPrefix, hourComponent, showSixWeeks, swipeEnabled, showVerticalScrollIndicator, verticalScrollEnabled, headerComponent, minHour, maxHour, ampm, showTime, ellipsizeTitle, allDayLabel, scrollOffsetMinutes, showNowIndicator, locale, activeDate, isRTL, freeSwipe, renderTimeGridHeader, renderHeaderForMonthView, renderCustomDateForMonth, itemSeparatorComponent }) {
1411
1460
  const mergedTheme = useMemo(() => mergeTheme(theme), [theme]);
1412
1461
  const internalCellHeight = useSharedValue(hourHeight);
package/dist/picker.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, a as MonthPagerProps, b as CalendarThemeProvider, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, n as MonthList, o as MonthView, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-CpRoOloh.mjs";
1
+ import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, a as MonthPagerProps, b as CalendarThemeProvider, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, n as MonthList, o as MonthView, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-D2s0x2Bn.mjs";
2
2
  import { DateRange, DateSelectionConstraints, DaySelectionState, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, UseDateRangeOptions, UseMonthGridOptions, buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
3
3
  export { type CalendarEvent, type CalendarMode, type CalendarTheme, CalendarThemeProvider, type DateRange, type DateSelectionConstraints, type DaySelectionState, DefaultMonthEvent, type EventKeyExtractor, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type RenderEvent, type RenderEventArgs, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };
package/dist/picker.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, a as MonthPagerProps, b as CalendarThemeProvider, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, n as MonthList, o as MonthView, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-86XCNCge.js";
1
+ import { C as defaultTheme, S as darkTheme, T as useCalendarTheme, a as MonthPagerProps, b as CalendarThemeProvider, d as EventKeyExtractor, f as ICalendarEvent, g as RenderEventArgs, h as RenderEvent, i as MonthPager, l as CalendarEvent, n as MonthList, o as MonthView, r as MonthListProps, s as MonthViewProps, t as DefaultMonthEvent, u as CalendarMode, v as WeekStartsOn, w as mergeTheme, x as PartialCalendarTheme, y as CalendarTheme } from "./DefaultMonthEvent-DaTEIcRs.js";
2
2
  import { DateRange, DateSelectionConstraints, DaySelectionState, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, UseDateRangeOptions, UseMonthGridOptions, buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
3
3
  export { type CalendarEvent, type CalendarMode, type CalendarTheme, CalendarThemeProvider, type DateRange, type DateSelectionConstraints, type DaySelectionState, DefaultMonthEvent, type EventKeyExtractor, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type RenderEvent, type RenderEventArgs, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };
package/dist/picker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_MonthList = require("./MonthList-BCfN-UGz.js");
2
+ const require_MonthList = require("./MonthList-oXiArmbu.js");
3
3
  let _super_calendar_core = require("@super-calendar/core");
4
4
  exports.CalendarThemeProvider = require_MonthList.CalendarThemeProvider;
5
5
  exports.DefaultMonthEvent = require_MonthList.DefaultMonthEvent;
package/dist/picker.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { c as defaultTheme, i as MonthView, l as mergeTheme, n as DefaultMonthEvent, o as CalendarThemeProvider, r as MonthPager, s as darkTheme, t as MonthList, u as useCalendarTheme } from "./MonthList-CyrEJ_U6.mjs";
1
+ import { c as defaultTheme, i as MonthView, l as mergeTheme, n as DefaultMonthEvent, o as CalendarThemeProvider, r as MonthPager, s as darkTheme, t as MonthList, u as useCalendarTheme } from "./MonthList-DXvjxiyu.mjs";
2
2
  import { buildMonthGrid, buildMonthWeeks, daySelectionState, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, minutesIntoDay, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
3
3
  export { CalendarThemeProvider, DefaultMonthEvent, MonthList, MonthPager, MonthView, buildMonthGrid, buildMonthWeeks, darkTheme, daySelectionState, defaultTheme, getIsToday, getWeekDays, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, mergeTheme, minutesIntoDay, nextDateRange, useCalendarTheme, useDateRange, useMonthGrid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/native",
3
- "version": "2.0.0",
3
+ "version": "2.1.3",
4
4
  "description": "Gesture-driven, virtualized month / week / day calendar and date picker for React Native (and web via react-native-web).",
5
5
  "keywords": [
6
6
  "agenda",
@@ -14,14 +14,14 @@
14
14
  "timetable",
15
15
  "week-view"
16
16
  ],
17
- "homepage": "https://github.com/afonsojramos/react-native-super-calendar#readme",
17
+ "homepage": "https://super-calendar.afonsojramos.me",
18
18
  "bugs": {
19
- "url": "https://github.com/afonsojramos/react-native-super-calendar/issues"
19
+ "url": "https://github.com/afonsojramos/super-calendar/issues"
20
20
  },
21
21
  "license": "MIT",
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "git+https://github.com/afonsojramos/react-native-super-calendar.git",
24
+ "url": "git+https://github.com/afonsojramos/super-calendar.git",
25
25
  "directory": "packages/native"
26
26
  },
27
27
  "source": "./src/index.tsx",
@@ -64,7 +64,7 @@
64
64
  "access": "public"
65
65
  },
66
66
  "dependencies": {
67
- "@super-calendar/core": "2.0.0"
67
+ "@super-calendar/core": "2.1.3"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@legendapp/list": ">=3",
@@ -1,12 +1,13 @@
1
1
  import { LegendList, type LegendListRenderItemProps } from "@legendapp/list/react-native";
2
2
  import { format, isSameDay, type Locale, startOfDay } from "date-fns";
3
- import { type ComponentType, useCallback, useMemo } from "react";
3
+ import { type ComponentType, type ReactElement, useCallback, useMemo } from "react";
4
4
  import { StyleSheet, Text, View } from "react-native";
5
5
  import { useCalendarTheme } from "../theme";
6
6
  import type { CalendarEvent, EventKeyExtractor, RenderEvent } from "../types";
7
7
  import { getIsToday } from "@super-calendar/core";
8
8
  import { isAllDayEvent } from "@super-calendar/core";
9
9
 
10
+ /** Props for {@link Agenda}, the day-grouped list view of events. */
10
11
  export type AgendaProps<T> = {
11
12
  events: CalendarEvent<T>[];
12
13
  locale?: Locale;
@@ -40,7 +41,7 @@ export function Agenda<T>({
40
41
  onPressDay,
41
42
  activeDate,
42
43
  itemSeparatorComponent,
43
- }: AgendaProps<T>) {
44
+ }: AgendaProps<T>): ReactElement {
44
45
  const theme = useCalendarTheme();
45
46
  const RenderEventComponent = renderEvent;
46
47
 
@@ -7,7 +7,7 @@ import {
7
7
  startOfMonth,
8
8
  startOfWeek,
9
9
  } from "date-fns";
10
- import { useCallback, useMemo } from "react";
10
+ import { type ReactElement, useCallback, useMemo } from "react";
11
11
  import type { StyleProp, ViewStyle } from "react-native";
12
12
  import { useSharedValue } from "react-native-reanimated";
13
13
  import { CalendarThemeProvider, mergeTheme, type PartialCalendarTheme } from "../theme";
@@ -32,6 +32,7 @@ import {
32
32
  TimeGrid,
33
33
  } from "./TimeGrid";
34
34
 
35
+ /** Props for the {@link Calendar} component. */
35
36
  export type CalendarProps<T> = {
36
37
  events: CalendarEvent<T>[];
37
38
  mode: CalendarMode;
@@ -231,6 +232,32 @@ function visibleRange(
231
232
  return [startOfDay(days[0]), endOfDay(days[days.length - 1])];
232
233
  }
233
234
 
235
+ /**
236
+ * The top-level calendar. Switches between month, week, day, 3days, custom, and
237
+ * schedule modes, and is gesture-driven and virtualized. It is a controlled
238
+ * component: pass `date` and `mode` and update them from `onChangeDate`.
239
+ *
240
+ * @example
241
+ * ```tsx
242
+ * import { Calendar, type CalendarEvent } from "react-native-super-calendar";
243
+ *
244
+ * function MyCalendar() {
245
+ * const [date, setDate] = useState(new Date());
246
+ * const events: CalendarEvent[] = [
247
+ * { title: "Standup", start: new Date(), end: new Date() },
248
+ * ];
249
+ * return (
250
+ * <Calendar
251
+ * mode="week"
252
+ * date={date}
253
+ * events={events}
254
+ * onChangeDate={setDate}
255
+ * onPressEvent={(e) => console.log(e.title)}
256
+ * />
257
+ * );
258
+ * }
259
+ * ```
260
+ */
234
261
  export function Calendar<T>({
235
262
  events,
236
263
  mode,
@@ -297,7 +324,7 @@ export function Calendar<T>({
297
324
  renderHeaderForMonthView,
298
325
  renderCustomDateForMonth,
299
326
  itemSeparatorComponent,
300
- }: CalendarProps<T>) {
327
+ }: CalendarProps<T>): ReactElement {
301
328
  const mergedTheme = useMemo(() => mergeTheme(theme), [theme]);
302
329
  const internalCellHeight = useSharedValue(hourHeight);
303
330
  const cellHeight = cellHeightProp ?? internalCellHeight;
@@ -1,3 +1,4 @@
1
+ import type { ReactElement } from "react";
1
2
  import { StyleSheet, Text, TouchableOpacity } from "react-native";
2
3
  import Animated, { useAnimatedStyle, useDerivedValue } from "react-native-reanimated";
3
4
  import { useCalendarTheme } from "../theme";
@@ -40,7 +41,7 @@ export function DefaultEvent<T>({
40
41
  cellStyle,
41
42
  onPress,
42
43
  onLongPress,
43
- }: RenderEventArgs<T>) {
44
+ }: RenderEventArgs<T>): ReactElement {
44
45
  const theme = useCalendarTheme();
45
46
  const isAllDayEvent = isAllDay ?? false;
46
47
  const timeLabel = eventTimeLabel({