@jsb188/calendar 1.1.10 → 1.1.11
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 +8 -6
- package/src/constants/calendar.ts +8 -1
- package/src/libs/calendar-geometry.ts +167 -91
- package/src/libs/calendar-gesture.ts +58 -15
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +86 -27
- package/src/libs/calendar-state.ts +10 -3
- package/src/libs/calendar-url.ts +31 -8
- package/src/main.ts +3 -0
- package/src/modules/Calendar.tsx +369 -275
- package/src/modules/MiniCalendar.tsx +370 -0
- package/src/ui/CalendarAgendaUI.tsx +31 -11
- package/src/ui/CalendarCoverageUI.tsx +66 -23
- package/src/ui/CalendarEventDetailUI.tsx +122 -117
- package/src/ui/CalendarEventFormUI.tsx +86 -59
- package/src/ui/CalendarMonthUI.tsx +25 -21
- package/src/ui/CalendarRailUI.tsx +199 -139
- package/src/ui/CalendarRequestUI.tsx +216 -177
- package/src/ui/CalendarToolbarUI.tsx +27 -18
- package/src/ui/CalendarUI.tsx +255 -229
- package/src/ui/CalendarViolationUI.tsx +53 -30
- package/src/ui/CalendarYearUI.tsx +36 -50
- package/tests/calendar-geometry.test.ts +226 -78
- package/tests/calendar-gesture.test.ts +43 -12
- package/tests/calendar-range.test.ts +159 -33
- package/tests/calendar-url.test.ts +55 -12
|
@@ -65,115 +65,167 @@ export interface CalendarRailUIProps {
|
|
|
65
65
|
* The rail's mini month grid.
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
-
const CalendarRailMiniMonthUI = memo(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
const CalendarRailMiniMonthUI = memo(
|
|
69
|
+
(p: {
|
|
70
|
+
miniMonth: CalendarRailMiniMonthObj;
|
|
71
|
+
weekdayInitials: string[];
|
|
72
|
+
selectedDateKey?: string | null;
|
|
73
|
+
previousMonthText: string;
|
|
74
|
+
nextMonthText: string;
|
|
75
|
+
onSelectDay: (dateKey: string) => void;
|
|
76
|
+
onStepMonth: (direction: 1 | -1) => void;
|
|
77
|
+
}) => {
|
|
78
|
+
const {
|
|
79
|
+
miniMonth,
|
|
80
|
+
weekdayInitials,
|
|
81
|
+
selectedDateKey,
|
|
82
|
+
previousMonthText,
|
|
83
|
+
nextMonthText,
|
|
84
|
+
onSelectDay,
|
|
85
|
+
onStepMonth,
|
|
86
|
+
} = p;
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
return (
|
|
89
|
+
<div
|
|
90
|
+
className="no_shrink"
|
|
91
|
+
style={{
|
|
92
|
+
paddingLeft: 12,
|
|
93
|
+
paddingRight: 12,
|
|
94
|
+
paddingTop: 8,
|
|
95
|
+
paddingBottom: 8,
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<div className="h_item gap_sm">
|
|
99
|
+
<span className="f ellip ft_sm ft_bold cl_md">{miniMonth.label}</span>
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
{/* No IconButton exists in the kit, so these are the documented raw
|
|
85
102
|
pattern: a bare button wrapping an Icon */}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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}`} />)}
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
className="no_shrink av_sm h_center"
|
|
106
|
+
aria-label={previousMonthText}
|
|
107
|
+
title={previousMonthText}
|
|
108
|
+
onClick={() => onStepMonth(-1)}
|
|
109
|
+
>
|
|
110
|
+
<Icon name="arrow-left" />
|
|
111
|
+
</button>
|
|
115
112
|
|
|
116
|
-
{miniMonth.days.map((day, index) => (
|
|
117
113
|
<button
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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}
|
|
114
|
+
type="button"
|
|
115
|
+
className="no_shrink av_sm h_center"
|
|
116
|
+
aria-label={nextMonthText}
|
|
117
|
+
title={nextMonthText}
|
|
118
|
+
onClick={() => onStepMonth(1)}
|
|
132
119
|
>
|
|
133
|
-
|
|
120
|
+
<Icon name="arrow-right" />
|
|
134
121
|
</button>
|
|
135
|
-
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div
|
|
125
|
+
style={{
|
|
126
|
+
display: 'grid',
|
|
127
|
+
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{weekdayInitials.map((initial, index) => (
|
|
131
|
+
<div key={index} className="a_c ft_tn cl_lt">
|
|
132
|
+
{initial}
|
|
133
|
+
</div>
|
|
134
|
+
))}
|
|
135
|
+
|
|
136
|
+
{Array.from(
|
|
137
|
+
{ length: miniMonth.leadingBlankCount },
|
|
138
|
+
(_unused, index) => (
|
|
139
|
+
<div key={`blank${index}`} />
|
|
140
|
+
),
|
|
141
|
+
)}
|
|
142
|
+
|
|
143
|
+
{miniMonth.days.map((day, index) => (
|
|
144
|
+
<button
|
|
145
|
+
key={day.dateKey}
|
|
146
|
+
type="button"
|
|
147
|
+
className={cn(
|
|
148
|
+
'a_c ft_tn r_xs',
|
|
149
|
+
// Today is bold and the anchored day is filled, so the two
|
|
150
|
+
// stay tellable apart when they are not the same day; a
|
|
151
|
+
// day borrowed from the next month recedes rather than
|
|
152
|
+
// disappearing
|
|
153
|
+
day.isToday
|
|
154
|
+
? 'ft_bold'
|
|
155
|
+
: day.isInPrimaryRange
|
|
156
|
+
? 'cl_md'
|
|
157
|
+
: 'cl_lt',
|
|
158
|
+
day.dateKey === selectedDateKey ? 'bg_active' : '',
|
|
159
|
+
)}
|
|
160
|
+
style={{ paddingTop: 2, paddingBottom: 2 }}
|
|
161
|
+
onClick={() => onSelectDay(day.dateKey)}
|
|
162
|
+
aria-current={
|
|
163
|
+
day.dateKey === selectedDateKey ? 'date' : undefined
|
|
164
|
+
}
|
|
165
|
+
>
|
|
166
|
+
{miniMonth.dayNumberLabels[index]}
|
|
167
|
+
</button>
|
|
168
|
+
))}
|
|
169
|
+
</div>
|
|
136
170
|
</div>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
171
|
+
);
|
|
172
|
+
},
|
|
173
|
+
);
|
|
140
174
|
|
|
141
175
|
/**
|
|
142
176
|
* One calendar's row: its colour, its name, and whether it is drawn.
|
|
143
177
|
*/
|
|
144
178
|
|
|
145
|
-
const CalendarRailSourceUI = memo(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
179
|
+
const CalendarRailSourceUI = memo(
|
|
180
|
+
(p: {
|
|
181
|
+
calendar: CalendarSourceObj;
|
|
182
|
+
onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
|
|
183
|
+
}) => {
|
|
184
|
+
const { calendar, onToggleCalendar } = p;
|
|
150
185
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
186
|
+
return (
|
|
187
|
+
<label
|
|
188
|
+
className="h_item gap_sm pointer unsel"
|
|
189
|
+
style={{
|
|
190
|
+
paddingLeft: 12,
|
|
191
|
+
paddingRight: 12,
|
|
192
|
+
paddingTop: 4,
|
|
193
|
+
paddingBottom: 4,
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
{/* The swatch is DATA — it is the calendar's own colour — so it is an
|
|
157
197
|
inline background rather than a class. A calendar with no colour
|
|
158
198
|
set gets the neutral chip instead of a black dot. */}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
199
|
+
<span
|
|
200
|
+
className={cn(
|
|
201
|
+
'no_shrink r_xs bd_1 bd_bd',
|
|
202
|
+
calendar.color ? '' : 'bg_alt',
|
|
203
|
+
)}
|
|
204
|
+
style={{
|
|
205
|
+
width: 10,
|
|
206
|
+
height: 10,
|
|
207
|
+
backgroundColor: calendar.color || undefined,
|
|
208
|
+
}}
|
|
209
|
+
/>
|
|
163
210
|
|
|
164
|
-
|
|
211
|
+
<span className="f ellip ft_sm" title={calendar.name}>
|
|
212
|
+
{calendar.name}
|
|
213
|
+
</span>
|
|
165
214
|
|
|
166
|
-
|
|
215
|
+
{/* Visibility is a viewer's own concern, so even a calendar they
|
|
167
216
|
cannot edit can be hidden */}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
217
|
+
<ToggleSwitch
|
|
218
|
+
size="sm"
|
|
219
|
+
className="no_shrink"
|
|
220
|
+
checked={calendar.visible}
|
|
221
|
+
onChange={(event) =>
|
|
222
|
+
onToggleCalendar(calendar.id, event.currentTarget.checked)
|
|
223
|
+
}
|
|
224
|
+
/>
|
|
225
|
+
</label>
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
);
|
|
177
229
|
|
|
178
230
|
export const CalendarRailUI = memo((p: CalendarRailUIProps) => {
|
|
179
231
|
const {
|
|
@@ -203,80 +255,88 @@ export const CalendarRailUI = memo((p: CalendarRailUIProps) => {
|
|
|
203
255
|
}
|
|
204
256
|
|
|
205
257
|
return (
|
|
206
|
-
<div
|
|
258
|
+
<div
|
|
259
|
+
className="no_shrink v_stretch h_f bd_r_1 bd_r_bd bg"
|
|
260
|
+
style={{ width: 36, paddingTop: 6 }}
|
|
261
|
+
>
|
|
207
262
|
<button
|
|
208
|
-
type=
|
|
209
|
-
className=
|
|
263
|
+
type="button"
|
|
264
|
+
className="av_sm h_center"
|
|
210
265
|
aria-label={expandText}
|
|
211
266
|
title={expandText}
|
|
212
267
|
onClick={() => onToggleOpen(true)}
|
|
213
268
|
>
|
|
214
|
-
<Icon name=
|
|
269
|
+
<Icon name="sidebar-expand" />
|
|
215
270
|
</button>
|
|
216
271
|
</div>
|
|
217
272
|
);
|
|
218
273
|
}
|
|
219
274
|
|
|
220
275
|
return (
|
|
221
|
-
<div
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
276
|
+
<div
|
|
277
|
+
className="no_shrink v_stretch h_f bd_r_1 bd_r_bd bg"
|
|
278
|
+
style={{ width: 232 }}
|
|
279
|
+
>
|
|
280
|
+
{miniMonth ? (
|
|
281
|
+
<CalendarRailMiniMonthUI
|
|
282
|
+
miniMonth={miniMonth}
|
|
283
|
+
weekdayInitials={weekdayInitials}
|
|
284
|
+
selectedDateKey={selectedDateKey}
|
|
285
|
+
previousMonthText={previousMonthText}
|
|
286
|
+
nextMonthText={nextMonthText}
|
|
287
|
+
onSelectDay={onSelectDay}
|
|
288
|
+
onStepMonth={onStepMonth}
|
|
289
|
+
/>
|
|
290
|
+
) : null}
|
|
235
291
|
|
|
236
292
|
<div
|
|
237
|
-
className=
|
|
238
|
-
style={{
|
|
293
|
+
className="no_shrink h_item gap_sm bd_t_1 bd_t_bd"
|
|
294
|
+
style={{
|
|
295
|
+
paddingLeft: 12,
|
|
296
|
+
paddingRight: 6,
|
|
297
|
+
paddingTop: 6,
|
|
298
|
+
paddingBottom: 2,
|
|
299
|
+
}}
|
|
239
300
|
>
|
|
240
|
-
<span className=
|
|
301
|
+
<span className="f ellip ft_tn cl_lt">{calendarsText}</span>
|
|
241
302
|
|
|
242
|
-
{onToggleOpen
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
)
|
|
254
|
-
: null}
|
|
303
|
+
{onToggleOpen ? (
|
|
304
|
+
<button
|
|
305
|
+
type="button"
|
|
306
|
+
className="no_shrink av_sm h_center"
|
|
307
|
+
aria-label={collapseText}
|
|
308
|
+
title={collapseText}
|
|
309
|
+
onClick={() => onToggleOpen(false)}
|
|
310
|
+
>
|
|
311
|
+
<Icon name="sidebar-close" />
|
|
312
|
+
</button>
|
|
313
|
+
) : null}
|
|
255
314
|
</div>
|
|
256
315
|
|
|
257
|
-
<div className=
|
|
258
|
-
{calendars.length
|
|
259
|
-
|
|
316
|
+
<div className="f h_0 app_scr auto_y">
|
|
317
|
+
{calendars.length ? (
|
|
318
|
+
calendars.map((calendar) => (
|
|
260
319
|
<CalendarRailSourceUI
|
|
261
320
|
key={calendar.id}
|
|
262
321
|
calendar={calendar}
|
|
263
322
|
onToggleCalendar={onToggleCalendar}
|
|
264
323
|
/>
|
|
265
324
|
))
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
325
|
+
) : (
|
|
326
|
+
<div
|
|
327
|
+
className="ft_tn cl_lt"
|
|
328
|
+
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 4 }}
|
|
329
|
+
>
|
|
330
|
+
{emptyText}
|
|
331
|
+
</div>
|
|
332
|
+
)}
|
|
271
333
|
</div>
|
|
272
334
|
|
|
273
|
-
{FooterComponent
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
)
|
|
279
|
-
: null}
|
|
335
|
+
{FooterComponent ? (
|
|
336
|
+
<div className="no_shrink bd_t_1 bd_t_bd" style={{ padding: 8 }}>
|
|
337
|
+
{FooterComponent}
|
|
338
|
+
</div>
|
|
339
|
+
) : null}
|
|
280
340
|
</div>
|
|
281
341
|
);
|
|
282
342
|
});
|