@remit/ui 0.0.224 → 0.0.225
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/dist/components/app-shell-slotted.js +1 -1
- package/dist/components/app-switcher.d.ts +15 -0
- package/dist/components/app-switcher.js +31 -0
- package/dist/components/calendar-event-popup.d.ts +43 -0
- package/dist/components/calendar-event-popup.js +18 -0
- package/dist/components/calendar-event-sidebar.d.ts +34 -0
- package/dist/components/calendar-event-sidebar.js +16 -0
- package/dist/components/calendar-grid.d.ts +8 -7
- package/dist/components/calendar-grid.js +39 -108
- package/dist/components/calendar-popover.d.ts +25 -0
- package/dist/components/calendar-popover.js +84 -0
- package/dist/components/calendar-quick-create.d.ts +35 -0
- package/dist/components/calendar-quick-create.js +26 -0
- package/dist/components/calendar-screen-toolbar.d.ts +30 -0
- package/dist/components/calendar-screen-toolbar.js +24 -0
- package/dist/components/calendar-sheet.d.ts +14 -0
- package/dist/components/calendar-sheet.js +34 -0
- package/dist/components/calendar-side-pane.d.ts +20 -0
- package/dist/components/calendar-side-pane.js +11 -0
- package/dist/components/calendar-time-grid.d.ts +64 -0
- package/dist/components/calendar-time-grid.js +666 -0
- package/dist/components/calendar-toolbar.d.ts +0 -31
- package/dist/components/calendar-toolbar.js +0 -27
- package/dist/components/calendar-year.d.ts +11 -0
- package/dist/components/calendar-year.js +9 -0
- package/dist/components/compose-fab.js +3 -1
- package/dist/components/mini-month.d.ts +19 -0
- package/dist/components/mini-month.js +34 -0
- package/dist/index.d.ts +19 -3
- package/dist/index.js +19 -3
- package/dist/lib/calendar-range.d.ts +10 -0
- package/dist/lib/calendar-range.js +39 -0
- package/dist/lib/calendar-slot-pick.d.ts +29 -0
- package/dist/lib/calendar-slot-pick.js +67 -0
- package/dist/lib/event-drag.d.ts +20 -0
- package/dist/lib/event-drag.js +50 -0
- package/dist/lib/grid-keyboard.d.ts +15 -0
- package/dist/lib/grid-keyboard.js +46 -0
- package/dist/lib/iso-week.d.ts +2 -0
- package/dist/lib/iso-week.js +13 -0
- package/dist/lib/long-press.d.ts +25 -0
- package/dist/lib/long-press.js +37 -0
- package/dist/lib/mini-month.d.ts +27 -0
- package/dist/lib/mini-month.js +33 -0
- package/dist/lib/popup-placement.d.ts +22 -0
- package/dist/lib/popup-placement.js +39 -0
- package/dist/lib/time-grid-layout.d.ts +38 -0
- package/dist/lib/time-grid-layout.js +94 -0
- package/package.json +1 -1
- package/dist/components/event-detail.d.ts +0 -38
- package/dist/components/event-detail.js +0 -21
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { TriangleAlert } from "lucide-react";
|
|
3
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { calendarColorClasses } from "../lib/calendar-color.js";
|
|
5
|
+
import { calendarEventBodyClasses } from "../lib/calendar-event-shell.js";
|
|
6
|
+
import { allDayRange, clickRange, isDrag, minuteAt, rangeMinutes, timedRange, } from "../lib/calendar-slot-pick.js";
|
|
7
|
+
import { cn } from "../lib/cn.js";
|
|
8
|
+
import { moveDays, moveTimed, resizeDays, resizeTimed, snappedMinutes, } from "../lib/event-drag.js";
|
|
9
|
+
import { initialFocus, moveFocus, stretchRange, } from "../lib/grid-keyboard.js";
|
|
10
|
+
import { HOLD_MS, pressMove, pressStart, pressTick, stepHandle, } from "../lib/long-press.js";
|
|
11
|
+
import { layoutAllDay, layoutDay, zonedMoment, } from "../lib/time-grid-layout.js";
|
|
12
|
+
import { CalendarEventChipContent } from "./calendar-event-chip-content.js";
|
|
13
|
+
const HOUR_HEIGHT = { comfortable: 48, compact: 24 };
|
|
14
|
+
const HOURS = Array.from({ length: 24 }, (_, hour) => hour);
|
|
15
|
+
const ALL_DAY_LANE = 22;
|
|
16
|
+
const FALLBACK_COLOR = "cal-1";
|
|
17
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
18
|
+
const clock = (minute) => `${pad(Math.floor(minute / 60) % 24)}:${pad(minute % 60)}`;
|
|
19
|
+
const dayLabel = (date, options) => new Intl.DateTimeFormat(undefined, { ...options, timeZone: "UTC" }).format(new Date(`${date}T00:00:00Z`));
|
|
20
|
+
/** "Wednesday 4 November, 08:00 to 09:45", for the live region and the focused slot. */
|
|
21
|
+
export function describeRange(range) {
|
|
22
|
+
const first = dayLabel(range.date, {
|
|
23
|
+
weekday: "long",
|
|
24
|
+
day: "numeric",
|
|
25
|
+
month: "long",
|
|
26
|
+
});
|
|
27
|
+
if (range.allDay) {
|
|
28
|
+
if (range.endDate === range.date)
|
|
29
|
+
return `${first}, all day`;
|
|
30
|
+
return `${first} to ${dayLabel(range.endDate, { weekday: "long", day: "numeric", month: "long" })}, all day`;
|
|
31
|
+
}
|
|
32
|
+
return `${first}, ${range.startTime} to ${range.endTime}`;
|
|
33
|
+
}
|
|
34
|
+
function zoneLabel(timeZone, now) {
|
|
35
|
+
const part = new Intl.DateTimeFormat("en-GB", {
|
|
36
|
+
timeZone,
|
|
37
|
+
timeZoneName: "short",
|
|
38
|
+
})
|
|
39
|
+
.formatToParts(new Date(now))
|
|
40
|
+
.find((candidate) => candidate.type === "timeZoneName");
|
|
41
|
+
return part?.value ?? "";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A day or a week of time, drawn by the kit rather than a calendar engine, so
|
|
45
|
+
* a press, a drag, a hold and the keyboard all reach the grid the same way.
|
|
46
|
+
* Every gesture leaves through `onGesture`; the grid only draws the draft it
|
|
47
|
+
* is handed.
|
|
48
|
+
*/
|
|
49
|
+
export function CalendarTimeGrid({ days, events, colorByCalendarId, density, timeZone, now, selectedEventId = "", draft, onGesture, onSelectEvent, onOpenDay, touch = false, canMove = () => false, onMoveEvent, className, }) {
|
|
50
|
+
const hourHeight = HOUR_HEIGHT[density];
|
|
51
|
+
const scrollRef = useRef(null);
|
|
52
|
+
const columnsRef = useRef(null);
|
|
53
|
+
const allDayRef = useRef(null);
|
|
54
|
+
const gesture = useRef(null);
|
|
55
|
+
const press = useRef(null);
|
|
56
|
+
const holdTimer = useRef(undefined);
|
|
57
|
+
const [focusSlot, setFocusSlot] = useState(null);
|
|
58
|
+
const [stretchAnchor, setStretchAnchor] = useState(null);
|
|
59
|
+
const [hasFocus, setHasFocus] = useState(false);
|
|
60
|
+
const [live, setLive] = useState("");
|
|
61
|
+
const focusCellId = useId();
|
|
62
|
+
const today = zonedMoment(now, timeZone);
|
|
63
|
+
const zoned = useMemo(() => events.map((event) => ({
|
|
64
|
+
event,
|
|
65
|
+
start: zonedMoment(event.start, timeZone),
|
|
66
|
+
end: zonedMoment(event.end, timeZone),
|
|
67
|
+
})), [events, timeZone]);
|
|
68
|
+
const timed = zoned.filter((entry) => !entry.event.allDay);
|
|
69
|
+
const allDay = zoned.filter((entry) => entry.event.allDay);
|
|
70
|
+
const byId = useMemo(() => new Map(zoned.map((entry) => [entry.event.id, entry.event])), [zoned]);
|
|
71
|
+
const bars = layoutAllDay(days, allDay.map((entry) => ({
|
|
72
|
+
id: entry.event.id,
|
|
73
|
+
first: entry.event.start.slice(0, 10),
|
|
74
|
+
last: lastDayOf(entry.event),
|
|
75
|
+
})));
|
|
76
|
+
const draftBar = draft?.range.allDay === true
|
|
77
|
+
? layoutAllDay(days, [
|
|
78
|
+
{ id: "draft", first: draft.range.date, last: draft.range.endDate },
|
|
79
|
+
])[0]
|
|
80
|
+
: undefined;
|
|
81
|
+
const laneCount = Math.max(1, ...bars.map((bar) => bar.lane + 1), draftBar ? 1 : 0);
|
|
82
|
+
const rangeKey = days.join(",");
|
|
83
|
+
const firstScroll = days.includes(today.date)
|
|
84
|
+
? Math.max(0, today.minute - 90)
|
|
85
|
+
: 8 * 60;
|
|
86
|
+
const firstScrollRef = useRef(firstScroll);
|
|
87
|
+
firstScrollRef.current = firstScroll;
|
|
88
|
+
useLayoutEffect(() => {
|
|
89
|
+
const scroller = scrollRef.current;
|
|
90
|
+
if (!scroller || rangeKey === "")
|
|
91
|
+
return;
|
|
92
|
+
scroller.scrollTop = (firstScrollRef.current / 60) * hourHeight;
|
|
93
|
+
}, [rangeKey, hourHeight]);
|
|
94
|
+
const rootRef = useRef(null);
|
|
95
|
+
const lift = useRef(null);
|
|
96
|
+
const liftTimer = useRef(undefined);
|
|
97
|
+
const suppressClick = useRef(false);
|
|
98
|
+
const [lifted, setLifted] = useState(null);
|
|
99
|
+
const endLift = useCallback(() => {
|
|
100
|
+
lift.current = null;
|
|
101
|
+
clearTimeout(liftTimer.current);
|
|
102
|
+
setLifted(null);
|
|
103
|
+
}, []);
|
|
104
|
+
const endGesture = useCallback(() => {
|
|
105
|
+
gesture.current = null;
|
|
106
|
+
press.current = null;
|
|
107
|
+
clearTimeout(holdTimer.current);
|
|
108
|
+
}, []);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
const onKey = (event) => {
|
|
111
|
+
if (event.key !== "Escape")
|
|
112
|
+
return;
|
|
113
|
+
if (lift.current?.dragging) {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
event.stopImmediatePropagation();
|
|
116
|
+
suppressClick.current = true;
|
|
117
|
+
endLift();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!gesture.current)
|
|
121
|
+
return;
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
event.stopImmediatePropagation();
|
|
124
|
+
endGesture();
|
|
125
|
+
onGesture({ type: "drag-cancel" });
|
|
126
|
+
};
|
|
127
|
+
window.addEventListener("keydown", onKey, true);
|
|
128
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
129
|
+
}, [endGesture, endLift, onGesture]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const scroller = scrollRef.current;
|
|
132
|
+
if (!scroller)
|
|
133
|
+
return;
|
|
134
|
+
const holdScroll = (event) => {
|
|
135
|
+
if (press.current?.phase === "held" ||
|
|
136
|
+
gesture.current?.dragging ||
|
|
137
|
+
lift.current?.dragging)
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
};
|
|
140
|
+
scroller.addEventListener("touchmove", holdScroll, { passive: false });
|
|
141
|
+
return () => scroller.removeEventListener("touchmove", holdScroll);
|
|
142
|
+
}, []);
|
|
143
|
+
const columnAt = (clientX) => {
|
|
144
|
+
const container = columnsRef.current;
|
|
145
|
+
if (!container)
|
|
146
|
+
return undefined;
|
|
147
|
+
const box = container.getBoundingClientRect();
|
|
148
|
+
const index = Math.floor(((clientX - box.left) / box.width) * days.length);
|
|
149
|
+
return days[Math.min(days.length - 1, Math.max(0, index))];
|
|
150
|
+
};
|
|
151
|
+
const minuteOf = (clientY) => {
|
|
152
|
+
const container = columnsRef.current;
|
|
153
|
+
if (!container)
|
|
154
|
+
return 0;
|
|
155
|
+
return minuteAt(clientY - container.getBoundingClientRect().top, hourHeight);
|
|
156
|
+
};
|
|
157
|
+
const announce = (range) => setLive(describeRange(range));
|
|
158
|
+
const startLift = (event, data, kind) => {
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
if (event.button !== 0 || !canMove(data.id) || !onMoveEvent)
|
|
161
|
+
return;
|
|
162
|
+
const column = columnAt(event.clientX);
|
|
163
|
+
if (!column)
|
|
164
|
+
return;
|
|
165
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
166
|
+
const byFinger = touch && event.pointerType === "touch";
|
|
167
|
+
lift.current = {
|
|
168
|
+
id: data.id,
|
|
169
|
+
kind,
|
|
170
|
+
allDay: data.allDay,
|
|
171
|
+
pointerId: event.pointerId,
|
|
172
|
+
x: event.clientX,
|
|
173
|
+
y: event.clientY,
|
|
174
|
+
startColumn: column,
|
|
175
|
+
start: zonedMoment(data.start, timeZone),
|
|
176
|
+
end: zonedMoment(data.end, timeZone),
|
|
177
|
+
first: data.start.slice(0, 10),
|
|
178
|
+
last: lastDayOf(data),
|
|
179
|
+
dragging: false,
|
|
180
|
+
press: byFinger
|
|
181
|
+
? pressStart(event.clientX, event.clientY, Date.now())
|
|
182
|
+
: null,
|
|
183
|
+
range: null,
|
|
184
|
+
invalid: false,
|
|
185
|
+
};
|
|
186
|
+
if (!byFinger)
|
|
187
|
+
return;
|
|
188
|
+
liftTimer.current = setTimeout(() => {
|
|
189
|
+
const current = lift.current;
|
|
190
|
+
if (!current?.press)
|
|
191
|
+
return;
|
|
192
|
+
current.press = pressTick(current.press, Date.now() + 1);
|
|
193
|
+
if (current.press.phase !== "held")
|
|
194
|
+
return;
|
|
195
|
+
current.dragging = true;
|
|
196
|
+
navigator.vibrate?.(10);
|
|
197
|
+
placeLift(current, current.x, current.y);
|
|
198
|
+
}, HOLD_MS);
|
|
199
|
+
};
|
|
200
|
+
const placeLift = (current, clientX, clientY) => {
|
|
201
|
+
const dayDelta = days.indexOf(columnAt(clientX) ?? current.startColumn) -
|
|
202
|
+
days.indexOf(current.startColumn);
|
|
203
|
+
const minutes = snappedMinutes(clientY - current.y, hourHeight);
|
|
204
|
+
let range;
|
|
205
|
+
if (current.allDay) {
|
|
206
|
+
const moved = current.kind === "move"
|
|
207
|
+
? moveDays(current.first, current.last, dayDelta)
|
|
208
|
+
: {
|
|
209
|
+
first: current.first,
|
|
210
|
+
last: resizeDays(current.first, current.last, dayDelta),
|
|
211
|
+
};
|
|
212
|
+
range = {
|
|
213
|
+
date: moved.first,
|
|
214
|
+
endDate: moved.last,
|
|
215
|
+
startTime: "",
|
|
216
|
+
endTime: "",
|
|
217
|
+
allDay: true,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
const moved = current.kind === "move"
|
|
222
|
+
? moveTimed(current.start, current.end, dayDelta, minutes)
|
|
223
|
+
: {
|
|
224
|
+
start: current.start,
|
|
225
|
+
end: resizeTimed(current.start, current.end, minutes),
|
|
226
|
+
};
|
|
227
|
+
range = {
|
|
228
|
+
date: moved.start.date,
|
|
229
|
+
endDate: moved.end.date,
|
|
230
|
+
startTime: clock(moved.start.minute),
|
|
231
|
+
endTime: clock(moved.end.minute),
|
|
232
|
+
allDay: false,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const box = rootRef.current?.getBoundingClientRect();
|
|
236
|
+
const invalid = box !== undefined &&
|
|
237
|
+
(clientX < box.left ||
|
|
238
|
+
clientX > box.right ||
|
|
239
|
+
clientY < box.top ||
|
|
240
|
+
clientY > box.bottom);
|
|
241
|
+
current.range = range;
|
|
242
|
+
current.invalid = invalid;
|
|
243
|
+
setLifted({ id: current.id, range, invalid });
|
|
244
|
+
};
|
|
245
|
+
const moveLift = (event) => {
|
|
246
|
+
const current = lift.current;
|
|
247
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
248
|
+
return;
|
|
249
|
+
if (current.press) {
|
|
250
|
+
current.press = pressMove(current.press, event.clientX, event.clientY);
|
|
251
|
+
if (current.press.phase === "scrolled") {
|
|
252
|
+
endLift();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (current.press.phase !== "held")
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
else if (!current.dragging &&
|
|
259
|
+
!isDrag(event.clientX - current.x, event.clientY - current.y))
|
|
260
|
+
return;
|
|
261
|
+
current.dragging = true;
|
|
262
|
+
placeLift(current, event.clientX, event.clientY);
|
|
263
|
+
};
|
|
264
|
+
const dropLift = (event) => {
|
|
265
|
+
const current = lift.current;
|
|
266
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
267
|
+
return;
|
|
268
|
+
if (current.dragging)
|
|
269
|
+
suppressClick.current = true;
|
|
270
|
+
const { range, invalid, dragging, id } = current;
|
|
271
|
+
endLift();
|
|
272
|
+
if (!dragging || !range || invalid)
|
|
273
|
+
return;
|
|
274
|
+
announce(range);
|
|
275
|
+
onMoveEvent?.(id, range);
|
|
276
|
+
};
|
|
277
|
+
const startTimed = (event) => {
|
|
278
|
+
if (event.button !== 0)
|
|
279
|
+
return;
|
|
280
|
+
const date = columnAt(event.clientX);
|
|
281
|
+
if (!date)
|
|
282
|
+
return;
|
|
283
|
+
const origin = event.currentTarget;
|
|
284
|
+
capturePointer(origin, event.pointerId);
|
|
285
|
+
const anchorMinute = minuteOf(event.clientY);
|
|
286
|
+
if (touch && event.pointerType === "touch") {
|
|
287
|
+
press.current = pressStart(event.clientX, event.clientY, Date.now());
|
|
288
|
+
gesture.current = {
|
|
289
|
+
kind: "touch",
|
|
290
|
+
pointerId: event.pointerId,
|
|
291
|
+
date,
|
|
292
|
+
anchorMinute,
|
|
293
|
+
x: event.clientX,
|
|
294
|
+
y: event.clientY,
|
|
295
|
+
dragging: false,
|
|
296
|
+
range: null,
|
|
297
|
+
origin,
|
|
298
|
+
};
|
|
299
|
+
holdTimer.current = setTimeout(() => {
|
|
300
|
+
if (!press.current || !gesture.current)
|
|
301
|
+
return;
|
|
302
|
+
press.current = pressTick(press.current, Date.now() + 1);
|
|
303
|
+
if (press.current.phase !== "held")
|
|
304
|
+
return;
|
|
305
|
+
const range = clickRange(date, anchorMinute);
|
|
306
|
+
gesture.current.dragging = true;
|
|
307
|
+
gesture.current.range = range;
|
|
308
|
+
navigator.vibrate?.(10);
|
|
309
|
+
onGesture({ type: "drag", range });
|
|
310
|
+
}, HOLD_MS);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
gesture.current = {
|
|
314
|
+
kind: "timed",
|
|
315
|
+
pointerId: event.pointerId,
|
|
316
|
+
date,
|
|
317
|
+
anchorMinute,
|
|
318
|
+
x: event.clientX,
|
|
319
|
+
y: event.clientY,
|
|
320
|
+
dragging: false,
|
|
321
|
+
range: null,
|
|
322
|
+
origin,
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
const startAllDay = (event) => {
|
|
326
|
+
if (event.button !== 0 || (touch && event.pointerType === "touch"))
|
|
327
|
+
return;
|
|
328
|
+
const date = columnAt(event.clientX);
|
|
329
|
+
if (!date)
|
|
330
|
+
return;
|
|
331
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
332
|
+
gesture.current = {
|
|
333
|
+
kind: "all-day",
|
|
334
|
+
pointerId: event.pointerId,
|
|
335
|
+
date,
|
|
336
|
+
anchorMinute: 0,
|
|
337
|
+
x: event.clientX,
|
|
338
|
+
y: event.clientY,
|
|
339
|
+
dragging: false,
|
|
340
|
+
range: null,
|
|
341
|
+
origin: event.currentTarget,
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
const startHandle = (edge, event) => {
|
|
345
|
+
if (!draft)
|
|
346
|
+
return;
|
|
347
|
+
event.stopPropagation();
|
|
348
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
349
|
+
gesture.current = {
|
|
350
|
+
kind: edge === "start" ? "handle-start" : "handle-end",
|
|
351
|
+
pointerId: event.pointerId,
|
|
352
|
+
date: draft.range.date,
|
|
353
|
+
anchorMinute: 0,
|
|
354
|
+
x: event.clientX,
|
|
355
|
+
y: event.clientY,
|
|
356
|
+
dragging: true,
|
|
357
|
+
range: draft.range,
|
|
358
|
+
origin: event.currentTarget,
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
const movePointer = (event) => {
|
|
362
|
+
const current = gesture.current;
|
|
363
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
364
|
+
return;
|
|
365
|
+
const dx = event.clientX - current.x;
|
|
366
|
+
const dy = event.clientY - current.y;
|
|
367
|
+
if (current.kind === "touch") {
|
|
368
|
+
if (!press.current)
|
|
369
|
+
return;
|
|
370
|
+
press.current = pressMove(press.current, event.clientX, event.clientY);
|
|
371
|
+
if (press.current.phase === "scrolled") {
|
|
372
|
+
endGesture();
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (press.current.phase !== "held")
|
|
376
|
+
return;
|
|
377
|
+
const range = stepHandle(clickRange(current.date, current.anchorMinute), "end", dy, hourHeight);
|
|
378
|
+
current.range = range;
|
|
379
|
+
onGesture({ type: "drag", range });
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (current.kind === "handle-start" || current.kind === "handle-end") {
|
|
383
|
+
if (!draft)
|
|
384
|
+
return;
|
|
385
|
+
const range = stepHandle(current.range ?? draft.range, current.kind === "handle-start" ? "start" : "end", dy, hourHeight);
|
|
386
|
+
onGesture({ type: "drag", range });
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (!current.dragging && !isDrag(dx, dy))
|
|
390
|
+
return;
|
|
391
|
+
current.dragging = true;
|
|
392
|
+
const range = current.kind === "all-day"
|
|
393
|
+
? allDayRange(current.date, columnAt(event.clientX) ?? current.date)
|
|
394
|
+
: timedRange(current.date, current.anchorMinute, minuteOf(event.clientY));
|
|
395
|
+
current.range = range;
|
|
396
|
+
onGesture({ type: "drag", range });
|
|
397
|
+
};
|
|
398
|
+
const endPointer = (event) => {
|
|
399
|
+
const current = gesture.current;
|
|
400
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
401
|
+
return;
|
|
402
|
+
if (current.kind === "handle-start" || current.kind === "handle-end") {
|
|
403
|
+
const range = draft?.range;
|
|
404
|
+
endGesture();
|
|
405
|
+
if (range) {
|
|
406
|
+
announce(range);
|
|
407
|
+
onGesture({ type: "drag-end", range });
|
|
408
|
+
}
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (current.kind === "touch") {
|
|
412
|
+
const range = current.range;
|
|
413
|
+
const tapped = press.current?.phase === "pending";
|
|
414
|
+
endGesture();
|
|
415
|
+
if (range) {
|
|
416
|
+
announce(range);
|
|
417
|
+
onGesture({ type: "drag-end", range });
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (tapped)
|
|
421
|
+
onGesture({
|
|
422
|
+
type: "click",
|
|
423
|
+
range: clickRange(current.date, current.anchorMinute),
|
|
424
|
+
origin: current.origin,
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
endGesture();
|
|
429
|
+
if (current.dragging && current.range) {
|
|
430
|
+
announce(current.range);
|
|
431
|
+
onGesture({ type: "drag-end", range: current.range });
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const range = current.kind === "all-day"
|
|
435
|
+
? allDayRange(current.date, current.date)
|
|
436
|
+
: clickRange(current.date, current.anchorMinute);
|
|
437
|
+
onGesture({ type: "click", range, origin: current.origin });
|
|
438
|
+
};
|
|
439
|
+
const cancelPointer = (event) => {
|
|
440
|
+
const current = gesture.current;
|
|
441
|
+
if (!current || current.pointerId !== event.pointerId)
|
|
442
|
+
return;
|
|
443
|
+
const wasShowing = current.dragging;
|
|
444
|
+
endGesture();
|
|
445
|
+
if (wasShowing)
|
|
446
|
+
onGesture({ type: "drag-cancel" });
|
|
447
|
+
};
|
|
448
|
+
const onKeyDown = (event) => {
|
|
449
|
+
if (event.target !== event.currentTarget)
|
|
450
|
+
return;
|
|
451
|
+
setHasFocus(true);
|
|
452
|
+
const slot = focusSlot ?? initialFocus(days, today.date, today.minute);
|
|
453
|
+
if (event.key === "Enter") {
|
|
454
|
+
event.preventDefault();
|
|
455
|
+
const range = stretchAnchor
|
|
456
|
+
? stretchRange(stretchAnchor, slot)
|
|
457
|
+
: clickRange(slot.date, slot.minute);
|
|
458
|
+
const origin = document.getElementById(focusCellId);
|
|
459
|
+
setStretchAnchor(null);
|
|
460
|
+
announce(range);
|
|
461
|
+
onGesture({ type: "keyboard", range, origin });
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (event.key === "Escape" && stretchAnchor) {
|
|
465
|
+
event.preventDefault();
|
|
466
|
+
event.stopPropagation();
|
|
467
|
+
setStretchAnchor(null);
|
|
468
|
+
onGesture({ type: "drag-cancel" });
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const next = moveFocus(slot, event.key, days);
|
|
472
|
+
if (!next)
|
|
473
|
+
return;
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
setFocusSlot(next);
|
|
476
|
+
scrollSlotIntoView(next.minute);
|
|
477
|
+
if (event.shiftKey) {
|
|
478
|
+
const anchor = stretchAnchor ?? slot;
|
|
479
|
+
setStretchAnchor(anchor);
|
|
480
|
+
const range = stretchRange(anchor, next);
|
|
481
|
+
announce(range);
|
|
482
|
+
onGesture({ type: "drag", range });
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (stretchAnchor) {
|
|
486
|
+
setStretchAnchor(null);
|
|
487
|
+
onGesture({ type: "drag-cancel" });
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const scrollSlotIntoView = (minute) => {
|
|
491
|
+
const scroller = scrollRef.current;
|
|
492
|
+
if (!scroller)
|
|
493
|
+
return;
|
|
494
|
+
const top = (minute / 60) * hourHeight;
|
|
495
|
+
if (top < scroller.scrollTop)
|
|
496
|
+
scroller.scrollTop = top;
|
|
497
|
+
else if (top + hourHeight > scroller.scrollTop + scroller.clientHeight)
|
|
498
|
+
scroller.scrollTop = top + hourHeight - scroller.clientHeight;
|
|
499
|
+
};
|
|
500
|
+
const shownFocus = focusSlot && days.includes(focusSlot.date)
|
|
501
|
+
? focusSlot
|
|
502
|
+
: initialFocus(days, today.date, today.minute);
|
|
503
|
+
const chip = (event, layout, tall) => {
|
|
504
|
+
const color = colorByCalendarId[event.calendarId] ?? FALLBACK_COLOR;
|
|
505
|
+
const timeText = event.allDay || (density === "compact" && !tall)
|
|
506
|
+
? ""
|
|
507
|
+
: clock(zonedMoment(event.start, timeZone).minute);
|
|
508
|
+
const movable = onMoveEvent !== undefined && canMove(event.id);
|
|
509
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-event-id": event.id, onPointerDown: (press) => startLift(press, event, "move"), onPointerMove: moveLift, onPointerUp: dropLift, onPointerCancel: endLift, onClick: (click) => {
|
|
510
|
+
if (suppressClick.current) {
|
|
511
|
+
suppressClick.current = false;
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
onSelectEvent(event.id, click.currentTarget);
|
|
515
|
+
}, "aria-label": `${event.title}, ${describeEvent(event, timeZone)}`, className: cn(calendarEventBodyClasses({
|
|
516
|
+
color,
|
|
517
|
+
layout,
|
|
518
|
+
density: "compact",
|
|
519
|
+
rsvp: event.myRsvp,
|
|
520
|
+
status: event.status,
|
|
521
|
+
selected: event.id === selectedEventId,
|
|
522
|
+
stacked: false,
|
|
523
|
+
}), "h-full w-full cursor-pointer text-left outline-none focus-visible:ring-2 focus-visible:ring-ring", touch && "touch-pan-y", lifted?.id === event.id && "opacity-40"), children: _jsx(CalendarEventChipContent, { title: event.title === "" ? "(No title)" : event.title, timeText: timeText, layout: layout, rsvp: event.myRsvp, hasThread: event.threadId !== "", isRecurring: event.recurrenceRule !== "", zoneCertainty: event.zoneCertainty }) }), movable && (_jsx("span", { "aria-hidden": "true", "data-resize-handle": "", onPointerDown: (press) => startLift(press, event, "resize"), onPointerMove: moveLift, onPointerUp: dropLift, onPointerCancel: endLift, className: cn("absolute", layout === "column"
|
|
524
|
+
? "inset-x-0 bottom-0 h-1.5 cursor-ns-resize"
|
|
525
|
+
: "inset-y-0 right-0 w-1.5 cursor-ew-resize"), style: { touchAction: "none" } }))] }));
|
|
526
|
+
};
|
|
527
|
+
const ghostLabel = (range) => range.allDay
|
|
528
|
+
? dayLabel(range.date, { weekday: "short", day: "numeric" })
|
|
529
|
+
: `${dayLabel(range.date, { weekday: "short", day: "numeric" })} · ${range.startTime} – ${range.endTime}`;
|
|
530
|
+
const ghost = (range, invalid) => (_jsx("div", { "data-lifted-event": "", className: cn("pointer-events-none absolute inset-0 z-30 flex flex-col overflow-hidden rounded-sm border-2 border-accent bg-accent-soft px-1.5 py-0.5 text-xs text-fg shadow-lg", invalid && "border-dashed opacity-60"), children: _jsx("span", { className: "truncate font-medium tabular-nums", children: ghostLabel(range) }) }));
|
|
531
|
+
const draftBlock = (body, extra) => {
|
|
532
|
+
if (!draft)
|
|
533
|
+
return null;
|
|
534
|
+
const hue = calendarColorClasses("cal-1");
|
|
535
|
+
return (_jsx("div", { "data-draft-block": "", className: cn("pointer-events-auto absolute z-20 flex flex-col overflow-hidden rounded-sm px-1.5 py-0.5 text-xs shadow-md", draft.tone === "draft"
|
|
536
|
+
? cn("border-2 border-dashed bg-surface/90", hue.border, hue.text)
|
|
537
|
+
: "bg-accent text-accent-fg", extra), children: body }));
|
|
538
|
+
};
|
|
539
|
+
const draftTitle = draft?.title === "" ? "New event" : (draft?.title ?? "");
|
|
540
|
+
const handle = (edge) => (_jsx("span", { "data-handle": edge, "aria-hidden": "true", onPointerDown: (event) => startHandle(edge, event), onPointerMove: movePointer, onPointerUp: endPointer, onPointerCancel: cancelPointer, className: cn("absolute inset-x-0 cursor-ns-resize", edge === "start" ? "top-0" : "bottom-0", touch ? "h-6" : "h-2"), style: { touchAction: "none" }, children: touch && (_jsx("span", { className: cn("absolute size-3 rounded-full border-2 border-accent bg-surface", edge === "start"
|
|
541
|
+
? "top-0 left-3 -translate-y-1/2"
|
|
542
|
+
: "right-3 bottom-0 translate-y-1/2") })) }));
|
|
543
|
+
const draftContent = draft ? (_jsxs(_Fragment, { children: [draft.tone === "draft" && (_jsx("span", { className: "text-2xs font-semibold uppercase tracking-wider", children: "Draft" })), _jsxs("span", { className: "flex items-center gap-1 truncate font-medium", children: [draft.warning && (_jsx(TriangleAlert, { className: "size-3.5 shrink-0", "aria-label": "Not saved" })), draftTitle] }), _jsxs("span", { className: "tabular-nums opacity-90", children: [draft.range.startTime, " \u2013 ", draft.range.endTime] }), draft.handles && (_jsxs(_Fragment, { children: [handle("start"), handle("end")] }))] })) : null;
|
|
544
|
+
return (_jsxs("div", { ref: rootRef, "data-testid": "calendar-grid", className: cn("flex h-full min-h-0 flex-col bg-surface text-fg select-none", className), children: [_jsxs("div", { className: "flex shrink-0 border-b border-line", children: [_jsx("div", { className: "flex w-14 shrink-0 items-end justify-end pr-2 pb-1 text-2xs text-fg-subtle", children: zoneLabel(timeZone, now) }), _jsx("div", { className: "grid flex-1", style: {
|
|
545
|
+
gridTemplateColumns: `repeat(${days.length}, minmax(0, 1fr))`,
|
|
546
|
+
}, children: days.map((date) => {
|
|
547
|
+
const isToday = date === today.date;
|
|
548
|
+
return (_jsxs("div", { className: "flex flex-col items-center gap-0.5 border-l border-line py-1", children: [_jsx("span", { className: cn("text-2xs font-medium uppercase tracking-wider", isToday ? "text-accent" : "text-fg-subtle"), children: dayLabel(date, { weekday: "short" }) }), _jsx("button", { type: "button", onClick: () => onOpenDay?.(date), "aria-label": dayLabel(date, {
|
|
549
|
+
weekday: "long",
|
|
550
|
+
day: "numeric",
|
|
551
|
+
month: "long",
|
|
552
|
+
year: "numeric",
|
|
553
|
+
}), "aria-current": isToday ? "date" : undefined, className: cn("flex size-9 items-center justify-center rounded-full text-xl tabular-nums outline-none focus-visible:ring-2 focus-visible:ring-ring", isToday
|
|
554
|
+
? "bg-accent text-accent-fg"
|
|
555
|
+
: "text-fg hover:bg-surface-sunken"), children: Number(date.slice(8)) })] }, date));
|
|
556
|
+
}) })] }), _jsxs("div", { className: "flex shrink-0 border-b border-line-strong", children: [_jsx("div", { className: "flex w-14 shrink-0 items-start justify-end pt-1 pr-2 text-2xs text-fg-subtle", children: "All day" }), _jsxs("div", { ref: allDayRef, "data-all-day-row": "", onPointerDown: startAllDay, onPointerMove: movePointer, onPointerUp: endPointer, onPointerCancel: cancelPointer, className: "relative flex-1", style: { height: laneCount * ALL_DAY_LANE + 6 }, children: [_jsx("div", { className: "pointer-events-none absolute inset-0 grid", style: {
|
|
557
|
+
gridTemplateColumns: `repeat(${days.length}, minmax(0, 1fr))`,
|
|
558
|
+
}, children: days.map((date) => (_jsx("div", { className: "border-l border-line" }, date))) }), bars.map((bar) => {
|
|
559
|
+
const event = byId.get(bar.id);
|
|
560
|
+
if (!event)
|
|
561
|
+
return null;
|
|
562
|
+
return (_jsx("div", { className: "absolute px-0.5", style: {
|
|
563
|
+
left: `${(bar.startIndex / days.length) * 100}%`,
|
|
564
|
+
width: `${(bar.span / days.length) * 100}%`,
|
|
565
|
+
top: 2 + bar.lane * ALL_DAY_LANE,
|
|
566
|
+
height: ALL_DAY_LANE - 2,
|
|
567
|
+
}, children: chip(event, "row", false) }, bar.id));
|
|
568
|
+
}), lifted?.range.allDay &&
|
|
569
|
+
(() => {
|
|
570
|
+
const bar = layoutAllDay(days, [
|
|
571
|
+
{
|
|
572
|
+
id: "lifted",
|
|
573
|
+
first: lifted.range.date,
|
|
574
|
+
last: lifted.range.endDate,
|
|
575
|
+
},
|
|
576
|
+
])[0];
|
|
577
|
+
if (!bar)
|
|
578
|
+
return null;
|
|
579
|
+
return (_jsx("div", { className: "absolute px-0.5", style: {
|
|
580
|
+
left: `${(bar.startIndex / days.length) * 100}%`,
|
|
581
|
+
width: `${(bar.span / days.length) * 100}%`,
|
|
582
|
+
top: 2,
|
|
583
|
+
height: ALL_DAY_LANE - 2,
|
|
584
|
+
}, children: ghost(lifted.range, lifted.invalid) }));
|
|
585
|
+
})(), draftBar && (_jsx("div", { className: "absolute px-0.5", style: {
|
|
586
|
+
left: `${(draftBar.startIndex / days.length) * 100}%`,
|
|
587
|
+
width: `${(draftBar.span / days.length) * 100}%`,
|
|
588
|
+
top: 2 + (laneCount - 1) * ALL_DAY_LANE,
|
|
589
|
+
height: ALL_DAY_LANE - 2,
|
|
590
|
+
}, children: draftBlock(_jsx("span", { className: "truncate font-medium", children: draftTitle }), "inset-0") }))] })] }), _jsx("div", { ref: scrollRef, role: "grid", "aria-label": "Time grid", "aria-activedescendant": hasFocus ? focusCellId : undefined, tabIndex: 0, onKeyDown: onKeyDown, onFocus: (event) => {
|
|
591
|
+
if (event.target === event.currentTarget &&
|
|
592
|
+
event.currentTarget.matches(":focus-visible"))
|
|
593
|
+
setHasFocus(true);
|
|
594
|
+
}, onBlur: () => setHasFocus(false), className: "relative min-h-0 flex-1 overflow-y-auto outline-none", children: _jsxs("div", { className: "flex", style: { height: 24 * hourHeight }, children: [_jsx("div", { className: "relative w-14 shrink-0", "aria-hidden": "true", children: HOURS.slice(1).map((hour) => (_jsxs("span", { className: "absolute right-2 -translate-y-1/2 text-2xs tabular-nums text-fg-subtle", style: { top: hour * hourHeight }, children: [pad(hour), ":00"] }, hour))) }), _jsx("div", { ref: columnsRef, "data-time-columns": "", onPointerDown: startTimed, onPointerMove: movePointer, onPointerUp: endPointer, onPointerCancel: cancelPointer, className: "relative grid flex-1", style: {
|
|
595
|
+
gridTemplateColumns: `repeat(${days.length}, minmax(0, 1fr))`,
|
|
596
|
+
touchAction: touch ? "pan-y" : undefined,
|
|
597
|
+
backgroundImage: `repeating-linear-gradient(to bottom, var(--color-line) 0 1px, transparent 1px ${hourHeight}px)`,
|
|
598
|
+
}, children: days.map((date) => {
|
|
599
|
+
const placed = layoutDay(date, timed.map((entry) => ({
|
|
600
|
+
id: entry.event.id,
|
|
601
|
+
start: entry.start,
|
|
602
|
+
end: entry.end,
|
|
603
|
+
})));
|
|
604
|
+
const draftHere = draft && !draft.range.allDay && draft.range.date === date
|
|
605
|
+
? rangeMinutes(draft.range)
|
|
606
|
+
: undefined;
|
|
607
|
+
return (_jsxs("div", { "data-date": date, className: "relative border-l border-line", children: [placed.map((span) => {
|
|
608
|
+
const event = byId.get(span.id);
|
|
609
|
+
if (!event)
|
|
610
|
+
return null;
|
|
611
|
+
const height = ((span.bottom - span.top) / 60) * hourHeight;
|
|
612
|
+
return (_jsx("div", { className: "absolute px-px", style: {
|
|
613
|
+
top: (span.top / 60) * hourHeight,
|
|
614
|
+
height: Math.max(height, 12),
|
|
615
|
+
left: `${(span.column / span.columns) * 100}%`,
|
|
616
|
+
width: `${100 / span.columns}%`,
|
|
617
|
+
}, children: chip(event, "column", height >= 36) }, span.id));
|
|
618
|
+
}), date === today.date && (_jsx("div", { "aria-hidden": "true", className: "pointer-events-none absolute right-0 left-0 z-10 border-t-2 border-danger", style: { top: (today.minute / 60) * hourHeight }, children: _jsx("span", { className: "absolute -top-[5px] -left-1 size-2 rounded-full bg-danger" }) })), hasFocus && shownFocus.date === date && (
|
|
619
|
+
// biome-ignore lint/a11y/useSemanticElements: the one row the active descendant lives in
|
|
620
|
+
_jsx("div", { role: "row", tabIndex: -1, className: "pointer-events-none absolute right-0 left-0 z-30", style: {
|
|
621
|
+
top: (shownFocus.minute / 60) * hourHeight,
|
|
622
|
+
height: hourHeight / 4,
|
|
623
|
+
}, children: _jsx("div", { id: focusCellId, role: "gridcell", tabIndex: -1, "aria-label": describeRange(clickRange(shownFocus.date, shownFocus.minute)).replace(/ to .*/, ""), className: "h-full rounded-xs ring-2 ring-ring" }) })), lifted &&
|
|
624
|
+
!lifted.range.allDay &&
|
|
625
|
+
lifted.range.date === date &&
|
|
626
|
+
(() => {
|
|
627
|
+
const minutes = rangeMinutes(lifted.range);
|
|
628
|
+
return (_jsx("div", { className: "absolute right-1 left-0", style: {
|
|
629
|
+
top: (minutes.start / 60) * hourHeight,
|
|
630
|
+
height: Math.max(((minutes.end - minutes.start) / 60) * hourHeight, 12),
|
|
631
|
+
}, children: ghost(lifted.range, lifted.invalid) }));
|
|
632
|
+
})(), draftHere && (_jsx("div", { className: "absolute right-1 left-0", style: {
|
|
633
|
+
top: (draftHere.start / 60) * hourHeight,
|
|
634
|
+
height: ((draftHere.end - draftHere.start) / 60) * hourHeight,
|
|
635
|
+
}, children: draftBlock(draftContent, "inset-0") }))] }, date));
|
|
636
|
+
}) })] }) }), _jsx("div", { "aria-live": "polite", className: "sr-only", children: live })] }));
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Keeps the pointer on the element that took the press. A pointer the browser
|
|
640
|
+
* no longer tracks — a synthetic one, or one already released — cannot be
|
|
641
|
+
* captured, and the gesture carries on without it.
|
|
642
|
+
*/
|
|
643
|
+
function capturePointer(element, pointerId) {
|
|
644
|
+
try {
|
|
645
|
+
element.setPointerCapture(pointerId);
|
|
646
|
+
}
|
|
647
|
+
catch {
|
|
648
|
+
// Not a live pointer: nothing to capture.
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
function lastDayOf(event) {
|
|
652
|
+
const end = event.end.slice(0, 10);
|
|
653
|
+
if (!event.allDay)
|
|
654
|
+
return end;
|
|
655
|
+
const [year, month, day] = end.split("-").map(Number);
|
|
656
|
+
const previous = new Date(Date.UTC(year, month - 1, day - 1));
|
|
657
|
+
const last = previous.toISOString().slice(0, 10);
|
|
658
|
+
return last < event.start.slice(0, 10) ? event.start.slice(0, 10) : last;
|
|
659
|
+
}
|
|
660
|
+
function describeEvent(event, timeZone) {
|
|
661
|
+
if (event.allDay)
|
|
662
|
+
return "all day";
|
|
663
|
+
const start = zonedMoment(event.start, timeZone);
|
|
664
|
+
const end = zonedMoment(event.end, timeZone);
|
|
665
|
+
return `${clock(start.minute)} to ${clock(end.minute)}`;
|
|
666
|
+
}
|