@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
|
@@ -33,14 +33,23 @@ describe('parseCalendarDateParam', () => {
|
|
|
33
33
|
// 2026-07-23T02:00Z is still the 22nd in Los Angeles
|
|
34
34
|
const lateNight = new Date('2026-07-23T02:00:00Z');
|
|
35
35
|
|
|
36
|
-
expect(
|
|
37
|
-
|
|
36
|
+
expect(
|
|
37
|
+
getCalendarDateKey(parseCalendarDateParam(null, lateNight, LA), LA),
|
|
38
|
+
).toBe('2026-07-22');
|
|
39
|
+
expect(
|
|
40
|
+
getCalendarDateKey(parseCalendarDateParam(null, lateNight, 'UTC'), 'UTC'),
|
|
41
|
+
).toBe('2026-07-23');
|
|
38
42
|
});
|
|
39
43
|
});
|
|
40
44
|
|
|
41
45
|
describe('getCalendarRange', () => {
|
|
42
46
|
it('builds a Sunday-start week covering the anchor', () => {
|
|
43
|
-
const range = getCalendarRange({
|
|
47
|
+
const range = getCalendarRange({
|
|
48
|
+
view: 'WEEK',
|
|
49
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
50
|
+
now: NOW,
|
|
51
|
+
timeZone: LA,
|
|
52
|
+
});
|
|
44
53
|
|
|
45
54
|
expect(range.days).toHaveLength(7);
|
|
46
55
|
expect(range.days[0].dateKey).toBe('2026-07-19');
|
|
@@ -65,20 +74,39 @@ describe('getCalendarRange', () => {
|
|
|
65
74
|
it('runs DAY and FOUR_DAYS forward from the anchor', () => {
|
|
66
75
|
const anchor = parseCalendarDateParam('2026-07-22', NOW, LA);
|
|
67
76
|
|
|
68
|
-
expect(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
expect(
|
|
78
|
+
getCalendarRange({
|
|
79
|
+
view: 'DAY',
|
|
80
|
+
anchorDate: anchor,
|
|
81
|
+
now: NOW,
|
|
82
|
+
timeZone: LA,
|
|
83
|
+
}).days.map((d) => d.dateKey),
|
|
84
|
+
).toEqual(['2026-07-22']);
|
|
85
|
+
expect(
|
|
86
|
+
getCalendarRange({
|
|
87
|
+
view: 'FOUR_DAYS',
|
|
88
|
+
anchorDate: anchor,
|
|
89
|
+
now: NOW,
|
|
90
|
+
timeZone: LA,
|
|
91
|
+
}).days.map((d) => d.dateKey),
|
|
92
|
+
).toEqual(['2026-07-22', '2026-07-23', '2026-07-24', '2026-07-25']);
|
|
72
93
|
});
|
|
73
94
|
|
|
74
95
|
it('always builds a six-week month grid, including neighbouring days', () => {
|
|
75
|
-
const range = getCalendarRange({
|
|
96
|
+
const range = getCalendarRange({
|
|
97
|
+
view: 'MONTH',
|
|
98
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
99
|
+
now: NOW,
|
|
100
|
+
timeZone: LA,
|
|
101
|
+
});
|
|
76
102
|
|
|
77
103
|
expect(range.days).toHaveLength(42);
|
|
78
104
|
// July 2026 starts on a Wednesday, so the grid opens on Sunday June 28
|
|
79
105
|
expect(range.days[0].dateKey).toBe('2026-06-28');
|
|
80
106
|
expect(range.days[0].isInPrimaryRange).toBe(false);
|
|
81
|
-
expect(
|
|
107
|
+
expect(
|
|
108
|
+
range.days.find((day) => day.dateKey === '2026-07-01')?.isInPrimaryRange,
|
|
109
|
+
).toBe(true);
|
|
82
110
|
expect(range.days[41].isInPrimaryRange).toBe(false);
|
|
83
111
|
});
|
|
84
112
|
|
|
@@ -99,14 +127,28 @@ describe('getCalendarRange', () => {
|
|
|
99
127
|
});
|
|
100
128
|
|
|
101
129
|
it('marks today and weekends in the calendar zone', () => {
|
|
102
|
-
const range = getCalendarRange({
|
|
130
|
+
const range = getCalendarRange({
|
|
131
|
+
view: 'WEEK',
|
|
132
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
133
|
+
now: NOW,
|
|
134
|
+
timeZone: LA,
|
|
135
|
+
});
|
|
103
136
|
|
|
104
|
-
expect(
|
|
105
|
-
|
|
137
|
+
expect(
|
|
138
|
+
range.days.filter((day) => day.isToday).map((day) => day.dateKey),
|
|
139
|
+
).toEqual(['2026-07-22']);
|
|
140
|
+
expect(
|
|
141
|
+
range.days.filter((day) => day.isWeekend).map((day) => day.dateKey),
|
|
142
|
+
).toEqual(['2026-07-19', '2026-07-25']);
|
|
106
143
|
});
|
|
107
144
|
|
|
108
145
|
it('falls back to a valid zone rather than throwing', () => {
|
|
109
|
-
const range = getCalendarRange({
|
|
146
|
+
const range = getCalendarRange({
|
|
147
|
+
view: 'DAY',
|
|
148
|
+
anchorDate: NOW,
|
|
149
|
+
now: NOW,
|
|
150
|
+
timeZone: 'Not/AZone',
|
|
151
|
+
});
|
|
110
152
|
|
|
111
153
|
expect(range.days).toHaveLength(1);
|
|
112
154
|
expect(range.timeZone).toBeTruthy();
|
|
@@ -148,14 +190,21 @@ describe('DST handling', () => {
|
|
|
148
190
|
|
|
149
191
|
expect(range.days).toHaveLength(7);
|
|
150
192
|
// 25 hours in the first day, 24 in the rest
|
|
151
|
-
expect(range.to.getTime() - range.from.getTime()).toBe(
|
|
193
|
+
expect(range.to.getTime() - range.from.getTime()).toBe(
|
|
194
|
+
(7 * 24 + 1) * 3_600_000,
|
|
195
|
+
);
|
|
152
196
|
});
|
|
153
197
|
});
|
|
154
198
|
|
|
155
199
|
describe('getCalendarStepAnchor', () => {
|
|
156
200
|
it('steps a month view by calendar months, clamping short months', () => {
|
|
157
201
|
const anchor = parseCalendarDateParam('2026-01-31', NOW, LA);
|
|
158
|
-
const next = getCalendarStepAnchor({
|
|
202
|
+
const next = getCalendarStepAnchor({
|
|
203
|
+
view: 'MONTH',
|
|
204
|
+
anchorDate: anchor,
|
|
205
|
+
direction: 1,
|
|
206
|
+
timeZone: LA,
|
|
207
|
+
});
|
|
159
208
|
|
|
160
209
|
// Stepping from January 31 must land in February, not skip to March
|
|
161
210
|
expect(getCalendarDateKey(next, LA)).toBe('2026-02-28');
|
|
@@ -164,17 +213,49 @@ describe('getCalendarStepAnchor', () => {
|
|
|
164
213
|
it('steps week, day and four-day views by their own spans', () => {
|
|
165
214
|
const anchor = parseCalendarDateParam('2026-07-22', NOW, LA);
|
|
166
215
|
|
|
167
|
-
expect(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
216
|
+
expect(
|
|
217
|
+
getCalendarDateKey(
|
|
218
|
+
getCalendarStepAnchor({
|
|
219
|
+
view: 'WEEK',
|
|
220
|
+
anchorDate: anchor,
|
|
221
|
+
direction: 1,
|
|
222
|
+
timeZone: LA,
|
|
223
|
+
}),
|
|
224
|
+
LA,
|
|
225
|
+
),
|
|
226
|
+
).toBe('2026-07-29');
|
|
227
|
+
expect(
|
|
228
|
+
getCalendarDateKey(
|
|
229
|
+
getCalendarStepAnchor({
|
|
230
|
+
view: 'DAY',
|
|
231
|
+
anchorDate: anchor,
|
|
232
|
+
direction: -1,
|
|
233
|
+
timeZone: LA,
|
|
234
|
+
}),
|
|
235
|
+
LA,
|
|
236
|
+
),
|
|
237
|
+
).toBe('2026-07-21');
|
|
238
|
+
expect(
|
|
239
|
+
getCalendarDateKey(
|
|
240
|
+
getCalendarStepAnchor({
|
|
241
|
+
view: 'FOUR_DAYS',
|
|
242
|
+
anchorDate: anchor,
|
|
243
|
+
direction: 1,
|
|
244
|
+
timeZone: LA,
|
|
245
|
+
}),
|
|
246
|
+
LA,
|
|
247
|
+
),
|
|
248
|
+
).toBe('2026-07-26');
|
|
173
249
|
});
|
|
174
250
|
|
|
175
251
|
it('steps a week across a DST boundary without drifting an hour', () => {
|
|
176
252
|
const anchor = parseCalendarDateParam('2026-10-28', NOW, LA);
|
|
177
|
-
const next = getCalendarStepAnchor({
|
|
253
|
+
const next = getCalendarStepAnchor({
|
|
254
|
+
view: 'WEEK',
|
|
255
|
+
anchorDate: anchor,
|
|
256
|
+
direction: 1,
|
|
257
|
+
timeZone: LA,
|
|
258
|
+
});
|
|
178
259
|
|
|
179
260
|
// A naive +7*24h would land at 23:00 on the 3rd, which reads as the wrong day
|
|
180
261
|
expect(getCalendarDateKey(next, LA)).toBe('2026-11-04');
|
|
@@ -184,7 +265,12 @@ describe('getCalendarStepAnchor', () => {
|
|
|
184
265
|
|
|
185
266
|
describe('minute helpers', () => {
|
|
186
267
|
it('round-trips minutes through a day start', () => {
|
|
187
|
-
const range = getCalendarRange({
|
|
268
|
+
const range = getCalendarRange({
|
|
269
|
+
view: 'DAY',
|
|
270
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
271
|
+
now: NOW,
|
|
272
|
+
timeZone: LA,
|
|
273
|
+
});
|
|
188
274
|
const dayStart = range.days[0].startAt;
|
|
189
275
|
const instant = getInstantFromDayMinutes(dayStart, 9 * 60 + 30);
|
|
190
276
|
|
|
@@ -201,32 +287,72 @@ describe('minute helpers', () => {
|
|
|
201
287
|
});
|
|
202
288
|
|
|
203
289
|
describe('getCalendarRangeTitle', () => {
|
|
204
|
-
const anchorFor = (dateKey: string) =>
|
|
290
|
+
const anchorFor = (dateKey: string) =>
|
|
291
|
+
parseCalendarDateParam(dateKey, NOW, LA);
|
|
205
292
|
|
|
206
293
|
it('titles a week inside one month', () => {
|
|
207
|
-
const range = getCalendarRange({
|
|
294
|
+
const range = getCalendarRange({
|
|
295
|
+
view: 'WEEK',
|
|
296
|
+
anchorDate: anchorFor('2026-07-22'),
|
|
297
|
+
now: NOW,
|
|
298
|
+
timeZone: LA,
|
|
299
|
+
});
|
|
208
300
|
|
|
209
301
|
expect(getCalendarRangeTitle(range)).toBe('Jul 19 – 25, 2026');
|
|
210
302
|
});
|
|
211
303
|
|
|
212
304
|
it('titles a week spanning two months', () => {
|
|
213
|
-
const range = getCalendarRange({
|
|
305
|
+
const range = getCalendarRange({
|
|
306
|
+
view: 'WEEK',
|
|
307
|
+
anchorDate: anchorFor('2026-07-30'),
|
|
308
|
+
now: NOW,
|
|
309
|
+
timeZone: LA,
|
|
310
|
+
});
|
|
214
311
|
|
|
215
312
|
expect(getCalendarRangeTitle(range)).toBe('Jul 26 – Aug 1, 2026');
|
|
216
313
|
});
|
|
217
314
|
|
|
218
315
|
it('titles a week spanning two years', () => {
|
|
219
|
-
const range = getCalendarRange({
|
|
316
|
+
const range = getCalendarRange({
|
|
317
|
+
view: 'WEEK',
|
|
318
|
+
anchorDate: anchorFor('2026-12-31'),
|
|
319
|
+
now: NOW,
|
|
320
|
+
timeZone: LA,
|
|
321
|
+
});
|
|
220
322
|
|
|
221
323
|
expect(getCalendarRangeTitle(range)).toBe('Dec 27, 2026 – Jan 2, 2027');
|
|
222
324
|
});
|
|
223
325
|
|
|
224
326
|
it('titles month, year and day views', () => {
|
|
225
|
-
expect(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
327
|
+
expect(
|
|
328
|
+
getCalendarRangeTitle(
|
|
329
|
+
getCalendarRange({
|
|
330
|
+
view: 'MONTH',
|
|
331
|
+
anchorDate: anchorFor('2026-07-22'),
|
|
332
|
+
now: NOW,
|
|
333
|
+
timeZone: LA,
|
|
334
|
+
}),
|
|
335
|
+
),
|
|
336
|
+
).toBe('July 2026');
|
|
337
|
+
expect(
|
|
338
|
+
getCalendarRangeTitle(
|
|
339
|
+
getCalendarRange({
|
|
340
|
+
view: 'YEAR',
|
|
341
|
+
anchorDate: anchorFor('2026-07-22'),
|
|
342
|
+
now: NOW,
|
|
343
|
+
timeZone: LA,
|
|
344
|
+
}),
|
|
345
|
+
),
|
|
346
|
+
).toBe('2026');
|
|
347
|
+
expect(
|
|
348
|
+
getCalendarRangeTitle(
|
|
349
|
+
getCalendarRange({
|
|
350
|
+
view: 'DAY',
|
|
351
|
+
anchorDate: anchorFor('2026-07-22'),
|
|
352
|
+
now: NOW,
|
|
353
|
+
timeZone: LA,
|
|
354
|
+
}),
|
|
355
|
+
),
|
|
356
|
+
).toBe('Wednesday, July 22, 2026');
|
|
231
357
|
});
|
|
232
358
|
});
|
|
@@ -15,8 +15,16 @@ const NOW = new Date('2026-07-22T19:00:00Z');
|
|
|
15
15
|
* Render the query string a write produces, for readable assertions.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
function write(
|
|
19
|
-
|
|
18
|
+
function write(
|
|
19
|
+
current: string,
|
|
20
|
+
next: Parameters<typeof writeCalendarUrlState>[1],
|
|
21
|
+
) {
|
|
22
|
+
return writeCalendarUrlState(
|
|
23
|
+
new URLSearchParams(current),
|
|
24
|
+
next,
|
|
25
|
+
NOW,
|
|
26
|
+
LA,
|
|
27
|
+
).toString();
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
describe('view slugs', () => {
|
|
@@ -27,7 +35,14 @@ describe('view slugs', () => {
|
|
|
27
35
|
});
|
|
28
36
|
|
|
29
37
|
it('round-trips every slug', () => {
|
|
30
|
-
for (const view of [
|
|
38
|
+
for (const view of [
|
|
39
|
+
'DAY',
|
|
40
|
+
'FOUR_DAYS',
|
|
41
|
+
'WEEK',
|
|
42
|
+
'MONTH',
|
|
43
|
+
'YEAR',
|
|
44
|
+
'AGENDA',
|
|
45
|
+
] as const) {
|
|
31
46
|
expect(parseCalendarViewSlug(getCalendarViewSlug(view))).toBe(view);
|
|
32
47
|
}
|
|
33
48
|
});
|
|
@@ -54,7 +69,11 @@ describe('readCalendarUrlState', () => {
|
|
|
54
69
|
});
|
|
55
70
|
|
|
56
71
|
it('reads a full URL', () => {
|
|
57
|
-
const state = readCalendarUrlState(
|
|
72
|
+
const state = readCalendarUrlState(
|
|
73
|
+
new URLSearchParams('v=month&d=2026-03-01&me=1&hide=a,b'),
|
|
74
|
+
NOW,
|
|
75
|
+
LA,
|
|
76
|
+
);
|
|
58
77
|
|
|
59
78
|
expect(state.view).toBe('MONTH');
|
|
60
79
|
expect(getCalendarDateKey(state.anchorDate, LA)).toBe('2026-03-01');
|
|
@@ -63,7 +82,11 @@ describe('readCalendarUrlState', () => {
|
|
|
63
82
|
});
|
|
64
83
|
|
|
65
84
|
it('ignores blank entries in the calendar list', () => {
|
|
66
|
-
const state = readCalendarUrlState(
|
|
85
|
+
const state = readCalendarUrlState(
|
|
86
|
+
new URLSearchParams('hide=a,,b,'),
|
|
87
|
+
NOW,
|
|
88
|
+
LA,
|
|
89
|
+
);
|
|
67
90
|
|
|
68
91
|
expect(state.hiddenCalendarIds).toEqual(['a', 'b']);
|
|
69
92
|
});
|
|
@@ -72,7 +95,14 @@ describe('readCalendarUrlState', () => {
|
|
|
72
95
|
describe('writeCalendarUrlState', () => {
|
|
73
96
|
it('writes nothing at all for the defaults', () => {
|
|
74
97
|
// The whole point: an untouched calendar has a clean URL
|
|
75
|
-
expect(
|
|
98
|
+
expect(
|
|
99
|
+
write('', {
|
|
100
|
+
view: 'WEEK',
|
|
101
|
+
anchorDate: NOW,
|
|
102
|
+
mineOnly: false,
|
|
103
|
+
hiddenCalendarIds: [],
|
|
104
|
+
}),
|
|
105
|
+
).toBe('');
|
|
76
106
|
});
|
|
77
107
|
|
|
78
108
|
it('writes only what differs from the default', () => {
|
|
@@ -82,17 +112,23 @@ describe('writeCalendarUrlState', () => {
|
|
|
82
112
|
});
|
|
83
113
|
|
|
84
114
|
it('omits the date when it is today', () => {
|
|
85
|
-
expect(write('', { anchorDate: new Date('2026-07-22T23:00:00Z') })).toBe(
|
|
115
|
+
expect(write('', { anchorDate: new Date('2026-07-22T23:00:00Z') })).toBe(
|
|
116
|
+
'',
|
|
117
|
+
);
|
|
86
118
|
});
|
|
87
119
|
|
|
88
120
|
it('writes the date when it is not today', () => {
|
|
89
|
-
expect(write('', { anchorDate: new Date('2026-08-01T12:00:00Z') })).toBe(
|
|
121
|
+
expect(write('', { anchorDate: new Date('2026-08-01T12:00:00Z') })).toBe(
|
|
122
|
+
'd=2026-08-01',
|
|
123
|
+
);
|
|
90
124
|
});
|
|
91
125
|
|
|
92
126
|
it('resolves "today" in the calendar zone, not in UTC', () => {
|
|
93
127
|
// 2026-07-23T02:00Z is still the 22nd in Los Angeles, so it is today
|
|
94
128
|
// and should produce no parameter at all
|
|
95
|
-
expect(write('', { anchorDate: new Date('2026-07-23T02:00:00Z') })).toBe(
|
|
129
|
+
expect(write('', { anchorDate: new Date('2026-07-23T02:00:00Z') })).toBe(
|
|
130
|
+
'',
|
|
131
|
+
);
|
|
96
132
|
});
|
|
97
133
|
|
|
98
134
|
it('clears a parameter when it returns to the default', () => {
|
|
@@ -114,11 +150,18 @@ describe('writeCalendarUrlState', () => {
|
|
|
114
150
|
});
|
|
115
151
|
|
|
116
152
|
it('changes nothing for keys it was not asked about', () => {
|
|
117
|
-
expect(write('v=month&me=1&d=2026-08-01', {})).toBe(
|
|
153
|
+
expect(write('v=month&me=1&d=2026-08-01', {})).toBe(
|
|
154
|
+
'v=month&me=1&d=2026-08-01',
|
|
155
|
+
);
|
|
118
156
|
});
|
|
119
157
|
|
|
120
158
|
it('produces a readable full URL', () => {
|
|
121
|
-
expect(
|
|
122
|
-
|
|
159
|
+
expect(
|
|
160
|
+
write('', {
|
|
161
|
+
view: 'MONTH',
|
|
162
|
+
anchorDate: new Date('2026-08-01T12:00:00Z'),
|
|
163
|
+
mineOnly: true,
|
|
164
|
+
}),
|
|
165
|
+
).toBe('v=month&d=2026-08-01&me=1');
|
|
123
166
|
});
|
|
124
167
|
});
|