@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
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
-
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
-
import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
|
|
4
|
-
import { memo } from 'react';
|
|
5
|
-
import type { CalendarDayObj, CalendarSourceObj } from '../types/calendar.d.ts';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The calendar's left rail: which calendars are drawn, and a mini month for
|
|
9
|
-
* jumping somewhere else.
|
|
10
|
-
*
|
|
11
|
-
* Stateless like the rest of /ui/. It holds no visibility map of its own — a
|
|
12
|
-
* calendar's toggle reflects the `visible` flag it arrives with, so the
|
|
13
|
-
* "absent means visible" rule stays in one place (isCalendarVisible in
|
|
14
|
-
* calendar-state) instead of being re-decided here. That is what makes a
|
|
15
|
-
* newly granted calendar show up without the viewer hunting for it: only an
|
|
16
|
-
* explicit untick ever hides one.
|
|
17
|
-
*
|
|
18
|
-
* The mini month deliberately draws no events. It is a jump target, and a
|
|
19
|
-
* month of dots at this size is noise that would also force the rail to load
|
|
20
|
-
* a range nobody is looking at.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* One month for the rail's navigator, shaped exactly like the year view's
|
|
25
|
-
* mini grids so the two read as the same control.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export interface CalendarRailMiniMonthObj {
|
|
29
|
-
// Localized month and year, e.g. "July 2026"
|
|
30
|
-
label: string;
|
|
31
|
-
// Leading blanks before the 1st, so it lands under its own weekday
|
|
32
|
-
leadingBlankCount: number;
|
|
33
|
-
days: CalendarDayObj[];
|
|
34
|
-
dayNumberLabels: string[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface CalendarRailUIProps {
|
|
38
|
-
open: boolean;
|
|
39
|
-
// Every calendar the viewer can see, in display order
|
|
40
|
-
calendars: CalendarSourceObj[];
|
|
41
|
-
miniMonth?: CalendarRailMiniMonthObj | null;
|
|
42
|
-
// Single-letter weekday initials for the mini grid's header
|
|
43
|
-
weekdayInitials: string[];
|
|
44
|
-
// The day the calendar is anchored on, marked in the mini grid
|
|
45
|
-
selectedDateKey?: string | null;
|
|
46
|
-
// Display strings. This package holds no copy of its own: the app owns
|
|
47
|
-
// i18n, so every user-visible word is passed in.
|
|
48
|
-
calendarsText: string;
|
|
49
|
-
emptyText: string;
|
|
50
|
-
expandText: string;
|
|
51
|
-
collapseText: string;
|
|
52
|
-
previousMonthText: string;
|
|
53
|
-
nextMonthText: string;
|
|
54
|
-
// Rendered at the bottom: subscribe, new calendar, whatever the page owns
|
|
55
|
-
FooterComponent?: React.ReactNode;
|
|
56
|
-
onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
|
|
57
|
-
onSelectDay: (dateKey: string) => void;
|
|
58
|
-
onStepMonth: (direction: 1 | -1) => void;
|
|
59
|
-
// Omitted when the page collapses the rail from somewhere else, in which
|
|
60
|
-
// case a closed rail takes no width at all
|
|
61
|
-
onToggleOpen?: (nextOpen: boolean) => void;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The rail's mini month grid.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
const CalendarRailMiniMonthUI = memo((p: {
|
|
69
|
-
miniMonth: CalendarRailMiniMonthObj;
|
|
70
|
-
weekdayInitials: string[];
|
|
71
|
-
selectedDateKey?: string | null;
|
|
72
|
-
previousMonthText: string;
|
|
73
|
-
nextMonthText: string;
|
|
74
|
-
onSelectDay: (dateKey: string) => void;
|
|
75
|
-
onStepMonth: (direction: 1 | -1) => void;
|
|
76
|
-
}) => {
|
|
77
|
-
const { miniMonth, weekdayInitials, selectedDateKey, previousMonthText, nextMonthText, onSelectDay, onStepMonth } = p;
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<div className='no_shrink' style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}>
|
|
81
|
-
<div className='h_item gap_sm'>
|
|
82
|
-
<span className='f ellip ft_sm ft_bold cl_md'>{miniMonth.label}</span>
|
|
83
|
-
|
|
84
|
-
{/* No IconButton exists in the kit, so these are the documented raw
|
|
85
|
-
pattern: a bare button wrapping an Icon */}
|
|
86
|
-
<button
|
|
87
|
-
type='button'
|
|
88
|
-
className='no_shrink av_sm h_center'
|
|
89
|
-
aria-label={previousMonthText}
|
|
90
|
-
title={previousMonthText}
|
|
91
|
-
onClick={() => onStepMonth(-1)}
|
|
92
|
-
>
|
|
93
|
-
<Icon name='arrow-left' />
|
|
94
|
-
</button>
|
|
95
|
-
|
|
96
|
-
<button
|
|
97
|
-
type='button'
|
|
98
|
-
className='no_shrink av_sm h_center'
|
|
99
|
-
aria-label={nextMonthText}
|
|
100
|
-
title={nextMonthText}
|
|
101
|
-
onClick={() => onStepMonth(1)}
|
|
102
|
-
>
|
|
103
|
-
<Icon name='arrow-right' />
|
|
104
|
-
</button>
|
|
105
|
-
</div>
|
|
106
|
-
|
|
107
|
-
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))' }}>
|
|
108
|
-
{weekdayInitials.map((initial, index) => (
|
|
109
|
-
<div key={index} className='a_c ft_tn cl_lt'>
|
|
110
|
-
{initial}
|
|
111
|
-
</div>
|
|
112
|
-
))}
|
|
113
|
-
|
|
114
|
-
{Array.from({ length: miniMonth.leadingBlankCount }, (_unused, index) => <div key={`blank${index}`} />)}
|
|
115
|
-
|
|
116
|
-
{miniMonth.days.map((day, index) => (
|
|
117
|
-
<button
|
|
118
|
-
key={day.dateKey}
|
|
119
|
-
type='button'
|
|
120
|
-
className={cn(
|
|
121
|
-
'a_c ft_tn r_xs',
|
|
122
|
-
// Today is bold and the anchored day is filled, so the two
|
|
123
|
-
// stay tellable apart when they are not the same day; a
|
|
124
|
-
// day borrowed from the next month recedes rather than
|
|
125
|
-
// disappearing
|
|
126
|
-
day.isToday ? 'ft_bold' : day.isInPrimaryRange ? 'cl_md' : 'cl_lt',
|
|
127
|
-
day.dateKey === selectedDateKey ? 'bg_active' : '',
|
|
128
|
-
)}
|
|
129
|
-
style={{ paddingTop: 2, paddingBottom: 2 }}
|
|
130
|
-
onClick={() => onSelectDay(day.dateKey)}
|
|
131
|
-
aria-current={day.dateKey === selectedDateKey ? 'date' : undefined}
|
|
132
|
-
>
|
|
133
|
-
{miniMonth.dayNumberLabels[index]}
|
|
134
|
-
</button>
|
|
135
|
-
))}
|
|
136
|
-
</div>
|
|
137
|
-
</div>
|
|
138
|
-
);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* One calendar's row: its colour, its name, and whether it is drawn.
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
const CalendarRailSourceUI = memo((p: {
|
|
146
|
-
calendar: CalendarSourceObj;
|
|
147
|
-
onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
|
|
148
|
-
}) => {
|
|
149
|
-
const { calendar, onToggleCalendar } = p;
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<label
|
|
153
|
-
className='h_item gap_sm pointer unsel'
|
|
154
|
-
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 4, paddingBottom: 4 }}
|
|
155
|
-
>
|
|
156
|
-
{/* The swatch is DATA — it is the calendar's own colour — so it is an
|
|
157
|
-
inline background rather than a class. A calendar with no colour
|
|
158
|
-
set gets the neutral chip instead of a black dot. */}
|
|
159
|
-
<span
|
|
160
|
-
className={cn('no_shrink r_xs bd_1 bd_bd', calendar.color ? '' : 'bg_alt')}
|
|
161
|
-
style={{ width: 10, height: 10, backgroundColor: calendar.color || undefined }}
|
|
162
|
-
/>
|
|
163
|
-
|
|
164
|
-
<span className='f ellip ft_sm' title={calendar.name}>{calendar.name}</span>
|
|
165
|
-
|
|
166
|
-
{/* Visibility is a viewer's own concern, so even a calendar they
|
|
167
|
-
cannot edit can be hidden */}
|
|
168
|
-
<ToggleSwitch
|
|
169
|
-
size='sm'
|
|
170
|
-
className='no_shrink'
|
|
171
|
-
checked={calendar.visible}
|
|
172
|
-
onChange={(event) => onToggleCalendar(calendar.id, event.currentTarget.checked)}
|
|
173
|
-
/>
|
|
174
|
-
</label>
|
|
175
|
-
);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
export const CalendarRailUI = memo((p: CalendarRailUIProps) => {
|
|
179
|
-
const {
|
|
180
|
-
open,
|
|
181
|
-
calendars,
|
|
182
|
-
miniMonth,
|
|
183
|
-
weekdayInitials,
|
|
184
|
-
selectedDateKey,
|
|
185
|
-
calendarsText,
|
|
186
|
-
emptyText,
|
|
187
|
-
expandText,
|
|
188
|
-
collapseText,
|
|
189
|
-
previousMonthText,
|
|
190
|
-
nextMonthText,
|
|
191
|
-
FooterComponent,
|
|
192
|
-
onToggleCalendar,
|
|
193
|
-
onSelectDay,
|
|
194
|
-
onStepMonth,
|
|
195
|
-
onToggleOpen,
|
|
196
|
-
} = p;
|
|
197
|
-
|
|
198
|
-
if (!open) {
|
|
199
|
-
// With no way to reopen it from here, a closed rail is simply gone; the
|
|
200
|
-
// page's own control is what brings it back
|
|
201
|
-
if (!onToggleOpen) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return (
|
|
206
|
-
<div className='no_shrink v_stretch h_f bd_r_1 bd_r_bd bg' style={{ width: 36, paddingTop: 6 }}>
|
|
207
|
-
<button
|
|
208
|
-
type='button'
|
|
209
|
-
className='av_sm h_center'
|
|
210
|
-
aria-label={expandText}
|
|
211
|
-
title={expandText}
|
|
212
|
-
onClick={() => onToggleOpen(true)}
|
|
213
|
-
>
|
|
214
|
-
<Icon name='sidebar-expand' />
|
|
215
|
-
</button>
|
|
216
|
-
</div>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return (
|
|
221
|
-
<div className='no_shrink v_stretch h_f bd_r_1 bd_r_bd bg' style={{ width: 232 }}>
|
|
222
|
-
{miniMonth
|
|
223
|
-
? (
|
|
224
|
-
<CalendarRailMiniMonthUI
|
|
225
|
-
miniMonth={miniMonth}
|
|
226
|
-
weekdayInitials={weekdayInitials}
|
|
227
|
-
selectedDateKey={selectedDateKey}
|
|
228
|
-
previousMonthText={previousMonthText}
|
|
229
|
-
nextMonthText={nextMonthText}
|
|
230
|
-
onSelectDay={onSelectDay}
|
|
231
|
-
onStepMonth={onStepMonth}
|
|
232
|
-
/>
|
|
233
|
-
)
|
|
234
|
-
: null}
|
|
235
|
-
|
|
236
|
-
<div
|
|
237
|
-
className='no_shrink h_item gap_sm bd_t_1 bd_t_bd'
|
|
238
|
-
style={{ paddingLeft: 12, paddingRight: 6, paddingTop: 6, paddingBottom: 2 }}
|
|
239
|
-
>
|
|
240
|
-
<span className='f ellip ft_tn cl_lt'>{calendarsText}</span>
|
|
241
|
-
|
|
242
|
-
{onToggleOpen
|
|
243
|
-
? (
|
|
244
|
-
<button
|
|
245
|
-
type='button'
|
|
246
|
-
className='no_shrink av_sm h_center'
|
|
247
|
-
aria-label={collapseText}
|
|
248
|
-
title={collapseText}
|
|
249
|
-
onClick={() => onToggleOpen(false)}
|
|
250
|
-
>
|
|
251
|
-
<Icon name='sidebar-close' />
|
|
252
|
-
</button>
|
|
253
|
-
)
|
|
254
|
-
: null}
|
|
255
|
-
</div>
|
|
256
|
-
|
|
257
|
-
<div className='f h_0 app_scr auto_y'>
|
|
258
|
-
{calendars.length
|
|
259
|
-
? calendars.map((calendar) => (
|
|
260
|
-
<CalendarRailSourceUI
|
|
261
|
-
key={calendar.id}
|
|
262
|
-
calendar={calendar}
|
|
263
|
-
onToggleCalendar={onToggleCalendar}
|
|
264
|
-
/>
|
|
265
|
-
))
|
|
266
|
-
: (
|
|
267
|
-
<div className='ft_tn cl_lt' style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 4 }}>
|
|
268
|
-
{emptyText}
|
|
269
|
-
</div>
|
|
270
|
-
)}
|
|
271
|
-
</div>
|
|
272
|
-
|
|
273
|
-
{FooterComponent
|
|
274
|
-
? (
|
|
275
|
-
<div className='no_shrink bd_t_1 bd_t_bd' style={{ padding: 8 }}>
|
|
276
|
-
{FooterComponent}
|
|
277
|
-
</div>
|
|
278
|
-
)
|
|
279
|
-
: null}
|
|
280
|
-
</div>
|
|
281
|
-
);
|
|
282
|
-
});
|