@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { WeekStartsOn } from "@super-calendar/core";
|
|
3
|
+
import { DateRows, type MonthViewProps } from "./MonthView";
|
|
4
|
+
|
|
5
|
+
/** Props for {@link MultiWeekView}. */
|
|
6
|
+
export interface MultiWeekViewProps<T = unknown> extends Omit<
|
|
7
|
+
MonthViewProps<T>,
|
|
8
|
+
"date" | "weekStartsOn" | "showAdjacentMonths"
|
|
9
|
+
> {
|
|
10
|
+
/**
|
|
11
|
+
* Any day in the first week to show. The rows start on the `weekStartsOn` day
|
|
12
|
+
* on or before it, in the device's local calendar.
|
|
13
|
+
*/
|
|
14
|
+
date: Date;
|
|
15
|
+
/**
|
|
16
|
+
* How many consecutive full weeks to show, as stacked rows. A positive whole
|
|
17
|
+
* number; default 2. Other values throw a `RangeError`.
|
|
18
|
+
*/
|
|
19
|
+
numberOfWeeks?: number;
|
|
20
|
+
/** First day of the week. Sunday = 0 (default) … Saturday = 6. */
|
|
21
|
+
weekStartsOn?: WeekStartsOn;
|
|
22
|
+
/** Event chip and overflow-button height in pixels (default 24). */
|
|
23
|
+
chipHeight?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Consecutive full weeks as stacked seven-day rows, with event chips and no hour
|
|
28
|
+
* slots. It has the month grid's event bars, overflow, selection, and drag
|
|
29
|
+
* interactions, and the month slots, `renderEvent`, and theme style it. Every
|
|
30
|
+
* row is kept at full height; when the view is given less room, the rows scroll
|
|
31
|
+
* under the title and weekday header.
|
|
32
|
+
*
|
|
33
|
+
* Standalone, it shows `events` as given; expand recurring events first with
|
|
34
|
+
* `expandRecurringEvents`, or use `Calendar` with `mode="multiweek"`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <MultiWeekView date={new Date()} numberOfWeeks={3} events={events} />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function MultiWeekView<T = unknown>({
|
|
42
|
+
date,
|
|
43
|
+
numberOfWeeks = 2,
|
|
44
|
+
chipHeight = 24,
|
|
45
|
+
...rest
|
|
46
|
+
}: MultiWeekViewProps<T>): ReactElement {
|
|
47
|
+
return (
|
|
48
|
+
<DateRows<T>
|
|
49
|
+
{...rest}
|
|
50
|
+
chipHeight={chipHeight}
|
|
51
|
+
source={{ kind: "multiweek", date, numberOfWeeks }}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ export {
|
|
|
42
42
|
type MonthViewSlot,
|
|
43
43
|
} from "./MonthView";
|
|
44
44
|
export { MonthList, type MonthListProps, type MonthListSlot } from "./MonthList";
|
|
45
|
+
export { MultiWeekView, type MultiWeekViewProps } from "./MultiWeekView";
|
|
45
46
|
export { YearView, type YearViewProps, type YearViewSlot } from "./YearView";
|
|
46
47
|
export {
|
|
47
48
|
type Resource,
|
|
@@ -101,6 +102,7 @@ export {
|
|
|
101
102
|
useNow,
|
|
102
103
|
useMonthGrid,
|
|
103
104
|
buildMonthGrid,
|
|
105
|
+
buildMultiWeekGrid,
|
|
104
106
|
layoutMonthWeek,
|
|
105
107
|
weekdayFormatToken,
|
|
106
108
|
type MonthEventSegment,
|
|
@@ -109,6 +111,11 @@ export {
|
|
|
109
111
|
type MonthGridWeek,
|
|
110
112
|
type MonthGridWeekday,
|
|
111
113
|
type MonthWeekEvents,
|
|
114
|
+
type MultiWeekGrid,
|
|
115
|
+
type MultiWeekGridDay,
|
|
116
|
+
type MultiWeekGridInterval,
|
|
117
|
+
type MultiWeekGridOptions,
|
|
118
|
+
type MultiWeekGridWeek,
|
|
112
119
|
type UseMonthGridOptions,
|
|
113
120
|
type WeekdayFormat,
|
|
114
121
|
} from "@super-calendar/core";
|
package/src/touch.ts
CHANGED
|
@@ -59,3 +59,73 @@ export function waitForHold(
|
|
|
59
59
|
document.addEventListener("pointerdown", anotherPointer);
|
|
60
60
|
return cancel;
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/** A quick swipe scrolls; a held pointer owns a date-row drag until release. */
|
|
64
|
+
export function holdDateDrag(
|
|
65
|
+
grab: EventGrab,
|
|
66
|
+
start: () => void,
|
|
67
|
+
move: (clientX: number, clientY: number) => void,
|
|
68
|
+
cancel: () => void,
|
|
69
|
+
release: () => void,
|
|
70
|
+
): () => void {
|
|
71
|
+
const doc = grab.box.ownerDocument;
|
|
72
|
+
let active = false;
|
|
73
|
+
let finished = false;
|
|
74
|
+
let cancelWait: (() => void) | undefined;
|
|
75
|
+
const detach = () => {
|
|
76
|
+
doc.removeEventListener("pointermove", onMove);
|
|
77
|
+
doc.removeEventListener("pointerup", onUp);
|
|
78
|
+
doc.removeEventListener("pointercancel", onCancel);
|
|
79
|
+
doc.removeEventListener("pointerdown", onAnotherPointer);
|
|
80
|
+
doc.removeEventListener("touchmove", onTouchMove);
|
|
81
|
+
doc.removeEventListener("contextmenu", onContextMenu);
|
|
82
|
+
};
|
|
83
|
+
const stop = () => {
|
|
84
|
+
if (finished) return;
|
|
85
|
+
finished = true;
|
|
86
|
+
detach();
|
|
87
|
+
cancelWait?.();
|
|
88
|
+
cancel();
|
|
89
|
+
release();
|
|
90
|
+
};
|
|
91
|
+
const onMove = (event: PointerEvent) => {
|
|
92
|
+
if (active && event.pointerId === grab.pointerId) move(event.clientX, event.clientY);
|
|
93
|
+
};
|
|
94
|
+
const onUp = (event: PointerEvent) => {
|
|
95
|
+
if (event.pointerId !== grab.pointerId) return;
|
|
96
|
+
finished = true;
|
|
97
|
+
detach();
|
|
98
|
+
release();
|
|
99
|
+
// The view's window pointerup handler commits the current range.
|
|
100
|
+
};
|
|
101
|
+
const onCancel = (event: PointerEvent) => {
|
|
102
|
+
if (event.pointerId === grab.pointerId) stop();
|
|
103
|
+
};
|
|
104
|
+
const onAnotherPointer = (event: PointerEvent) => {
|
|
105
|
+
if (event.pointerId !== grab.pointerId) stop();
|
|
106
|
+
};
|
|
107
|
+
const onTouchMove = (event: TouchEvent) => {
|
|
108
|
+
if (active && event.cancelable) event.preventDefault();
|
|
109
|
+
};
|
|
110
|
+
const onContextMenu = (event: Event) => {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
};
|
|
113
|
+
doc.addEventListener("pointermove", onMove);
|
|
114
|
+
doc.addEventListener("pointerup", onUp);
|
|
115
|
+
doc.addEventListener("pointercancel", onCancel);
|
|
116
|
+
doc.addEventListener("pointerdown", onAnotherPointer);
|
|
117
|
+
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
118
|
+
doc.addEventListener("contextmenu", onContextMenu);
|
|
119
|
+
cancelWait = waitForHold(
|
|
120
|
+
grab,
|
|
121
|
+
400,
|
|
122
|
+
8,
|
|
123
|
+
() => {
|
|
124
|
+
active = true;
|
|
125
|
+
start();
|
|
126
|
+
},
|
|
127
|
+
release,
|
|
128
|
+
stop,
|
|
129
|
+
);
|
|
130
|
+
return stop;
|
|
131
|
+
}
|