@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsb188/calendar",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "Calendar and scheduling surface for web.",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
@@ -9,33 +9,34 @@
9
9
  ".": "./src/main.ts",
10
10
  "./constants/calendar": "./src/constants/calendar.ts",
11
11
  "./libs/calendar-geometry": "./src/libs/calendar-geometry.ts",
12
+ "./libs/calendar-now": "./src/libs/calendar-now.ts",
12
13
  "./libs/calendar-gesture": "./src/libs/calendar-gesture.ts",
13
14
  "./libs/calendar-range": "./src/libs/calendar-range.ts",
14
15
  "./libs/calendar-state": "./src/libs/calendar-state.ts",
15
16
  "./libs/calendar-url": "./src/libs/calendar-url.ts",
17
+ "./modules/MiniCalendar": "./src/modules/MiniCalendar.tsx",
16
18
  "./types/calendar.d.ts": "./src/types/calendar.d.ts",
17
19
  "./ui/CalendarAgendaUI": "./src/ui/CalendarAgendaUI.tsx",
18
- "./ui/CalendarCoverageUI": "./src/ui/CalendarCoverageUI.tsx",
19
- "./ui/CalendarEventDetailUI": "./src/ui/CalendarEventDetailUI.tsx",
20
- "./ui/CalendarEventFormUI": "./src/ui/CalendarEventFormUI.tsx",
21
20
  "./ui/CalendarMonthUI": "./src/ui/CalendarMonthUI.tsx",
22
- "./ui/CalendarRailUI": "./src/ui/CalendarRailUI.tsx",
23
- "./ui/CalendarRequestUI": "./src/ui/CalendarRequestUI.tsx",
24
21
  "./ui/CalendarToolbarUI": "./src/ui/CalendarToolbarUI.tsx",
25
22
  "./ui/CalendarUI": "./src/ui/CalendarUI.tsx",
26
- "./ui/CalendarViolationUI": "./src/ui/CalendarViolationUI.tsx",
27
- "./ui/CalendarYearUI": "./src/ui/CalendarYearUI.tsx"
23
+ "./ui/CalendarYearUI": "./src/ui/CalendarYearUI.tsx",
24
+ "./libs/roster-layout": "./src/libs/roster-layout.ts",
25
+ "./ui/RosterUI": "./src/ui/RosterUI.tsx",
26
+ "./ui/ShiftFormUI": "./src/ui/ShiftFormUI.tsx",
27
+ "./types/shift-form.d.ts": "./src/types/shift-form.d.ts"
28
28
  },
29
29
  "peerDependencies": {
30
- "@jsb188/app": "1.1.10",
31
- "@jsb188/graphql": "1.1.10",
32
- "@jsb188/mday": "1.1.10",
33
- "@jsb188/react": "1.1.10",
34
- "@jsb188/react-web": "1.1.10",
30
+ "@jsb188/app": "1.1.12",
31
+ "@jsb188/graphql": "1.1.12",
32
+ "@jsb188/mday": "1.1.12",
33
+ "@jsb188/react": "1.1.12",
34
+ "@jsb188/react-web": "1.1.12",
35
35
  "jotai": "^2.20.2",
36
36
  "luxon": "^3.7.2",
37
- "react": "^19.2.8",
38
- "react-router": "^8.3.0"
37
+ "react": "^19.3.0",
38
+ "react-router": "^8.4.0",
39
+ "@jsb188/form": "1.1.12"
39
40
  },
