@super-calendar/dom 2.8.2 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/index.d.mts +88 -11
- package/dist/index.d.ts +88 -11
- package/dist/index.js +394 -85
- package/dist/index.mjs +396 -87
- package/package.json +2 -2
- package/src/Calendar.tsx +49 -4
- package/src/MonthView.tsx +200 -50
- package/src/TimeGrid.tsx +257 -54
- package/src/YearView.tsx +218 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-calendar/dom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.1",
|
|
4
4
|
"description": "Virtualized month / week / day calendar and date picker for react-dom. No React Native, no react-native-web.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"calendar",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@super-calendar/core": "2.
|
|
51
|
+
"@super-calendar/core": "2.9.1"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@legendapp/list": ">=3",
|
package/src/Calendar.tsx
CHANGED
|
@@ -55,7 +55,13 @@ export interface CalendarProps<T = unknown>
|
|
|
55
55
|
* a day-grouped agenda list, and the others a time grid.
|
|
56
56
|
*/
|
|
57
57
|
mode?: CalendarMode;
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Controlled anchor date, read in the device's local time zone; change it
|
|
60
|
+
* (e.g. from your own header) to navigate. Construct it as a local date
|
|
61
|
+
* (`new Date(2026, 7, 24)`), not a UTC instant:
|
|
62
|
+
* `new Date("2026-08-24T00:00:00Z")` is still Aug 23 on devices west of UTC
|
|
63
|
+
* and anchors the previous week.
|
|
64
|
+
*/
|
|
59
65
|
date: Date;
|
|
60
66
|
/**
|
|
61
67
|
* Fires with the next/previous period's date when the user pages the focused
|
|
@@ -146,13 +152,24 @@ export interface CalendarProps<T = unknown>
|
|
|
146
152
|
eventOverlap?: boolean;
|
|
147
153
|
/** Snap dragged/created events to this many minutes. */
|
|
148
154
|
dragStepMinutes?: number;
|
|
149
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Tap empty space: the date+time pressed on the week/day grid, or the tapped
|
|
157
|
+
* day at midnight in `month` mode (where it fires alongside `onPressDay`).
|
|
158
|
+
*/
|
|
150
159
|
onPressCell?: (date: Date) => void;
|
|
151
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Drag empty space to create. On the week/day grid that sweeps out a time
|
|
162
|
+
* range; in `month` mode it sweeps out an **all-day** span across the days
|
|
163
|
+
* dragged (`start` at midnight of the first, `end` at midnight after the last).
|
|
164
|
+
*/
|
|
152
165
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
153
166
|
/** Fires when an event drag begins. */
|
|
154
167
|
onDragStart?: (event: CalendarEvent<T>) => void;
|
|
155
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Enables drag-to-move/resize; return `false` to reject the drop. In `month`
|
|
170
|
+
* mode an event chip can be dragged onto another day, shifting both ends by the
|
|
171
|
+
* days dragged so the time of day and duration are kept.
|
|
172
|
+
*/
|
|
156
173
|
onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
|
|
157
174
|
/** Tap a day's column header. */
|
|
158
175
|
onPressDateHeader?: (day: Date) => void;
|
|
@@ -173,6 +190,11 @@ export interface CalendarProps<T = unknown>
|
|
|
173
190
|
moreLabel?: string;
|
|
174
191
|
/** Render neighbouring months' days in the leading/trailing cells (default true). */
|
|
175
192
|
showAdjacentMonths?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Render the built-in "Month yyyy" title above the month grid. Default true. Set
|
|
195
|
+
* false when your own header already shows the month and year. Month mode only.
|
|
196
|
+
*/
|
|
197
|
+
showTitle?: boolean;
|
|
176
198
|
/** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
177
199
|
weekdayFormat?: WeekdayFormat;
|
|
178
200
|
/** Fill the cell with the range background instead of the pill band. */
|
|
@@ -189,6 +211,13 @@ export interface CalendarProps<T = unknown>
|
|
|
189
211
|
keyboardDayNavigation?: boolean;
|
|
190
212
|
/** Tap a day cell. */
|
|
191
213
|
onPressDay?: (date: Date) => void;
|
|
214
|
+
/**
|
|
215
|
+
* Month and year modes: reports a create sweep's day span as it happens, as the
|
|
216
|
+
* ordered inclusive `[start, end]` days, so a selection highlight can follow the
|
|
217
|
+
* drag. Pair it with `useDateRange`'s `selectRange`. Enables the sweep on its
|
|
218
|
+
* own, so it works without `onCreateEvent`.
|
|
219
|
+
*/
|
|
220
|
+
onSelectDrag?: (start: Date, end: Date) => void;
|
|
192
221
|
/** Tap a month's title in the year view — e.g. jump to that month. */
|
|
193
222
|
onPressMonth?: (month: Date) => void;
|
|
194
223
|
/** Tap the "+N more" overflow row. */
|
|
@@ -309,6 +338,7 @@ export function Calendar<T = unknown>({
|
|
|
309
338
|
maxVisibleEventCount,
|
|
310
339
|
moreLabel,
|
|
311
340
|
showAdjacentMonths,
|
|
341
|
+
showTitle,
|
|
312
342
|
weekdayFormat,
|
|
313
343
|
fillCellOnSelection,
|
|
314
344
|
selectedRange,
|
|
@@ -318,6 +348,7 @@ export function Calendar<T = unknown>({
|
|
|
318
348
|
isDateDisabled,
|
|
319
349
|
keyboardDayNavigation,
|
|
320
350
|
onPressDay,
|
|
351
|
+
onSelectDrag,
|
|
321
352
|
onPressMonth,
|
|
322
353
|
onPressMore,
|
|
323
354
|
renderMonthEvent,
|
|
@@ -371,8 +402,15 @@ export function Calendar<T = unknown>({
|
|
|
371
402
|
style={height != null ? { height, ...style } : style}
|
|
372
403
|
classNames={classNames}
|
|
373
404
|
styles={styles}
|
|
405
|
+
selectedRange={selectedRange}
|
|
406
|
+
selectedDates={selectedDates}
|
|
407
|
+
minDate={minDate}
|
|
408
|
+
maxDate={maxDate}
|
|
409
|
+
isDateDisabled={isDateDisabled}
|
|
374
410
|
onPressDay={onPressDay}
|
|
375
411
|
onPressMonth={onPressMonth}
|
|
412
|
+
onSelectDrag={onSelectDrag}
|
|
413
|
+
onCreateEvent={onCreateEvent}
|
|
376
414
|
/>
|
|
377
415
|
);
|
|
378
416
|
} else if (mode === "schedule") {
|
|
@@ -412,6 +450,7 @@ export function Calendar<T = unknown>({
|
|
|
412
450
|
maxVisibleEventCount={maxVisibleEventCount}
|
|
413
451
|
moreLabel={moreLabel}
|
|
414
452
|
showAdjacentMonths={showAdjacentMonths}
|
|
453
|
+
showTitle={showTitle}
|
|
415
454
|
fillCellOnSelection={fillCellOnSelection}
|
|
416
455
|
selectedRange={selectedRange}
|
|
417
456
|
selectedDates={selectedDates}
|
|
@@ -420,7 +459,13 @@ export function Calendar<T = unknown>({
|
|
|
420
459
|
isDateDisabled={isDateDisabled}
|
|
421
460
|
keyboardDayNavigation={keyboardDayNavigation}
|
|
422
461
|
onPressDay={onPressDay}
|
|
462
|
+
onPressCell={onPressCell}
|
|
423
463
|
onCreateEvent={onCreateEvent}
|
|
464
|
+
onSelectDrag={onSelectDrag}
|
|
465
|
+
onDragEvent={onDragEvent}
|
|
466
|
+
onDragStart={onDragStart}
|
|
467
|
+
eventStartEditable={eventStartEditable}
|
|
468
|
+
eventOverlap={eventOverlap}
|
|
424
469
|
onPressEvent={onPressEvent}
|
|
425
470
|
onPressMore={onPressMore}
|
|
426
471
|
renderEvent={renderMonthEvent}
|
package/src/MonthView.tsx
CHANGED
|
@@ -30,8 +30,11 @@ import {
|
|
|
30
30
|
isBackgroundEvent,
|
|
31
31
|
isAllDayEvent,
|
|
32
32
|
layoutMonthWeek,
|
|
33
|
+
monthCreateRange,
|
|
34
|
+
monthDropBounds,
|
|
33
35
|
type MonthGridDay,
|
|
34
36
|
type MonthGridWeek,
|
|
37
|
+
overlapsOtherEvents,
|
|
35
38
|
rangeBandKind,
|
|
36
39
|
type WeekdayFormat,
|
|
37
40
|
type WeekStartsOn,
|
|
@@ -66,6 +69,8 @@ const DATE_ROW = 24;
|
|
|
66
69
|
const CHIP_HEIGHT = 18;
|
|
67
70
|
const CHIP_GAP = 2;
|
|
68
71
|
const CELL_PAD = 4;
|
|
72
|
+
// Opacity of an event chip while it is being dragged to another day.
|
|
73
|
+
const DRAGGED_CHIP_OPACITY = 0.4;
|
|
69
74
|
|
|
70
75
|
/** Props passed to a custom month event chip renderer. */
|
|
71
76
|
export interface DomMonthEventArgs<T = unknown> {
|
|
@@ -78,6 +83,13 @@ export interface DomMonthEventArgs<T = unknown> {
|
|
|
78
83
|
/** A component that renders a single month-grid event chip. */
|
|
79
84
|
export type DomMonthEvent<T = unknown> = ComponentType<DomMonthEventArgs<T>>;
|
|
80
85
|
|
|
86
|
+
// An in-progress month drag: either a day span being swept out for a new event,
|
|
87
|
+
// or an existing event being carried to another day. Days are held as start-of-day
|
|
88
|
+
// timestamps, so the reducer-ish updates compare cheaply.
|
|
89
|
+
type MonthDrag<T> =
|
|
90
|
+
| { kind: "create"; anchor: number; hover: number }
|
|
91
|
+
| { kind: "move"; event: CalendarEvent<T>; from: number; to: number };
|
|
92
|
+
|
|
81
93
|
/** Props for {@link MonthView}. */
|
|
82
94
|
export interface MonthViewProps<T = unknown>
|
|
83
95
|
extends DateSelectionConstraints, SlotStyleProps<MonthViewSlot> {
|
|
@@ -139,6 +151,11 @@ export interface MonthViewProps<T = unknown>
|
|
|
139
151
|
theme?: Partial<DomCalendarTheme>;
|
|
140
152
|
/** Fired when a selectable day is clicked. */
|
|
141
153
|
onPressDay?: (date: Date) => void;
|
|
154
|
+
/**
|
|
155
|
+
* Fired alongside `onPressDay` when a day cell is clicked, with the same day at
|
|
156
|
+
* midnight, so one handler can create events across month and week/day modes.
|
|
157
|
+
*/
|
|
158
|
+
onPressCell?: (date: Date) => void;
|
|
142
159
|
/**
|
|
143
160
|
* In events mode, enables drag-to-create: press on a day and drag across others
|
|
144
161
|
* to sketch a span, then release to fire this with the all-day range (`start` at
|
|
@@ -147,6 +164,28 @@ export interface MonthViewProps<T = unknown>
|
|
|
147
164
|
* carry `data-creating` for styling.
|
|
148
165
|
*/
|
|
149
166
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
167
|
+
/**
|
|
168
|
+
* Reports the day span of a create sweep **as it happens**, as the ordered
|
|
169
|
+
* inclusive `[start, end]` days (both at midnight), so a selection highlight can
|
|
170
|
+
* follow the drag instead of appearing only on release. Pair it with
|
|
171
|
+
* `useDateRange`'s `selectRange` to drive `selectedRange`. Enables the sweep on
|
|
172
|
+
* its own, so it works without `onCreateEvent`.
|
|
173
|
+
*/
|
|
174
|
+
onSelectDrag?: (start: Date, end: Date) => void;
|
|
175
|
+
/**
|
|
176
|
+
* In events mode, enables drag-to-reschedule: press an event chip and drop it on
|
|
177
|
+
* another day. Called with the event and its new `start`/`end`, both shifted by
|
|
178
|
+
* the whole days dragged, so the time of day and duration are preserved. Return
|
|
179
|
+
* `false` to reject the drop. The day under the pointer carries `data-drop` for
|
|
180
|
+
* styling.
|
|
181
|
+
*/
|
|
182
|
+
onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
|
|
183
|
+
/** Fired the instant an event is picked up for a drag, before anything is committed. */
|
|
184
|
+
onDragStart?: (event: CalendarEvent<T>) => void;
|
|
185
|
+
/** Allow moving events by default (per-event `startEditable` overrides). Default true. */
|
|
186
|
+
eventStartEditable?: boolean;
|
|
187
|
+
/** Reject a drop that would overlap another event (default true = allowed). */
|
|
188
|
+
eventOverlap?: boolean;
|
|
150
189
|
/**
|
|
151
190
|
* When events are shown, also make the day cells keyboard-navigable: a single
|
|
152
191
|
* roving tab stop, arrow keys move the focus, Enter opens the day (`onPressDay`).
|
|
@@ -198,28 +237,39 @@ function dayCellDefault(
|
|
|
198
237
|
* rounded strip (the default) or fill the whole cell (`fillCell`). Returns null
|
|
199
238
|
* for days with no band. Endpoints get the leading/trailing pill rounding. Its
|
|
200
239
|
* geometry is structural; only the fill colour is themed.
|
|
240
|
+
*
|
|
241
|
+
* In events mode the strip tracks the compact date badge instead of the picker's
|
|
242
|
+
* tall cell, so it reads as a band across the dates rather than a block over the
|
|
243
|
+
* event chips (and matches the native renderer's month grid).
|
|
201
244
|
*/
|
|
202
245
|
function rangeBandDefault(
|
|
203
246
|
day: MonthGridDay,
|
|
204
247
|
theme: DomCalendarTheme,
|
|
205
248
|
fillCell: boolean,
|
|
249
|
+
eventsMode: boolean,
|
|
206
250
|
): SlotDefault | null {
|
|
207
251
|
const kind = rangeBandKind(day, fillCell);
|
|
208
252
|
if (kind === "none") return null;
|
|
209
253
|
const fill = kind === "fill";
|
|
210
|
-
const
|
|
211
|
-
const
|
|
254
|
+
const badgeSize = eventsMode ? DATE_ROW - 2 : theme.dayBadgeSize;
|
|
255
|
+
const bandHeight = eventsMode ? badgeSize : theme.rangeBandHeight;
|
|
256
|
+
const inset = fill ? 0 : eventsMode ? CELL_PAD : Math.max(0, (theme.cellHeight - bandHeight) / 2);
|
|
257
|
+
const radius = fill ? 0 : bandHeight / 2;
|
|
212
258
|
const rounding = bandRounding(kind);
|
|
213
259
|
// Cap the pill at the endpoint circles: a start/end band stops at the circle's
|
|
214
260
|
// outer edge (half a badge in from the cell centre) rather than spilling to the
|
|
215
|
-
// cell edge, so no band shows in the empty space beside the day circles.
|
|
216
|
-
|
|
261
|
+
// cell edge, so no band shows in the empty space beside the day circles. Events
|
|
262
|
+
// mode puts the badge in the cell's corner instead of its centre, so there the
|
|
263
|
+
// band spans the whole cell and only rounds its outer ends.
|
|
264
|
+
const cap = eventsMode ? 0 : `calc(50% - ${badgeSize / 2}px)`;
|
|
217
265
|
const base: CSSProperties = {
|
|
218
266
|
position: "absolute",
|
|
219
267
|
left: rounding.start ? cap : 0,
|
|
220
268
|
right: rounding.end ? cap : 0,
|
|
221
269
|
top: inset,
|
|
222
|
-
|
|
270
|
+
// An events cell is far taller than its date row, so the strip is sized from
|
|
271
|
+
// the badge rather than stretched to the cell's bottom.
|
|
272
|
+
...(fill || !eventsMode ? { bottom: inset } : { height: bandHeight }),
|
|
223
273
|
zIndex: 0,
|
|
224
274
|
};
|
|
225
275
|
if (rounding.start) {
|
|
@@ -268,6 +318,9 @@ function eventCellDefault(
|
|
|
268
318
|
theme: DomCalendarTheme,
|
|
269
319
|
height: number,
|
|
270
320
|
highlightWeekends: boolean,
|
|
321
|
+
// True while a drag is over this day: a create sweep covering it, or a move
|
|
322
|
+
// about to land on it. Tinted over the weekend shading so the drag reads live.
|
|
323
|
+
isDragTarget: boolean,
|
|
271
324
|
): SlotDefault {
|
|
272
325
|
return {
|
|
273
326
|
base: {
|
|
@@ -286,8 +339,9 @@ function eventCellDefault(
|
|
|
286
339
|
},
|
|
287
340
|
themed: {
|
|
288
341
|
borderTop: `1px solid ${theme.gridLine}`,
|
|
289
|
-
background:
|
|
290
|
-
|
|
342
|
+
background: isDragTarget
|
|
343
|
+
? theme.rangeBackground
|
|
344
|
+
: highlightWeekends && day.isWeekend && !day.isInRange
|
|
291
345
|
? theme.weekendBackground
|
|
292
346
|
: "transparent",
|
|
293
347
|
color: day.isDisabled ? theme.textDisabled : theme.text,
|
|
@@ -442,7 +496,13 @@ export function MonthView<T = unknown>({
|
|
|
442
496
|
maxDate,
|
|
443
497
|
isDateDisabled,
|
|
444
498
|
onPressDay,
|
|
499
|
+
onPressCell,
|
|
445
500
|
onCreateEvent,
|
|
501
|
+
onSelectDrag,
|
|
502
|
+
onDragEvent,
|
|
503
|
+
onDragStart,
|
|
504
|
+
eventStartEditable = true,
|
|
505
|
+
eventOverlap = true,
|
|
446
506
|
keyboardDayNavigation = false,
|
|
447
507
|
className,
|
|
448
508
|
style,
|
|
@@ -573,44 +633,93 @@ export function MonthView<T = unknown>({
|
|
|
573
633
|
const gridRef = useRef<HTMLDivElement>(null);
|
|
574
634
|
const focusKey = format(focusedDate, "yyyy-MM-dd");
|
|
575
635
|
|
|
576
|
-
//
|
|
577
|
-
// all-day span,
|
|
578
|
-
|
|
579
|
-
const
|
|
580
|
-
|
|
636
|
+
// Dragging (events mode): press a day and drag across others to sketch an
|
|
637
|
+
// all-day span, or press an event chip and drop it on another day. Both are
|
|
638
|
+
// released on a window pointerup, so letting go anywhere still commits.
|
|
639
|
+
const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
|
|
640
|
+
const dragRef = useRef(drag);
|
|
641
|
+
dragRef.current = drag;
|
|
581
642
|
const movedRef = useRef(false);
|
|
582
|
-
// Set when a drag commits, so the click the browser fires next is swallowed
|
|
583
|
-
//
|
|
643
|
+
// Set when a drag commits, so the click the browser fires next is swallowed (it
|
|
644
|
+
// must not also open the day, or the event the drag landed on). A drag that ends
|
|
645
|
+
// over a different element than it began on gets its trailing click on their
|
|
646
|
+
// common ancestor instead, where no handler consumes the guard — so every press
|
|
647
|
+
// clears it first, keeping it scoped to the one interaction that set it.
|
|
584
648
|
const suppressClickRef = useRef(false);
|
|
649
|
+
const consumeSuppressedClick = () => {
|
|
650
|
+
if (!suppressClickRef.current) return false;
|
|
651
|
+
suppressClickRef.current = false;
|
|
652
|
+
return true;
|
|
653
|
+
};
|
|
654
|
+
// `disabled` and `draggable: false` lock an event outright; `startEditable`
|
|
655
|
+
// (per event, falling back to the grid default) allows or blocks a move.
|
|
656
|
+
const canMove = (event: CalendarEvent<T>) =>
|
|
657
|
+
onDragEvent != null &&
|
|
658
|
+
!event.disabled &&
|
|
659
|
+
event.draggable !== false &&
|
|
660
|
+
(event.startEditable ?? eventStartEditable);
|
|
661
|
+
// A fresh press starts a new interaction, so any guard left over from the
|
|
662
|
+
// previous one is stale.
|
|
663
|
+
const beginPress = () => {
|
|
664
|
+
suppressClickRef.current = false;
|
|
665
|
+
movedRef.current = false;
|
|
666
|
+
};
|
|
585
667
|
const beginCreate = (day: Date) => {
|
|
586
|
-
if (!onCreateEvent) return;
|
|
668
|
+
if (!onCreateEvent && !onSelectDrag) return;
|
|
587
669
|
const t = startOfDay(day).getTime();
|
|
588
|
-
|
|
589
|
-
|
|
670
|
+
setDrag({ kind: "create", anchor: t, hover: t });
|
|
671
|
+
};
|
|
672
|
+
const beginMove = (event: CalendarEvent<T>, day: Date) => {
|
|
673
|
+
if (!canMove(event)) return;
|
|
674
|
+
const t = startOfDay(day).getTime();
|
|
675
|
+
setDrag({ kind: "move", event, from: t, to: t });
|
|
676
|
+
onDragStart?.(event);
|
|
590
677
|
};
|
|
591
|
-
const
|
|
592
|
-
|
|
678
|
+
const extendDrag = (day: Date) => {
|
|
679
|
+
const current = dragRef.current;
|
|
680
|
+
if (!current) return;
|
|
593
681
|
const t = startOfDay(day).getTime();
|
|
594
|
-
if (t
|
|
595
|
-
|
|
596
|
-
|
|
682
|
+
if (t === (current.kind === "create" ? current.hover : current.to)) return;
|
|
683
|
+
movedRef.current = true;
|
|
684
|
+
setDrag(current.kind === "create" ? { ...current, hover: t } : { ...current, to: t });
|
|
685
|
+
// A sweep reports its span live, so a selection can track the drag; a move
|
|
686
|
+
// has nothing to report until it is dropped.
|
|
687
|
+
if (current.kind === "create") {
|
|
688
|
+
const [lo, hi] = current.anchor <= t ? [current.anchor, t] : [t, current.anchor];
|
|
689
|
+
onSelectDrag?.(new Date(lo), new Date(hi));
|
|
597
690
|
}
|
|
598
691
|
};
|
|
599
|
-
const
|
|
692
|
+
const isDragging = drag !== null;
|
|
693
|
+
// Whether any month drag is wired up at all, so the cells only take over touch
|
|
694
|
+
// scrolling and pointer tracking when one of the handlers can actually fire.
|
|
695
|
+
const dragWired = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
|
|
600
696
|
useEffect(() => {
|
|
601
|
-
if (!
|
|
697
|
+
if (!isDragging) return;
|
|
602
698
|
const finish = () => {
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
if (!
|
|
699
|
+
const current = dragRef.current;
|
|
700
|
+
setDrag(null);
|
|
701
|
+
if (!current || !movedRef.current) return;
|
|
606
702
|
suppressClickRef.current = true;
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
703
|
+
if (current.kind === "create") {
|
|
704
|
+
const range = monthCreateRange(new Date(current.anchor), new Date(current.hover));
|
|
705
|
+
onCreateEvent?.(range.start, range.end);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
const next = monthDropBounds(current.event, new Date(current.from), new Date(current.to));
|
|
709
|
+
if (!next) return;
|
|
710
|
+
// Reject a drop that would land the event on top of another when
|
|
711
|
+
// `eventOverlap` is off, before the consumer's handler ever sees it.
|
|
712
|
+
if (
|
|
713
|
+
eventOverlap === false &&
|
|
714
|
+
overlapsOtherEvents(events ?? [], current.event, next.start, next.end)
|
|
715
|
+
) {
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
onDragEvent?.(current.event, next.start, next.end);
|
|
610
719
|
};
|
|
611
720
|
window.addEventListener("pointerup", finish);
|
|
612
721
|
return () => window.removeEventListener("pointerup", finish);
|
|
613
|
-
}, [
|
|
722
|
+
}, [isDragging, onCreateEvent, onDragEvent, eventOverlap, events]);
|
|
614
723
|
const onKeyDown = (e: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
615
724
|
let next: Date | null = null;
|
|
616
725
|
if (e.key === "ArrowLeft") next = addDays(focusedDate, -1);
|
|
@@ -732,7 +841,7 @@ export function MonthView<T = unknown>({
|
|
|
732
841
|
<div key={day.id} role="gridcell" aria-hidden style={{ height: cellHeight }} />
|
|
733
842
|
);
|
|
734
843
|
}
|
|
735
|
-
const band = rangeBandDefault(day, theme, fillCellOnSelection);
|
|
844
|
+
const band = rangeBandDefault(day, theme, fillCellOnSelection, eventsMode);
|
|
736
845
|
const label = format(
|
|
737
846
|
day.date,
|
|
738
847
|
"EEEE, d MMMM yyyy",
|
|
@@ -740,9 +849,12 @@ export function MonthView<T = unknown>({
|
|
|
740
849
|
);
|
|
741
850
|
const dayTime = startOfDay(day.date).getTime();
|
|
742
851
|
const inCreate =
|
|
743
|
-
|
|
744
|
-
dayTime >= Math.min(
|
|
745
|
-
dayTime <= Math.max(
|
|
852
|
+
drag?.kind === "create" &&
|
|
853
|
+
dayTime >= Math.min(drag.anchor, drag.hover) &&
|
|
854
|
+
dayTime <= Math.max(drag.anchor, drag.hover);
|
|
855
|
+
// The day an event is about to land on (not the one it came from).
|
|
856
|
+
const isDropTarget =
|
|
857
|
+
drag?.kind === "move" && dayTime === drag.to && drag.to !== drag.from;
|
|
746
858
|
// Present/absent data-* attributes so consumers can style day state
|
|
747
859
|
// with CSS/Tailwind variants (e.g. `data-[today]:bg-blue-500`).
|
|
748
860
|
const dayData = dataState({
|
|
@@ -753,6 +865,7 @@ export function MonthView<T = unknown>({
|
|
|
753
865
|
"data-outside": !day.isCurrentMonth,
|
|
754
866
|
"data-disabled": day.isDisabled,
|
|
755
867
|
"data-creating": inCreate,
|
|
868
|
+
"data-drop": isDropTarget,
|
|
756
869
|
});
|
|
757
870
|
|
|
758
871
|
if (eventsMode) {
|
|
@@ -768,7 +881,13 @@ export function MonthView<T = unknown>({
|
|
|
768
881
|
const dayLabel = format(day.date, "d MMMM", locale ? { locale } : undefined);
|
|
769
882
|
const dayCellProps = slot(
|
|
770
883
|
"day",
|
|
771
|
-
eventCellDefault(
|
|
884
|
+
eventCellDefault(
|
|
885
|
+
day,
|
|
886
|
+
theme,
|
|
887
|
+
cellHeight,
|
|
888
|
+
highlightWeekends,
|
|
889
|
+
inCreate || isDropTarget,
|
|
890
|
+
),
|
|
772
891
|
);
|
|
773
892
|
return (
|
|
774
893
|
// Events mode: by default the cell is not a tab stop, so keyboard
|
|
@@ -785,30 +904,36 @@ export function MonthView<T = unknown>({
|
|
|
785
904
|
aria-disabled={day.isDisabled || undefined}
|
|
786
905
|
aria-label={label}
|
|
787
906
|
{...dayCellProps}
|
|
788
|
-
//
|
|
789
|
-
// sketches a span instead of scrolling
|
|
907
|
+
// Dragging disables touch scroll on the cell so a swipe
|
|
908
|
+
// sketches a span (or carries an event) instead of scrolling
|
|
909
|
+
// the grid, and stops the sweep from text-selecting the day
|
|
910
|
+
// numbers and chip titles it passes over.
|
|
790
911
|
style={
|
|
791
|
-
|
|
792
|
-
? { ...dayCellProps.style, touchAction: "none" }
|
|
912
|
+
dragWired
|
|
913
|
+
? { ...dayCellProps.style, touchAction: "none", userSelect: "none" }
|
|
793
914
|
: dayCellProps.style
|
|
794
915
|
}
|
|
795
916
|
onPointerDown={
|
|
796
|
-
|
|
917
|
+
dragWired && !day.isDisabled
|
|
797
918
|
? (e) => {
|
|
798
|
-
if (e.button
|
|
919
|
+
if (e.button !== 0) return;
|
|
920
|
+
beginPress();
|
|
921
|
+
beginCreate(day.date);
|
|
799
922
|
}
|
|
800
923
|
: undefined
|
|
801
924
|
}
|
|
802
|
-
|
|
925
|
+
// A disabled day is out of every selection, drag included, so
|
|
926
|
+
// a sweep never extends onto it and no drop lands there.
|
|
927
|
+
onPointerEnter={
|
|
928
|
+
dragWired && !day.isDisabled ? () => extendDrag(day.date) : undefined
|
|
929
|
+
}
|
|
803
930
|
onClick={
|
|
804
931
|
day.isDisabled
|
|
805
932
|
? undefined
|
|
806
933
|
: () => {
|
|
807
|
-
if (
|
|
808
|
-
suppressClickRef.current = false;
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
934
|
+
if (consumeSuppressedClick()) return;
|
|
811
935
|
onPressDay?.(day.date);
|
|
936
|
+
onPressCell?.(startOfDay(day.date));
|
|
812
937
|
}
|
|
813
938
|
}
|
|
814
939
|
onKeyDown={
|
|
@@ -819,6 +944,7 @@ export function MonthView<T = unknown>({
|
|
|
819
944
|
if (e.key === "Enter" || e.key === " ") {
|
|
820
945
|
e.preventDefault();
|
|
821
946
|
onPressDay?.(day.date);
|
|
947
|
+
onPressCell?.(startOfDay(day.date));
|
|
822
948
|
}
|
|
823
949
|
}
|
|
824
950
|
: undefined
|
|
@@ -832,18 +958,30 @@ export function MonthView<T = unknown>({
|
|
|
832
958
|
overflowing right across the days they span. Rendered here
|
|
833
959
|
(not a row overlay) so each bar is valid content of its
|
|
834
960
|
start day's gridcell and reads with that day. Made
|
|
835
|
-
non-interactive mid drag
|
|
961
|
+
non-interactive mid drag so a sweep (or a move) reaches the
|
|
836
962
|
cells beneath. */}
|
|
837
963
|
{barSegs
|
|
838
964
|
.filter((b) => b.startCol === dayCol)
|
|
839
965
|
.map((b) => {
|
|
840
966
|
const span = b.endCol - b.startCol + 1;
|
|
967
|
+
const isDragged = drag?.kind === "move" && drag.event === b.seg.event;
|
|
841
968
|
return (
|
|
842
969
|
<button
|
|
843
970
|
key={`bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}`}
|
|
844
971
|
type="button"
|
|
972
|
+
onPointerDown={
|
|
973
|
+
canMove(b.seg.event)
|
|
974
|
+
? (e) => {
|
|
975
|
+
if (e.button !== 0) return;
|
|
976
|
+
e.stopPropagation();
|
|
977
|
+
beginPress();
|
|
978
|
+
beginMove(b.seg.event, day.date);
|
|
979
|
+
}
|
|
980
|
+
: undefined
|
|
981
|
+
}
|
|
845
982
|
onClick={(e) => {
|
|
846
983
|
e.stopPropagation();
|
|
984
|
+
if (consumeSuppressedClick()) return;
|
|
847
985
|
onPressEvent?.(b.seg.event);
|
|
848
986
|
}}
|
|
849
987
|
{...barChipButton}
|
|
@@ -868,7 +1006,12 @@ export function MonthView<T = unknown>({
|
|
|
868
1006
|
CHIP_GAP +
|
|
869
1007
|
b.seg.lane * (CHIP_HEIGHT + CHIP_GAP),
|
|
870
1008
|
height: CHIP_HEIGHT,
|
|
871
|
-
pointerEvents:
|
|
1009
|
+
pointerEvents: isDragging ? "none" : "auto",
|
|
1010
|
+
// Fade the bar being carried, so the tinted drop
|
|
1011
|
+
// target reads as where it is going.
|
|
1012
|
+
opacity: isDragged ? DRAGGED_CHIP_OPACITY : undefined,
|
|
1013
|
+
cursor: canMove(b.seg.event) ? "grab" : undefined,
|
|
1014
|
+
touchAction: dragWired ? "none" : undefined,
|
|
872
1015
|
zIndex: 2,
|
|
873
1016
|
}}
|
|
874
1017
|
>
|
|
@@ -1024,7 +1167,14 @@ export function MonthView<T = unknown>({
|
|
|
1024
1167
|
aria-label={label}
|
|
1025
1168
|
aria-pressed={day.isSelected || day.isInRange}
|
|
1026
1169
|
{...slot("day", dayCellDefault(day, theme, highlightWeekends))}
|
|
1027
|
-
onClick={
|
|
1170
|
+
onClick={
|
|
1171
|
+
day.isDisabled
|
|
1172
|
+
? undefined
|
|
1173
|
+
: () => {
|
|
1174
|
+
onPressDay?.(day.date);
|
|
1175
|
+
onPressCell?.(startOfDay(day.date));
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1028
1178
|
onMouseEnter={day.isDisabled ? undefined : () => setHoveredKey(day.id)}
|
|
1029
1179
|
onMouseLeave={() => setHoveredKey((k) => (k === day.id ? null : k))}
|
|
1030
1180
|
>
|