@wtfalch/calendar 0.1.0

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/calendar/calendar-client.d.ts +7 -0
  4. package/dist/calendar/calendar-client.js +242 -0
  5. package/dist/calendar/calendar.css +953 -0
  6. package/dist/calendar/client.d.ts +87 -0
  7. package/dist/calendar/client.js +233 -0
  8. package/dist/calendar/errors.d.ts +28 -0
  9. package/dist/calendar/errors.js +61 -0
  10. package/dist/calendar/fake/index.d.ts +36 -0
  11. package/dist/calendar/fake/index.js +79 -0
  12. package/dist/calendar/fake/sample.d.ts +66 -0
  13. package/dist/calendar/fake/sample.js +116 -0
  14. package/dist/calendar/fake/store.d.ts +79 -0
  15. package/dist/calendar/fake/store.js +906 -0
  16. package/dist/calendar/index.d.ts +12 -0
  17. package/dist/calendar/index.js +11 -0
  18. package/dist/calendar/push.d.ts +38 -0
  19. package/dist/calendar/push.js +129 -0
  20. package/dist/calendar/react/AvailabilityRibbon.d.ts +40 -0
  21. package/dist/calendar/react/AvailabilityRibbon.js +108 -0
  22. package/dist/calendar/react/Calendar.d.ts +28 -0
  23. package/dist/calendar/react/Calendar.js +431 -0
  24. package/dist/calendar/react/EventDetail.d.ts +22 -0
  25. package/dist/calendar/react/EventDetail.js +91 -0
  26. package/dist/calendar/react/EventEditor.d.ts +52 -0
  27. package/dist/calendar/react/EventEditor.js +188 -0
  28. package/dist/calendar/react/ShareDialog.d.ts +25 -0
  29. package/dist/calendar/react/ShareDialog.js +125 -0
  30. package/dist/calendar/react/Toolbar.d.ts +29 -0
  31. package/dist/calendar/react/Toolbar.js +58 -0
  32. package/dist/calendar/react/index.d.ts +9 -0
  33. package/dist/calendar/react/index.js +8 -0
  34. package/dist/calendar/react/participants.d.ts +34 -0
  35. package/dist/calendar/react/participants.js +40 -0
  36. package/dist/calendar/types.d.ts +384 -0
  37. package/dist/calendar/types.js +40 -0
  38. package/dist/calendar/uri.d.ts +13 -0
  39. package/dist/calendar/uri.js +22 -0
  40. package/dist/calendar/wire.d.ts +177 -0
  41. package/dist/calendar/wire.js +349 -0
  42. package/package.json +82 -0
