@super-calendar/solid 0.0.0-stage → 2.16.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/LICENSE +21 -0
- package/README.md +267 -2
- package/dist/client/index.d.ts +1082 -0
- package/dist/client/index.js +6614 -0
- package/dist/server/index.d.ts +1082 -0
- package/dist/server/index.js +8011 -0
- package/package.json +59 -3
- package/src/Agenda.tsx +296 -0
- package/src/Calendar.tsx +574 -0
- package/src/DateRangePicker.tsx +405 -0
- package/src/EventActions.tsx +497 -0
- package/src/MonthList.tsx +233 -0
- package/src/MonthView.tsx +1587 -0
- package/src/ResourceTimeline.tsx +1748 -0
- package/src/TimeGrid.tsx +2833 -0
- package/src/VirtualList.tsx +119 -0
- package/src/YearView.tsx +652 -0
- package/src/createEventSource.ts +76 -0
- package/src/index.ts +106 -0
- package/src/props.ts +24 -0
- package/src/slots.ts +91 -0
- package/src/state.ts +62 -0
- package/src/styles.ts +68 -0
- package/src/theme.ts +44 -0
- package/src/touch.ts +61 -0
package/src/TimeGrid.tsx
ADDED
|
@@ -0,0 +1,2833 @@
|
|
|
1
|
+
import { Dynamic, type JSX } from "@solidjs/web";
|
|
2
|
+
import {
|
|
3
|
+
backgroundBandsForDay,
|
|
4
|
+
type BusinessHours,
|
|
5
|
+
type BusinessHoursBand,
|
|
6
|
+
type CalendarEvent,
|
|
7
|
+
type CalendarHandle,
|
|
8
|
+
type CalendarLabels,
|
|
9
|
+
type CalendarMode,
|
|
10
|
+
type CreateGhostArgs,
|
|
11
|
+
cellRangeFromDrag,
|
|
12
|
+
clampMoveStartMinutes,
|
|
13
|
+
closedHourBands,
|
|
14
|
+
eventAccessibilityLabel as defaultEventAccessibilityLabel,
|
|
15
|
+
type EventAccessibilityLabeler,
|
|
16
|
+
eventChipLayout,
|
|
17
|
+
eventTimeLabel,
|
|
18
|
+
formatHour,
|
|
19
|
+
getIsToday,
|
|
20
|
+
getViewDays,
|
|
21
|
+
isAllDayEvent,
|
|
22
|
+
isBackgroundEvent,
|
|
23
|
+
isSameCalendarDay,
|
|
24
|
+
isWeekend,
|
|
25
|
+
layoutDayEvents,
|
|
26
|
+
movedClockSpan,
|
|
27
|
+
overlapsOtherEvents,
|
|
28
|
+
pageStepDays,
|
|
29
|
+
type PositionedEvent,
|
|
30
|
+
resolveCalendarLabels,
|
|
31
|
+
resolveDraggedBounds,
|
|
32
|
+
shiftMinutes,
|
|
33
|
+
type TimeGridMode,
|
|
34
|
+
titleNumberOfLines,
|
|
35
|
+
type WeekdayFormat,
|
|
36
|
+
weekdayFormatToken,
|
|
37
|
+
type WeekStartsOn,
|
|
38
|
+
} from "@super-calendar/core/vanilla";
|
|
39
|
+
import {
|
|
40
|
+
addDays,
|
|
41
|
+
differenceInCalendarDays,
|
|
42
|
+
format,
|
|
43
|
+
getISOWeek,
|
|
44
|
+
type Locale,
|
|
45
|
+
startOfDay,
|
|
46
|
+
} from "date-fns";
|
|
47
|
+
import {
|
|
48
|
+
type Component,
|
|
49
|
+
createEffect,
|
|
50
|
+
createMemo,
|
|
51
|
+
createSignal,
|
|
52
|
+
For,
|
|
53
|
+
onSettled,
|
|
54
|
+
Show,
|
|
55
|
+
untrack,
|
|
56
|
+
} from "solid-js";
|
|
57
|
+
import {
|
|
58
|
+
createEventActions,
|
|
59
|
+
EventActionsDialog,
|
|
60
|
+
describeEventDates,
|
|
61
|
+
type EventActionsSlot,
|
|
62
|
+
EventActionsMenu,
|
|
63
|
+
type EventEditAction,
|
|
64
|
+
} from "./EventActions";
|
|
65
|
+
import { withDefaults } from "./props";
|
|
66
|
+
import { createSlots, dataState, type ResolvedSlot, type SlotStyleProps } from "./slots";
|
|
67
|
+
import { createNow } from "./state";
|
|
68
|
+
import {
|
|
69
|
+
css,
|
|
70
|
+
type CSSProperties,
|
|
71
|
+
type DomKeyboardEvent,
|
|
72
|
+
type DomMouseEvent,
|
|
73
|
+
type DomPointerEvent,
|
|
74
|
+
type ElementRef,
|
|
75
|
+
} from "./styles";
|
|
76
|
+
import { mergeSolidTheme, type SolidCalendarTheme } from "./theme";
|
|
77
|
+
import { type EventGrab, waitForHold } from "./touch";
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Styleable parts of {@link TimeGrid}. Pass a class or inline style per slot via
|
|
81
|
+
* the `classNames` / `styles` props.
|
|
82
|
+
*/
|
|
83
|
+
export type TimeGridSlot =
|
|
84
|
+
| "header"
|
|
85
|
+
| "weekNumber"
|
|
86
|
+
| "columnHeader"
|
|
87
|
+
| "columnHeaderWeekday"
|
|
88
|
+
| "columnHeaderDate"
|
|
89
|
+
| "allDayLane"
|
|
90
|
+
| "allDayLabel"
|
|
91
|
+
| "allDayColumn"
|
|
92
|
+
| "allDayEvent"
|
|
93
|
+
| "hourGutter"
|
|
94
|
+
| "hourLabel"
|
|
95
|
+
| "dayColumn"
|
|
96
|
+
| "gridLines"
|
|
97
|
+
| "businessHours"
|
|
98
|
+
| "backgroundEvent"
|
|
99
|
+
| "event"
|
|
100
|
+
| "eventBox"
|
|
101
|
+
| "nowIndicator"
|
|
102
|
+
| "createGhost"
|
|
103
|
+
| EventActionsSlot;
|
|
104
|
+
const GUTTER_WIDTH = 56;
|
|
105
|
+
const HOURS_PER_DAY = 24;
|
|
106
|
+
// Floor for a timed event box's height, so a very short event still shows a
|
|
107
|
+
// sliver of its chip. Overridable per grid via `minEventHeight`.
|
|
108
|
+
const DEFAULT_MIN_EVENT_HEIGHT = 14;
|
|
109
|
+
// Horizontal inset of each event box from its column edges. Overridable per grid
|
|
110
|
+
// via `eventGap`.
|
|
111
|
+
const DEFAULT_EVENT_GAP = 1;
|
|
112
|
+
const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
|
|
113
|
+
// Two create-preview ranges cover the same times.
|
|
114
|
+
const sameRange = (a: CreateGhostArgs | null, b: CreateGhostArgs | null) =>
|
|
115
|
+
a === b ||
|
|
116
|
+
(!!a && !!b && a.start.getTime() === b.start.getTime() && a.end.getTime() === b.end.getTime());
|
|
117
|
+
// Floor for the create-by-drag preview, so a press shows a line before it moves.
|
|
118
|
+
const CREATE_PREVIEW_MIN_HEIGHT = 2;
|
|
119
|
+
// Vertical placement of the create preview inside a day column `gridHeight` px
|
|
120
|
+
// tall. Both ends are clamped to the visible hours. The preview is anchored to
|
|
121
|
+
// the nearer column edge, so its minimum height and any custom border
|
|
122
|
+
// grow toward the middle of the grid instead of past its first or last hour.
|
|
123
|
+
function createPreviewPlacement(topPx: number, heightPx: number, gridHeight: number) {
|
|
124
|
+
const start = clamp(topPx, 0, gridHeight);
|
|
125
|
+
const end = clamp(topPx + heightPx, 0, gridHeight);
|
|
126
|
+
const height = Math.min(gridHeight, Math.max(end - start, CREATE_PREVIEW_MIN_HEIGHT));
|
|
127
|
+
const top = Math.min(start, gridHeight - height);
|
|
128
|
+
return top + height / 2 > gridHeight / 2
|
|
129
|
+
? { bottom: gridHeight - top - height, height }
|
|
130
|
+
: { top, height };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Edge auto-advance: how close to the day-columns edge (px) counts as "at the
|
|
134
|
+
// edge", how long to dwell there before paging, and the repeat interval while
|
|
135
|
+
// the pointer stays in the zone.
|
|
136
|
+
const EDGE_ZONE = 32;
|
|
137
|
+
const EDGE_DWELL_MS = 600;
|
|
138
|
+
const EDGE_REPEAT_MS = 600;
|
|
139
|
+
const CELL_TOUCH_SLOP_PX = 8;
|
|
140
|
+
|
|
141
|
+
// Off-screen but readable by assistive tech: gives an element an accessible name
|
|
142
|
+
// without changing the visible layout.
|
|
143
|
+
const VISUALLY_HIDDEN: CSSProperties = {
|
|
144
|
+
position: "absolute",
|
|
145
|
+
width: 1,
|
|
146
|
+
height: 1,
|
|
147
|
+
padding: 0,
|
|
148
|
+
margin: -1,
|
|
149
|
+
overflow: "hidden",
|
|
150
|
+
clip: "rect(0 0 0 0)",
|
|
151
|
+
clipPath: "inset(50%)",
|
|
152
|
+
whiteSpace: "nowrap",
|
|
153
|
+
border: 0,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Props passed to a custom time-grid event renderer. */
|
|
157
|
+
export interface SolidRenderEventArgs<T = unknown> {
|
|
158
|
+
/** The event to render. */
|
|
159
|
+
event: CalendarEvent<T>;
|
|
160
|
+
/** The current view mode. */
|
|
161
|
+
mode: CalendarMode;
|
|
162
|
+
/** Whether the event is all-day. */
|
|
163
|
+
isAllDay: boolean;
|
|
164
|
+
/** Pixel height of the event box (timed events only). */
|
|
165
|
+
boxHeight?: number;
|
|
166
|
+
/** The event started before the visible day and continues into it. */
|
|
167
|
+
continuesBefore?: boolean;
|
|
168
|
+
/** The event continues past the visible day. */
|
|
169
|
+
continuesAfter?: boolean;
|
|
170
|
+
/** Show the time range in 12-hour AM/PM. */
|
|
171
|
+
ampm?: boolean;
|
|
172
|
+
/** Call to fire the view's `onPressEvent` for this event. */
|
|
173
|
+
onPress: () => void;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A component that renders a single time-grid event box. */
|
|
177
|
+
export type SolidRenderEvent<T = unknown> = Component<SolidRenderEventArgs<T>>;
|
|
178
|
+
|
|
179
|
+
/** Props for {@link TimeGrid}. */
|
|
180
|
+
export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot> {
|
|
181
|
+
/** Anchor date; the visible columns are derived from it and `mode`. */
|
|
182
|
+
date: Date;
|
|
183
|
+
/** Events to lay out on the grid. */
|
|
184
|
+
events?: CalendarEvent<T>[];
|
|
185
|
+
/** "day" (default), "3days", "week", or "custom" (with `numberOfDays`). */
|
|
186
|
+
mode?: TimeGridMode;
|
|
187
|
+
/** Column count for `mode="custom"`. */
|
|
188
|
+
numberOfDays?: number;
|
|
189
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
190
|
+
weekStartsOn?: WeekStartsOn;
|
|
191
|
+
/** Column-header weekday label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
192
|
+
weekdayFormat?: WeekdayFormat;
|
|
193
|
+
/** Initial pixels per hour (default 48). */
|
|
194
|
+
hourHeight?: number;
|
|
195
|
+
/** Vertical scroll, in minutes from midnight (default 8:00). Applied on mount and whenever it changes. */
|
|
196
|
+
scrollOffsetMinutes?: number;
|
|
197
|
+
/** Pinch / Ctrl-⌘-scroll to zoom the grid (default true). */
|
|
198
|
+
zoomable?: boolean;
|
|
199
|
+
/** Lower bound for pixels per hour when zooming. */
|
|
200
|
+
minHourHeight?: number;
|
|
201
|
+
/** Upper bound for pixels per hour when zooming. */
|
|
202
|
+
maxHourHeight?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Minimum pixel height of a timed event box, so short events stay legible and
|
|
205
|
+
* clickable. Also the floor of the `boxHeight` handed to `renderEvent`. Default
|
|
206
|
+
* 14; pass 0 to size every box strictly by its duration.
|
|
207
|
+
*/
|
|
208
|
+
minEventHeight?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Inset in pixels between a timed event box and its column edges (each side).
|
|
211
|
+
* Default 1; pass 0 to let events fill their column.
|
|
212
|
+
*/
|
|
213
|
+
eventGap?: number;
|
|
214
|
+
/** Snap dragged events to this many minutes (default 15). */
|
|
215
|
+
dragStepMinutes?: number;
|
|
216
|
+
/** Hold duration before a DOM touch or pen drag, in ms (default 300). */
|
|
217
|
+
touchDragDelay?: number;
|
|
218
|
+
/** Movement tolerance for a DOM touch or pen hold, in px (default 8). */
|
|
219
|
+
touchDragThreshold?: number;
|
|
220
|
+
/** Render event time ranges in 12-hour AM/PM (default false, 24h). */
|
|
221
|
+
ampm?: boolean;
|
|
222
|
+
/** Sub-divisions per hour for the grid lines, e.g. 2 for half-hour (default 1). */
|
|
223
|
+
timeslots?: number;
|
|
224
|
+
/** First hour shown (0–23). Default 0. */
|
|
225
|
+
minHour?: number;
|
|
226
|
+
/** Last hour shown, exclusive (1–24). Default 24. */
|
|
227
|
+
maxHour?: number;
|
|
228
|
+
/** Hide the left hour-axis column (lines stay, labels/gutter go). Default false. */
|
|
229
|
+
hideHours?: boolean;
|
|
230
|
+
/** Show the ISO week number in the header gutter. Default false. */
|
|
231
|
+
showWeekNumber?: boolean;
|
|
232
|
+
/** Prefix for the week number, e.g. "W" → "W28". Default "W". */
|
|
233
|
+
weekNumberPrefix?: string;
|
|
234
|
+
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
235
|
+
hiddenDays?: number[];
|
|
236
|
+
/** Shade the hours outside business hours; `null` shades the whole day. */
|
|
237
|
+
businessHours?: BusinessHours;
|
|
238
|
+
/**
|
|
239
|
+
* Render a closed-hours band's content yourself (a label, icon, pattern).
|
|
240
|
+
* The grid keeps positioning the band; when set, the themed tint is dropped
|
|
241
|
+
* and your output fills the band instead. Decorative only: the
|
|
242
|
+
* band stays non-interactive and hidden from assistive tech.
|
|
243
|
+
*/
|
|
244
|
+
renderBusinessHours?: (band: BusinessHoursBand) => JSX.Element;
|
|
245
|
+
/**
|
|
246
|
+
* A component that draws a `display: "background"` event's band in place of
|
|
247
|
+
* the themed shade. Rendered like `renderEvent`, it receives the event, the
|
|
248
|
+
* mode, `continuesBefore` / `continuesAfter` for a multi-day event, and
|
|
249
|
+
* `onPress`, which fires `onPressEvent`. The band then takes pointer events and
|
|
250
|
+
* is no longer hidden from assistive tech; cell clicks and drag-to-create are
|
|
251
|
+
* unreachable underneath it. Without it the band stays a shaded, inert range.
|
|
252
|
+
*/
|
|
253
|
+
renderBackgroundEvent?: SolidRenderEvent<T>;
|
|
254
|
+
/** Show the current-time indicator on today's column (default true). */
|
|
255
|
+
showNowIndicator?: boolean;
|
|
256
|
+
/** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
|
|
257
|
+
now?: Date;
|
|
258
|
+
/** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
|
|
259
|
+
timeZone?: string;
|
|
260
|
+
/** Show the all-day lane above the grid (default true). */
|
|
261
|
+
showAllDayEventCell?: boolean;
|
|
262
|
+
/** Show the "all-day" text beside the lane (default false). */
|
|
263
|
+
showAllDayLabel?: boolean;
|
|
264
|
+
/** Translations for the screen-reader words and gutter text; omitted keys use English. */
|
|
265
|
+
labels?: Partial<CalendarLabels>;
|
|
266
|
+
/** Tint Saturday/Sunday columns with the weekend background (default true). Set
|
|
267
|
+
* false to treat weekends like any other day. */
|
|
268
|
+
highlightWeekends?: boolean;
|
|
269
|
+
/** Allow moving events by default (per-event `startEditable` overrides). Default true. */
|
|
270
|
+
eventStartEditable?: boolean;
|
|
271
|
+
/** Allow resizing events by default (per-event `durationEditable` overrides). Default true. */
|
|
272
|
+
eventDurationEditable?: boolean;
|
|
273
|
+
/** Allow a dragged/resized event to overlap another (default true). Set false to
|
|
274
|
+
* reject a drop that would collide, snapping the event back. */
|
|
275
|
+
eventOverlap?: boolean;
|
|
276
|
+
/** date-fns locale for the column headers and time labels. */
|
|
277
|
+
locale?: Locale;
|
|
278
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
279
|
+
theme?: Partial<SolidCalendarTheme>;
|
|
280
|
+
/** Height of the scroll viewport, in px. */
|
|
281
|
+
height?: number | string;
|
|
282
|
+
/** Custom event renderer; falls back to the built-in event box. */
|
|
283
|
+
renderEvent?: SolidRenderEvent<T>;
|
|
284
|
+
/**
|
|
285
|
+
* Override the screen-reader label for each event. Receives the event and a
|
|
286
|
+
* `{ mode, isAllDay, ampm }` context; return the full text to announce. Defaults
|
|
287
|
+
* to the title plus the time range (or "all day"), which the grid otherwise only
|
|
288
|
+
* conveys visually.
|
|
289
|
+
*/
|
|
290
|
+
eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
|
|
291
|
+
/** Replace the hour-axis label. Receives the hour (0-23) and the `ampm` flag. */
|
|
292
|
+
hourComponent?: (hour: number, ampm: boolean) => JSX.Element;
|
|
293
|
+
/**
|
|
294
|
+
* Add arrow-key navigation between events. Up/Down move between a day's events by
|
|
295
|
+
* time, Left/Right jump to the nearest event in the adjacent day, Home/End go to
|
|
296
|
+
* the day's first/last event; Enter/Space activate. Additive: every event stays
|
|
297
|
+
* individually tabbable (so screen-reader users keep full access), so this is a
|
|
298
|
+
* convenience for sighted keyboard users. Default false.
|
|
299
|
+
*/
|
|
300
|
+
keyboardEventNavigation?: boolean;
|
|
301
|
+
/** Tap an event. */
|
|
302
|
+
onPressEvent?: (event: CalendarEvent<T>) => void;
|
|
303
|
+
/** Tap a day's column header. */
|
|
304
|
+
onPressDateHeader?: (day: Date) => void;
|
|
305
|
+
/** Tap empty grid space; called with the date and time at the press. */
|
|
306
|
+
onPressCell?: (date: Date) => void;
|
|
307
|
+
/** Drag empty grid space to create; called with the swept start/end. */
|
|
308
|
+
onCreateEvent?: (start: Date, end: Date) => void;
|
|
309
|
+
/**
|
|
310
|
+
* A component that draws content inside the drag-to-create preview, such as a
|
|
311
|
+
* draft title and the live time range. It receives the snapped `start` and
|
|
312
|
+
* `end` that `onCreateEvent` would get if the pointer were released now, and
|
|
313
|
+
* its props update as the sweep changes them. The grid keeps positioning,
|
|
314
|
+
* sizing and styling the preview and clips the content to it; the content is
|
|
315
|
+
* non-interactive and hidden from assistive tech. Renders only while a sweep
|
|
316
|
+
* can create, so it needs `onCreateEvent` and does not enable creation itself.
|
|
317
|
+
*/
|
|
318
|
+
renderCreateGhost?: Component<CreateGhostArgs>;
|
|
319
|
+
/** Fires when an event drag begins (e.g. to trigger haptics). */
|
|
320
|
+
onDragStart?: (event: CalendarEvent<T>) => void;
|
|
321
|
+
/**
|
|
322
|
+
* Enables drag-to-move and resize; called with the proposed new start/end.
|
|
323
|
+
* Return `false` to reject the drop (the event snaps back).
|
|
324
|
+
*/
|
|
325
|
+
onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
|
|
326
|
+
/** Stable, unique event identity for the web editing dialog across data refreshes. */
|
|
327
|
+
getEventId?: (event: CalendarEvent<T>) => string | number;
|
|
328
|
+
/**
|
|
329
|
+
* Page the grid to a new anchor date. Supplying it alongside `onDragEvent`
|
|
330
|
+
* turns on edge auto-advance: dragging an event to the left/right edge and
|
|
331
|
+
* dwelling briefly pages the view so the event can be dropped on a day in the
|
|
332
|
+
* previous/next period. Controlled, like the native renderer's `onChangeDate`.
|
|
333
|
+
*/
|
|
334
|
+
onChangeDate?: (date: Date) => void;
|
|
335
|
+
/** Class applied to the root element. */
|
|
336
|
+
className?: string;
|
|
337
|
+
/** Inline styles applied to the root element. */
|
|
338
|
+
style?: CSSProperties;
|
|
339
|
+
}
|
|
340
|
+
type DragState = {
|
|
341
|
+
key: string;
|
|
342
|
+
// "resize" drags the bottom edge (changes the end); "resize-start" drags the
|
|
343
|
+
// top edge (changes the start, end fixed).
|
|
344
|
+
kind: "move" | "resize" | "resize-start";
|
|
345
|
+
startHours: number;
|
|
346
|
+
// The row a move asked for. `startHours` is where it lands, an hour later when
|
|
347
|
+
// that row is in the hour a spring-forward change skips; the commit re-resolves
|
|
348
|
+
// the request against the day it drops on.
|
|
349
|
+
requestedStartHours: number;
|
|
350
|
+
durationHours: number;
|
|
351
|
+
/** Whole day columns the box has been dragged across, clamped to the view. */
|
|
352
|
+
dayDelta: number;
|
|
353
|
+
/** Pixel equivalent of dayDelta, applied as a transform on the dragged box. */
|
|
354
|
+
dayOffsetPx: number;
|
|
355
|
+
/** Whether the dragged segment carries on from the previous day / into the next. */
|
|
356
|
+
continuesBefore: boolean;
|
|
357
|
+
continuesAfter: boolean;
|
|
358
|
+
/** Hours of a move that run past the end of the day, previewed in the next column. */
|
|
359
|
+
spillHours: number;
|
|
360
|
+
/** Column that previews the spill, or -1 when there is none to show. */
|
|
361
|
+
spillDayIndex: number;
|
|
362
|
+
moved: boolean;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// Chip line metrics, matched to the box font below so the title clamp lands on a
|
|
366
|
+
// line boundary. 16px matches the native renderer's `eventTitle` line height, so
|
|
367
|
+
// the "does the time line still fit" decision flips at the same box height on
|
|
368
|
+
// both. The time reserves two lines (it can wrap on a narrow column).
|
|
369
|
+
const DOM_TITLE_LINE_HEIGHT = 16;
|
|
370
|
+
const DOM_TIME_LINE_HEIGHT = 30;
|
|
371
|
+
const DOM_BOX_PADDING_V = 2;
|
|
372
|
+
|
|
373
|
+
// Where a dragged segment's start lands: shifted on the clock by as many minutes
|
|
374
|
+
// as its row moved, plus whole days to `base`, from the instant it started at.
|
|
375
|
+
// Shifting the real instant rather than rebuilding it from rows keeps a start in
|
|
376
|
+
// the hour a fall-back change repeats on its own occurrence.
|
|
377
|
+
function movedSegmentStart(
|
|
378
|
+
origin: {
|
|
379
|
+
startHours: number;
|
|
380
|
+
segmentStart: Date;
|
|
381
|
+
base: Date;
|
|
382
|
+
},
|
|
383
|
+
base: Date,
|
|
384
|
+
startHours: number,
|
|
385
|
+
): Date {
|
|
386
|
+
const dayMinutes = differenceInCalendarDays(base, origin.base) * HOURS_PER_DAY * 60;
|
|
387
|
+
return shiftMinutes(
|
|
388
|
+
origin.segmentStart,
|
|
389
|
+
dayMinutes + Math.round((startHours - origin.startHours) * 60),
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
function DefaultDomEvent<T>(
|
|
393
|
+
incoming: SolidRenderEventArgs<T> & {
|
|
394
|
+
theme: SolidCalendarTheme;
|
|
395
|
+
boxProps?: ResolvedSlot;
|
|
396
|
+
},
|
|
397
|
+
) {
|
|
398
|
+
const props = withDefaults(
|
|
399
|
+
{
|
|
400
|
+
ampm: false,
|
|
401
|
+
} satisfies Partial<
|
|
402
|
+
SolidRenderEventArgs<T> & {
|
|
403
|
+
theme: SolidCalendarTheme;
|
|
404
|
+
boxProps?: ResolvedSlot;
|
|
405
|
+
}
|
|
406
|
+
>,
|
|
407
|
+
incoming,
|
|
408
|
+
);
|
|
409
|
+
const timeLabel = createMemo(() =>
|
|
410
|
+
eventTimeLabel({
|
|
411
|
+
mode: props.mode,
|
|
412
|
+
isAllDay: props.isAllDay,
|
|
413
|
+
start: props.event.start,
|
|
414
|
+
end: props.event.end,
|
|
415
|
+
ampm: props.ampm,
|
|
416
|
+
showTime: true,
|
|
417
|
+
}),
|
|
418
|
+
);
|
|
419
|
+
// The title fills the box in whole lines; the time is secondary and only shows
|
|
420
|
+
// once a full line is free beneath it. Mirrors the RN renderer via the same
|
|
421
|
+
// core helper, so a 30-minute slot shows just its title instead of clipping
|
|
422
|
+
// both lines, and the title never ends on a half-cut line.
|
|
423
|
+
const layout = createMemo(() =>
|
|
424
|
+
eventChipLayout({
|
|
425
|
+
boxHeightPx: props.boxHeight,
|
|
426
|
+
mode: props.mode,
|
|
427
|
+
hasTime: !props.isAllDay && timeLabel() != null,
|
|
428
|
+
titleLineHeightPx: DOM_TITLE_LINE_HEIGHT,
|
|
429
|
+
timeLineHeightPx: DOM_TIME_LINE_HEIGHT,
|
|
430
|
+
paddingYPx: DOM_BOX_PADDING_V,
|
|
431
|
+
}),
|
|
432
|
+
);
|
|
433
|
+
const oneLine = createMemo(() => titleNumberOfLines(props.mode, props.isAllDay) === 1);
|
|
434
|
+
// A chip reduced to a single title line (no time) centers it vertically, so a
|
|
435
|
+
// very short event reads balanced instead of hugging the top edge.
|
|
436
|
+
const centerLoneTitle = createMemo(() => layout().titleMaxLines === 1 && !layout().showTime);
|
|
437
|
+
// Structural box metrics always apply; the card's look (colour, radius, type)
|
|
438
|
+
// is themed and yields to a `eventBox` class when one is supplied.
|
|
439
|
+
const boxBase = createMemo<CSSProperties>(() => ({
|
|
440
|
+
height: "100%",
|
|
441
|
+
boxSizing: "border-box",
|
|
442
|
+
overflow: "hidden",
|
|
443
|
+
lineHeight: `${DOM_TITLE_LINE_HEIGHT}px`,
|
|
444
|
+
...(centerLoneTitle()
|
|
445
|
+
? {
|
|
446
|
+
display: "flex",
|
|
447
|
+
flexDirection: "column",
|
|
448
|
+
justifyContent: "center",
|
|
449
|
+
}
|
|
450
|
+
: null),
|
|
451
|
+
}));
|
|
452
|
+
const boxThemed = createMemo<CSSProperties>(() => ({
|
|
453
|
+
padding: `${DOM_BOX_PADDING_V}px 6px`,
|
|
454
|
+
borderRadius: 6,
|
|
455
|
+
background: props.theme.eventBackground,
|
|
456
|
+
color: props.theme.eventText,
|
|
457
|
+
fontSize: 12,
|
|
458
|
+
}));
|
|
459
|
+
return (
|
|
460
|
+
<div
|
|
461
|
+
class={props.boxProps?.class}
|
|
462
|
+
data-slot={props.boxProps?.["data-slot"]}
|
|
463
|
+
style={css(
|
|
464
|
+
props.boxProps?.class
|
|
465
|
+
? {
|
|
466
|
+
...boxBase(),
|
|
467
|
+
...props.boxProps.style,
|
|
468
|
+
}
|
|
469
|
+
: {
|
|
470
|
+
...boxBase(),
|
|
471
|
+
...boxThemed(),
|
|
472
|
+
...props.boxProps?.style,
|
|
473
|
+
},
|
|
474
|
+
)}
|
|
475
|
+
>
|
|
476
|
+
<div
|
|
477
|
+
style={css({
|
|
478
|
+
fontWeight: 600,
|
|
479
|
+
overflow: "hidden",
|
|
480
|
+
// Clip on a line boundary with no ellipsis. The all-day lane is a single
|
|
481
|
+
// line; timed events wrap to as many whole lines as the box allows.
|
|
482
|
+
...(oneLine()
|
|
483
|
+
? {
|
|
484
|
+
whiteSpace: "nowrap",
|
|
485
|
+
}
|
|
486
|
+
: {
|
|
487
|
+
wordBreak: "break-word",
|
|
488
|
+
...(layout().titleMaxLines > 0
|
|
489
|
+
? {
|
|
490
|
+
maxHeight: layout().titleMaxLines * DOM_TITLE_LINE_HEIGHT,
|
|
491
|
+
}
|
|
492
|
+
: null),
|
|
493
|
+
}),
|
|
494
|
+
})}
|
|
495
|
+
>
|
|
496
|
+
{props.event.title}
|
|
497
|
+
</div>
|
|
498
|
+
{layout().showTime ? (
|
|
499
|
+
<div
|
|
500
|
+
style={css({
|
|
501
|
+
opacity: 0.75,
|
|
502
|
+
overflow: "hidden",
|
|
503
|
+
maxHeight: DOM_TIME_LINE_HEIGHT,
|
|
504
|
+
})}
|
|
505
|
+
>
|
|
506
|
+
{timeLabel()}
|
|
507
|
+
</div>
|
|
508
|
+
) : null}
|
|
509
|
+
</div>
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// A `Date` that advances every minute while `enabled`, so the now-indicator
|
|
514
|
+
// tracks the wall clock instead of freezing at the last render. Mirrors the
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* A day / week / N-day time grid rendered with plain DOM elements. Events are
|
|
518
|
+
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
519
|
+
* multi-day clipping match the React Native renderer. Supports Ctrl/⌘-scroll and
|
|
520
|
+
* two-finger pinch to zoom, and pointer drag to move / resize events.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```tsx
|
|
524
|
+
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
|
|
528
|
+
export function TimeGrid<T = unknown>(
|
|
529
|
+
incoming: TimeGridProps<T> & {
|
|
530
|
+
ref?: (handle: CalendarHandle) => void;
|
|
531
|
+
},
|
|
532
|
+
): JSX.Element {
|
|
533
|
+
const props = withDefaults(
|
|
534
|
+
{
|
|
535
|
+
events: new Array<CalendarEvent<T>>(),
|
|
536
|
+
mode: "day",
|
|
537
|
+
numberOfDays: 1,
|
|
538
|
+
weekStartsOn: 0,
|
|
539
|
+
weekdayFormat: "short",
|
|
540
|
+
hourHeight: 48,
|
|
541
|
+
scrollOffsetMinutes: 8 * 60,
|
|
542
|
+
zoomable: true,
|
|
543
|
+
minHourHeight: 24,
|
|
544
|
+
maxHourHeight: 160,
|
|
545
|
+
minEventHeight: DEFAULT_MIN_EVENT_HEIGHT,
|
|
546
|
+
eventGap: DEFAULT_EVENT_GAP,
|
|
547
|
+
dragStepMinutes: 15,
|
|
548
|
+
touchDragDelay: 300,
|
|
549
|
+
touchDragThreshold: 8,
|
|
550
|
+
ampm: false,
|
|
551
|
+
timeslots: 1,
|
|
552
|
+
minHour: 0,
|
|
553
|
+
maxHour: 24,
|
|
554
|
+
hideHours: false,
|
|
555
|
+
showWeekNumber: false,
|
|
556
|
+
weekNumberPrefix: "W",
|
|
557
|
+
keyboardEventNavigation: false,
|
|
558
|
+
showNowIndicator: true,
|
|
559
|
+
highlightWeekends: true,
|
|
560
|
+
eventStartEditable: true,
|
|
561
|
+
eventDurationEditable: true,
|
|
562
|
+
eventOverlap: true,
|
|
563
|
+
showAllDayEventCell: true,
|
|
564
|
+
showAllDayLabel: false,
|
|
565
|
+
height: 600,
|
|
566
|
+
} satisfies Partial<
|
|
567
|
+
TimeGridProps<T> & {
|
|
568
|
+
ref?: (handle: CalendarHandle) => void;
|
|
569
|
+
}
|
|
570
|
+
>,
|
|
571
|
+
incoming,
|
|
572
|
+
);
|
|
573
|
+
const theme = createMemo(() => mergeSolidTheme(props.theme));
|
|
574
|
+
const labels = createMemo(() => resolveCalendarLabels(props.labels));
|
|
575
|
+
const slot = createSlots<TimeGridSlot>(props);
|
|
576
|
+
const scrollRef: ElementRef<HTMLDivElement | null> = {
|
|
577
|
+
current: null,
|
|
578
|
+
};
|
|
579
|
+
const dfns = createMemo(() =>
|
|
580
|
+
props.locale
|
|
581
|
+
? {
|
|
582
|
+
locale: props.locale,
|
|
583
|
+
}
|
|
584
|
+
: undefined,
|
|
585
|
+
);
|
|
586
|
+
// Clamped like the native renderer: a zero or negative step would divide by zero
|
|
587
|
+
// in the snap below and put NaN through every drag commit.
|
|
588
|
+
const snapMinutes = createMemo(() => Math.max(1, props.dragStepMinutes));
|
|
589
|
+
const snapHours = createMemo(() => snapMinutes() / 60);
|
|
590
|
+
|
|
591
|
+
// The visible hour window [windowStart, windowEnd). Clamped the same way as the
|
|
592
|
+
// native renderer so out-of-range props can't invert or overflow the day.
|
|
593
|
+
const windowStart = createMemo(() => Math.max(0, Math.min(props.minHour, 23)));
|
|
594
|
+
const windowEnd = createMemo(() => Math.max(windowStart() + 1, Math.min(props.maxHour, 24)));
|
|
595
|
+
const windowHours = createMemo(() => windowEnd() - windowStart());
|
|
596
|
+
const gutterWidth = createMemo(() => (props.hideHours ? 0 : GUTTER_WIDTH));
|
|
597
|
+
const RenderBackground = createMemo(() => props.renderBackgroundEvent);
|
|
598
|
+
const visibleHours = createMemo(() =>
|
|
599
|
+
Array.from(
|
|
600
|
+
{
|
|
601
|
+
length: windowHours(),
|
|
602
|
+
},
|
|
603
|
+
(_, i) => windowStart() + i,
|
|
604
|
+
),
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
// Ticks every minute so the red now-line follows the wall clock; a `now`
|
|
608
|
+
// override pins it, and `timeZone` shifts it to match zone-shifted events.
|
|
609
|
+
const now = createNow(() => ({
|
|
610
|
+
enabled: props.showNowIndicator,
|
|
611
|
+
now: props.now,
|
|
612
|
+
timeZone: props.timeZone,
|
|
613
|
+
}));
|
|
614
|
+
const [hourHeight, setHourHeight] = createSignal(untrack(() => props.hourHeight));
|
|
615
|
+
createEffect(
|
|
616
|
+
() => [props.hourHeight],
|
|
617
|
+
() =>
|
|
618
|
+
untrack(() => {
|
|
619
|
+
setHourHeight(props.hourHeight);
|
|
620
|
+
}),
|
|
621
|
+
);
|
|
622
|
+
const hourHeightRef = {
|
|
623
|
+
current: untrack(() => hourHeight()),
|
|
624
|
+
};
|
|
625
|
+
createEffect(
|
|
626
|
+
() => hourHeight(),
|
|
627
|
+
(value) => {
|
|
628
|
+
hourHeightRef.current = value;
|
|
629
|
+
},
|
|
630
|
+
); // `drag` drives the visual; `dragRef` is the source of truth the pointer
|
|
631
|
+
// handlers read, so they never see a stale state closure between events.
|
|
632
|
+
const [drag, setDrag] = createSignal<DragState | null>(null);
|
|
633
|
+
const dragRef: ElementRef<DragState | null> = {
|
|
634
|
+
current: null,
|
|
635
|
+
};
|
|
636
|
+
const dragOrigin: ElementRef<{
|
|
637
|
+
pointerX: number;
|
|
638
|
+
pointerY: number;
|
|
639
|
+
pointerType: string;
|
|
640
|
+
startHours: number;
|
|
641
|
+
durationHours: number;
|
|
642
|
+
dayIndex: number;
|
|
643
|
+
dayWidth: number;
|
|
644
|
+
// The dragged *segment*'s bounds when the gesture began. A multi-day event is
|
|
645
|
+
// laid out as one segment per day, so the commit shifts the real event by how
|
|
646
|
+
// far its segment moved rather than rebuilding the event from the segment
|
|
647
|
+
// (which would truncate everything outside the dragged day).
|
|
648
|
+
segmentStart: Date;
|
|
649
|
+
segmentEnd: Date;
|
|
650
|
+
// Midnight of the day the segment was grabbed on.
|
|
651
|
+
base: Date;
|
|
652
|
+
} | null> = {
|
|
653
|
+
current: null,
|
|
654
|
+
};
|
|
655
|
+
const applyDrag = (next: DragState | null) => {
|
|
656
|
+
dragRef.current = next;
|
|
657
|
+
setDrag(next);
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
// Create-by-drag / tap on empty grid space. Mouse and pen sweep out a new
|
|
661
|
+
// event; on touch the column scrolls instead, so a tap still hits onPressCell.
|
|
662
|
+
// `startPx` stays unsorted: the live range passes it to `cellRangeFromDrag` as
|
|
663
|
+
// the sweep's origin, exactly as the commit does.
|
|
664
|
+
const [createBox, setCreateBox] = createSignal<{
|
|
665
|
+
dayIndex: number;
|
|
666
|
+
dayTime: number;
|
|
667
|
+
startPx: number;
|
|
668
|
+
curPx: number;
|
|
669
|
+
} | null>(null);
|
|
670
|
+
const createOrigin: ElementRef<{
|
|
671
|
+
pointerId: number;
|
|
672
|
+
clientY: number;
|
|
673
|
+
el: HTMLElement;
|
|
674
|
+
dayIndex: number;
|
|
675
|
+
dayTime: number;
|
|
676
|
+
creating: boolean;
|
|
677
|
+
startPx: number;
|
|
678
|
+
} | null> = {
|
|
679
|
+
current: null,
|
|
680
|
+
};
|
|
681
|
+
createEffect(
|
|
682
|
+
() => createBox() !== null,
|
|
683
|
+
(active) => {
|
|
684
|
+
if (!active) return;
|
|
685
|
+
// Scrolling a column or an ancestor moves it beneath the held pointer.
|
|
686
|
+
const onScroll = () => {
|
|
687
|
+
const origin = createOrigin.current;
|
|
688
|
+
if (!origin) return;
|
|
689
|
+
const curPx = origin.clientY - origin.el.getBoundingClientRect().top;
|
|
690
|
+
setCreateBox((current) =>
|
|
691
|
+
current && current.curPx !== curPx ? { ...current, curPx } : current,
|
|
692
|
+
);
|
|
693
|
+
};
|
|
694
|
+
window.addEventListener("scroll", onScroll, true);
|
|
695
|
+
return () => window.removeEventListener("scroll", onScroll, true);
|
|
696
|
+
},
|
|
697
|
+
);
|
|
698
|
+
// Touch never sweeps, so a tap presses the cell from its click, which the
|
|
699
|
+
// browser skips when the finger scrolled the grid instead.
|
|
700
|
+
const cellTouchRef: ElementRef<{
|
|
701
|
+
pointerId: number;
|
|
702
|
+
x: number;
|
|
703
|
+
y: number;
|
|
704
|
+
} | null> = {
|
|
705
|
+
current: null,
|
|
706
|
+
};
|
|
707
|
+
const cellEnabled = createMemo(() => !!props.onPressCell || !!props.onCreateEvent);
|
|
708
|
+
const days = createMemo(() =>
|
|
709
|
+
getViewDays(
|
|
710
|
+
props.mode,
|
|
711
|
+
props.date,
|
|
712
|
+
props.weekStartsOn,
|
|
713
|
+
props.numberOfDays,
|
|
714
|
+
false,
|
|
715
|
+
undefined,
|
|
716
|
+
props.hiddenDays,
|
|
717
|
+
),
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
// Edge auto-advance. During a move drag the pointer stream is handled at the
|
|
721
|
+
// document level (attached in beginDrag) so it survives the day columns
|
|
722
|
+
// unmounting when a page change swaps `date`. The listeners read these live
|
|
723
|
+
// refs rather than a stale render closure; `daysRef`/`pageDepsRef` update every
|
|
724
|
+
// render so the drop and the next page use the current view.
|
|
725
|
+
const edgeAdvanceEnabled = createMemo(() => !!props.onChangeDate && !!props.onDragEvent);
|
|
726
|
+
const columnsRef: ElementRef<HTMLDivElement | null> = {
|
|
727
|
+
current: null,
|
|
728
|
+
};
|
|
729
|
+
const edgeTimer: ElementRef<ReturnType<typeof setTimeout> | null> = {
|
|
730
|
+
current: null,
|
|
731
|
+
};
|
|
732
|
+
const edgeSide: ElementRef<-1 | 0 | 1> = {
|
|
733
|
+
current: 0,
|
|
734
|
+
};
|
|
735
|
+
const ptr = {
|
|
736
|
+
current: untrack(() => ({
|
|
737
|
+
x: 0,
|
|
738
|
+
y: 0,
|
|
739
|
+
})),
|
|
740
|
+
};
|
|
741
|
+
const pagedRef = {
|
|
742
|
+
current: false,
|
|
743
|
+
};
|
|
744
|
+
const [paged, setPaged] = createSignal(false);
|
|
745
|
+
const draggedRef: ElementRef<{
|
|
746
|
+
event: CalendarEvent<T>;
|
|
747
|
+
onPress: () => void;
|
|
748
|
+
grabX: number;
|
|
749
|
+
grabY: number;
|
|
750
|
+
w: number;
|
|
751
|
+
h: number;
|
|
752
|
+
} | null> = {
|
|
753
|
+
current: null,
|
|
754
|
+
};
|
|
755
|
+
const ghostRef: ElementRef<HTMLDivElement | null> = {
|
|
756
|
+
current: null,
|
|
757
|
+
};
|
|
758
|
+
// A held touch or pen drag stops touchmove from scrolling the grid.
|
|
759
|
+
const touchDragRef = {
|
|
760
|
+
current: false,
|
|
761
|
+
};
|
|
762
|
+
const activeGrabRef: ElementRef<EventGrab | null> = {
|
|
763
|
+
current: null,
|
|
764
|
+
};
|
|
765
|
+
// Cancels a touch or pen press that has not become a drag yet.
|
|
766
|
+
const cancelHoldRef: ElementRef<(() => void) | null> = {
|
|
767
|
+
current: null,
|
|
768
|
+
};
|
|
769
|
+
// A touch or pen tap ended on an event; its click presses the event.
|
|
770
|
+
const tappedRef: ElementRef<HTMLElement | null> = {
|
|
771
|
+
current: null,
|
|
772
|
+
};
|
|
773
|
+
const docHandlersRef: ElementRef<{
|
|
774
|
+
move: (e: PointerEvent) => void;
|
|
775
|
+
up: (e: PointerEvent) => void;
|
|
776
|
+
cancel: (e: PointerEvent) => void;
|
|
777
|
+
} | null> = {
|
|
778
|
+
current: null,
|
|
779
|
+
};
|
|
780
|
+
const daysRef = {
|
|
781
|
+
current: untrack(() => days()),
|
|
782
|
+
};
|
|
783
|
+
createEffect(
|
|
784
|
+
() => days(),
|
|
785
|
+
(value) => {
|
|
786
|
+
daysRef.current = value;
|
|
787
|
+
},
|
|
788
|
+
);
|
|
789
|
+
const pageDepsRef = {
|
|
790
|
+
current: untrack(() => ({
|
|
791
|
+
date: props.date,
|
|
792
|
+
mode: props.mode,
|
|
793
|
+
weekStartsOn: props.weekStartsOn,
|
|
794
|
+
numberOfDays: props.numberOfDays,
|
|
795
|
+
})),
|
|
796
|
+
};
|
|
797
|
+
createEffect(
|
|
798
|
+
() => ({
|
|
799
|
+
date: props.date,
|
|
800
|
+
mode: props.mode,
|
|
801
|
+
weekStartsOn: props.weekStartsOn,
|
|
802
|
+
numberOfDays: props.numberOfDays,
|
|
803
|
+
}),
|
|
804
|
+
(value) => {
|
|
805
|
+
pageDepsRef.current = value;
|
|
806
|
+
},
|
|
807
|
+
);
|
|
808
|
+
const onChangeDateRef = {
|
|
809
|
+
current: untrack(() => props.onChangeDate),
|
|
810
|
+
};
|
|
811
|
+
createEffect(
|
|
812
|
+
() => props.onChangeDate,
|
|
813
|
+
(value) => {
|
|
814
|
+
onChangeDateRef.current = value;
|
|
815
|
+
},
|
|
816
|
+
); // Wrap the handler so a drop that would overlap another event is rejected when
|
|
817
|
+
// `eventOverlap` is false, without the consumer wiring it in `onDragEvent`.
|
|
818
|
+
const onDragEventRef = {
|
|
819
|
+
current: untrack(() => props.onDragEvent),
|
|
820
|
+
};
|
|
821
|
+
createEffect(
|
|
822
|
+
() =>
|
|
823
|
+
props.onDragEvent && props.eventOverlap === false
|
|
824
|
+
? (event, start, end) =>
|
|
825
|
+
overlapsOtherEvents(props.events, event, start, end)
|
|
826
|
+
? false
|
|
827
|
+
: props.onDragEvent?.(event, start, end)
|
|
828
|
+
: props.onDragEvent,
|
|
829
|
+
(value) => {
|
|
830
|
+
onDragEventRef.current = value;
|
|
831
|
+
},
|
|
832
|
+
);
|
|
833
|
+
// What a drag may change on an event: `draggable: false` locks it, and
|
|
834
|
+
// `startEditable`/`durationEditable` (per event, falling back to the grid
|
|
835
|
+
// props) split whether it can be moved vs resized.
|
|
836
|
+
const editability = (event: CalendarEvent<T>) => {
|
|
837
|
+
const editable = !!props.onDragEvent && event.draggable !== false;
|
|
838
|
+
return {
|
|
839
|
+
canMove: editable && (event.startEditable ?? props.eventStartEditable),
|
|
840
|
+
canResize: editable && (event.durationEditable ?? props.eventDurationEditable),
|
|
841
|
+
};
|
|
842
|
+
};
|
|
843
|
+
const eventLabel = (event: CalendarEvent<T>) =>
|
|
844
|
+
props.eventAccessibilityLabel
|
|
845
|
+
? props.eventAccessibilityLabel(event, {
|
|
846
|
+
mode: props.mode,
|
|
847
|
+
isAllDay: false,
|
|
848
|
+
ampm: props.ampm,
|
|
849
|
+
})
|
|
850
|
+
: defaultEventAccessibilityLabel({
|
|
851
|
+
title: event.title,
|
|
852
|
+
isAllDay: false,
|
|
853
|
+
start: event.start,
|
|
854
|
+
end: event.end,
|
|
855
|
+
ampm: props.ampm,
|
|
856
|
+
labels: labels(),
|
|
857
|
+
});
|
|
858
|
+
const eventDescription = (event: CalendarEvent<T>) =>
|
|
859
|
+
`${describeEventDates(event)}, ${eventLabel(event)}`;
|
|
860
|
+
// The actions dialog's steps, matching the native screen-reader actions: one
|
|
861
|
+
// snap step, or one page of days, through the same commit path as a drop.
|
|
862
|
+
const pageDays = () =>
|
|
863
|
+
pageStepDays(props.mode, props.date, props.weekStartsOn, props.numberOfDays);
|
|
864
|
+
const actionDelta = (id: string): [number, number] | null => {
|
|
865
|
+
const step = snapMinutes();
|
|
866
|
+
const page = pageDays() * HOURS_PER_DAY * 60;
|
|
867
|
+
switch (id) {
|
|
868
|
+
case "move-later":
|
|
869
|
+
return [step, step];
|
|
870
|
+
case "move-earlier":
|
|
871
|
+
return [-step, -step];
|
|
872
|
+
case "extend":
|
|
873
|
+
return [0, step];
|
|
874
|
+
case "shorten":
|
|
875
|
+
return [0, -step];
|
|
876
|
+
case "move-next-page":
|
|
877
|
+
return [page, page];
|
|
878
|
+
case "move-previous-page":
|
|
879
|
+
return [-page, -page];
|
|
880
|
+
default:
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
const editActions = (event: CalendarEvent<T>): EventEditAction[] => {
|
|
885
|
+
if (isAllDayEvent(event) || isBackgroundEvent(event)) return [];
|
|
886
|
+
const { canMove, canResize } = editability(event);
|
|
887
|
+
const step = snapMinutes();
|
|
888
|
+
const words = labels();
|
|
889
|
+
const action = (id: string, label: string): EventEditAction => {
|
|
890
|
+
const [startDelta, endDelta] = actionDelta(id) ?? [0, 0];
|
|
891
|
+
const next = resolveDraggedBounds(event.start, event.end, startDelta, endDelta, step);
|
|
892
|
+
return { id, label, available: next !== null };
|
|
893
|
+
};
|
|
894
|
+
return [
|
|
895
|
+
...(canMove
|
|
896
|
+
? [
|
|
897
|
+
action("move-later", words.moveLater(step)),
|
|
898
|
+
action("move-earlier", words.moveEarlier(step)),
|
|
899
|
+
]
|
|
900
|
+
: []),
|
|
901
|
+
...(canResize
|
|
902
|
+
? [action("extend", words.extend(step)), action("shorten", words.shorten(step))]
|
|
903
|
+
: []),
|
|
904
|
+
...(canMove
|
|
905
|
+
? [
|
|
906
|
+
action("move-next-page", words.moveToNextPage(pageDays(), props.mode)),
|
|
907
|
+
action("move-previous-page", words.moveToPreviousPage(pageDays(), props.mode)),
|
|
908
|
+
]
|
|
909
|
+
: []),
|
|
910
|
+
];
|
|
911
|
+
};
|
|
912
|
+
const eventActions = createEventActions<CalendarEvent<T>>(
|
|
913
|
+
() => props.events,
|
|
914
|
+
editActions,
|
|
915
|
+
(event, id) => {
|
|
916
|
+
const delta = actionDelta(id);
|
|
917
|
+
const next =
|
|
918
|
+
delta && resolveDraggedBounds(event.start, event.end, delta[0], delta[1], snapMinutes());
|
|
919
|
+
if (!next || onDragEventRef.current?.(event, next.start, next.end) === false) return null;
|
|
920
|
+
return (candidate) =>
|
|
921
|
+
candidate !== event &&
|
|
922
|
+
candidate.start.getTime() === next.start.getTime() &&
|
|
923
|
+
candidate.end.getTime() === next.end.getTime() &&
|
|
924
|
+
candidate.title === event.title;
|
|
925
|
+
},
|
|
926
|
+
() => props.getEventId,
|
|
927
|
+
);
|
|
928
|
+
const allDayByDay = createMemo(
|
|
929
|
+
// A multi-day all-day event shows in every column it overlaps (matching the
|
|
930
|
+
// native AllDayLane), not just its start day.
|
|
931
|
+
() =>
|
|
932
|
+
days().map((day) => {
|
|
933
|
+
const dayStart = startOfDay(day);
|
|
934
|
+
const dayEnd = addDays(dayStart, 1);
|
|
935
|
+
return props.events.filter(
|
|
936
|
+
(e) => isAllDayEvent(e) && !isBackgroundEvent(e) && e.start < dayEnd && e.end > dayStart,
|
|
937
|
+
);
|
|
938
|
+
}),
|
|
939
|
+
);
|
|
940
|
+
const hasAllDay = createMemo(() => allDayByDay().some((list) => list.length > 0));
|
|
941
|
+
createEffect(
|
|
942
|
+
() => [props.scrollOffsetMinutes, windowStart()],
|
|
943
|
+
() =>
|
|
944
|
+
untrack(() => {
|
|
945
|
+
// On mount / when the offset prop changes, not on every zoom (hence the ref).
|
|
946
|
+
// The offset is measured from midnight, so subtract the window's start hour.
|
|
947
|
+
if (scrollRef.current)
|
|
948
|
+
scrollRef.current.scrollTop = Math.max(
|
|
949
|
+
0,
|
|
950
|
+
(props.scrollOffsetMinutes / 60 - windowStart()) * hourHeightRef.current,
|
|
951
|
+
);
|
|
952
|
+
}),
|
|
953
|
+
);
|
|
954
|
+
onSettled(() => {
|
|
955
|
+
props.ref?.(
|
|
956
|
+
(() => ({
|
|
957
|
+
scrollToTime: (minutes, { animated = true } = {}) => {
|
|
958
|
+
const el = scrollRef.current;
|
|
959
|
+
if (!el) return;
|
|
960
|
+
const top = Math.max(0, (minutes / 60 - windowStart()) * hourHeightRef.current);
|
|
961
|
+
const smooth =
|
|
962
|
+
animated && !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
963
|
+
if (smooth && typeof el.scrollTo === "function")
|
|
964
|
+
el.scrollTo({
|
|
965
|
+
top,
|
|
966
|
+
behavior: "smooth",
|
|
967
|
+
});
|
|
968
|
+
else el.scrollTop = top;
|
|
969
|
+
},
|
|
970
|
+
}))(),
|
|
971
|
+
);
|
|
972
|
+
return () => {
|
|
973
|
+
scrollRef.current = null;
|
|
974
|
+
columnsRef.current = null;
|
|
975
|
+
};
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
// Zoom: Ctrl/⌘ + wheel (native listener so we can preventDefault), plus
|
|
979
|
+
// two-pointer pinch. Both scale hourHeight about the current view.
|
|
980
|
+
createEffect(
|
|
981
|
+
() => [props.zoomable, props.minHourHeight, props.maxHourHeight],
|
|
982
|
+
() =>
|
|
983
|
+
untrack(() => {
|
|
984
|
+
const el = scrollRef.current;
|
|
985
|
+
if (!el || !props.zoomable) return;
|
|
986
|
+
const onWheel = (e: WheelEvent) => {
|
|
987
|
+
if (!e.ctrlKey && !e.metaKey) return;
|
|
988
|
+
e.preventDefault();
|
|
989
|
+
setHourHeight((h) =>
|
|
990
|
+
clamp(h * (1 - e.deltaY * 0.0015), props.minHourHeight, props.maxHourHeight),
|
|
991
|
+
);
|
|
992
|
+
};
|
|
993
|
+
el.addEventListener("wheel", onWheel, {
|
|
994
|
+
passive: false,
|
|
995
|
+
});
|
|
996
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
997
|
+
}),
|
|
998
|
+
);
|
|
999
|
+
|
|
1000
|
+
// Browser touch-action is fixed for the gesture; cancel touchmove only during a held drag.
|
|
1001
|
+
createEffect(
|
|
1002
|
+
() => [],
|
|
1003
|
+
() =>
|
|
1004
|
+
untrack(() => {
|
|
1005
|
+
const el = scrollRef.current;
|
|
1006
|
+
if (!el) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
const onTouchMove = (e: TouchEvent) => {
|
|
1010
|
+
if (touchDragRef.current && e.cancelable) {
|
|
1011
|
+
e.preventDefault();
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
const onContextMenu = (e: Event) => {
|
|
1015
|
+
if (touchDragRef.current || cancelHoldRef.current) {
|
|
1016
|
+
e.preventDefault();
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
el.addEventListener("touchmove", onTouchMove, {
|
|
1020
|
+
passive: false,
|
|
1021
|
+
});
|
|
1022
|
+
el.addEventListener("contextmenu", onContextMenu);
|
|
1023
|
+
return () => {
|
|
1024
|
+
el.removeEventListener("touchmove", onTouchMove);
|
|
1025
|
+
el.removeEventListener("contextmenu", onContextMenu);
|
|
1026
|
+
};
|
|
1027
|
+
}),
|
|
1028
|
+
);
|
|
1029
|
+
const pinch: ElementRef<Map<number, number>> = {
|
|
1030
|
+
current: new Map(),
|
|
1031
|
+
};
|
|
1032
|
+
const pinchBase: ElementRef<{
|
|
1033
|
+
dist: number;
|
|
1034
|
+
height: number;
|
|
1035
|
+
} | null> = {
|
|
1036
|
+
current: null,
|
|
1037
|
+
};
|
|
1038
|
+
const onBodyPointerDown = (e: DomPointerEvent) => {
|
|
1039
|
+
if (!props.zoomable || e.pointerType !== "touch") return;
|
|
1040
|
+
pinch.current.set(e.pointerId, e.clientY);
|
|
1041
|
+
if (pinch.current.size === 2) {
|
|
1042
|
+
const ys = [...pinch.current.values()];
|
|
1043
|
+
pinchBase.current = {
|
|
1044
|
+
dist: Math.abs(ys[0] - ys[1]),
|
|
1045
|
+
height: hourHeight(),
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
const onBodyPointerMove = (e: DomPointerEvent) => {
|
|
1050
|
+
if (!pinch.current.has(e.pointerId)) return;
|
|
1051
|
+
pinch.current.set(e.pointerId, e.clientY);
|
|
1052
|
+
if (pinch.current.size === 2 && pinchBase.current) {
|
|
1053
|
+
const ys = [...pinch.current.values()];
|
|
1054
|
+
const dist = Math.abs(ys[0] - ys[1]);
|
|
1055
|
+
const ratio = dist / (pinchBase.current.dist || 1);
|
|
1056
|
+
setHourHeight(
|
|
1057
|
+
clamp(pinchBase.current.height * ratio, props.minHourHeight, props.maxHourHeight),
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
const onBodyPointerUp = (e: DomPointerEvent) => {
|
|
1062
|
+
pinch.current.delete(e.pointerId);
|
|
1063
|
+
if (pinch.current.size < 2) pinchBase.current = null;
|
|
1064
|
+
};
|
|
1065
|
+
const Renderer = createMemo(() => props.renderEvent);
|
|
1066
|
+
const totalHeight = createMemo(() => windowHours() * hourHeight());
|
|
1067
|
+
|
|
1068
|
+
// The day under a screen point, from the `data-date` on the column beneath the
|
|
1069
|
+
// pointer (the ghost is pointer-transparent, so it doesn't shadow it). Guarded
|
|
1070
|
+
// for jsdom, which has no `elementFromPoint`.
|
|
1071
|
+
const dayAt = (x: number, y: number): Date | null => {
|
|
1072
|
+
if (typeof document === "undefined" || typeof document.elementFromPoint !== "function") {
|
|
1073
|
+
return null;
|
|
1074
|
+
}
|
|
1075
|
+
const el = document.elementFromPoint(x, y)?.closest?.("[data-date]");
|
|
1076
|
+
const iso = el?.getAttribute("data-date");
|
|
1077
|
+
return iso ? new Date(iso) : null;
|
|
1078
|
+
};
|
|
1079
|
+
const clearEdgeTimer = () => {
|
|
1080
|
+
if (edgeTimer.current) {
|
|
1081
|
+
clearTimeout(edgeTimer.current);
|
|
1082
|
+
edgeTimer.current = null;
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
// Page one period toward the held edge, then re-arm so holding keeps advancing.
|
|
1087
|
+
const fireEdge = () => {
|
|
1088
|
+
const side = edgeSide.current;
|
|
1089
|
+
if (side === 0) return;
|
|
1090
|
+
const p = pageDepsRef.current;
|
|
1091
|
+
const step = pageStepDays(p.mode, p.date, p.weekStartsOn, p.numberOfDays);
|
|
1092
|
+
onChangeDateRef.current?.(addDays(p.date, side * step));
|
|
1093
|
+
pagedRef.current = true;
|
|
1094
|
+
setPaged(true);
|
|
1095
|
+
edgeTimer.current = setTimeout(fireEdge, EDGE_REPEAT_MS);
|
|
1096
|
+
};
|
|
1097
|
+
const detachDocListeners = () => {
|
|
1098
|
+
const h = docHandlersRef.current;
|
|
1099
|
+
if (!h) return;
|
|
1100
|
+
document.removeEventListener("pointermove", h.move);
|
|
1101
|
+
document.removeEventListener("pointerup", h.up);
|
|
1102
|
+
document.removeEventListener("pointercancel", h.cancel);
|
|
1103
|
+
docHandlersRef.current = null;
|
|
1104
|
+
};
|
|
1105
|
+
const finishDrag = () => {
|
|
1106
|
+
detachDocListeners();
|
|
1107
|
+
clearEdgeTimer();
|
|
1108
|
+
edgeSide.current = 0;
|
|
1109
|
+
pagedRef.current = false;
|
|
1110
|
+
setPaged(false);
|
|
1111
|
+
touchDragRef.current = false;
|
|
1112
|
+
activeGrabRef.current = null;
|
|
1113
|
+
draggedRef.current = null;
|
|
1114
|
+
dragOrigin.current = null;
|
|
1115
|
+
applyDrag(null);
|
|
1116
|
+
};
|
|
1117
|
+
const moveDrag = (e: PointerEvent) => {
|
|
1118
|
+
const d = dragRef.current;
|
|
1119
|
+
if (!d || !dragOrigin.current) return;
|
|
1120
|
+
if (
|
|
1121
|
+
touchDragRef.current &&
|
|
1122
|
+
!d.moved &&
|
|
1123
|
+
Math.hypot(
|
|
1124
|
+
e.clientX - dragOrigin.current.pointerX,
|
|
1125
|
+
e.clientY - dragOrigin.current.pointerY,
|
|
1126
|
+
) <= props.touchDragThreshold
|
|
1127
|
+
) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
ptr.current = {
|
|
1131
|
+
x: e.clientX,
|
|
1132
|
+
y: e.clientY,
|
|
1133
|
+
};
|
|
1134
|
+
// Read the live row height (ref, not the state closure) so a mid-drag zoom
|
|
1135
|
+
// keeps the math aligned with what's on screen.
|
|
1136
|
+
const dHours = (e.clientY - dragOrigin.current.pointerY) / hourHeightRef.current;
|
|
1137
|
+
const snap = (v: number) => Math.round(v / snapHours()) * snapHours();
|
|
1138
|
+
if (d.kind === "move") {
|
|
1139
|
+
// Only the start is held inside the window; the end may run past the end of
|
|
1140
|
+
// the day, continuing on the next one (see `clampMoveStartMinutes`). A
|
|
1141
|
+
// segment that continues *before* is skipped: its 00:00 top edge is where the
|
|
1142
|
+
// layout clipped the event, not where the event starts, so holding it there
|
|
1143
|
+
// would make the tail of a midnight-spanning event impossible to drag earlier.
|
|
1144
|
+
const raw = snap(dragOrigin.current.startHours + dHours);
|
|
1145
|
+
const requestedHours = d.continuesBefore
|
|
1146
|
+
? raw
|
|
1147
|
+
: clampMoveStartMinutes(raw * 60, windowStart(), windowEnd(), snapMinutes()) / 60;
|
|
1148
|
+
// Map the horizontal drag to whole day columns, clamped so the in-view box
|
|
1149
|
+
// can't leave the visible range (mirrors the native renderer). Once paged,
|
|
1150
|
+
// the drop day comes from the hit-test instead.
|
|
1151
|
+
const o = dragOrigin.current;
|
|
1152
|
+
const rawDayDelta = o.dayWidth > 0 ? Math.round((e.clientX - o.pointerX) / o.dayWidth) : 0;
|
|
1153
|
+
const targetDay = clamp(o.dayIndex + rawDayDelta, 0, daysRef.current.length - 1);
|
|
1154
|
+
const dayDelta = targetDay - o.dayIndex;
|
|
1155
|
+
// Draw the box where the drop commits it: a start in the hour a
|
|
1156
|
+
// spring-forward change skips moves on past it, and the kept elapsed
|
|
1157
|
+
// duration covers a different number of rows once a DST change falls
|
|
1158
|
+
// inside it or stops falling inside it.
|
|
1159
|
+
const dayMinutes =
|
|
1160
|
+
differenceInCalendarDays(startOfDay(daysRef.current[targetDay] ?? o.base), o.base) *
|
|
1161
|
+
HOURS_PER_DAY *
|
|
1162
|
+
60;
|
|
1163
|
+
const moved = movedClockSpan(
|
|
1164
|
+
o.segmentStart,
|
|
1165
|
+
o.segmentEnd,
|
|
1166
|
+
dayMinutes + Math.round((requestedHours - o.startHours) * 60),
|
|
1167
|
+
);
|
|
1168
|
+
const startHours = o.startHours + moved.startHours - dayMinutes / 60;
|
|
1169
|
+
const durationHours = moved.hours;
|
|
1170
|
+
// Preview the part that runs past *midnight* at the top of the next column.
|
|
1171
|
+
// Measured against the end of the day, not `windowEnd`: a narrowed window
|
|
1172
|
+
// (say 8–18) leaves plenty of events hanging below the last visible hour
|
|
1173
|
+
// without them reaching the next day at all.
|
|
1174
|
+
const spillHours = Math.min(
|
|
1175
|
+
Math.max(startHours + durationHours - HOURS_PER_DAY, 0),
|
|
1176
|
+
windowHours(),
|
|
1177
|
+
);
|
|
1178
|
+
const nextDay = daysRef.current[targetDay + 1];
|
|
1179
|
+
const spillDayIndex =
|
|
1180
|
+
spillHours > 0 &&
|
|
1181
|
+
nextDay &&
|
|
1182
|
+
// Only when that column really is the next calendar day (`hiddenDays` can
|
|
1183
|
+
// break the run), otherwise the spill lands off-view and isn't shown.
|
|
1184
|
+
differenceInCalendarDays(nextDay, daysRef.current[targetDay]) === 1 &&
|
|
1185
|
+
// A segment that already continues after owns a real next-day box; a
|
|
1186
|
+
// preview on top of it would just double up.
|
|
1187
|
+
!d.continuesAfter
|
|
1188
|
+
? targetDay + 1
|
|
1189
|
+
: -1;
|
|
1190
|
+
applyDrag({
|
|
1191
|
+
...d,
|
|
1192
|
+
startHours,
|
|
1193
|
+
requestedStartHours: requestedHours,
|
|
1194
|
+
durationHours,
|
|
1195
|
+
dayDelta,
|
|
1196
|
+
dayOffsetPx: dayDelta * o.dayWidth,
|
|
1197
|
+
spillHours,
|
|
1198
|
+
spillDayIndex,
|
|
1199
|
+
moved: true,
|
|
1200
|
+
});
|
|
1201
|
+
// Follow the pointer with the floating ghost once the origin column is gone.
|
|
1202
|
+
const g = ghostRef.current;
|
|
1203
|
+
const held = draggedRef.current;
|
|
1204
|
+
if (g && held) {
|
|
1205
|
+
g.style.transform = `translate(${e.clientX - held.grabX}px, ${e.clientY - held.grabY}px)`;
|
|
1206
|
+
}
|
|
1207
|
+
// Edge auto-advance: dwell near a horizontal edge to page the view. Read the
|
|
1208
|
+
// columns rect live so a mid-drag scroll/layout shift can't stale it.
|
|
1209
|
+
if (edgeAdvanceEnabled() && o.pointerType === "mouse") {
|
|
1210
|
+
const rect = columnsRef.current?.getBoundingClientRect();
|
|
1211
|
+
if (rect && rect.right > rect.left) {
|
|
1212
|
+
const left = rect.left + gutterWidth();
|
|
1213
|
+
const side: -1 | 0 | 1 =
|
|
1214
|
+
e.clientX <= left + EDGE_ZONE ? -1 : e.clientX >= rect.right - EDGE_ZONE ? 1 : 0;
|
|
1215
|
+
if (side !== edgeSide.current) {
|
|
1216
|
+
clearEdgeTimer();
|
|
1217
|
+
edgeSide.current = side;
|
|
1218
|
+
if (side !== 0) edgeTimer.current = setTimeout(fireEdge, EDGE_DWELL_MS);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
} else if (d.kind === "resize") {
|
|
1223
|
+
const durationHours = clamp(
|
|
1224
|
+
snap(dragOrigin.current.durationHours + dHours),
|
|
1225
|
+
snapHours(),
|
|
1226
|
+
Math.max(snapHours(), windowEnd() - d.startHours),
|
|
1227
|
+
);
|
|
1228
|
+
applyDrag({
|
|
1229
|
+
...d,
|
|
1230
|
+
durationHours,
|
|
1231
|
+
moved: true,
|
|
1232
|
+
});
|
|
1233
|
+
} else {
|
|
1234
|
+
// Top-edge resize: move the start, keep the end fixed. Clamp the start into
|
|
1235
|
+
// the window and never past one snap step before the end.
|
|
1236
|
+
const o = dragOrigin.current;
|
|
1237
|
+
const end = o.startHours + o.durationHours;
|
|
1238
|
+
const startHours = clamp(snap(o.startHours + dHours), windowStart(), end - snapHours());
|
|
1239
|
+
applyDrag({
|
|
1240
|
+
...d,
|
|
1241
|
+
startHours,
|
|
1242
|
+
durationHours: end - startHours,
|
|
1243
|
+
moved: true,
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
const endDrag = (e: PointerEvent) => {
|
|
1248
|
+
const d = dragRef.current;
|
|
1249
|
+
if (!d) return;
|
|
1250
|
+
try {
|
|
1251
|
+
activeGrabRef.current?.box.releasePointerCapture?.(e.pointerId);
|
|
1252
|
+
} catch {
|
|
1253
|
+
// Best-effort release; ignore if the capture was never granted.
|
|
1254
|
+
}
|
|
1255
|
+
const held = draggedRef.current;
|
|
1256
|
+
if (!d.moved) {
|
|
1257
|
+
const wasTouch = touchDragRef.current;
|
|
1258
|
+
const tapBox = activeGrabRef.current?.box ?? null;
|
|
1259
|
+
finishDrag();
|
|
1260
|
+
if (wasTouch) {
|
|
1261
|
+
tappedRef.current = tapBox;
|
|
1262
|
+
} else {
|
|
1263
|
+
held?.onPress();
|
|
1264
|
+
}
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
const origin = dragOrigin.current;
|
|
1268
|
+
const originIndex = origin?.dayIndex ?? 0;
|
|
1269
|
+
let base: Date | null = null;
|
|
1270
|
+
if (d.kind === "move") {
|
|
1271
|
+
if (pagedRef.current) {
|
|
1272
|
+
// The origin column has scrolled off with the page change, so the day
|
|
1273
|
+
// under the pointer is authoritative; dropping off the grid snaps back.
|
|
1274
|
+
const day = dayAt(e.clientX, e.clientY);
|
|
1275
|
+
base = day ? startOfDay(day) : null;
|
|
1276
|
+
} else {
|
|
1277
|
+
// In view: resolve from the days array (correct under hiddenDays), as
|
|
1278
|
+
// before. `dayDelta` is clamped to the visible range at drag time.
|
|
1279
|
+
base = startOfDay(
|
|
1280
|
+
daysRef.current[originIndex + d.dayDelta] ?? daysRef.current[originIndex],
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
} else {
|
|
1284
|
+
base = startOfDay(daysRef.current[originIndex] ?? daysRef.current[0]);
|
|
1285
|
+
}
|
|
1286
|
+
if (held && origin && d.kind === "resize") {
|
|
1287
|
+
// Resolve the end like the native renderer, from the edge the layout drew,
|
|
1288
|
+
// so it lands at the row the edge was dragged to on either side of a DST
|
|
1289
|
+
// change.
|
|
1290
|
+
const endDelta = Math.round(
|
|
1291
|
+
(d.startHours + d.durationHours - origin.startHours - origin.durationHours) * 60,
|
|
1292
|
+
);
|
|
1293
|
+
const next = resolveDraggedBounds(
|
|
1294
|
+
held.event.start,
|
|
1295
|
+
held.event.end,
|
|
1296
|
+
0,
|
|
1297
|
+
endDelta,
|
|
1298
|
+
snapMinutes(),
|
|
1299
|
+
);
|
|
1300
|
+
if (next) onDragEventRef.current?.(held.event, next.start, next.end);
|
|
1301
|
+
} else if (base && held && origin) {
|
|
1302
|
+
// Shift the real event by how far its segment moved, so a move that now
|
|
1303
|
+
// spans midnight (and every later drag of the resulting multi-day event)
|
|
1304
|
+
// keeps the parts outside the dragged day instead of clipping to it.
|
|
1305
|
+
const segmentStart = movedSegmentStart(
|
|
1306
|
+
origin,
|
|
1307
|
+
base,
|
|
1308
|
+
d.kind === "move" ? d.requestedStartHours : d.startHours,
|
|
1309
|
+
);
|
|
1310
|
+
const startShift = segmentStart.getTime() - origin.segmentStart.getTime();
|
|
1311
|
+
const endShift = d.kind === "move" ? startShift : 0;
|
|
1312
|
+
const start = new Date(held.event.start.getTime() + startShift);
|
|
1313
|
+
const end = new Date(held.event.end.getTime() + endShift);
|
|
1314
|
+
if (end > start) onDragEventRef.current?.(held.event, start, end);
|
|
1315
|
+
}
|
|
1316
|
+
finishDrag();
|
|
1317
|
+
};
|
|
1318
|
+
const cancelDrag = () => {
|
|
1319
|
+
finishDrag();
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
// Takes the laid-out segment whole rather than five of its fields: the two
|
|
1323
|
+
// `continues*` flags are the same type, so passing them positionally invites a
|
|
1324
|
+
// silent transposition.
|
|
1325
|
+
const beginDrag = (
|
|
1326
|
+
e: EventGrab,
|
|
1327
|
+
pe: PositionedEvent<T>,
|
|
1328
|
+
key: string,
|
|
1329
|
+
kind: "move" | "resize" | "resize-start",
|
|
1330
|
+
dayIndex: number,
|
|
1331
|
+
onPress?: () => void,
|
|
1332
|
+
) => {
|
|
1333
|
+
const { event, startHours, durationHours, continuesBefore, continuesAfter } = pe;
|
|
1334
|
+
try {
|
|
1335
|
+
e.box.setPointerCapture?.(e.pointerId);
|
|
1336
|
+
} catch {
|
|
1337
|
+
// Pointer capture is best-effort; some environments reject it.
|
|
1338
|
+
}
|
|
1339
|
+
touchDragRef.current = e.pointerType !== "mouse";
|
|
1340
|
+
activeGrabRef.current = e;
|
|
1341
|
+
// The event box sits inside its day column, so the parent's width is one day;
|
|
1342
|
+
// columns are equal-width, so measuring one is enough. Resizes never move
|
|
1343
|
+
// across days, so 0 is fine there.
|
|
1344
|
+
const boxEl = e.box;
|
|
1345
|
+
const column = kind === "move" ? boxEl.parentElement : null;
|
|
1346
|
+
const dayWidth = column ? column.getBoundingClientRect().width : 0;
|
|
1347
|
+
const boxRect = kind === "move" ? boxEl.getBoundingClientRect() : null;
|
|
1348
|
+
const originBase = startOfDay(days()[dayIndex] ?? days()[0]);
|
|
1349
|
+
const originNextDay = addDays(originBase, 1);
|
|
1350
|
+
const segmentStart = event.start > originBase ? event.start : originBase;
|
|
1351
|
+
dragOrigin.current = {
|
|
1352
|
+
pointerX: e.clientX,
|
|
1353
|
+
pointerY: e.clientY,
|
|
1354
|
+
pointerType: e.pointerType,
|
|
1355
|
+
startHours,
|
|
1356
|
+
durationHours,
|
|
1357
|
+
dayIndex,
|
|
1358
|
+
dayWidth,
|
|
1359
|
+
// The segment's real edges rather than ones rebuilt from its rows: in the
|
|
1360
|
+
// hour a fall-back change repeats, one row maps to two instants.
|
|
1361
|
+
segmentStart,
|
|
1362
|
+
segmentEnd: event.end < originNextDay ? event.end : originNextDay,
|
|
1363
|
+
base: originBase,
|
|
1364
|
+
};
|
|
1365
|
+
draggedRef.current = {
|
|
1366
|
+
event,
|
|
1367
|
+
onPress: onPress ?? (() => {}),
|
|
1368
|
+
grabX: boxRect ? e.clientX - boxRect.left : 0,
|
|
1369
|
+
grabY: boxRect ? e.clientY - boxRect.top : 0,
|
|
1370
|
+
w: boxRect ? boxRect.width : 0,
|
|
1371
|
+
h: boxRect ? boxRect.height : 0,
|
|
1372
|
+
};
|
|
1373
|
+
ptr.current = {
|
|
1374
|
+
x: e.clientX,
|
|
1375
|
+
y: e.clientY,
|
|
1376
|
+
};
|
|
1377
|
+
edgeSide.current = 0;
|
|
1378
|
+
pagedRef.current = false;
|
|
1379
|
+
setPaged(false);
|
|
1380
|
+
clearEdgeTimer();
|
|
1381
|
+
applyDrag({
|
|
1382
|
+
key,
|
|
1383
|
+
kind,
|
|
1384
|
+
startHours,
|
|
1385
|
+
requestedStartHours: startHours,
|
|
1386
|
+
durationHours,
|
|
1387
|
+
continuesBefore,
|
|
1388
|
+
continuesAfter,
|
|
1389
|
+
dayDelta: 0,
|
|
1390
|
+
dayOffsetPx: 0,
|
|
1391
|
+
spillHours: 0,
|
|
1392
|
+
spillDayIndex: -1,
|
|
1393
|
+
moved: false,
|
|
1394
|
+
});
|
|
1395
|
+
props.onDragStart?.(event);
|
|
1396
|
+
// Transport the rest of the drag at the document level so it survives the day
|
|
1397
|
+
// columns unmounting on a page change (the dragged box's own node disappears).
|
|
1398
|
+
// Detach any prior set first so a second beginDrag can't leak listeners.
|
|
1399
|
+
detachDocListeners();
|
|
1400
|
+
const handlers = {
|
|
1401
|
+
move: (event: PointerEvent) => {
|
|
1402
|
+
if (event.pointerId === e.pointerId) {
|
|
1403
|
+
moveDrag(event);
|
|
1404
|
+
}
|
|
1405
|
+
},
|
|
1406
|
+
up: (event: PointerEvent) => {
|
|
1407
|
+
if (event.pointerId === e.pointerId) {
|
|
1408
|
+
endDrag(event);
|
|
1409
|
+
}
|
|
1410
|
+
},
|
|
1411
|
+
cancel: (event: PointerEvent) => {
|
|
1412
|
+
if (event.pointerId === e.pointerId) {
|
|
1413
|
+
cancelDrag();
|
|
1414
|
+
}
|
|
1415
|
+
},
|
|
1416
|
+
};
|
|
1417
|
+
docHandlersRef.current = handlers;
|
|
1418
|
+
document.addEventListener("pointermove", handlers.move);
|
|
1419
|
+
document.addEventListener("pointerup", handlers.up);
|
|
1420
|
+
document.addEventListener("pointercancel", handlers.cancel);
|
|
1421
|
+
};
|
|
1422
|
+
const pressEvent = (
|
|
1423
|
+
e: DomPointerEvent<HTMLElement>,
|
|
1424
|
+
pe: PositionedEvent<T>,
|
|
1425
|
+
key: string,
|
|
1426
|
+
kind: "move" | "resize" | "resize-start",
|
|
1427
|
+
dayIndex: number,
|
|
1428
|
+
onPress?: () => void,
|
|
1429
|
+
) => {
|
|
1430
|
+
if (!props.onDragEvent || e.button > 0 || createOrigin.current) {
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
e.stopPropagation();
|
|
1434
|
+
const hadPendingHold = cancelHoldRef.current !== null;
|
|
1435
|
+
cancelHoldRef.current?.();
|
|
1436
|
+
tappedRef.current = null;
|
|
1437
|
+
if (hadPendingHold || activeGrabRef.current || (e.pointerType !== "mouse" && !e.isPrimary)) {
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
const grab: EventGrab = {
|
|
1441
|
+
box: e.currentTarget,
|
|
1442
|
+
pointerId: e.pointerId,
|
|
1443
|
+
pointerType: e.pointerType,
|
|
1444
|
+
clientX: e.clientX,
|
|
1445
|
+
clientY: e.clientY,
|
|
1446
|
+
};
|
|
1447
|
+
if (e.pointerType === "mouse") {
|
|
1448
|
+
beginDrag(grab, pe, key, kind, dayIndex, onPress);
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
cancelHoldRef.current = waitForHold(
|
|
1452
|
+
grab,
|
|
1453
|
+
props.touchDragDelay,
|
|
1454
|
+
props.touchDragThreshold,
|
|
1455
|
+
() => {
|
|
1456
|
+
cancelHoldRef.current = null;
|
|
1457
|
+
beginDrag(grab, pe, key, kind, dayIndex, onPress);
|
|
1458
|
+
},
|
|
1459
|
+
() => {
|
|
1460
|
+
cancelHoldRef.current = null;
|
|
1461
|
+
tappedRef.current = grab.box;
|
|
1462
|
+
},
|
|
1463
|
+
() => {
|
|
1464
|
+
cancelHoldRef.current = null;
|
|
1465
|
+
},
|
|
1466
|
+
);
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
// Remove any lingering document listeners / dwell timer if we unmount mid-drag.
|
|
1470
|
+
createEffect(
|
|
1471
|
+
() => [],
|
|
1472
|
+
() =>
|
|
1473
|
+
untrack(() => () => {
|
|
1474
|
+
cancelHoldRef.current?.();
|
|
1475
|
+
detachDocListeners();
|
|
1476
|
+
clearEdgeTimer();
|
|
1477
|
+
}),
|
|
1478
|
+
);
|
|
1479
|
+
createEffect(
|
|
1480
|
+
() => [props.date, props.events, props.onDragEvent],
|
|
1481
|
+
() =>
|
|
1482
|
+
untrack(() => {
|
|
1483
|
+
cancelHoldRef.current?.();
|
|
1484
|
+
}),
|
|
1485
|
+
);
|
|
1486
|
+
const pxFromTop = (el: HTMLElement, clientY: number) => clientY - el.getBoundingClientRect().top;
|
|
1487
|
+
const beginCreate = (e: DomPointerEvent, dayIndex: number) => {
|
|
1488
|
+
if (createOrigin.current || activeGrabRef.current || e.isPrimary === false) return;
|
|
1489
|
+
// Mouse / pen only: on touch the column must stay free to scroll the grid.
|
|
1490
|
+
// Only from the column background, primary button, never on an event.
|
|
1491
|
+
cellTouchRef.current =
|
|
1492
|
+
e.pointerType === "touch" && e.target === e.currentTarget
|
|
1493
|
+
? {
|
|
1494
|
+
pointerId: e.pointerId,
|
|
1495
|
+
x: e.clientX,
|
|
1496
|
+
y: e.clientY,
|
|
1497
|
+
}
|
|
1498
|
+
: null;
|
|
1499
|
+
if (!cellEnabled() || e.pointerType === "touch") return;
|
|
1500
|
+
if (e.target !== e.currentTarget || e.button > 0) return;
|
|
1501
|
+
const el = e.currentTarget as HTMLElement;
|
|
1502
|
+
const startPx = pxFromTop(el, e.clientY);
|
|
1503
|
+
try {
|
|
1504
|
+
el.setPointerCapture?.(e.pointerId);
|
|
1505
|
+
} catch {
|
|
1506
|
+
// Best-effort capture.
|
|
1507
|
+
}
|
|
1508
|
+
createOrigin.current = {
|
|
1509
|
+
pointerId: e.pointerId,
|
|
1510
|
+
clientY: e.clientY,
|
|
1511
|
+
el,
|
|
1512
|
+
dayIndex,
|
|
1513
|
+
dayTime: days()[dayIndex].getTime(),
|
|
1514
|
+
creating: !!props.onCreateEvent,
|
|
1515
|
+
startPx,
|
|
1516
|
+
};
|
|
1517
|
+
setCreateBox({
|
|
1518
|
+
dayIndex,
|
|
1519
|
+
dayTime: days()[dayIndex].getTime(),
|
|
1520
|
+
startPx,
|
|
1521
|
+
curPx: startPx,
|
|
1522
|
+
});
|
|
1523
|
+
};
|
|
1524
|
+
const moveCreate = (e: DomPointerEvent) => {
|
|
1525
|
+
const touch = cellTouchRef.current;
|
|
1526
|
+
if (
|
|
1527
|
+
touch &&
|
|
1528
|
+
e.pointerId === touch.pointerId &&
|
|
1529
|
+
Math.hypot(e.clientX - touch.x, e.clientY - touch.y) > CELL_TOUCH_SLOP_PX
|
|
1530
|
+
) {
|
|
1531
|
+
cellTouchRef.current = null;
|
|
1532
|
+
}
|
|
1533
|
+
const o = createOrigin.current;
|
|
1534
|
+
if (!o || o.pointerId !== e.pointerId) return;
|
|
1535
|
+
o.clientY = e.clientY;
|
|
1536
|
+
setCreateBox({
|
|
1537
|
+
dayIndex: o.dayIndex,
|
|
1538
|
+
dayTime: o.dayTime,
|
|
1539
|
+
startPx: o.startPx,
|
|
1540
|
+
curPx: pxFromTop(o.el, e.clientY),
|
|
1541
|
+
});
|
|
1542
|
+
};
|
|
1543
|
+
const endCreate = (e: DomPointerEvent) => {
|
|
1544
|
+
const o = createOrigin.current;
|
|
1545
|
+
if (!o || o.pointerId !== e.pointerId) return;
|
|
1546
|
+
try {
|
|
1547
|
+
o.el.releasePointerCapture?.(e.pointerId);
|
|
1548
|
+
} catch {
|
|
1549
|
+
// Best-effort release.
|
|
1550
|
+
}
|
|
1551
|
+
const endPx = pxFromTop(o.el, e.clientY);
|
|
1552
|
+
const day = days()[o.dayIndex];
|
|
1553
|
+
const moved = Math.abs(endPx - o.startPx) > 4;
|
|
1554
|
+
const h = hourHeightRef.current;
|
|
1555
|
+
if (moved && props.onCreateEvent) {
|
|
1556
|
+
const range = cellRangeFromDrag(day, o.startPx, endPx, h, windowStart(), snapMinutes());
|
|
1557
|
+
if (range) props.onCreateEvent(range.start, range.end);
|
|
1558
|
+
} else if (props.onPressCell) {
|
|
1559
|
+
const at = cellRangeFromDrag(day, o.startPx, o.startPx, h, windowStart(), snapMinutes());
|
|
1560
|
+
if (at) props.onPressCell(at.start);
|
|
1561
|
+
}
|
|
1562
|
+
createOrigin.current = null;
|
|
1563
|
+
setCreateBox(null);
|
|
1564
|
+
};
|
|
1565
|
+
const tapCell = (e: DomMouseEvent<HTMLDivElement>, dayIndex: number) => {
|
|
1566
|
+
const touch = cellTouchRef.current;
|
|
1567
|
+
cellTouchRef.current = null;
|
|
1568
|
+
const day = days()[dayIndex];
|
|
1569
|
+
if (!touch || !props.onPressCell || !day || e.target !== e.currentTarget) {
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
const px = pxFromTop(e.currentTarget, e.clientY);
|
|
1573
|
+
const at = cellRangeFromDrag(day, px, px, hourHeightRef.current, windowStart(), snapMinutes());
|
|
1574
|
+
if (at) {
|
|
1575
|
+
props.onPressCell(at.start);
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
// A gesture the browser/OS cancels (scroll takeover, etc.) must not commit a
|
|
1579
|
+
// create, just drop the in-progress state.
|
|
1580
|
+
const clearCreate = () => {
|
|
1581
|
+
const previous = createOrigin.current;
|
|
1582
|
+
createOrigin.current = null;
|
|
1583
|
+
setCreateBox(null);
|
|
1584
|
+
try {
|
|
1585
|
+
previous?.el.releasePointerCapture?.(previous.pointerId);
|
|
1586
|
+
} catch {
|
|
1587
|
+
// The browser may have already released capture.
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
createEffect(
|
|
1591
|
+
() => ({ days: days(), creating: !!props.onCreateEvent, enabled: cellEnabled() }),
|
|
1592
|
+
(state) => {
|
|
1593
|
+
const origin = createOrigin.current;
|
|
1594
|
+
if (
|
|
1595
|
+
origin &&
|
|
1596
|
+
(!state.enabled ||
|
|
1597
|
+
(origin.creating && !state.creating) ||
|
|
1598
|
+
state.days[origin.dayIndex]?.getTime() !== origin.dayTime)
|
|
1599
|
+
)
|
|
1600
|
+
clearCreate();
|
|
1601
|
+
},
|
|
1602
|
+
);
|
|
1603
|
+
const cancelCreate = (e: DomPointerEvent) => {
|
|
1604
|
+
if (cellTouchRef.current?.pointerId === e.pointerId) cellTouchRef.current = null;
|
|
1605
|
+
if (createOrigin.current?.pointerId !== e.pointerId) return;
|
|
1606
|
+
clearCreate();
|
|
1607
|
+
};
|
|
1608
|
+
// Without capture the column stops seeing the sweep's moves and release, so
|
|
1609
|
+
// drop it. Leaves `cellTouchRef` alone: touch taps resolve on the later click.
|
|
1610
|
+
const loseCreateCapture = (e: DomPointerEvent) => {
|
|
1611
|
+
if (createOrigin.current?.pointerId !== e.pointerId) return;
|
|
1612
|
+
clearCreate();
|
|
1613
|
+
};
|
|
1614
|
+
// Pointer capture does not move keyboard focus to the grid.
|
|
1615
|
+
createEffect(
|
|
1616
|
+
() => [],
|
|
1617
|
+
() => {
|
|
1618
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
1619
|
+
if (event.key !== "Escape" || !createOrigin.current) return;
|
|
1620
|
+
event.preventDefault();
|
|
1621
|
+
event.stopPropagation();
|
|
1622
|
+
clearCreate();
|
|
1623
|
+
};
|
|
1624
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1625
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
1626
|
+
},
|
|
1627
|
+
);
|
|
1628
|
+
|
|
1629
|
+
// Per-day layout and shading are pure functions of days/events/businessHours,
|
|
1630
|
+
// so memoize them, otherwise every drag pointermove (which calls setDrag)
|
|
1631
|
+
// re-runs the full layout for each column.
|
|
1632
|
+
const positionedByDay = createMemo(() => days().map((day) => layoutDayEvents(props.events, day)));
|
|
1633
|
+
|
|
1634
|
+
// Keep the original boxes mounted for pointer capture, but replace every
|
|
1635
|
+
// segment of a moving multi-day event with the same shifted range.
|
|
1636
|
+
const moveOrigin = () => dragOrigin.current;
|
|
1637
|
+
const heldEvent = () => draggedRef.current?.event;
|
|
1638
|
+
const movingEvent = createMemo(() => {
|
|
1639
|
+
drag();
|
|
1640
|
+
const currentHeldEvent = heldEvent();
|
|
1641
|
+
return (
|
|
1642
|
+
currentHeldEvent &&
|
|
1643
|
+
(props.events.includes(currentHeldEvent)
|
|
1644
|
+
? currentHeldEvent
|
|
1645
|
+
: (props.events.find((event) => {
|
|
1646
|
+
return (
|
|
1647
|
+
event.start.getTime() === currentHeldEvent.start.getTime() &&
|
|
1648
|
+
event.end.getTime() === currentHeldEvent.end.getTime() &&
|
|
1649
|
+
event.title === currentHeldEvent.title
|
|
1650
|
+
);
|
|
1651
|
+
}) ?? currentHeldEvent))
|
|
1652
|
+
);
|
|
1653
|
+
});
|
|
1654
|
+
const multiDayMove = createMemo(() => {
|
|
1655
|
+
const currentDrag = drag();
|
|
1656
|
+
const currentMoveOrigin = moveOrigin();
|
|
1657
|
+
const currentMovingEvent = movingEvent();
|
|
1658
|
+
return !paged() &&
|
|
1659
|
+
currentDrag?.kind === "move" &&
|
|
1660
|
+
(currentDrag.continuesBefore || currentDrag.continuesAfter) &&
|
|
1661
|
+
currentMoveOrigin &&
|
|
1662
|
+
currentMovingEvent
|
|
1663
|
+
? (() => {
|
|
1664
|
+
const target = days()[currentMoveOrigin.dayIndex + currentDrag.dayDelta];
|
|
1665
|
+
const segmentStart = movedSegmentStart(
|
|
1666
|
+
currentMoveOrigin,
|
|
1667
|
+
startOfDay(target),
|
|
1668
|
+
currentDrag.requestedStartHours,
|
|
1669
|
+
);
|
|
1670
|
+
const shift = segmentStart.getTime() - currentMoveOrigin.segmentStart.getTime();
|
|
1671
|
+
return {
|
|
1672
|
+
...currentMovingEvent,
|
|
1673
|
+
start: new Date(currentMovingEvent.start.getTime() + shift),
|
|
1674
|
+
end: new Date(currentMovingEvent.end.getTime() + shift),
|
|
1675
|
+
allDay: false,
|
|
1676
|
+
};
|
|
1677
|
+
})()
|
|
1678
|
+
: null;
|
|
1679
|
+
});
|
|
1680
|
+
|
|
1681
|
+
// The tail of an in-progress move that runs past midnight, shown on `dayIndex`
|
|
1682
|
+
// so the drop is visible on both days at once. `drag` and `draggedRef` are set
|
|
1683
|
+
// together in `beginDrag` and cleared together in `finishDrag`, so the guard on
|
|
1684
|
+
// the state keeps the ref read consistent.
|
|
1685
|
+
const spillPreviewFor = (dayIndex: number): SolidRenderEventArgs<T> | null => {
|
|
1686
|
+
const currentDrag = drag();
|
|
1687
|
+
if (
|
|
1688
|
+
paged() ||
|
|
1689
|
+
!currentDrag ||
|
|
1690
|
+
currentDrag.kind !== "move" ||
|
|
1691
|
+
currentDrag.spillDayIndex !== dayIndex
|
|
1692
|
+
)
|
|
1693
|
+
return null;
|
|
1694
|
+
const dragged = draggedRef.current?.event;
|
|
1695
|
+
if (!dragged) return null;
|
|
1696
|
+
return {
|
|
1697
|
+
event: dragged,
|
|
1698
|
+
mode: props.mode,
|
|
1699
|
+
isAllDay: false,
|
|
1700
|
+
boxHeight: Math.max(currentDrag.spillHours * hourHeight(), props.minEventHeight),
|
|
1701
|
+
continuesBefore: true,
|
|
1702
|
+
continuesAfter: false,
|
|
1703
|
+
ampm: props.ampm,
|
|
1704
|
+
onPress: () => {},
|
|
1705
|
+
};
|
|
1706
|
+
};
|
|
1707
|
+
|
|
1708
|
+
// Arrow-key navigation across events (`keyboardEventNavigation`). This is purely
|
|
1709
|
+
// additive: every event stays a tab stop (so screen-reader users keep full
|
|
1710
|
+
// access), and the arrow keys are a convenience for sighted keyboard users. It's
|
|
1711
|
+
// deliberately NOT a roving tabindex, that needs a composite container role
|
|
1712
|
+
// (grid/listbox), which this overlapping, absolutely-positioned layout can't
|
|
1713
|
+
// honestly claim, and without one it would strip events from the tab order for
|
|
1714
|
+
// exactly the screen-reader users it's meant to help. Events are keyed `day:idx`
|
|
1715
|
+
// to match the rendered chips and sorted by start time so Up/Down step through a
|
|
1716
|
+
// day chronologically.
|
|
1717
|
+
const navByDay = createMemo(() =>
|
|
1718
|
+
positionedByDay().map((list, day) =>
|
|
1719
|
+
list
|
|
1720
|
+
.map((pe, idx) => ({
|
|
1721
|
+
key: `${day}:${idx}`,
|
|
1722
|
+
start: pe.startHours,
|
|
1723
|
+
dur: pe.durationHours,
|
|
1724
|
+
}))
|
|
1725
|
+
.filter((n) => !(n.start >= windowEnd() || n.start + n.dur <= windowStart()))
|
|
1726
|
+
.sort((a, b) => a.start - b.start),
|
|
1727
|
+
),
|
|
1728
|
+
);
|
|
1729
|
+
// The event to move focus to for an arrow/Home/End key, or null to stay put.
|
|
1730
|
+
const nextEventKey = (currentKey: string, arrowKey: string): string | null => {
|
|
1731
|
+
let day = -1;
|
|
1732
|
+
let pos = -1;
|
|
1733
|
+
for (let d = 0; d < navByDay().length; d++) {
|
|
1734
|
+
const p = navByDay()[d].findIndex((n) => n.key === currentKey);
|
|
1735
|
+
if (p !== -1) {
|
|
1736
|
+
day = d;
|
|
1737
|
+
pos = p;
|
|
1738
|
+
break;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
if (day === -1) return null;
|
|
1742
|
+
const start = navByDay()[day][pos].start;
|
|
1743
|
+
// The event in day `d` whose start time is closest to the current one.
|
|
1744
|
+
const nearestInDay = (d: number): string | null => {
|
|
1745
|
+
let best: string | null = null;
|
|
1746
|
+
let bestDiff = Number.POSITIVE_INFINITY;
|
|
1747
|
+
for (const n of navByDay()[d]) {
|
|
1748
|
+
const diff = Math.abs(n.start - start);
|
|
1749
|
+
if (diff < bestDiff) {
|
|
1750
|
+
bestDiff = diff;
|
|
1751
|
+
best = n.key;
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
return best;
|
|
1755
|
+
};
|
|
1756
|
+
switch (arrowKey) {
|
|
1757
|
+
case "ArrowDown":
|
|
1758
|
+
return navByDay()[day][Math.min(pos + 1, navByDay()[day].length - 1)].key;
|
|
1759
|
+
case "ArrowUp":
|
|
1760
|
+
return navByDay()[day][Math.max(pos - 1, 0)].key;
|
|
1761
|
+
case "ArrowRight":
|
|
1762
|
+
for (let d = day + 1; d < navByDay().length; d++) {
|
|
1763
|
+
const k = nearestInDay(d);
|
|
1764
|
+
if (k) return k;
|
|
1765
|
+
}
|
|
1766
|
+
return null;
|
|
1767
|
+
case "ArrowLeft":
|
|
1768
|
+
for (let d = day - 1; d >= 0; d--) {
|
|
1769
|
+
const k = nearestInDay(d);
|
|
1770
|
+
if (k) return k;
|
|
1771
|
+
}
|
|
1772
|
+
return null;
|
|
1773
|
+
case "Home":
|
|
1774
|
+
return navByDay()[day][0].key;
|
|
1775
|
+
case "End":
|
|
1776
|
+
return navByDay()[day][navByDay()[day].length - 1].key;
|
|
1777
|
+
default:
|
|
1778
|
+
return null;
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
const onEventKeyDown = (currentKey: string, e: DomKeyboardEvent) => {
|
|
1782
|
+
const next = nextEventKey(currentKey, e.key);
|
|
1783
|
+
if (!next) return;
|
|
1784
|
+
e.preventDefault();
|
|
1785
|
+
scrollRef.current?.querySelector<HTMLElement>(`[data-event-key="${next}"]`)?.focus();
|
|
1786
|
+
};
|
|
1787
|
+
// Shade only the closed hours inside the visible window.
|
|
1788
|
+
const bandsByDay = createMemo(() =>
|
|
1789
|
+
days().map((day) => closedHourBands(day, props.businessHours, windowStart(), windowEnd())),
|
|
1790
|
+
);
|
|
1791
|
+
// `display: "background"` events, sliced per day and clipped to the window.
|
|
1792
|
+
const backgroundByDay = createMemo(() =>
|
|
1793
|
+
days().map((day) => {
|
|
1794
|
+
const seen = new Map<string, number>();
|
|
1795
|
+
return backgroundBandsForDay(props.events, day)
|
|
1796
|
+
.map((b) => ({
|
|
1797
|
+
...b,
|
|
1798
|
+
startHours: Math.max(b.startHours, windowStart()),
|
|
1799
|
+
endHours: Math.min(b.endHours, windowEnd()),
|
|
1800
|
+
}))
|
|
1801
|
+
.filter((b) => b.endHours > b.startHours)
|
|
1802
|
+
.map((b) => {
|
|
1803
|
+
const base = `bg-${b.event.start.toISOString()}-${b.event.end.toISOString()}`;
|
|
1804
|
+
const nth = (seen.get(base) ?? 0) + 1;
|
|
1805
|
+
seen.set(base, nth);
|
|
1806
|
+
return {
|
|
1807
|
+
...b,
|
|
1808
|
+
key: nth === 1 ? base : `${base}-${nth}`,
|
|
1809
|
+
};
|
|
1810
|
+
});
|
|
1811
|
+
}),
|
|
1812
|
+
);
|
|
1813
|
+
const gridLines = createMemo(() => {
|
|
1814
|
+
const hourLines = `repeating-linear-gradient(to bottom, transparent 0, transparent ${hourHeight() - 1}px, ${theme().gridLine} ${hourHeight() - 1}px, ${theme().gridLine} ${hourHeight()}px)`;
|
|
1815
|
+
if (props.timeslots <= 1) return hourLines;
|
|
1816
|
+
const slotHeight = hourHeight() / props.timeslots;
|
|
1817
|
+
return `${hourLines}, repeating-linear-gradient(to bottom, transparent 0, transparent ${slotHeight - 1}px, ${theme().gridLine}80 ${slotHeight - 1}px, ${theme().gridLine}80 ${slotHeight}px)`;
|
|
1818
|
+
});
|
|
1819
|
+
return (
|
|
1820
|
+
<div
|
|
1821
|
+
ref={(el) => (eventActions.rootRef.current = el)}
|
|
1822
|
+
tabindex={-1}
|
|
1823
|
+
class={props.className}
|
|
1824
|
+
style={css({
|
|
1825
|
+
fontFamily: theme().fontFamily,
|
|
1826
|
+
color: theme().text,
|
|
1827
|
+
display: "flex",
|
|
1828
|
+
flexDirection: "column",
|
|
1829
|
+
...props.style,
|
|
1830
|
+
})}
|
|
1831
|
+
>
|
|
1832
|
+
<EventActionsMenu
|
|
1833
|
+
events={[
|
|
1834
|
+
...new Set(
|
|
1835
|
+
positionedByDay()
|
|
1836
|
+
.flat()
|
|
1837
|
+
.filter(
|
|
1838
|
+
(pe) =>
|
|
1839
|
+
pe.startHours < windowEnd() && pe.startHours + pe.durationHours > windowStart(),
|
|
1840
|
+
)
|
|
1841
|
+
.map((pe) => pe.event),
|
|
1842
|
+
),
|
|
1843
|
+
].filter((event) => editActions(event).length > 0)}
|
|
1844
|
+
label={labels().editEvents}
|
|
1845
|
+
labelFor={(event) => labels().eventActions(event.title ?? "")}
|
|
1846
|
+
descriptionFor={eventDescription}
|
|
1847
|
+
onSelect={eventActions.select}
|
|
1848
|
+
rootRef={eventActions.rootRef}
|
|
1849
|
+
slot={slot}
|
|
1850
|
+
theme={theme()}
|
|
1851
|
+
/>
|
|
1852
|
+
{/* Header */}
|
|
1853
|
+
<div
|
|
1854
|
+
{...slot("header", {
|
|
1855
|
+
base: {
|
|
1856
|
+
display: "flex",
|
|
1857
|
+
},
|
|
1858
|
+
themed: {
|
|
1859
|
+
borderBottom: `1px solid ${theme().gridLine}`,
|
|
1860
|
+
},
|
|
1861
|
+
})}
|
|
1862
|
+
>
|
|
1863
|
+
<div
|
|
1864
|
+
{...slot("weekNumber", {
|
|
1865
|
+
base: {
|
|
1866
|
+
width: gutterWidth(),
|
|
1867
|
+
flex: "none",
|
|
1868
|
+
display: "flex",
|
|
1869
|
+
alignItems: "center",
|
|
1870
|
+
justifyContent: "center",
|
|
1871
|
+
overflow: "hidden",
|
|
1872
|
+
},
|
|
1873
|
+
themed: {
|
|
1874
|
+
fontSize: 10,
|
|
1875
|
+
color: theme().textMuted,
|
|
1876
|
+
},
|
|
1877
|
+
})}
|
|
1878
|
+
>
|
|
1879
|
+
{props.showWeekNumber && gutterWidth() > 0 && days()[0]
|
|
1880
|
+
? // Reference the visible Thursday: an ISO week is defined by its Thursday,
|
|
1881
|
+
// so a Sunday-start week (days[0] is Sunday, the previous ISO week's last
|
|
1882
|
+
// day) still shows the week number its Mon–Sat body belongs to.
|
|
1883
|
+
`${props.weekNumberPrefix}${getISOWeek(days().find((d) => d.getDay() === 4) ?? days()[0])}`
|
|
1884
|
+
: null}
|
|
1885
|
+
</div>
|
|
1886
|
+
{
|
|
1887
|
+
<For each={days()} keyed={false}>
|
|
1888
|
+
{(day) => {
|
|
1889
|
+
const today = createMemo(() => getIsToday(day()));
|
|
1890
|
+
// Full, unambiguous date for assistive tech; the visible weekday + day
|
|
1891
|
+
// number below are decorative (aria-hidden) so it isn't read twice.
|
|
1892
|
+
const dateLabel = createMemo(() => format(day(), "EEEE, d MMMM yyyy", dfns()));
|
|
1893
|
+
const headerProps = createMemo(() =>
|
|
1894
|
+
slot("columnHeader", {
|
|
1895
|
+
base: {
|
|
1896
|
+
flex: 1,
|
|
1897
|
+
border: "none",
|
|
1898
|
+
background: "transparent",
|
|
1899
|
+
font: "inherit",
|
|
1900
|
+
cursor: props.onPressDateHeader ? "pointer" : "default",
|
|
1901
|
+
display: "flex",
|
|
1902
|
+
flexDirection: "column",
|
|
1903
|
+
alignItems: "center",
|
|
1904
|
+
gap: 2,
|
|
1905
|
+
},
|
|
1906
|
+
themed: {
|
|
1907
|
+
color: theme().textMuted,
|
|
1908
|
+
padding: "6px 0",
|
|
1909
|
+
},
|
|
1910
|
+
}),
|
|
1911
|
+
);
|
|
1912
|
+
const inner = createMemo(() => (
|
|
1913
|
+
<>
|
|
1914
|
+
<span style={css(VISUALLY_HIDDEN)}>
|
|
1915
|
+
{today() ? `${dateLabel()}, ${labels().today}` : dateLabel()}
|
|
1916
|
+
</span>
|
|
1917
|
+
<span
|
|
1918
|
+
aria-hidden="true"
|
|
1919
|
+
{...slot("columnHeaderWeekday", {
|
|
1920
|
+
themed: {
|
|
1921
|
+
fontSize: 11,
|
|
1922
|
+
fontWeight: 600,
|
|
1923
|
+
},
|
|
1924
|
+
})}
|
|
1925
|
+
>
|
|
1926
|
+
{format(day(), weekdayFormatToken(props.weekdayFormat), dfns())}
|
|
1927
|
+
</span>
|
|
1928
|
+
<span
|
|
1929
|
+
aria-hidden="true"
|
|
1930
|
+
{...dataState({
|
|
1931
|
+
"data-today": today(),
|
|
1932
|
+
})}
|
|
1933
|
+
{...slot("columnHeaderDate", {
|
|
1934
|
+
base: {
|
|
1935
|
+
width: 28,
|
|
1936
|
+
height: 28,
|
|
1937
|
+
borderRadius: "50%",
|
|
1938
|
+
display: "flex",
|
|
1939
|
+
alignItems: "center",
|
|
1940
|
+
justifyContent: "center",
|
|
1941
|
+
},
|
|
1942
|
+
themed: {
|
|
1943
|
+
fontSize: 15,
|
|
1944
|
+
fontWeight: 600,
|
|
1945
|
+
background: today() ? theme().todayBackground : "transparent",
|
|
1946
|
+
color: today() ? theme().todayText : theme().text,
|
|
1947
|
+
},
|
|
1948
|
+
})}
|
|
1949
|
+
>
|
|
1950
|
+
{format(day(), "d", dfns())}
|
|
1951
|
+
</span>
|
|
1952
|
+
</>
|
|
1953
|
+
));
|
|
1954
|
+
// Interactive → a real, labeled button. Otherwise a labeled, non-focusable
|
|
1955
|
+
// element that screen readers can still announce (never `aria-hidden`, so
|
|
1956
|
+
// the day columns aren't invisible to assistive tech).
|
|
1957
|
+
return (
|
|
1958
|
+
<>
|
|
1959
|
+
{props.onPressDateHeader ? (
|
|
1960
|
+
<button
|
|
1961
|
+
type="button"
|
|
1962
|
+
onClick={() => props.onPressDateHeader?.(day())}
|
|
1963
|
+
{...dataState({
|
|
1964
|
+
"data-today": today(),
|
|
1965
|
+
})}
|
|
1966
|
+
{...headerProps()}
|
|
1967
|
+
>
|
|
1968
|
+
{inner()}
|
|
1969
|
+
</button>
|
|
1970
|
+
) : (
|
|
1971
|
+
<div
|
|
1972
|
+
{...dataState({
|
|
1973
|
+
"data-today": today(),
|
|
1974
|
+
})}
|
|
1975
|
+
{...headerProps()}
|
|
1976
|
+
>
|
|
1977
|
+
{inner()}
|
|
1978
|
+
</div>
|
|
1979
|
+
)}
|
|
1980
|
+
</>
|
|
1981
|
+
);
|
|
1982
|
+
}}
|
|
1983
|
+
</For>
|
|
1984
|
+
}
|
|
1985
|
+
</div>
|
|
1986
|
+
|
|
1987
|
+
{/* All-day lane */}
|
|
1988
|
+
{props.showAllDayEventCell && hasAllDay() ? (
|
|
1989
|
+
<div
|
|
1990
|
+
{...slot("allDayLane", {
|
|
1991
|
+
base: {
|
|
1992
|
+
display: "flex",
|
|
1993
|
+
},
|
|
1994
|
+
themed: {
|
|
1995
|
+
borderBottom: `1px solid ${theme().gridLine}`,
|
|
1996
|
+
},
|
|
1997
|
+
})}
|
|
1998
|
+
>
|
|
1999
|
+
<div
|
|
2000
|
+
{...slot("allDayLabel", {
|
|
2001
|
+
// `minWidth: 0` + `overflow: hidden` so the text doesn't spill when
|
|
2002
|
+
// `hideHours` collapses the gutter to zero width.
|
|
2003
|
+
base: {
|
|
2004
|
+
width: gutterWidth(),
|
|
2005
|
+
flex: "none",
|
|
2006
|
+
minWidth: 0,
|
|
2007
|
+
overflow: "hidden",
|
|
2008
|
+
textAlign: "right",
|
|
2009
|
+
},
|
|
2010
|
+
themed: {
|
|
2011
|
+
fontSize: 10,
|
|
2012
|
+
color: theme().textMuted,
|
|
2013
|
+
padding: "4px 6px 0 0",
|
|
2014
|
+
},
|
|
2015
|
+
})}
|
|
2016
|
+
>
|
|
2017
|
+
{props.showAllDayLabel ? labels().allDay : null}
|
|
2018
|
+
</div>
|
|
2019
|
+
{
|
|
2020
|
+
<For each={allDayByDay()} keyed={false}>
|
|
2021
|
+
{(list, i) => {
|
|
2022
|
+
const dayStart = createMemo(() => startOfDay(days()[i]));
|
|
2023
|
+
const dayEnd = createMemo(() => addDays(dayStart(), 1));
|
|
2024
|
+
return (
|
|
2025
|
+
<div
|
|
2026
|
+
{...slot("allDayColumn", {
|
|
2027
|
+
base: {
|
|
2028
|
+
flex: 1,
|
|
2029
|
+
minWidth: 0,
|
|
2030
|
+
// Mirror the day column's geometry so the all-day chip lines up
|
|
2031
|
+
// exactly with the timed events below it: a 1px left border (the
|
|
2032
|
+
// grid line, transparent here) plus a 1px horizontal inset.
|
|
2033
|
+
borderLeft: "1px solid transparent",
|
|
2034
|
+
padding: "2px 1px",
|
|
2035
|
+
display: "flex",
|
|
2036
|
+
flexDirection: "column",
|
|
2037
|
+
gap: 2,
|
|
2038
|
+
},
|
|
2039
|
+
})}
|
|
2040
|
+
>
|
|
2041
|
+
{
|
|
2042
|
+
<For each={list()} keyed={false}>
|
|
2043
|
+
{(event) => {
|
|
2044
|
+
const args = createMemo<SolidRenderEventArgs<T>>(() => ({
|
|
2045
|
+
event: event(),
|
|
2046
|
+
mode: props.mode,
|
|
2047
|
+
isAllDay: true,
|
|
2048
|
+
// Whether this all-day event continues into the previous/next
|
|
2049
|
+
// column, so custom renderers can draw continuation affordances.
|
|
2050
|
+
continuesBefore: event().start < dayStart(),
|
|
2051
|
+
continuesAfter: event().end > dayEnd(),
|
|
2052
|
+
ampm: props.ampm,
|
|
2053
|
+
onPress: () => props.onPressEvent?.(event()),
|
|
2054
|
+
}));
|
|
2055
|
+
return (
|
|
2056
|
+
<button
|
|
2057
|
+
type="button"
|
|
2058
|
+
onClick={() => props.onPressEvent?.(event())}
|
|
2059
|
+
aria-label={
|
|
2060
|
+
props.eventAccessibilityLabel
|
|
2061
|
+
? props.eventAccessibilityLabel(event(), {
|
|
2062
|
+
mode: props.mode,
|
|
2063
|
+
isAllDay: true,
|
|
2064
|
+
ampm: props.ampm,
|
|
2065
|
+
})
|
|
2066
|
+
: defaultEventAccessibilityLabel({
|
|
2067
|
+
title: event().title,
|
|
2068
|
+
isAllDay: true,
|
|
2069
|
+
start: event().start,
|
|
2070
|
+
end: event().end,
|
|
2071
|
+
ampm: props.ampm,
|
|
2072
|
+
labels: labels(),
|
|
2073
|
+
})
|
|
2074
|
+
}
|
|
2075
|
+
{...slot("allDayEvent", {
|
|
2076
|
+
base: {
|
|
2077
|
+
border: "none",
|
|
2078
|
+
padding: 0,
|
|
2079
|
+
background: "transparent",
|
|
2080
|
+
cursor: "pointer",
|
|
2081
|
+
textAlign: "left",
|
|
2082
|
+
height: 22,
|
|
2083
|
+
},
|
|
2084
|
+
})}
|
|
2085
|
+
>
|
|
2086
|
+
{Renderer() ? (
|
|
2087
|
+
<Dynamic component={Renderer()} {...args()} />
|
|
2088
|
+
) : (
|
|
2089
|
+
<DefaultDomEvent
|
|
2090
|
+
{...args()}
|
|
2091
|
+
theme={theme()}
|
|
2092
|
+
boxProps={slot("eventBox")}
|
|
2093
|
+
/>
|
|
2094
|
+
)}
|
|
2095
|
+
</button>
|
|
2096
|
+
);
|
|
2097
|
+
}}
|
|
2098
|
+
</For>
|
|
2099
|
+
}
|
|
2100
|
+
</div>
|
|
2101
|
+
);
|
|
2102
|
+
}}
|
|
2103
|
+
</For>
|
|
2104
|
+
}
|
|
2105
|
+
</div>
|
|
2106
|
+
) : null}
|
|
2107
|
+
|
|
2108
|
+
{/* Scrollable body */}
|
|
2109
|
+
<div
|
|
2110
|
+
ref={(el) => (scrollRef.current = el)}
|
|
2111
|
+
onPointerDown={onBodyPointerDown}
|
|
2112
|
+
onPointerMove={onBodyPointerMove}
|
|
2113
|
+
onPointerUp={onBodyPointerUp}
|
|
2114
|
+
onPointerCancel={onBodyPointerUp}
|
|
2115
|
+
style={css({
|
|
2116
|
+
overflowY: "auto",
|
|
2117
|
+
height: props.height,
|
|
2118
|
+
position: "relative",
|
|
2119
|
+
touchAction: props.zoomable ? "pan-y" : "auto",
|
|
2120
|
+
})}
|
|
2121
|
+
>
|
|
2122
|
+
<div
|
|
2123
|
+
ref={(el) => (columnsRef.current = el)}
|
|
2124
|
+
style={css({
|
|
2125
|
+
display: "flex",
|
|
2126
|
+
height: totalHeight(),
|
|
2127
|
+
position: "relative",
|
|
2128
|
+
})}
|
|
2129
|
+
>
|
|
2130
|
+
{/* Hour gutter (hidden when hideHours; the grid lines stay). */}
|
|
2131
|
+
{props.hideHours ? null : (
|
|
2132
|
+
<div
|
|
2133
|
+
{...slot("hourGutter", {
|
|
2134
|
+
base: {
|
|
2135
|
+
width: gutterWidth(),
|
|
2136
|
+
flex: "none",
|
|
2137
|
+
position: "relative",
|
|
2138
|
+
},
|
|
2139
|
+
})}
|
|
2140
|
+
>
|
|
2141
|
+
{
|
|
2142
|
+
<For each={visibleHours()} keyed={false}>
|
|
2143
|
+
{(h) => (
|
|
2144
|
+
<div
|
|
2145
|
+
{...slot("hourLabel", {
|
|
2146
|
+
base: {
|
|
2147
|
+
position: "absolute",
|
|
2148
|
+
// Clamp so the top-of-grid label (`h === windowStart`) sits at
|
|
2149
|
+
// the edge instead of clipping 6px above it.
|
|
2150
|
+
top: Math.max(0, (h() - windowStart()) * hourHeight() - 6),
|
|
2151
|
+
right: 6,
|
|
2152
|
+
},
|
|
2153
|
+
themed: {
|
|
2154
|
+
fontSize: 10,
|
|
2155
|
+
color: theme().textMuted,
|
|
2156
|
+
},
|
|
2157
|
+
})}
|
|
2158
|
+
>
|
|
2159
|
+
{props.hourComponent
|
|
2160
|
+
? props.hourComponent(h(), props.ampm)
|
|
2161
|
+
: h() === 0
|
|
2162
|
+
? ""
|
|
2163
|
+
: formatHour(h(), {
|
|
2164
|
+
ampm: props.ampm,
|
|
2165
|
+
})}
|
|
2166
|
+
</div>
|
|
2167
|
+
)}
|
|
2168
|
+
</For>
|
|
2169
|
+
}
|
|
2170
|
+
</div>
|
|
2171
|
+
)}
|
|
2172
|
+
|
|
2173
|
+
{/* Day columns */}
|
|
2174
|
+
{
|
|
2175
|
+
<For each={days()} keyed={false}>
|
|
2176
|
+
{(day, dayIndex) => {
|
|
2177
|
+
const positioned = createMemo(() => positionedByDay()[dayIndex]);
|
|
2178
|
+
const nowHours = createMemo(
|
|
2179
|
+
() => (now().getHours() * 60 + now().getMinutes()) / 60,
|
|
2180
|
+
);
|
|
2181
|
+
const showNow = createMemo(
|
|
2182
|
+
() =>
|
|
2183
|
+
props.showNowIndicator &&
|
|
2184
|
+
isSameCalendarDay(day(), now()) &&
|
|
2185
|
+
nowHours() >= windowStart() &&
|
|
2186
|
+
nowHours() <= windowEnd(),
|
|
2187
|
+
);
|
|
2188
|
+
const nowTop = createMemo(() => (nowHours() - windowStart()) * hourHeight());
|
|
2189
|
+
const bands = createMemo(() => bandsByDay()[dayIndex]);
|
|
2190
|
+
const ghost = createMemo(() => {
|
|
2191
|
+
const currentCreateBox = createBox();
|
|
2192
|
+
return currentCreateBox?.dayIndex === dayIndex &&
|
|
2193
|
+
currentCreateBox.dayTime === day().getTime()
|
|
2194
|
+
? currentCreateBox
|
|
2195
|
+
: null;
|
|
2196
|
+
});
|
|
2197
|
+
// What `onCreateEvent` would receive if the sweep ended here. Kept
|
|
2198
|
+
// while the range holds, so content updates only when it changes.
|
|
2199
|
+
const ghostRange = createMemo(
|
|
2200
|
+
() => {
|
|
2201
|
+
const currentGhost = ghost();
|
|
2202
|
+
return currentGhost && props.renderCreateGhost && props.onCreateEvent
|
|
2203
|
+
? cellRangeFromDrag(
|
|
2204
|
+
day(),
|
|
2205
|
+
currentGhost.startPx,
|
|
2206
|
+
currentGhost.curPx,
|
|
2207
|
+
hourHeight(),
|
|
2208
|
+
windowStart(),
|
|
2209
|
+
snapMinutes(),
|
|
2210
|
+
)
|
|
2211
|
+
: null;
|
|
2212
|
+
},
|
|
2213
|
+
{ equals: sameRange },
|
|
2214
|
+
);
|
|
2215
|
+
// The tail of a move that runs past midnight, previewed at the top of
|
|
2216
|
+
// this column. The dragged event is looked up from its `drag.key`
|
|
2217
|
+
// ("<originColumn>:<index>"), so no extra state has to track it.
|
|
2218
|
+
const spill = createMemo(() => (multiDayMove() ? null : spillPreviewFor(dayIndex)));
|
|
2219
|
+
const moveSegment = createMemo(() => {
|
|
2220
|
+
const currentMultiDayMove = multiDayMove();
|
|
2221
|
+
return currentMultiDayMove
|
|
2222
|
+
? layoutDayEvents<T>([currentMultiDayMove], day())[0]
|
|
2223
|
+
: undefined;
|
|
2224
|
+
});
|
|
2225
|
+
return (
|
|
2226
|
+
<div
|
|
2227
|
+
// Identifies the drop day for a cross-page drag hit-test.
|
|
2228
|
+
data-date={day().toISOString()}
|
|
2229
|
+
// Empty columns are a pointer-only create surface: drag to sweep
|
|
2230
|
+
// out an event. They are deliberately not tab stops, so keyboard
|
|
2231
|
+
// focus moves through events only, not every empty day.
|
|
2232
|
+
onPointerDown={cellEnabled() ? (e) => beginCreate(e, dayIndex) : undefined}
|
|
2233
|
+
onPointerMove={cellEnabled() ? moveCreate : undefined}
|
|
2234
|
+
onPointerUp={cellEnabled() ? endCreate : undefined}
|
|
2235
|
+
onPointerCancel={cellEnabled() ? cancelCreate : undefined}
|
|
2236
|
+
onLostPointerCapture={cellEnabled() ? loseCreateCapture : undefined}
|
|
2237
|
+
onClick={cellEnabled() ? (e) => tapCell(e, dayIndex) : undefined}
|
|
2238
|
+
{...dataState({
|
|
2239
|
+
"data-today": getIsToday(day()),
|
|
2240
|
+
"data-weekend": isWeekend(day()),
|
|
2241
|
+
})}
|
|
2242
|
+
{...slot("dayColumn", {
|
|
2243
|
+
base: {
|
|
2244
|
+
flex: 1,
|
|
2245
|
+
position: "relative",
|
|
2246
|
+
},
|
|
2247
|
+
// Weekend columns are tinted (matching the native renderer); the
|
|
2248
|
+
// tint sits behind the grid lines, business-hours shade and events.
|
|
2249
|
+
themed: {
|
|
2250
|
+
borderLeft: `1px solid ${theme().gridLine}`,
|
|
2251
|
+
...(props.highlightWeekends && isWeekend(day())
|
|
2252
|
+
? {
|
|
2253
|
+
background: theme().weekendBackground,
|
|
2254
|
+
}
|
|
2255
|
+
: null),
|
|
2256
|
+
},
|
|
2257
|
+
})}
|
|
2258
|
+
>
|
|
2259
|
+
{/* Business-hours shade, behind the grid lines and events. */}
|
|
2260
|
+
{
|
|
2261
|
+
<For each={bands()} keyed={false}>
|
|
2262
|
+
{(b) => (
|
|
2263
|
+
<div
|
|
2264
|
+
aria-hidden="true"
|
|
2265
|
+
{...slot("businessHours", {
|
|
2266
|
+
base: {
|
|
2267
|
+
position: "absolute",
|
|
2268
|
+
left: 0,
|
|
2269
|
+
right: 0,
|
|
2270
|
+
top: (b().start - windowStart()) * hourHeight(),
|
|
2271
|
+
height: (b().end - b().start) * hourHeight(),
|
|
2272
|
+
pointerEvents: "none",
|
|
2273
|
+
zIndex: 0,
|
|
2274
|
+
},
|
|
2275
|
+
themed: props.renderBusinessHours
|
|
2276
|
+
? undefined
|
|
2277
|
+
: {
|
|
2278
|
+
background: theme().outsideHoursBackground,
|
|
2279
|
+
},
|
|
2280
|
+
})}
|
|
2281
|
+
>
|
|
2282
|
+
{props.renderBusinessHours?.({
|
|
2283
|
+
date: day(),
|
|
2284
|
+
start: b().start,
|
|
2285
|
+
end: b().end,
|
|
2286
|
+
})}
|
|
2287
|
+
</div>
|
|
2288
|
+
)}
|
|
2289
|
+
</For>
|
|
2290
|
+
}
|
|
2291
|
+
{/* Background events: shaded time ranges, or the consumer's own band. */}
|
|
2292
|
+
{
|
|
2293
|
+
<For each={backgroundByDay()[dayIndex]} keyed={false}>
|
|
2294
|
+
{(b) => {
|
|
2295
|
+
const geometry = createMemo(() => ({
|
|
2296
|
+
position: "absolute" as const,
|
|
2297
|
+
left: 0,
|
|
2298
|
+
right: 0,
|
|
2299
|
+
top: (b().startHours - windowStart()) * hourHeight(),
|
|
2300
|
+
height: (b().endHours - b().startHours) * hourHeight(),
|
|
2301
|
+
zIndex: 0,
|
|
2302
|
+
overflow: "hidden" as const,
|
|
2303
|
+
}));
|
|
2304
|
+
return (
|
|
2305
|
+
<>
|
|
2306
|
+
{(() => {
|
|
2307
|
+
if (!RenderBackground()) {
|
|
2308
|
+
return (
|
|
2309
|
+
<div
|
|
2310
|
+
aria-hidden="true"
|
|
2311
|
+
title={b().event.title}
|
|
2312
|
+
{...slot("backgroundEvent", {
|
|
2313
|
+
base: {
|
|
2314
|
+
...geometry(),
|
|
2315
|
+
pointerEvents: "none",
|
|
2316
|
+
},
|
|
2317
|
+
themed: {
|
|
2318
|
+
background: theme().backgroundEvent,
|
|
2319
|
+
},
|
|
2320
|
+
})}
|
|
2321
|
+
/>
|
|
2322
|
+
);
|
|
2323
|
+
}
|
|
2324
|
+
const dayStart = createMemo(() => startOfDay(days()[dayIndex]));
|
|
2325
|
+
return (
|
|
2326
|
+
<div
|
|
2327
|
+
{...slot("backgroundEvent", {
|
|
2328
|
+
base: {
|
|
2329
|
+
...geometry(),
|
|
2330
|
+
pointerEvents: "auto",
|
|
2331
|
+
},
|
|
2332
|
+
})}
|
|
2333
|
+
>
|
|
2334
|
+
<Dynamic
|
|
2335
|
+
component={RenderBackground()}
|
|
2336
|
+
event={b().event}
|
|
2337
|
+
mode={props.mode}
|
|
2338
|
+
isAllDay={false}
|
|
2339
|
+
boxHeight={geometry().height}
|
|
2340
|
+
continuesBefore={b().event.start < dayStart()}
|
|
2341
|
+
continuesAfter={b().event.end > addDays(dayStart(), 1)}
|
|
2342
|
+
ampm={props.ampm}
|
|
2343
|
+
onPress={() => props.onPressEvent?.(b().event)}
|
|
2344
|
+
/>
|
|
2345
|
+
</div>
|
|
2346
|
+
);
|
|
2347
|
+
})()}
|
|
2348
|
+
</>
|
|
2349
|
+
);
|
|
2350
|
+
}}
|
|
2351
|
+
</For>
|
|
2352
|
+
}
|
|
2353
|
+
{/* Grid lines, painted over the shade so they stay visible. */}
|
|
2354
|
+
<div
|
|
2355
|
+
aria-hidden="true"
|
|
2356
|
+
{...slot("gridLines", {
|
|
2357
|
+
base: {
|
|
2358
|
+
position: "absolute",
|
|
2359
|
+
inset: 0,
|
|
2360
|
+
pointerEvents: "none",
|
|
2361
|
+
zIndex: 0,
|
|
2362
|
+
},
|
|
2363
|
+
themed: {
|
|
2364
|
+
backgroundImage: gridLines(),
|
|
2365
|
+
},
|
|
2366
|
+
})}
|
|
2367
|
+
/>
|
|
2368
|
+
{
|
|
2369
|
+
<For each={positioned()} keyed={false}>
|
|
2370
|
+
{(pe, idx) => {
|
|
2371
|
+
const key = createMemo(() => `${dayIndex}:${idx}`);
|
|
2372
|
+
// Not while paged: after a page change the origin box is gone and
|
|
2373
|
+
// the ghost stands in, so a same-slot event on the new page (e.g. a
|
|
2374
|
+
// recurring one) must not also render lifted.
|
|
2375
|
+
const active = createMemo(() => {
|
|
2376
|
+
const currentDrag = drag();
|
|
2377
|
+
return !paged() &&
|
|
2378
|
+
currentDrag?.key === key() &&
|
|
2379
|
+
(!multiDayMove() || pe().event === movingEvent())
|
|
2380
|
+
? currentDrag
|
|
2381
|
+
: null;
|
|
2382
|
+
});
|
|
2383
|
+
const hiddenForMove = createMemo(
|
|
2384
|
+
() => !!multiDayMove() && pe().event === movingEvent(),
|
|
2385
|
+
);
|
|
2386
|
+
const startHours = createMemo(() => {
|
|
2387
|
+
const currentActive = active();
|
|
2388
|
+
return currentActive ? currentActive.startHours : pe().startHours;
|
|
2389
|
+
});
|
|
2390
|
+
const durationHours = createMemo(() => {
|
|
2391
|
+
const currentActive = active();
|
|
2392
|
+
return currentActive ? currentActive.durationHours : pe().durationHours;
|
|
2393
|
+
});
|
|
2394
|
+
// Drop events that fall entirely outside the visible window; those
|
|
2395
|
+
// that straddle an edge render clipped by the scroll container.
|
|
2396
|
+
const outside = createMemo(
|
|
2397
|
+
() =>
|
|
2398
|
+
!active() &&
|
|
2399
|
+
(pe().startHours >= windowEnd() ||
|
|
2400
|
+
pe().startHours + pe().durationHours <= windowStart()),
|
|
2401
|
+
);
|
|
2402
|
+
return (
|
|
2403
|
+
<>
|
|
2404
|
+
{(() => {
|
|
2405
|
+
if (outside()) return null;
|
|
2406
|
+
const top = createMemo(
|
|
2407
|
+
() => (startHours() - windowStart()) * hourHeight(),
|
|
2408
|
+
);
|
|
2409
|
+
// A drag that runs past midnight is cut off at the day boundary
|
|
2410
|
+
// (a move previews the remainder in the next column). Applied to
|
|
2411
|
+
// resting boxes too, where `layoutDayEvents` has already clipped
|
|
2412
|
+
// them to the day, so the height doesn't jump on commit.
|
|
2413
|
+
const boxHeight = createMemo(() =>
|
|
2414
|
+
Math.max(
|
|
2415
|
+
Math.min(durationHours(), HOURS_PER_DAY - startHours()) *
|
|
2416
|
+
hourHeight(),
|
|
2417
|
+
props.minEventHeight,
|
|
2418
|
+
),
|
|
2419
|
+
);
|
|
2420
|
+
const widthPct = createMemo(() => 100 / pe().columns);
|
|
2421
|
+
const onPress = () => props.onPressEvent?.(pe().event);
|
|
2422
|
+
const args = createMemo<SolidRenderEventArgs<T>>(() => ({
|
|
2423
|
+
event: pe().event,
|
|
2424
|
+
mode: props.mode,
|
|
2425
|
+
isAllDay: false,
|
|
2426
|
+
boxHeight: boxHeight(),
|
|
2427
|
+
continuesBefore: pe().continuesBefore,
|
|
2428
|
+
continuesAfter: pe().continuesAfter,
|
|
2429
|
+
ampm: props.ampm,
|
|
2430
|
+
onPress,
|
|
2431
|
+
}));
|
|
2432
|
+
// `draggable: false` locks a single event: it keeps its normal
|
|
2433
|
+
// look and still responds to clicks, it just can't be dragged.
|
|
2434
|
+
// `startEditable`/`durationEditable` (per-event, falling back to
|
|
2435
|
+
// the grid props) split whether it can be moved vs resized.
|
|
2436
|
+
const editable = createMemo(
|
|
2437
|
+
() => !!props.onDragEvent && pe().event.draggable !== false,
|
|
2438
|
+
);
|
|
2439
|
+
const canMove = createMemo(
|
|
2440
|
+
() =>
|
|
2441
|
+
editable() &&
|
|
2442
|
+
(pe().event.startEditable ?? props.eventStartEditable),
|
|
2443
|
+
);
|
|
2444
|
+
const canResize = createMemo(
|
|
2445
|
+
() =>
|
|
2446
|
+
editable() &&
|
|
2447
|
+
(pe().event.durationEditable ?? props.eventDurationEditable),
|
|
2448
|
+
);
|
|
2449
|
+
return (
|
|
2450
|
+
<div
|
|
2451
|
+
role="button"
|
|
2452
|
+
// Always a tab stop: keyboard nav is additive, arrows only add a
|
|
2453
|
+
// faster path between events without removing any from Tab order.
|
|
2454
|
+
tabindex={0}
|
|
2455
|
+
data-event-key={
|
|
2456
|
+
props.keyboardEventNavigation ? key() : undefined
|
|
2457
|
+
}
|
|
2458
|
+
aria-label={eventLabel(pe().event)}
|
|
2459
|
+
onKeyDown={(e) => {
|
|
2460
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2461
|
+
e.preventDefault();
|
|
2462
|
+
onPress();
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
if (props.keyboardEventNavigation) onEventKeyDown(key(), e);
|
|
2466
|
+
}}
|
|
2467
|
+
// Pointer move/up/cancel are handled at the document level
|
|
2468
|
+
// (attached in beginDrag) so the drag survives the columns
|
|
2469
|
+
// remounting on a page change.
|
|
2470
|
+
onPointerDown={
|
|
2471
|
+
canMove()
|
|
2472
|
+
? (e) =>
|
|
2473
|
+
pressEvent(e, pe(), key(), "move", dayIndex, onPress)
|
|
2474
|
+
: undefined
|
|
2475
|
+
}
|
|
2476
|
+
onClick={
|
|
2477
|
+
canMove()
|
|
2478
|
+
? (e) => {
|
|
2479
|
+
if (
|
|
2480
|
+
e.detail === 0 ||
|
|
2481
|
+
(tappedRef.current &&
|
|
2482
|
+
e.currentTarget.contains(tappedRef.current))
|
|
2483
|
+
) {
|
|
2484
|
+
tappedRef.current = null;
|
|
2485
|
+
onPress();
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
: onPress
|
|
2489
|
+
}
|
|
2490
|
+
{...dataState({
|
|
2491
|
+
"data-dragging": !!active() && !hiddenForMove(),
|
|
2492
|
+
})}
|
|
2493
|
+
{...slot("event", {
|
|
2494
|
+
base: {
|
|
2495
|
+
position: "absolute",
|
|
2496
|
+
top: top(),
|
|
2497
|
+
// Height is the event's duration, so it always tracks the
|
|
2498
|
+
// grid's hour scale (zoom/resize). Content that doesn't fit
|
|
2499
|
+
// is the renderer's concern: the built-in one clamps, and a
|
|
2500
|
+
// custom renderer should adapt to the `boxHeight` it's given.
|
|
2501
|
+
height: boxHeight(),
|
|
2502
|
+
left: `calc(${pe().column * widthPct()}% + ${props.eventGap}px)`,
|
|
2503
|
+
width: `calc(${widthPct()}% - ${props.eventGap * 2}px)`,
|
|
2504
|
+
cursor: canMove() ? "grab" : "pointer",
|
|
2505
|
+
touchAction: canMove() ? "pan-y" : "auto",
|
|
2506
|
+
userSelect: canMove() ? "none" : undefined,
|
|
2507
|
+
WebkitTouchCallout: canMove() ? "none" : undefined,
|
|
2508
|
+
zIndex: active() ? 3 : 1,
|
|
2509
|
+
opacity: active() ? 0.85 : 1,
|
|
2510
|
+
visibility: hiddenForMove() ? "hidden" : undefined,
|
|
2511
|
+
// Snap the dragged box over the target day column so the
|
|
2512
|
+
// drop location is visible before release.
|
|
2513
|
+
...(active() && active()?.dayOffsetPx !== 0
|
|
2514
|
+
? {
|
|
2515
|
+
transform: `translateX(${active()?.dayOffsetPx}px)`,
|
|
2516
|
+
}
|
|
2517
|
+
: null),
|
|
2518
|
+
},
|
|
2519
|
+
})}
|
|
2520
|
+
>
|
|
2521
|
+
{Renderer() ? (
|
|
2522
|
+
<Dynamic component={Renderer()} {...args()} />
|
|
2523
|
+
) : (
|
|
2524
|
+
<DefaultDomEvent
|
|
2525
|
+
{...args()}
|
|
2526
|
+
theme={theme()}
|
|
2527
|
+
boxProps={slot("eventBox")}
|
|
2528
|
+
/>
|
|
2529
|
+
)}
|
|
2530
|
+
{/* A release without movement on a handle presses the event, like
|
|
2531
|
+
the box itself. Only when the box can move: otherwise it carries
|
|
2532
|
+
its own `onClick`, which would press the event a second time. */}
|
|
2533
|
+
{canResize() && !pe().continuesBefore ? (
|
|
2534
|
+
<div
|
|
2535
|
+
onPointerDown={(e) => {
|
|
2536
|
+
pressEvent(
|
|
2537
|
+
e,
|
|
2538
|
+
pe(),
|
|
2539
|
+
key(),
|
|
2540
|
+
"resize-start",
|
|
2541
|
+
dayIndex,
|
|
2542
|
+
canMove() ? onPress : undefined,
|
|
2543
|
+
);
|
|
2544
|
+
}}
|
|
2545
|
+
style={css({
|
|
2546
|
+
position: "absolute",
|
|
2547
|
+
left: 0,
|
|
2548
|
+
right: 0,
|
|
2549
|
+
top: 0,
|
|
2550
|
+
height: 8,
|
|
2551
|
+
cursor: "ns-resize",
|
|
2552
|
+
touchAction: "pan-y",
|
|
2553
|
+
})}
|
|
2554
|
+
/>
|
|
2555
|
+
) : null}
|
|
2556
|
+
{/* Only the segment that owns the real end may be resized
|
|
2557
|
+
from the bottom (matching the native renderer). On a
|
|
2558
|
+
continued segment the bottom edge is the day boundary,
|
|
2559
|
+
not the event's end, so dragging it would move an end
|
|
2560
|
+
the user can't see. */}
|
|
2561
|
+
{canResize() && !pe().continuesAfter ? (
|
|
2562
|
+
<div
|
|
2563
|
+
onPointerDown={(e) => {
|
|
2564
|
+
pressEvent(
|
|
2565
|
+
e,
|
|
2566
|
+
pe(),
|
|
2567
|
+
key(),
|
|
2568
|
+
"resize",
|
|
2569
|
+
dayIndex,
|
|
2570
|
+
canMove() ? onPress : undefined,
|
|
2571
|
+
);
|
|
2572
|
+
}}
|
|
2573
|
+
style={css({
|
|
2574
|
+
position: "absolute",
|
|
2575
|
+
left: 0,
|
|
2576
|
+
right: 0,
|
|
2577
|
+
bottom: 0,
|
|
2578
|
+
height: 8,
|
|
2579
|
+
cursor: "ns-resize",
|
|
2580
|
+
touchAction: "pan-y",
|
|
2581
|
+
})}
|
|
2582
|
+
/>
|
|
2583
|
+
) : null}
|
|
2584
|
+
</div>
|
|
2585
|
+
);
|
|
2586
|
+
})()}
|
|
2587
|
+
</>
|
|
2588
|
+
);
|
|
2589
|
+
}}
|
|
2590
|
+
</For>
|
|
2591
|
+
}
|
|
2592
|
+
{
|
|
2593
|
+
<Show when={moveSegment()}>
|
|
2594
|
+
{(moveSegment) => (
|
|
2595
|
+
<div
|
|
2596
|
+
aria-hidden="true"
|
|
2597
|
+
{...dataState({
|
|
2598
|
+
"data-dragging": true,
|
|
2599
|
+
})}
|
|
2600
|
+
{...slot("event", {
|
|
2601
|
+
base: {
|
|
2602
|
+
position: "absolute",
|
|
2603
|
+
top: (moveSegment().startHours - windowStart()) * hourHeight(),
|
|
2604
|
+
left: props.eventGap,
|
|
2605
|
+
right: props.eventGap,
|
|
2606
|
+
height: Math.max(
|
|
2607
|
+
moveSegment().durationHours * hourHeight(),
|
|
2608
|
+
props.minEventHeight,
|
|
2609
|
+
),
|
|
2610
|
+
pointerEvents: "none",
|
|
2611
|
+
zIndex: 3,
|
|
2612
|
+
opacity: 0.85,
|
|
2613
|
+
},
|
|
2614
|
+
})}
|
|
2615
|
+
>
|
|
2616
|
+
{(() => {
|
|
2617
|
+
const args: SolidRenderEventArgs<T> = {
|
|
2618
|
+
event: moveSegment().event,
|
|
2619
|
+
mode: props.mode,
|
|
2620
|
+
isAllDay: false,
|
|
2621
|
+
boxHeight: Math.max(
|
|
2622
|
+
moveSegment().durationHours * hourHeight(),
|
|
2623
|
+
props.minEventHeight,
|
|
2624
|
+
),
|
|
2625
|
+
continuesBefore: moveSegment().continuesBefore,
|
|
2626
|
+
continuesAfter: moveSegment().continuesAfter,
|
|
2627
|
+
ampm: props.ampm,
|
|
2628
|
+
onPress: () => {},
|
|
2629
|
+
};
|
|
2630
|
+
return (
|
|
2631
|
+
<>
|
|
2632
|
+
{Renderer() ? (
|
|
2633
|
+
<Dynamic component={Renderer()} {...args} />
|
|
2634
|
+
) : (
|
|
2635
|
+
<DefaultDomEvent
|
|
2636
|
+
{...args}
|
|
2637
|
+
theme={theme()}
|
|
2638
|
+
boxProps={slot("eventBox")}
|
|
2639
|
+
/>
|
|
2640
|
+
)}
|
|
2641
|
+
</>
|
|
2642
|
+
);
|
|
2643
|
+
})()}
|
|
2644
|
+
</div>
|
|
2645
|
+
)}
|
|
2646
|
+
</Show>
|
|
2647
|
+
}
|
|
2648
|
+
{
|
|
2649
|
+
<Show when={spill()}>
|
|
2650
|
+
{(spill) => (
|
|
2651
|
+
<div
|
|
2652
|
+
aria-hidden="true"
|
|
2653
|
+
{...dataState({
|
|
2654
|
+
"data-dragging": true,
|
|
2655
|
+
})}
|
|
2656
|
+
{...slot("event", {
|
|
2657
|
+
base: {
|
|
2658
|
+
position: "absolute",
|
|
2659
|
+
// Anchored at midnight, which sits `windowStart` hours above
|
|
2660
|
+
// the top of the grid. With a window that starts after 00:00
|
|
2661
|
+
// the preview is scrolled out of view, exactly like the
|
|
2662
|
+
// continuation the drop will commit.
|
|
2663
|
+
top: -windowStart() * hourHeight(),
|
|
2664
|
+
left: props.eventGap,
|
|
2665
|
+
right: props.eventGap,
|
|
2666
|
+
height: spill().boxHeight,
|
|
2667
|
+
pointerEvents: "none",
|
|
2668
|
+
zIndex: 3,
|
|
2669
|
+
opacity: 0.85,
|
|
2670
|
+
},
|
|
2671
|
+
})}
|
|
2672
|
+
>
|
|
2673
|
+
{Renderer() ? (
|
|
2674
|
+
<Dynamic component={Renderer()} {...spill()} />
|
|
2675
|
+
) : (
|
|
2676
|
+
<DefaultDomEvent
|
|
2677
|
+
{...spill()}
|
|
2678
|
+
theme={theme()}
|
|
2679
|
+
boxProps={slot("eventBox")}
|
|
2680
|
+
/>
|
|
2681
|
+
)}
|
|
2682
|
+
</div>
|
|
2683
|
+
)}
|
|
2684
|
+
</Show>
|
|
2685
|
+
}
|
|
2686
|
+
{showNow() ? (
|
|
2687
|
+
<div
|
|
2688
|
+
{...slot("nowIndicator", {
|
|
2689
|
+
base: {
|
|
2690
|
+
position: "absolute",
|
|
2691
|
+
top: nowTop(),
|
|
2692
|
+
left: 0,
|
|
2693
|
+
right: 0,
|
|
2694
|
+
height: 0,
|
|
2695
|
+
zIndex: 2,
|
|
2696
|
+
pointerEvents: "none",
|
|
2697
|
+
},
|
|
2698
|
+
})}
|
|
2699
|
+
>
|
|
2700
|
+
<div
|
|
2701
|
+
style={css({
|
|
2702
|
+
height: 2,
|
|
2703
|
+
background: theme().nowIndicator,
|
|
2704
|
+
})}
|
|
2705
|
+
/>
|
|
2706
|
+
<div
|
|
2707
|
+
style={css({
|
|
2708
|
+
position: "absolute",
|
|
2709
|
+
left: -3,
|
|
2710
|
+
top: -3,
|
|
2711
|
+
width: 8,
|
|
2712
|
+
height: 8,
|
|
2713
|
+
borderRadius: "50%",
|
|
2714
|
+
background: theme().nowIndicator,
|
|
2715
|
+
})}
|
|
2716
|
+
/>
|
|
2717
|
+
</div>
|
|
2718
|
+
) : null}
|
|
2719
|
+
{
|
|
2720
|
+
<Show when={ghost()}>
|
|
2721
|
+
{(ghost) => (
|
|
2722
|
+
<div
|
|
2723
|
+
aria-hidden="true"
|
|
2724
|
+
// Custom content stays out of the tab order and pointer input.
|
|
2725
|
+
inert={ghostRange() ? true : undefined}
|
|
2726
|
+
{...slot("createGhost", {
|
|
2727
|
+
base: {
|
|
2728
|
+
position: "absolute",
|
|
2729
|
+
left: props.eventGap,
|
|
2730
|
+
right: props.eventGap,
|
|
2731
|
+
...createPreviewPlacement(
|
|
2732
|
+
Math.min(ghost().startPx, ghost().curPx),
|
|
2733
|
+
Math.abs(ghost().curPx - ghost().startPx),
|
|
2734
|
+
totalHeight(),
|
|
2735
|
+
),
|
|
2736
|
+
// Borders, including custom ones, stay inside the placed box.
|
|
2737
|
+
boxSizing: "border-box",
|
|
2738
|
+
...(ghostRange() ? { overflow: "hidden" } : null),
|
|
2739
|
+
opacity: 0.7,
|
|
2740
|
+
pointerEvents: "none",
|
|
2741
|
+
zIndex: 2,
|
|
2742
|
+
},
|
|
2743
|
+
themed: {
|
|
2744
|
+
background: theme().rangeBackground,
|
|
2745
|
+
border: `1px solid ${theme().selectedBackground}`,
|
|
2746
|
+
borderRadius: 6,
|
|
2747
|
+
},
|
|
2748
|
+
})}
|
|
2749
|
+
>
|
|
2750
|
+
<Show when={ghostRange()}>
|
|
2751
|
+
{(range) => (
|
|
2752
|
+
<Dynamic
|
|
2753
|
+
component={props.renderCreateGhost}
|
|
2754
|
+
start={range().start}
|
|
2755
|
+
end={range().end}
|
|
2756
|
+
/>
|
|
2757
|
+
)}
|
|
2758
|
+
</Show>
|
|
2759
|
+
</div>
|
|
2760
|
+
)}
|
|
2761
|
+
</Show>
|
|
2762
|
+
}
|
|
2763
|
+
</div>
|
|
2764
|
+
);
|
|
2765
|
+
}}
|
|
2766
|
+
</For>
|
|
2767
|
+
}
|
|
2768
|
+
</div>
|
|
2769
|
+
</div>
|
|
2770
|
+
{/* Floating drag ghost: shown only after a page change, when the dragged
|
|
2771
|
+
event's own column has unmounted. Positioned imperatively per pointer
|
|
2772
|
+
move (see moveDrag) and pointer-transparent so the drop hit-test reads
|
|
2773
|
+
the column beneath it. */}
|
|
2774
|
+
{paged() && draggedRef.current ? (
|
|
2775
|
+
<div
|
|
2776
|
+
ref={(el) => (ghostRef.current = el)}
|
|
2777
|
+
aria-hidden="true"
|
|
2778
|
+
style={css({
|
|
2779
|
+
position: "fixed",
|
|
2780
|
+
left: 0,
|
|
2781
|
+
top: 0,
|
|
2782
|
+
width: draggedRef.current.w,
|
|
2783
|
+
height: draggedRef.current.h,
|
|
2784
|
+
transform: `translate(${ptr.current.x - draggedRef.current.grabX}px, ${ptr.current.y - draggedRef.current.grabY}px)`,
|
|
2785
|
+
pointerEvents: "none",
|
|
2786
|
+
zIndex: 1000,
|
|
2787
|
+
opacity: 0.85,
|
|
2788
|
+
})}
|
|
2789
|
+
>
|
|
2790
|
+
{Renderer() ? (
|
|
2791
|
+
<Dynamic
|
|
2792
|
+
component={Renderer()}
|
|
2793
|
+
event={draggedRef.current.event}
|
|
2794
|
+
mode={props.mode}
|
|
2795
|
+
isAllDay={false}
|
|
2796
|
+
boxHeight={draggedRef.current.h}
|
|
2797
|
+
ampm={props.ampm}
|
|
2798
|
+
onPress={() => {}}
|
|
2799
|
+
/>
|
|
2800
|
+
) : (
|
|
2801
|
+
<DefaultDomEvent
|
|
2802
|
+
event={draggedRef.current.event}
|
|
2803
|
+
mode={props.mode}
|
|
2804
|
+
isAllDay={false}
|
|
2805
|
+
boxHeight={draggedRef.current.h}
|
|
2806
|
+
ampm={props.ampm}
|
|
2807
|
+
onPress={() => {}}
|
|
2808
|
+
theme={theme()}
|
|
2809
|
+
boxProps={slot("eventBox")}
|
|
2810
|
+
/>
|
|
2811
|
+
)}
|
|
2812
|
+
</div>
|
|
2813
|
+
) : null}
|
|
2814
|
+
<Show when={eventActions.openEvent()}>
|
|
2815
|
+
{(event) => (
|
|
2816
|
+
<EventActionsDialog
|
|
2817
|
+
dialogRef={eventActions.dialogRef}
|
|
2818
|
+
title={labels().eventActions(event().title ?? "")}
|
|
2819
|
+
description={eventDescription(event())}
|
|
2820
|
+
actions={editActions(event())}
|
|
2821
|
+
closeLabel={labels().close}
|
|
2822
|
+
rejectedLabel={labels().eventChangeRejected}
|
|
2823
|
+
rejections={eventActions.rejections()}
|
|
2824
|
+
onAction={eventActions.run}
|
|
2825
|
+
onClose={() => eventActions.close(true)}
|
|
2826
|
+
slot={slot}
|
|
2827
|
+
theme={theme()}
|
|
2828
|
+
/>
|
|
2829
|
+
)}
|
|
2830
|
+
</Show>
|
|
2831
|
+
</div>
|
|
2832
|
+
);
|
|
2833
|
+
}
|