40
41
  "scripts": {
41
42
  "test": "vitest run --config ./vitest.config.ts --passWithNoTests",
@@ -13,6 +13,7 @@
13
13
  */
14
14
 
15
15
  export const CALENDAR_VIEW_ENUMS = [
16
+ 'ROSTER',
16
17
  'DAY',
17
18
  'FOUR_DAYS',
18
19
  'WEEK',
@@ -25,7 +26,10 @@ export type CalendarViewEnum = (typeof CALENDAR_VIEW_ENUMS)[number];
25
26
 
26
27
  // How many days each time-grid view shows. MONTH/YEAR/AGENDA are absent on
27
28
  // purpose: their spans are derived from the anchor date, not from a count.
28
- export const CALENDAR_VIEW_DAY_COUNTS: Partial<Record<CalendarViewEnum, number>> = {
29
+ export const CALENDAR_VIEW_DAY_COUNTS: Partial<
30
+ Record<CalendarViewEnum, number>
31
+ > = {
32
+ ROSTER: 7,
29
33
  DAY: 1,
30
34
  FOUR_DAYS: 4,
31
35
  WEEK: 7,
@@ -35,6 +39,11 @@ export const CALENDAR_VIEW_DAY_COUNTS: Partial<Record<CalendarViewEnum, number>>
35
39
  // worker opening "Schedule" wants what is coming, not what they already did.
36
40
  export const CALENDAR_AGENDA_DAY_COUNT = 30;
37
41
 
42
+ // How often the calendar re-reads the clock. The now line moves in minutes and
43
+ // "today" changes once a day, so polling faster buys nothing; polling slower
44
+ // would leave a calendar open past midnight highlighting yesterday.
45
+ export const CALENDAR_NOW_TICK_MS = 30_000;
46
+
38
47
  /**
39
48
  * Time-grid geometry. These are the defaults; the grid scales its hour height
40
49
  * to the container, so they are starting points rather than fixed sizes.
@@ -99,6 +108,11 @@ export const CALENDAR_MONTH_CELL_MAX_EVENTS = 3;
99
108
 
100
109
  export const CALENDAR_SEARCH_PARAMS = {
101
110
  view: 'v',
111
+ calendar: 'cal',
112
+ room: 'room',
113
+ groupByRoom: 'rooms',
114
+ panel: 'p',
115
+ open: 'o',
102
116
  date: 'd',
103
117
  mine: 'me',
104
118
  // The calendars the viewer has HIDDEN; absent means show everything
@@ -111,6 +125,7 @@ export const CALENDAR_SEARCH_PARAMS = {
111
125
  */
112
126
 
113
127
  export const CALENDAR_VIEW_SLUGS: Record<CalendarViewEnum, string> = {
128
+ ROSTER: 'roster',
114
129
  DAY: 'day',
115
130
  FOUR_DAYS: '4day',
116
131
  WEEK: 'week',
@@ -134,6 +149,5 @@ export const CALENDAR_DATE_PARAM_FORMAT = 'yyyy-MM-dd';
134
149
 
135
150
  // The stripe pattern is a MASK on a :before pseudo-element, so it needs both a
136
151
  // fill colour class ("*_bf") and a positioned parent ("rel", or any absolutely
137
- // positioned element) or it renders as nothing at all. This is the same
138
- // combination DataTable-InboundContact and VerticalDataTableDesigner use.
152
+ // positioned element) or it renders as nothing at all.
139
153
  export const CALENDAR_DRAFT_PATTERN_CLASS_NAME = 'pattern_stripes medium_bf';
@@ -3,8 +3,15 @@ import {
3
3
  CALENDAR_MIN_EVENT_MINUTES,
4
4
  CALENDAR_OVERLAP_STACK_RATIO,
5
5
  } from '../constants/calendar.ts';
6
- import type { CalendarDayObj, CalendarEventLayoutObj, CalendarEventObj } from '../types/calendar.d.ts';
7
- import { getDayLengthMinutes, getMinutesFromDayStart } from './calendar-range.ts';
6
+ import type {
7
+ CalendarDayObj,
8
+ CalendarEventLayoutObj,
9
+ CalendarEventObj,
10
+ } from '../types/calendar.d.ts';
11
+ import {
12
+ getDayLengthMinutes,
13
+ getMinutesFromDayStart,
14
+ } from './calendar-range.ts';
8
15
 
9
16
  /**
10
17
  * Time-grid geometry: turning a list of events into rectangles.
@@ -28,11 +35,65 @@ import { getDayLengthMinutes, getMinutesFromDayStart } from './calendar-range.ts
28
35
  */
29
36
 
30
37
  /*
31
- * Return whether two half-open intervals overlap.
38
+ * Return the inclusive day-index span one event touches, or null when it
39
+ * touches none of the days on screen.
40
+ *
41
+ * Days are consecutive and sorted, so the span is found by binary search rather
42
+ * than by testing the event against every day. Without this every pass over the
43
+ * grid is events × days: a month of a busy calendar is 42 days against several
44
+ * hundred entries, walked again on each of the three layout passes and on every
45
+ * re-render they are not memoized through.
32
46
  */
33
47
 
34
- function intervalsOverlap(aStart: number, aEnd: number, bStart: number, bEnd: number): boolean {
35
- return aStart < bEnd && bStart < aEnd;
48
+ function getEventDaySpan(
49
+ event: CalendarEventObj,
50
+ days: CalendarDayObj[],
51
+ ): { startDayIndex: number; endDayIndex: number } | null {
52
+ if (!days.length) {
53
+ return null;
54
+ }
55
+
56
+ const eventStartMs = event.startAt.getTime();
57
+ const eventEndMs = event.endAt.getTime();
58
+
59
+ if (
60
+ eventStartMs >= days[days.length - 1].endAt.getTime() ||
61
+ eventEndMs <= days[0].startAt.getTime()
62
+ ) {
63
+ return null;
64
+ }
65
+
66
+ // First day whose end is strictly after the event's start
67
+ let low = 0;
68
+ let high = days.length - 1;
69
+
70
+ while (low < high) {
71
+ const mid = (low + high) >> 1;
72
+
73
+ if (days[mid].endAt.getTime() > eventStartMs) {
74
+ high = mid;
75
+ } else {
76
+ low = mid + 1;
77
+ }
78
+ }
79
+
80
+ const startDayIndex = low;
81
+
82
+ // Last day whose start is strictly before the event's end
83
+ low = startDayIndex;
84
+ high = days.length - 1;
85
+
86
+ while (low < high) {
87
+ const mid = (low + high + 1) >> 1;
88
+
89
+ if (days[mid].startAt.getTime() < eventEndMs) {
90
+ low = mid;
91
+ } else {
92
+ high = mid - 1;
93
+ }
94
+ }
95
+
96
+ return { startDayIndex, endDayIndex: low };
36
97
  }
37
98
 
38
99
  interface PlacedEvent {
@@ -73,15 +134,24 @@ function clipEventToDay(
73
134
  // A zero-length event is still somebody's calendar entry; give it the
74
135
  // minimum height rather than dropping it
75
136
  const dayLengthMinutes = getDayLengthMinutes(day);
76
- const startMinute = Math.max(0, getMinutesFromDayStart(event.startAt, day.startAt));
77
- const endMinute = Math.min(dayLengthMinutes, getMinutesFromDayStart(event.endAt, day.startAt));
137
+ const startMinute = Math.max(
138
+ 0,
139
+ getMinutesFromDayStart(event.startAt, day.startAt),
140
+ );
141
+ const endMinute = Math.min(
142
+ dayLengthMinutes,
143
+ getMinutesFromDayStart(event.endAt, day.startAt),
144
+ );
78
145
 
79
146
  return {
80
147
  event,
81
148
  dayIndex,
82
149
  startMinute,
83
150
  endMinute,
84
- layoutEndMinute: Math.min(dayLengthMinutes, Math.max(endMinute, startMinute + CALENDAR_MIN_EVENT_MINUTES)),
151
+ layoutEndMinute: Math.min(
152
+ dayLengthMinutes,
153
+ Math.max(endMinute, startMinute + CALENDAR_MIN_EVENT_MINUTES),
154
+ ),
85
155
  continuesFromPreviousDay: eventStartMs < dayStartMs,
86
156
  continuesToNextDay: eventEndMs > dayEndMs,
87
157
  column: 0,
@@ -101,11 +171,12 @@ function clipEventToDay(
101
171
  */
102
172
 
103
173
  function assignOverlapColumns(placed: PlacedEvent[]): void {
104
- placed.sort((left, right) => (
105
- left.startMinute - right.startMinute ||
106
- right.layoutEndMinute - left.layoutEndMinute ||
107
- String(left.event.id).localeCompare(String(right.event.id))
108
- ));
174
+ placed.sort(
175
+ (left, right) =>
176
+ left.startMinute - right.startMinute ||
177
+ right.layoutEndMinute - left.layoutEndMinute ||
178
+ String(left.event.id).localeCompare(String(right.event.id)),
179
+ );
109
180
 
110
181
  let cluster: PlacedEvent[] = [];
111
182
  let clusterEnd = -Infinity;
@@ -134,7 +205,9 @@ function assignOverlapColumns(placed: PlacedEvent[]): void {
134
205
  columnFreeFrom = [];
135
206
  }
136
207
 
137
- let column = columnFreeFrom.findIndex((freeFrom) => entry.startMinute >= freeFrom);
208
+ let column = columnFreeFrom.findIndex(
209
+ (freeFrom) => entry.startMinute >= freeFrom,
210
+ );
138
211
 
139
212
  if (column === -1) {
140
213
  column = columnFreeFrom.length;
@@ -160,7 +233,10 @@ function assignOverlapColumns(placed: PlacedEvent[]): void {
160
233
  * seventh-of-a-column sliver would not.
161
234
  */
162
235
 
163
- function getHorizontalGeometry(column: number, columnCount: number): { left: number; width: number } {
236
+ function getHorizontalGeometry(
237
+ column: number,
238
+ columnCount: number,
239
+ ): { left: number; width: number } {
164
240
  if (columnCount <= CALENDAR_MAX_OVERLAP_COLUMNS) {
165
241
  return {
166
242
  left: column / columnCount,
@@ -168,7 +244,10 @@ function getHorizontalGeometry(column: number, columnCount: number): { left: num
168
244
  };
169
245
  }
170
246
 
171
- const left = Math.min(column * CALENDAR_OVERLAP_STACK_RATIO, 1 - CALENDAR_OVERLAP_STACK_RATIO);
247
+ const left = Math.min(
248
+ column * CALENDAR_OVERLAP_STACK_RATIO,
249
+ 1 - CALENDAR_OVERLAP_STACK_RATIO,
250
+ );
172
251
 
173
252
  return {
174
253
  left,
@@ -195,7 +274,17 @@ export function getCalendarTimedLayout(
195
274
  continue;
196
275
  }
197
276
 
198
- for (let dayIndex = 0; dayIndex < days.length; dayIndex++) {
277
+ const span = getEventDaySpan(event, days);
278
+
279
+ if (!span) {
280
+ continue;
281
+ }
282
+
283
+ for (
284
+ let dayIndex = span.startDayIndex;
285
+ dayIndex <= span.endDayIndex;
286
+ dayIndex++
287
+ ) {
199
288
  const placed = clipEventToDay(event, days[dayIndex], dayIndex);
200
289
 
201
290
  if (placed) {
@@ -210,7 +299,10 @@ export function getCalendarTimedLayout(
210
299
  assignOverlapColumns(dayEvents);
211
300
 
212
301
  for (const entry of dayEvents) {
213
- const { left, width } = getHorizontalGeometry(entry.column, entry.columnCount);
302
+ const { left, width } = getHorizontalGeometry(
303
+ entry.column,
304
+ entry.columnCount,
305
+ );
214
306
 
215
307
  layout.push({
216
308
  event: entry.event,
@@ -264,46 +356,49 @@ export function getCalendarAllDayLayout(
264
356
  const rangeStartMs = days[0].startAt.getTime();
265
357
  const rangeEndMs = days[days.length - 1].endAt.getTime();
266
358
 
267
- const bars = events
268
- .filter((event) => (
269
- // An entry belongs in the band when it is flagged all-day, or when it
270
- // simply spans more than one of the days on screen — a three-day
271
- // closure is not usefully drawn as three tall columns
272
- (event.allDay || spansMultipleDays(event, days)) &&
273
- event.startAt.getTime() < rangeEndMs &&
274
- event.endAt.getTime() > rangeStartMs
275
- ))
276
- .map((event) => {
277
- const startDayIndex = days.findIndex((day) => event.startAt.getTime() < day.endAt.getTime());
278
- let endDayIndex = -1;
279
-
280
- for (let index = days.length - 1; index >= 0; index--) {
281
- if (event.endAt.getTime() > days[index].startAt.getTime()) {
282
- endDayIndex = index;
283
- break;
284
- }
285
- }
359
+ const bars: CalendarAllDayBarObj[] = [];
360
+
361
+ for (const event of events) {
362
+ // One span lookup serves the membership test and the geometry: the day
363
+ // range an event touches IS the answer to "does it span more than one
364
+ // day on screen", so asking separately walked the day list three times
365
+ const span = getEventDaySpan(event, days);
366
+
367
+ if (!span) {
368
+ continue;
369
+ }
286
370
 
287
- return {
288
- event,
289
- startDayIndex: startDayIndex === -1 ? 0 : startDayIndex,
290
- endDayIndex: endDayIndex === -1 ? days.length - 1 : endDayIndex,
291
- row: 0,
292
- continuesFromPreviousDay: event.startAt.getTime() < rangeStartMs,
293
- continuesToNextDay: event.endAt.getTime() > rangeEndMs,
294
- };
295
- })
296
- .sort((left, right) => (
371
+ // Timed overnight events remain in the timed grid only.
372
+ if (!event.allDay) {
373
+ continue;
374
+ }
375
+
376
+ bars.push({
377
+ event,
378
+ startDayIndex: span.startDayIndex,
379
+ endDayIndex: span.endDayIndex,
380
+ row: 0,
381
+ continuesFromPreviousDay: event.startAt.getTime() < rangeStartMs,
382
+ continuesToNextDay: event.endAt.getTime() > rangeEndMs,
383
+ });
384
+ }
385
+
386
+ bars.sort(
387
+ (left, right) =>
297
388
  left.startDayIndex - right.startDayIndex ||
298
- (right.endDayIndex - right.startDayIndex) - (left.endDayIndex - left.startDayIndex) ||
299
- String(left.event.id).localeCompare(String(right.event.id))
300
- ));
389
+ right.endDayIndex -
390
+ right.startDayIndex -
391
+ (left.endDayIndex - left.startDayIndex) ||
392
+ String(left.event.id).localeCompare(String(right.event.id)),
393
+ );
301
394
 
302
395
  // Row index -> the day index that row is free from
303
396
  const rowFreeFrom: number[] = [];
304
397
 
305
398
  for (const bar of bars) {
306
- let row = rowFreeFrom.findIndex((freeFrom) => bar.startDayIndex >= freeFrom);
399
+ let row = rowFreeFrom.findIndex(
400
+ (freeFrom) => bar.startDayIndex >= freeFrom,
401
+ );
307
402
 
308
403
  if (row === -1) {
309
404
  row = rowFreeFrom.length;
@@ -318,31 +413,6 @@ export function getCalendarAllDayLayout(
318
413
  return bars;
319
414
  }
320
415
 
321
- /*
322
- * Return whether one event covers more than one of the days on screen.
323
- */
324
-
325
- function spansMultipleDays(event: CalendarEventObj, days: CalendarDayObj[]): boolean {
326
- let touched = 0;
327
-
328
- for (const day of days) {
329
- if (intervalsOverlap(
330
- event.startAt.getTime(),
331
- event.endAt.getTime(),
332
- day.startAt.getTime(),
333
- day.endAt.getTime(),
334
- )) {
335
- touched++;
336
-
337
- if (touched > 1) {
338
- return true;
339
- }
340
- }
341
- }
342
-
343
- return false;
344
- }
345
-
346
416
  /**
347
417
  * One month-grid cell: the day, the events that fit, and how many did not.
348
418
  */
@@ -401,25 +471,29 @@ export function getCalendarEventsByDateKey(
401
471
  }
402
472
 
403
473
  for (const event of events) {
404
- for (const day of days) {
405
- if (intervalsOverlap(
406
- event.startAt.getTime(),
407
- event.endAt.getTime(),
408
- day.startAt.getTime(),
409
- day.endAt.getTime(),
410
- )) {
411
- byDateKey.get(day.dateKey)?.push(event);
412
- }
474
+ const span = getEventDaySpan(event, days);
475
+
476
+ if (!span) {
477
+ continue;
478
+ }
479
+
480
+ for (
481
+ let dayIndex = span.startDayIndex;
482
+ dayIndex <= span.endDayIndex;
483
+ dayIndex++
484
+ ) {
485
+ byDateKey.get(days[dayIndex].dateKey)?.push(event);
413
486
  }
414
487
  }
415
488
 
416
489
  for (const dayEvents of byDateKey.values()) {
417
- dayEvents.sort((left, right) => (
418
- // All-day entries head the list; below them, chronological
419
- Number(right.allDay) - Number(left.allDay) ||
420
- left.startAt.getTime() - right.startAt.getTime() ||
421
- String(left.id).localeCompare(String(right.id))
422
- ));
490
+ dayEvents.sort(
491
+ (left, right) =>
492
+ // All-day entries head the list; below them, chronological
493
+ Number(right.allDay) - Number(left.allDay) ||
494
+ left.startAt.getTime() - right.startAt.getTime() ||
495
+ String(left.id).localeCompare(String(right.id)),
496
+ );
423
497
  }
424
498
 
425
499
  return byDateKey;
@@ -5,7 +5,11 @@ import {
5
5
  CALENDAR_SNAP_MINUTES,
6
6
  } from '../constants/calendar.ts';
7
7
  import type { CalendarDayObj } from '../types/calendar.d.ts';
8
- import { getDayLengthMinutes, getInstantFromDayMinutes, snapMinutes } from './calendar-range.ts';
8
+ import {
9
+ getDayLengthMinutes,
10
+ getInstantFromDayMinutes,
11
+ snapMinutes,
12
+ } from './calendar-range.ts';
9
13
 
10
14
  /**
11
15
  * The calendar's pointer gesture engine.
@@ -21,8 +25,6 @@ import { getDayLengthMinutes, getInstantFromDayMinutes, snapMinutes } from './ca
21
25
  * can be tested without a DOM.
22
26
  */
23
27
 
24
- export type CalendarGestureKind = 'CREATE' | 'MOVE' | 'RESIZE_START' | 'RESIZE_END';
25
-
26
28
  export interface CalendarGestureRange {
27
29
  startAt: Date;
28
30
  endAt: Date;
@@ -45,12 +47,19 @@ export function getCalendarPointerSlot(p: {
45
47
  const { offsetX, offsetY, contentWidth, hourHeight, days } = p;
46
48
 
47
49
  const columnWidth = contentWidth / Math.max(1, days.length);
48
- const dayIndex = Math.max(0, Math.min(days.length - 1, Math.floor(offsetX / Math.max(1, columnWidth))));
50
+ const dayIndex = Math.max(
51
+ 0,
52
+ Math.min(days.length - 1, Math.floor(offsetX / Math.max(1, columnWidth))),
53
+ );
49
54
  const dayLengthMinutes = getDayLengthMinutes(days[dayIndex]);
50
55
 
51
56
  return {
52
57
  dayIndex,
53
- minute: snapMinutes((offsetY / hourHeight) * 60, CALENDAR_SNAP_MINUTES, dayLengthMinutes),
58
+ minute: snapMinutes(
59
+ (offsetY / hourHeight) * 60,
60
+ CALENDAR_SNAP_MINUTES,
61
+ dayLengthMinutes,
62
+ ),
54
63
  };
55
64
  }
56
65
 
@@ -78,14 +87,20 @@ export function getCalendarCreateRange(p: {
78
87
  const dayLengthMinutes = getDayLengthMinutes(day);
79
88
 
80
89
  if (!moved) {
81
- const startMinute = Math.min(anchorMinute, dayLengthMinutes - CALENDAR_DEFAULT_NEW_EVENT_MINUTES);
90
+ const startMinute = Math.min(
91
+ anchorMinute,
92
+ dayLengthMinutes - CALENDAR_DEFAULT_NEW_EVENT_MINUTES,
93
+ );
82
94
 
83
95
  return {
84
96
  dayIndex: anchorDayIndex,
85
97
  startAt: getInstantFromDayMinutes(day.startAt, Math.max(0, startMinute)),
86
98
  endAt: getInstantFromDayMinutes(
87
99
  day.startAt,
88
- Math.min(dayLengthMinutes, Math.max(0, startMinute) + CALENDAR_DEFAULT_NEW_EVENT_MINUTES),
100
+ Math.min(
101
+ dayLengthMinutes,
102
+ Math.max(0, startMinute) + CALENDAR_DEFAULT_NEW_EVENT_MINUTES,
103
+ ),
89
104
  ),
90
105
  };
91
106
  }
@@ -100,7 +115,10 @@ export function getCalendarCreateRange(p: {
100
115
  startAt: getInstantFromDayMinutes(day.startAt, startMinute),
101
116
  endAt: getInstantFromDayMinutes(
102
117
  day.startAt,
103
- Math.min(dayLengthMinutes, Math.max(endMinute, startMinute + CALENDAR_MIN_EVENT_MINUTES)),
118
+ Math.min(
119
+ dayLengthMinutes,
120
+ Math.max(endMinute, startMinute + CALENDAR_MIN_EVENT_MINUTES),
121
+ ),
104
122
  ),
105
123
  };
106
124
  }
@@ -122,7 +140,14 @@ export function getCalendarMoveRange(p: {
122
140
  currentDayIndex: number;
123
141
  currentMinute: number;
124
142
  }): CalendarGestureRange {
125
- const { days, startAt, endAt, grabOffsetMinutes, currentDayIndex, currentMinute } = p;
143
+ const {
144
+ days,
145
+ startAt,
146
+ endAt,
147
+ grabOffsetMinutes,
148
+ currentDayIndex,
149
+ currentMinute,
150
+ } = p;
126
151
 
127
152
  const day = days[currentDayIndex];
128
153
  const dayLengthMinutes = getDayLengthMinutes(day);
@@ -174,7 +199,10 @@ export function getCalendarResizeRange(p: {
174
199
 
175
200
  if (edge === 'START') {
176
201
  const endMinute = (endAt.getTime() - dayStartMs) / 60_000;
177
- const startMinute = Math.min(currentMinute, endMinute - CALENDAR_MIN_EVENT_MINUTES);
202
+ const startMinute = Math.min(
203
+ currentMinute,
204
+ endMinute - CALENDAR_MIN_EVENT_MINUTES,
205
+ );
178
206
 
179
207
  return {
180
208
  dayIndex,
@@ -184,17 +212,26 @@ export function getCalendarResizeRange(p: {
184
212
  }
185
213
 
186
214
  const startMinute = (startAt.getTime() - dayStartMs) / 60_000;
187
- const endMinute = Math.max(currentMinute, startMinute + CALENDAR_MIN_EVENT_MINUTES);
215
+ const endMinute = Math.max(
216
+ currentMinute,
217
+ startMinute + CALENDAR_MIN_EVENT_MINUTES,
218
+ );
188
219
 
189
220
  return {
190
221
  dayIndex,
191
222
  startAt,
192
- endAt: getInstantFromDayMinutes(day.startAt, Math.min(dayLengthMinutes, endMinute)),
223
+ endAt: getInstantFromDayMinutes(
224
+ day.startAt,
225
+ Math.min(dayLengthMinutes, endMinute),
226
+ ),
193
227
  };
194
228
  }
195
229
 
196
230
  export interface CalendarGestureParams {
197
- kind: CalendarGestureKind;
231
+ // Deliberately no "kind": what a gesture DOES is entirely decided by the
232
+ // resolveRange the caller supplies, so a kind field here was an input
233
+ // nothing read — and the grid was passing 'RESIZE_END' for both resize
234
+ // edges, a wrong value that only went unnoticed because it was ignored.
198
235
  pointerId: number;
199
236
  // Client coordinates where the gesture began, for the movement threshold
200
237
  originClientX: number;
@@ -204,7 +241,11 @@ export interface CalendarGestureParams {
204
241
  // Called on release only when the gesture was not cancelled
205
242
  onCommit: (range: CalendarGestureRange, moved: boolean) => void;
206
243
  // Resolve the range for the pointer's current client position
207
- resolveRange: (clientX: number, clientY: number, moved: boolean) => CalendarGestureRange | null;
244
+ resolveRange: (
245
+ clientX: number,
246
+ clientY: number,
247
+ moved: boolean,
248
+ ) => CalendarGestureRange | null;
208
249
  onFinish?: () => void;
209
250
  }
210
251
 
@@ -217,7 +258,9 @@ export interface CalendarGestureParams {
217
258
  * tracking rather than freezing at the boundary.
218
259
  */
219
260
 
220
- export function startCalendarGesture(params: CalendarGestureParams): () => void {
261
+ export function startCalendarGesture(
262
+ params: CalendarGestureParams,
263
+ ): () => void {
221
264
  let finished = false;
222
265
  let moved = false;
223
266
 
@@ -0,0 +1,39 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { CALENDAR_NOW_TICK_MS } from '../constants/calendar.ts';
3
+
4
+ /**
5
+ * A clock the calendar can trust.
6
+ *
7
+ * Every other surface in the app can read the time once at mount and be right
8
+ * for as long as it is open. A calendar cannot: it draws a "now" line, it
9
+ * highlights today's column, and it decides which day an undated URL means. A
10
+ * calendar left open on a wall display or on somebody's second monitor — which
11
+ * is exactly how calendars are used — would otherwise keep yesterday
12
+ * highlighted and keep the now line frozen where it was when the page loaded.
13
+ *
14
+ * The returned Date only changes identity when the minute does, so a consumer
15
+ * can use it as a hook dependency without re-running on every tick.
16
+ */
17
+
18
+ export function useCalendarNow(): Date {
19
+ const [now, setNow] = useState(() => new Date());
20
+
21
+ useEffect(() => {
22
+ const interval = setInterval(() => {
23
+ setNow((current) => {
24
+ const next = new Date();
25
+
26
+ // Returning the SAME reference within a minute is what keeps this
27
+ // from invalidating the layout memos sixty times an hour
28
+ return Math.floor(next.getTime() / 60_000) ===
29
+ Math.floor(current.getTime() / 60_000)
30
+ ? current
31
+ : next;
32
+ });
33
+ }, CALENDAR_NOW_TICK_MS);
34
+
35
+ return () => clearInterval(interval);
36
+ }, []);
37
+
38
+ return now;
39
+ }