@super-calendar/native 2.16.0 → 2.18.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 +59 -0
- package/dist/{DefaultMonthEvent-ClIxUp__.d.ts → DefaultMonthEvent-B7xVeY7Q.d.ts} +29 -10
- package/dist/{DefaultMonthEvent-No5YhOcV.d.mts → DefaultMonthEvent-hGk7wSrr.d.mts} +29 -10
- package/dist/{MonthList-Dmp8JXvj.js → MonthList-C_NTufaK.js} +462 -92
- package/dist/{MonthList-D97JhM4F.mjs → MonthList-DdQxRhUy.mjs} +453 -95
- package/dist/index.d.mts +54 -13
- package/dist/index.d.ts +54 -13
- package/dist/index.js +245 -72
- package/dist/index.mjs +210 -74
- 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 -2
- package/src/components/AllDayLane.tsx +64 -37
- package/src/components/Calendar.tsx +173 -34
- package/src/components/MonthPager.tsx +212 -21
- package/src/components/MonthView.tsx +419 -118
- package/src/components/MultiWeekView.tsx +34 -0
- package/src/components/TimeGrid.tsx +60 -11
- package/src/components/YearView.tsx +12 -1
- package/src/index.tsx +17 -2
- package/src/types.ts +2 -2
- package/src/utils/holdWebDateDrag.ts +63 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { addMonths, differenceInCalendarMonths, format, isSameMonth, startOfDay, startOfMonth } from "date-fns";
|
|
1
|
+
import { addDays, addMonths, addWeeks, differenceInCalendarMonths, differenceInCalendarWeeks, format, isSameMonth, startOfDay, startOfMonth, startOfWeek } from "date-fns";
|
|
2
2
|
import { createContext, createElement, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { CalendarSelectionProvider, buildMonthWeeks, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, defaultCalendarLabels, eventAccessibilityLabel, eventTimeLabel, filterHiddenDays, getIsToday, getWeekDays, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isSameCalendarDay, isWeekend, layoutMonthWeek, lightColors, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, overlapsOtherEvents, rangeBandKind, resolveCalendarLabels, titleEllipsizeMode, titleNumberOfLines, useCalendarSelection, weekdayFormatToken } from "@super-calendar/core";
|
|
3
|
+
import { CalendarSelectionProvider, buildMonthWeeks, buildMultiWeekGrid, compareDayEvents, darkColors, dayAccessibilityLabel, dayBadgeKind, daySelectionState, defaultCalendarLabels, eventAccessibilityLabel, eventTimeLabel, filterHiddenDays, getIsToday, getWeekDays, groupEventsByDay, isAllDayEvent, isBackgroundEvent, isDateSelectable, isSameCalendarDay, isWeekend, layoutMonthWeek, lightColors, monthCreateRange, monthDropBounds, monthEventCapacity, monthVisibleCount, nowInTimeZone, overlapsOtherEvents, rangeBandKind, resolveCalendarLabels, titleEllipsizeMode, titleNumberOfLines, useCalendarSelection, weekdayFormatToken } from "@super-calendar/core";
|
|
4
4
|
import { Modal, Platform, Pressable, ScrollView, StyleSheet, Text, TouchableOpacity, View, useWindowDimensions } from "react-native";
|
|
5
5
|
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -198,8 +198,67 @@ function withEventAccessibilityLabel(renderEvent, labeler, ampm) {
|
|
|
198
198
|
});
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
+
// src/utils/holdWebDateDrag.ts
|
|
202
|
+
/** Keep quick swipes scrollable, then let a held pointer own the date-row drag. */
|
|
203
|
+
function holdWebDateDrag(node, pointer, start, move, cancel, release) {
|
|
204
|
+
const doc = node.ownerDocument;
|
|
205
|
+
let active = false;
|
|
206
|
+
let finished = false;
|
|
207
|
+
const detach = () => {
|
|
208
|
+
clearTimeout(timer);
|
|
209
|
+
doc.removeEventListener("pointermove", onMove);
|
|
210
|
+
doc.removeEventListener("pointerup", onUp);
|
|
211
|
+
doc.removeEventListener("pointercancel", onCancel);
|
|
212
|
+
doc.removeEventListener("pointerdown", onAnotherPointer);
|
|
213
|
+
doc.removeEventListener("touchmove", onTouchMove);
|
|
214
|
+
doc.removeEventListener("contextmenu", onContextMenu);
|
|
215
|
+
};
|
|
216
|
+
const stop = () => {
|
|
217
|
+
if (finished) return;
|
|
218
|
+
finished = true;
|
|
219
|
+
detach();
|
|
220
|
+
cancel();
|
|
221
|
+
release();
|
|
222
|
+
};
|
|
223
|
+
const onMove = (event) => {
|
|
224
|
+
if (event.pointerId !== pointer.pointerId) return;
|
|
225
|
+
if (active) move(event.clientX, event.clientY);
|
|
226
|
+
else if (Math.hypot(event.clientX - pointer.clientX, event.clientY - pointer.clientY) > 8) stop();
|
|
227
|
+
};
|
|
228
|
+
const onUp = (event) => {
|
|
229
|
+
if (event.pointerId !== pointer.pointerId) return;
|
|
230
|
+
finished = true;
|
|
231
|
+
detach();
|
|
232
|
+
release();
|
|
233
|
+
};
|
|
234
|
+
const onCancel = (event) => {
|
|
235
|
+
if (event.pointerId === pointer.pointerId) stop();
|
|
236
|
+
};
|
|
237
|
+
const onAnotherPointer = (event) => {
|
|
238
|
+
if (event.pointerId !== pointer.pointerId) stop();
|
|
239
|
+
};
|
|
240
|
+
const onTouchMove = (event) => {
|
|
241
|
+
if (active && event.cancelable) event.preventDefault();
|
|
242
|
+
};
|
|
243
|
+
const onContextMenu = (event) => event.preventDefault();
|
|
244
|
+
const timer = setTimeout(() => {
|
|
245
|
+
active = true;
|
|
246
|
+
start();
|
|
247
|
+
}, 400);
|
|
248
|
+
doc.addEventListener("pointermove", onMove);
|
|
249
|
+
doc.addEventListener("pointerup", onUp);
|
|
250
|
+
doc.addEventListener("pointercancel", onCancel);
|
|
251
|
+
doc.addEventListener("pointerdown", onAnotherPointer);
|
|
252
|
+
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
253
|
+
doc.addEventListener("contextmenu", onContextMenu);
|
|
254
|
+
return stop;
|
|
255
|
+
}
|
|
201
256
|
// src/components/MonthView.tsx
|
|
202
257
|
const isWeb$2 = Platform.OS === "web";
|
|
258
|
+
const webPreviewProps = isWeb$2 ? {
|
|
259
|
+
"aria-hidden": true,
|
|
260
|
+
inert: "inert"
|
|
261
|
+
} : {};
|
|
203
262
|
const DAY_CELL_PADDING_TOP = 4;
|
|
204
263
|
const DATE_BADGE_HEIGHT = 24;
|
|
205
264
|
const BAND_CENTER_Y = 16;
|
|
@@ -234,7 +293,28 @@ function isInCreateSpan(drag, day) {
|
|
|
234
293
|
const b = startOfDay(drag.hover).getTime();
|
|
235
294
|
return time >= Math.min(a, b) && time <= Math.max(a, b);
|
|
236
295
|
}
|
|
237
|
-
function MonthViewInner({ date,
|
|
296
|
+
function MonthViewInner({ date, showAdjacentMonths = true, showSixWeeks = false, ...rest }) {
|
|
297
|
+
const source = useMemo(() => ({
|
|
298
|
+
kind: "month",
|
|
299
|
+
date,
|
|
300
|
+
showAdjacentMonths,
|
|
301
|
+
showSixWeeks
|
|
302
|
+
}), [
|
|
303
|
+
date,
|
|
304
|
+
showAdjacentMonths,
|
|
305
|
+
showSixWeeks
|
|
306
|
+
]);
|
|
307
|
+
return /* @__PURE__ */ jsx(DateRows, {
|
|
308
|
+
...rest,
|
|
309
|
+
source
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function DateRowsInner({ source, events, maxVisibleEventCount, chipHeight, chipGap = CELL_ROW_GAP, weekStartsOn, hiddenDays, weekdayFormat = "short", locale, now, timeZone, sortedMonthView = true, moreLabel = "{moreCount} More", labels: labelsProp, highlightWeekends = true, disableMonthEventCellPress = false, isRTL = false, showTitle = true, showWeekdays = true, activeDate, selectedDates: selectedDatesProp, selectedRange: selectedRangeProp, fillCellOnSelection = false, minDate: minDateProp, maxDate: maxDateProp, isDateDisabled: isDateDisabledProp, calendarCellStyle, renderEvent, eventAccessibilityLabel, keyExtractor, onPressDay, onLongPressDay, onPressCell, onPressEvent, onLongPressEvent, onPressMore, onCreateEvent, renderCreateGhost: RenderCreateGhost, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, renderCustomDateForMonth, onDayPointerDown, onDayPointerEnter, classNames, styles: styleOverrides }) {
|
|
313
|
+
const { date } = source;
|
|
314
|
+
const multiWeek = source.kind === "multiweek";
|
|
315
|
+
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
316
|
+
const showSixWeeks = source.kind === "month" ? source.showSixWeeks : false;
|
|
317
|
+
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : void 0;
|
|
238
318
|
const theme = useCalendarTheme();
|
|
239
319
|
const badgeArea = 28 + chipGap;
|
|
240
320
|
const slot = createSlots({
|
|
@@ -257,17 +337,33 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
257
337
|
const [hoveredKey, setHoveredKey] = useState(null);
|
|
258
338
|
const [pressedKey, setPressedKey] = useState(null);
|
|
259
339
|
const [moreOpenFor, setMoreOpenFor] = useState(null);
|
|
260
|
-
const
|
|
340
|
+
const today = nowInTimeZone(now, timeZone);
|
|
341
|
+
const multiWeekGrid = useMemo(() => numberOfWeeks === void 0 ? null : buildMultiWeekGrid(date, {
|
|
342
|
+
numberOfWeeks,
|
|
343
|
+
weekStartsOn,
|
|
344
|
+
isRTL,
|
|
345
|
+
hiddenDays
|
|
346
|
+
}), [
|
|
347
|
+
date,
|
|
348
|
+
numberOfWeeks,
|
|
349
|
+
weekStartsOn,
|
|
350
|
+
isRTL,
|
|
351
|
+
hiddenDays
|
|
352
|
+
]);
|
|
353
|
+
const weeks = useMemo(() => multiWeekGrid ? multiWeekGrid.weeks.map((week) => week.days.map((day) => day.date)) : buildMonthWeeks(date, weekStartsOn, {
|
|
261
354
|
showSixWeeks,
|
|
262
355
|
isRTL,
|
|
263
356
|
hiddenDays
|
|
264
357
|
}), [
|
|
358
|
+
multiWeekGrid,
|
|
265
359
|
date,
|
|
266
360
|
weekStartsOn,
|
|
267
361
|
isRTL,
|
|
268
362
|
showSixWeeks,
|
|
269
363
|
hiddenDays
|
|
270
364
|
]);
|
|
365
|
+
const title = multiWeekGrid ? `${format(multiWeekGrid.visibleRange.start, "PP", { locale })} – ${format(addDays(multiWeekGrid.visibleRange.endExclusive, -1), "PP", { locale })}` : format(date, "MMMM yyyy", { locale });
|
|
366
|
+
const windowKey = multiWeekGrid ? `${multiWeekGrid.period.start.getTime()}:${numberOfWeeks}:${hiddenDays?.join(",")}:${isRTL}` : null;
|
|
271
367
|
const weekdayLabels = useMemo(() => {
|
|
272
368
|
const days = filterHiddenDays(getWeekDays(date, weekStartsOn), hiddenDays);
|
|
273
369
|
return isRTL ? days.reverse() : days;
|
|
@@ -290,6 +386,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
290
386
|
chipHeight,
|
|
291
387
|
chipGap
|
|
292
388
|
]);
|
|
389
|
+
const minimumRowHeight = badgeArea + Math.max(1, maxVisibleEventCount ?? FALLBACK_VISIBLE_COUNT) * chipMetrics.chipRowHeight;
|
|
293
390
|
const capacity = useMemo(() => {
|
|
294
391
|
if (maxVisibleEventCount != null) return {
|
|
295
392
|
full: maxVisibleEventCount,
|
|
@@ -318,7 +415,8 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
318
415
|
if (sortedMonthView) for (const list of map.values()) list.sort(compareDayEvents);
|
|
319
416
|
return map;
|
|
320
417
|
}, [events, sortedMonthView]);
|
|
321
|
-
const
|
|
418
|
+
const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
|
|
419
|
+
const showGrid = multiWeek || events.length > 0 || createContentEnabled;
|
|
322
420
|
const weekLayouts = useMemo(() => showGrid ? weeks.map((week) => layoutMonthWeek(week, collectRowEvents(week, eventsByDay))) : [], [
|
|
323
421
|
showGrid,
|
|
324
422
|
weeks,
|
|
@@ -326,20 +424,56 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
326
424
|
]);
|
|
327
425
|
const dragEnabled = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
328
426
|
const gridRef = useRef(null);
|
|
427
|
+
const heldTouch = useRef(null);
|
|
428
|
+
const heldOrigin = useRef(null);
|
|
329
429
|
const [drag, setDrag] = useState(null);
|
|
430
|
+
const createRange = useMemo(() => createContentEnabled && drag?.kind === "create" ? monthCreateRange(drag.anchor, drag.hover) : null, [createContentEnabled, drag]);
|
|
330
431
|
const dragRef = useRef(null);
|
|
432
|
+
const interactionWindow = useRef(windowKey);
|
|
433
|
+
interactionWindow.current = windowKey;
|
|
434
|
+
const mounted = useRef(true);
|
|
435
|
+
useEffect(() => {
|
|
436
|
+
mounted.current = true;
|
|
437
|
+
return () => {
|
|
438
|
+
mounted.current = false;
|
|
439
|
+
dragRef.current = null;
|
|
440
|
+
};
|
|
441
|
+
}, []);
|
|
331
442
|
const movedRef = useRef(false);
|
|
332
443
|
const suppressPressRef = useRef(false);
|
|
333
444
|
const applyDrag = useCallback((next) => {
|
|
334
445
|
dragRef.current = next;
|
|
335
446
|
setDrag(next);
|
|
336
447
|
}, []);
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
if (windowKey === null) return;
|
|
450
|
+
applyDrag(null);
|
|
451
|
+
setMoreOpenFor(null);
|
|
452
|
+
return () => {
|
|
453
|
+
dragRef.current = null;
|
|
454
|
+
};
|
|
455
|
+
}, [windowKey, applyDrag]);
|
|
456
|
+
useEffect(() => () => {
|
|
457
|
+
heldTouch.current?.();
|
|
458
|
+
}, [windowKey]);
|
|
337
459
|
const consumeSuppressedPress = useCallback(() => {
|
|
338
460
|
if (!suppressPressRef.current) return false;
|
|
339
461
|
suppressPressRef.current = false;
|
|
340
462
|
return true;
|
|
341
463
|
}, []);
|
|
342
464
|
const canMoveEvent = useCallback((event) => !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable), [eventStartEditable]);
|
|
465
|
+
useEffect(() => {
|
|
466
|
+
const origin = heldOrigin.current;
|
|
467
|
+
if (!origin) return;
|
|
468
|
+
const current = dragRef.current;
|
|
469
|
+
const destination = current ? current.kind === "create" ? current.hover : current.to : origin.day;
|
|
470
|
+
const constraints = {
|
|
471
|
+
minDate,
|
|
472
|
+
maxDate,
|
|
473
|
+
isDateDisabled
|
|
474
|
+
};
|
|
475
|
+
if (!isDateSelectable(origin.day, constraints) || !isDateSelectable(destination, constraints) || (origin.event ? !onDragEvent || !events.includes(origin.event) || !canMoveEvent(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
|
|
476
|
+
});
|
|
343
477
|
const hitTest = useCallback((x, y) => {
|
|
344
478
|
const { width, height } = gridSize;
|
|
345
479
|
if (width <= 0 || height <= 0 || weeks.length === 0) return null;
|
|
@@ -375,10 +509,16 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
375
509
|
maxDate,
|
|
376
510
|
isDateDisabled
|
|
377
511
|
]);
|
|
378
|
-
const beginDrag = useCallback((x, y) => {
|
|
512
|
+
const beginDrag = useCallback((x, y, origin) => {
|
|
513
|
+
if (!mounted.current || multiWeek && interactionWindow.current !== windowKey) return;
|
|
514
|
+
if (origin && (!isDateSelectable(origin.day, {
|
|
515
|
+
minDate,
|
|
516
|
+
maxDate,
|
|
517
|
+
isDateDisabled
|
|
518
|
+
}) || origin.event && !events.includes(origin.event))) return;
|
|
379
519
|
suppressPressRef.current = false;
|
|
380
520
|
movedRef.current = false;
|
|
381
|
-
const hit = hitTest(x, y);
|
|
521
|
+
const hit = origin ?? hitTest(x, y);
|
|
382
522
|
if (!hit) return;
|
|
383
523
|
if (hit.event) {
|
|
384
524
|
if (!onDragEvent || !canMoveEvent(hit.event)) return;
|
|
@@ -403,7 +543,13 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
403
543
|
onSelectDrag,
|
|
404
544
|
onDragStart,
|
|
405
545
|
canMoveEvent,
|
|
406
|
-
applyDrag
|
|
546
|
+
applyDrag,
|
|
547
|
+
multiWeek,
|
|
548
|
+
windowKey,
|
|
549
|
+
minDate,
|
|
550
|
+
maxDate,
|
|
551
|
+
isDateDisabled,
|
|
552
|
+
events
|
|
407
553
|
]);
|
|
408
554
|
const extendDrag = useCallback((x, y) => {
|
|
409
555
|
const current = dragRef.current;
|
|
@@ -483,13 +629,57 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
483
629
|
target.addEventListener?.("pointerup", up);
|
|
484
630
|
const node = gridRef.current;
|
|
485
631
|
if (node?.style) {
|
|
486
|
-
node.style.touchAction = "none";
|
|
632
|
+
node.style.touchAction = multiWeek ? "pan-y" : "none";
|
|
487
633
|
node.style.userSelect = "none";
|
|
488
634
|
}
|
|
489
635
|
return () => target.removeEventListener?.("pointerup", up);
|
|
490
|
-
}, [
|
|
636
|
+
}, [
|
|
637
|
+
dragEnabled,
|
|
638
|
+
endDrag,
|
|
639
|
+
multiWeek
|
|
640
|
+
]);
|
|
641
|
+
const webDragHandlers = useRef({
|
|
642
|
+
beginDrag,
|
|
643
|
+
extendDrag
|
|
644
|
+
});
|
|
645
|
+
webDragHandlers.current = {
|
|
646
|
+
beginDrag,
|
|
647
|
+
extendDrag
|
|
648
|
+
};
|
|
649
|
+
const pressWebGrid = (event) => {
|
|
650
|
+
const pointer = event.nativeEvent;
|
|
651
|
+
if (multiWeek && (pointer.button !== 0 || pointer.isPrimary === false || heldTouch.current)) return;
|
|
652
|
+
if (multiWeek) suppressPressRef.current = false;
|
|
653
|
+
const start = () => {
|
|
654
|
+
const point = gridPoint(pointer.clientX, pointer.clientY);
|
|
655
|
+
if (point) webDragHandlers.current.beginDrag(point.x, point.y);
|
|
656
|
+
};
|
|
657
|
+
if (!multiWeek || !pointer.pointerType || pointer.pointerType === "mouse") {
|
|
658
|
+
start();
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const node = gridRef.current;
|
|
662
|
+
if (!node) return;
|
|
663
|
+
const point = gridPoint(pointer.clientX, pointer.clientY);
|
|
664
|
+
if (!point) return;
|
|
665
|
+
const origin = hitTest(point.x, point.y);
|
|
666
|
+
if (!origin) return;
|
|
667
|
+
heldOrigin.current = origin;
|
|
668
|
+
heldTouch.current = holdWebDateDrag(node, pointer, () => {
|
|
669
|
+
if (interactionWindow.current === windowKey) webDragHandlers.current.beginDrag(point.x, point.y, origin);
|
|
670
|
+
}, (x, y) => {
|
|
671
|
+
const point = gridPoint(x, y);
|
|
672
|
+
if (point) webDragHandlers.current.extendDrag(point.x, point.y);
|
|
673
|
+
}, () => {
|
|
674
|
+
applyDrag(null);
|
|
675
|
+
movedRef.current = false;
|
|
676
|
+
}, () => {
|
|
677
|
+
heldTouch.current = null;
|
|
678
|
+
heldOrigin.current = null;
|
|
679
|
+
});
|
|
680
|
+
};
|
|
491
681
|
const renderDay = (day, dayCol, rowLayout, visibleLanes) => {
|
|
492
|
-
const isCurrentMonth = isSameMonth(day, date);
|
|
682
|
+
const isCurrentMonth = multiWeek || isSameMonth(day, date);
|
|
493
683
|
if (!isCurrentMonth && !showAdjacentMonths) return /* @__PURE__ */ jsx(View, { ...slot("day", {
|
|
494
684
|
base: [styles$3.dayCell, { gap: chipGap }],
|
|
495
685
|
themed: [showGrid && {
|
|
@@ -499,7 +689,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
499
689
|
}, theme.containers.dayCell]
|
|
500
690
|
}) }, day.toISOString());
|
|
501
691
|
const dayEvents = eventsByDay.get(startOfDay(day).toISOString()) ?? [];
|
|
502
|
-
const isToday = getIsToday(day);
|
|
692
|
+
const isToday = getIsToday(day, today);
|
|
503
693
|
const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
|
|
504
694
|
const { isDisabled, isSelected, isInRange, isRangeStart, isRangeEnd } = daySelectionState(day, {
|
|
505
695
|
selectedDates,
|
|
@@ -670,7 +860,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
670
860
|
themed: [theme.text.monthTitle, { color: theme.colors.text }]
|
|
671
861
|
}),
|
|
672
862
|
allowFontScaling: false,
|
|
673
|
-
children:
|
|
863
|
+
children: title
|
|
674
864
|
}) : null,
|
|
675
865
|
showWeekdays ? /* @__PURE__ */ jsx(View, {
|
|
676
866
|
...slot("weekdays", {
|
|
@@ -713,7 +903,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
713
903
|
style: styles$3.moreCardRow,
|
|
714
904
|
children: /* @__PURE__ */ jsx(RenderEventComponent, {
|
|
715
905
|
event,
|
|
716
|
-
mode: "month",
|
|
906
|
+
mode: multiWeek ? "multiweek" : "month",
|
|
717
907
|
isAllDay: isAllDayEvent(event),
|
|
718
908
|
onPress: () => {
|
|
719
909
|
setMoreOpenFor(null);
|
|
@@ -724,74 +914,110 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
724
914
|
})
|
|
725
915
|
})
|
|
726
916
|
}) : null,
|
|
727
|
-
/* @__PURE__ */ jsx(
|
|
728
|
-
|
|
729
|
-
children: /* @__PURE__ */ jsx(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
} : null,
|
|
745
|
-
children: weeks.map((week, weekIndex) => {
|
|
746
|
-
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
747
|
-
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
748
|
-
const cols = week.length;
|
|
749
|
-
let firstVisCol = 0;
|
|
750
|
-
let lastVisCol = cols - 1;
|
|
751
|
-
if (showGrid && !showAdjacentMonths) {
|
|
752
|
-
const first = week.findIndex((d) => isSameMonth(d, date));
|
|
753
|
-
if (first !== -1) {
|
|
754
|
-
firstVisCol = first;
|
|
755
|
-
lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
|
|
917
|
+
/* @__PURE__ */ jsx(DateRowsViewport, {
|
|
918
|
+
scrollable: multiWeek,
|
|
919
|
+
children: /* @__PURE__ */ jsx(MonthGridSurface, {
|
|
920
|
+
gesture: dragGesture,
|
|
921
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
922
|
+
ref: gridRef,
|
|
923
|
+
testID: multiWeek ? "multiweek-grid" : "month-grid",
|
|
924
|
+
accessibilityLabel: multiWeek ? title : void 0,
|
|
925
|
+
...slot("grid", { base: [styles$3.container, multiWeek ? { minHeight: minimumRowHeight * weeks.length } : void 0] }),
|
|
926
|
+
onLayout: handleLayout,
|
|
927
|
+
...isWeb$2 && dragEnabled ? {
|
|
928
|
+
onPointerDown: pressWebGrid,
|
|
929
|
+
onPointerMove: (event) => {
|
|
930
|
+
if (heldTouch.current) return;
|
|
931
|
+
if (!dragRef.current) return;
|
|
932
|
+
const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
|
|
933
|
+
if (point) extendDrag(point.x, point.y);
|
|
756
934
|
}
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
935
|
+
} : null,
|
|
936
|
+
children: weeks.map((week, weekIndex) => {
|
|
937
|
+
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
938
|
+
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
939
|
+
const cols = week.length;
|
|
940
|
+
let firstVisCol = 0;
|
|
941
|
+
let lastVisCol = cols - 1;
|
|
942
|
+
if (showGrid && !showAdjacentMonths) {
|
|
943
|
+
const first = week.findIndex((d) => isSameMonth(d, date));
|
|
944
|
+
if (first !== -1) {
|
|
945
|
+
firstVisCol = first;
|
|
946
|
+
lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
const draftColumns = createRange ? week.flatMap((day, index) => (showAdjacentMonths || isSameMonth(day, date)) && day >= createRange.start && day < createRange.end ? [index] : []) : [];
|
|
950
|
+
const draftStart = draftColumns[0];
|
|
951
|
+
const draftEnd = draftColumns.at(-1);
|
|
952
|
+
const draftLane = Math.min(visibleLanes, Math.max(0, capacity.full - 1));
|
|
953
|
+
const draftTop = badgeArea + draftLane * chipMetrics.chipRowHeight;
|
|
954
|
+
const draftHeight = Math.min(chipMetrics.chipHeight, Math.max(0, gridHeight / weeks.length - draftTop));
|
|
955
|
+
return /* @__PURE__ */ createElement(View, {
|
|
956
|
+
...slot("week", {
|
|
957
|
+
base: styles$3.weekRow,
|
|
958
|
+
themed: theme.containers.weekRow
|
|
959
|
+
}),
|
|
960
|
+
key: multiWeekGrid?.weeks[weekIndex].id ?? week[0].toISOString()
|
|
961
|
+
}, week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes)), showGrid ? /* @__PURE__ */ jsxs(View, {
|
|
962
|
+
style: [StyleSheet.absoluteFill, multiWeek ? styles$3.childrenOnlyPointerEvents : { pointerEvents: "box-none" }],
|
|
963
|
+
children: [rowLayout.segments.filter((seg) => seg.lane < visibleLanes).map((seg) => {
|
|
964
|
+
const startCol = Math.max(seg.startCol, firstVisCol);
|
|
965
|
+
const endCol = Math.min(seg.endCol, lastVisCol);
|
|
966
|
+
if (startCol > endCol) return null;
|
|
967
|
+
const isDragged = drag?.kind === "move" && drag.event === seg.event;
|
|
968
|
+
return /* @__PURE__ */ jsx(View, {
|
|
969
|
+
style: [{
|
|
970
|
+
position: "absolute",
|
|
971
|
+
left: pct(startCol / cols * 100),
|
|
972
|
+
width: pct((endCol - startCol + 1) / cols * 100),
|
|
973
|
+
top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
|
|
974
|
+
height: chipMetrics.chipHeight,
|
|
975
|
+
paddingHorizontal: CHIP_INSET_H,
|
|
976
|
+
opacity: isDragged ? DRAGGED_BAR_OPACITY : 1
|
|
977
|
+
}, multiWeek ? drag ? styles$3.noPointerEvents : styles$3.childrenOnlyPointerEvents : { pointerEvents: drag ? "none" : "box-none" }],
|
|
978
|
+
children: /* @__PURE__ */ jsx(RenderEventComponent, {
|
|
979
|
+
event: seg.event,
|
|
980
|
+
mode: multiWeek ? "multiweek" : "month",
|
|
981
|
+
isAllDay: isAllDayEvent(seg.event),
|
|
982
|
+
onPress: disableMonthEventCellPress ? () => {} : () => {
|
|
983
|
+
if (consumeSuppressedPress()) return;
|
|
984
|
+
onPressEvent(seg.event);
|
|
985
|
+
},
|
|
986
|
+
onLongPress: disableMonthEventCellPress || !onLongPressEvent ? void 0 : () => onLongPressEvent(seg.event)
|
|
987
|
+
})
|
|
988
|
+
}, `bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`);
|
|
989
|
+
}), RenderCreateGhost && createRange && draftStart !== void 0 && draftEnd !== void 0 && draftHeight > 0 ? /* @__PURE__ */ jsx(View, {
|
|
990
|
+
testID: "month-create-ghost",
|
|
991
|
+
...slot("createGhost", {
|
|
992
|
+
base: {
|
|
993
|
+
position: "absolute",
|
|
994
|
+
left: pct(draftStart / cols * 100),
|
|
995
|
+
right: pct((cols - 1 - draftEnd) / cols * 100),
|
|
996
|
+
top: draftTop,
|
|
997
|
+
height: draftHeight,
|
|
998
|
+
marginHorizontal: CHIP_INSET_H,
|
|
999
|
+
overflow: "hidden",
|
|
1000
|
+
zIndex: 1
|
|
789
1001
|
},
|
|
790
|
-
|
|
1002
|
+
themed: {
|
|
1003
|
+
backgroundColor: theme.colors.rangeBackground,
|
|
1004
|
+
borderColor: theme.colors.selectedBackground,
|
|
1005
|
+
borderWidth: 1,
|
|
1006
|
+
borderRadius: 4
|
|
1007
|
+
}
|
|
1008
|
+
}),
|
|
1009
|
+
...webPreviewProps,
|
|
1010
|
+
pointerEvents: "none",
|
|
1011
|
+
accessible: false,
|
|
1012
|
+
accessibilityElementsHidden: true,
|
|
1013
|
+
importantForAccessibility: "no-hide-descendants",
|
|
1014
|
+
children: /* @__PURE__ */ jsx(RenderCreateGhost, {
|
|
1015
|
+
start: createRange.start,
|
|
1016
|
+
end: createRange.end
|
|
791
1017
|
})
|
|
792
|
-
}
|
|
793
|
-
})
|
|
794
|
-
})
|
|
1018
|
+
}) : null]
|
|
1019
|
+
}) : null);
|
|
1020
|
+
})
|
|
795
1021
|
})
|
|
796
1022
|
})
|
|
797
1023
|
})
|
|
@@ -799,6 +1025,13 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
799
1025
|
})
|
|
800
1026
|
});
|
|
801
1027
|
}
|
|
1028
|
+
function DateRowsViewport({ scrollable, children }) {
|
|
1029
|
+
return scrollable ? /* @__PURE__ */ jsx(ScrollView, {
|
|
1030
|
+
style: styles$3.container,
|
|
1031
|
+
contentContainerStyle: { flexGrow: 1 },
|
|
1032
|
+
children
|
|
1033
|
+
}) : children;
|
|
1034
|
+
}
|
|
802
1035
|
function MonthGridSurface({ gesture, children }) {
|
|
803
1036
|
if (!gesture) return children;
|
|
804
1037
|
return /* @__PURE__ */ jsx(GestureDetector, {
|
|
@@ -823,6 +1056,11 @@ function MonthGridSurface({ gesture, children }) {
|
|
|
823
1056
|
* ```
|
|
824
1057
|
*/
|
|
825
1058
|
const MonthView = memo(MonthViewInner);
|
|
1059
|
+
/**
|
|
1060
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
1061
|
+
* spanning event bars, overflow, selection, and drag handling.
|
|
1062
|
+
*/
|
|
1063
|
+
const DateRows = memo(DateRowsInner);
|
|
826
1064
|
const styles$3 = StyleSheet.create({
|
|
827
1065
|
root: { flex: 1 },
|
|
828
1066
|
title: {
|
|
@@ -839,6 +1077,8 @@ const styles$3 = StyleSheet.create({
|
|
|
839
1077
|
textAlign: "center"
|
|
840
1078
|
},
|
|
841
1079
|
container: { flex: 1 },
|
|
1080
|
+
childrenOnlyPointerEvents: { pointerEvents: "box-none" },
|
|
1081
|
+
noPointerEvents: { pointerEvents: "none" },
|
|
842
1082
|
weekRow: {
|
|
843
1083
|
flex: 1,
|
|
844
1084
|
flexDirection: "row"
|
|
@@ -898,7 +1138,18 @@ const styles$3 = StyleSheet.create({
|
|
|
898
1138
|
const isWeb$1 = Platform.OS === "web";
|
|
899
1139
|
const PAGE_WINDOW$1 = 60;
|
|
900
1140
|
const PAGE_VIEWABILITY = { itemVisiblePercentThreshold: 90 };
|
|
901
|
-
function MonthPagerInner({
|
|
1141
|
+
function MonthPagerInner({ showAdjacentMonths = true, showSixWeeks = false, ...rest }) {
|
|
1142
|
+
const spec = useMemo(() => ({
|
|
1143
|
+
kind: "month",
|
|
1144
|
+
showAdjacentMonths,
|
|
1145
|
+
showSixWeeks
|
|
1146
|
+
}), [showAdjacentMonths, showSixWeeks]);
|
|
1147
|
+
return /* @__PURE__ */ jsx(DateRowsPager, {
|
|
1148
|
+
...rest,
|
|
1149
|
+
spec
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEventCount, chipHeight, chipGap, weekStartsOn, hiddenDays, weekdayFormat = "short", locale, now, timeZone, sortedMonthView, moreLabel, labels, highlightWeekends, disableMonthEventCellPress, isRTL, calendarCellStyle, renderEvent, keyExtractor, onPressDay, onLongPressDay, onPressCell, onPressEvent, onLongPressEvent, onPressMore, onCreateEvent, renderCreateGhost, onSelectDrag, selectedDates, selectedRange, fillCellOnSelection, minDate, maxDate, isDateDisabled, onDragEvent, onDragStart, eventStartEditable, eventOverlap, onChangeDate, freeSwipe = false, swipeEnabled = true, showTitle = true, activeDate, renderHeaderForMonthView, renderCustomDateForMonth, classNames, styles: styleOverrides }) {
|
|
902
1153
|
const theme = useCalendarTheme();
|
|
903
1154
|
const slot = useMemo(() => createSlots({
|
|
904
1155
|
classNames,
|
|
@@ -925,10 +1176,23 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
925
1176
|
}, []);
|
|
926
1177
|
const [pageHeight, setPageHeight] = useState(height);
|
|
927
1178
|
const [containerWidth, setContainerWidth] = useState(width);
|
|
928
|
-
const [anchorDate] = useState(date);
|
|
929
|
-
const
|
|
930
|
-
const
|
|
931
|
-
|
|
1179
|
+
const [anchorDate] = useState(initialAnchor ?? date);
|
|
1180
|
+
const numberOfWeeks = spec.kind === "multiweek" ? spec.numberOfWeeks : void 0;
|
|
1181
|
+
const anchor = useMemo(() => numberOfWeeks === void 0 ? startOfMonth(anchorDate) : startOfWeek(anchorDate, { weekStartsOn }), [
|
|
1182
|
+
anchorDate,
|
|
1183
|
+
numberOfWeeks,
|
|
1184
|
+
weekStartsOn
|
|
1185
|
+
]);
|
|
1186
|
+
const monthDates = useMemo(() => {
|
|
1187
|
+
const dates = Array.from({ length: 121 }, (_, i) => numberOfWeeks === void 0 ? addMonths(anchor, i - PAGE_WINDOW$1) : addWeeks(anchor, (i - PAGE_WINDOW$1) * numberOfWeeks));
|
|
1188
|
+
return numberOfWeeks === void 0 ? dates : dates.filter((page) => Number.isFinite(page.getTime()) && Number.isFinite(addWeeks(page, numberOfWeeks).getTime()));
|
|
1189
|
+
}, [anchor, numberOfWeeks]);
|
|
1190
|
+
const activeIndex = useCallback((target) => numberOfWeeks === void 0 ? differenceInCalendarMonths(startOfMonth(target), anchor) + PAGE_WINDOW$1 : differenceInCalendarWeeks(target, monthDates[0], { weekStartsOn }) / numberOfWeeks, [
|
|
1191
|
+
anchor,
|
|
1192
|
+
monthDates,
|
|
1193
|
+
numberOfWeeks,
|
|
1194
|
+
weekStartsOn
|
|
1195
|
+
])(date);
|
|
932
1196
|
const viewedIndexRef = useRef(activeIndex);
|
|
933
1197
|
const pendingScrollIndexRef = useRef(null);
|
|
934
1198
|
const handleViewableItemsChanged = useCallback((info) => {
|
|
@@ -972,20 +1236,33 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
972
1236
|
isRTL,
|
|
973
1237
|
hiddenDays
|
|
974
1238
|
]);
|
|
975
|
-
const
|
|
1239
|
+
const nowTime = now?.getTime();
|
|
1240
|
+
const monthExtraData = useMemo(() => ({
|
|
976
1241
|
events,
|
|
977
1242
|
activeDate,
|
|
1243
|
+
nowTime,
|
|
1244
|
+
timeZone,
|
|
978
1245
|
fillCellOnSelection,
|
|
979
1246
|
dragSelect: onSelectDrag != null,
|
|
980
1247
|
chipHeight,
|
|
981
|
-
chipGap
|
|
1248
|
+
chipGap,
|
|
1249
|
+
renderCreateGhost,
|
|
1250
|
+
onCreateEvent,
|
|
1251
|
+
createGhostClassName: classNames?.createGhost,
|
|
1252
|
+
createGhostStyle: styleOverrides?.createGhost
|
|
982
1253
|
}), [
|
|
983
1254
|
events,
|
|
984
1255
|
activeDate,
|
|
1256
|
+
nowTime,
|
|
1257
|
+
timeZone,
|
|
985
1258
|
fillCellOnSelection,
|
|
986
1259
|
onSelectDrag,
|
|
987
1260
|
chipHeight,
|
|
988
|
-
chipGap
|
|
1261
|
+
chipGap,
|
|
1262
|
+
renderCreateGhost,
|
|
1263
|
+
onCreateEvent,
|
|
1264
|
+
classNames?.createGhost,
|
|
1265
|
+
styleOverrides?.createGhost
|
|
989
1266
|
]);
|
|
990
1267
|
const selection = useMemo(() => ({
|
|
991
1268
|
selectedDates,
|
|
@@ -1000,6 +1277,20 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1000
1277
|
maxDate,
|
|
1001
1278
|
isDateDisabled
|
|
1002
1279
|
]);
|
|
1280
|
+
const sourceFor = useMemo(() => {
|
|
1281
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
1282
|
+
return (item) => {
|
|
1283
|
+
let source = cache.get(item);
|
|
1284
|
+
if (!source) {
|
|
1285
|
+
source = {
|
|
1286
|
+
...spec,
|
|
1287
|
+
date: item
|
|
1288
|
+
};
|
|
1289
|
+
cache.set(item, source);
|
|
1290
|
+
}
|
|
1291
|
+
return source;
|
|
1292
|
+
};
|
|
1293
|
+
}, [spec]);
|
|
1003
1294
|
const snapToIndices = useMemo(() => monthDates.map((_, index) => index), [monthDates]);
|
|
1004
1295
|
const keyExtractorList = useCallback((item) => item.toISOString(), []);
|
|
1005
1296
|
const getFixedItemSize = useCallback(() => containerWidth, [containerWidth]);
|
|
@@ -1008,8 +1299,8 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1008
1299
|
width: containerWidth,
|
|
1009
1300
|
height: pageHeight
|
|
1010
1301
|
},
|
|
1011
|
-
children: /* @__PURE__ */ jsx(
|
|
1012
|
-
|
|
1302
|
+
children: /* @__PURE__ */ jsx(DateRows, {
|
|
1303
|
+
source: sourceFor(item),
|
|
1013
1304
|
events,
|
|
1014
1305
|
showTitle: false,
|
|
1015
1306
|
showWeekdays: false,
|
|
@@ -1019,14 +1310,14 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1019
1310
|
weekStartsOn,
|
|
1020
1311
|
hiddenDays,
|
|
1021
1312
|
locale,
|
|
1313
|
+
now,
|
|
1314
|
+
timeZone,
|
|
1022
1315
|
sortedMonthView,
|
|
1023
1316
|
moreLabel,
|
|
1024
1317
|
labels,
|
|
1025
|
-
showAdjacentMonths,
|
|
1026
1318
|
highlightWeekends,
|
|
1027
1319
|
disableMonthEventCellPress,
|
|
1028
1320
|
isRTL,
|
|
1029
|
-
showSixWeeks,
|
|
1030
1321
|
activeDate,
|
|
1031
1322
|
calendarCellStyle,
|
|
1032
1323
|
renderEvent,
|
|
@@ -1038,6 +1329,7 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1038
1329
|
onLongPressEvent,
|
|
1039
1330
|
onPressMore,
|
|
1040
1331
|
onCreateEvent,
|
|
1332
|
+
renderCreateGhost,
|
|
1041
1333
|
onSelectDrag,
|
|
1042
1334
|
fillCellOnSelection,
|
|
1043
1335
|
onDragEvent,
|
|
@@ -1058,14 +1350,15 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1058
1350
|
weekStartsOn,
|
|
1059
1351
|
hiddenDays,
|
|
1060
1352
|
locale,
|
|
1353
|
+
now,
|
|
1354
|
+
timeZone,
|
|
1061
1355
|
sortedMonthView,
|
|
1062
1356
|
moreLabel,
|
|
1063
1357
|
labels,
|
|
1064
|
-
|
|
1358
|
+
sourceFor,
|
|
1065
1359
|
highlightWeekends,
|
|
1066
1360
|
disableMonthEventCellPress,
|
|
1067
1361
|
isRTL,
|
|
1068
|
-
showSixWeeks,
|
|
1069
1362
|
activeDate,
|
|
1070
1363
|
calendarCellStyle,
|
|
1071
1364
|
renderEvent,
|
|
@@ -1077,6 +1370,7 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1077
1370
|
onLongPressEvent,
|
|
1078
1371
|
onPressMore,
|
|
1079
1372
|
onCreateEvent,
|
|
1373
|
+
renderCreateGhost,
|
|
1080
1374
|
onSelectDrag,
|
|
1081
1375
|
fillCellOnSelection,
|
|
1082
1376
|
onDragEvent,
|
|
@@ -1087,6 +1381,22 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1087
1381
|
classNames,
|
|
1088
1382
|
styleOverrides
|
|
1089
1383
|
]);
|
|
1384
|
+
const listExtraData = useMemo(() => numberOfWeeks === void 0 ? monthExtraData : { renderItem }, [
|
|
1385
|
+
numberOfWeeks,
|
|
1386
|
+
monthExtraData,
|
|
1387
|
+
renderItem
|
|
1388
|
+
]);
|
|
1389
|
+
const visible = useMemo(() => numberOfWeeks === void 0 ? null : buildMultiWeekGrid(date, {
|
|
1390
|
+
numberOfWeeks,
|
|
1391
|
+
weekStartsOn,
|
|
1392
|
+
hiddenDays
|
|
1393
|
+
}).visibleRange, [
|
|
1394
|
+
date,
|
|
1395
|
+
numberOfWeeks,
|
|
1396
|
+
weekStartsOn,
|
|
1397
|
+
hiddenDays
|
|
1398
|
+
]);
|
|
1399
|
+
const title = visible ? `${format(visible.start, "PP", { locale })} – ${format(addDays(visible.endExclusive, -1), "PP", { locale })}` : format(date, "MMMM yyyy", { locale });
|
|
1090
1400
|
return /* @__PURE__ */ jsx(CalendarSelectionProvider, {
|
|
1091
1401
|
value: selection,
|
|
1092
1402
|
children: /* @__PURE__ */ jsxs(View, {
|
|
@@ -1099,7 +1409,7 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1099
1409
|
themed: [theme.text.monthTitle, { color: theme.colors.text }]
|
|
1100
1410
|
}),
|
|
1101
1411
|
allowFontScaling: false,
|
|
1102
|
-
children:
|
|
1412
|
+
children: title
|
|
1103
1413
|
}) : null,
|
|
1104
1414
|
renderHeaderForMonthView ? renderHeaderForMonthView(weekDays) : /* @__PURE__ */ jsx(MonthWeekdayHeader, {
|
|
1105
1415
|
weekDays,
|
|
@@ -1157,6 +1467,54 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1157
1467
|
* ```
|
|
1158
1468
|
*/
|
|
1159
1469
|
const MonthPager = memo(MonthPagerInner);
|
|
1470
|
+
/** The swipeable pager behind `MonthPager` and `Calendar`'s row modes. */
|
|
1471
|
+
function DateRowsPagerRoot(props) {
|
|
1472
|
+
const count = props.spec.kind === "multiweek" ? props.spec.numberOfWeeks : void 0;
|
|
1473
|
+
const target = useMemo(() => count === void 0 ? props.date : buildMultiWeekGrid(props.date, {
|
|
1474
|
+
numberOfWeeks: count,
|
|
1475
|
+
weekStartsOn: props.weekStartsOn
|
|
1476
|
+
}).period.start, [
|
|
1477
|
+
props.date,
|
|
1478
|
+
count,
|
|
1479
|
+
props.weekStartsOn
|
|
1480
|
+
]);
|
|
1481
|
+
const [series, setSeries] = useState(() => ({
|
|
1482
|
+
anchor: target,
|
|
1483
|
+
count,
|
|
1484
|
+
weekStartsOn: props.weekStartsOn
|
|
1485
|
+
}));
|
|
1486
|
+
let current = series;
|
|
1487
|
+
if (count !== void 0) {
|
|
1488
|
+
const offset = differenceInCalendarWeeks(target, series.anchor, { weekStartsOn: props.weekStartsOn }) / count;
|
|
1489
|
+
if (series.count !== count || series.weekStartsOn !== props.weekStartsOn || !Number.isInteger(offset) || Math.abs(offset) > PAGE_WINDOW$1) {
|
|
1490
|
+
current = {
|
|
1491
|
+
anchor: target,
|
|
1492
|
+
count,
|
|
1493
|
+
weekStartsOn: props.weekStartsOn
|
|
1494
|
+
};
|
|
1495
|
+
setSeries(current);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
const key = count === void 0 ? "month" : `${current.anchor.getTime()}:${count}:${props.weekStartsOn}`;
|
|
1499
|
+
const generation = useRef(key);
|
|
1500
|
+
generation.current = key;
|
|
1501
|
+
useEffect(() => {
|
|
1502
|
+
generation.current = key;
|
|
1503
|
+
return () => {
|
|
1504
|
+
generation.current = "unmounted";
|
|
1505
|
+
};
|
|
1506
|
+
}, [key]);
|
|
1507
|
+
const onChangeDate = useCallback((date) => {
|
|
1508
|
+
if (generation.current === key) props.onChangeDate(date);
|
|
1509
|
+
}, [key, props.onChangeDate]);
|
|
1510
|
+
return /* @__PURE__ */ createElement(DateRowsPagerInner, {
|
|
1511
|
+
...props,
|
|
1512
|
+
key,
|
|
1513
|
+
initialAnchor: count === void 0 ? void 0 : current.anchor,
|
|
1514
|
+
onChangeDate
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
const DateRowsPager = memo(DateRowsPagerRoot);
|
|
1160
1518
|
const MonthWeekdayHeader = ({ weekDays, weekdayFormat = "short", locale, slot }) => {
|
|
1161
1519
|
const theme = useCalendarTheme();
|
|
1162
1520
|
return /* @__PURE__ */ jsx(View, {
|
|
@@ -1680,4 +2038,4 @@ const styles = StyleSheet.create({
|
|
|
1680
2038
|
fontWeight: "600"
|
|
1681
2039
|
}
|
|
1682
2040
|
});
|
|
1683
|
-
export {
|
|
2041
|
+
export { mergeTheme as _, DateRows as a, useWebPagerKeys as c, useSlots as d, CalendarLabelsContext as f, defaultTheme as g, darkTheme as h, MonthPager as i, SlotStylesProvider as l, CalendarThemeProvider as m, DefaultMonthEvent as n, MonthView as o, useCalendarLabels as p, DateRowsPager as r, withEventAccessibilityLabel as s, MonthList as t, createSlots as u, useCalendarTheme as v };
|