@jsb188/calendar 1.1.2
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 +45 -0
- package/src/constants/calendar.ts +153 -0
- package/src/css.d.ts +7 -0
- package/src/libs/calendar-geometry.ts +500 -0
- package/src/libs/calendar-gesture.ts +341 -0
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +401 -0
- package/src/libs/calendar-state.ts +26 -0
- package/src/libs/calendar-url.ts +191 -0
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +32 -0
- package/src/modules/Calendar.tsx +736 -0
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +128 -0
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +115 -0
- package/src/ui/CalendarMonthUI.tsx +142 -0
- package/src/ui/CalendarToolbarUI.tsx +133 -0
- package/src/ui/CalendarUI.tsx +401 -0
- package/src/ui/CalendarYearUI.tsx +67 -0
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +549 -0
- package/tests/calendar-gesture.test.ts +340 -0
- package/tests/calendar-range.test.ts +358 -0
- package/tests/calendar-url.test.ts +189 -0
- package/tests/roster-layout.test.ts +210 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { type MouseEvent, memo, useCallback, useMemo } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
getCalendarTimeZone,
|
|
7
|
+
normalizeCalendarWeekStartsOn,
|
|
8
|
+
} from '../libs/calendar-range.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A month at a glance.
|
|
12
|
+
*
|
|
13
|
+
* Standalone on purpose: it reads nothing from the rest of this package — no
|
|
14
|
+
* range math, no atoms, no CalendarDayObj — so it drops into a sidebar, a date
|
|
15
|
+
* picker, or a surface that never imports the calendar grid at all. It draws
|
|
16
|
+
* the month itself from a single date and reports clicks back out; every other
|
|
17
|
+
* decision is a prop.
|
|
18
|
+
*
|
|
19
|
+
* Days are addressed by their local date key ("yyyy-MM-dd") rather than by
|
|
20
|
+
* Date, so a caller asking "is this day selected" never has to reason about
|
|
21
|
+
* instants and zones, which disagree about which day it is.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const FILE_CONSTANTS = {
|
|
25
|
+
// Six rows always, never five: a grid that changed height between months
|
|
26
|
+
// would make everything below it jump on every step
|
|
27
|
+
weekCount: 6,
|
|
28
|
+
dateFormat: 'yyyy-MM-dd',
|
|
29
|
+
daySize: 26,
|
|
30
|
+
headerStyle: { marginBottom: 6 },
|
|
31
|
+
gridStyle: {
|
|
32
|
+
display: 'grid' as const,
|
|
33
|
+
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
34
|
+
},
|
|
35
|
+
columnLabelStyle: { paddingBottom: 2 },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* One drawn cell.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
interface MiniCalendarDayObj {
|
|
43
|
+
dateKey: string;
|
|
44
|
+
// Day of month, localized
|
|
45
|
+
label: string;
|
|
46
|
+
// False for the leading and trailing days of the neighbouring months
|
|
47
|
+
isInMonth: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Build the six-by-seven grid a month is drawn on, padded at both ends so the
|
|
52
|
+
* 1st lands under its own weekday column.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
function buildMiniCalendarWeeks(p: {
|
|
56
|
+
monthDate: Date;
|
|
57
|
+
timeZone?: string | null;
|
|
58
|
+
locale?: string | null;
|
|
59
|
+
weekStartsOn: number;
|
|
60
|
+
}): MiniCalendarDayObj[][] {
|
|
61
|
+
const { monthDate, timeZone, locale, weekStartsOn } = p;
|
|
62
|
+
const monthStart = DateTime.fromJSDate(monthDate, {
|
|
63
|
+
zone: timeZone || undefined,
|
|
64
|
+
})
|
|
65
|
+
.setLocale(locale || 'en')
|
|
66
|
+
.startOf('month');
|
|
67
|
+
// luxon: 1 = Monday .. 7 = Sunday; normalize to 0 = Sunday
|
|
68
|
+
const gridStart = monthStart.minus({
|
|
69
|
+
days: ((monthStart.weekday % 7) - weekStartsOn + 7) % 7,
|
|
70
|
+
});
|
|
71
|
+
const weeks: MiniCalendarDayObj[][] = [];
|
|
72
|
+
|
|
73
|
+
for (let weekIndex = 0; weekIndex < FILE_CONSTANTS.weekCount; weekIndex++) {
|
|
74
|
+
const week: MiniCalendarDayObj[] = [];
|
|
75
|
+
|
|
76
|
+
for (let dayIndex = 0; dayIndex < 7; dayIndex++) {
|
|
77
|
+
const day = gridStart.plus({ days: weekIndex * 7 + dayIndex });
|
|
78
|
+
|
|
79
|
+
week.push({
|
|
80
|
+
dateKey: day.toFormat(FILE_CONSTANTS.dateFormat),
|
|
81
|
+
label: day.toFormat('d'),
|
|
82
|
+
isInMonth:
|
|
83
|
+
day.month === monthStart.month && day.year === monthStart.year,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
weeks.push(week);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return weeks;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* Return the text treatment one day gets. A selected day takes its colour from
|
|
95
|
+
* the fill behind it, so it opts out of all three.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
function getMiniCalendarDayColorClassName(p: {
|
|
99
|
+
isSelected: boolean;
|
|
100
|
+
isToday: boolean;
|
|
101
|
+
isInMonth: boolean;
|
|
102
|
+
}): string {
|
|
103
|
+
if (p.isSelected) {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (p.isToday) {
|
|
108
|
+
return 'cl_primary ft_bold';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// A leading or trailing day belongs to the neighbouring month; dimmed, not
|
|
112
|
+
// hidden, so the week it sits in still reads as a week
|
|
113
|
+
return p.isInMonth ? 'cl_md' : 'cl_lt';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface MiniCalendarProps {
|
|
117
|
+
className?: string;
|
|
118
|
+
// Any instant inside the month to draw
|
|
119
|
+
monthDate: Date;
|
|
120
|
+
timeZone?: string | null;
|
|
121
|
+
locale?: string | null;
|
|
122
|
+
// 0 = Sunday .. 6 = Saturday
|
|
123
|
+
weekStartsOn?: number;
|
|
124
|
+
// The heading above the grid. Absent, and with no stepper, the header row
|
|
125
|
+
// is not drawn at all, so a caller that titles its own panel gets only the
|
|
126
|
+
// month.
|
|
127
|
+
title?: string | null;
|
|
128
|
+
// Column headings; derived from the locale when not supplied
|
|
129
|
+
weekdayLabels?: string[];
|
|
130
|
+
// Days drawn as chosen: a solid filled square
|
|
131
|
+
selectedDateKeys?: string[];
|
|
132
|
+
// Days drawn as the range currently on screen: a faint band behind the row.
|
|
133
|
+
// Any run of them is joined, so a week reads as one band and four days read
|
|
134
|
+
// as one shorter band, without the caller saying which shape it meant.
|
|
135
|
+
highlightedDateKeys?: string[];
|
|
136
|
+
// The day marked as today, passed in rather than read from the system
|
|
137
|
+
// clock, so this agrees with whatever zone its owner draws in
|
|
138
|
+
todayDateKey?: string | null;
|
|
139
|
+
// Leading and trailing days of the neighbouring months, dimmed. Off leaves
|
|
140
|
+
// those cells empty so the month reads as its own block.
|
|
141
|
+
showAdjacentMonthDays?: boolean;
|
|
142
|
+
// Edge of one day square, in pixels
|
|
143
|
+
daySize?: number;
|
|
144
|
+
// Display strings; the package owns no copy of its own
|
|
145
|
+
previousText?: string;
|
|
146
|
+
nextText?: string;
|
|
147
|
+
// The two paint states, so a caller can theme the grid without forking it
|
|
148
|
+
selectedClassName?: string;
|
|
149
|
+
highlightClassName?: string;
|
|
150
|
+
// Absent means no stepper is drawn, for a grid somebody else navigates
|
|
151
|
+
onStepMonth?: (direction: 1 | -1) => void;
|
|
152
|
+
onSelectDay?: (dateKey: string) => void;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const MiniCalendar = memo((p: MiniCalendarProps) => {
|
|
156
|
+
const {
|
|
157
|
+
className,
|
|
158
|
+
monthDate,
|
|
159
|
+
timeZone,
|
|
160
|
+
locale,
|
|
161
|
+
weekStartsOn,
|
|
162
|
+
title,
|
|
163
|
+
weekdayLabels,
|
|
164
|
+
selectedDateKeys,
|
|
165
|
+
highlightedDateKeys,
|
|
166
|
+
todayDateKey,
|
|
167
|
+
showAdjacentMonthDays,
|
|
168
|
+
daySize,
|
|
169
|
+
previousText,
|
|
170
|
+
nextText,
|
|
171
|
+
selectedClassName,
|
|
172
|
+
highlightClassName,
|
|
173
|
+
onStepMonth,
|
|
174
|
+
onSelectDay,
|
|
175
|
+
} = p;
|
|
176
|
+
|
|
177
|
+
const resolvedTimeZone = getCalendarTimeZone(timeZone);
|
|
178
|
+
const weekStart = normalizeCalendarWeekStartsOn(weekStartsOn);
|
|
179
|
+
const size = daySize || FILE_CONSTANTS.daySize;
|
|
180
|
+
const cellStyle = useMemo(() => ({ height: size + 4 }), [size]);
|
|
181
|
+
const dayStyle = useMemo(() => ({ width: size, height: size }), [size]);
|
|
182
|
+
|
|
183
|
+
// The grid only changes when the date crosses into another month, so it is
|
|
184
|
+
// keyed on the month rather than the instant: a caller passing a live clock
|
|
185
|
+
// would otherwise rebuild all 42 cells on every tick
|
|
186
|
+
const monthKey = useMemo(
|
|
187
|
+
() =>
|
|
188
|
+
DateTime.fromJSDate(monthDate, { zone: resolvedTimeZone }).toFormat(
|
|
189
|
+
'yyyy-MM',
|
|
190
|
+
),
|
|
191
|
+
[monthDate, resolvedTimeZone],
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
const weeks = useMemo(
|
|
195
|
+
// "monthDate" is read inside but "monthKey" is the dependency; see above
|
|
196
|
+
() =>
|
|
197
|
+
buildMiniCalendarWeeks({
|
|
198
|
+
monthDate,
|
|
199
|
+
timeZone: resolvedTimeZone,
|
|
200
|
+
locale,
|
|
201
|
+
weekStartsOn: weekStart,
|
|
202
|
+
}),
|
|
203
|
+
[monthKey, resolvedTimeZone, locale, weekStart],
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
/*
|
|
207
|
+
* Column headings, built from a real week so they honour the locale and the
|
|
208
|
+
* configured week start rather than a hardcoded list.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
const columnLabels = useMemo(() => {
|
|
212
|
+
if (weekdayLabels) {
|
|
213
|
+
return weekdayLabels;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Any Sunday; 2026-01-04 is one
|
|
217
|
+
const sunday = DateTime.fromObject(
|
|
218
|
+
{ year: 2026, month: 1, day: 4 },
|
|
219
|
+
{ zone: resolvedTimeZone },
|
|
220
|
+
).setLocale(locale || 'en');
|
|
221
|
+
|
|
222
|
+
return Array.from({ length: 7 }, (_unused, index) =>
|
|
223
|
+
sunday
|
|
224
|
+
.plus({ days: index + weekStart })
|
|
225
|
+
.toFormat('ccc')
|
|
226
|
+
.slice(0, 2),
|
|
227
|
+
);
|
|
228
|
+
}, [weekdayLabels, resolvedTimeZone, locale, weekStart]);
|
|
229
|
+
|
|
230
|
+
// Membership is asked 42 times per render, so the lists become sets once
|
|
231
|
+
const selectedSet = useMemo(
|
|
232
|
+
() => new Set(selectedDateKeys || []),
|
|
233
|
+
[selectedDateKeys],
|
|
234
|
+
);
|
|
235
|
+
const highlightedSet = useMemo(
|
|
236
|
+
() => new Set(highlightedDateKeys || []),
|
|
237
|
+
[highlightedDateKeys],
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* Move to the month represented by the clicked step action.
|
|
242
|
+
*/
|
|
243
|
+
const handleStepMonth = useCallback(
|
|
244
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
245
|
+
onStepMonth?.(
|
|
246
|
+
event.currentTarget.dataset.direction === 'PREVIOUS' ? -1 : 1,
|
|
247
|
+
);
|
|
248
|
+
},
|
|
249
|
+
[onStepMonth],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* Report the date stored on the clicked day without allocating one callback
|
|
254
|
+
* for every day cell.
|
|
255
|
+
*/
|
|
256
|
+
const handleSelectDay = useCallback(
|
|
257
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
258
|
+
const dateKey = event.currentTarget.dataset.dateKey;
|
|
259
|
+
if (dateKey) {
|
|
260
|
+
onSelectDay?.(dateKey);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
[onSelectDay],
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<div className={cn('unsel', className)}>
|
|
268
|
+
{title || onStepMonth ? (
|
|
269
|
+
<div
|
|
270
|
+
className="h_spread"
|
|
271
|
+
style={FILE_CONSTANTS.headerStyle}
|
|
272
|
+
>
|
|
273
|
+
<span className="f ellip ft_sm ft_bold cl_md">{title || ''}</span>
|
|
274
|
+
|
|
275
|
+
{onStepMonth ? (
|
|
276
|
+
<span className="h_item no_shrink">
|
|
277
|
+
{/* No IconButton exists in the kit, so these are the
|
|
278
|
+
documented raw pattern: a bare button wrapping an
|
|
279
|
+
Icon. The sprite has no chevron-left, so the
|
|
280
|
+
previous arrow is the right one turned around. */}
|
|
281
|
+
<button
|
|
282
|
+
type="button"
|
|
283
|
+
className="av_sm h_center tf_rotate_180"
|
|
284
|
+
aria-label={previousText}
|
|
285
|
+
title={previousText}
|
|
286
|
+
data-direction="PREVIOUS"
|
|
287
|
+
onClick={handleStepMonth}
|
|
288
|
+
>
|
|
289
|
+
<Icon name="chevron-right" />
|
|
290
|
+
</button>
|
|
291
|
+
|
|
292
|
+
<button
|
|
293
|
+
type="button"
|
|
294
|
+
className="av_sm h_center"
|
|
295
|
+
aria-label={nextText}
|
|
296
|
+
title={nextText}
|
|
297
|
+
data-direction="NEXT"
|
|
298
|
+
onClick={handleStepMonth}
|
|
299
|
+
>
|
|
300
|
+
<Icon name="chevron-right" />
|
|
301
|
+
</button>
|
|
302
|
+
</span>
|
|
303
|
+
) : null}
|
|
304
|
+
</div>
|
|
305
|
+
) : null}
|
|
306
|
+
|
|
307
|
+
<div style={FILE_CONSTANTS.gridStyle}>
|
|
308
|
+
{columnLabels.map((label, index) => (
|
|
309
|
+
<div
|
|
310
|
+
key={index}
|
|
311
|
+
className="a_c ft_xxs cl_lt"
|
|
312
|
+
style={FILE_CONSTANTS.columnLabelStyle}
|
|
313
|
+
>
|
|
314
|
+
{label}
|
|
315
|
+
</div>
|
|
316
|
+
))}
|
|
317
|
+
</div>
|
|
318
|
+
|
|
319
|
+
{weeks.map((week, weekIndex) => (
|
|
320
|
+
<div
|
|
321
|
+
key={weekIndex}
|
|
322
|
+
style={FILE_CONSTANTS.gridStyle}
|
|
323
|
+
>
|
|
324
|
+
{week.map((day, dayIndex) => {
|
|
325
|
+
const isHighlighted = highlightedSet.has(day.dateKey);
|
|
326
|
+
const isSelected = selectedSet.has(day.dateKey);
|
|
327
|
+
const isDrawn = day.isInMonth || !!showAdjacentMonthDays;
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<div
|
|
331
|
+
key={day.dateKey}
|
|
332
|
+
className={cn(
|
|
333
|
+
'h_center',
|
|
334
|
+
isHighlighted ? highlightClassName || 'bg_alt' : '',
|
|
335
|
+
// Only the ends of a run are rounded, so a highlighted
|
|
336
|
+
// week reads as one band rather than seven pills
|
|
337
|
+
isHighlighted &&
|
|
338
|
+
!highlightedSet.has(week[dayIndex - 1]?.dateKey || '')
|
|
339
|
+
? 'rl_df'
|
|
340
|
+
: '',
|
|
341
|
+
isHighlighted &&
|
|
342
|
+
!highlightedSet.has(week[dayIndex + 1]?.dateKey || '')
|
|
343
|
+
? 'rr_df'
|
|
344
|
+
: '',
|
|
345
|
+
)}
|
|
346
|
+
style={cellStyle}
|
|
347
|
+
>
|
|
348
|
+
{isDrawn ? (
|
|
349
|
+
<button
|
|
350
|
+
type="button"
|
|
351
|
+
className={cn(
|
|
352
|
+
'h_center ft_sm r_df',
|
|
353
|
+
isSelected
|
|
354
|
+
? selectedClassName || 'bg_primary'
|
|
355
|
+
: 'bg_active_hv',
|
|
356
|
+
getMiniCalendarDayColorClassName({
|
|
357
|
+
isSelected,
|
|
358
|
+
isToday: day.dateKey === todayDateKey,
|
|
359
|
+
isInMonth: day.isInMonth,
|
|
360
|
+
}),
|
|
361
|
+
)}
|
|
362
|
+
data-date-key={day.dateKey}
|
|
363
|
+
style={dayStyle}
|
|
364
|
+
onClick={handleSelectDay}
|
|
365
|
+
>
|
|
366
|
+
{day.label}
|
|
367
|
+
</button>
|
|
368
|
+
) : null}
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
})}
|
|
372
|
+
</div>
|
|
373
|
+
))}
|
|
374
|
+
</div>
|
|
375
|
+
);
|
|
376
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { CalendarViewEnum } from '../constants/calendar.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calendar surface types.
|
|
5
|
+
*
|
|
6
|
+
* These describe what the calendar draws, which is deliberately narrower than
|
|
7
|
+
* what the schedule API returns: the grid needs a title, a time range, and a
|
|
8
|
+
* few flags, and nothing it renders should depend on the full server shape.
|
|
9
|
+
* Keeping the boundary here is what lets the same grid draw a daycare shift,
|
|
10
|
+
* an off-site, and a network event.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One entry as the grid understands it. Times are real instants; the grid
|
|
15
|
+
* converts them into the calendar's display zone once, at layout time.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface CalendarEventObj {
|
|
19
|
+
id: string;
|
|
20
|
+
calendarId: string;
|
|
21
|
+
title: string;
|
|
22
|
+
startAt: Date;
|
|
23
|
+
endAt: Date;
|
|
24
|
+
allDay: boolean;
|
|
25
|
+
// SHIFT | EVENT | BLOCK — a BLOCK is drawn as unavailability, not staffing
|
|
26
|
+
kind: string;
|
|
27
|
+
// DRAFT | PUBLISHED | CANCELED
|
|
28
|
+
status: string;
|
|
29
|
+
location?: string | null;
|
|
30
|
+
note?: string | null;
|
|
31
|
+
color?: string | null;
|
|
32
|
+
// Everyone working this entry, for the assignee chips and "my calendar only"
|
|
33
|
+
assigneeResourceIds: string[];
|
|
34
|
+
assigneeNames?: string[];
|
|
35
|
+
roomId?: string | null;
|
|
36
|
+
roomName?: string | null;
|
|
37
|
+
breach?: 'BLOCK' | 'WARN' | null;
|
|
38
|
+
version?: string;
|
|
39
|
+
pending?: boolean;
|
|
40
|
+
// How many people the entry still needs; drives the "open shift" treatment
|
|
41
|
+
openCount?: number;
|
|
42
|
+
// Set when the viewer is one of the assignees, so the grid can mark it
|
|
43
|
+
// without re-deriving the answer for every event on every render
|
|
44
|
+
isMine?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One event placed in the time grid: the vertical extent in minutes from the
|
|
49
|
+
* top of its day, plus the horizontal share it takes of that day's column.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
export interface CalendarEventLayoutObj {
|
|
53
|
+
event: CalendarEventObj;
|
|
54
|
+
// Index of the day column this segment belongs to
|
|
55
|
+
dayIndex: number;
|
|
56
|
+
// Minutes from local midnight; the grid multiplies by the hour height
|
|
57
|
+
startMinute: number;
|
|
58
|
+
endMinute: number;
|
|
59
|
+
// Fractions of the day column's width, 0..1
|
|
60
|
+
left: number;
|
|
61
|
+
width: number;
|
|
62
|
+
// Which overlap column this took, and how many there were, so a stacked
|
|
63
|
+
// layout can raise the one in front
|
|
64
|
+
column: number;
|
|
65
|
+
columnCount: number;
|
|
66
|
+
// True when this is the continuation of an entry that began on an earlier
|
|
67
|
+
// day, so the grid can round only the corners that are really ends
|
|
68
|
+
continuesFromPreviousDay: boolean;
|
|
69
|
+
continuesToNextDay: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* One day in a rendered range, resolved in the calendar's display zone.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
export interface CalendarDayObj {
|
|
77
|
+
// Local calendar date, "yyyy-MM-dd", stable across zones
|
|
78
|
+
dateKey: string;
|
|
79
|
+
// Local midnight of this day as an instant
|
|
80
|
+
startAt: Date;
|
|
81
|
+
endAt: Date;
|
|
82
|
+
isToday: boolean;
|
|
83
|
+
isWeekend: boolean;
|
|
84
|
+
// False for the leading and trailing days of a month grid
|
|
85
|
+
isInPrimaryRange: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The window a view is currently showing, plus the days inside it.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export interface CalendarRangeObj {
|
|
93
|
+
view: CalendarViewEnum;
|
|
94
|
+
// The date the view is anchored to; what "next" and "previous" move
|
|
95
|
+
anchorDate: Date;
|
|
96
|
+
// The instants to query — a month view's range covers its leading and
|
|
97
|
+
// trailing days too, because they are drawn
|
|
98
|
+
from: Date;
|
|
99
|
+
to: Date;
|
|
100
|
+
days: CalendarDayObj[];
|
|
101
|
+
timeZone: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A time range the user is drawing or has selected, in the grid.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
export interface CalendarSelectionObj {
|
|
109
|
+
startAt: Date;
|
|
110
|
+
endAt: Date;
|
|
111
|
+
allDay: boolean;
|
|
112
|
+
// Which calendar a new entry would be created on
|
|
113
|
+
calendarId: string | null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One calendar in the overlay list, with the viewer's toggle state.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
export interface CalendarSourceObj {
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
color: string | null;
|
|
124
|
+
kind: string;
|
|
125
|
+
// COVERAGE calendars run the constraint engine and get the coverage board
|
|
126
|
+
canEdit: boolean;
|
|
127
|
+
visible: boolean;
|
|
128
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ScheduleSlotInput } from '@jsb188/graphql/schedule.d';
|
|
2
|
+
export interface ShiftFormValues {
|
|
3
|
+
kind: 'SHIFT' | 'EVENT' | 'BLOCK';
|
|
4
|
+
title: string;
|
|
5
|
+
roomId: string;
|
|
6
|
+
start: string;
|
|
7
|
+
end: string;
|
|
8
|
+
allDay: boolean;
|
|
9
|
+
note: string;
|
|
10
|
+
location: string;
|
|
11
|
+
slots: ScheduleSlotInput[];
|
|
12
|
+
repeat: '' | 'DAILY' | 'WEEKLY' | 'MONTHLY';
|
|
13
|
+
interval: number;
|
|
14
|
+
weekdays: number[];
|
|
15
|
+
monthDay: number;
|
|
16
|
+
count: string;
|
|
17
|
+
until: string;
|
|
18
|
+
future: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
4
|
+
import type { CalendarEventObj } from '../types/calendar.d.ts';
|
|
5
|
+
|
|
6
|
+
const FILE_CONSTANTS = {
|
|
7
|
+
dayHeaderStyle: {
|
|
8
|
+
paddingLeft: 12,
|
|
9
|
+
paddingRight: 12,
|
|
10
|
+
paddingTop: 6,
|
|
11
|
+
paddingBottom: 2,
|
|
12
|
+
},
|
|
13
|
+
eventStyle: {
|
|
14
|
+
paddingLeft: 12,
|
|
15
|
+
paddingRight: 12,
|
|
16
|
+
paddingTop: 4,
|
|
17
|
+
paddingBottom: 4,
|
|
18
|
+
},
|
|
19
|
+
timeLabelStyle: { width: 104 },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The agenda ("Schedule") list.
|
|
24
|
+
*
|
|
25
|
+
* Runs FORWARD from its anchor rather than around it: a worker opening this
|
|
26
|
+
* wants what is coming, not what they already worked. Days with nothing on
|
|
27
|
+
* them are omitted entirely — a month of empty headings is scrolling, not
|
|
28
|
+
* information — but the whole list being empty is called out explicitly, so an
|
|
29
|
+
* empty agenda never reads as a failed load.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export interface CalendarAgendaDayObj {
|
|
33
|
+
dateKey: string;
|
|
34
|
+
// Localized, e.g. "Wed, Jul 22"
|
|
35
|
+
label: string;
|
|
36
|
+
isToday: boolean;
|
|
37
|
+
events: CalendarEventObj[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CalendarAgendaUIProps {
|
|
41
|
+
days: CalendarAgendaDayObj[];
|
|
42
|
+
selectedEventId: string | null;
|
|
43
|
+
// Formatted time range per event id, or the all-day word
|
|
44
|
+
timeLabelByEventId: Map<string, string>;
|
|
45
|
+
emptyText: string;
|
|
46
|
+
onSelectEvent: (eventId: string) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const CalendarAgendaUI = memo((p: CalendarAgendaUIProps) => {
|
|
50
|
+
const {
|
|
51
|
+
days,
|
|
52
|
+
selectedEventId,
|
|
53
|
+
timeLabelByEventId,
|
|
54
|
+
emptyText,
|
|
55
|
+
onSelectEvent,
|
|
56
|
+
} = p;
|
|
57
|
+
|
|
58
|
+
if (!days.length) {
|
|
59
|
+
return (
|
|
60
|
+
<div className="f h_0 v_center a_c">
|
|
61
|
+
<span className="ft_sm cl_lt">{emptyText}</span>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="f h_0 app_scr auto_y">
|
|
68
|
+
{days.map((day) => (
|
|
69
|
+
<div
|
|
70
|
+
key={day.dateKey}
|
|
71
|
+
className="bd_t_1 bd_t_bd"
|
|
72
|
+
>
|
|
73
|
+
<div
|
|
74
|
+
className={cn('ft_xxs', day.isToday ? 'ft_bold' : 'cl_lt')}
|
|
75
|
+
style={FILE_CONSTANTS.dayHeaderStyle}
|
|
76
|
+
>
|
|
77
|
+
{day.label}
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
{day.events.map((event) => (
|
|
81
|
+
<button
|
|
82
|
+
key={`${day.dateKey}:${event.id}`}
|
|
83
|
+
type="button"
|
|
84
|
+
className={cn(
|
|
85
|
+
'w_f a_l h_item gap_sm',
|
|
86
|
+
event.status === 'CANCELED' ? 'strikethrough' : '',
|
|
87
|
+
selectedEventId === event.id ? 'bg_active' : '',
|
|
88
|
+
)}
|
|
89
|
+
style={FILE_CONSTANTS.eventStyle}
|
|
90
|
+
onClick={() => onSelectEvent(event.id)}
|
|
91
|
+
>
|
|
92
|
+
<span
|
|
93
|
+
className={cn(
|
|
94
|
+
'no_shrink ft_xxs cl_lt rel of',
|
|
95
|
+
event.status === 'DRAFT'
|
|
96
|
+
? CALENDAR_DRAFT_PATTERN_CLASS_NAME
|
|
97
|
+
: '',
|
|
98
|
+
)}
|
|
99
|
+
style={FILE_CONSTANTS.timeLabelStyle}
|
|
100
|
+
>
|
|
101
|
+
{timeLabelByEventId.get(event.id) || ''}
|
|
102
|
+
</span>
|
|
103
|
+
|
|
104
|
+
<span className="f ellip ft_sm">{event.title}</span>
|
|
105
|
+
|
|
106
|
+
{event.isMine ? (
|
|
107
|
+
<span className="no_shrink ft_xxs cl_lt">•</span>
|
|
108
|
+
) : null}
|
|
109
|
+
</button>
|
|
110
|
+
))}
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
});
|