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