@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.
@@ -1,3 +1,4 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
1
2
  import { cn } from '@jsb188/app/utils/string.ts';
2
3
  import { memo } from 'react';
3
4
  import {
@@ -6,7 +7,10 @@ import {
6
7
  CALENDAR_GUTTER_WIDTH,
7
8
  } from '../constants/calendar.ts';
8
9
  import type { CalendarAllDayBarObj } from '../libs/calendar-geometry.ts';
9
- import type { CalendarDayObj, CalendarEventLayoutObj } from '../types/calendar.d.ts';
10
+ import type {
11
+ CalendarDayObj,
12
+ CalendarEventLayoutObj,
13
+ } from '../types/calendar.d.ts';
10
14
 
11
15
  /**
12
16
  * Stateless calendar UI.
@@ -27,70 +31,72 @@ import type { CalendarDayObj, CalendarEventLayoutObj } from '../types/calendar.d
27
31
  * The left-hand hour labels.
28
32
  */
29
33
 
30
- export const CalendarTimeGutterUI = memo((p: {
31
- hourHeight: number;
32
- // Labels for hours 0..23, already formatted and localized by the caller
33
- hourLabels: string[];
34
- }) => {
35
- const { hourHeight, hourLabels } = p;
34
+ export const CalendarTimeGutterUI = memo(
35
+ (p: {
36
+ hourHeight: number;
37
+ // Labels for hours 0..23, already formatted and localized by the caller
38
+ hourLabels: string[];
39
+ }) => {
40
+ const { hourHeight, hourLabels } = p;
36
41
 
37
- return (
38
- <div
39
- className='no_shrink rel'
40
- style={{ width: CALENDAR_GUTTER_WIDTH }}
41
- >
42
- {hourLabels.map((label, hour) => (
43
- <div
44
- key={hour}
45
- className='abs w_f a_r ft_tn cl_lt'
46
- // Pulled up by half a line so the label sits ON its gridline
47
- // rather than hanging below it. Midnight is unlabelled: it is
48
- // the day boundary the header already names.
49
- style={{ top: hour * hourHeight - 7, paddingRight: 6 }}
50
- >
51
- {hour === 0 ? null : label}
52
- </div>
53
- ))}
54
- </div>
55
- );
56
- });
42
+ return (
43
+ <div
44
+ className="no_shrink rel"
45
+ style={{ width: CALENDAR_GUTTER_WIDTH }}
46
+ >
47
+ {hourLabels.map((label, hour) => (
48
+ <div
49
+ key={hour}
50
+ className="abs w_f a_r ft_xxs cl_lt"
51
+ // Pulled up by half a line so the label sits ON its gridline
52
+ // rather than hanging below it. Midnight is unlabelled: it is
53
+ // the day boundary the header already names.
54
+ style={{ top: hour * hourHeight - 7, paddingRight: 6 }}
55
+ >
56
+ {hour === 0 ? null : label}
57
+ </div>
58
+ ))}
59
+ </div>
60
+ );
61
+ },
62
+ );
57
63
 
58
64
  /**
59
65
  * The horizontal hour lines behind the day columns.
60
66
  */
61
67
 
62
- export const CalendarHourLinesUI = memo((p: {
63
- hourCount: number;
64
- hourHeight: number;
65
- }) => {
66
- const { hourCount, hourHeight } = p;
68
+ export const CalendarHourLinesUI = memo(
69
+ (p: { hourCount: number; hourHeight: number }) => {
70
+ const { hourCount, hourHeight } = p;
67
71
 
68
- return (
69
- <>
70
- {Array.from({ length: hourCount }, (_unused, hour) => (
71
- <div
72
- key={hour}
73
- className='abs w_f bd_t_1 bd_t_bd'
74
- style={{ top: hour * hourHeight }}
75
- />
76
- ))}
77
- </>
78
- );
79
- });
72
+ return (
73
+ <>
74
+ {Array.from({ length: hourCount }, (_unused, hour) => (
75
+ <div
76
+ key={hour}
77
+ className="abs w_f bd_t_1 bd_t_bd"
78
+ style={{ top: hour * hourHeight }}
79
+ />
80
+ ))}
81
+ </>
82
+ );
83
+ },
84
+ );
80
85
 
81
86
  /**
82
87
  * The "now" line, drawn only on the day that is actually today.
83
88
  */
84
89
 
85
- export const CalendarNowLineUI = memo((p: {
86
- topOffset: number;
87
- }) => {
90
+ export const CalendarNowLineUI = memo((p: { topOffset: number }) => {
88
91
  return (
89
92
  <div
90
- className='abs w_f z3'
93
+ className="abs w_f z3"
91
94
  style={{ top: p.topOffset }}
92
95
  >
93
- <div className='bg_red' style={{ height: 2 }} />
96
+ <div
97
+ className="bg_red"
98
+ style={{ height: 2 }}
99
+ />
94
100
  </div>
95
101
  );
96
102
  });
@@ -131,181 +137,227 @@ export interface CalendarEventUIProps {
131
137
  * One event block in the time grid.
132
138
  */
133
139
 
134
- export const CalendarEventUI = memo((p: CalendarEventUIProps) => {
135
- const { layout, hourHeight, selected, editable, timeLabel, onSelect } = p;
136
- const { event } = layout;
140
+ export const CalendarEventUI = memo(
141
+ (p: CalendarEventUIProps) => {
142
+ const { layout, hourHeight, selected, editable, timeLabel, onSelect } = p;
143
+ const { event } = layout;
137
144
 
138
- const top = (layout.startMinute / 60) * hourHeight;
139
- // Never shorter than a line of text, or it stops being clickable
140
- const height = Math.max(((layout.endMinute - layout.startMinute) / 60) * hourHeight, 16);
145
+ const top = (layout.startMinute / 60) * hourHeight;
146
+ // Never shorter than a line of text, or it stops being clickable
147
+ const height = Math.max(
148
+ ((layout.endMinute - layout.startMinute) / 60) * hourHeight,
149
+ 16,
150
+ );
141
151
 
142
- return (
143
- <button
144
- type='button'
145
- className={cn(
146
- 'abs of a_l r_xs bd_1 bd_bd',
147
- // A stacked event has to paint over the ones behind it, and the
148
- // selected one over everything
149
- selected ? 'z3' : 'z2',
150
- getCalendarEventStatusClassName(event.status),
151
- event.isMine ? 'bg_active' : 'bg_alt',
152
- )}
153
- style={{
154
- top,
155
- height,
156
- left: `${layout.left * 100}%`,
157
- width: `calc(${layout.width * 100}% - 2px)`,
158
- paddingLeft: 4,
159
- paddingRight: 4,
160
- // A continued block keeps square edges where it was cut, so the
161
- // user can see it runs off the end of the day
162
- borderTopLeftRadius: layout.continuesFromPreviousDay ? 0 : undefined,
163
- borderTopRightRadius: layout.continuesFromPreviousDay ? 0 : undefined,
164
- borderBottomLeftRadius: layout.continuesToNextDay ? 0 : undefined,
165
- borderBottomRightRadius: layout.continuesToNextDay ? 0 : undefined,
166
- borderLeftColor: event.color || undefined,
167
- borderLeftWidth: event.color ? 3 : undefined,
168
- }}
169
- onClick={() => onSelect(event.id)}
170
- aria-current={selected ? 'true' : undefined}
171
- data-calendar-event-id={event.id}
172
- >
173
- <span className='ellip ft_tn ft_bold'>{event.title}</span>
152
+ return (
153
+ <button
154
+ type="button"
155
+ className={cn(
156
+ 'abs of a_l r_xs bd_1 bd_bd',
157
+ // A stacked event has to paint over the ones behind it, and the
158
+ // selected one over everything
159
+ selected ? 'z3' : 'z2',
160
+ getCalendarEventStatusClassName(event.status),
161
+ event.isMine ? 'bg_active' : 'bg_alt',
162
+ event.pending ? 'op_60' : '',
163
+ event.kind === 'BLOCK' ? 'pattern_texture cl_lt' : '',
164
+ )}
165
+ style={{
166
+ top,
167
+ height,
168
+ left: `${layout.left * 100}%`,
169
+ width: `calc(${layout.width * 100}% - 2px)`,
170
+ paddingLeft: 4,
171
+ paddingRight: 4,
172
+ // A continued block keeps square edges where it was cut, so the
173
+ // user can see it runs off the end of the day
174
+ borderTopLeftRadius: layout.continuesFromPreviousDay ? 0 : undefined,
175
+ borderTopRightRadius: layout.continuesFromPreviousDay ? 0 : undefined,
176
+ borderBottomLeftRadius: layout.continuesToNextDay ? 0 : undefined,
177
+ borderBottomRightRadius: layout.continuesToNextDay ? 0 : undefined,
178
+ borderLeftColor: event.color || undefined,
179
+ borderLeftWidth: event.color ? 3 : undefined,
180
+ }}
181
+ onClick={() => onSelect(event.id)}
182
+ aria-current={selected ? 'true' : undefined}
183
+ data-calendar-event-id={event.id}
184
+ >
185
+ <span className="ellip ft_xxs ft_bold">{event.title}</span>
186
+ {event.breach ? (
187
+ <span
188
+ className={cn(
189
+ 'abs r_5',
190
+ event.breach === 'BLOCK' ? 'bg_err' : 'bg_warn',
191
+ )}
192
+ style={{ width: 6, height: 6, right: 3, top: 3 }}
193
+ />
194
+ ) : null}
195
+ {(event.openCount || 0) > 0 ? (
196
+ <span className="pill bg_amber_alt_lt ft_xxs">
197
+ {i18n.t('calendar.open_count', { count: event.openCount })}
198
+ </span>
199
+ ) : null}
174
200
 
175
- {/* Below roughly 40 minutes there is only room for one line */}
176
- {height >= 32 ? <span className='ellip ft_tn cl_lt'>{timeLabel}</span> : null}
201
+ {/* Below roughly 40 minutes there is only room for one line */}
202
+ {height >= 32 ? (
203
+ <span className="ellip ft_xxs cl_lt">{timeLabel}</span>
204
+ ) : null}
177
205
 
178
- {/* Resize grips. Only offered when the block is tall enough to leave
206
+ {/* Resize grips. Only offered when the block is tall enough to leave
179
207
  a middle over to grab for moving — on a short block the grips
180
208
  would cover the whole thing and moving would become impossible */}
181
- {editable && height >= 28
182
- ? (
209
+ {editable && height >= 28 ? (
183
210
  <>
184
211
  <span
185
- className='abs w_f'
186
- style={{ top: 0, left: 0, height: 6, cursor: 'ns-resize', touchAction: 'none' }}
187
- data-calendar-edge='START'
212
+ className="abs w_f"
213
+ style={{
214
+ top: 0,
215
+ left: 0,
216
+ height: 6,
217
+ cursor: 'ns-resize',
218
+ touchAction: 'none',
219
+ }}
220
+ data-calendar-edge="START"
188
221
  />
189
222
  <span
190
- className='abs w_f'
191
- style={{ bottom: 0, left: 0, height: 6, cursor: 'ns-resize', touchAction: 'none' }}
192
- data-calendar-edge='END'
223
+ className="abs w_f"
224
+ style={{
225
+ bottom: 0,
226
+ left: 0,
227
+ height: 6,
228
+ cursor: 'ns-resize',
229
+ touchAction: 'none',
230
+ }}
231
+ data-calendar-edge="END"
193
232
  />
194
233
  </>
195
- )
196
- : null}
197
- </button>
198
- );
199
- }, (prev, next) => (
200
- // The layout objects are rebuilt on every data change, so comparing them by
201
- // identity would defeat the memo; compare what is actually drawn
202
- prev.layout.event === next.layout.event &&
203
- prev.layout.startMinute === next.layout.startMinute &&
204
- prev.layout.endMinute === next.layout.endMinute &&
205
- prev.layout.left === next.layout.left &&
206
- prev.layout.width === next.layout.width &&
207
- prev.layout.continuesFromPreviousDay === next.layout.continuesFromPreviousDay &&
208
- prev.layout.continuesToNextDay === next.layout.continuesToNextDay &&
209
- prev.hourHeight === next.hourHeight &&
210
- prev.selected === next.selected &&
211
- prev.editable === next.editable &&
212
- prev.timeLabel === next.timeLabel &&
213
- prev.onSelect === next.onSelect
214
- ));
234
+ ) : null}
235
+ </button>
236
+ );
237
+ },
238
+ (prev, next) =>
239
+ // The layout objects are rebuilt on every data change, so comparing them by
240
+ // identity would defeat the memo; compare what is actually drawn
241
+ prev.layout.event === next.layout.event &&
242
+ prev.layout.startMinute === next.layout.startMinute &&
243
+ prev.layout.endMinute === next.layout.endMinute &&
244
+ prev.layout.left === next.layout.left &&
245
+ prev.layout.width === next.layout.width &&
246
+ prev.layout.continuesFromPreviousDay ===
247
+ next.layout.continuesFromPreviousDay &&
248
+ prev.layout.continuesToNextDay === next.layout.continuesToNextDay &&
249
+ prev.hourHeight === next.hourHeight &&
250
+ prev.selected === next.selected &&
251
+ prev.editable === next.editable &&
252
+ prev.timeLabel === next.timeLabel &&
253
+ prev.onSelect === next.onSelect,
254
+ );
215
255
 
216
256
  /**
217
257
  * The all-day band above the time grid.
218
258
  */
219
259
 
220
- export const CalendarAllDayBandUI = memo((p: {
221
- bars: CalendarAllDayBarObj[];
222
- dayCount: number;
223
- selectedEventId: string | null;
224
- onSelect: (eventId: string) => void;
225
- }) => {
226
- const { bars, dayCount, selectedEventId, onSelect } = p;
260
+ export const CalendarAllDayBandUI = memo(
261
+ (p: {
262
+ bars: CalendarAllDayBarObj[];
263
+ dayCount: number;
264
+ selectedEventId: string | null;
265
+ onSelect: (eventId: string) => void;
266
+ }) => {
267
+ const { bars, dayCount, selectedEventId, onSelect } = p;
227
268
 
228
- if (!bars.length) {
229
- return null;
230
- }
269
+ if (!bars.length) {
270
+ return null;
271
+ }
231
272
 
232
- const rowCount = Math.max(...bars.map((bar) => bar.row)) + 1;
273
+ const rowCount = Math.max(...bars.map((bar) => bar.row)) + 1;
233
274
 
234
- return (
235
- <div
236
- className='no_shrink rel bd_b_1 bd_b_bd'
237
- style={{
238
- marginLeft: CALENDAR_GUTTER_WIDTH,
239
- height: rowCount * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 4,
240
- }}
241
- >
242
- {bars.map((bar) => (
243
- <button
244
- key={bar.event.id}
245
- type='button'
246
- className={cn(
247
- 'abs of a_l r_xs ellip ft_tn',
248
- getCalendarEventStatusClassName(bar.event.status),
249
- bar.event.isMine ? 'bg_active' : 'bg_alt',
250
- selectedEventId === bar.event.id ? 'z3' : 'z2',
251
- )}
252
- style={{
253
- top: bar.row * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 2,
254
- height: CALENDAR_ALL_DAY_ROW_HEIGHT,
255
- left: `${(bar.startDayIndex / dayCount) * 100}%`,
256
- width: `calc(${((bar.endDayIndex - bar.startDayIndex + 1) / dayCount) * 100}% - 2px)`,
257
- paddingLeft: 4,
258
- paddingRight: 4,
259
- borderTopLeftRadius: bar.continuesFromPreviousDay ? 0 : undefined,
260
- borderBottomLeftRadius: bar.continuesFromPreviousDay ? 0 : undefined,
261
- borderTopRightRadius: bar.continuesToNextDay ? 0 : undefined,
262
- borderBottomRightRadius: bar.continuesToNextDay ? 0 : undefined,
263
- }}
264
- onClick={() => onSelect(bar.event.id)}
265
- aria-current={selectedEventId === bar.event.id ? 'true' : undefined}
266
- >
267
- {bar.event.title}
268
- </button>
269
- ))}
270
- </div>
271
- );
272
- });
275
+ return (
276
+ <div
277
+ className="no_shrink rel bd_b_1 bd_b_bd"
278
+ style={{
279
+ marginLeft: CALENDAR_GUTTER_WIDTH,
280
+ height: rowCount * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 4,
281
+ }}
282
+ >
283
+ {bars.map((bar) => (
284
+ <button
285
+ key={bar.event.id}
286
+ type="button"
287
+ className={cn(
288
+ 'abs of a_l r_xs ellip ft_xxs',
289
+ getCalendarEventStatusClassName(bar.event.status),
290
+ bar.event.isMine ? 'bg_active' : 'bg_alt',
291
+ bar.event.pending ? 'op_60' : '',
292
+ bar.event.kind === 'BLOCK' ? 'pattern_texture cl_lt' : '',
293
+ selectedEventId === bar.event.id ? 'z3' : 'z2',
294
+ )}
295
+ style={{
296
+ top: bar.row * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 2,
297
+ height: CALENDAR_ALL_DAY_ROW_HEIGHT,
298
+ left: `${(bar.startDayIndex / dayCount) * 100}%`,
299
+ width: `calc(${((bar.endDayIndex - bar.startDayIndex + 1) / dayCount) * 100}% - 2px)`,
300
+ paddingLeft: 4,
301
+ paddingRight: 4,
302
+ borderTopLeftRadius: bar.continuesFromPreviousDay ? 0 : undefined,
303
+ borderBottomLeftRadius: bar.continuesFromPreviousDay
304
+ ? 0
305
+ : undefined,
306
+ borderTopRightRadius: bar.continuesToNextDay ? 0 : undefined,
307
+ borderBottomRightRadius: bar.continuesToNextDay ? 0 : undefined,
308
+ }}
309
+ onClick={() => onSelect(bar.event.id)}
310
+ aria-current={selectedEventId === bar.event.id ? 'true' : undefined}
311
+ >
312
+ {bar.event.title}
313
+ </button>
314
+ ))}
315
+ </div>
316
+ );
317
+ },
318
+ );
273
319
 
274
320
  /**
275
321
  * The day-of-week header row above the grid.
276
322
  */
277
323
 
278
- export const CalendarDayHeaderUI = memo((p: {
279
- days: CalendarDayObj[];
280
- // Pre-formatted per day: the weekday abbreviation and the day number
281
- dayLabels: Array<{ weekday: string; dayNumber: string }>;
282
- onSelectDay?: (dateKey: string) => void;
283
- }) => {
284
- const { days, dayLabels, onSelectDay } = p;
324
+ export const CalendarDayHeaderUI = memo(
325
+ (p: {
326
+ days: CalendarDayObj[];
327
+ // Pre-formatted per day: the weekday abbreviation and the day number
328
+ dayLabels: Array<{ weekday: string; dayNumber: string }>;
329
+ onSelectDay?: (dateKey: string) => void;
330
+ }) => {
331
+ const { days, dayLabels, onSelectDay } = p;
285
332
 
286
- return (
287
- <div
288
- className='no_shrink h_stretch bd_b_1 bd_b_bd'
289
- style={{ marginLeft: CALENDAR_GUTTER_WIDTH }}
290
- >
291
- {days.map((day, index) => (
292
- <button
293
- key={day.dateKey}
294
- type='button'
295
- className={cn('f a_c', day.isWeekend ? 'bg_alt' : '')}
296
- style={{ paddingTop: 4, paddingBottom: 4 }}
297
- disabled={!onSelectDay}
298
- onClick={onSelectDay ? () => onSelectDay(day.dateKey) : undefined}
299
- >
300
- <span className='ellip ft_tn cl_lt'>{dayLabels[index]?.weekday}</span>
301
- <span className={cn('ellip ft_sm', day.isToday ? 'ft_bold' : 'cl_md')}>
302
- {dayLabels[index]?.dayNumber}
303
- </span>
304
- </button>
305
- ))}
306
- </div>
307
- );
308
- });
333
+ return (
334
+ <div
335
+ className="no_shrink h_stretch bd_b_1 bd_b_bd"
336
+ style={{ marginLeft: CALENDAR_GUTTER_WIDTH }}
337
+ >
338
+ {days.map((day, index) => (
339
+ <button
340
+ key={day.dateKey}
341
+ type="button"
342
+ className={cn('f a_c', day.isWeekend ? 'bg_alt' : '')}
343
+ style={{ paddingTop: 4, paddingBottom: 4 }}
344
+ disabled={!onSelectDay}
345
+ onClick={onSelectDay ? () => onSelectDay(day.dateKey) : undefined}
346
+ >
347
+ <span className="ellip ft_xxs cl_lt">
348
+ {dayLabels[index]?.weekday}
349
+ </span>
350
+ <span
351
+ className={cn('ellip ft_sm', day.isToday ? 'ft_bold' : 'cl_md')}
352
+ >
353
+ {dayLabels[index]?.dayNumber}
354
+ </span>
355
+ </button>
356
+ ))}
357
+ </div>
358
+ );
359
+ },
360
+ );
309
361
 
310
362
  /**
311
363
  * The ghost block shown while a range is being drawn, moved, or resized.
@@ -315,33 +367,35 @@ export const CalendarDayHeaderUI = memo((p: {
315
367
  * than something that exists yet.
316
368
  */
317
369
 
318
- export const CalendarDraftBlockUI = memo((p: {
319
- startMinute: number;
320
- endMinute: number;
321
- hourHeight: number;
322
- label: string;
323
- }) => {
324
- const { startMinute, endMinute, hourHeight, label } = p;
370
+ export const CalendarDraftBlockUI = memo(
371
+ (p: {
372
+ startMinute: number;
373
+ endMinute: number;
374
+ hourHeight: number;
375
+ label: string;
376
+ }) => {
377
+ const { startMinute, endMinute, hourHeight, label } = p;
325
378
 
326
- const top = (startMinute / 60) * hourHeight;
327
- const height = Math.max(((endMinute - startMinute) / 60) * hourHeight, 16);
379
+ const top = (startMinute / 60) * hourHeight;
380
+ const height = Math.max(((endMinute - startMinute) / 60) * hourHeight, 16);
328
381
 
329
- return (
330
- <div
331
- className='abs of a_l r_xs bd_1 bd_bd bg_active z4'
332
- style={{
333
- top,
334
- height,
335
- left: 0,
336
- width: 'calc(100% - 2px)',
337
- paddingLeft: 4,
338
- paddingRight: 4,
339
- opacity: 0.8,
340
- // The ghost must never eat the pointer stream that is drawing it
341
- pointerEvents: 'none',
342
- }}
343
- >
344
- <span className='ellip ft_tn ft_bold'>{label}</span>
345
- </div>
346
- );
347
- });
382
+ return (
383
+ <div
384
+ className="abs of a_l r_xs bd_1 bd_bd bg_active z4"
385
+ style={{
386
+ top,
387
+ height,
388
+ left: 0,
389
+ width: 'calc(100% - 2px)',
390
+ paddingLeft: 4,
391
+ paddingRight: 4,
392
+ opacity: 0.8,
393
+ // The ghost must never eat the pointer stream that is drawing it
394
+ pointerEvents: 'none',
395
+ }}
396
+ >
397
+ <span className="ellip ft_xxs ft_bold">{label}</span>
398
+ </div>
399
+ );
400
+ },
401
+ );