@super-calendar/native 2.16.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/dist/{DefaultMonthEvent-ClIxUp__.d.ts → DefaultMonthEvent-C3C30hfV.d.mts} +8 -8
- package/dist/{DefaultMonthEvent-No5YhOcV.d.mts → DefaultMonthEvent-Dx3lD7ig.d.ts} +8 -8
- package/dist/{MonthList-Dmp8JXvj.js → MonthList-B2TSGYp7.js} +400 -91
- package/dist/{MonthList-D97JhM4F.mjs → MonthList-N1GVDIE4.mjs} +391 -94
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +68 -11
- package/dist/index.mjs +63 -13
- package/dist/picker.d.mts +1 -1
- package/dist/picker.d.ts +1 -1
- package/dist/picker.js +1 -1
- package/dist/picker.mjs +1 -1
- package/package.json +2 -2
- package/src/components/Calendar.tsx +74 -9
- package/src/components/MonthPager.tsx +175 -20
- package/src/components/MonthView.tsx +332 -116
- package/src/components/MultiWeekView.tsx +34 -0
- package/src/index.tsx +7 -0
- 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, 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,6 +198,61 @@ 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";
|
|
203
258
|
const DAY_CELL_PADDING_TOP = 4;
|
|
@@ -234,7 +289,28 @@ function isInCreateSpan(drag, day) {
|
|
|
234
289
|
const b = startOfDay(drag.hover).getTime();
|
|
235
290
|
return time >= Math.min(a, b) && time <= Math.max(a, b);
|
|
236
291
|
}
|
|
237
|
-
function MonthViewInner({ date,
|
|
292
|
+
function MonthViewInner({ date, showAdjacentMonths = true, showSixWeeks = false, ...rest }) {
|
|
293
|
+
const source = useMemo(() => ({
|
|
294
|
+
kind: "month",
|
|
295
|
+
date,
|
|
296
|
+
showAdjacentMonths,
|
|
297
|
+
showSixWeeks
|
|
298
|
+
}), [
|
|
299
|
+
date,
|
|
300
|
+
showAdjacentMonths,
|
|
301
|
+
showSixWeeks
|
|
302
|
+
]);
|
|
303
|
+
return /* @__PURE__ */ jsx(DateRows, {
|
|
304
|
+
...rest,
|
|
305
|
+
source
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function DateRowsInner({ source, events, maxVisibleEventCount, chipHeight, chipGap = CELL_ROW_GAP, weekStartsOn, hiddenDays, weekdayFormat = "short", locale, 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, onSelectDrag, onDragEvent, onDragStart, eventStartEditable = true, eventOverlap = true, renderCustomDateForMonth, onDayPointerDown, onDayPointerEnter, classNames, styles: styleOverrides }) {
|
|
309
|
+
const { date } = source;
|
|
310
|
+
const multiWeek = source.kind === "multiweek";
|
|
311
|
+
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
312
|
+
const showSixWeeks = source.kind === "month" ? source.showSixWeeks : false;
|
|
313
|
+
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : void 0;
|
|
238
314
|
const theme = useCalendarTheme();
|
|
239
315
|
const badgeArea = 28 + chipGap;
|
|
240
316
|
const slot = createSlots({
|
|
@@ -257,17 +333,32 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
257
333
|
const [hoveredKey, setHoveredKey] = useState(null);
|
|
258
334
|
const [pressedKey, setPressedKey] = useState(null);
|
|
259
335
|
const [moreOpenFor, setMoreOpenFor] = useState(null);
|
|
260
|
-
const
|
|
336
|
+
const multiWeekGrid = useMemo(() => numberOfWeeks === void 0 ? null : buildMultiWeekGrid(date, {
|
|
337
|
+
numberOfWeeks,
|
|
338
|
+
weekStartsOn,
|
|
339
|
+
isRTL,
|
|
340
|
+
hiddenDays
|
|
341
|
+
}), [
|
|
342
|
+
date,
|
|
343
|
+
numberOfWeeks,
|
|
344
|
+
weekStartsOn,
|
|
345
|
+
isRTL,
|
|
346
|
+
hiddenDays
|
|
347
|
+
]);
|
|
348
|
+
const weeks = useMemo(() => multiWeekGrid ? multiWeekGrid.weeks.map((week) => week.days.map((day) => day.date)) : buildMonthWeeks(date, weekStartsOn, {
|
|
261
349
|
showSixWeeks,
|
|
262
350
|
isRTL,
|
|
263
351
|
hiddenDays
|
|
264
352
|
}), [
|
|
353
|
+
multiWeekGrid,
|
|
265
354
|
date,
|
|
266
355
|
weekStartsOn,
|
|
267
356
|
isRTL,
|
|
268
357
|
showSixWeeks,
|
|
269
358
|
hiddenDays
|
|
270
359
|
]);
|
|
360
|
+
const title = multiWeekGrid ? `${format(multiWeekGrid.visibleRange.start, "PP", { locale })} – ${format(addDays(multiWeekGrid.visibleRange.endExclusive, -1), "PP", { locale })}` : format(date, "MMMM yyyy", { locale });
|
|
361
|
+
const windowKey = multiWeekGrid ? `${multiWeekGrid.period.start.getTime()}:${numberOfWeeks}:${hiddenDays?.join(",")}:${isRTL}` : null;
|
|
271
362
|
const weekdayLabels = useMemo(() => {
|
|
272
363
|
const days = filterHiddenDays(getWeekDays(date, weekStartsOn), hiddenDays);
|
|
273
364
|
return isRTL ? days.reverse() : days;
|
|
@@ -290,6 +381,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
290
381
|
chipHeight,
|
|
291
382
|
chipGap
|
|
292
383
|
]);
|
|
384
|
+
const minimumRowHeight = badgeArea + Math.max(1, maxVisibleEventCount ?? FALLBACK_VISIBLE_COUNT) * chipMetrics.chipRowHeight;
|
|
293
385
|
const capacity = useMemo(() => {
|
|
294
386
|
if (maxVisibleEventCount != null) return {
|
|
295
387
|
full: maxVisibleEventCount,
|
|
@@ -318,7 +410,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
318
410
|
if (sortedMonthView) for (const list of map.values()) list.sort(compareDayEvents);
|
|
319
411
|
return map;
|
|
320
412
|
}, [events, sortedMonthView]);
|
|
321
|
-
const showGrid = events.length > 0;
|
|
413
|
+
const showGrid = multiWeek || events.length > 0;
|
|
322
414
|
const weekLayouts = useMemo(() => showGrid ? weeks.map((week) => layoutMonthWeek(week, collectRowEvents(week, eventsByDay))) : [], [
|
|
323
415
|
showGrid,
|
|
324
416
|
weeks,
|
|
@@ -326,20 +418,55 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
326
418
|
]);
|
|
327
419
|
const dragEnabled = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
328
420
|
const gridRef = useRef(null);
|
|
421
|
+
const heldTouch = useRef(null);
|
|
422
|
+
const heldOrigin = useRef(null);
|
|
329
423
|
const [drag, setDrag] = useState(null);
|
|
330
424
|
const dragRef = useRef(null);
|
|
425
|
+
const interactionWindow = useRef(windowKey);
|
|
426
|
+
interactionWindow.current = windowKey;
|
|
427
|
+
const mounted = useRef(true);
|
|
428
|
+
useEffect(() => {
|
|
429
|
+
mounted.current = true;
|
|
430
|
+
return () => {
|
|
431
|
+
mounted.current = false;
|
|
432
|
+
dragRef.current = null;
|
|
433
|
+
};
|
|
434
|
+
}, []);
|
|
331
435
|
const movedRef = useRef(false);
|
|
332
436
|
const suppressPressRef = useRef(false);
|
|
333
437
|
const applyDrag = useCallback((next) => {
|
|
334
438
|
dragRef.current = next;
|
|
335
439
|
setDrag(next);
|
|
336
440
|
}, []);
|
|
441
|
+
useEffect(() => {
|
|
442
|
+
if (windowKey === null) return;
|
|
443
|
+
applyDrag(null);
|
|
444
|
+
setMoreOpenFor(null);
|
|
445
|
+
return () => {
|
|
446
|
+
dragRef.current = null;
|
|
447
|
+
};
|
|
448
|
+
}, [windowKey, applyDrag]);
|
|
449
|
+
useEffect(() => () => {
|
|
450
|
+
heldTouch.current?.();
|
|
451
|
+
}, [windowKey]);
|
|
337
452
|
const consumeSuppressedPress = useCallback(() => {
|
|
338
453
|
if (!suppressPressRef.current) return false;
|
|
339
454
|
suppressPressRef.current = false;
|
|
340
455
|
return true;
|
|
341
456
|
}, []);
|
|
342
457
|
const canMoveEvent = useCallback((event) => !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable), [eventStartEditable]);
|
|
458
|
+
useEffect(() => {
|
|
459
|
+
const origin = heldOrigin.current;
|
|
460
|
+
if (!origin) return;
|
|
461
|
+
const current = dragRef.current;
|
|
462
|
+
const destination = current ? current.kind === "create" ? current.hover : current.to : origin.day;
|
|
463
|
+
const constraints = {
|
|
464
|
+
minDate,
|
|
465
|
+
maxDate,
|
|
466
|
+
isDateDisabled
|
|
467
|
+
};
|
|
468
|
+
if (!isDateSelectable(origin.day, constraints) || !isDateSelectable(destination, constraints) || (origin.event ? !onDragEvent || !events.includes(origin.event) || !canMoveEvent(origin.event) : !onCreateEvent && !onSelectDrag)) heldTouch.current?.();
|
|
469
|
+
});
|
|
343
470
|
const hitTest = useCallback((x, y) => {
|
|
344
471
|
const { width, height } = gridSize;
|
|
345
472
|
if (width <= 0 || height <= 0 || weeks.length === 0) return null;
|
|
@@ -375,10 +502,16 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
375
502
|
maxDate,
|
|
376
503
|
isDateDisabled
|
|
377
504
|
]);
|
|
378
|
-
const beginDrag = useCallback((x, y) => {
|
|
505
|
+
const beginDrag = useCallback((x, y, origin) => {
|
|
506
|
+
if (!mounted.current || multiWeek && interactionWindow.current !== windowKey) return;
|
|
507
|
+
if (origin && (!isDateSelectable(origin.day, {
|
|
508
|
+
minDate,
|
|
509
|
+
maxDate,
|
|
510
|
+
isDateDisabled
|
|
511
|
+
}) || origin.event && !events.includes(origin.event))) return;
|
|
379
512
|
suppressPressRef.current = false;
|
|
380
513
|
movedRef.current = false;
|
|
381
|
-
const hit = hitTest(x, y);
|
|
514
|
+
const hit = origin ?? hitTest(x, y);
|
|
382
515
|
if (!hit) return;
|
|
383
516
|
if (hit.event) {
|
|
384
517
|
if (!onDragEvent || !canMoveEvent(hit.event)) return;
|
|
@@ -403,7 +536,13 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
403
536
|
onSelectDrag,
|
|
404
537
|
onDragStart,
|
|
405
538
|
canMoveEvent,
|
|
406
|
-
applyDrag
|
|
539
|
+
applyDrag,
|
|
540
|
+
multiWeek,
|
|
541
|
+
windowKey,
|
|
542
|
+
minDate,
|
|
543
|
+
maxDate,
|
|
544
|
+
isDateDisabled,
|
|
545
|
+
events
|
|
407
546
|
]);
|
|
408
547
|
const extendDrag = useCallback((x, y) => {
|
|
409
548
|
const current = dragRef.current;
|
|
@@ -483,13 +622,57 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
483
622
|
target.addEventListener?.("pointerup", up);
|
|
484
623
|
const node = gridRef.current;
|
|
485
624
|
if (node?.style) {
|
|
486
|
-
node.style.touchAction = "none";
|
|
625
|
+
node.style.touchAction = multiWeek ? "pan-y" : "none";
|
|
487
626
|
node.style.userSelect = "none";
|
|
488
627
|
}
|
|
489
628
|
return () => target.removeEventListener?.("pointerup", up);
|
|
490
|
-
}, [
|
|
629
|
+
}, [
|
|
630
|
+
dragEnabled,
|
|
631
|
+
endDrag,
|
|
632
|
+
multiWeek
|
|
633
|
+
]);
|
|
634
|
+
const webDragHandlers = useRef({
|
|
635
|
+
beginDrag,
|
|
636
|
+
extendDrag
|
|
637
|
+
});
|
|
638
|
+
webDragHandlers.current = {
|
|
639
|
+
beginDrag,
|
|
640
|
+
extendDrag
|
|
641
|
+
};
|
|
642
|
+
const pressWebGrid = (event) => {
|
|
643
|
+
const pointer = event.nativeEvent;
|
|
644
|
+
if (multiWeek && (pointer.button !== 0 || pointer.isPrimary === false || heldTouch.current)) return;
|
|
645
|
+
if (multiWeek) suppressPressRef.current = false;
|
|
646
|
+
const start = () => {
|
|
647
|
+
const point = gridPoint(pointer.clientX, pointer.clientY);
|
|
648
|
+
if (point) webDragHandlers.current.beginDrag(point.x, point.y);
|
|
649
|
+
};
|
|
650
|
+
if (!multiWeek || !pointer.pointerType || pointer.pointerType === "mouse") {
|
|
651
|
+
start();
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const node = gridRef.current;
|
|
655
|
+
if (!node) return;
|
|
656
|
+
const point = gridPoint(pointer.clientX, pointer.clientY);
|
|
657
|
+
if (!point) return;
|
|
658
|
+
const origin = hitTest(point.x, point.y);
|
|
659
|
+
if (!origin) return;
|
|
660
|
+
heldOrigin.current = origin;
|
|
661
|
+
heldTouch.current = holdWebDateDrag(node, pointer, () => {
|
|
662
|
+
if (interactionWindow.current === windowKey) webDragHandlers.current.beginDrag(point.x, point.y, origin);
|
|
663
|
+
}, (x, y) => {
|
|
664
|
+
const point = gridPoint(x, y);
|
|
665
|
+
if (point) webDragHandlers.current.extendDrag(point.x, point.y);
|
|
666
|
+
}, () => {
|
|
667
|
+
applyDrag(null);
|
|
668
|
+
movedRef.current = false;
|
|
669
|
+
}, () => {
|
|
670
|
+
heldTouch.current = null;
|
|
671
|
+
heldOrigin.current = null;
|
|
672
|
+
});
|
|
673
|
+
};
|
|
491
674
|
const renderDay = (day, dayCol, rowLayout, visibleLanes) => {
|
|
492
|
-
const isCurrentMonth = isSameMonth(day, date);
|
|
675
|
+
const isCurrentMonth = multiWeek || isSameMonth(day, date);
|
|
493
676
|
if (!isCurrentMonth && !showAdjacentMonths) return /* @__PURE__ */ jsx(View, { ...slot("day", {
|
|
494
677
|
base: [styles$3.dayCell, { gap: chipGap }],
|
|
495
678
|
themed: [showGrid && {
|
|
@@ -670,7 +853,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
670
853
|
themed: [theme.text.monthTitle, { color: theme.colors.text }]
|
|
671
854
|
}),
|
|
672
855
|
allowFontScaling: false,
|
|
673
|
-
children:
|
|
856
|
+
children: title
|
|
674
857
|
}) : null,
|
|
675
858
|
showWeekdays ? /* @__PURE__ */ jsx(View, {
|
|
676
859
|
...slot("weekdays", {
|
|
@@ -713,7 +896,7 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
713
896
|
style: styles$3.moreCardRow,
|
|
714
897
|
children: /* @__PURE__ */ jsx(RenderEventComponent, {
|
|
715
898
|
event,
|
|
716
|
-
mode: "month",
|
|
899
|
+
mode: multiWeek ? "multiweek" : "month",
|
|
717
900
|
isAllDay: isAllDayEvent(event),
|
|
718
901
|
onPress: () => {
|
|
719
902
|
setMoreOpenFor(null);
|
|
@@ -724,74 +907,75 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
724
907
|
})
|
|
725
908
|
})
|
|
726
909
|
}) : 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));
|
|
910
|
+
/* @__PURE__ */ jsx(DateRowsViewport, {
|
|
911
|
+
scrollable: multiWeek,
|
|
912
|
+
children: /* @__PURE__ */ jsx(MonthGridSurface, {
|
|
913
|
+
gesture: dragGesture,
|
|
914
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
915
|
+
ref: gridRef,
|
|
916
|
+
testID: multiWeek ? "multiweek-grid" : "month-grid",
|
|
917
|
+
accessibilityLabel: multiWeek ? title : void 0,
|
|
918
|
+
...slot("grid", { base: [styles$3.container, multiWeek ? { minHeight: minimumRowHeight * weeks.length } : void 0] }),
|
|
919
|
+
onLayout: handleLayout,
|
|
920
|
+
...isWeb$2 && dragEnabled ? {
|
|
921
|
+
onPointerDown: pressWebGrid,
|
|
922
|
+
onPointerMove: (event) => {
|
|
923
|
+
if (heldTouch.current) return;
|
|
924
|
+
if (!dragRef.current) return;
|
|
925
|
+
const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
|
|
926
|
+
if (point) extendDrag(point.x, point.y);
|
|
756
927
|
}
|
|
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
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
928
|
+
} : null,
|
|
929
|
+
children: weeks.map((week, weekIndex) => {
|
|
930
|
+
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
931
|
+
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
932
|
+
const cols = week.length;
|
|
933
|
+
let firstVisCol = 0;
|
|
934
|
+
let lastVisCol = cols - 1;
|
|
935
|
+
if (showGrid && !showAdjacentMonths) {
|
|
936
|
+
const first = week.findIndex((d) => isSameMonth(d, date));
|
|
937
|
+
if (first !== -1) {
|
|
938
|
+
firstVisCol = first;
|
|
939
|
+
lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return /* @__PURE__ */ createElement(View, {
|
|
943
|
+
...slot("week", {
|
|
944
|
+
base: styles$3.weekRow,
|
|
945
|
+
themed: theme.containers.weekRow
|
|
946
|
+
}),
|
|
947
|
+
key: multiWeekGrid?.weeks[weekIndex].id ?? week[0].toISOString()
|
|
948
|
+
}, week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes)), showGrid ? /* @__PURE__ */ jsx(View, {
|
|
949
|
+
style: [StyleSheet.absoluteFill, multiWeek ? styles$3.childrenOnlyPointerEvents : { pointerEvents: "box-none" }],
|
|
950
|
+
children: rowLayout.segments.filter((seg) => seg.lane < visibleLanes).map((seg) => {
|
|
951
|
+
const startCol = Math.max(seg.startCol, firstVisCol);
|
|
952
|
+
const endCol = Math.min(seg.endCol, lastVisCol);
|
|
953
|
+
if (startCol > endCol) return null;
|
|
954
|
+
const isDragged = drag?.kind === "move" && drag.event === seg.event;
|
|
955
|
+
return /* @__PURE__ */ jsx(View, {
|
|
956
|
+
style: [{
|
|
957
|
+
position: "absolute",
|
|
958
|
+
left: pct(startCol / cols * 100),
|
|
959
|
+
width: pct((endCol - startCol + 1) / cols * 100),
|
|
960
|
+
top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
|
|
961
|
+
height: chipMetrics.chipHeight,
|
|
962
|
+
paddingHorizontal: CHIP_INSET_H,
|
|
963
|
+
opacity: isDragged ? DRAGGED_BAR_OPACITY : 1
|
|
964
|
+
}, multiWeek ? drag ? styles$3.noPointerEvents : styles$3.childrenOnlyPointerEvents : { pointerEvents: drag ? "none" : "box-none" }],
|
|
965
|
+
children: /* @__PURE__ */ jsx(RenderEventComponent, {
|
|
966
|
+
event: seg.event,
|
|
967
|
+
mode: multiWeek ? "multiweek" : "month",
|
|
968
|
+
isAllDay: isAllDayEvent(seg.event),
|
|
969
|
+
onPress: disableMonthEventCellPress ? () => {} : () => {
|
|
970
|
+
if (consumeSuppressedPress()) return;
|
|
971
|
+
onPressEvent(seg.event);
|
|
972
|
+
},
|
|
973
|
+
onLongPress: disableMonthEventCellPress || !onLongPressEvent ? void 0 : () => onLongPressEvent(seg.event)
|
|
974
|
+
})
|
|
975
|
+
}, `bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`);
|
|
976
|
+
})
|
|
977
|
+
}) : null);
|
|
978
|
+
})
|
|
795
979
|
})
|
|
796
980
|
})
|
|
797
981
|
})
|
|
@@ -799,6 +983,13 @@ function MonthViewInner({ date, events, maxVisibleEventCount, chipHeight, chipGa
|
|
|
799
983
|
})
|
|
800
984
|
});
|
|
801
985
|
}
|
|
986
|
+
function DateRowsViewport({ scrollable, children }) {
|
|
987
|
+
return scrollable ? /* @__PURE__ */ jsx(ScrollView, {
|
|
988
|
+
style: styles$3.container,
|
|
989
|
+
contentContainerStyle: { flexGrow: 1 },
|
|
990
|
+
children
|
|
991
|
+
}) : children;
|
|
992
|
+
}
|
|
802
993
|
function MonthGridSurface({ gesture, children }) {
|
|
803
994
|
if (!gesture) return children;
|
|
804
995
|
return /* @__PURE__ */ jsx(GestureDetector, {
|
|
@@ -823,6 +1014,11 @@ function MonthGridSurface({ gesture, children }) {
|
|
|
823
1014
|
* ```
|
|
824
1015
|
*/
|
|
825
1016
|
const MonthView = memo(MonthViewInner);
|
|
1017
|
+
/**
|
|
1018
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
1019
|
+
* spanning event bars, overflow, selection, and drag handling.
|
|
1020
|
+
*/
|
|
1021
|
+
const DateRows = memo(DateRowsInner);
|
|
826
1022
|
const styles$3 = StyleSheet.create({
|
|
827
1023
|
root: { flex: 1 },
|
|
828
1024
|
title: {
|
|
@@ -839,6 +1035,8 @@ const styles$3 = StyleSheet.create({
|
|
|
839
1035
|
textAlign: "center"
|
|
840
1036
|
},
|
|
841
1037
|
container: { flex: 1 },
|
|
1038
|
+
childrenOnlyPointerEvents: { pointerEvents: "box-none" },
|
|
1039
|
+
noPointerEvents: { pointerEvents: "none" },
|
|
842
1040
|
weekRow: {
|
|
843
1041
|
flex: 1,
|
|
844
1042
|
flexDirection: "row"
|
|
@@ -898,7 +1096,18 @@ const styles$3 = StyleSheet.create({
|
|
|
898
1096
|
const isWeb$1 = Platform.OS === "web";
|
|
899
1097
|
const PAGE_WINDOW$1 = 60;
|
|
900
1098
|
const PAGE_VIEWABILITY = { itemVisiblePercentThreshold: 90 };
|
|
901
|
-
function MonthPagerInner({
|
|
1099
|
+
function MonthPagerInner({ showAdjacentMonths = true, showSixWeeks = false, ...rest }) {
|
|
1100
|
+
const spec = useMemo(() => ({
|
|
1101
|
+
kind: "month",
|
|
1102
|
+
showAdjacentMonths,
|
|
1103
|
+
showSixWeeks
|
|
1104
|
+
}), [showAdjacentMonths, showSixWeeks]);
|
|
1105
|
+
return /* @__PURE__ */ jsx(DateRowsPager, {
|
|
1106
|
+
...rest,
|
|
1107
|
+
spec
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
function DateRowsPagerInner({ spec, initialAnchor, date, events, maxVisibleEventCount, chipHeight, chipGap, weekStartsOn, hiddenDays, weekdayFormat = "short", locale, sortedMonthView, moreLabel, labels, highlightWeekends, disableMonthEventCellPress, isRTL, calendarCellStyle, renderEvent, keyExtractor, onPressDay, onLongPressDay, onPressCell, onPressEvent, onLongPressEvent, onPressMore, onCreateEvent, 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
1111
|
const theme = useCalendarTheme();
|
|
903
1112
|
const slot = useMemo(() => createSlots({
|
|
904
1113
|
classNames,
|
|
@@ -925,10 +1134,23 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
925
1134
|
}, []);
|
|
926
1135
|
const [pageHeight, setPageHeight] = useState(height);
|
|
927
1136
|
const [containerWidth, setContainerWidth] = useState(width);
|
|
928
|
-
const [anchorDate] = useState(date);
|
|
929
|
-
const
|
|
930
|
-
const
|
|
931
|
-
|
|
1137
|
+
const [anchorDate] = useState(initialAnchor ?? date);
|
|
1138
|
+
const numberOfWeeks = spec.kind === "multiweek" ? spec.numberOfWeeks : void 0;
|
|
1139
|
+
const anchor = useMemo(() => numberOfWeeks === void 0 ? startOfMonth(anchorDate) : startOfWeek(anchorDate, { weekStartsOn }), [
|
|
1140
|
+
anchorDate,
|
|
1141
|
+
numberOfWeeks,
|
|
1142
|
+
weekStartsOn
|
|
1143
|
+
]);
|
|
1144
|
+
const monthDates = useMemo(() => {
|
|
1145
|
+
const dates = Array.from({ length: 121 }, (_, i) => numberOfWeeks === void 0 ? addMonths(anchor, i - PAGE_WINDOW$1) : addWeeks(anchor, (i - PAGE_WINDOW$1) * numberOfWeeks));
|
|
1146
|
+
return numberOfWeeks === void 0 ? dates : dates.filter((page) => Number.isFinite(page.getTime()) && Number.isFinite(addWeeks(page, numberOfWeeks).getTime()));
|
|
1147
|
+
}, [anchor, numberOfWeeks]);
|
|
1148
|
+
const activeIndex = useCallback((target) => numberOfWeeks === void 0 ? differenceInCalendarMonths(startOfMonth(target), anchor) + PAGE_WINDOW$1 : differenceInCalendarWeeks(target, monthDates[0], { weekStartsOn }) / numberOfWeeks, [
|
|
1149
|
+
anchor,
|
|
1150
|
+
monthDates,
|
|
1151
|
+
numberOfWeeks,
|
|
1152
|
+
weekStartsOn
|
|
1153
|
+
])(date);
|
|
932
1154
|
const viewedIndexRef = useRef(activeIndex);
|
|
933
1155
|
const pendingScrollIndexRef = useRef(null);
|
|
934
1156
|
const handleViewableItemsChanged = useCallback((info) => {
|
|
@@ -972,7 +1194,7 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
972
1194
|
isRTL,
|
|
973
1195
|
hiddenDays
|
|
974
1196
|
]);
|
|
975
|
-
const
|
|
1197
|
+
const monthExtraData = useMemo(() => ({
|
|
976
1198
|
events,
|
|
977
1199
|
activeDate,
|
|
978
1200
|
fillCellOnSelection,
|
|
@@ -1000,6 +1222,20 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1000
1222
|
maxDate,
|
|
1001
1223
|
isDateDisabled
|
|
1002
1224
|
]);
|
|
1225
|
+
const sourceFor = useMemo(() => {
|
|
1226
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
1227
|
+
return (item) => {
|
|
1228
|
+
let source = cache.get(item);
|
|
1229
|
+
if (!source) {
|
|
1230
|
+
source = {
|
|
1231
|
+
...spec,
|
|
1232
|
+
date: item
|
|
1233
|
+
};
|
|
1234
|
+
cache.set(item, source);
|
|
1235
|
+
}
|
|
1236
|
+
return source;
|
|
1237
|
+
};
|
|
1238
|
+
}, [spec]);
|
|
1003
1239
|
const snapToIndices = useMemo(() => monthDates.map((_, index) => index), [monthDates]);
|
|
1004
1240
|
const keyExtractorList = useCallback((item) => item.toISOString(), []);
|
|
1005
1241
|
const getFixedItemSize = useCallback(() => containerWidth, [containerWidth]);
|
|
@@ -1008,8 +1244,8 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1008
1244
|
width: containerWidth,
|
|
1009
1245
|
height: pageHeight
|
|
1010
1246
|
},
|
|
1011
|
-
children: /* @__PURE__ */ jsx(
|
|
1012
|
-
|
|
1247
|
+
children: /* @__PURE__ */ jsx(DateRows, {
|
|
1248
|
+
source: sourceFor(item),
|
|
1013
1249
|
events,
|
|
1014
1250
|
showTitle: false,
|
|
1015
1251
|
showWeekdays: false,
|
|
@@ -1022,11 +1258,9 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1022
1258
|
sortedMonthView,
|
|
1023
1259
|
moreLabel,
|
|
1024
1260
|
labels,
|
|
1025
|
-
showAdjacentMonths,
|
|
1026
1261
|
highlightWeekends,
|
|
1027
1262
|
disableMonthEventCellPress,
|
|
1028
1263
|
isRTL,
|
|
1029
|
-
showSixWeeks,
|
|
1030
1264
|
activeDate,
|
|
1031
1265
|
calendarCellStyle,
|
|
1032
1266
|
renderEvent,
|
|
@@ -1061,11 +1295,10 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1061
1295
|
sortedMonthView,
|
|
1062
1296
|
moreLabel,
|
|
1063
1297
|
labels,
|
|
1064
|
-
|
|
1298
|
+
sourceFor,
|
|
1065
1299
|
highlightWeekends,
|
|
1066
1300
|
disableMonthEventCellPress,
|
|
1067
1301
|
isRTL,
|
|
1068
|
-
showSixWeeks,
|
|
1069
1302
|
activeDate,
|
|
1070
1303
|
calendarCellStyle,
|
|
1071
1304
|
renderEvent,
|
|
@@ -1087,6 +1320,22 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1087
1320
|
classNames,
|
|
1088
1321
|
styleOverrides
|
|
1089
1322
|
]);
|
|
1323
|
+
const listExtraData = useMemo(() => numberOfWeeks === void 0 ? monthExtraData : { renderItem }, [
|
|
1324
|
+
numberOfWeeks,
|
|
1325
|
+
monthExtraData,
|
|
1326
|
+
renderItem
|
|
1327
|
+
]);
|
|
1328
|
+
const visible = useMemo(() => numberOfWeeks === void 0 ? null : buildMultiWeekGrid(date, {
|
|
1329
|
+
numberOfWeeks,
|
|
1330
|
+
weekStartsOn,
|
|
1331
|
+
hiddenDays
|
|
1332
|
+
}).visibleRange, [
|
|
1333
|
+
date,
|
|
1334
|
+
numberOfWeeks,
|
|
1335
|
+
weekStartsOn,
|
|
1336
|
+
hiddenDays
|
|
1337
|
+
]);
|
|
1338
|
+
const title = visible ? `${format(visible.start, "PP", { locale })} – ${format(addDays(visible.endExclusive, -1), "PP", { locale })}` : format(date, "MMMM yyyy", { locale });
|
|
1090
1339
|
return /* @__PURE__ */ jsx(CalendarSelectionProvider, {
|
|
1091
1340
|
value: selection,
|
|
1092
1341
|
children: /* @__PURE__ */ jsxs(View, {
|
|
@@ -1099,7 +1348,7 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1099
1348
|
themed: [theme.text.monthTitle, { color: theme.colors.text }]
|
|
1100
1349
|
}),
|
|
1101
1350
|
allowFontScaling: false,
|
|
1102
|
-
children:
|
|
1351
|
+
children: title
|
|
1103
1352
|
}) : null,
|
|
1104
1353
|
renderHeaderForMonthView ? renderHeaderForMonthView(weekDays) : /* @__PURE__ */ jsx(MonthWeekdayHeader, {
|
|
1105
1354
|
weekDays,
|
|
@@ -1157,6 +1406,54 @@ function MonthPagerInner({ date, events, maxVisibleEventCount, chipHeight, chipG
|
|
|
1157
1406
|
* ```
|
|
1158
1407
|
*/
|
|
1159
1408
|
const MonthPager = memo(MonthPagerInner);
|
|
1409
|
+
/** The swipeable pager behind `MonthPager` and `Calendar`'s row modes. */
|
|
1410
|
+
function DateRowsPagerRoot(props) {
|
|
1411
|
+
const count = props.spec.kind === "multiweek" ? props.spec.numberOfWeeks : void 0;
|
|
1412
|
+
const target = useMemo(() => count === void 0 ? props.date : buildMultiWeekGrid(props.date, {
|
|
1413
|
+
numberOfWeeks: count,
|
|
1414
|
+
weekStartsOn: props.weekStartsOn
|
|
1415
|
+
}).period.start, [
|
|
1416
|
+
props.date,
|
|
1417
|
+
count,
|
|
1418
|
+
props.weekStartsOn
|
|
1419
|
+
]);
|
|
1420
|
+
const [series, setSeries] = useState(() => ({
|
|
1421
|
+
anchor: target,
|
|
1422
|
+
count,
|
|
1423
|
+
weekStartsOn: props.weekStartsOn
|
|
1424
|
+
}));
|
|
1425
|
+
let current = series;
|
|
1426
|
+
if (count !== void 0) {
|
|
1427
|
+
const offset = differenceInCalendarWeeks(target, series.anchor, { weekStartsOn: props.weekStartsOn }) / count;
|
|
1428
|
+
if (series.count !== count || series.weekStartsOn !== props.weekStartsOn || !Number.isInteger(offset) || Math.abs(offset) > PAGE_WINDOW$1) {
|
|
1429
|
+
current = {
|
|
1430
|
+
anchor: target,
|
|
1431
|
+
count,
|
|
1432
|
+
weekStartsOn: props.weekStartsOn
|
|
1433
|
+
};
|
|
1434
|
+
setSeries(current);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
const key = count === void 0 ? "month" : `${current.anchor.getTime()}:${count}:${props.weekStartsOn}`;
|
|
1438
|
+
const generation = useRef(key);
|
|
1439
|
+
generation.current = key;
|
|
1440
|
+
useEffect(() => {
|
|
1441
|
+
generation.current = key;
|
|
1442
|
+
return () => {
|
|
1443
|
+
generation.current = "unmounted";
|
|
1444
|
+
};
|
|
1445
|
+
}, [key]);
|
|
1446
|
+
const onChangeDate = useCallback((date) => {
|
|
1447
|
+
if (generation.current === key) props.onChangeDate(date);
|
|
1448
|
+
}, [key, props.onChangeDate]);
|
|
1449
|
+
return /* @__PURE__ */ createElement(DateRowsPagerInner, {
|
|
1450
|
+
...props,
|
|
1451
|
+
key,
|
|
1452
|
+
initialAnchor: count === void 0 ? void 0 : current.anchor,
|
|
1453
|
+
onChangeDate
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
const DateRowsPager = memo(DateRowsPagerRoot);
|
|
1160
1457
|
const MonthWeekdayHeader = ({ weekDays, weekdayFormat = "short", locale, slot }) => {
|
|
1161
1458
|
const theme = useCalendarTheme();
|
|
1162
1459
|
return /* @__PURE__ */ jsx(View, {
|
|
@@ -1680,4 +1977,4 @@ const styles = StyleSheet.create({
|
|
|
1680
1977
|
fontWeight: "600"
|
|
1681
1978
|
}
|
|
1682
1979
|
});
|
|
1683
|
-
export {
|
|
1980
|
+
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 };
|