@super-calendar/dom 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 +44 -0
- package/dist/index.d.mts +49 -7
- package/dist/index.d.ts +49 -7
- package/dist/index.js +424 -87
- package/dist/index.mjs +420 -90
- package/package.json +2 -2
- package/src/Calendar.tsx +78 -13
- package/src/MonthView.tsx +388 -65
- package/src/MultiWeekView.tsx +54 -0
- package/src/index.ts +7 -0
- package/src/touch.ts +70 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-calendar/dom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
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.17.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@legendapp/list": ">=3",
|
package/src/Calendar.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
addDays,
|
|
3
3
|
addMonths,
|
|
4
|
+
addWeeks,
|
|
4
5
|
endOfDay,
|
|
5
6
|
endOfMonth,
|
|
6
7
|
endOfWeek,
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
type DateRange,
|
|
35
36
|
type DateSelectionConstraints,
|
|
36
37
|
type EventAccessibilityLabeler,
|
|
38
|
+
buildMultiWeekGrid,
|
|
37
39
|
eventsInTimeZone,
|
|
38
40
|
expandRecurringEvents,
|
|
39
41
|
getViewDays,
|
|
@@ -44,6 +46,7 @@ import type { CalendarHandle, CalendarLabels } from "@super-calendar/core";
|
|
|
44
46
|
import { Agenda, type AgendaSlot, type DomAgendaEvent } from "./Agenda";
|
|
45
47
|
import { YearView, type YearViewSlot } from "./YearView";
|
|
46
48
|
import { type DomMonthEvent, MonthView, type MonthViewSlot } from "./MonthView";
|
|
49
|
+
import { MultiWeekView } from "./MultiWeekView";
|
|
47
50
|
import type { SlotStyleProps } from "./slots";
|
|
48
51
|
import { type DomRenderEvent, TimeGrid, type TimeGridSlot } from "./TimeGrid";
|
|
49
52
|
import type { DomCalendarTheme } from "./theme";
|
|
@@ -59,8 +62,9 @@ export type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot | YearViewS
|
|
|
59
62
|
export interface CalendarProps<T = unknown>
|
|
60
63
|
extends DateSelectionConstraints, SlotStyleProps<CalendarSlot> {
|
|
61
64
|
/**
|
|
62
|
-
* The view to render (default "week"). `month` renders a month grid,
|
|
63
|
-
* a day-grouped agenda list,
|
|
65
|
+
* The view to render (default "week"). `month` renders a month grid,
|
|
66
|
+
* `multiweek` stacked week rows, `schedule` a day-grouped agenda list, `year`
|
|
67
|
+
* twelve mini months, and the others a time grid.
|
|
64
68
|
*/
|
|
65
69
|
mode?: CalendarMode;
|
|
66
70
|
/**
|
|
@@ -73,8 +77,9 @@ export interface CalendarProps<T = unknown>
|
|
|
73
77
|
date: Date;
|
|
74
78
|
/**
|
|
75
79
|
* Fires with the next/previous period's date when the user pages the focused
|
|
76
|
-
* calendar with **PageDown** / **PageUp** (a month in `month`,
|
|
77
|
-
* `schedule`, else the view's
|
|
80
|
+
* calendar with **PageDown** / **PageUp** (a month in `month`,
|
|
81
|
+
* `numberOfWeeks` weeks in `multiweek`, a week in `schedule`, else the view's
|
|
82
|
+
* day span). It's controlled, so update `date` in
|
|
78
83
|
* response. Omit it to leave paging to your own controls.
|
|
79
84
|
*/
|
|
80
85
|
onChangeDate?: (date: Date) => void;
|
|
@@ -92,6 +97,11 @@ export interface CalendarProps<T = unknown>
|
|
|
92
97
|
now?: Date;
|
|
93
98
|
/** Column count for `mode="custom"`. */
|
|
94
99
|
numberOfDays?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Week rows for `mode="multiweek"`: a positive whole number, default 2. The
|
|
102
|
+
* rows start on the week containing `date`. Other values throw a `RangeError`.
|
|
103
|
+
*/
|
|
104
|
+
numberOfWeeks?: number;
|
|
95
105
|
/** date-fns locale for titles, headers, and time labels. */
|
|
96
106
|
locale?: Locale;
|
|
97
107
|
/**
|
|
@@ -220,7 +230,7 @@ export interface CalendarProps<T = unknown>
|
|
|
220
230
|
*/
|
|
221
231
|
keyboardEventNavigation?: boolean;
|
|
222
232
|
|
|
223
|
-
// --- Month
|
|
233
|
+
// --- Month and multiweek modes ---
|
|
224
234
|
/** Max chips per day before a "+N more" row. */
|
|
225
235
|
maxVisibleEventCount?: number;
|
|
226
236
|
/** Month chip height in pixels; omit to keep the renderer default. */
|
|
@@ -278,14 +288,20 @@ export interface CalendarProps<T = unknown>
|
|
|
278
288
|
const EMPTY_EVENTS: CalendarEvent<never>[] = [];
|
|
279
289
|
|
|
280
290
|
// Recurrence is expanded over the range a mode renders: the month grid for
|
|
281
|
-
// `month`, the day columns for the time-grid
|
|
282
|
-
// `schedule` agenda (which has no bounded
|
|
291
|
+
// `month`, the week rows for `multiweek`, the day columns for the time-grid
|
|
292
|
+
// modes, and a forward window for the `schedule` agenda (which has no bounded
|
|
293
|
+
// viewport of its own).
|
|
283
294
|
function expansionRange(
|
|
284
295
|
mode: CalendarMode,
|
|
285
296
|
date: Date,
|
|
286
297
|
weekStartsOn: WeekStartsOn,
|
|
287
298
|
numberOfDays: number | undefined,
|
|
299
|
+
numberOfWeeks: number,
|
|
288
300
|
): [Date, Date] {
|
|
301
|
+
if (mode === "multiweek") {
|
|
302
|
+
const { period } = buildMultiWeekGrid(date, { weekStartsOn, numberOfWeeks });
|
|
303
|
+
return [period.start, endOfDay(addDays(period.endExclusive, -1))];
|
|
304
|
+
}
|
|
289
305
|
if (mode === "month") {
|
|
290
306
|
return [
|
|
291
307
|
startOfWeek(startOfMonth(date), { weekStartsOn }),
|
|
@@ -308,16 +324,19 @@ function expansionRange(
|
|
|
308
324
|
}
|
|
309
325
|
|
|
310
326
|
// The date one page away in `direction` (+1 next, −1 previous): a year for
|
|
311
|
-
// `year`, a month for `month`,
|
|
327
|
+
// `year`, a month for `month`, the shown weeks for `multiweek`, a week for
|
|
328
|
+
// `schedule`, else the view's day span.
|
|
312
329
|
function pageStep(
|
|
313
330
|
mode: CalendarMode,
|
|
314
331
|
date: Date,
|
|
315
332
|
direction: number,
|
|
316
333
|
weekStartsOn: WeekStartsOn,
|
|
317
334
|
numberOfDays: number | undefined,
|
|
335
|
+
numberOfWeeks: number,
|
|
318
336
|
): Date {
|
|
319
337
|
if (mode === "year") return addYears(date, direction);
|
|
320
338
|
if (mode === "month") return addMonths(date, direction);
|
|
339
|
+
if (mode === "multiweek") return addWeeks(date, direction * numberOfWeeks);
|
|
321
340
|
if (mode === "schedule") return addDays(date, direction * 7);
|
|
322
341
|
return addDays(date, direction * getViewDays(mode, date, weekStartsOn, numberOfDays ?? 1).length);
|
|
323
342
|
}
|
|
@@ -347,6 +366,7 @@ function CalendarInner<T = unknown>(
|
|
|
347
366
|
hiddenDays,
|
|
348
367
|
now,
|
|
349
368
|
numberOfDays,
|
|
369
|
+
numberOfWeeks = 2,
|
|
350
370
|
locale,
|
|
351
371
|
timeZone,
|
|
352
372
|
theme,
|
|
@@ -433,7 +453,7 @@ function CalendarInner<T = unknown>(
|
|
|
433
453
|
const displayEvents = useMemo(() => {
|
|
434
454
|
let out: CalendarEvent<T>[] = events ?? EMPTY_EVENTS;
|
|
435
455
|
if (out.some((e) => e.recurrence)) {
|
|
436
|
-
let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays);
|
|
456
|
+
let [start, end] = expansionRange(mode, date, weekStartsOn, numberOfDays, numberOfWeeks);
|
|
437
457
|
// A display zone shifts each occurrence's wall-clock by up to ~a day, which
|
|
438
458
|
// can move an edge occurrence into a visible column; widen so it's generated.
|
|
439
459
|
if (timeZone) {
|
|
@@ -445,15 +465,17 @@ function CalendarInner<T = unknown>(
|
|
|
445
465
|
if (timeZone) out = eventsInTimeZone(out, timeZone);
|
|
446
466
|
return out;
|
|
447
467
|
// `date.getTime()`: recompute on the instant, not a re-created Date identity.
|
|
448
|
-
}, [events, mode, date.getTime(), weekStartsOn, numberOfDays, timeZone]);
|
|
468
|
+
}, [events, mode, date.getTime(), weekStartsOn, numberOfDays, numberOfWeeks, timeZone]);
|
|
449
469
|
|
|
450
470
|
// PageDown / PageUp page the calendar when the consumer opts in with
|
|
451
471
|
// `onChangeDate`; keydowns bubble up from the focused grid to this handler.
|
|
452
472
|
const handlePageKeys = (e: ReactKeyboardEvent) => {
|
|
453
473
|
if (!onChangeDate) return;
|
|
454
|
-
if (e.key === "PageDown")
|
|
455
|
-
|
|
456
|
-
else
|
|
474
|
+
if (e.key === "PageDown") {
|
|
475
|
+
onChangeDate(pageStep(mode, date, 1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
476
|
+
} else if (e.key === "PageUp") {
|
|
477
|
+
onChangeDate(pageStep(mode, date, -1, weekStartsOn, numberOfDays, numberOfWeeks));
|
|
478
|
+
} else return;
|
|
457
479
|
e.preventDefault();
|
|
458
480
|
};
|
|
459
481
|
|
|
@@ -545,6 +567,49 @@ function CalendarInner<T = unknown>(
|
|
|
545
567
|
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
546
568
|
/>
|
|
547
569
|
);
|
|
570
|
+
} else if (mode === "multiweek") {
|
|
571
|
+
view = (
|
|
572
|
+
<MultiWeekView<T>
|
|
573
|
+
date={date}
|
|
574
|
+
numberOfWeeks={numberOfWeeks}
|
|
575
|
+
events={displayEvents}
|
|
576
|
+
weekStartsOn={weekStartsOn}
|
|
577
|
+
hiddenDays={hiddenDays}
|
|
578
|
+
weekdayFormat={weekdayFormat}
|
|
579
|
+
highlightWeekends={highlightWeekends}
|
|
580
|
+
locale={locale}
|
|
581
|
+
labels={labels}
|
|
582
|
+
theme={theme}
|
|
583
|
+
className={className}
|
|
584
|
+
style={height != null ? { height, ...style } : style}
|
|
585
|
+
classNames={classNames}
|
|
586
|
+
styles={styles}
|
|
587
|
+
maxVisibleEventCount={maxVisibleEventCount}
|
|
588
|
+
chipHeight={chipHeight}
|
|
589
|
+
chipGap={chipGap}
|
|
590
|
+
moreLabel={moreLabel}
|
|
591
|
+
showTitle={showTitle}
|
|
592
|
+
fillCellOnSelection={fillCellOnSelection}
|
|
593
|
+
selectedRange={selectedRange}
|
|
594
|
+
selectedDates={selectedDates}
|
|
595
|
+
minDate={minDate}
|
|
596
|
+
maxDate={maxDate}
|
|
597
|
+
isDateDisabled={isDateDisabled}
|
|
598
|
+
keyboardDayNavigation={keyboardDayNavigation}
|
|
599
|
+
onPressDay={onPressDay}
|
|
600
|
+
onPressCell={onPressCell}
|
|
601
|
+
onCreateEvent={onCreateEvent}
|
|
602
|
+
onSelectDrag={onSelectDrag}
|
|
603
|
+
onDragEvent={onDragEvent}
|
|
604
|
+
onDragStart={onDragStart}
|
|
605
|
+
eventStartEditable={eventStartEditable}
|
|
606
|
+
eventOverlap={eventOverlap}
|
|
607
|
+
onPressEvent={onPressEvent}
|
|
608
|
+
onPressMore={onPressMore}
|
|
609
|
+
renderEvent={renderMonthEvent}
|
|
610
|
+
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
611
|
+
/>
|
|
612
|
+
);
|
|
548
613
|
} else {
|
|
549
614
|
view = (
|
|
550
615
|
<TimeGrid<T>
|