@open-webapp/calendar 0.12.0 → 0.14.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.
- package/README.md +119 -1
- package/dist/core/events.d.ts +3 -0
- package/dist/core/events.js +19 -0
- package/dist/core/types.d.ts +10 -0
- package/dist/react/CalendarPane.d.ts +17 -0
- package/dist/react/CalendarPane.js +152 -31
- package/dist/react/EventDetails.d.ts +13 -0
- package/dist/react/EventDetails.js +89 -0
- package/dist/react/detailsText.d.ts +14 -0
- package/dist/react/detailsText.js +44 -0
- package/dist/react/inviteeUtils.d.ts +3 -0
- package/dist/react/inviteeUtils.js +30 -0
- package/dist/styles.css +178 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Multi-account Google Calendar read-only sync (controller) plus React UI (`CalendarPane`, `CalendarSelector`). Storage and encryption are host-supplied adapters.
|
|
4
4
|
|
|
5
|
+
> **0.14.0 is additive and non-breaking.** The event details overlay is redesigned, and the optional `onRsvpChange` prop lets the host write RSVP changes. See [0.14.0](#0140-minor-additive-non-breaking).
|
|
6
|
+
>
|
|
7
|
+
> **0.13.0 is BREAKING.** Clicking an event title now opens an in-pane event details overlay instead of a popup window. See [0.13.0](#0130-breaking-pre-10-minor).
|
|
8
|
+
>
|
|
5
9
|
> **0.12.0 is BREAKING.** See [0.12.0](#0120-breaking-pre-10-minor) for exclusive Unaccepted filtering and new RSVP defaults.
|
|
6
10
|
>
|
|
7
11
|
> **0.10.0 is BREAKING.** See [0.10.0](#0100-breaking-pre-10-minor) for the approved CalendarPane selector-popup geometry correction.
|
|
@@ -160,7 +164,96 @@ Call at top level of a vitest file; it registers a `describe('StorageAdapter con
|
|
|
160
164
|
| `emptyState?` | `ReactNode` | replaces the built-in not-connected block |
|
|
161
165
|
| `sourceNotice?` | `(source) => ReactNode` | per-source slot, rendered for `needs-scope` sources (e.g. re-consent button); without it the built-in reauth block is shown |
|
|
162
166
|
| `onClose?` | `() => void` | |
|
|
163
|
-
| `popupName?` | `string` | `window.open` name for the event popup (default `notesdiary-cal-event`) |
|
|
167
|
+
| `popupName?` | `string` | `window.open` name for the event popup window (default `notesdiary-cal-event`). The popup now opens only from the overlay's "Open in Google Calendar" link |
|
|
168
|
+
| `onRsvpChange?` | `(event: CalendarEvent, status: RsvpStatus) => Promise<void>` | 0.14.0. Host-owned RSVP writer. When absent, the overlay has no "Change RSVP" row. The package never writes to Google itself. See [Change RSVP](#change-rsvp-onrsvpchange) |
|
|
169
|
+
|
|
170
|
+
#### Event details overlay
|
|
171
|
+
|
|
172
|
+
A plain left click on an event title opens a bottom-sheet overlay inside the pane (`role="dialog"`, `aria-modal="true"`). The sheet is laid out like the event card, but larger, top to bottom:
|
|
173
|
+
|
|
174
|
+
1. Top row, same information as the card: time range (or `All day`), Join (only when `joinUrl` is set), a read-only RSVP status, and the close (×) button.
|
|
175
|
+
2. Title (the dialog's accessible name, an `h2`).
|
|
176
|
+
3. Organizer row: the label "Organizer", the organizer label, and "(you)" when `organizer.self` is true. Hidden when there is no organizer label.
|
|
177
|
+
4. Calendar line: calendar color dot, calendar name, source (account) label, and location when set.
|
|
178
|
+
5. Description: plain text (HTML is stripped), with links kept clickable.
|
|
179
|
+
6. Invitees (see [Invitee rules](#invitee-rules)).
|
|
180
|
+
7. Change RSVP (see [Change RSVP](#change-rsvp-onrsvpchange)).
|
|
181
|
+
8. "Open in Google Calendar" link (only when `htmlLink` is set).
|
|
182
|
+
|
|
183
|
+
- Close with Escape, the close (X) button, or a click on the backdrop. Focus is trapped inside the sheet while it is open, starts on the sheet, and returns to the title that opened it when it closes.
|
|
184
|
+
- Modified clicks (ctrl, cmd, shift, alt, or middle click) keep the native new-tab behavior of the title link.
|
|
185
|
+
- Events without an `htmlLink` still open the overlay. The "Open in Google Calendar" link is hidden for them.
|
|
186
|
+
- There is no prop to opt out. Hosts that relied on the title click opening a popup window must use the overlay's link or handle the click themselves.
|
|
187
|
+
- The time-range formatting is the same as the event card's.
|
|
188
|
+
|
|
189
|
+
##### Invitee rules
|
|
190
|
+
|
|
191
|
+
- The heading reads `Invitees (N)`, where N is the total number of attendees.
|
|
192
|
+
- The summary line counts each status: `yes` (accepted), `maybe` (tentative), `awaiting` (needs action, and any unknown status), `no` (declined), joined with ` · `. Zero buckets are omitted, so the summary reads, for example, `2 yes · 1 maybe · 1 awaiting`. An empty attendee list gives an empty summary.
|
|
193
|
+
- Order: the organizer first, then you (self), then accepted, tentative, needs action, declined. Within each status, rows sort by name (display name, else email), case-insensitively. An organizer who is also you appears once, first.
|
|
194
|
+
- Tags: `Organizer` on the organizer's row and `(you)` on your row. Every row shows its status glyph and label (Accepted, Maybe, Declined, Unaccepted). An attendee without a display name shows the email.
|
|
195
|
+
- At most 10 rows show at first. A `Show all N` button expands the list in place and changes to `Show fewer`. It sets `aria-expanded`.
|
|
196
|
+
|
|
197
|
+
##### Hidden-row matrix
|
|
198
|
+
|
|
199
|
+
| Case | Invitees | Change RSVP | Organizer row |
|
|
200
|
+
| --- | --- | --- | --- |
|
|
201
|
+
| No attendees | hidden | hidden | shown when there is an organizer label |
|
|
202
|
+
| Only you are listed | hidden | hidden | shown when there is an organizer label |
|
|
203
|
+
| You are not invited (no attendee is `self`) | shown | hidden | shown when there is an organizer label |
|
|
204
|
+
| Invited, no `onRsvpChange` | shown | hidden | shown when there is an organizer label |
|
|
205
|
+
| Invited, `onRsvpChange` provided | shown | shown | shown when there is an organizer label |
|
|
206
|
+
|
|
207
|
+
##### Change RSVP (`onRsvpChange`)
|
|
208
|
+
|
|
209
|
+
`onRsvpChange` is an optional prop on `CalendarPane`. The host does the write; the package makes no Google request for it and asks for no new OAuth scopes. Recurring events are handled per instance: the `event` passed to the host is the instance the user opened.
|
|
210
|
+
|
|
211
|
+
- The row is a radiogroup labeled "Change RSVP" with three options: Yes (accepted), Maybe (tentative), and No (declined). Unaccepted is not offered. Each option is a radio with `aria-checked`. Arrow keys move between options. The row shows only when the prop is set, you are an attendee, and the event has attendees.
|
|
212
|
+
- Choosing an option calls `onRsvpChange(event, status)` once. Choosing the already selected option still calls it, so a host can rely on one call per click.
|
|
213
|
+
- Optimistic update: the overlay and the event card show the new status at once. The options are disabled while the write is pending, and a live region reads "Updating RSVP...".
|
|
214
|
+
- Success: the override stays until a controller refresh delivers that event, so the server's status takes over then. If the new status is hidden by the RSVP filter chips, the overlay stays open, and the card leaves the list only after the overlay closes. Changing filter chips still closes the overlay, as before.
|
|
215
|
+
- Failure: if the promise rejects or throws, or does not settle within **60 seconds** (`RSVP_PENDING_TIMEOUT_MS = 60000`), the previous status comes back and the live region shows "Couldn't update RSVP. Retry". Retry sends the last chosen status again. A result that arrives after the timeout is ignored. The timer is not cleared by closing the overlay, so a timed-out write still rolls back. In that case no error message shows, because the overlay is closed.
|
|
216
|
+
- The overlay's status and the card's status come from the same override, so both change together.
|
|
217
|
+
|
|
218
|
+
Host example. The host owns the token and the Google request. Fetch the event, change only your own attendee entry, then patch the attendee list:
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
<CalendarPane
|
|
222
|
+
// ...other props
|
|
223
|
+
onRsvpChange={async (event, status) => {
|
|
224
|
+
const token = await getAccessToken(event.sourceId); // host-owned token
|
|
225
|
+
const calendarId = encodeURIComponent(event.calendarId ?? 'primary');
|
|
226
|
+
const eventUrl = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/${encodeURIComponent(event.id)}`;
|
|
227
|
+
const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' };
|
|
228
|
+
|
|
229
|
+
const current = await fetch(eventUrl, { headers }).then((r) => {
|
|
230
|
+
if (!r.ok) throw new Error(`GET event failed: ${r.status}`);
|
|
231
|
+
return r.json();
|
|
232
|
+
});
|
|
233
|
+
const attendees = (current.attendees ?? []).map((a: { self?: boolean; responseStatus?: string }) =>
|
|
234
|
+
a.self ? { ...a, responseStatus: status } : a,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const res = await fetch(`${eventUrl}?sendUpdates=all`, {
|
|
238
|
+
method: 'PATCH',
|
|
239
|
+
headers,
|
|
240
|
+
body: JSON.stringify({ attendees }),
|
|
241
|
+
});
|
|
242
|
+
if (!res.ok) throw new Error(`PATCH event failed: ${res.status}`); // rejects, so the overlay rolls back
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Google's `responseStatus` values match `RsvpStatus` for the three options (`accepted`, `tentative`, `declined`). Choose `sendUpdates` to match your notification policy.
|
|
248
|
+
|
|
249
|
+
##### Footer-safe overlay
|
|
250
|
+
|
|
251
|
+
- When the pane renders its footer (`.calendar-pane--has-footer`, which needs calendars), the backdrop and sheet stop at the footer's top edge. The footer stays visible, undimmed, and clickable. Without a footer, the overlay covers the whole pane.
|
|
252
|
+
- The footer height comes from `--calendar-footer-height` (default `64px`). If the host changes the footer height, set this variable on `.calendar-pane` to match.
|
|
253
|
+
- The sheet's maximum height is 80% of the area above the footer, and it scrolls internally.
|
|
254
|
+
- A click on the footer while the overlay is open closes the overlay, and the footer action still runs (for example, the calendar dropdown opens). Focus does not return to the title in that case, because the footer action takes focus.
|
|
255
|
+
|
|
256
|
+
`CalendarEvent` gains optional fields used by the overlay: `location?: string`, `description?: string` (HTML is converted to plain text for display), and `attendees?: CalendarEventAttendee[]`, where `CalendarEventAttendee` is `{ email: string; displayName?: string; responseStatus: RsvpStatus; self?: boolean; organizer?: boolean }`. Missing fields are simply not shown.
|
|
164
257
|
|
|
165
258
|
#### RSVP chips
|
|
166
259
|
|
|
@@ -231,10 +324,35 @@ Day ribbon styling: each day's ribbon alternates between two tones by day parity
|
|
|
231
324
|
|
|
232
325
|
The Unaccepted count badge uses `.calendar-rsvp-chip-badge`, with light and dark styling included in `styles.css`.
|
|
233
326
|
|
|
327
|
+
Event details overlay (0.13.0, footer-safe and redesigned in 0.14.0): `.calendar-event-details` is the backdrop (absolutely positioned inside the pane root, dimmed, bottom-aligned). In a pane with a footer, `.calendar-pane--has-footer > .calendar-event-details` sets `bottom: var(--calendar-footer-height)` so the footer is not covered. `.calendar-event-details-sheet` is the bottom sheet (max 80% of the area above the footer, scrolls internally). Both use the pane's palette tokens, so they follow the pane's `theme`. The overlay is positioned against the nearest positioned ancestor, so the pane root must stay positioned.
|
|
328
|
+
|
|
329
|
+
Overlay hooks (0.14.0). Layout: `-grabber`, `-toprow`, `-time`, `-close`, `-header`, `-title`, `-dot`, `-body`. Sections: `-organizer`, `-calendar`, `-location` (span inside `-calendar`), `-description`, `-invitees` (contains `h3`, `-invitee-summary`, `ul`/`li`), `-tag` (Organizer and (you) tags), `-rsvp` (contains `[role='radiogroup']`, `[role='radio']` with `aria-checked`, and `-rsvp-status` for the live region), `-open`. The per-row status pill uses the shared `.calendar-event-rsvp` and `.calendar-event-rsvp--{status}` classes. The 0.13.0 `-when`, `-actions` and `-attendees` section classes are no longer rendered. Disabled RSVP options carry the native `disabled` attribute and the `:disabled` style.
|
|
330
|
+
|
|
331
|
+
The `--calendar-footer-height` variable is the one host value the overlay reads. Keep it equal to the host's footer height when the footer is changed.
|
|
332
|
+
|
|
234
333
|
The shared `.calendar-selector-trigger` uses border-box inline-flex, centered alignment, an 8px gap, 36px minimum height, 8px 12px padding, 6px radius, a 1px solid control border, inherited font and pointer cursor. `.calendar-selector-trigger-label` bounds long labels with ellipsis; `.calendar-selector-chevron` stays 12px and does not shrink or add a tab stop. Existing scoped surface/text/control-border tokens style the resting trigger, the hover token supplies its hover background, and the focus token supplies a 2px `:focus-visible` outline with 2px offset. The default 64px footer and 6px upward clearance remain unchanged. Only pane dropdowns use the approved trigger-left, pane-inset and available-height exception; standalone selectors retain their existing right-aligned 220px-to-320px geometry and 240px options cap. Import the shipped stylesheet for both footer and standalone use.
|
|
235
334
|
|
|
236
335
|
Done, Select all and Clear use the approved action-only flat styling via `.calendar-selector-actions > button` in standalone and grouped footer dropdowns: transparent resting background, zero border, no shadow, inherited font, `--calendar-selector-text` color and pointer cursor. Hover uses `--calendar-hover`; pointer focus has no decorative outline, while keyboard `:focus-visible` uses a 2px solid `--calendar-focus` outline with 2px offset. Action padding, row flex layout and 8px gap/top/bottom margins, footer/dropdown geometry, trigger/search/option styling, other native controls and all selection, callback and focus-return contracts are preserved.
|
|
237
336
|
|
|
337
|
+
## 0.14.0 (minor, additive, non-breaking)
|
|
338
|
+
|
|
339
|
+
- Additive only. No existing prop, return value, thrown error, storage field or contract test changed. No migration is required. The version bump is 0.13.0 to 0.14.0.
|
|
340
|
+
- Event details overlay redesigned: a top row matching the card (time or `All day`, Join, read-only RSVP status, close), then title, Organizer, calendar and location, description, Invitees, Change RSVP, and "Open in Google Calendar".
|
|
341
|
+
- Invitees section: `Invitees (N)`, a summary line (`yes`, `maybe`, `awaiting`, `no`), and a sorted list with Organizer and (you) tags. Ten rows show first, with a `Show all N` button that expands in place.
|
|
342
|
+
- New optional `onRsvpChange?: (event, status) => Promise<void>` prop on `CalendarPane`. The host performs the Google write with its own token. The package makes no Google write and requests no new scopes. Without the prop, the overlay has no Change RSVP row.
|
|
343
|
+
- RSVP changes are optimistic: the overlay and card update at once. A rejected or timed-out (60 seconds) write rolls back and shows "Couldn't update RSVP. Retry", with Retry resending the last status.
|
|
344
|
+
- The overlay is footer-safe. With a footer rendered, the footer stays visible and clickable above the overlay, and the overlay height is limited by `--calendar-footer-height`.
|
|
345
|
+
- New and renamed overlay CSS hooks are listed under [Host CSS](#host-css). `-when`, `-actions` and `-attendees` are no longer rendered.
|
|
346
|
+
|
|
347
|
+
## 0.13.0 (BREAKING pre-1.0 minor)
|
|
348
|
+
|
|
349
|
+
- Plain left click on an event title opens an in-pane event details overlay (bottom sheet, `role="dialog"`, `aria-modal`) instead of the event popup window. It closes with Escape, the X button or the backdrop, traps focus while open and returns focus to the title on close.
|
|
350
|
+
- The overlay shows time, calendar, organizer, Join and RSVP, location, plain-text description, and the first 10 attendees, with an "Open in Google Calendar" link.
|
|
351
|
+
- The `popupName` popup window now opens only from that link. Modified clicks (ctrl/cmd/shift/alt/middle) keep the native new-tab behavior. Events without `htmlLink` open the overlay too.
|
|
352
|
+
- `CalendarEvent` gains optional `location`, `description` and `attendees` (`CalendarEventAttendee[]`). Existing rows without them still read.
|
|
353
|
+
- New host CSS hooks: `.calendar-event-details` and `.calendar-event-details-sheet`.
|
|
354
|
+
- Breaking for hosts relying on the title click opening a popup. There is no opt-out prop. No storage migration is required.
|
|
355
|
+
|
|
238
356
|
## 0.12.0 (BREAKING pre-1.0 minor)
|
|
239
357
|
|
|
240
358
|
- Unaccepted (O) is again an exclusive `needsAction` shortcut. It saves the current RSVP selection when enabled and restores it when disabled; it is no longer an independent toggle.
|
package/dist/core/events.d.ts
CHANGED
package/dist/core/events.js
CHANGED
|
@@ -212,6 +212,22 @@ export function extractJoinUrl(raw) {
|
|
|
212
212
|
const desc = typeof raw.description === 'string' ? raw.description.match(JOIN_URL_REGEX) : null;
|
|
213
213
|
return desc ? desc[0] : null;
|
|
214
214
|
}
|
|
215
|
+
function parseAttendees(raw) {
|
|
216
|
+
if (!Array.isArray(raw))
|
|
217
|
+
return undefined;
|
|
218
|
+
return raw
|
|
219
|
+
.filter((a) => a && typeof a === 'object')
|
|
220
|
+
.map((a) => ({
|
|
221
|
+
email: typeof a.email === 'string' ? a.email : '',
|
|
222
|
+
displayName: typeof a.displayName === 'string' ? a.displayName : undefined,
|
|
223
|
+
responseStatus: a.responseStatus === 'accepted' || a.responseStatus === 'tentative' ||
|
|
224
|
+
a.responseStatus === 'declined' || a.responseStatus === 'needsAction'
|
|
225
|
+
? a.responseStatus
|
|
226
|
+
: 'needsAction',
|
|
227
|
+
self: typeof a.self === 'boolean' ? a.self : undefined,
|
|
228
|
+
organizer: typeof a.organizer === 'boolean' ? a.organizer : undefined,
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
215
231
|
/** Parses a raw Google Calendar event. Returns null for cancelled/malformed input; never throws. */
|
|
216
232
|
export function parseEvent(raw, ctx) {
|
|
217
233
|
try {
|
|
@@ -239,6 +255,9 @@ export function parseEvent(raw, ctx) {
|
|
|
239
255
|
self: Boolean(raw.organizer?.self),
|
|
240
256
|
},
|
|
241
257
|
htmlLink: raw.htmlLink ?? '',
|
|
258
|
+
location: typeof raw.location === 'string' ? raw.location : undefined,
|
|
259
|
+
description: typeof raw.description === 'string' ? raw.description : undefined,
|
|
260
|
+
attendees: parseAttendees(raw.attendees),
|
|
242
261
|
};
|
|
243
262
|
}
|
|
244
263
|
catch {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -29,6 +29,16 @@ export interface CalendarEvent {
|
|
|
29
29
|
self: boolean;
|
|
30
30
|
};
|
|
31
31
|
htmlLink: string;
|
|
32
|
+
location?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
attendees?: CalendarEventAttendee[];
|
|
35
|
+
}
|
|
36
|
+
export interface CalendarEventAttendee {
|
|
37
|
+
email: string;
|
|
38
|
+
displayName?: string;
|
|
39
|
+
responseStatus: RsvpStatus;
|
|
40
|
+
self?: boolean;
|
|
41
|
+
organizer?: boolean;
|
|
32
42
|
}
|
|
33
43
|
export interface CalendarInfo {
|
|
34
44
|
id: string;
|
|
@@ -20,5 +20,22 @@ export interface CalendarPaneProps {
|
|
|
20
20
|
onReconnect?: () => void;
|
|
21
21
|
/** Window name used for the event popup. */
|
|
22
22
|
popupName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Optional host-provided RSVP writer. When present, the event details overlay shows a
|
|
25
|
+
* "Change RSVP" row. The package never writes to Google itself; the host performs the write.
|
|
26
|
+
*/
|
|
27
|
+
onRsvpChange?: (event: CalendarEvent, status: RsvpStatus) => Promise<void>;
|
|
23
28
|
}
|
|
29
|
+
export declare const RSVP_PENDING_TIMEOUT_MS = 60000;
|
|
30
|
+
export declare const RSVP_CHIPS: {
|
|
31
|
+
status: RsvpStatus;
|
|
32
|
+
label: string;
|
|
33
|
+
path: string;
|
|
34
|
+
}[];
|
|
35
|
+
export declare function RsvpGlyph({ path, size, strokeWidth }: {
|
|
36
|
+
path: string;
|
|
37
|
+
size?: number;
|
|
38
|
+
strokeWidth?: number;
|
|
39
|
+
}): import("react").JSX.Element;
|
|
40
|
+
export declare function formatTimeRange(event: CalendarEvent): string;
|
|
24
41
|
export declare function CalendarPane(props: CalendarPaneProps): import("react").JSX.Element;
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { filterByRsvp, groupByDay, getOrganizerLabel, formatDayHeader, formatRibbonLabel, isEventCurrent, findNextUpcomingEvent, getCalendarEventKey, DEFAULT_RSVP_STATUSES, } from '../core/events.js';
|
|
4
4
|
import { GroupedCalendarSelector } from './CalendarSelector.js';
|
|
5
|
+
import { EventDetails } from './EventDetails.js';
|
|
5
6
|
function nextRsvpSelection(selection, status, saved) {
|
|
6
7
|
const isUnacceptedOnly = selection.size === 1 && selection.has('needsAction');
|
|
7
8
|
if (status === 'needsAction') {
|
|
@@ -24,17 +25,9 @@ function nextRsvpSelection(selection, status, saved) {
|
|
|
24
25
|
}
|
|
25
26
|
return { next: next.size === 0 ? new Set(DEFAULT_RSVP_STATUSES) : next, saved: null };
|
|
26
27
|
}
|
|
27
|
-
function useWindowWidth() {
|
|
28
|
-
const [width, setWidth] = useState(typeof window !== 'undefined' ? window.innerWidth : 1024);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const handler = () => setWidth(window.innerWidth);
|
|
31
|
-
window.addEventListener('resize', handler);
|
|
32
|
-
return () => window.removeEventListener('resize', handler);
|
|
33
|
-
}, []);
|
|
34
|
-
return width;
|
|
35
|
-
}
|
|
36
28
|
const SOURCE_COLORS = ['#4285f4', '#ea4335', '#34a853', '#fbbc04', '#a142f4', '#00acc1', '#ff7043', '#8d6e63'];
|
|
37
|
-
const
|
|
29
|
+
export const RSVP_PENDING_TIMEOUT_MS = 60000;
|
|
30
|
+
export const RSVP_CHIPS = [
|
|
38
31
|
{
|
|
39
32
|
status: 'accepted',
|
|
40
33
|
label: 'Accepted',
|
|
@@ -56,7 +49,7 @@ const RSVP_CHIPS = [
|
|
|
56
49
|
path: 'M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z',
|
|
57
50
|
},
|
|
58
51
|
];
|
|
59
|
-
function RsvpGlyph({ path, size = 16, strokeWidth = 2.2 }) {
|
|
52
|
+
export function RsvpGlyph({ path, size = 16, strokeWidth = 2.2 }) {
|
|
60
53
|
return (_jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: path, stroke: "currentColor", strokeWidth: strokeWidth, strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
61
54
|
}
|
|
62
55
|
function RsvpStatusIcon({ status }) {
|
|
@@ -106,7 +99,7 @@ function formatTimeOfDay(dateTime) {
|
|
|
106
99
|
const d = new Date(dateTime);
|
|
107
100
|
return d.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
108
101
|
}
|
|
109
|
-
function formatTimeRange(event) {
|
|
102
|
+
export function formatTimeRange(event) {
|
|
110
103
|
const startDateTime = event.start.dateTime;
|
|
111
104
|
const endDateTime = event.end.dateTime;
|
|
112
105
|
if (!startDateTime)
|
|
@@ -123,7 +116,6 @@ function usableUrl(url) {
|
|
|
123
116
|
return trimmed === '' ? null : trimmed;
|
|
124
117
|
}
|
|
125
118
|
export function CalendarPane(props) {
|
|
126
|
-
const isDesktop = useWindowWidth() >= 960;
|
|
127
119
|
const { sources, controller, selectedRsvpStatuses, theme = 'system' } = props;
|
|
128
120
|
const popupName = props.popupName ?? DEFAULT_POPUP_NAME;
|
|
129
121
|
const [version, setVersion] = useState(0);
|
|
@@ -137,7 +129,44 @@ export function CalendarPane(props) {
|
|
|
137
129
|
void Promise.resolve(controller.hydrate()).catch(() => { });
|
|
138
130
|
}, [controller]);
|
|
139
131
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
140
|
-
const
|
|
132
|
+
const serverEvents = useMemo(() => controller.getEvents(), [controller, version]);
|
|
133
|
+
const [overrides, setOverrides] = useState(() => new Map());
|
|
134
|
+
const events = useMemo(() => overrides.size === 0
|
|
135
|
+
? serverEvents
|
|
136
|
+
: serverEvents.map((e) => {
|
|
137
|
+
const o = overrides.get(getCalendarEventKey(e));
|
|
138
|
+
return o ? { ...e, selfResponseStatus: o } : e;
|
|
139
|
+
}), [serverEvents, overrides]);
|
|
140
|
+
const [rsvpPending, setRsvpPending] = useState(false);
|
|
141
|
+
const [rsvpError, setRsvpError] = useState(false);
|
|
142
|
+
const rsvpPendingRef = useRef(false);
|
|
143
|
+
const rsvpTimerRef = useRef(null);
|
|
144
|
+
const mountedRef = useRef(true);
|
|
145
|
+
const detailKeyRef = useRef(null);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
mountedRef.current = true;
|
|
148
|
+
return () => {
|
|
149
|
+
mountedRef.current = false;
|
|
150
|
+
if (rsvpTimerRef.current)
|
|
151
|
+
clearTimeout(rsvpTimerRef.current);
|
|
152
|
+
};
|
|
153
|
+
}, []);
|
|
154
|
+
// Server truth wins: a refresh delivering a key clears its override.
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
setOverrides((prev) => {
|
|
157
|
+
if (prev.size === 0)
|
|
158
|
+
return prev;
|
|
159
|
+
const keys = new Set(serverEvents.map(getCalendarEventKey));
|
|
160
|
+
const next = new Map(prev);
|
|
161
|
+
let changed = false;
|
|
162
|
+
for (const k of prev.keys())
|
|
163
|
+
if (keys.has(k)) {
|
|
164
|
+
next.delete(k);
|
|
165
|
+
changed = true;
|
|
166
|
+
}
|
|
167
|
+
return changed ? next : prev;
|
|
168
|
+
});
|
|
169
|
+
}, [serverEvents]);
|
|
141
170
|
const statuses = controller.getSourceStatus();
|
|
142
171
|
const connected = props.connected ?? sources.length > 0;
|
|
143
172
|
const ctrlState = typeof controller.getState === 'function'
|
|
@@ -160,13 +189,109 @@ export function CalendarPane(props) {
|
|
|
160
189
|
const didMountRsvpRef = useRef(false);
|
|
161
190
|
const savedRsvpRef = useRef(null);
|
|
162
191
|
const [now, setNow] = useState(() => new Date());
|
|
192
|
+
const [detail, setDetail] = useState(null);
|
|
193
|
+
const detailKey = detail ? getCalendarEventKey(detail.snapshot) : null;
|
|
194
|
+
detailKeyRef.current = detailKey;
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
setRsvpPending(false);
|
|
197
|
+
setRsvpError(false);
|
|
198
|
+
}, [detailKey]);
|
|
199
|
+
function handleRsvpChange(_event, status) {
|
|
200
|
+
const onRsvpChange = props.onRsvpChange;
|
|
201
|
+
const raw = detail?.snapshot;
|
|
202
|
+
if (!onRsvpChange || !raw || rsvpPendingRef.current)
|
|
203
|
+
return;
|
|
204
|
+
const key = getCalendarEventKey(raw);
|
|
205
|
+
const rollback = () => setOverrides((m) => {
|
|
206
|
+
if (!m.has(key))
|
|
207
|
+
return m;
|
|
208
|
+
const n = new Map(m);
|
|
209
|
+
n.delete(key);
|
|
210
|
+
return n;
|
|
211
|
+
});
|
|
212
|
+
let done = false;
|
|
213
|
+
const finish = (ok) => {
|
|
214
|
+
if (done)
|
|
215
|
+
return;
|
|
216
|
+
done = true;
|
|
217
|
+
if (rsvpTimerRef.current)
|
|
218
|
+
clearTimeout(rsvpTimerRef.current);
|
|
219
|
+
rsvpTimerRef.current = null;
|
|
220
|
+
rsvpPendingRef.current = false;
|
|
221
|
+
if (!mountedRef.current)
|
|
222
|
+
return;
|
|
223
|
+
if (!ok)
|
|
224
|
+
rollback();
|
|
225
|
+
if (detailKeyRef.current === key) {
|
|
226
|
+
setRsvpPending(false);
|
|
227
|
+
setRsvpError(!ok);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
rsvpPendingRef.current = true;
|
|
231
|
+
setRsvpPending(true);
|
|
232
|
+
setRsvpError(false);
|
|
233
|
+
setOverrides((m) => new Map(m).set(key, status));
|
|
234
|
+
rsvpTimerRef.current = setTimeout(() => finish(false), RSVP_PENDING_TIMEOUT_MS);
|
|
235
|
+
let p;
|
|
236
|
+
try {
|
|
237
|
+
p = Promise.resolve(onRsvpChange(raw, status));
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
p = Promise.reject(new Error('rsvp failed'));
|
|
241
|
+
}
|
|
242
|
+
p.then(() => finish(true), () => finish(false));
|
|
243
|
+
}
|
|
244
|
+
function closeDetail(returnFocus) {
|
|
245
|
+
const trigger = detail?.trigger;
|
|
246
|
+
setDetail(null);
|
|
247
|
+
if (returnFocus && trigger)
|
|
248
|
+
trigger.focus();
|
|
249
|
+
}
|
|
250
|
+
// Refresh with the same key updates the snapshot; a vanished key keeps the last snapshot.
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
if (detailKey === null)
|
|
253
|
+
return;
|
|
254
|
+
const fresh = serverEvents.find((e) => getCalendarEventKey(e) === detailKey);
|
|
255
|
+
if (fresh)
|
|
256
|
+
setDetail((d) => (d && d.snapshot !== fresh ? { ...d, snapshot: fresh } : d));
|
|
257
|
+
}, [serverEvents, detailKey]);
|
|
258
|
+
const selectionSignature = sources
|
|
259
|
+
.map((s) => `${s.id}:${[...controller.getSelectedIds(s.id)].sort().join(',')}`)
|
|
260
|
+
.join('|');
|
|
261
|
+
const rsvpSignature = [...selectedRsvpStatuses].sort().join(',');
|
|
262
|
+
const didMountFilterRef = useRef(false);
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
if (!didMountFilterRef.current) {
|
|
265
|
+
didMountFilterRef.current = true;
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
setDetail(null);
|
|
269
|
+
}, [selectionSignature, rsvpSignature]);
|
|
270
|
+
function renderTitle(event) {
|
|
271
|
+
const titleSpan = _jsx("span", { className: "calendar-event-title", children: event.summary });
|
|
272
|
+
if (usableUrl(event.htmlLink) !== null) {
|
|
273
|
+
return (_jsx("a", { className: "calendar-event-title-link", href: event.htmlLink, target: "_blank", rel: "noopener noreferrer", onClick: (e) => {
|
|
274
|
+
if (e.button === 0 && !e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey) {
|
|
275
|
+
e.preventDefault();
|
|
276
|
+
openDetail(e, event);
|
|
277
|
+
}
|
|
278
|
+
}, children: titleSpan }));
|
|
279
|
+
}
|
|
280
|
+
return (_jsx("button", { type: "button", className: "calendar-event-title-link", onClick: (e) => openDetail(e, event), children: titleSpan }));
|
|
281
|
+
}
|
|
282
|
+
function openDetail(e, event) {
|
|
283
|
+
setDetail({ snapshot: event, trigger: e.currentTarget });
|
|
284
|
+
}
|
|
163
285
|
useEffect(() => {
|
|
164
286
|
if (selectedRsvpStatuses.size !== 1 || !selectedRsvpStatuses.has('needsAction')) {
|
|
165
287
|
savedRsvpRef.current = null;
|
|
166
288
|
}
|
|
167
289
|
}, [selectedRsvpStatuses]);
|
|
168
290
|
const unacceptedCount = useMemo(() => events.filter((event) => event.selfResponseStatus === 'needsAction').length, [events]);
|
|
169
|
-
const filteredEvents = useMemo(() =>
|
|
291
|
+
const filteredEvents = useMemo(() => {
|
|
292
|
+
const visible = new Set(filterByRsvp(events, selectedRsvpStatuses));
|
|
293
|
+
return events.filter((e) => visible.has(e) || getCalendarEventKey(e) === detailKey);
|
|
294
|
+
}, [events, selectedRsvpStatuses, detailKey]);
|
|
170
295
|
const calendarsByKey = useMemo(() => {
|
|
171
296
|
const map = new Map();
|
|
172
297
|
for (const s of sources)
|
|
@@ -392,7 +517,7 @@ export function CalendarPane(props) {
|
|
|
392
517
|
const loading = ctrlState.loading && filteredEvents.length === 0;
|
|
393
518
|
const emptyStateText = 'No matching events in the next 30 days';
|
|
394
519
|
const showCalendarSelector = calendarSources.length > 0;
|
|
395
|
-
return (_jsxs("div", { className:
|
|
520
|
+
return (_jsxs("div", { className: `calendar-pane${showCalendarSelector ? ' calendar-pane--has-footer' : ''}`, "data-calendar-theme": theme, ref: paneRef, children: [_jsxs("div", { className: "calendar-pane-scroll", ref: scrollRef, children: [_jsxs("div", { className: "calendar-rsvp-chips", ref: chipsRef, children: [_jsx("div", { className: "calendar-rsvp-chip-group", role: "group", "aria-label": "RSVP Status Filters", children: RSVP_CHIPS.map((chip) => (_jsxs("button", { type: "button", className: `calendar-rsvp-chip${selectedRsvpStatuses.has(chip.status) ? ' selected' : ''}`, "aria-pressed": selectedRsvpStatuses.has(chip.status), "aria-label": chip.status === 'needsAction' ? `${chip.label} (${unacceptedCount})` : chip.label, title: chip.status === 'needsAction' ? `${chip.label} (${unacceptedCount})` : chip.label, onClick: () => handleToggle(chip.status), children: [_jsx(RsvpGlyph, { path: chip.path }), chip.status === 'needsAction' && unacceptedCount > 0 && (_jsx("span", { className: "calendar-rsvp-chip-badge", "aria-hidden": "true", children: unacceptedCount > 99 ? '99+' : unacceptedCount }))] }, chip.status))) }), _jsx("button", { type: "button", className: "calendar-today-btn", "aria-label": "Scroll to today", title: "Scroll to today", onClick: () => recenter('smooth'), children: "Today" })] }), needsScopeSources.map((s) => (_jsx("div", { children: props.sourceNotice?.(s) }, s.id))), error && (_jsx("div", { className: "empty-state calendar-empty-state", role: "alert", children: _jsx("p", { children: "Couldn't load calendar events. Try again shortly." }) })), !(error && filteredEvents.length === 0) && (_jsxs("div", { className: "calendar-day-groups", children: [dayGroups.map((group) => (_jsxs("div", { className: "calendar-day-group", children: [_jsx("div", { className: "calendar-day-header", ref: (el) => {
|
|
396
521
|
if (el) {
|
|
397
522
|
dayHeaderRefs.current.set(group.dateKey, el);
|
|
398
523
|
}
|
|
@@ -416,9 +541,8 @@ export function CalendarPane(props) {
|
|
|
416
541
|
? event.selfResponseStatus
|
|
417
542
|
: 'needsAction';
|
|
418
543
|
if (event.isAllDay) {
|
|
419
|
-
return (_jsxs("div", { className: `calendar-event-allday calendar-event-row--rsvp-${rsvpStatus}`, children: [_jsxs("div", { className: "calendar-event-header", children: [_jsx("span", { className: "calendar-event-time", children: "All day" }), _jsx(RsvpStatusIcon, { status: event.selfResponseStatus })] }), _jsxs("span", { className: "calendar-event-title-wrap", children: [
|
|
544
|
+
return (_jsxs("div", { className: `calendar-event-allday calendar-event-row--rsvp-${rsvpStatus}`, children: [_jsxs("div", { className: "calendar-event-header", children: [_jsx("span", { className: "calendar-event-time", children: "All day" }), _jsx(RsvpStatusIcon, { status: event.selfResponseStatus })] }), _jsxs("span", { className: "calendar-event-title-wrap", children: [renderTitle(event), props.renderEventAction?.(event)] }), showCalendarLabel && (_jsxs("span", { className: "calendar-event-calendar", children: [_jsx("span", { className: "calendar-event-calendar-dot", style: { backgroundColor: calendar.backgroundColor } }), calendar.summary] })), showOrganizerLabel && (_jsxs("span", { className: "calendar-event-organizer", children: [multi && (_jsx("span", { className: "calendar-event-source-dot", style: { backgroundColor: sourceColor(event.sourceId) } })), organizerText] }))] }, eventKey));
|
|
420
545
|
}
|
|
421
|
-
const hasLink = usableUrl(event.htmlLink) !== null;
|
|
422
546
|
return (_jsxs("div", { className: `calendar-event-row${currentEventKeys.has(eventKey) ? ' calendar-event-row--current' : ''}${selectedEventKey === eventKey ? ' calendar-event-row--selected' : ''} calendar-event-row--rsvp-${rsvpStatus}`, ref: (el) => {
|
|
423
547
|
if (el) {
|
|
424
548
|
timedEventRefs.current.set(eventKey, el);
|
|
@@ -426,18 +550,12 @@ export function CalendarPane(props) {
|
|
|
426
550
|
else {
|
|
427
551
|
timedEventRefs.current.delete(eventKey);
|
|
428
552
|
}
|
|
429
|
-
}, children: [_jsxs("div", { className: "calendar-event-header", children: [_jsx("span", { className: "calendar-event-time", children: formatTimeRange(event) }), _jsxs("div", { className: "calendar-event-actions", children: [event.joinUrl && (_jsx("a", { className: "calendar-event-join", href: event.joinUrl, target: "_blank", rel: "noopener noreferrer", onClick: (e) => e.stopPropagation(), children: "Join" })), _jsx(RsvpStatusIcon, { status: event.selfResponseStatus })] })] }), _jsxs("div", { className: "calendar-event-title-wrap", children: [
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
!e.altKey) {
|
|
436
|
-
e.preventDefault();
|
|
437
|
-
openEventPopup(event.htmlLink, popupRef, popupName);
|
|
438
|
-
}
|
|
439
|
-
}, children: _jsx("span", { className: "calendar-event-title", children: event.summary }) })) : (_jsx("span", { className: "calendar-event-title", children: event.summary })), props.renderEventAction?.(event)] }), showCalendarLabel && (_jsxs("span", { className: "calendar-event-calendar", children: [_jsx("span", { className: "calendar-event-calendar-dot", style: { backgroundColor: calendar.backgroundColor } }), calendar.summary] })), showOrganizerLabel && (_jsxs("span", { className: "calendar-event-organizer", children: [multi && (_jsx("span", { className: "calendar-event-source-dot", style: { backgroundColor: sourceColor(event.sourceId) } })), organizerText] }))] }, eventKey));
|
|
440
|
-
}) })] }))] }, group.dateKey))), loading && _jsx("p", { className: "calendar-empty-state-text", children: "Loading calendar\u2026" }), filteredEvents.length === 0 && !loading && !error && needsScopeSources.length === 0 && _jsx("p", { className: "calendar-empty-state-text", children: emptyStateText })] }))] }), showCalendarSelector && (_jsx("footer", { className: "calendar-pane-footer", children: _jsx(GroupedCalendarSelector, { theme: theme, groups: calendarSources.map((s) => ({
|
|
553
|
+
}, children: [_jsxs("div", { className: "calendar-event-header", children: [_jsx("span", { className: "calendar-event-time", children: formatTimeRange(event) }), _jsxs("div", { className: "calendar-event-actions", children: [event.joinUrl && (_jsx("a", { className: "calendar-event-join", href: event.joinUrl, target: "_blank", rel: "noopener noreferrer", onClick: (e) => e.stopPropagation(), children: "Join" })), _jsx(RsvpStatusIcon, { status: event.selfResponseStatus })] })] }), _jsxs("div", { className: "calendar-event-title-wrap", children: [renderTitle(event), props.renderEventAction?.(event)] }), showCalendarLabel && (_jsxs("span", { className: "calendar-event-calendar", children: [_jsx("span", { className: "calendar-event-calendar-dot", style: { backgroundColor: calendar.backgroundColor } }), calendar.summary] })), showOrganizerLabel && (_jsxs("span", { className: "calendar-event-organizer", children: [multi && (_jsx("span", { className: "calendar-event-source-dot", style: { backgroundColor: sourceColor(event.sourceId) } })), organizerText] }))] }, eventKey));
|
|
554
|
+
}) })] }))] }, group.dateKey))), loading && _jsx("p", { className: "calendar-empty-state-text", children: "Loading calendar\u2026" }), filteredEvents.length === 0 && !loading && !error && needsScopeSources.length === 0 && _jsx("p", { className: "calendar-empty-state-text", children: emptyStateText })] }))] }), showCalendarSelector && (_jsx("footer", { className: "calendar-pane-footer", onPointerDownCapture: () => {
|
|
555
|
+
// Close without preventDefault/stopPropagation so the footer action proceeds.
|
|
556
|
+
if (detail)
|
|
557
|
+
setDetail(null);
|
|
558
|
+
}, children: _jsx(GroupedCalendarSelector, { theme: theme, groups: calendarSources.map((s) => ({
|
|
441
559
|
id: s.id,
|
|
442
560
|
calendars: controller.getCalendars(s.id),
|
|
443
561
|
selectedIds: controller.getSelectedIds(s.id),
|
|
@@ -445,5 +563,8 @@ export function CalendarPane(props) {
|
|
|
445
563
|
void controller.setSelectedIds(s.id, ids);
|
|
446
564
|
},
|
|
447
565
|
heading: multi ? s.email : undefined,
|
|
448
|
-
})) }) }))
|
|
566
|
+
})) }) })), detail && (_jsx(EventDetails, { event: (() => {
|
|
567
|
+
const o = overrides.get(detailKey);
|
|
568
|
+
return o ? { ...detail.snapshot, selfResponseStatus: o } : detail.snapshot;
|
|
569
|
+
})(), onRsvpChange: props.onRsvpChange ? handleRsvpChange : undefined, pending: rsvpPending, error: rsvpError, calendar: calendarsByKey.get(`${detail.snapshot.sourceId}\u0000${detail.snapshot.calendarId}`), sourceLabel: multi ? sourceEmail(detail.snapshot.sourceId) : '', onClose: () => closeDetail(true), onOpenLink: (url) => openEventPopup(url, popupRef, popupName) }))] }));
|
|
449
570
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CalendarEvent, CalendarInfo, RsvpStatus } from '../core/types.js';
|
|
2
|
+
export interface EventDetailsProps {
|
|
3
|
+
event: CalendarEvent;
|
|
4
|
+
calendar?: CalendarInfo;
|
|
5
|
+
sourceLabel: string;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
onOpenLink: (url: string) => void;
|
|
8
|
+
onRsvpChange?: (event: CalendarEvent, status: RsvpStatus) => void | Promise<void>;
|
|
9
|
+
pending?: boolean;
|
|
10
|
+
error?: boolean | string;
|
|
11
|
+
onRetry?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function EventDetails({ event, calendar, sourceLabel, onClose, onOpenLink, onRsvpChange, pending, error, onRetry }: EventDetailsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { getOrganizerLabel } from '../core/events.js';
|
|
4
|
+
import { RSVP_CHIPS, RsvpGlyph, formatTimeRange } from './CalendarPane.js';
|
|
5
|
+
import { htmlToPlainText, linkifyText } from './detailsText.js';
|
|
6
|
+
import { sortInvitees, summarizeInvitees } from './inviteeUtils.js';
|
|
7
|
+
const RSVP_OPTIONS = [
|
|
8
|
+
{ status: 'accepted', label: 'Yes' },
|
|
9
|
+
{ status: 'tentative', label: 'Maybe' },
|
|
10
|
+
{ status: 'declined', label: 'No' },
|
|
11
|
+
];
|
|
12
|
+
const MAX_INVITEES = 10;
|
|
13
|
+
const FOCUSABLE = 'a[href],button:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
14
|
+
function rsvpOf(status) {
|
|
15
|
+
return RSVP_CHIPS.find((c) => c.status === status) ?? RSVP_CHIPS[3];
|
|
16
|
+
}
|
|
17
|
+
function Status({ status }) {
|
|
18
|
+
const g = rsvpOf(status);
|
|
19
|
+
return (_jsxs("span", { className: `calendar-event-rsvp calendar-event-rsvp--${g.status}`, children: [_jsx(RsvpGlyph, { path: g.path, size: 14, strokeWidth: 2.4 }), " ", g.label] }));
|
|
20
|
+
}
|
|
21
|
+
export function EventDetails({ event, calendar, sourceLabel, onClose, onOpenLink, onRsvpChange, pending, error, onRetry }) {
|
|
22
|
+
const sheetRef = useRef(null);
|
|
23
|
+
const lastStatus = useRef(null);
|
|
24
|
+
const [expanded, setExpanded] = useState(false);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
sheetRef.current?.focus();
|
|
27
|
+
}, []);
|
|
28
|
+
const time = event.isAllDay ? 'All day' : formatTimeRange(event);
|
|
29
|
+
const organizer = getOrganizerLabel(event);
|
|
30
|
+
const description = htmlToPlainText(event.description);
|
|
31
|
+
const attendees = event.attendees ?? [];
|
|
32
|
+
const onlySelf = attendees.length === 1 && !!attendees[0].self;
|
|
33
|
+
const showInvitees = attendees.length > 0 && !onlySelf;
|
|
34
|
+
const invited = attendees.some((a) => a.self);
|
|
35
|
+
const showRsvp = !!onRsvpChange && showInvitees && invited;
|
|
36
|
+
const sorted = showInvitees ? sortInvitees(attendees) : [];
|
|
37
|
+
const visible = expanded ? sorted : sorted.slice(0, MAX_INVITEES);
|
|
38
|
+
function choose(status) {
|
|
39
|
+
if (pending || !onRsvpChange)
|
|
40
|
+
return;
|
|
41
|
+
lastStatus.current = status;
|
|
42
|
+
void onRsvpChange(event, status);
|
|
43
|
+
}
|
|
44
|
+
function retry() {
|
|
45
|
+
if (onRetry)
|
|
46
|
+
onRetry();
|
|
47
|
+
else if (lastStatus.current)
|
|
48
|
+
choose(lastStatus.current);
|
|
49
|
+
}
|
|
50
|
+
function onRadioKeyDown(e) {
|
|
51
|
+
const dir = e.key === 'ArrowRight' || e.key === 'ArrowDown' ? 1 : e.key === 'ArrowLeft' || e.key === 'ArrowUp' ? -1 : 0;
|
|
52
|
+
if (!dir)
|
|
53
|
+
return;
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
const radios = Array.from(e.currentTarget.parentElement?.querySelectorAll('[role="radio"]') ?? []);
|
|
56
|
+
const i = radios.indexOf(e.currentTarget);
|
|
57
|
+
radios[(i + dir + radios.length) % radios.length]?.focus();
|
|
58
|
+
}
|
|
59
|
+
function onKeyDown(e) {
|
|
60
|
+
if (e.key === 'Escape') {
|
|
61
|
+
e.stopPropagation();
|
|
62
|
+
onClose();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (e.key !== 'Tab')
|
|
66
|
+
return;
|
|
67
|
+
const items = Array.from(sheetRef.current?.querySelectorAll(FOCUSABLE) ?? []);
|
|
68
|
+
if (items.length === 0)
|
|
69
|
+
return;
|
|
70
|
+
const first = items[0];
|
|
71
|
+
const last = items[items.length - 1];
|
|
72
|
+
const active = document.activeElement;
|
|
73
|
+
if (e.shiftKey && (active === first || active === sheetRef.current)) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
last.focus();
|
|
76
|
+
}
|
|
77
|
+
else if (!e.shiftKey && active === last) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
first.focus();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const checkedStatus = RSVP_OPTIONS.some((o) => o.status === event.selfResponseStatus)
|
|
83
|
+
? event.selfResponseStatus
|
|
84
|
+
: RSVP_OPTIONS[0].status;
|
|
85
|
+
return (_jsx("div", { className: "calendar-event-details", onClick: onClose, onKeyDown: onKeyDown, children: _jsxs("div", { ref: sheetRef, className: "calendar-event-details-sheet", role: "dialog", "aria-modal": "true", "aria-label": event.summary, tabIndex: -1, onClick: (e) => e.stopPropagation(), children: [_jsx("div", { className: "calendar-event-details-grabber", "aria-hidden": "true" }), _jsxs("div", { className: "calendar-event-details-toprow", children: [_jsx("span", { className: "calendar-event-details-time", children: time }), event.joinUrl && (_jsx("a", { href: event.joinUrl, target: "_blank", rel: "noopener noreferrer", children: "Join" })), _jsx(Status, { status: event.selfResponseStatus }), _jsx("button", { type: "button", className: "calendar-event-details-close", "aria-label": "Close", onClick: onClose, children: "\u00D7" })] }), _jsx("div", { className: "calendar-event-details-header", children: _jsx("h2", { className: "calendar-event-details-title", children: event.summary }) }), _jsxs("div", { className: "calendar-event-details-body", children: [organizer && (_jsxs("section", { className: "calendar-event-details-organizer", children: [_jsx("span", { children: "Organizer" }), " ", _jsx("span", { children: organizer }), event.organizer.self && _jsx("span", { children: " (you)" })] })), (calendar || sourceLabel || event.location) && (_jsxs("section", { className: "calendar-event-details-calendar", children: [_jsx("span", { className: "calendar-event-details-dot", "aria-hidden": "true", style: { background: calendar?.backgroundColor } }), calendar?.summary && _jsx("span", { children: calendar.summary }), sourceLabel && _jsxs("span", { children: [" ", sourceLabel] }), event.location && _jsxs("span", { className: "calendar-event-details-location", children: [" ", event.location] })] })), description && (_jsx("section", { className: "calendar-event-details-description", style: { whiteSpace: 'pre-wrap' }, children: linkifyText(description).map((t, i) => t.type === 'link' ? (_jsx("a", { href: t.href, target: "_blank", rel: "noopener noreferrer", children: t.text }, i)) : (_jsx("span", { children: t.text }, i))) })), showInvitees && (_jsxs("section", { className: "calendar-event-details-invitees", children: [_jsxs("h3", { children: ["Invitees (", attendees.length, ")"] }), _jsx("div", { className: "calendar-event-details-invitee-summary", children: summarizeInvitees(attendees) }), _jsx("ul", { children: visible.map((a, i) => (_jsxs("li", { children: [_jsx("span", { children: a.displayName || a.email }), a.organizer && _jsx("span", { className: "calendar-event-details-tag", children: " Organizer" }), a.self && _jsx("span", { className: "calendar-event-details-tag", children: " (you)" }), ' ', _jsx(Status, { status: a.responseStatus })] }, `${a.email}-${i}`))) }), sorted.length > MAX_INVITEES && (_jsx("button", { type: "button", "aria-expanded": expanded, onClick: () => setExpanded((v) => !v), children: expanded ? 'Show fewer' : `Show all ${sorted.length}` }))] })), showRsvp && (_jsxs("section", { className: "calendar-event-details-rsvp", children: [_jsx("div", { role: "radiogroup", "aria-label": "Change RSVP", children: RSVP_OPTIONS.map((o) => (_jsx("button", { type: "button", role: "radio", "aria-checked": event.selfResponseStatus === o.status, tabIndex: o.status === checkedStatus ? 0 : -1, disabled: !!pending, onClick: () => choose(o.status), onKeyDown: onRadioKeyDown, children: o.label }, o.status))) }), _jsx("div", { "aria-live": "polite", className: "calendar-event-details-rsvp-status", children: pending ? ('Updating RSVP...') : error ? (_jsxs(_Fragment, { children: [_jsx("span", { children: "Couldn't update RSVP." }), ' ', _jsx("button", { type: "button", onClick: retry, children: "Retry" })] })) : null })] })), event.htmlLink && (_jsx("section", { className: "calendar-event-details-open", children: _jsx("a", { href: event.htmlLink, target: "_blank", rel: "noopener noreferrer", onClick: (e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
onOpenLink(event.htmlLink);
|
|
88
|
+
}, children: "Open in Google Calendar" }) }))] })] }) }));
|
|
89
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Token = {
|
|
2
|
+
type: 'text';
|
|
3
|
+
text: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'link';
|
|
6
|
+
text: string;
|
|
7
|
+
href: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function htmlToPlainText(html?: string): string;
|
|
10
|
+
export declare function linkifyText(text: string): Token[];
|
|
11
|
+
export declare function formatEventWhen(start?: string, end?: string, allDay?: boolean): {
|
|
12
|
+
date: string;
|
|
13
|
+
time: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const BLOCK = 'p,div,li,tr,h1,h2,h3,h4,h5,h6,ul,ol,blockquote';
|
|
2
|
+
export function htmlToPlainText(html) {
|
|
3
|
+
if (!html)
|
|
4
|
+
return '';
|
|
5
|
+
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
6
|
+
doc.querySelectorAll('script,style').forEach((n) => n.remove());
|
|
7
|
+
doc.querySelectorAll('br').forEach((n) => n.replaceWith('\n'));
|
|
8
|
+
doc.querySelectorAll(BLOCK).forEach((n) => n.append('\n'));
|
|
9
|
+
return (doc.body.textContent ?? '').replace(/\n{3,}/g, '\n\n').trim();
|
|
10
|
+
}
|
|
11
|
+
export function linkifyText(text) {
|
|
12
|
+
const tokens = [];
|
|
13
|
+
const re = /https?:\/\/[^\s<>"]+/g;
|
|
14
|
+
let last = 0;
|
|
15
|
+
let m;
|
|
16
|
+
while ((m = re.exec(text))) {
|
|
17
|
+
const url = m[0].replace(/[.,;:!?)\]}'"]+$/, '');
|
|
18
|
+
if (m.index > last)
|
|
19
|
+
tokens.push({ type: 'text', text: text.slice(last, m.index) });
|
|
20
|
+
tokens.push({ type: 'link', text: url, href: url });
|
|
21
|
+
last = m.index + url.length;
|
|
22
|
+
re.lastIndex = last;
|
|
23
|
+
}
|
|
24
|
+
if (last < text.length)
|
|
25
|
+
tokens.push({ type: 'text', text: text.slice(last) });
|
|
26
|
+
return tokens;
|
|
27
|
+
}
|
|
28
|
+
function timeOfDay(dateTime) {
|
|
29
|
+
return new Date(dateTime).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
30
|
+
}
|
|
31
|
+
function parseLocalDate(s) {
|
|
32
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
33
|
+
return m ? new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : new Date(s);
|
|
34
|
+
}
|
|
35
|
+
export function formatEventWhen(start, end, allDay) {
|
|
36
|
+
if (!start)
|
|
37
|
+
return { date: '', time: '' };
|
|
38
|
+
const d = allDay ? parseLocalDate(start) : new Date(start);
|
|
39
|
+
const date = d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
|
|
40
|
+
if (allDay)
|
|
41
|
+
return { date, time: '' };
|
|
42
|
+
const s = timeOfDay(start);
|
|
43
|
+
return { date, time: end ? `${s} – ${timeOfDay(end)}` : s };
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const ORDER = ['accepted', 'tentative', 'needsAction', 'declined'];
|
|
2
|
+
const LABELS = { accepted: 'yes', tentative: 'maybe', needsAction: 'awaiting', declined: 'no' };
|
|
3
|
+
function bucketOf(status) {
|
|
4
|
+
return ORDER.includes(status) ? status : 'needsAction';
|
|
5
|
+
}
|
|
6
|
+
function nameOf(a) {
|
|
7
|
+
return (a.displayName || a.email || '').toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
function rank(a) {
|
|
10
|
+
if (a.organizer)
|
|
11
|
+
return 0;
|
|
12
|
+
if (a.self)
|
|
13
|
+
return 1;
|
|
14
|
+
return 2 + ORDER.indexOf(bucketOf(a.responseStatus));
|
|
15
|
+
}
|
|
16
|
+
export function sortInvitees(attendees) {
|
|
17
|
+
return [...attendees].sort((a, b) => {
|
|
18
|
+
const r = rank(a) - rank(b);
|
|
19
|
+
if (r !== 0)
|
|
20
|
+
return r;
|
|
21
|
+
const n = nameOf(a).localeCompare(nameOf(b));
|
|
22
|
+
return n !== 0 ? n : (a.email || '').toLowerCase().localeCompare((b.email || '').toLowerCase());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function summarizeInvitees(attendees) {
|
|
26
|
+
const counts = { accepted: 0, tentative: 0, needsAction: 0, declined: 0 };
|
|
27
|
+
for (const a of attendees)
|
|
28
|
+
counts[bucketOf(a.responseStatus)]++;
|
|
29
|
+
return ORDER.filter((b) => counts[b] > 0).map((b) => `${counts[b]} ${LABELS[b]}`).join(' · ');
|
|
30
|
+
}
|
package/dist/styles.css
CHANGED
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
.calendar-pane {
|
|
89
|
+
position: relative;
|
|
89
90
|
--calendar-footer-height: 64px;
|
|
90
91
|
display: flex;
|
|
91
92
|
flex-direction: column;
|
|
@@ -843,3 +844,180 @@
|
|
|
843
844
|
opacity: 0.7;
|
|
844
845
|
overflow-wrap: anywhere;
|
|
845
846
|
}
|
|
847
|
+
|
|
848
|
+
/* Event details overlay: confined to the pane, bottom sheet. */
|
|
849
|
+
.calendar-event-details {
|
|
850
|
+
position: absolute;
|
|
851
|
+
inset: 0;
|
|
852
|
+
z-index: 20;
|
|
853
|
+
display: flex;
|
|
854
|
+
flex-direction: column;
|
|
855
|
+
justify-content: flex-end;
|
|
856
|
+
background: rgb(0 0 0 / 45%);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
.calendar-pane--has-footer > .calendar-event-details {
|
|
860
|
+
bottom: var(--calendar-footer-height);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
.calendar-event-details-sheet {
|
|
864
|
+
box-sizing: border-box;
|
|
865
|
+
max-height: 80%;
|
|
866
|
+
overflow-y: auto;
|
|
867
|
+
padding: 8px 16px 16px;
|
|
868
|
+
background: var(--calendar-surface);
|
|
869
|
+
color: var(--calendar-text);
|
|
870
|
+
border-top: 1px solid var(--calendar-border);
|
|
871
|
+
border-radius: 14px 14px 0 0;
|
|
872
|
+
animation: calendar-event-details-slide 0.2s ease-out;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
.calendar-event-details-grabber {
|
|
876
|
+
width: 36px;
|
|
877
|
+
height: 4px;
|
|
878
|
+
margin: 0 auto 8px;
|
|
879
|
+
border-radius: 2px;
|
|
880
|
+
background: var(--calendar-border);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
.calendar-event-details-header {
|
|
884
|
+
display: flex;
|
|
885
|
+
align-items: center;
|
|
886
|
+
gap: 8px;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
.calendar-event-details-dot {
|
|
890
|
+
flex: none;
|
|
891
|
+
width: 10px;
|
|
892
|
+
height: 10px;
|
|
893
|
+
border-radius: 50%;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
.calendar-event-details-title {
|
|
897
|
+
flex: 1;
|
|
898
|
+
min-width: 0;
|
|
899
|
+
margin: 0;
|
|
900
|
+
font-size: 1.05em;
|
|
901
|
+
overflow-wrap: anywhere;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
.calendar-event-details-close {
|
|
905
|
+
flex: none;
|
|
906
|
+
border: 0;
|
|
907
|
+
background: transparent;
|
|
908
|
+
color: inherit;
|
|
909
|
+
font: inherit;
|
|
910
|
+
cursor: pointer;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
.calendar-event-details-toprow {
|
|
914
|
+
display: flex;
|
|
915
|
+
flex-wrap: wrap;
|
|
916
|
+
align-items: center;
|
|
917
|
+
gap: 8px;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
.calendar-event-details-time {
|
|
921
|
+
flex: 1;
|
|
922
|
+
min-width: 0;
|
|
923
|
+
font-variant-numeric: tabular-nums;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
.calendar-event-details-organizer,
|
|
927
|
+
.calendar-event-details-calendar {
|
|
928
|
+
display: flex;
|
|
929
|
+
flex-wrap: wrap;
|
|
930
|
+
align-items: center;
|
|
931
|
+
gap: 4px 6px;
|
|
932
|
+
font-size: 0.9em;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
.calendar-event-details-invitees h3 {
|
|
936
|
+
margin: 0 0 4px;
|
|
937
|
+
font-size: 0.95em;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
.calendar-event-details-invitee-summary {
|
|
941
|
+
margin-bottom: 6px;
|
|
942
|
+
font-size: 0.85em;
|
|
943
|
+
opacity: 0.75;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
.calendar-event-details-invitees ul {
|
|
947
|
+
margin: 0;
|
|
948
|
+
padding: 0;
|
|
949
|
+
list-style: none;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
.calendar-event-details-invitees li {
|
|
953
|
+
display: flex;
|
|
954
|
+
flex-wrap: wrap;
|
|
955
|
+
align-items: center;
|
|
956
|
+
gap: 2px 6px;
|
|
957
|
+
padding: 2px 0;
|
|
958
|
+
font-size: 0.9em;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
.calendar-event-details-tag {
|
|
962
|
+
padding: 0 6px;
|
|
963
|
+
border-radius: 8px;
|
|
964
|
+
background: var(--calendar-badge);
|
|
965
|
+
color: var(--calendar-badge-text);
|
|
966
|
+
font-size: 0.75em;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
.calendar-event-details-rsvp [role='radiogroup'] {
|
|
970
|
+
display: flex;
|
|
971
|
+
flex-wrap: wrap;
|
|
972
|
+
gap: 6px;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
.calendar-event-details-rsvp [role='radio'] {
|
|
976
|
+
padding: 4px 12px;
|
|
977
|
+
border: 1px solid var(--calendar-chip-border);
|
|
978
|
+
border-radius: 14px;
|
|
979
|
+
background: transparent;
|
|
980
|
+
color: var(--calendar-chip-text);
|
|
981
|
+
font: inherit;
|
|
982
|
+
cursor: pointer;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
.calendar-event-details-rsvp [role='radio'][aria-checked='true'] {
|
|
986
|
+
border-color: var(--calendar-chip-selected);
|
|
987
|
+
background: var(--calendar-chip-selected);
|
|
988
|
+
color: var(--calendar-chip-selected-text);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
.calendar-event-details-rsvp [role='radio']:focus-visible {
|
|
992
|
+
outline: 2px solid var(--calendar-focus);
|
|
993
|
+
outline-offset: 2px;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
.calendar-event-details-rsvp [role='radio']:disabled {
|
|
997
|
+
opacity: 0.6;
|
|
998
|
+
cursor: default;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
.calendar-event-details-rsvp-status {
|
|
1002
|
+
margin-top: 6px;
|
|
1003
|
+
font-size: 0.85em;
|
|
1004
|
+
color: var(--calendar-rsvp-declined);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
.calendar-event-details-body {
|
|
1008
|
+
min-height: 0;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
.calendar-event-details-body > section {
|
|
1012
|
+
margin-top: 10px;
|
|
1013
|
+
overflow-wrap: anywhere;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
@keyframes calendar-event-details-slide {
|
|
1017
|
+
from { transform: translateY(100%); }
|
|
1018
|
+
to { transform: translateY(0); }
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1022
|
+
.calendar-event-details-sheet { animation: none; }
|
|
1023
|
+
}
|