@jsb188/calendar 1.1.10 → 1.1.12
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/package.json +16 -15
- package/src/constants/calendar.ts +17 -3
- package/src/libs/calendar-geometry.ts +165 -91
- package/src/libs/calendar-gesture.ts +58 -15
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +88 -27
- package/src/libs/calendar-state.ts +21 -156
- package/src/libs/calendar-url.ts +55 -8
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +3 -0
- package/src/modules/Calendar.tsx +375 -287
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +7 -1
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +43 -14
- package/src/ui/CalendarMonthUI.tsx +38 -26
- package/src/ui/CalendarToolbarUI.tsx +50 -27
- package/src/ui/CalendarUI.tsx +280 -226
- package/src/ui/CalendarYearUI.tsx +36 -50
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +230 -84
- package/tests/calendar-gesture.test.ts +43 -12
- package/tests/calendar-range.test.ts +159 -33
- package/tests/calendar-url.test.ts +77 -12
- package/tests/roster-layout.test.ts +210 -0
- package/src/ui/CalendarCoverageUI.tsx +0 -199
- package/src/ui/CalendarEventDetailUI.tsx +0 -260
- package/src/ui/CalendarEventFormUI.tsx +0 -239
- package/src/ui/CalendarRailUI.tsx +0 -282
- package/src/ui/CalendarRequestUI.tsx +0 -537
- package/src/ui/CalendarViolationUI.tsx +0 -207
package/src/modules/Calendar.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
|
-
import { useAtom
|
|
3
|
+
import { useAtom } from 'jotai';
|
|
4
4
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import {
|
|
6
6
|
CALENDAR_GUTTER_WIDTH,
|
|
@@ -23,15 +23,22 @@ import {
|
|
|
23
23
|
startCalendarGesture,
|
|
24
24
|
type CalendarGestureRange,
|
|
25
25
|
} from '../libs/calendar-gesture.ts';
|
|
26
|
-
import { getCalendarRange, getDayLengthMinutes, getMinutesFromDayStart } from '../libs/calendar-range.ts';
|
|
27
26
|
import {
|
|
28
|
-
|
|
27
|
+
getCalendarDateKey,
|
|
28
|
+
getCalendarRange,
|
|
29
|
+
getDayLengthMinutes,
|
|
30
|
+
getMinutesFromDayStart,
|
|
31
|
+
normalizeCalendarWeekStartsOn,
|
|
32
|
+
} from '../libs/calendar-range.ts';
|
|
33
|
+
import {
|
|
29
34
|
createCalendarStateAtoms,
|
|
30
|
-
getCalendarStateScopeKey,
|
|
31
35
|
type CalendarStateAtoms,
|
|
32
36
|
} from '../libs/calendar-state.ts';
|
|
33
37
|
import type { CalendarEventObj } from '../types/calendar.d.ts';
|
|
34
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
CalendarAgendaUI,
|
|
40
|
+
type CalendarAgendaDayObj,
|
|
41
|
+
} from '../ui/CalendarAgendaUI.tsx';
|
|
35
42
|
import { CalendarMonthUI } from '../ui/CalendarMonthUI.tsx';
|
|
36
43
|
import {
|
|
37
44
|
CalendarAllDayBandUI,
|
|
@@ -42,7 +49,10 @@ import {
|
|
|
42
49
|
CalendarNowLineUI,
|
|
43
50
|
CalendarTimeGutterUI,
|
|
44
51
|
} from '../ui/CalendarUI.tsx';
|
|
45
|
-
import {
|
|
52
|
+
import {
|
|
53
|
+
CalendarYearUI,
|
|
54
|
+
type CalendarYearMonthObj,
|
|
55
|
+
} from '../ui/CalendarYearUI.tsx';
|
|
46
56
|
|
|
47
57
|
/**
|
|
48
58
|
* The calendar surface.
|
|
@@ -96,26 +106,43 @@ export function Calendar(p: CalendarProps) {
|
|
|
96
106
|
// Created in a ref, never inline in the render body: creating atoms inline
|
|
97
107
|
// would hand every render a fresh bag and reset all state
|
|
98
108
|
if (!stateAtomsRef.current) {
|
|
99
|
-
stateAtomsRef.current = createCalendarStateAtoms(
|
|
109
|
+
stateAtomsRef.current = createCalendarStateAtoms();
|
|
100
110
|
}
|
|
101
111
|
|
|
102
|
-
return
|
|
112
|
+
return (
|
|
113
|
+
<CalendarContent
|
|
114
|
+
{...p}
|
|
115
|
+
stateAtoms={stateAtomsRef.current}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
103
118
|
}
|
|
104
119
|
|
|
105
120
|
type CalendarContentProps = CalendarProps & {
|
|
106
121
|
stateAtoms: CalendarStateAtoms;
|
|
107
122
|
};
|
|
108
123
|
|
|
124
|
+
/*
|
|
125
|
+
* Render the default month overflow label when the caller supplies no formatter.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
function getDefaultCalendarMoreLabel(count: number): string {
|
|
129
|
+
return `+${count}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
109
132
|
/*
|
|
110
133
|
* Format the hour labels once per locale rather than per hour per render.
|
|
111
134
|
*/
|
|
112
135
|
|
|
113
136
|
function useCalendarHourLabels(timeZone: string, locale?: string | null) {
|
|
114
137
|
return useMemo(() => {
|
|
115
|
-
const base = DateTime.fromObject(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
const base = DateTime.fromObject(
|
|
139
|
+
{ year: 2026, month: 1, day: 1 },
|
|
140
|
+
{ zone: timeZone },
|
|
141
|
+
).setLocale(locale || 'en');
|
|
142
|
+
|
|
143
|
+
return Array.from({ length: 24 }, (_unused, hour) =>
|
|
144
|
+
base.set({ hour }).toFormat('h a'),
|
|
145
|
+
);
|
|
119
146
|
}, [timeZone, locale]);
|
|
120
147
|
}
|
|
121
148
|
|
|
@@ -145,20 +172,25 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
145
172
|
stateAtoms,
|
|
146
173
|
} = p;
|
|
147
174
|
|
|
148
|
-
const [
|
|
149
|
-
|
|
150
|
-
|
|
175
|
+
const [selectedEventId, setSelectedEventId] = useAtom(
|
|
176
|
+
stateAtoms.selectedEventIdAtom,
|
|
177
|
+
);
|
|
151
178
|
|
|
179
|
+
// "now" ticks every minute to move the now line, but the range only uses it
|
|
180
|
+
// to decide which column is today — so the memo keys on the local DATE
|
|
181
|
+
// rather than the instant. Keying on the instant would rebuild the day
|
|
182
|
+
// objects every minute, and every layout pass hanging off range.days with
|
|
183
|
+
// them, to redraw a line that moved one pixel.
|
|
184
|
+
const nowDateKey = getCalendarDateKey(now, timeZone);
|
|
152
185
|
const range = useMemo(
|
|
186
|
+
// "now" is read inside but "nowDateKey" is the dependency: the range only
|
|
187
|
+
// changes when the local date does
|
|
153
188
|
() => getCalendarRange({ view, anchorDate, now, timeZone, weekStartsOn }),
|
|
154
|
-
[view, anchorDate,
|
|
189
|
+
[view, anchorDate, nowDateKey, timeZone, weekStartsOn],
|
|
155
190
|
);
|
|
156
191
|
|
|
157
192
|
// One pass over the week per data change, not per subscriber
|
|
158
|
-
const visibleEvents =
|
|
159
|
-
() => applyCalendarOptimisticOverlays(events, optimisticEvents, removedEventIds),
|
|
160
|
-
[events, optimisticEvents, removedEventIds],
|
|
161
|
-
);
|
|
193
|
+
const visibleEvents = events;
|
|
162
194
|
|
|
163
195
|
const isTimeGrid = !!CALENDAR_VIEW_DAY_COUNTS[view];
|
|
164
196
|
|
|
@@ -166,15 +198,34 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
166
198
|
// running the overlap sweep over it to draw a grid that shows no events
|
|
167
199
|
// would be pure waste on every render.
|
|
168
200
|
const timedLayout = useMemo(
|
|
169
|
-
() =>
|
|
201
|
+
() =>
|
|
202
|
+
isTimeGrid
|
|
203
|
+
? getCalendarTimedLayout(
|
|
204
|
+
visibleEvents.filter((event) => !event.allDay),
|
|
205
|
+
range.days,
|
|
206
|
+
)
|
|
207
|
+
: [],
|
|
170
208
|
[isTimeGrid, visibleEvents, range.days],
|
|
171
209
|
);
|
|
172
210
|
const allDayBars = useMemo(
|
|
173
|
-
() =>
|
|
211
|
+
() =>
|
|
212
|
+
isTimeGrid
|
|
213
|
+
? getCalendarAllDayLayout(
|
|
214
|
+
visibleEvents.filter((event) => event.allDay),
|
|
215
|
+
range.days,
|
|
216
|
+
)
|
|
217
|
+
: [],
|
|
174
218
|
[isTimeGrid, visibleEvents, range.days],
|
|
175
219
|
);
|
|
176
220
|
const monthCells = useMemo(
|
|
177
|
-
() =>
|
|
221
|
+
() =>
|
|
222
|
+
view === 'MONTH'
|
|
223
|
+
? getCalendarMonthCells(
|
|
224
|
+
visibleEvents,
|
|
225
|
+
range.days,
|
|
226
|
+
CALENDAR_MONTH_CELL_MAX_EVENTS,
|
|
227
|
+
)
|
|
228
|
+
: [],
|
|
178
229
|
[view, visibleEvents, range.days],
|
|
179
230
|
);
|
|
180
231
|
|
|
@@ -183,7 +234,9 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
183
234
|
const dayLabels = useMemo(
|
|
184
235
|
() =>
|
|
185
236
|
range.days.map((day) => {
|
|
186
|
-
const local = DateTime.fromJSDate(day.startAt, {
|
|
237
|
+
const local = DateTime.fromJSDate(day.startAt, {
|
|
238
|
+
zone: range.timeZone,
|
|
239
|
+
}).setLocale(locale || 'en');
|
|
187
240
|
|
|
188
241
|
return {
|
|
189
242
|
weekday: local.toFormat('ccc'),
|
|
@@ -199,17 +252,20 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
199
252
|
*/
|
|
200
253
|
|
|
201
254
|
const weekdayLabels = useMemo(() => {
|
|
202
|
-
const weekStart =
|
|
255
|
+
const weekStart = normalizeCalendarWeekStartsOn(weekStartsOn);
|
|
203
256
|
// Any Sunday; 2026-01-04 is one
|
|
204
|
-
const sunday = DateTime.fromObject(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
257
|
+
const sunday = DateTime.fromObject(
|
|
258
|
+
{ year: 2026, month: 1, day: 4 },
|
|
259
|
+
{ zone: range.timeZone },
|
|
260
|
+
).setLocale(locale || 'en');
|
|
261
|
+
|
|
262
|
+
return Array.from({ length: 7 }, (_unused, index) =>
|
|
263
|
+
sunday.plus({ days: index + weekStart }).toFormat('ccc'),
|
|
264
|
+
);
|
|
208
265
|
}, [range.timeZone, locale, weekStartsOn]);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
[weekdayLabels],
|
|
266
|
+
const dayNumberLabels = useMemo(
|
|
267
|
+
() => dayLabels.map((label) => label.dayNumber),
|
|
268
|
+
[dayLabels],
|
|
213
269
|
);
|
|
214
270
|
|
|
215
271
|
const timeLabelByEventId = useMemo(() => {
|
|
@@ -231,17 +287,24 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
231
287
|
return labels;
|
|
232
288
|
}, [timedLayout, range.timeZone, locale]);
|
|
233
289
|
|
|
234
|
-
const handleSelectEvent = useCallback(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
// reference on a no-op keeps subscribers from re-rendering
|
|
238
|
-
current?.eventId === eventId
|
|
239
|
-
? null
|
|
240
|
-
: { eventId, anchorRect: { top: 0, left: 0, width: 0, height: 0 } }
|
|
241
|
-
));
|
|
290
|
+
const handleSelectEvent = useCallback(
|
|
291
|
+
(eventId: string) => {
|
|
292
|
+
setSelectedEventId((current) => (current === eventId ? null : eventId));
|
|
242
293
|
|
|
243
|
-
|
|
244
|
-
|
|
294
|
+
onSelectEvent?.(eventId);
|
|
295
|
+
},
|
|
296
|
+
[onSelectEvent],
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
/*
|
|
300
|
+
* Forward day selection with one stable callback for every calendar view.
|
|
301
|
+
*/
|
|
302
|
+
const handleSelectDay = useCallback(
|
|
303
|
+
(dateKey: string) => {
|
|
304
|
+
onSelectDay?.(dateKey);
|
|
305
|
+
},
|
|
306
|
+
[onSelectDay],
|
|
307
|
+
);
|
|
245
308
|
|
|
246
309
|
const layoutByDayIndex = useMemo(() => {
|
|
247
310
|
const byDay: Array<typeof timedLayout> = range.days.map(() => []);
|
|
@@ -256,13 +319,19 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
256
319
|
// A DST day is 23 or 25 hours long; drawing 24 would put every event after
|
|
257
320
|
// the transition an hour out
|
|
258
321
|
const gridHeight = useMemo(
|
|
259
|
-
() =>
|
|
322
|
+
() =>
|
|
323
|
+
(Math.max(...range.days.map(getDayLengthMinutes)) / 60) *
|
|
324
|
+
CALENDAR_HOUR_HEIGHT,
|
|
260
325
|
[range.days],
|
|
261
326
|
);
|
|
327
|
+
const gridContentStyle = useMemo(
|
|
328
|
+
() => ({ height: gridHeight, touchAction: 'manipulation' as const }),
|
|
329
|
+
[gridHeight],
|
|
330
|
+
);
|
|
262
331
|
|
|
263
332
|
/*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
333
|
+
* The twelve months the year view draws. Each mini grid builds its own days
|
|
334
|
+
* from the month it is given, so this only has to name them.
|
|
266
335
|
*/
|
|
267
336
|
|
|
268
337
|
const yearMonths = useMemo<CalendarYearMonthObj[]>(() => {
|
|
@@ -270,29 +339,21 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
270
339
|
return [];
|
|
271
340
|
}
|
|
272
341
|
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (local.day === 1) {
|
|
280
|
-
months.push({
|
|
281
|
-
label: local.toFormat('LLLL'),
|
|
282
|
-
// luxon: 1 = Monday .. 7 = Sunday; normalize to 0 = Sunday
|
|
283
|
-
leadingBlankCount: ((local.weekday % 7) - weekStart + 7) % 7,
|
|
284
|
-
days: [],
|
|
285
|
-
dayNumberLabels: [],
|
|
286
|
-
});
|
|
287
|
-
}
|
|
342
|
+
const yearStart = DateTime.fromJSDate(range.anchorDate, {
|
|
343
|
+
zone: range.timeZone,
|
|
344
|
+
})
|
|
345
|
+
.setLocale(locale || 'en')
|
|
346
|
+
.startOf('year');
|
|
288
347
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
month?.dayNumberLabels.push(local.toFormat('d'));
|
|
292
|
-
}
|
|
348
|
+
return Array.from({ length: 12 }, (_unused, index) => {
|
|
349
|
+
const monthStart = yearStart.plus({ months: index });
|
|
293
350
|
|
|
294
|
-
|
|
295
|
-
|
|
351
|
+
return {
|
|
352
|
+
label: monthStart.toFormat('LLLL'),
|
|
353
|
+
monthDate: monthStart.toJSDate(),
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}, [view, range.anchorDate, range.timeZone, locale]);
|
|
296
357
|
|
|
297
358
|
/*
|
|
298
359
|
* Build the agenda list, omitting days with nothing on them.
|
|
@@ -338,9 +399,11 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
338
399
|
|
|
339
400
|
labels.set(
|
|
340
401
|
event.id,
|
|
341
|
-
event.allDay
|
|
342
|
-
|
|
343
|
-
.
|
|
402
|
+
event.allDay
|
|
403
|
+
? allDayText || ''
|
|
404
|
+
: DateTime.fromJSDate(event.startAt, { zone: range.timeZone })
|
|
405
|
+
.setLocale(locale || 'en')
|
|
406
|
+
.toFormat('h:mm a'),
|
|
344
407
|
);
|
|
345
408
|
}
|
|
346
409
|
}
|
|
@@ -359,7 +422,9 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
359
422
|
|
|
360
423
|
const gridContentRef = useRef<HTMLDivElement | null>(null);
|
|
361
424
|
const cancelGestureRef = useRef<(() => void) | null>(null);
|
|
362
|
-
const [draftRange, setDraftRange] = useState<CalendarGestureRange | null>(
|
|
425
|
+
const [draftRange, setDraftRange] = useState<CalendarGestureRange | null>(
|
|
426
|
+
null,
|
|
427
|
+
);
|
|
363
428
|
|
|
364
429
|
// Everything the resolver needs, read at pointer time rather than captured
|
|
365
430
|
// at pointerdown, so a scroll mid-drag does not use a stale layout
|
|
@@ -379,7 +444,8 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
379
444
|
// Returning the same reference on an unchanged range is what keeps a
|
|
380
445
|
// slow drag from re-rendering the grid on every frame
|
|
381
446
|
if (
|
|
382
|
-
current &&
|
|
447
|
+
current &&
|
|
448
|
+
next &&
|
|
383
449
|
current.dayIndex === next.dayIndex &&
|
|
384
450
|
current.startAt.getTime() === next.startAt.getTime() &&
|
|
385
451
|
current.endAt.getTime() === next.endAt.getTime()
|
|
@@ -391,128 +457,143 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
391
457
|
});
|
|
392
458
|
}, []);
|
|
393
459
|
|
|
394
|
-
const handleGridPointerDown = useCallback(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const content = gridContentRef.current;
|
|
401
|
-
if (!content) {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const target = event.target as HTMLElement;
|
|
406
|
-
const blockElement = target.closest('[data-calendar-event-id]') as HTMLElement | null;
|
|
407
|
-
const edge = (target.closest('[data-calendar-edge]') as HTMLElement | null)?.dataset.calendarEdge;
|
|
408
|
-
|
|
409
|
-
/*
|
|
410
|
-
* Translate a client position into the day column and snapped minute
|
|
411
|
-
* under it, measured against the CONTENT box so scrolling is accounted
|
|
412
|
-
* for without tracking scrollTop separately.
|
|
413
|
-
*/
|
|
414
|
-
|
|
415
|
-
const resolveSlot = (clientX: number, clientY: number) => {
|
|
416
|
-
const contentRect = content.getBoundingClientRect();
|
|
417
|
-
|
|
418
|
-
return getCalendarPointerSlot({
|
|
419
|
-
offsetX: clientX - contentRect.left - CALENDAR_GUTTER_WIDTH,
|
|
420
|
-
offsetY: clientY - contentRect.top,
|
|
421
|
-
contentWidth: contentRect.width - CALENDAR_GUTTER_WIDTH,
|
|
422
|
-
hourHeight: CALENDAR_HOUR_HEIGHT,
|
|
423
|
-
days: gestureContextRef.current.range.days,
|
|
424
|
-
});
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
const anchorSlot = resolveSlot(event.clientX, event.clientY);
|
|
428
|
-
const eventId = blockElement?.dataset.calendarEventId || null;
|
|
429
|
-
const grabbed = eventId
|
|
430
|
-
? gestureContextRef.current.timedLayout.find((entry) => entry.event.id === eventId)
|
|
431
|
-
: null;
|
|
432
|
-
|
|
433
|
-
let resolveRange: (clientX: number, clientY: number, moved: boolean) => CalendarGestureRange | null;
|
|
434
|
-
|
|
435
|
-
if (grabbed && edge) {
|
|
436
|
-
resolveRange = (clientX, clientY) => {
|
|
437
|
-
const slot = resolveSlot(clientX, clientY);
|
|
438
|
-
|
|
439
|
-
return getCalendarResizeRange({
|
|
440
|
-
days: gestureContextRef.current.range.days,
|
|
441
|
-
dayIndex: grabbed.dayIndex,
|
|
442
|
-
startAt: grabbed.event.startAt,
|
|
443
|
-
endAt: grabbed.event.endAt,
|
|
444
|
-
edge: edge === 'START' ? 'START' : 'END',
|
|
445
|
-
currentMinute: slot.minute,
|
|
446
|
-
});
|
|
447
|
-
};
|
|
448
|
-
} else if (grabbed) {
|
|
449
|
-
// Where in the block it was grabbed, so it does not jump under the
|
|
450
|
-
// pointer on the first pixel of movement
|
|
451
|
-
const grabOffsetMinutes = anchorSlot.minute - grabbed.startMinute;
|
|
460
|
+
const handleGridPointerDown = useCallback(
|
|
461
|
+
(event: React.PointerEvent<HTMLDivElement>) => {
|
|
462
|
+
// Only the primary button, and never a second finger mid-gesture
|
|
463
|
+
if (!editable || event.button !== 0 || cancelGestureRef.current) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
452
466
|
|
|
453
|
-
|
|
454
|
-
|
|
467
|
+
const content = gridContentRef.current;
|
|
468
|
+
if (!content) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
455
471
|
|
|
456
|
-
|
|
472
|
+
const target = event.target as HTMLElement;
|
|
473
|
+
const blockElement = target.closest(
|
|
474
|
+
'[data-calendar-event-id]',
|
|
475
|
+
) as HTMLElement | null;
|
|
476
|
+
const edge = (
|
|
477
|
+
target.closest('[data-calendar-edge]') as HTMLElement | null
|
|
478
|
+
)?.dataset.calendarEdge;
|
|
479
|
+
|
|
480
|
+
/*
|
|
481
|
+
* Translate a client position into the day column and snapped minute
|
|
482
|
+
* under it, measured against the CONTENT box so scrolling is accounted
|
|
483
|
+
* for without tracking scrollTop separately.
|
|
484
|
+
*/
|
|
485
|
+
|
|
486
|
+
const resolveSlot = (clientX: number, clientY: number) => {
|
|
487
|
+
const contentRect = content.getBoundingClientRect();
|
|
488
|
+
|
|
489
|
+
return getCalendarPointerSlot({
|
|
490
|
+
offsetX: clientX - contentRect.left - CALENDAR_GUTTER_WIDTH,
|
|
491
|
+
offsetY: clientY - contentRect.top,
|
|
492
|
+
contentWidth: contentRect.width - CALENDAR_GUTTER_WIDTH,
|
|
493
|
+
hourHeight: CALENDAR_HOUR_HEIGHT,
|
|
457
494
|
days: gestureContextRef.current.range.days,
|
|
458
|
-
startAt: grabbed.event.startAt,
|
|
459
|
-
endAt: grabbed.event.endAt,
|
|
460
|
-
grabOffsetMinutes,
|
|
461
|
-
currentDayIndex: slot.dayIndex,
|
|
462
|
-
currentMinute: slot.minute,
|
|
463
495
|
});
|
|
464
496
|
};
|
|
465
|
-
} else {
|
|
466
|
-
resolveRange = (clientX, clientY, moved) => {
|
|
467
|
-
const slot = resolveSlot(clientX, clientY);
|
|
468
497
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
498
|
+
const anchorSlot = resolveSlot(event.clientX, event.clientY);
|
|
499
|
+
const eventId = blockElement?.dataset.calendarEventId || null;
|
|
500
|
+
const grabbed = eventId
|
|
501
|
+
? gestureContextRef.current.timedLayout.find(
|
|
502
|
+
(entry) => entry.event.id === eventId,
|
|
503
|
+
)
|
|
504
|
+
: null;
|
|
505
|
+
|
|
506
|
+
let resolveRange: (
|
|
507
|
+
clientX: number,
|
|
508
|
+
clientY: number,
|
|
509
|
+
moved: boolean,
|
|
510
|
+
) => CalendarGestureRange | null;
|
|
511
|
+
|
|
512
|
+
if (grabbed && edge) {
|
|
513
|
+
resolveRange = (clientX, clientY) => {
|
|
514
|
+
const slot = resolveSlot(clientX, clientY);
|
|
515
|
+
|
|
516
|
+
return getCalendarResizeRange({
|
|
517
|
+
days: gestureContextRef.current.range.days,
|
|
518
|
+
dayIndex: grabbed.dayIndex,
|
|
519
|
+
startAt: grabbed.event.startAt,
|
|
520
|
+
endAt: grabbed.event.endAt,
|
|
521
|
+
edge: edge === 'START' ? 'START' : 'END',
|
|
522
|
+
currentMinute: slot.minute,
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
} else if (grabbed) {
|
|
526
|
+
// Where in the block it was grabbed, so it does not jump under the
|
|
527
|
+
// pointer on the first pixel of movement
|
|
528
|
+
const grabOffsetMinutes = anchorSlot.minute - grabbed.startMinute;
|
|
529
|
+
|
|
530
|
+
resolveRange = (clientX, clientY) => {
|
|
531
|
+
const slot = resolveSlot(clientX, clientY);
|
|
532
|
+
|
|
533
|
+
return getCalendarMoveRange({
|
|
534
|
+
days: gestureContextRef.current.range.days,
|
|
535
|
+
startAt: grabbed.event.startAt,
|
|
536
|
+
endAt: grabbed.event.endAt,
|
|
537
|
+
grabOffsetMinutes,
|
|
538
|
+
currentDayIndex: slot.dayIndex,
|
|
539
|
+
currentMinute: slot.minute,
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
} else {
|
|
543
|
+
resolveRange = (clientX, clientY, moved) => {
|
|
544
|
+
const slot = resolveSlot(clientX, clientY);
|
|
545
|
+
|
|
546
|
+
return getCalendarCreateRange({
|
|
547
|
+
days: gestureContextRef.current.range.days,
|
|
548
|
+
anchorDayIndex: anchorSlot.dayIndex,
|
|
549
|
+
anchorMinute: anchorSlot.minute,
|
|
550
|
+
currentDayIndex: slot.dayIndex,
|
|
551
|
+
currentMinute: slot.minute,
|
|
552
|
+
moved,
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
}
|
|
479
556
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
557
|
+
cancelGestureRef.current = startCalendarGesture({
|
|
558
|
+
pointerId: event.pointerId,
|
|
559
|
+
originClientX: event.clientX,
|
|
560
|
+
originClientY: event.clientY,
|
|
561
|
+
resolveRange,
|
|
562
|
+
onPreview: applyDraft,
|
|
563
|
+
onCommit: (committed, moved) => {
|
|
564
|
+
if (grabbed) {
|
|
565
|
+
// A press that never moved is somebody opening the block, not
|
|
566
|
+
// asking to move it by zero minutes
|
|
567
|
+
if (moved) {
|
|
568
|
+
onMoveEvent?.({
|
|
569
|
+
eventId: grabbed.event.id,
|
|
570
|
+
startAt: committed.startAt,
|
|
571
|
+
endAt: committed.endAt,
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return;
|
|
497
576
|
}
|
|
498
577
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
578
|
+
onCreateRange?.({
|
|
579
|
+
startAt: committed.startAt,
|
|
580
|
+
endAt: committed.endAt,
|
|
581
|
+
});
|
|
582
|
+
},
|
|
583
|
+
onFinish: () => {
|
|
584
|
+
cancelGestureRef.current = null;
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
},
|
|
588
|
+
[editable, applyDraft, onCreateRange, onMoveEvent],
|
|
589
|
+
);
|
|
509
590
|
|
|
510
591
|
const todayIndex = range.days.findIndex((day) => day.isToday);
|
|
511
|
-
const nowOffset =
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
592
|
+
const nowOffset =
|
|
593
|
+
todayIndex >= 0
|
|
594
|
+
? (getMinutesFromDayStart(now, range.days[todayIndex].startAt) / 60) *
|
|
595
|
+
CALENDAR_HOUR_HEIGHT
|
|
596
|
+
: -1;
|
|
516
597
|
|
|
517
598
|
// The ghost's own label, so a drag reads as a time range while it is being
|
|
518
599
|
// drawn rather than as an unlabelled rectangle
|
|
@@ -522,8 +603,12 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
522
603
|
}
|
|
523
604
|
|
|
524
605
|
const zone = range.timeZone;
|
|
525
|
-
const start = DateTime.fromJSDate(draftRange.startAt, { zone }).setLocale(
|
|
526
|
-
|
|
606
|
+
const start = DateTime.fromJSDate(draftRange.startAt, { zone }).setLocale(
|
|
607
|
+
locale || 'en',
|
|
608
|
+
);
|
|
609
|
+
const end = DateTime.fromJSDate(draftRange.endAt, { zone }).setLocale(
|
|
610
|
+
locale || 'en',
|
|
611
|
+
);
|
|
527
612
|
|
|
528
613
|
return `${start.toFormat('h:mm a')} – ${end.toFormat('h:mm a')}`;
|
|
529
614
|
}, [draftRange, range.timeZone, locale]);
|
|
@@ -534,115 +619,118 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
534
619
|
|
|
535
620
|
{/* Only the time grid has day columns to label and an all-day band
|
|
536
621
|
to hang above them */}
|
|
537
|
-
{isTimeGrid
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
onSelectDay={onSelectDay}
|
|
544
|
-
/>
|
|
545
|
-
|
|
546
|
-
<CalendarAllDayBandUI
|
|
547
|
-
bars={allDayBars}
|
|
548
|
-
dayCount={range.days.length}
|
|
549
|
-
selectedEventId={selectedEventId}
|
|
550
|
-
onSelect={handleSelectEvent}
|
|
551
|
-
/>
|
|
552
|
-
</>
|
|
553
|
-
)
|
|
554
|
-
: null}
|
|
555
|
-
|
|
556
|
-
{view === 'MONTH'
|
|
557
|
-
? (
|
|
558
|
-
<CalendarMonthUI
|
|
559
|
-
cells={monthCells}
|
|
560
|
-
weekdayLabels={weekdayLabels}
|
|
561
|
-
dayNumberLabels={dayLabels.map((label) => label.dayNumber)}
|
|
562
|
-
selectedEventId={selectedEventId}
|
|
563
|
-
moreLabel={moreLabel || ((count) => `+${count}`)}
|
|
564
|
-
onSelectEvent={handleSelectEvent}
|
|
565
|
-
onSelectDay={(dateKey) => onSelectDay?.(dateKey)}
|
|
566
|
-
onSelectOverflow={(dateKey) => onSelectDay?.(dateKey)}
|
|
622
|
+
{isTimeGrid ? (
|
|
623
|
+
<>
|
|
624
|
+
<CalendarDayHeaderUI
|
|
625
|
+
days={range.days}
|
|
626
|
+
dayLabels={dayLabels}
|
|
627
|
+
onSelectDay={onSelectDay}
|
|
567
628
|
/>
|
|
568
|
-
)
|
|
569
|
-
: null}
|
|
570
|
-
|
|
571
|
-
{view === 'YEAR'
|
|
572
|
-
? (
|
|
573
|
-
<CalendarYearUI
|
|
574
|
-
months={yearMonths}
|
|
575
|
-
weekdayInitials={weekdayInitials}
|
|
576
|
-
onSelectDay={(dateKey) => onSelectDay?.(dateKey)}
|
|
577
|
-
/>
|
|
578
|
-
)
|
|
579
|
-
: null}
|
|
580
629
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
days={agendaDays}
|
|
630
|
+
<CalendarAllDayBandUI
|
|
631
|
+
bars={allDayBars}
|
|
632
|
+
dayCount={range.days.length}
|
|
585
633
|
selectedEventId={selectedEventId}
|
|
586
|
-
|
|
587
|
-
emptyText={agendaEmptyText || ''}
|
|
588
|
-
onSelectEvent={handleSelectEvent}
|
|
634
|
+
onSelect={handleSelectEvent}
|
|
589
635
|
/>
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
{
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
636
|
+
</>
|
|
637
|
+
) : null}
|
|
638
|
+
|
|
639
|
+
{view === 'MONTH' ? (
|
|
640
|
+
<CalendarMonthUI
|
|
641
|
+
cells={monthCells}
|
|
642
|
+
weekdayLabels={weekdayLabels}
|
|
643
|
+
dayNumberLabels={dayNumberLabels}
|
|
644
|
+
selectedEventId={selectedEventId}
|
|
645
|
+
moreLabel={moreLabel || getDefaultCalendarMoreLabel}
|
|
646
|
+
onSelectEvent={handleSelectEvent}
|
|
647
|
+
onSelectDay={handleSelectDay}
|
|
648
|
+
onSelectOverflow={handleSelectDay}
|
|
649
|
+
/>
|
|
650
|
+
) : null}
|
|
651
|
+
|
|
652
|
+
{view === 'YEAR' ? (
|
|
653
|
+
<CalendarYearUI
|
|
654
|
+
months={yearMonths}
|
|
655
|
+
timeZone={range.timeZone}
|
|
656
|
+
locale={locale}
|
|
657
|
+
weekStartsOn={weekStartsOn}
|
|
658
|
+
todayDateKey={nowDateKey}
|
|
659
|
+
onSelectDay={handleSelectDay}
|
|
660
|
+
/>
|
|
661
|
+
) : null}
|
|
662
|
+
|
|
663
|
+
{view === 'AGENDA' ? (
|
|
664
|
+
<CalendarAgendaUI
|
|
665
|
+
days={agendaDays}
|
|
666
|
+
selectedEventId={selectedEventId}
|
|
667
|
+
timeLabelByEventId={agendaTimeLabels}
|
|
668
|
+
emptyText={agendaEmptyText || ''}
|
|
669
|
+
onSelectEvent={handleSelectEvent}
|
|
670
|
+
/>
|
|
671
|
+
) : null}
|
|
672
|
+
|
|
673
|
+
{isTimeGrid ? (
|
|
674
|
+
<div className="f h_0 app_scr auto_y rel">
|
|
675
|
+
<div
|
|
676
|
+
ref={gridContentRef}
|
|
677
|
+
className="h_stretch rel"
|
|
678
|
+
style={gridContentStyle}
|
|
679
|
+
onPointerDown={handleGridPointerDown}
|
|
680
|
+
>
|
|
681
|
+
<CalendarTimeGutterUI
|
|
682
|
+
hourHeight={CALENDAR_HOUR_HEIGHT}
|
|
683
|
+
hourLabels={hourLabels}
|
|
684
|
+
/>
|
|
685
|
+
|
|
686
|
+
{range.days.map((day, dayIndex) => (
|
|
687
|
+
<div
|
|
688
|
+
key={day.dateKey}
|
|
689
|
+
className={cn(
|
|
690
|
+
'f rel bd_l_1 bd_l_bd',
|
|
691
|
+
day.isWeekend ? 'bg_alt' : '',
|
|
692
|
+
)}
|
|
693
|
+
>
|
|
694
|
+
<CalendarHourLinesUI
|
|
695
|
+
hourCount={Math.ceil(getDayLengthMinutes(day) / 60)}
|
|
696
|
+
hourHeight={CALENDAR_HOUR_HEIGHT}
|
|
697
|
+
/>
|
|
698
|
+
|
|
699
|
+
{dayIndex === todayIndex && nowOffset >= 0 ? (
|
|
700
|
+
<CalendarNowLineUI topOffset={nowOffset} />
|
|
701
|
+
) : null}
|
|
702
|
+
|
|
703
|
+
{layoutByDayIndex[dayIndex]?.map((entry) => (
|
|
704
|
+
<CalendarEventUI
|
|
705
|
+
key={entry.event.id}
|
|
706
|
+
editable={!!editable}
|
|
707
|
+
layout={entry}
|
|
611
708
|
hourHeight={CALENDAR_HOUR_HEIGHT}
|
|
709
|
+
selected={selectedEventId === entry.event.id}
|
|
710
|
+
timeLabel={timeLabelByEventId.get(entry.event.id) || ''}
|
|
711
|
+
onSelect={handleSelectEvent}
|
|
612
712
|
/>
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
? (
|
|
632
|
-
<CalendarDraftBlockUI
|
|
633
|
-
startMinute={getMinutesFromDayStart(draftRange.startAt, day.startAt)}
|
|
634
|
-
endMinute={getMinutesFromDayStart(draftRange.endAt, day.startAt)}
|
|
635
|
-
hourHeight={CALENDAR_HOUR_HEIGHT}
|
|
636
|
-
label={draftTimeLabel}
|
|
637
|
-
/>
|
|
638
|
-
)
|
|
639
|
-
: null}
|
|
640
|
-
</div>
|
|
641
|
-
))}
|
|
642
|
-
</div>
|
|
713
|
+
))}
|
|
714
|
+
|
|
715
|
+
{draftRange?.dayIndex === dayIndex ? (
|
|
716
|
+
<CalendarDraftBlockUI
|
|
717
|
+
startMinute={getMinutesFromDayStart(
|
|
718
|
+
draftRange.startAt,
|
|
719
|
+
day.startAt,
|
|
720
|
+
)}
|
|
721
|
+
endMinute={getMinutesFromDayStart(
|
|
722
|
+
draftRange.endAt,
|
|
723
|
+
day.startAt,
|
|
724
|
+
)}
|
|
725
|
+
hourHeight={CALENDAR_HOUR_HEIGHT}
|
|
726
|
+
label={draftTimeLabel}
|
|
727
|
+
/>
|
|
728
|
+
) : null}
|
|
729
|
+
</div>
|
|
730
|
+
))}
|
|
643
731
|
</div>
|
|
644
|
-
|
|
645
|
-
|
|
732
|
+
</div>
|
|
733
|
+
) : null}
|
|
646
734
|
</div>
|
|
647
735
|
);
|
|
648
736
|
});
|