@@ -0,0 +1,431 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * `Calendar` — a month, week, day or agenda view on react-big-calendar,
4
+ * driven by `CalendarProps.location` and fetching through `CalendarProps.client`.
5
+ *
6
+ * MSG-055 (https://github.com/wtfalch/messaging/issues/158) turned MSG-053's
7
+ * shell into the first of the four first-ship features: a person's own events,
8
+ * created, edited and deleted here, recurring included. The direction this
9
+ * builds to is recorded in
10
+ * `.impeccable/surfaces/src-calendar-react-calendar-tsx.md`.
11
+ *
12
+ * **The grid is the map and the pane is the decision.** Selecting an event
13
+ * opens a pane beside the grid rather than a dialog over it, because deciding
14
+ * what to do about a meeting means looking at the week around it, and a dialog
15
+ * covers exactly that. Below the design system's `medium` breakpoint there is
16
+ * no week to look at, so the pane becomes a bottom sheet instead.
17
+ *
18
+ * The controlled/uncontrolled seam `Mail.tsx`
19
+ * (`packages/email/src/mailbox/react/Mail.tsx:69-106` on `email`'s
20
+ * `origin/main`) set for `location`/`onNavigate` is unchanged.
21
+ *
22
+ * No Agora code: only `react`, `react-big-calendar`, `dayjs` (its bundled
23
+ * localizer, already a dependency of `react-big-calendar` itself),
24
+ * `@wtfalch/design` for the component vocabulary — an optional peer, exactly
25
+ * as `@wtfalch/email`'s own `Mail` declares it — and this package's own
26
+ * `../types.ts`/`../wire.ts`.
27
+ */
28
+ import { Empty, MEDIA_QUERIES, Modal, ScrollArea, Skeleton, SplitPane, useMediaQuery, } from '@wtfalch/design';
29
+ import dayjs from 'dayjs';
30
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
31
+ import { Calendar as BigCalendar, Views, dayjsLocalizer } from 'react-big-calendar';
32
+ import { CalendarError } from "../types.js";
33
+ import { parseDurationMs } from "../wire.js";
34
+ import { EventDetail } from "./EventDetail.js";
35
+ import { EventEditor } from "./EventEditor.js";
36
+ import { ShareDialog } from "./ShareDialog.js";
37
+ import { Toolbar } from "./Toolbar.js";
38
+ import { sameAddress } from "./participants.js";
39
+ const localizer = dayjsLocalizer(dayjs);
40
+ /** The date in a month cell is `6`, not `06`. react-big-calendar's dayjs
41
+ * localizer pads by default, and a zero-padded day reads as a code rather
42
+ * than a date. */
43
+ const FORMATS = { dateFormat: 'D' };
44
+ /** Where the day and week columns open. Left alone react-big-calendar starts
45
+ * at midnight, so the phone's day column -- the whole of the small-breakpoint
46
+ * composition -- opens on six hours of dead night and every real meeting is
47
+ * below the fold. 7am is early enough to keep a breakfast meeting visible.
48
+ * The date is ignored; only the time of day is read. */
49
+ const SCROLL_TO = new Date(1970, 0, 1, 7, 0, 0);
50
+ /** The only views this component offers a reader -- `CalendarLocation.view`'s
51
+ * own union, not react-big-calendar's `work_week`, which nothing in the
52
+ * contract names. */
53
+ const SUPPORTED_VIEWS = [Views.MONTH, Views.WEEK, Views.DAY, Views.AGENDA];
54
+ function toRbcView(view) {
55
+ if (view === 'week')
56
+ return Views.WEEK;
57
+ if (view === 'day')
58
+ return Views.DAY;
59
+ if (view === 'agenda')
60
+ return Views.AGENDA;
61
+ return Views.MONTH;
62
+ }
63
+ function fromRbcView(view) {
64
+ if (view === Views.WEEK)
65
+ return 'week';
66
+ if (view === Views.DAY)
67
+ return 'day';
68
+ if (view === Views.AGENDA)
69
+ return 'agenda';
70
+ return 'month';
71
+ }
72
+ /**
73
+ * The bounds `listEvents` is called with for a given view/date. Always both
74
+ * `after` and `before` -- `CalendarRange`'s own doc comment -- padded a week
75
+ * either side for `month`, matching the leading/trailing days
76
+ * react-big-calendar's own month grid draws from neighbouring months.
77
+ */
78
+ function rangeFor(view, date) {
79
+ const start = new Date(date);
80
+ const end = new Date(date);
81
+ if (view === 'day') {
82
+ start.setUTCHours(0, 0, 0, 0);
83
+ end.setUTCHours(0, 0, 0, 0);
84
+ end.setUTCDate(end.getUTCDate() + 1);
85
+ }
86
+ else if (view === 'week') {
87
+ start.setUTCHours(0, 0, 0, 0);
88
+ start.setUTCDate(start.getUTCDate() - start.getUTCDay());
89
+ end.setTime(start.getTime());
90
+ end.setUTCDate(end.getUTCDate() + 7);
91
+ }
92
+ else if (view === 'agenda') {
93
+ start.setUTCHours(0, 0, 0, 0);
94
+ end.setUTCHours(0, 0, 0, 0);
95
+ end.setUTCDate(end.getUTCDate() + 30);
96
+ }
97
+ else {
98
+ start.setUTCDate(1);
99
+ start.setUTCHours(0, 0, 0, 0);
100
+ start.setUTCDate(start.getUTCDate() - 7);
101
+ end.setUTCMonth(end.getUTCMonth() + 1, 1);
102
+ end.setUTCHours(0, 0, 0, 0);
103
+ end.setUTCDate(end.getUTCDate() + 7);
104
+ }
105
+ return { after: start.toISOString(), before: end.toISOString() };
106
+ }
107
+ /**
108
+ * `CalendarEvent.start` is a local date-time with no offset (`types.ts`'s own
109
+ * doc comment); rendered here as if it were UTC, the same simplification the
110
+ * fake's own store uses for its date arithmetic
111
+ * (`fake/store.ts`'s `new Date(`${event.start}Z`)`). A real per-event
112
+ * timezone conversion is display work for MSG-055, not this ticket's shape
113
+ * -- logged as a Finding.
114
+ */
115
+ function toGridEvent(event) {
116
+ const start = new Date(`${event.start}Z`);
117
+ const end = new Date(start.getTime() + (parseDurationMs(event.duration) ?? 0));
118
+ return { id: event.id, title: event.title, start, end, allDay: event.isAllDay, source: event };
119
+ }
120
+ function cx(...classes) {
121
+ return classes.filter(Boolean).join(' ');
122
+ }
123
+ /** Whether `query` matches right now, read directly off `matchMedia`. A plain
124
+ * function rather than the `useMediaQuery` hook, because this runs inside a
125
+ * `useState` initialiser, where a second hook may not be called.
126
+ *
127
+ * `fallback` stands in when there is no `matchMedia` to ask -- an SSR render,
128
+ * or a test that has not stubbed one. `useMediaQuery` itself always answers
129
+ * conservatively `false` there, by its own doc comment, because most of its
130
+ * callers have nothing hidden to get wrong either way; a phone's day-only
131
+ * grid is the opposite of that, so an unknown width defaults to the grid
132
+ * that shows the whole month rather than the one that hides most of it. */
133
+ function matchesNow(query, fallback) {
134
+ return typeof window !== 'undefined' && typeof window.matchMedia === 'function'
135
+ ? window.matchMedia(query).matches
136
+ : fallback;
137
+ }
138
+ /** The uncontrolled default view, read once at mount: the day column below
139
+ * the design system's small breakpoint (`sm`), the month grid at or above
140
+ * it -- or when it cannot be asked at all. A host that supplies `location`
141
+ * never reaches this -- `current` is `location` itself in that case. */
142
+ function initialView() {
143
+ return matchesNow(MEDIA_QUERIES.sm, true) ? 'month' : 'day';
144
+ }
145
+ /**
146
+ * The seven days of `date`'s week, Sunday first, in UTC.
147
+ *
148
+ * UTC rather than local time because everything downstream of a picked day is
149
+ * UTC: `rangeFor` floors a day with `setUTCHours(0, 0, 0, 0)`, and
150
+ * `toGridEvent` reads an event's local-date-time start as if it were UTC. A
151
+ * local-midnight day is an hour or more the *other* side of that floor for
152
+ * anyone east of UTC, so picking Friday fetched Thursday and the column came
153
+ * back empty while the heading still said Friday.
154
+ */
155
+ function weekDays(date) {
156
+ const start = new Date(date);
157
+ start.setUTCHours(0, 0, 0, 0);
158
+ start.setUTCDate(start.getUTCDate() - start.getUTCDay());
159
+ return Array.from({ length: 7 }, (_, i) => {
160
+ const day = new Date(start);
161
+ day.setUTCDate(day.getUTCDate() + i);
162
+ return day;
163
+ });
164
+ }
165
+ function isSameDay(a, b) {
166
+ return (a.getUTCFullYear() === b.getUTCFullYear() &&
167
+ a.getUTCMonth() === b.getUTCMonth() &&
168
+ a.getUTCDate() === b.getUTCDate());
169
+ }
170
+ /**
171
+ * Fetch on mount and whenever the range's own edges change. `onError` lives
172
+ * in a ref, mirroring `@wtfalch/email/mailbox/react/hooks.ts`'s `useResource`:
173
+ * every call site builds an inline callback, and depending on it is how a
174
+ * fetch loop that never stops fetching gets written.
175
+ *
176
+ * `reload` re-runs the same fetch after a write. The server owns recurrence
177
+ * expansion, so a create or edit of a repeating event changes rows this client
178
+ * could not have predicted; asking again is the only honest way to know what
179
+ * the grid now holds.
180
+ */
181
+ function useCalendarEvents(client, range, onError) {
182
+ const [state, setState] = useState({ events: undefined, error: undefined });
183
+ const [loading, setLoading] = useState(true);
184
+ const [generation, setGeneration] = useState(0);
185
+ const onErrorRef = useRef(onError);
186
+ onErrorRef.current = onError;
187
+ const reload = useCallback(() => setGeneration((n) => n + 1), []);
188
+ // `generation` is the refetch trigger: nothing inside the effect reads it,
189
+ // and bumping it is how a write asks for a fresh list.
190
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the trigger is deliberately unread
191
+ useEffect(() => {
192
+ let live = true;
193
+ setLoading(true);
194
+ client
195
+ .listEvents(range)
196
+ .then((events) => {
197
+ if (live)
198
+ setState({ events, error: undefined });
199
+ }, (thrown) => {
200
+ const error = thrown instanceof CalendarError ? thrown : new CalendarError(String(thrown));
201
+ if (live) {
202
+ setState((previous) => ({ events: previous.events, error }));
203
+ onErrorRef.current?.(error);
204
+ }
205
+ })
206
+ .finally(() => {
207
+ if (live)
208
+ setLoading(false);
209
+ });
210
+ return () => {
211
+ live = false;
212
+ };
213
+ }, [client, range, generation]);
214
+ return { events: state.events, error: state.error, loading, reload };
215
+ }
216
+ /**
217
+ * The calendar a new event lands on.
218
+ *
219
+ * First-ship views overlay every calendar rather than selecting one, so there
220
+ * is no calendar in `CalendarLocation` to create against. The person's own
221
+ * first calendar is the answer, and it comes from `listCalendars` rather than
222
+ * from whichever event happens to be on screen — an empty month would
223
+ * otherwise leave nothing to create into.
224
+ */
225
+ /**
226
+ * The viewer's own calendar address, for telling their participant row from
227
+ * everyone else's.
228
+ *
229
+ * Read from the client rather than taken as a prop, the way
230
+ * `@wtfalch/email`'s `Mail` reads its identities: a host cannot forget to
231
+ * pass it, and cannot pass the wrong one. It costs no request of its own --
232
+ * the address is in the JMAP session document the connection already caches.
233
+ *
234
+ * A failure here is not this hook's to report. The event fetch runs against
235
+ * the same session and surfaces the same outage through `onError`; all that
236
+ * is lost meanwhile is the RSVP row, which is the honest thing to lose when
237
+ * we cannot say whose invite it is.
238
+ */
239
+ function useMe(client) {
240
+ const [me, setMe] = useState(undefined);
241
+ useEffect(() => {
242
+ let live = true;
243
+ client.identity().then((identity) => {
244
+ if (live)
245
+ setMe(identity.calendarAddress);
246
+ }, () => { });
247
+ return () => {
248
+ live = false;
249
+ };
250
+ }, [client]);
251
+ return me;
252
+ }
253
+ /**
254
+ * How the editor asks when a set of people are busy.
255
+ *
256
+ * One `resolvePrincipal` per address to turn it into the `principalId`
257
+ * `getAvailability` takes, then one availability call each. An address that
258
+ * resolves to nobody, or a call that fails, simply has no entry — which the
259
+ * ribbon draws as unknown, because that is what it is.
260
+ *
261
+ * **An empty list is not "free".** It is the same answer the server gives for
262
+ * never-shared and for shared-then-revoked, measured live and pinned in
263
+ * `wire-live-transcript.test.ts`. The ribbon is the place that decides what to
264
+ * draw; this function only reports what came back.
265
+ */
266
+ function useAvailabilityLookup(client) {
267
+ return useCallback(async (addresses, day) => {
268
+ const from = new Date(day);
269
+ from.setHours(0, 0, 0, 0);
270
+ const to = new Date(from);
271
+ to.setDate(to.getDate() + 1);
272
+ const range = { after: from.toISOString(), before: to.toISOString() };
273
+ const answers = new Map();
274
+ await Promise.all(addresses.map(async (address) => {
275
+ try {
276
+ const principal = await client.resolvePrincipal(address);
277
+ if (!principal)
278
+ return;
279
+ answers.set(address, await client.getAvailability(principal.accountId, range));
280
+ }
281
+ catch {
282
+ // No entry, so the band stays unknown. A failure to ask is one
283
+ // more way of not being able to see somebody.
284
+ }
285
+ }));
286
+ return answers;
287
+ }, [client]);
288
+ }
289
+ function useDefaultCalendarId(client) {
290
+ const [id, setId] = useState(undefined);
291
+ useEffect(() => {
292
+ let live = true;
293
+ client.listCalendars().then((calendars) => {
294
+ if (live)
295
+ setId(calendars[0]?.id);
296
+ }, () => {
297
+ // A failure here is not this hook's to report: the event list fetch
298
+ // runs against the same session and surfaces the same outage through
299
+ // `onError`.
300
+ });
301
+ return () => {
302
+ live = false;
303
+ };
304
+ }, [client]);
305
+ return id;
306
+ }
307
+ export function Calendar({ client, location, onNavigate, account, onError, now, className, }) {
308
+ const [own, setOwn] = useState(() => ({
309
+ view: initialView(),
310
+ date: now ?? new Date(),
311
+ eventId: null,
312
+ }));
313
+ // Controlled when a location was given, and then entirely -- mirroring
314
+ // `Mail.tsx`'s own `controlled`/`navigate` pair.
315
+ const controlled = location !== undefined;
316
+ const current = controlled ? location : own;
317
+ const navigate = useCallback((to) => {
318
+ if (controlled)
319
+ onNavigate?.(to);
320
+ else
321
+ setOwn(to);
322
+ }, [controlled, onNavigate]);
323
+ const range = useMemo(() => rangeFor(current.view, current.date), [current.view, current.date]);
324
+ const { events, error, loading, reload } = useCalendarEvents(client, range, onError);
325
+ const gridEvents = useMemo(() => (events ?? []).map(toGridEvent), [events]);
326
+ /** Below `md` the pane and the editor become sheets. The same breakpoint
327
+ * `Shell` and `SideList` collapse at, from the same constant. 0.21.0 put
328
+ * these on Tailwind's scale, so `medium` (860) became `md` (768). */
329
+ const roomy = useMediaQuery(MEDIA_QUERIES.md);
330
+ const compact = !roomy;
331
+ /** Below `sm`, a breakpoint narrower than `md` and new in 0.21.0: the grid
332
+ * becomes a single day column with a scrollable week strip above it for
333
+ * picking the day, in place of the month grid the wider layouts show. */
334
+ const phone = !useMediaQuery(MEDIA_QUERIES.sm);
335
+ const defaultCalendarId = useDefaultCalendarId(client);
336
+ const availability = useAvailabilityLookup(client);
337
+ const me = useMe(client);
338
+ /** `undefined` when the editor is closed; otherwise what it is editing. A
339
+ * create carries the slot the person picked, so making an event by clicking
340
+ * Thursday afternoon starts on Thursday afternoon. */
341
+ const [editing, setEditing] = useState(undefined);
342
+ /** Whether the sharing dialog is open. Sharing is about the calendar, not
343
+ * about any event on it, so it carries no selection with it. */
344
+ const [sharing, setSharing] = useState(false);
345
+ const selected = useMemo(() => (events ?? []).find((event) => event.id === current.eventId), [events, current.eventId]);
346
+ const handleNavigate = useCallback((nextDate) => navigate({ view: current.view, date: nextDate, eventId: current.eventId }), [navigate, current.view, current.eventId]);
347
+ const handleView = useCallback((nextView) => navigate({ view: fromRbcView(nextView), date: current.date, eventId: current.eventId }), [navigate, current.date, current.eventId]);
348
+ const handleSelectEvent = useCallback((event) => navigate({ view: current.view, date: current.date, eventId: event.source.id }), [navigate, current.view, current.date]);
349
+ const closeDetail = useCallback(() => navigate({ view: current.view, date: current.date, eventId: null }), [navigate, current.view, current.date]);
350
+ /**
351
+ * Which event id a write addresses.
352
+ *
353
+ * An expanded occurrence's id is synthetic. Changing "only this event" means
354
+ * sending the patch to that synthetic id, which the server turns into a
355
+ * `recurrenceOverrides` entry on the master; destroying it records
356
+ * `{excluded: true}` there instead of deleting anything. Changing the whole
357
+ * series means addressing the master, which arrives as `baseEventId`. Both
358
+ * paths were confirmed live against Stalwart v0.16.20 for MSG-055. An event
359
+ * with no `baseEventId` is not an occurrence, so its own id is the series.
360
+ */
361
+ const targetId = useCallback((event, scope) => {
362
+ if (scope === 'series')
363
+ return event.baseEventId ?? event.id;
364
+ return event.id;
365
+ }, []);
366
+ /**
367
+ * Refetch, and stop pointing at whatever was selected.
368
+ *
369
+ * Synthetic occurrence ids are positional, not stable: excluding one
370
+ * occurrence renumbers the rest, so an id held across a write can silently
371
+ * name a different occurrence afterwards. Confirmed live. Clearing the
372
+ * selection is the honest answer — the thing the pane was showing may no
373
+ * longer be at that id, and showing the wrong meeting is worse than showing
374
+ * none.
375
+ */
376
+ const afterWrite = useCallback(() => {
377
+ closeDetail();
378
+ reload();
379
+ }, [closeDetail, reload]);
380
+ const saveEvent = useCallback(async (draft, scope, notify) => {
381
+ const event = editing?.event;
382
+ const options = { sendSchedulingMessages: notify };
383
+ if (event === undefined)
384
+ await client.createEvent(draft.calendarId, draft, options);
385
+ else
386
+ await client.updateEvent(targetId(event, scope), draft, options);
387
+ afterWrite();
388
+ }, [afterWrite, client, editing, targetId]);
389
+ const deleteEvent = useCallback(async (scope, notify) => {
390
+ const event = editing?.event;
391
+ if (event === undefined)
392
+ return;
393
+ await client.deleteEvent(targetId(event, scope), { sendSchedulingMessages: notify });
394
+ afterWrite();
395
+ }, [afterWrite, client, editing, targetId]);
396
+ /**
397
+ * Answer an invite.
398
+ *
399
+ * Always with `sendSchedulingMessages: true`, and not by the person's
400
+ * choice: an RSVP nobody is told about is not an RSVP. That is the opposite
401
+ * of the editor's Save, where telling people is the separate decision --
402
+ * here the telling *is* the act.
403
+ *
404
+ * The patch addresses the viewer's own participant entry by its map key.
405
+ * Those keys are assigned by `wire.ts` (`p0`, `p1`, ...) and are never part
406
+ * of the contract, so the key is looked up by address rather than assumed.
407
+ */
408
+ const respond = useCallback(async (answer) => {
409
+ if (selected === undefined || me === undefined)
410
+ return;
411
+ const participants = (selected.participants ?? []).map((person) => sameAddress(person.calendarAddress, me)
412
+ ? { ...person, participationStatus: answer }
413
+ : person);
414
+ await client.updateEvent(selected.id, { participants }, { sendSchedulingMessages: true });
415
+ reload();
416
+ }, [client, me, reload, selected]);
417
+ const empty = !loading && !error && gridEvents.length === 0;
418
+ const detail = selected !== undefined ? (_jsx(EventDetail, { event: selected, me: me, onEdit: () => setEditing({ event: selected, start: undefined }), onRespond: respond, onClose: closeDetail })) : null;
419
+ /** The phone day view's own picker: the week around `current.date`, tapping
420
+ * a day moving the single day column below it rather than switching view.
421
+ * Only below `sm`, and only for the day view -- the month/week/agenda
422
+ * grids react-big-calendar draws at phone width need no second picker. */
423
+ const weekStrip = phone && current.view === 'day' ? (_jsx(ScrollArea, { axis: "x", hideBar: true, className: "wtcal-week-strip", label: "Pick a day", children: _jsx("div", { className: "wtcal-week-strip-row", children: weekDays(current.date).map((day) => {
424
+ const picked = isSameDay(day, current.date);
425
+ return (_jsxs("button", { type: "button", className: cx('wtcal-week-strip-day', picked && 'is-selected'), "aria-pressed": picked, onClick: () => handleNavigate(day), children: [_jsx("span", { className: "wtcal-week-strip-dow", children: day.toLocaleDateString(undefined, { weekday: 'short', timeZone: 'UTC' }) }), _jsx("span", { className: "wtcal-week-strip-num", children: day.getUTCDate() })] }, day.toISOString()));
426
+ }) }) })) : null;
427
+ const grid = (_jsx("div", { className: "wtcal-grid", children: _jsx(BigCalendar, { localizer: localizer, events: gridEvents, view: toRbcView(current.view), date: current.date, views: SUPPORTED_VIEWS, formats: FORMATS, toolbar: false, selectable: true, onNavigate: handleNavigate, onView: handleView, onSelectEvent: handleSelectEvent, onSelectSlot: (slot) => setEditing({ event: undefined, start: slot.start }), scrollToTime: SCROLL_TO, getNow: () => now ?? new Date(), titleAccessor: "title", startAccessor: "start", endAccessor: "end", allDayAccessor: "allDay", style: { height: '100%' } }) }));
428
+ return (_jsxs("div", { className: cx('wtcal', compact && 'is-compact', className), children: [_jsx(Toolbar, { view: current.view, date: current.date, compact: compact, account: account, onMove: handleNavigate, onToday: () => handleNavigate(now ?? new Date()), onView: (view) => navigate({ view, date: current.date, eventId: current.eventId }), onCreate: () => setEditing({ event: undefined, start: undefined }), onShare: defaultCalendarId !== undefined ? () => setSharing(true) : undefined }), _jsxs("div", { className: "wtcal-body", children: [loading && (_jsx("div", { className: "wtcal-loading", "aria-busy": "true", "aria-live": "polite", "aria-label": "Loading your calendar", children: _jsx("div", { className: "wtcal-loading-grid", children: Array.from({ length: 35 }, (_, n) => (
429
+ // biome-ignore lint/suspicious/noArrayIndexKey: a fixed-length row of interchangeable placeholders, never reordered or removed individually -- there is no other identity to key them by.
430
+ _jsx(Skeleton, { variant: "rounded", height: "100%" }, n))) }) })), !loading && error && (_jsx("p", { className: "wtcal-status is-error", role: "alert", children: error.message })), !loading && !error && (_jsxs(_Fragment, { children: [weekStrip, empty && _jsx(Empty, { className: "wtcal-empty", children: "Nothing on the calendar here." }), roomy && detail !== null ? (_jsxs(SplitPane, { className: "wtcal-split", label: "Event details width", defaultSize: 72, min: 55, max: 82, storageKey: "wtcal-detail", children: [grid, _jsx(ScrollArea, { className: "wtcal-pane", label: "Event details", children: detail })] })) : (grid)] }))] }), compact && detail !== null && (_jsx(Modal, { edge: "bottom", onClose: closeDetail, labelledBy: undefined, closeButton: false, children: detail })), sharing && defaultCalendarId !== undefined && (_jsx(ShareDialog, { client: client, calendarId: defaultCalendarId, compact: compact, onClose: () => setSharing(false) })), editing !== undefined && (_jsx(EventEditor, { event: editing.event, initialStart: editing.start, now: now ?? new Date(), calendarId: editing.event?.calendarId ?? defaultCalendarId ?? '', compact: compact, onSave: saveEvent, onDelete: editing.event !== undefined ? deleteEvent : undefined, onClose: () => setEditing(undefined), availability: availability }))] }));
431
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The detail pane: one event, read, with the way into editing it.
3
+ *
4
+ * It is a pane rather than a dialog on purpose. Deciding what to do about a
5
+ * meeting means looking at the week around it, and a dialog covers exactly
6
+ * the thing the decision needs. On a phone there is no week to look at, so
7
+ * `Calendar` renders this inside a bottom sheet instead.
8
+ */
9
+ import type { CalendarEvent, CalendarParticipationStatus } from '../types.ts';
10
+ export type EventDetailProps = {
11
+ event: CalendarEvent;
12
+ /** The viewer's own calendar address, from `client.identity()`. Undefined
13
+ * while it is still being fetched, which is why the RSVP row appears a
14
+ * moment after the pane rather than with it. */
15
+ me?: string;
16
+ onEdit: () => void;
17
+ /** Answer an invite. Absent on an event the viewer is not a participant of,
18
+ * which is what makes the RSVP row conditional. */
19
+ onRespond?: (answer: CalendarParticipationStatus) => Promise<void>;
20
+ onClose: () => void;
21
+ };
22
+ export declare function EventDetail({ event, me, onEdit, onRespond, onClose }: EventDetailProps): import("react").JSX.Element;
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The detail pane: one event, read, with the way into editing it.
4
+ *
5
+ * It is a pane rather than a dialog on purpose. Deciding what to do about a
6
+ * meeting means looking at the week around it, and a dialog covers exactly
7
+ * the thing the decision needs. On a phone there is no week to look at, so
8
+ * `Calendar` renders this inside a bottom sheet instead.
9
+ */
10
+ import { Button, Icon, Identity, Pill } from '@wtfalch/design';
11
+ import { useState } from 'react';
12
+ import { parseDurationMs } from "../wire.js";
13
+ import { STATUS_TONE, STATUS_WORD, addressOf, sameAddress } from "./participants.js";
14
+ /** The three answers a person can give, in the order a person weighs them.
15
+ * "No answer yet" is not among them: it is the absence of an answer, not one
16
+ * somebody chooses. */
17
+ const ANSWERS = [
18
+ { value: 'accepted', label: 'Yes' },
19
+ { value: 'tentative', label: 'Maybe' },
20
+ { value: 'declined', label: 'No' },
21
+ ];
22
+ function formatWhen(event) {
23
+ const start = new Date(`${event.start}Z`);
24
+ const date = start.toLocaleDateString(undefined, {
25
+ weekday: 'long',
26
+ day: 'numeric',
27
+ month: 'long',
28
+ timeZone: 'UTC',
29
+ });
30
+ if (event.isAllDay)
31
+ return `${date}, all day`;
32
+ const time = (at) => at.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', timeZone: 'UTC' });
33
+ const ms = parseDurationMs(event.duration);
34
+ if (ms === null)
35
+ return `${date}, ${time(start)}`;
36
+ return `${date}, ${time(start)} to ${time(new Date(start.getTime() + ms))}`;
37
+ }
38
+ /**
39
+ * What the pane says about repetition.
40
+ *
41
+ * An expanded occurrence carries no `recurrenceRule` of its own — only the
42
+ * master holds the rule — so reading the rule alone leaves every occurrence
43
+ * looking like a one-off. That silence is the dangerous kind: it is exactly
44
+ * the event whose edit reaches eleven others.
45
+ */
46
+ function formatRepeat(event) {
47
+ const rule = event.recurrenceRule;
48
+ if (rule === undefined) {
49
+ return event.recurrenceId !== undefined ? 'One of a repeating series' : null;
50
+ }
51
+ const every = rule.interval !== undefined && rule.interval > 1
52
+ ? `Every ${rule.interval} ${rule.frequency.replace('ly', 's').replace('dais', 'days')}`
53
+ : { daily: 'Every day', weekly: 'Every week', monthly: 'Every month', yearly: 'Every year' }[rule.frequency];
54
+ if (rule.count !== undefined)
55
+ return `${every}, ${rule.count} times`;
56
+ if (rule.until !== undefined)
57
+ return `${every}, until ${rule.until.slice(0, 10)}`;
58
+ return every;
59
+ }
60
+ export function EventDetail({ event, me, onEdit, onRespond, onClose }) {
61
+ const repeat = formatRepeat(event);
62
+ const participants = event.participants ?? [];
63
+ const [answering, setAnswering] = useState(null);
64
+ const [failure, setFailure] = useState(null);
65
+ /** The viewer's own row, if they are on the list at all. An event somebody
66
+ * made themselves has them on it as `owner`, and an owner does not RSVP to
67
+ * their own meeting -- they already know. */
68
+ const mine = me === undefined
69
+ ? undefined
70
+ : participants.find((person) => sameAddress(person.calendarAddress, me));
71
+ const invited = mine !== undefined && !(mine.roles ?? []).includes('owner');
72
+ const respond = async (answer) => {
73
+ if (onRespond === undefined)
74
+ return;
75
+ setAnswering(answer);
76
+ setFailure(null);
77
+ try {
78
+ await onRespond(answer);
79
+ }
80
+ catch (thrown) {
81
+ setFailure(thrown instanceof Error ? thrown.message : String(thrown));
82
+ }
83
+ finally {
84
+ setAnswering(null);
85
+ }
86
+ };
87
+ return (_jsxs("article", { className: "wtcal-detail", "aria-label": event.title, children: [_jsxs("header", { className: "wtcal-detail-head", children: [_jsx("h2", { className: "wtcal-detail-title", children: event.title }), _jsx(Button, { kind: "ghost", size: "sm", iconOnly: true, "aria-label": "Close event details", onPress: onClose, children: _jsx(Icon, { name: "close", size: "sm" }) })] }), _jsx("p", { className: "wtcal-detail-when", children: formatWhen(event) }), repeat !== null && _jsx("p", { className: "wtcal-detail-repeat", children: repeat }), invited && onRespond !== undefined && (_jsxs("section", { className: "wtcal-rsvp", "aria-label": "Your answer", children: [_jsx("h3", { className: "wtcal-detail-label", children: "Are you going?" }), _jsx("div", { className: "wtcal-rsvp-answers", children: ANSWERS.map((answer) => {
88
+ const chosen = mine?.participationStatus === answer.value;
89
+ return (_jsx(Button, { kind: chosen ? 'primary' : 'default', "aria-pressed": chosen, busy: answering === answer.value, disabled: answering !== null, onPress: () => void respond(answer.value), children: answer.label }, answer.value));
90
+ }) }), _jsx("p", { className: "wtcal-rsvp-note", children: "The organiser is told either way." }), failure !== null && (_jsx("p", { className: "wtcal-failure", role: "alert", children: failure }))] })), event.status === 'cancelled' && _jsx(Pill, { tone: "bad", children: "Cancelled" }), event.status === 'tentative' && _jsx(Pill, { tone: "warn", children: "Tentative" }), event.location !== undefined && (_jsxs("section", { className: "wtcal-detail-section", children: [_jsx("h3", { className: "wtcal-detail-label", children: "Where" }), _jsx("p", { className: "wtcal-detail-text", children: event.location })] })), event.description !== undefined && (_jsxs("section", { className: "wtcal-detail-section", children: [_jsx("h3", { className: "wtcal-detail-label", children: "Notes" }), _jsx("p", { className: "wtcal-detail-text", children: event.description })] })), participants.length > 0 && (_jsxs("section", { className: "wtcal-detail-section", children: [_jsxs("h3", { className: "wtcal-detail-label", children: [participants.length, " invited"] }), _jsx("ul", { className: "wtcal-detail-people", children: participants.map((participant) => (_jsx("li", { children: _jsx(Identity, { kind: "line", size: "sm", name: participant.name ?? null, address: addressOf(participant), aside: participant.participationStatus !== undefined && (_jsx(Pill, { quiet: true, tone: STATUS_TONE[participant.participationStatus], children: STATUS_WORD[participant.participationStatus] })) }) }, participant.calendarAddress))) })] })), _jsx("footer", { className: "wtcal-detail-actions", children: _jsx(Button, { kind: "primary", onPress: onEdit, children: "Edit event" }) })] }));
91
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The event editor: create, edit and delete a person's own events, recurring
3
+ * included (MSG-055, https://github.com/wtfalch/messaging/issues/158).
4
+ *
5
+ * Two things here are decisions rather than plumbing.
6
+ *
7
+ * **A recurring edit asks which.** Editing an occurrence of a series can mean
8
+ * two different things, and a calendar that guesses is a calendar that quietly
9
+ * moves eleven other meetings. So when the event being edited belongs to a
10
+ * series, saving and deleting both go through an explicit choice, and the
11
+ * choice has no default.
12
+ *
13
+ * **Sending mail is its own decision.** Adding somebody to an event and
14
+ * telling them about it are two different acts. `sendSchedulingMessages`
15
+ * defaults to false in the client for exactly that reason, and the control
16
+ * here defaults to off with it: Save changes the event, and only the checkbox
17
+ * sends anyone mail. A calendar that mails eleven people because somebody
18
+ * fixed a typo in a title is a calendar people stop trusting.
19
+ *
20
+ * `@wtfalch/design` is an optional peer, the same way `react` is: the
21
+ * framework-free `./calendar` export never reaches this file.
22
+ */
23
+ import type { CalendarEvent, CalendarEventDraft } from '../types.ts';
24
+ import { type AvailabilityLookup } from './AvailabilityRibbon.tsx';
25
+ /** Which copies of a recurring event an edit or a delete applies to. There is
26
+ * no default: the person says, every time. */
27
+ export type RecurrenceScope = 'occurrence' | 'series';
28
+ export type EventEditorProps = {
29
+ /** The event being changed, or `undefined` to create one. */
30
+ event?: CalendarEvent;
31
+ /** Where a new event starts, when the person made one by picking a slot.
32
+ * Falls back to `now`, never to the machine clock: `Calendar` may be told
33
+ * what "now" is, and a new event that lands an hour after the real time
34
+ * while the grid shows a different week is a bug nobody reports twice. */
35
+ initialStart?: Date;
36
+ /** The calendar's own idea of now. */
37
+ now: Date;
38
+ /** The calendar a new event lands on. */
39
+ calendarId: string;
40
+ /** True below the design system's small breakpoint, where the editor is a
41
+ * bottom sheet rather than a centred window. */
42
+ compact: boolean;
43
+ /** `notify` is the person's answer to "tell everyone?", never inferred.
44
+ * It rides through to `sendSchedulingMessages` unchanged. */
45
+ onSave: (draft: CalendarEventDraft, scope: RecurrenceScope | null, notify: boolean) => Promise<void>;
46
+ onDelete?: (scope: RecurrenceScope | null, notify: boolean) => Promise<void>;
47
+ onClose: () => void;
48
+ /** How to ask when the participants are busy. Absent when the surrounding
49
+ * app gave no way to ask, and the ribbon then does not draw at all. */
50
+ availability?: AvailabilityLookup;
51
+ };
52
+ export declare function EventEditor({ event, initialStart, now, calendarId, compact, onSave, onDelete, onClose, availability, }: EventEditorProps): import("react").JSX.Element;