@super-calendar/solid 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 +88 -7
- package/dist/client/index.d.ts +96 -17
- package/dist/client/index.js +1093 -382
- package/dist/server/index.d.ts +96 -17
- package/dist/server/index.js +1788 -930
- package/package.json +2 -2
- package/src/Agenda.tsx +17 -1
- package/src/Calendar.tsx +175 -27
- package/src/MonthView.tsx +589 -98
- package/src/MultiWeekView.tsx +49 -0
- package/src/TimeGrid.tsx +350 -155
- package/src/YearView.tsx +17 -1
- package/src/index.ts +7 -0
- package/src/touch.ts +70 -0
package/src/MonthView.tsx
CHANGED
|
@@ -2,7 +2,10 @@ import { Dynamic, type JSX } from "@solidjs/web";
|
|
|
2
2
|
import {
|
|
3
3
|
bandRounding,
|
|
4
4
|
buildMonthGrid,
|
|
5
|
+
buildMultiWeekGrid,
|
|
6
|
+
nowInTimeZone,
|
|
5
7
|
type CalendarEvent,
|
|
8
|
+
type CreateGhostArgs,
|
|
6
9
|
type CalendarLabels,
|
|
7
10
|
compareDayEvents,
|
|
8
11
|
type DateRange,
|
|
@@ -16,8 +19,8 @@ import {
|
|
|
16
19
|
layoutMonthWeek,
|
|
17
20
|
monthCreateRange,
|
|
18
21
|
monthDropBounds,
|
|
19
|
-
type
|
|
20
|
-
type
|
|
22
|
+
type MonthGridWeekday,
|
|
23
|
+
type MultiWeekGridDay,
|
|
21
24
|
overlapsOtherEvents,
|
|
22
25
|
rangeBandKind,
|
|
23
26
|
resolveCalendarLabels,
|
|
@@ -42,6 +45,7 @@ import {
|
|
|
42
45
|
Show,
|
|
43
46
|
untrack,
|
|
44
47
|
} from "solid-js";
|
|
48
|
+
import { holdDateDrag } from "./touch";
|
|
45
49
|
import { withDefaults } from "./props";
|
|
46
50
|
import { createSlots, dataState, type SlotDefault, type SlotStyleProps } from "./slots";
|
|
47
51
|
import { css, type CSSProperties, type DomKeyboardEvent, type ElementRef } from "./styles";
|
|
@@ -61,6 +65,7 @@ export type MonthViewSlot =
|
|
|
61
65
|
| "dayBadge"
|
|
62
66
|
| "rangeBand"
|
|
63
67
|
| "events"
|
|
68
|
+
| "createGhost"
|
|
64
69
|
| "chipButton"
|
|
65
70
|
| "chip"
|
|
66
71
|
| "more"
|
|
@@ -79,6 +84,10 @@ const CHIP_GAP = 2;
|
|
|
79
84
|
const CELL_PAD = 4;
|
|
80
85
|
// Opacity of an event chip while it is being dragged to another day.
|
|
81
86
|
const DRAGGED_CHIP_OPACITY = 0.4;
|
|
87
|
+
// How far a press travels before it becomes a drag. Until then the chips stay
|
|
88
|
+
// hit-testable, so a click still reaches the chip it pressed.
|
|
89
|
+
const DRAG_SLOP_PX = 4;
|
|
90
|
+
const TOUCH_DRAG_SLOP_PX = 8;
|
|
82
91
|
|
|
83
92
|
/** Props passed to a custom month event chip renderer. */
|
|
84
93
|
export interface SolidMonthEventArgs<T = unknown> {
|
|
@@ -86,6 +95,8 @@ export interface SolidMonthEventArgs<T = unknown> {
|
|
|
86
95
|
event: CalendarEvent<T>;
|
|
87
96
|
/** Call to fire the view's `onPressEvent` for this chip. */
|
|
88
97
|
onPress: () => void;
|
|
98
|
+
/** The current row view. Supplied by the calendar; optional for existing standalone chip callers. */
|
|
99
|
+
mode?: "month" | "multiweek";
|
|
89
100
|
}
|
|
90
101
|
|
|
91
102
|
/** A component that renders a single month-grid event chip. */
|
|
@@ -94,7 +105,7 @@ export type SolidMonthEvent<T = unknown> = Component<SolidMonthEventArgs<T>>;
|
|
|
94
105
|
// An in-progress month drag: either a day span being swept out for a new event,
|
|
95
106
|
// or an existing event being carried to another day. Days are held as start-of-day
|
|
96
107
|
// timestamps, so the reducer-ish updates compare cheaply.
|
|
97
|
-
type MonthDrag<T> =
|
|
108
|
+
type MonthDrag<T> = (
|
|
98
109
|
| {
|
|
99
110
|
kind: "create";
|
|
100
111
|
pointerId: number;
|
|
@@ -107,7 +118,23 @@ type MonthDrag<T> =
|
|
|
107
118
|
event: CalendarEvent<T>;
|
|
108
119
|
from: number;
|
|
109
120
|
to: number;
|
|
110
|
-
}
|
|
121
|
+
}
|
|
122
|
+
) & {
|
|
123
|
+
// The rows the drag began in, so a drag never commits into a different window.
|
|
124
|
+
windowKey: string;
|
|
125
|
+
// Set once the pointer travels past the drag slop (or a touch hold fires).
|
|
126
|
+
// Chips stop taking pointer input only then, so a plain click is not
|
|
127
|
+
// retargeted to the day cell beneath.
|
|
128
|
+
armed: boolean;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// A day as the shared rows render it. Month days carry `isCurrentMonth`;
|
|
132
|
+
// multi-week days omit it because every one of them is inside the period.
|
|
133
|
+
type RowDay = MultiWeekGridDay & { isCurrentMonth?: boolean };
|
|
134
|
+
type RowWeek = { id: string; days: RowDay[] };
|
|
135
|
+
|
|
136
|
+
// A leading or trailing day of a neighbouring month in the month grid.
|
|
137
|
+
const isOutsidePeriod = (day: RowDay) => day.isCurrentMonth === false;
|
|
111
138
|
|
|
112
139
|
/** Props for {@link MonthView}. */
|
|
113
140
|
export interface MonthViewProps<T = unknown>
|
|
@@ -172,6 +199,13 @@ export interface MonthViewProps<T = unknown>
|
|
|
172
199
|
showWeekdays?: boolean;
|
|
173
200
|
/** date-fns locale for the title and weekday labels. */
|
|
174
201
|
locale?: Locale;
|
|
202
|
+
/**
|
|
203
|
+
* The instant whose calendar day is highlighted as today. Defaults to the
|
|
204
|
+
* device clock, and is read in `timeZone` when one is set.
|
|
205
|
+
*/
|
|
206
|
+
now?: Date;
|
|
207
|
+
/** Highlight today as it is in this IANA time zone (default: the device's). */
|
|
208
|
+
timeZone?: string;
|
|
175
209
|
/** Theme overrides; falls back to the default light theme. */
|
|
176
210
|
theme?: Partial<SolidCalendarTheme>;
|
|
177
211
|
/** Fired when a selectable day is clicked. */
|
|
@@ -189,6 +223,12 @@ export interface MonthViewProps<T = unknown>
|
|
|
189
223
|
* carry `data-creating` for styling.
|
|
190
224
|
*/
|
|
191
225
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
226
|
+
/**
|
|
227
|
+
* Custom content for a drag-to-create preview, once per covered week row.
|
|
228
|
+
* Receives the full all-day range with an exclusive end. Requires onCreateEvent.
|
|
229
|
+
* Content is clipped, noninteractive, and hidden from assistive technology.
|
|
230
|
+
*/
|
|
231
|
+
renderCreateGhost?: Component<CreateGhostArgs>;
|
|
192
232
|
/**
|
|
193
233
|
* Reports the day span of a create sweep **as it happens**, as the ordered
|
|
194
234
|
* inclusive `[start, end]` days (both at midnight), so a selection highlight can
|
|
@@ -228,7 +268,7 @@ export interface MonthViewProps<T = unknown>
|
|
|
228
268
|
// always applied) and `themed` (colour/type/spacing, dropped when a class is set).
|
|
229
269
|
|
|
230
270
|
function dayCellDefault(
|
|
231
|
-
day:
|
|
271
|
+
day: RowDay,
|
|
232
272
|
theme: SolidCalendarTheme,
|
|
233
273
|
highlightWeekends: boolean,
|
|
234
274
|
): SlotDefault {
|
|
@@ -268,7 +308,7 @@ function dayCellDefault(
|
|
|
268
308
|
* event chips (and matches the native renderer's month grid).
|
|
269
309
|
*/
|
|
270
310
|
function rangeBandDefault(
|
|
271
|
-
day:
|
|
311
|
+
day: RowDay,
|
|
272
312
|
theme: SolidCalendarTheme,
|
|
273
313
|
fillCell: boolean,
|
|
274
314
|
eventsMode: boolean,
|
|
@@ -318,7 +358,7 @@ function rangeBandDefault(
|
|
|
318
358
|
},
|
|
319
359
|
};
|
|
320
360
|
}
|
|
321
|
-
function badgeDefault(day:
|
|
361
|
+
function badgeDefault(day: RowDay, theme: SolidCalendarTheme, hovered: boolean): SlotDefault {
|
|
322
362
|
const badge = dayBadgeKind(day, day.isToday);
|
|
323
363
|
const filled = badge !== "none";
|
|
324
364
|
const background = filled
|
|
@@ -349,7 +389,7 @@ function badgeDefault(day: MonthGridDay, theme: SolidCalendarTheme, hovered: boo
|
|
|
349
389
|
// --- Calendar (events) layout styles -------------------------------------
|
|
350
390
|
|
|
351
391
|
function eventCellDefault(
|
|
352
|
-
day:
|
|
392
|
+
day: RowDay,
|
|
353
393
|
theme: SolidCalendarTheme,
|
|
354
394
|
height: number,
|
|
355
395
|
highlightWeekends: boolean,
|
|
@@ -384,7 +424,7 @@ function eventCellDefault(
|
|
|
384
424
|
},
|
|
385
425
|
};
|
|
386
426
|
}
|
|
387
|
-
function compactBadgeDefault(day:
|
|
427
|
+
function compactBadgeDefault(day: RowDay, theme: SolidCalendarTheme): SlotDefault {
|
|
388
428
|
const badge = dayBadgeKind(day, day.isToday);
|
|
389
429
|
const filled = badge !== "none";
|
|
390
430
|
return {
|
|
@@ -443,7 +483,11 @@ function chipDefault(theme: SolidCalendarTheme, chipHeight: number): SlotDefault
|
|
|
443
483
|
},
|
|
444
484
|
};
|
|
445
485
|
}
|
|
446
|
-
function moreButtonDefault(
|
|
486
|
+
function moreButtonDefault(
|
|
487
|
+
theme: SolidCalendarTheme,
|
|
488
|
+
chipHeight: number,
|
|
489
|
+
multiWeek = false,
|
|
490
|
+
): SlotDefault {
|
|
447
491
|
return {
|
|
448
492
|
base: {
|
|
449
493
|
position: "relative",
|
|
@@ -455,6 +499,7 @@ function moreButtonDefault(theme: SolidCalendarTheme, chipHeight: number): SlotD
|
|
|
455
499
|
height: chipHeight,
|
|
456
500
|
lineHeight: `${chipHeight}px`,
|
|
457
501
|
fontFamily: "inherit",
|
|
502
|
+
...(multiWeek ? { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } : {}),
|
|
458
503
|
},
|
|
459
504
|
themed: {
|
|
460
505
|
padding: "0 6px",
|
|
@@ -476,7 +521,7 @@ interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
|
|
|
476
521
|
// A multi-day event lives in each covered day's bucket, so dedupe by reference;
|
|
477
522
|
// this scans only the row's days, not every event in the month.
|
|
478
523
|
function collectRowEvents<T>(
|
|
479
|
-
week:
|
|
524
|
+
week: RowWeek,
|
|
480
525
|
eventsByDay: ReadonlyMap<string, CalendarEvent<T>[]>,
|
|
481
526
|
): CalendarEvent<T>[] {
|
|
482
527
|
const seen = new Set<CalendarEvent<T>>();
|
|
@@ -494,6 +539,38 @@ function collectRowEvents<T>(
|
|
|
494
539
|
return out;
|
|
495
540
|
}
|
|
496
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Which rows a {@link DateRows} grid shows. Internal to the package: the public
|
|
544
|
+
* views adapt their own props to it.
|
|
545
|
+
*/
|
|
546
|
+
export type DateRowsSource =
|
|
547
|
+
| {
|
|
548
|
+
kind: "month";
|
|
549
|
+
/** Any day within the month to render. */
|
|
550
|
+
date: Date;
|
|
551
|
+
showAdjacentMonths: boolean;
|
|
552
|
+
}
|
|
553
|
+
| {
|
|
554
|
+
kind: "multiweek";
|
|
555
|
+
/** Any day within the first week to render. */
|
|
556
|
+
date: Date;
|
|
557
|
+
numberOfWeeks: number;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// The localized first and last displayed days, e.g. "Nov 1, 2026 – Nov 14, 2026".
|
|
561
|
+
function rangeTitle(start: Date, endExclusive: Date, locale?: Locale): string {
|
|
562
|
+
const options = locale ? { locale } : undefined;
|
|
563
|
+
return `${format(start, "PP", options)} – ${format(addDays(endExclusive, -1), "PP", options)}`;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Props for the private {@link DateRows} grid shared by the public row views. */
|
|
567
|
+
export interface DateRowsProps<T = unknown> extends Omit<
|
|
568
|
+
MonthViewInternalProps<T>,
|
|
569
|
+
"date" | "showAdjacentMonths"
|
|
570
|
+
> {
|
|
571
|
+
source: DateRowsSource;
|
|
572
|
+
}
|
|
573
|
+
|
|
497
574
|
/**
|
|
498
575
|
* A single static month grid, rendered with plain DOM elements.
|
|
499
576
|
*
|
|
@@ -502,7 +579,28 @@ function collectRowEvents<T>(
|
|
|
502
579
|
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
503
580
|
* ```
|
|
504
581
|
*/
|
|
505
|
-
export function MonthView<T = unknown>(
|
|
582
|
+
export function MonthView<T = unknown>(props: MonthViewInternalProps<T>): JSX.Element {
|
|
583
|
+
return (
|
|
584
|
+
<DateRows<T>
|
|
585
|
+
{...props}
|
|
586
|
+
source={{
|
|
587
|
+
kind: "month",
|
|
588
|
+
get date() {
|
|
589
|
+
return props.date;
|
|
590
|
+
},
|
|
591
|
+
get showAdjacentMonths() {
|
|
592
|
+
return props.showAdjacentMonths ?? true;
|
|
593
|
+
},
|
|
594
|
+
}}
|
|
595
|
+
/>
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The day-row grid behind the public row views: week rows of day cells with
|
|
601
|
+
* spanning event bars, overflow, selection, drag, and keyboard handling.
|
|
602
|
+
*/
|
|
603
|
+
export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
506
604
|
const props = withDefaults(
|
|
507
605
|
{
|
|
508
606
|
weekStartsOn: 0,
|
|
@@ -511,7 +609,6 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
511
609
|
chipHeight: CHIP_HEIGHT,
|
|
512
610
|
chipGap: CHIP_GAP,
|
|
513
611
|
moreLabel: "{moreCount} More",
|
|
514
|
-
showAdjacentMonths: true,
|
|
515
612
|
highlightWeekends: true,
|
|
516
613
|
fillCellOnSelection: false,
|
|
517
614
|
showTitle: true,
|
|
@@ -519,16 +616,32 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
519
616
|
eventStartEditable: true,
|
|
520
617
|
eventOverlap: true,
|
|
521
618
|
keyboardDayNavigation: false,
|
|
522
|
-
} satisfies Partial<
|
|
619
|
+
} satisfies Partial<DateRowsProps<T>>,
|
|
523
620
|
incoming,
|
|
524
621
|
);
|
|
525
622
|
const theme = createMemo(() => mergeSolidTheme(props.theme));
|
|
526
623
|
const labels = createMemo(() => resolveCalendarLabels(props.labels));
|
|
527
624
|
const slot = createSlots<MonthViewSlot>(props);
|
|
625
|
+
const multiWeek = createMemo(() => props.source.kind === "multiweek");
|
|
626
|
+
// Multi-week rows only contain days of the requested period, so nothing is blanked.
|
|
627
|
+
const showAdjacentMonths = createMemo(() =>
|
|
628
|
+
props.source.kind === "month" ? props.source.showAdjacentMonths : true,
|
|
629
|
+
);
|
|
630
|
+
const numberOfWeeks = createMemo(() =>
|
|
631
|
+
props.source.kind === "multiweek" ? props.source.numberOfWeeks : undefined,
|
|
632
|
+
);
|
|
633
|
+
// The mode reported to custom renderers and accessibility labels.
|
|
634
|
+
const viewMode = createMemo((): "month" | "multiweek" => (multiWeek() ? "multiweek" : "month"));
|
|
528
635
|
|
|
529
636
|
// Calendar layout (date in the corner + event chips) is on whenever `events`
|
|
530
|
-
// is provided; otherwise the compact picker badge layout is used.
|
|
531
|
-
|
|
637
|
+
// is provided; otherwise the compact picker badge layout is used. Multi-week
|
|
638
|
+
// rows always use the calendar layout.
|
|
639
|
+
const createContentEnabled = createMemo(
|
|
640
|
+
() => props.onCreateEvent != null && props.renderCreateGhost != null,
|
|
641
|
+
);
|
|
642
|
+
const eventsMode = createMemo(
|
|
643
|
+
() => props.events !== undefined || multiWeek() || createContentEnabled(),
|
|
644
|
+
);
|
|
532
645
|
// The day cells form a roving tab stop (arrow keys + Enter) in the picker
|
|
533
646
|
// always, and in events mode only when the consumer opts in. Otherwise events
|
|
534
647
|
// mode tabs through the event chips alone.
|
|
@@ -597,20 +710,52 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
597
710
|
// Reserve `maxVisibleEventCount` rows below the date so every cell is uniform;
|
|
598
711
|
// when a day overflows, the last row becomes the "+N more" affordance.
|
|
599
712
|
const eventRowHeight = createMemo(
|
|
600
|
-
() =>
|
|
713
|
+
() =>
|
|
714
|
+
CELL_PAD * 2 +
|
|
715
|
+
DATE_ROW +
|
|
716
|
+
(multiWeek() ? Math.max(1, props.maxVisibleEventCount) : props.maxVisibleEventCount) *
|
|
717
|
+
(props.chipHeight + props.chipGap),
|
|
601
718
|
);
|
|
602
|
-
const _grid = createMemo(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
719
|
+
const _grid = createMemo(
|
|
720
|
+
(): {
|
|
721
|
+
weeks: RowWeek[];
|
|
722
|
+
weekdays: MonthGridWeekday[];
|
|
723
|
+
title: string;
|
|
724
|
+
period: { start: Date; endExclusive: Date } | null;
|
|
725
|
+
} => {
|
|
726
|
+
const options = {
|
|
727
|
+
weekStartsOn: props.weekStartsOn,
|
|
728
|
+
hiddenDays: props.hiddenDays,
|
|
729
|
+
weekdayFormat: props.weekdayFormat,
|
|
730
|
+
selectedRange: props.selectedRange,
|
|
731
|
+
selectedDates: props.selectedDates,
|
|
732
|
+
minDate: props.minDate,
|
|
733
|
+
maxDate: props.maxDate,
|
|
734
|
+
isDateDisabled: props.isDateDisabled,
|
|
735
|
+
locale: props.locale,
|
|
736
|
+
// Read here, not memoized apart, so each rebuild sees the current day.
|
|
737
|
+
today: nowInTimeZone(props.now, props.timeZone),
|
|
738
|
+
};
|
|
739
|
+
const weeks = numberOfWeeks();
|
|
740
|
+
if (weeks === undefined) {
|
|
741
|
+
return {
|
|
742
|
+
...buildMonthGrid(props.source.date, options),
|
|
743
|
+
title: format(
|
|
744
|
+
props.source.date,
|
|
745
|
+
"MMMM yyyy",
|
|
746
|
+
props.locale ? { locale: props.locale } : undefined,
|
|
747
|
+
),
|
|
748
|
+
period: null,
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
const grid = buildMultiWeekGrid(props.source.date, { ...options, numberOfWeeks: weeks });
|
|
752
|
+
return {
|
|
753
|
+
weeks: grid.weeks,
|
|
754
|
+
weekdays: grid.weekdays,
|
|
755
|
+
title: rangeTitle(grid.visibleRange.start, grid.visibleRange.endExclusive, props.locale),
|
|
756
|
+
period: grid.period,
|
|
757
|
+
};
|
|
758
|
+
},
|
|
614
759
|
);
|
|
615
760
|
|
|
616
761
|
// Lay out each week row's spanning bars once per data change, not per render, so
|
|
@@ -626,15 +771,47 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
626
771
|
: [],
|
|
627
772
|
);
|
|
628
773
|
|
|
774
|
+
// Multi-week rows rove over the rendered, enabled days only (oldest first), so
|
|
775
|
+
// focus skips hidden and disabled days and never leaves the displayed weeks.
|
|
776
|
+
const focusableDays = createMemo(() =>
|
|
777
|
+
_grid().period
|
|
778
|
+
? _grid()
|
|
779
|
+
.weeks.flatMap((week) => week.days)
|
|
780
|
+
.filter((day) => !day.isDisabled)
|
|
781
|
+
.map((day) => startOfDay(day.date))
|
|
782
|
+
.sort((a, b) => a.getTime() - b.getTime())
|
|
783
|
+
: null,
|
|
784
|
+
);
|
|
785
|
+
const focusableKeys = createMemo(() => {
|
|
786
|
+
const days = focusableDays();
|
|
787
|
+
return days ? new Set(days.map((d) => format(d, "yyyy-MM-dd"))) : null;
|
|
788
|
+
});
|
|
789
|
+
|
|
629
790
|
// Roving tabindex: only one day is in the tab order; arrow keys move focus
|
|
630
791
|
// within the month, so the grid is a single, sensible tab stop.
|
|
631
|
-
const initialFocus = createMemo(() => {
|
|
632
|
-
const
|
|
792
|
+
const initialFocus = createMemo((): Date | null => {
|
|
793
|
+
const days = focusableDays();
|
|
794
|
+
const keys = focusableKeys();
|
|
795
|
+
if (days && keys) {
|
|
796
|
+
// The selected day, then today, then the first enabled day; none when every
|
|
797
|
+
// displayed day is disabled.
|
|
798
|
+
const rendered = (d?: Date | null): d is Date => !!d && keys.has(format(d, "yyyy-MM-dd"));
|
|
799
|
+
const rangeStart = props.selectedRange?.start;
|
|
800
|
+
if (rendered(rangeStart)) return startOfDay(rangeStart);
|
|
801
|
+
const picked = props.selectedDates?.find(rendered);
|
|
802
|
+
if (picked) return startOfDay(picked);
|
|
803
|
+
const today = new Date();
|
|
804
|
+
if (rendered(today)) return startOfDay(today);
|
|
805
|
+
return days[0] ?? null;
|
|
806
|
+
}
|
|
807
|
+
const inMonth = (d?: Date | null) => !!d && isSameMonth(d, props.source.date);
|
|
633
808
|
if (inMonth(props.selectedRange?.start)) return startOfDay(props.selectedRange!.start);
|
|
634
809
|
const picked = props.selectedDates?.find(inMonth);
|
|
635
810
|
if (picked) return startOfDay(picked);
|
|
636
811
|
const today = new Date();
|
|
637
|
-
return isSameMonth(today, props.
|
|
812
|
+
return isSameMonth(today, props.source.date)
|
|
813
|
+
? startOfDay(today)
|
|
814
|
+
: startOfMonth(props.source.date);
|
|
638
815
|
});
|
|
639
816
|
const [focusedDate, setFocusedDate] = createSignal(untrack(() => initialFocus()));
|
|
640
817
|
const initialFocusRef = {
|
|
@@ -646,12 +823,20 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
646
823
|
initialFocusRef.current = value;
|
|
647
824
|
},
|
|
648
825
|
);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
826
|
+
// The displayed window: the month, or the first week and count of multi-week rows.
|
|
827
|
+
const windowKey = createMemo(() => {
|
|
828
|
+
const period = _grid().period;
|
|
829
|
+
return period
|
|
830
|
+
? `${format(period.start, "yyyy-MM-dd")}+${numberOfWeeks()}:${_grid()
|
|
831
|
+
.weekdays.map((day) => day.date.getDay())
|
|
832
|
+
.join(",")}`
|
|
833
|
+
: format(props.source.date, "yyyy-MM");
|
|
834
|
+
});
|
|
835
|
+
let focusedWindow = untrack(windowKey);
|
|
836
|
+
createEffect(windowKey, (key) =>
|
|
652
837
|
untrack(() => {
|
|
653
|
-
if (
|
|
654
|
-
|
|
838
|
+
if (key === focusedWindow) return;
|
|
839
|
+
focusedWindow = key;
|
|
655
840
|
setFocusedDate(initialFocusRef.current);
|
|
656
841
|
}),
|
|
657
842
|
);
|
|
@@ -659,12 +844,54 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
659
844
|
const gridRef: ElementRef<HTMLDivElement | null> = {
|
|
660
845
|
current: null,
|
|
661
846
|
};
|
|
662
|
-
const
|
|
847
|
+
const lastDayFocus: ElementRef<HTMLElement | null> = { current: null };
|
|
848
|
+
// A multi-week focus target that hidden days or new constraints removed falls
|
|
849
|
+
// back to the initial target, without moving DOM focus.
|
|
850
|
+
const focusKey = createMemo(() => {
|
|
851
|
+
const focused = focusedDate();
|
|
852
|
+
const stored = focused ? format(focused, "yyyy-MM-dd") : null;
|
|
853
|
+
const keys = focusableKeys();
|
|
854
|
+
if (!keys || (stored !== null && keys.has(stored))) return stored;
|
|
855
|
+
const initial = initialFocus();
|
|
856
|
+
return initial && format(initial, "yyyy-MM-dd");
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
createEffect(
|
|
860
|
+
() => ({ enabled: multiWeek(), key: focusKey() }),
|
|
861
|
+
({ enabled, key }) => {
|
|
862
|
+
if (!enabled) return;
|
|
863
|
+
const active = gridRef.current?.ownerDocument.activeElement;
|
|
864
|
+
const removedDay =
|
|
865
|
+
active === gridRef.current?.ownerDocument.body &&
|
|
866
|
+
lastDayFocus.current !== null &&
|
|
867
|
+
!lastDayFocus.current.isConnected;
|
|
868
|
+
if (!removedDay && (!active?.hasAttribute("data-day") || !gridRef.current?.contains(active)))
|
|
869
|
+
return;
|
|
870
|
+
if (
|
|
871
|
+
active?.getAttribute("data-day") === key &&
|
|
872
|
+
active?.getAttribute("aria-disabled") !== "true"
|
|
873
|
+
)
|
|
874
|
+
return;
|
|
875
|
+
const next = key
|
|
876
|
+
? gridRef.current?.querySelector<HTMLElement>(`[data-day="${key}"]`)
|
|
877
|
+
: gridRef.current;
|
|
878
|
+
next?.focus();
|
|
879
|
+
},
|
|
880
|
+
);
|
|
663
881
|
|
|
664
882
|
// Dragging (events mode): press a day and drag across others to sketch an
|
|
665
883
|
// all-day span, or press an event chip and drop it on another day. Both are
|
|
666
884
|
// released on a window pointerup, so letting go anywhere still commits.
|
|
667
885
|
const [drag, setDrag] = createSignal<MonthDrag<T> | null>(null);
|
|
886
|
+
const createRange = createMemo(
|
|
887
|
+
() => {
|
|
888
|
+
const current = drag();
|
|
889
|
+
return createContentEnabled() && current?.kind === "create"
|
|
890
|
+
? monthCreateRange(new Date(current.anchor), new Date(current.hover))
|
|
891
|
+
: null;
|
|
892
|
+
},
|
|
893
|
+
{ equals: (a, b) => a === b || (!!a && !!b && +a.start === +b.start && +a.end === +b.end) },
|
|
894
|
+
);
|
|
668
895
|
const dragRef: ElementRef<MonthDrag<T> | null> = { current: null };
|
|
669
896
|
const applyDrag = (value: MonthDrag<T> | null) => {
|
|
670
897
|
dragRef.current = value;
|
|
@@ -681,8 +908,9 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
681
908
|
const suppressClickRef = {
|
|
682
909
|
current: false,
|
|
683
910
|
};
|
|
684
|
-
|
|
685
|
-
|
|
911
|
+
// Keyboard and assistive-technology clicks have detail 0 and never trail a drag.
|
|
912
|
+
const consumeSuppressedClick = (detail: number) => {
|
|
913
|
+
if (detail === 0 || !suppressClickRef.current) return false;
|
|
686
914
|
suppressClickRef.current = false;
|
|
687
915
|
return true;
|
|
688
916
|
};
|
|
@@ -693,15 +921,22 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
693
921
|
!event.disabled &&
|
|
694
922
|
event.draggable !== false &&
|
|
695
923
|
(event.startEditable ?? props.eventStartEditable);
|
|
924
|
+
// Where the current press began and how far it may travel before it drags.
|
|
925
|
+
let pressOrigin = { x: 0, y: 0, slop: DRAG_SLOP_PX };
|
|
696
926
|
// A fresh press starts a new interaction, so any guard left over from the
|
|
697
927
|
// previous one is stale.
|
|
698
928
|
const beginPress = (e: PointerEvent) => {
|
|
699
929
|
if (dragRef.current || e.isPrimary === false) return false;
|
|
700
930
|
suppressClickRef.current = false;
|
|
701
931
|
movedRef.current = false;
|
|
932
|
+
pressOrigin = {
|
|
933
|
+
x: e.clientX,
|
|
934
|
+
y: e.clientY,
|
|
935
|
+
slop: e.pointerType === "touch" ? TOUCH_DRAG_SLOP_PX : DRAG_SLOP_PX,
|
|
936
|
+
};
|
|
702
937
|
return true;
|
|
703
938
|
};
|
|
704
|
-
const beginCreate = (day: Date, pointerId: number) => {
|
|
939
|
+
const beginCreate = (day: Date, pointerId: number, armed: boolean) => {
|
|
705
940
|
if (!props.onCreateEvent && !props.onSelectDrag) return;
|
|
706
941
|
const t = startOfDay(day).getTime();
|
|
707
942
|
applyDrag({
|
|
@@ -709,9 +944,11 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
709
944
|
pointerId,
|
|
710
945
|
anchor: t,
|
|
711
946
|
hover: t,
|
|
947
|
+
windowKey: windowKey(),
|
|
948
|
+
armed,
|
|
712
949
|
});
|
|
713
950
|
};
|
|
714
|
-
const beginMove = (event: CalendarEvent<T>, day: Date, pointerId: number) => {
|
|
951
|
+
const beginMove = (event: CalendarEvent<T>, day: Date, pointerId: number, armed: boolean) => {
|
|
715
952
|
if (!canMove(event)) return;
|
|
716
953
|
const t = startOfDay(day).getTime();
|
|
717
954
|
applyDrag({
|
|
@@ -720,6 +957,8 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
720
957
|
event,
|
|
721
958
|
from: t,
|
|
722
959
|
to: t,
|
|
960
|
+
windowKey: windowKey(),
|
|
961
|
+
armed,
|
|
723
962
|
});
|
|
724
963
|
props.onDragStart?.(event);
|
|
725
964
|
};
|
|
@@ -734,10 +973,12 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
734
973
|
? {
|
|
735
974
|
...current,
|
|
736
975
|
hover: t,
|
|
976
|
+
armed: true,
|
|
737
977
|
}
|
|
738
978
|
: {
|
|
739
979
|
...current,
|
|
740
980
|
to: t,
|
|
981
|
+
armed: true,
|
|
741
982
|
},
|
|
742
983
|
);
|
|
743
984
|
// A sweep reports its span live, so a selection can track the drag; a move
|
|
@@ -747,7 +988,101 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
747
988
|
props.onSelectDrag?.(new Date(lo), new Date(hi));
|
|
748
989
|
}
|
|
749
990
|
};
|
|
991
|
+
let heldTouch: (() => void) | null = null;
|
|
992
|
+
let heldOrigin: { day: Date; event?: CalendarEvent<T> } | null = null;
|
|
993
|
+
const dayLookup = createMemo(
|
|
994
|
+
() =>
|
|
995
|
+
new Map(
|
|
996
|
+
_grid()
|
|
997
|
+
.weeks.flatMap((week) => week.days)
|
|
998
|
+
.map((day) => [day.id, day]),
|
|
999
|
+
),
|
|
1000
|
+
);
|
|
1001
|
+
const pressRow = (
|
|
1002
|
+
event: PointerEvent & { currentTarget: HTMLElement },
|
|
1003
|
+
day: Date,
|
|
1004
|
+
moving?: CalendarEvent<T>,
|
|
1005
|
+
) => {
|
|
1006
|
+
if (event.button !== 0 || heldTouch || !beginPress(event)) return;
|
|
1007
|
+
const start = (armed: boolean) => {
|
|
1008
|
+
if (moving) beginMove(moving, day, event.pointerId, armed);
|
|
1009
|
+
else beginCreate(day, event.pointerId, armed);
|
|
1010
|
+
};
|
|
1011
|
+
if (!multiWeek() || !event.pointerType || event.pointerType === "mouse") {
|
|
1012
|
+
start(false);
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
heldOrigin = { day, event: moving };
|
|
1016
|
+
heldTouch = holdDateDrag(
|
|
1017
|
+
{
|
|
1018
|
+
box: event.currentTarget,
|
|
1019
|
+
pointerId: event.pointerId,
|
|
1020
|
+
pointerType: event.pointerType,
|
|
1021
|
+
clientX: event.clientX,
|
|
1022
|
+
clientY: event.clientY,
|
|
1023
|
+
},
|
|
1024
|
+
// The hold itself is the deliberate gesture, so a held drag starts armed.
|
|
1025
|
+
() => start(true),
|
|
1026
|
+
(x, y) => {
|
|
1027
|
+
const element = gridRef.current?.ownerDocument
|
|
1028
|
+
.elementFromPoint(x, y)
|
|
1029
|
+
?.closest<HTMLElement>("[data-day]");
|
|
1030
|
+
if (!element || !gridRef.current?.contains(element)) return;
|
|
1031
|
+
const day = dayLookup().get(element.dataset.day ?? "");
|
|
1032
|
+
if (day && !day.isDisabled) extendDrag(day.date, event.pointerId);
|
|
1033
|
+
},
|
|
1034
|
+
() => {
|
|
1035
|
+
applyDrag(null);
|
|
1036
|
+
movedRef.current = false;
|
|
1037
|
+
},
|
|
1038
|
+
() => {
|
|
1039
|
+
heldTouch = null;
|
|
1040
|
+
heldOrigin = null;
|
|
1041
|
+
},
|
|
1042
|
+
);
|
|
1043
|
+
};
|
|
1044
|
+
createEffect(
|
|
1045
|
+
() => windowKey(),
|
|
1046
|
+
() => () => {
|
|
1047
|
+
heldTouch?.();
|
|
1048
|
+
},
|
|
1049
|
+
);
|
|
1050
|
+
createEffect(
|
|
1051
|
+
() => ({
|
|
1052
|
+
days: dayLookup(),
|
|
1053
|
+
events: props.events,
|
|
1054
|
+
canCreate: !!(props.onCreateEvent || props.onSelectDrag),
|
|
1055
|
+
canMove: !!props.onDragEvent,
|
|
1056
|
+
eventStartEditable: props.eventStartEditable,
|
|
1057
|
+
}),
|
|
1058
|
+
(state) => {
|
|
1059
|
+
const origin = heldOrigin;
|
|
1060
|
+
if (!origin) return;
|
|
1061
|
+
const current = dragRef.current;
|
|
1062
|
+
const destination = current
|
|
1063
|
+
? new Date(current.kind === "create" ? current.hover : current.to)
|
|
1064
|
+
: origin.day;
|
|
1065
|
+
const enabled = (day: Date) => {
|
|
1066
|
+
const cell = state.days.get(format(day, "yyyy-MM-dd"));
|
|
1067
|
+
return cell != null && !cell.isDisabled;
|
|
1068
|
+
};
|
|
1069
|
+
if (
|
|
1070
|
+
!enabled(origin.day) ||
|
|
1071
|
+
!enabled(destination) ||
|
|
1072
|
+
(origin.event
|
|
1073
|
+
? !state.canMove ||
|
|
1074
|
+
!state.events?.includes(origin.event) ||
|
|
1075
|
+
origin.event.disabled ||
|
|
1076
|
+
origin.event.draggable === false ||
|
|
1077
|
+
!(origin.event.startEditable ?? state.eventStartEditable)
|
|
1078
|
+
: !state.canCreate)
|
|
1079
|
+
) {
|
|
1080
|
+
heldTouch?.();
|
|
1081
|
+
}
|
|
1082
|
+
},
|
|
1083
|
+
);
|
|
750
1084
|
const isDragging = createMemo(() => drag() !== null);
|
|
1085
|
+
const dragArmed = createMemo(() => drag()?.armed === true);
|
|
751
1086
|
// Whether any month drag is wired up at all, so the cells only take over touch
|
|
752
1087
|
// scrolling and pointer tracking when one of the handlers can actually fire.
|
|
753
1088
|
const dragWired = createMemo(
|
|
@@ -762,8 +1097,16 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
762
1097
|
const current = dragRef.current;
|
|
763
1098
|
if (!current || current.pointerId !== e.pointerId) return;
|
|
764
1099
|
applyDrag(null);
|
|
765
|
-
if (!movedRef.current)
|
|
1100
|
+
if (!movedRef.current) {
|
|
1101
|
+
// An armed move that returns to its day is released over the day cell,
|
|
1102
|
+
// because the chip ignored pointer input mid drag. The click that
|
|
1103
|
+
// follows belongs to the abandoned drag, not to the day.
|
|
1104
|
+
if (current.kind === "move" && current.armed) suppressClickRef.current = true;
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
766
1107
|
suppressClickRef.current = true;
|
|
1108
|
+
// Multi-week rows drop a drag whose window was replaced before release.
|
|
1109
|
+
if (multiWeek() && current.windowKey !== windowKey()) return;
|
|
767
1110
|
if (current.kind === "create") {
|
|
768
1111
|
const range = monthCreateRange(new Date(current.anchor), new Date(current.hover));
|
|
769
1112
|
props.onCreateEvent?.(range.start, range.end);
|
|
@@ -781,31 +1124,99 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
781
1124
|
}
|
|
782
1125
|
props.onDragEvent?.(current.event, next.start, next.end);
|
|
783
1126
|
};
|
|
784
|
-
const
|
|
785
|
-
|
|
1127
|
+
const clear = () => {
|
|
1128
|
+
heldTouch?.();
|
|
786
1129
|
applyDrag(null);
|
|
787
1130
|
movedRef.current = false;
|
|
788
1131
|
suppressClickRef.current = true;
|
|
789
1132
|
};
|
|
1133
|
+
const cancel = (event: PointerEvent) => {
|
|
1134
|
+
if (dragRef.current?.pointerId === event.pointerId) clear();
|
|
1135
|
+
};
|
|
1136
|
+
const arm = (event: PointerEvent) => {
|
|
1137
|
+
const current = dragRef.current;
|
|
1138
|
+
if (!current || current.armed || current.pointerId !== event.pointerId) return;
|
|
1139
|
+
const distance = Math.hypot(event.clientX - pressOrigin.x, event.clientY - pressOrigin.y);
|
|
1140
|
+
if (distance <= pressOrigin.slop) return;
|
|
1141
|
+
applyDrag({ ...current, armed: true });
|
|
1142
|
+
};
|
|
1143
|
+
const keyDown = (event: KeyboardEvent) => {
|
|
1144
|
+
if (event.key !== "Escape") return;
|
|
1145
|
+
event.preventDefault();
|
|
1146
|
+
clear();
|
|
1147
|
+
};
|
|
1148
|
+
window.addEventListener("pointermove", arm);
|
|
790
1149
|
window.addEventListener("pointerup", finish);
|
|
791
1150
|
window.addEventListener("pointercancel", cancel);
|
|
1151
|
+
window.addEventListener("keydown", keyDown);
|
|
792
1152
|
return () => {
|
|
1153
|
+
window.removeEventListener("pointermove", arm);
|
|
793
1154
|
window.removeEventListener("pointerup", finish);
|
|
794
1155
|
window.removeEventListener("pointercancel", cancel);
|
|
1156
|
+
window.removeEventListener("keydown", keyDown);
|
|
795
1157
|
};
|
|
796
1158
|
}),
|
|
797
1159
|
);
|
|
1160
|
+
// Replacing the multi-week window cancels a drag and closes the overflow
|
|
1161
|
+
// popover, so neither acts on days that are no longer shown.
|
|
1162
|
+
let transientWindow = untrack(windowKey);
|
|
1163
|
+
createEffect(windowKey, (key) =>
|
|
1164
|
+
untrack(() => {
|
|
1165
|
+
if (key === transientWindow) return;
|
|
1166
|
+
transientWindow = key;
|
|
1167
|
+
if (!multiWeek()) return;
|
|
1168
|
+
applyDrag(null);
|
|
1169
|
+
setMoreOpenFor(null);
|
|
1170
|
+
}),
|
|
1171
|
+
);
|
|
1172
|
+
// Multi-week roving: the neighbouring focusable day, the same weekday in the
|
|
1173
|
+
// nearest week that has it enabled, or the first/last focusable day.
|
|
1174
|
+
const nextMultiWeekFocus = (key: string): Date | null => {
|
|
1175
|
+
const days = focusableDays();
|
|
1176
|
+
const keys = focusableKeys();
|
|
1177
|
+
const period = _grid().period;
|
|
1178
|
+
if (!days || !keys || !period) return null;
|
|
1179
|
+
const index = days.findIndex((d) => format(d, "yyyy-MM-dd") === focusKey());
|
|
1180
|
+
if (index === -1) return null;
|
|
1181
|
+
if (key === "ArrowLeft") return days[index - 1] ?? null;
|
|
1182
|
+
if (key === "ArrowRight") return days[index + 1] ?? null;
|
|
1183
|
+
if (key === "Home") return days[0];
|
|
1184
|
+
if (key === "End") return days[days.length - 1];
|
|
1185
|
+
const step = key === "ArrowUp" ? -7 : 7;
|
|
1186
|
+
for (
|
|
1187
|
+
let cursor = addDays(days[index], step);
|
|
1188
|
+
cursor >= period.start && cursor < period.endExclusive;
|
|
1189
|
+
cursor = addDays(cursor, step)
|
|
1190
|
+
) {
|
|
1191
|
+
if (keys.has(format(cursor, "yyyy-MM-dd"))) return cursor;
|
|
1192
|
+
}
|
|
1193
|
+
return null;
|
|
1194
|
+
};
|
|
798
1195
|
const onKeyDown = (e: DomKeyboardEvent<HTMLDivElement>) => {
|
|
1196
|
+
if (multiWeek()) {
|
|
1197
|
+
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"].includes(e.key)) {
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
e.preventDefault();
|
|
1201
|
+
const target = nextMultiWeekFocus(e.key);
|
|
1202
|
+
if (!target) return;
|
|
1203
|
+
setFocusedDate(target);
|
|
1204
|
+
const targetKey = format(target, "yyyy-MM-dd");
|
|
1205
|
+
gridRef.current?.querySelector<HTMLElement>(`[data-day="${targetKey}"]`)?.focus();
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
const focused = focusedDate();
|
|
1209
|
+
if (!focused) return;
|
|
799
1210
|
let next: Date | null = null;
|
|
800
|
-
if (e.key === "ArrowLeft") next = addDays(
|
|
801
|
-
else if (e.key === "ArrowRight") next = addDays(
|
|
802
|
-
else if (e.key === "ArrowUp") next = addDays(
|
|
803
|
-
else if (e.key === "ArrowDown") next = addDays(
|
|
804
|
-
else if (e.key === "Home") next = startOfMonth(props.date);
|
|
805
|
-
else if (e.key === "End") next = endOfMonth(props.date);
|
|
1211
|
+
if (e.key === "ArrowLeft") next = addDays(focused, -1);
|
|
1212
|
+
else if (e.key === "ArrowRight") next = addDays(focused, 1);
|
|
1213
|
+
else if (e.key === "ArrowUp") next = addDays(focused, -7);
|
|
1214
|
+
else if (e.key === "ArrowDown") next = addDays(focused, 7);
|
|
1215
|
+
else if (e.key === "Home") next = startOfMonth(props.source.date);
|
|
1216
|
+
else if (e.key === "End") next = endOfMonth(props.source.date);
|
|
806
1217
|
else return;
|
|
807
1218
|
e.preventDefault();
|
|
808
|
-
if (!isSameMonth(next, props.date)) return;
|
|
1219
|
+
if (!isSameMonth(next, props.source.date)) return;
|
|
809
1220
|
setFocusedDate(next);
|
|
810
1221
|
const key = format(next, "yyyy-MM-dd");
|
|
811
1222
|
gridRef.current?.querySelector<HTMLElement>(`[data-day="${key}"]`)?.focus();
|
|
@@ -816,6 +1227,9 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
816
1227
|
style={css({
|
|
817
1228
|
fontFamily: theme().fontFamily,
|
|
818
1229
|
color: theme().text,
|
|
1230
|
+
// Multi-week rows keep their full height; when the view is given less
|
|
1231
|
+
// room, the grid scrolls under the title and weekday header.
|
|
1232
|
+
...(multiWeek() ? { display: "flex", flexDirection: "column", minHeight: 0 } : null),
|
|
819
1233
|
...props.style,
|
|
820
1234
|
})}
|
|
821
1235
|
>
|
|
@@ -829,15 +1243,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
829
1243
|
},
|
|
830
1244
|
})}
|
|
831
1245
|
>
|
|
832
|
-
{
|
|
833
|
-
props.date,
|
|
834
|
-
"MMMM yyyy",
|
|
835
|
-
props.locale
|
|
836
|
-
? {
|
|
837
|
-
locale: props.locale,
|
|
838
|
-
}
|
|
839
|
-
: undefined,
|
|
840
|
-
)}
|
|
1246
|
+
{_grid().title}
|
|
841
1247
|
</div>
|
|
842
1248
|
) : null}
|
|
843
1249
|
{props.showWeekdays ? (
|
|
@@ -845,7 +1251,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
845
1251
|
{...slot("weekdays", {
|
|
846
1252
|
base: {
|
|
847
1253
|
display: "grid",
|
|
848
|
-
gridTemplateColumns:
|
|
1254
|
+
gridTemplateColumns: `repeat(${_grid().weekdays.length}, minmax(0, 1fr))`,
|
|
849
1255
|
},
|
|
850
1256
|
themed: {
|
|
851
1257
|
borderBottom: `1px solid ${theme().gridLine}`,
|
|
@@ -876,19 +1282,15 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
876
1282
|
<div
|
|
877
1283
|
ref={(el) => (gridRef.current = el)}
|
|
878
1284
|
role="grid"
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
"MMMM yyyy",
|
|
882
|
-
props.locale
|
|
883
|
-
? {
|
|
884
|
-
locale: props.locale,
|
|
885
|
-
}
|
|
886
|
-
: undefined,
|
|
887
|
-
)}
|
|
1285
|
+
tabindex={multiWeek() ? -1 : undefined}
|
|
1286
|
+
aria-label={_grid().title}
|
|
888
1287
|
// Arrow-key roving applies whenever the day cells are a tab stop: the
|
|
889
1288
|
// picker always, events mode only when keyboardDayNavigation is set.
|
|
890
1289
|
onKeyDown={dayRoving() ? onKeyDown : undefined}
|
|
891
|
-
{...slot(
|
|
1290
|
+
{...slot(
|
|
1291
|
+
"grid",
|
|
1292
|
+
multiWeek() ? { base: { flex: "1 1 auto", minHeight: 0, overflowY: "auto" } } : undefined,
|
|
1293
|
+
)}
|
|
892
1294
|
>
|
|
893
1295
|
{
|
|
894
1296
|
<For each={_grid().weeks} keyed={false}>
|
|
@@ -913,9 +1315,9 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
913
1315
|
const columns = createMemo(() => {
|
|
914
1316
|
let first = 0;
|
|
915
1317
|
let last = cols() - 1;
|
|
916
|
-
if (eventsMode() && !
|
|
917
|
-
const start = week().days.findIndex((d) => d
|
|
918
|
-
const end = [...week().days].reverse().findIndex((d) => d
|
|
1318
|
+
if (eventsMode() && !showAdjacentMonths()) {
|
|
1319
|
+
const start = week().days.findIndex((d) => !isOutsidePeriod(d));
|
|
1320
|
+
const end = [...week().days].reverse().findIndex((d) => !isOutsidePeriod(d));
|
|
919
1321
|
if (start !== -1) {
|
|
920
1322
|
first = start;
|
|
921
1323
|
last = cols() - 1 - end;
|
|
@@ -926,6 +1328,29 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
926
1328
|
last,
|
|
927
1329
|
};
|
|
928
1330
|
});
|
|
1331
|
+
const draftColumns = createMemo(() => {
|
|
1332
|
+
const range = createRange();
|
|
1333
|
+
return range
|
|
1334
|
+
? week().days.flatMap((day, index) =>
|
|
1335
|
+
(!showAdjacentMonths() && isOutsidePeriod(day)) ||
|
|
1336
|
+
day.date < range.start ||
|
|
1337
|
+
day.date >= range.end
|
|
1338
|
+
? []
|
|
1339
|
+
: [index],
|
|
1340
|
+
)
|
|
1341
|
+
: [];
|
|
1342
|
+
});
|
|
1343
|
+
const draftTop = createMemo(
|
|
1344
|
+
() =>
|
|
1345
|
+
CELL_PAD +
|
|
1346
|
+
DATE_ROW +
|
|
1347
|
+
props.chipGap +
|
|
1348
|
+
Math.min(visibleLanes(), Math.max(0, props.maxVisibleEventCount - 1)) *
|
|
1349
|
+
(props.chipHeight + props.chipGap),
|
|
1350
|
+
);
|
|
1351
|
+
const draftHeight = createMemo(() =>
|
|
1352
|
+
Math.min(props.chipHeight, Math.max(0, eventRowHeight() - draftTop())),
|
|
1353
|
+
);
|
|
929
1354
|
return (
|
|
930
1355
|
<>
|
|
931
1356
|
{(() => {
|
|
@@ -955,7 +1380,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
955
1380
|
{...slot("week", {
|
|
956
1381
|
base: {
|
|
957
1382
|
display: "grid",
|
|
958
|
-
gridTemplateColumns:
|
|
1383
|
+
gridTemplateColumns: `repeat(${cols()}, minmax(0, 1fr))`,
|
|
959
1384
|
},
|
|
960
1385
|
})}
|
|
961
1386
|
>
|
|
@@ -963,7 +1388,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
963
1388
|
<For each={week().days} keyed={false}>
|
|
964
1389
|
{(day, dayCol) => {
|
|
965
1390
|
const hidden = createMemo(
|
|
966
|
-
() => !
|
|
1391
|
+
() => !showAdjacentMonths() && isOutsidePeriod(day()),
|
|
967
1392
|
);
|
|
968
1393
|
const cellHeight = createMemo(() =>
|
|
969
1394
|
eventsMode() ? eventRowHeight() : theme().cellHeight,
|
|
@@ -1037,7 +1462,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1037
1462
|
"data-selected": day().isSelected,
|
|
1038
1463
|
"data-range": day().isInRange,
|
|
1039
1464
|
"data-weekend": day().isWeekend,
|
|
1040
|
-
"data-outside":
|
|
1465
|
+
"data-outside": isOutsidePeriod(day()),
|
|
1041
1466
|
"data-disabled": day().isDisabled,
|
|
1042
1467
|
"data-creating": inCreate(),
|
|
1043
1468
|
"data-drop": isDropTarget(),
|
|
@@ -1096,8 +1521,26 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1096
1521
|
role="gridcell"
|
|
1097
1522
|
data-day={day().id}
|
|
1098
1523
|
onFocusIn={(event) => {
|
|
1099
|
-
if (event.target === event.currentTarget)
|
|
1524
|
+
if (event.target === event.currentTarget) {
|
|
1525
|
+
lastDayFocus.current = event.currentTarget;
|
|
1100
1526
|
setFocusedDate(day().date);
|
|
1527
|
+
}
|
|
1528
|
+
}}
|
|
1529
|
+
onFocusOut={(event) => {
|
|
1530
|
+
if (event.target !== event.currentTarget) return;
|
|
1531
|
+
const previous = event.currentTarget;
|
|
1532
|
+
if (event.relatedTarget) lastDayFocus.current = null;
|
|
1533
|
+
else {
|
|
1534
|
+
// Removal blurs before detaching the node. Distinguish
|
|
1535
|
+
// it from a manual blur after the DOM update finishes.
|
|
1536
|
+
queueMicrotask(() => {
|
|
1537
|
+
if (
|
|
1538
|
+
lastDayFocus.current === previous &&
|
|
1539
|
+
previous.isConnected
|
|
1540
|
+
)
|
|
1541
|
+
lastDayFocus.current = null;
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1101
1544
|
}}
|
|
1102
1545
|
{...dayData()}
|
|
1103
1546
|
tabindex={
|
|
@@ -1130,7 +1573,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1130
1573
|
dragWired()
|
|
1131
1574
|
? {
|
|
1132
1575
|
...dayCellProps().style,
|
|
1133
|
-
touchAction: "none",
|
|
1576
|
+
touchAction: multiWeek() ? "pan-y" : "none",
|
|
1134
1577
|
userSelect: "none",
|
|
1135
1578
|
}
|
|
1136
1579
|
: dayCellProps().style,
|
|
@@ -1138,8 +1581,8 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1138
1581
|
onPointerDown={
|
|
1139
1582
|
dragWired() && !day().isDisabled
|
|
1140
1583
|
? (e) => {
|
|
1141
|
-
|
|
1142
|
-
|
|
1584
|
+
const date = day().date;
|
|
1585
|
+
pressRow(e, date);
|
|
1143
1586
|
}
|
|
1144
1587
|
: undefined
|
|
1145
1588
|
}
|
|
@@ -1153,8 +1596,8 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1153
1596
|
onClick={
|
|
1154
1597
|
day().isDisabled
|
|
1155
1598
|
? undefined
|
|
1156
|
-
: () => {
|
|
1157
|
-
if (consumeSuppressedClick()) return;
|
|
1599
|
+
: (e) => {
|
|
1600
|
+
if (consumeSuppressedClick(e.detail)) return;
|
|
1158
1601
|
props.onPressDay?.(day().date);
|
|
1159
1602
|
props.onPressCell?.(startOfDay(day().date));
|
|
1160
1603
|
}
|
|
@@ -1199,6 +1642,45 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1199
1642
|
start day's gridcell and reads with that day. Made
|
|
1200
1643
|
non-interactive mid drag so a sweep (or a move) reaches the
|
|
1201
1644
|
cells beneath. */}
|
|
1645
|
+
<Show
|
|
1646
|
+
when={
|
|
1647
|
+
props.renderCreateGhost &&
|
|
1648
|
+
createRange() &&
|
|
1649
|
+
draftColumns()[0] === dayCol &&
|
|
1650
|
+
draftHeight() > 0
|
|
1651
|
+
}
|
|
1652
|
+
>
|
|
1653
|
+
<div
|
|
1654
|
+
{...slot("createGhost", {
|
|
1655
|
+
base: {
|
|
1656
|
+
position: "absolute",
|
|
1657
|
+
left: 2,
|
|
1658
|
+
width: `calc(${(draftColumns().at(-1)! - dayCol + 1) * 100}% - 4px)`,
|
|
1659
|
+
top: draftTop(),
|
|
1660
|
+
height: draftHeight(),
|
|
1661
|
+
boxSizing: "border-box",
|
|
1662
|
+
pointerEvents: "none",
|
|
1663
|
+
overflow: "hidden",
|
|
1664
|
+
zIndex: 3,
|
|
1665
|
+
},
|
|
1666
|
+
themed: {
|
|
1667
|
+
background: theme().rangeBackground,
|
|
1668
|
+
border: `1px solid ${theme().selectedBackground}`,
|
|
1669
|
+
borderRadius: 4,
|
|
1670
|
+
fontSize: 12,
|
|
1671
|
+
color: theme().text,
|
|
1672
|
+
},
|
|
1673
|
+
})}
|
|
1674
|
+
inert
|
|
1675
|
+
aria-hidden="true"
|
|
1676
|
+
>
|
|
1677
|
+
<Dynamic
|
|
1678
|
+
component={props.renderCreateGhost!}
|
|
1679
|
+
start={createRange()!.start}
|
|
1680
|
+
end={createRange()!.end}
|
|
1681
|
+
/>
|
|
1682
|
+
</div>
|
|
1683
|
+
</Show>
|
|
1202
1684
|
{
|
|
1203
1685
|
<For
|
|
1204
1686
|
each={barSegs().filter((b) => b.startCol === dayCol)}
|
|
@@ -1211,7 +1693,8 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1211
1693
|
const isDragged = createMemo(() => {
|
|
1212
1694
|
const currentDrag = drag();
|
|
1213
1695
|
return (
|
|
1214
|
-
currentDrag?.
|
|
1696
|
+
currentDrag?.armed === true &&
|
|
1697
|
+
currentDrag.kind === "move" &&
|
|
1215
1698
|
currentDrag.event === b().seg.event
|
|
1216
1699
|
);
|
|
1217
1700
|
});
|
|
@@ -1221,20 +1704,16 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1221
1704
|
onPointerDown={
|
|
1222
1705
|
canMove(b().seg.event)
|
|
1223
1706
|
? (e) => {
|
|
1224
|
-
if (e.button !== 0 || !beginPress(e))
|
|
1225
|
-
return;
|
|
1226
1707
|
e.stopPropagation();
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
e.pointerId,
|
|
1231
|
-
);
|
|
1708
|
+
const event = b().seg.event;
|
|
1709
|
+
const date = day().date;
|
|
1710
|
+
pressRow(e, date, event);
|
|
1232
1711
|
}
|
|
1233
1712
|
: undefined
|
|
1234
1713
|
}
|
|
1235
1714
|
onClick={(e) => {
|
|
1236
1715
|
e.stopPropagation();
|
|
1237
|
-
if (consumeSuppressedClick()) return;
|
|
1716
|
+
if (consumeSuppressedClick(e.detail)) return;
|
|
1238
1717
|
props.onPressEvent?.(b().seg.event);
|
|
1239
1718
|
}}
|
|
1240
1719
|
{...barChipButton()}
|
|
@@ -1244,7 +1723,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1244
1723
|
? props.eventAccessibilityLabel(
|
|
1245
1724
|
b().seg.event,
|
|
1246
1725
|
{
|
|
1247
|
-
mode:
|
|
1726
|
+
mode: viewMode(),
|
|
1248
1727
|
isAllDay: isAllDayEvent(
|
|
1249
1728
|
b().seg.event,
|
|
1250
1729
|
),
|
|
@@ -1265,7 +1744,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1265
1744
|
b().seg.lane *
|
|
1266
1745
|
(props.chipHeight + props.chipGap),
|
|
1267
1746
|
height: props.chipHeight,
|
|
1268
|
-
pointerEvents:
|
|
1747
|
+
pointerEvents: dragArmed() ? "none" : "auto",
|
|
1269
1748
|
// Fade the bar being carried, so the tinted drop
|
|
1270
1749
|
// target reads as where it is going.
|
|
1271
1750
|
opacity: isDragged()
|
|
@@ -1274,13 +1753,18 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1274
1753
|
cursor: canMove(b().seg.event)
|
|
1275
1754
|
? "grab"
|
|
1276
1755
|
: undefined,
|
|
1277
|
-
touchAction: dragWired()
|
|
1756
|
+
touchAction: dragWired()
|
|
1757
|
+
? multiWeek()
|
|
1758
|
+
? "pan-y"
|
|
1759
|
+
: "none"
|
|
1760
|
+
: undefined,
|
|
1278
1761
|
zIndex: 2,
|
|
1279
1762
|
})}
|
|
1280
1763
|
>
|
|
1281
1764
|
{Chip() ? (
|
|
1282
1765
|
<Dynamic
|
|
1283
1766
|
component={Chip()}
|
|
1767
|
+
mode={viewMode()}
|
|
1284
1768
|
event={b().seg.event}
|
|
1285
1769
|
onPress={() =>
|
|
1286
1770
|
props.onPressEvent?.(b().seg.event)
|
|
@@ -1361,7 +1845,11 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1361
1845
|
}}
|
|
1362
1846
|
{...slot(
|
|
1363
1847
|
"more",
|
|
1364
|
-
moreButtonDefault(
|
|
1848
|
+
moreButtonDefault(
|
|
1849
|
+
theme(),
|
|
1850
|
+
props.chipHeight,
|
|
1851
|
+
multiWeek(),
|
|
1852
|
+
),
|
|
1365
1853
|
)}
|
|
1366
1854
|
aria-label={`${labels().moreEvents(hiddenEvents().length)}, ${dayLabel()}`}
|
|
1367
1855
|
aria-expanded={
|
|
@@ -1473,6 +1961,7 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1473
1961
|
{Chip() ? (
|
|
1474
1962
|
<Dynamic
|
|
1475
1963
|
component={Chip()}
|
|
1964
|
+
mode={viewMode()}
|
|
1476
1965
|
event={event()}
|
|
1477
1966
|
onPress={() =>
|
|
1478
1967
|
props.onPressEvent?.(event())
|
|
@@ -1508,8 +1997,10 @@ export function MonthView<T = unknown>(incoming: MonthViewInternalProps<T>): JSX
|
|
|
1508
1997
|
role="gridcell"
|
|
1509
1998
|
data-day={day().id}
|
|
1510
1999
|
onFocusIn={(event) => {
|
|
1511
|
-
if (event.target === event.currentTarget)
|
|
2000
|
+
if (event.target === event.currentTarget) {
|
|
2001
|
+
lastDayFocus.current = event.currentTarget;
|
|
1512
2002
|
setFocusedDate(day().date);
|
|
2003
|
+
}
|
|
1513
2004
|
}}
|
|
1514
2005
|
{...dayData()}
|
|
1515
2006
|
tabindex={day().id === focusKey() ? 0 : -1}
|