@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,188 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The event editor: create, edit and delete a person's own events, recurring
4
+ * included (MSG-055, https://github.com/wtfalch/messaging/issues/158).
5
+ *
6
+ * Two things here are decisions rather than plumbing.
7
+ *
8
+ * **A recurring edit asks which.** Editing an occurrence of a series can mean
9
+ * two different things, and a calendar that guesses is a calendar that quietly
10
+ * moves eleven other meetings. So when the event being edited belongs to a
11
+ * series, saving and deleting both go through an explicit choice, and the
12
+ * choice has no default.
13
+ *
14
+ * **Sending mail is its own decision.** Adding somebody to an event and
15
+ * telling them about it are two different acts. `sendSchedulingMessages`
16
+ * defaults to false in the client for exactly that reason, and the control
17
+ * here defaults to off with it: Save changes the event, and only the checkbox
18
+ * sends anyone mail. A calendar that mails eleven people because somebody
19
+ * fixed a typo in a title is a calendar people stop trusting.
20
+ *
21
+ * `@wtfalch/design` is an optional peer, the same way `react` is: the
22
+ * framework-free `./calendar` export never reaches this file.
23
+ */
24
+ import { Button, Checkbox, Field, Icon, Input, Modal, Pill, Select, Textarea, } from '@wtfalch/design';
25
+ import { useCallback, useId, useMemo, useState } from 'react';
26
+ import { parseDurationMs } from "../wire.js";
27
+ import { AvailabilityRibbon } from "./AvailabilityRibbon.js";
28
+ import { STATUS_TONE, STATUS_WORD, addressOf, mailtoOf, sameAddress } from "./participants.js";
29
+ const FREQUENCIES = [
30
+ { value: '', label: 'Does not repeat' },
31
+ { value: 'daily', label: 'Every day' },
32
+ { value: 'weekly', label: 'Every week' },
33
+ { value: 'monthly', label: 'Every month' },
34
+ { value: 'yearly', label: 'Every year' },
35
+ ];
36
+ const DURATIONS = [
37
+ { value: 'PT15M', label: '15 minutes' },
38
+ { value: 'PT30M', label: '30 minutes' },
39
+ { value: 'PT1H', label: '1 hour' },
40
+ { value: 'PT1H30M', label: '1 hour 30 minutes' },
41
+ { value: 'PT2H', label: '2 hours' },
42
+ { value: 'PT4H', label: '4 hours' },
43
+ { value: 'PT8H', label: 'All working day' },
44
+ ];
45
+ /** `CalendarEvent.start` is a local date-time with no offset, which is exactly
46
+ * what `<input type="datetime-local">` reads and writes. Trimming to minutes
47
+ * is the only conversion either direction needs. */
48
+ function toInputValue(start) {
49
+ return start.slice(0, 16);
50
+ }
51
+ function fromInputValue(value) {
52
+ return value.length === 16 ? `${value}:00` : value;
53
+ }
54
+ function startOfNextHour(from) {
55
+ const next = new Date(from);
56
+ next.setMinutes(0, 0, 0);
57
+ next.setHours(next.getHours() + 1);
58
+ const pad = (n) => String(n).padStart(2, '0');
59
+ return `${next.getFullYear()}-${pad(next.getMonth() + 1)}-${pad(next.getDate())}T${pad(next.getHours())}:${pad(next.getMinutes())}:00`;
60
+ }
61
+ /** A duration the picker does not offer is still a real duration, so it joins
62
+ * the list rather than being silently rounded to one that is. */
63
+ function durationOptions(current) {
64
+ if (DURATIONS.some((option) => option.value === current))
65
+ return DURATIONS;
66
+ const ms = parseDurationMs(current);
67
+ const label = ms === null ? current : `${Math.round(ms / 60_000)} minutes`;
68
+ return [...DURATIONS, { value: current, label }];
69
+ }
70
+ export function EventEditor({ event, initialStart, now, calendarId, compact, onSave, onDelete, onClose, availability, }) {
71
+ const creating = event === undefined;
72
+ const recurring = event?.recurrenceRule !== undefined || event?.recurrenceId !== undefined;
73
+ const [title, setTitle] = useState(event?.title ?? '');
74
+ const [start, setStart] = useState(event ? toInputValue(event.start) : toInputValue(startOfNextHour(initialStart ?? now)));
75
+ const [duration, setDuration] = useState(event?.duration ?? 'PT1H');
76
+ const [isAllDay, setIsAllDay] = useState(event?.isAllDay ?? false);
77
+ const [location, setLocation] = useState(event?.location ?? '');
78
+ const [description, setDescription] = useState(event?.description ?? '');
79
+ const [frequency, setFrequency] = useState(event?.recurrenceRule?.frequency ?? '');
80
+ const [participants, setParticipants] = useState(event?.participants ?? []);
81
+ const [invitee, setInvitee] = useState('');
82
+ /** Off, always, whatever the event already has on it. Sending is a decision
83
+ * the person makes on this visit, not one the last visit made for them. */
84
+ const [notify, setNotify] = useState(false);
85
+ /** `null` when nothing is pending, otherwise the action waiting on a scope
86
+ * answer. Saving and deleting both pass through here for a series. */
87
+ const [pending, setPending] = useState(null);
88
+ const [busy, setBusy] = useState(false);
89
+ const [failure, setFailure] = useState(null);
90
+ const titleId = useId();
91
+ const titleMissing = title.trim() === '';
92
+ const draft = useMemo(() => ({
93
+ calendarId: event?.calendarId ?? calendarId,
94
+ uid: event?.uid ?? '',
95
+ title: title.trim(),
96
+ description: description.trim() === '' ? undefined : description.trim(),
97
+ start: fromInputValue(start),
98
+ timeZone: event?.timeZone ?? null,
99
+ duration,
100
+ isAllDay,
101
+ location: location.trim() === '' ? undefined : location.trim(),
102
+ recurrenceRule: frequency === '' ? undefined : { frequency, interval: 1 },
103
+ participants: participants.length === 0 ? undefined : participants,
104
+ status: event?.status ?? 'confirmed',
105
+ }), [
106
+ calendarId,
107
+ description,
108
+ duration,
109
+ event,
110
+ frequency,
111
+ isAllDay,
112
+ location,
113
+ participants,
114
+ start,
115
+ title,
116
+ ]);
117
+ /** Somebody typed an address and meant it. Duplicates are dropped rather
118
+ * than refused: adding a person already on the list is not an error, it is
119
+ * just nothing. */
120
+ const addInvitee = useCallback(() => {
121
+ const bare = invitee.trim().replace(/^mailto:/i, '');
122
+ if (bare === '')
123
+ return;
124
+ setParticipants((current) => current.some((person) => sameAddress(person.calendarAddress, bare))
125
+ ? current
126
+ : [...current, { calendarAddress: mailtoOf(bare), roles: ['attendee'] }]);
127
+ setInvitee('');
128
+ }, [invitee]);
129
+ const removeInvitee = useCallback((address) => {
130
+ setParticipants((current) => current.filter((person) => !sameAddress(person.calendarAddress, address)));
131
+ }, []);
132
+ const run = useCallback(async (action, scope) => {
133
+ setBusy(true);
134
+ setFailure(null);
135
+ try {
136
+ if (action === 'save')
137
+ await onSave(draft, scope, notify);
138
+ else
139
+ await onDelete?.(scope, notify);
140
+ onClose();
141
+ }
142
+ catch (thrown) {
143
+ setPending(null);
144
+ setFailure(thrown instanceof Error ? thrown.message : String(thrown));
145
+ }
146
+ finally {
147
+ setBusy(false);
148
+ }
149
+ }, [draft, notify, onClose, onDelete, onSave]);
150
+ const attempt = useCallback((action) => {
151
+ if (action === 'save' && titleMissing)
152
+ return;
153
+ if (recurring)
154
+ setPending(action);
155
+ else
156
+ void run(action, null);
157
+ }, [recurring, run, titleMissing]);
158
+ if (pending !== null) {
159
+ return (_jsxs(Modal, { title: pending === 'save' ? 'Change which events?' : 'Delete which events?', description: "This event repeats, so the change has to say how far it reaches.", edge: compact ? 'bottom' : undefined, width: "26rem", onClose: busy ? undefined : () => setPending(null), closeDisabled: busy, footer: _jsx(Button, { kind: "ghost", onPress: () => setPending(null), disabled: busy, children: "Back" }), children: [_jsxs("div", { className: "wtcal-scope", children: [_jsx(Button, { kind: pending === 'delete' ? 'danger' : 'default', block: true, busy: busy, onPress: () => void run(pending, 'occurrence'), children: pending === 'save' ? 'Only this event' : 'Delete only this event' }), _jsx(Button, { kind: pending === 'delete' ? 'danger' : 'default', block: true, busy: busy, onPress: () => void run(pending, 'series'), children: pending === 'save' ? 'This and every repeat' : 'Delete the whole series' })] }), failure !== null && (_jsx("p", { className: "wtcal-failure", role: "alert", children: failure }))] }));
160
+ }
161
+ return (_jsx(Modal, { title: creating ? 'New event' : 'Edit event', edge: compact ? 'bottom' : undefined, width: "34rem", onClose: busy ? undefined : onClose, closeDisabled: busy, labelledBy: titleId, footer:
162
+ // The send control sits with Save, not up in the form with the
163
+ // participant list. Whether to mail anyone is decided at the moment of
164
+ // saving, and a form this tall scrolls -- at the bottom of it the one
165
+ // control that sends mail was below the fold, which is the last place
166
+ // to hide it.
167
+ // `is-compact` rides on this element too, for the same reason the form
168
+ // below carries its own: the footer is `Modal`'s, rendered through the
169
+ // portal outside `.wtcal`, so a `.wtcal.is-compact ...` rule would
170
+ // never match it.
171
+ _jsxs("div", { className: compact ? 'wtcal-editor-actions is-compact' : 'wtcal-editor-actions', children: [!creating && onDelete !== undefined && (_jsx(Button, { kind: "danger", onPress: () => attempt('delete'), disabled: busy, children: "Delete" })), participants.length > 0 && (
172
+ // `tile` reserves the room the tick needs. A `Checkbox` draws its
173
+ // mark at its own top right and counts on a full-width row, where
174
+ // the label never reaches it. Here the control shrink-wraps beside
175
+ // Cancel and Save, so at 1440px the label ran 102px and the mark
176
+ // began 3px before it ended -- the circle sat on the last letter.
177
+ // The prop is the system's own answer to that, and the only thing
178
+ // it changes is the body's right padding.
179
+ _jsx(Checkbox, { tile: true, label: "Email everyone", checked: notify, onChange: setNotify, disabled: busy })), _jsx("span", { className: "wtcal-editor-spacer" }), _jsx(Button, { kind: "ghost", onPress: onClose, disabled: busy, children: "Cancel" }), _jsx(Button, { kind: "primary", busy: busy, disabled: titleMissing, onPress: () => attempt('save'), children: creating ? 'Create event' : 'Save changes' })] }), children: _jsxs("div", { className: compact ? 'wtcal-editor is-compact' : 'wtcal-editor', children: [_jsx(Field, { label: "Title", required: true, children: (wiring) => (_jsx(Input, { ...wiring, block: true, size: "lg", value: title, placeholder: "What is this meeting?", onChange: (e) => setTitle(e.target.value) })) }), _jsxs("div", { className: "wtcal-editor-row", children: [_jsx(Field, { label: isAllDay ? 'Day' : 'Starts', children: (wiring) => (_jsx(Input, { ...wiring, block: true, type: isAllDay ? 'date' : 'datetime-local', value: isAllDay ? start.slice(0, 10) : start, onChange: (e) => setStart(isAllDay ? `${e.target.value}T00:00` : e.target.value) })) }), !isAllDay && (_jsx(Field, { label: "For", children: (wiring) => (_jsx(Select, { ...wiring, block: true, value: duration, onChange: (e) => setDuration(e.target.value), children: durationOptions(duration).map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })) }))] }), !isAllDay && (_jsx(AvailabilityRibbon, { participants: participants, start: new Date(start), durationMinutes: (parseDurationMs(duration) ?? 3_600_000) / 60_000, lookup: availability })), _jsx(Checkbox, { label: "All day", checked: isAllDay, onChange: setIsAllDay }), _jsx(Field, { label: "Repeats", children: (wiring) => (_jsx(Select, { ...wiring, block: true, value: frequency, onChange: (e) => setFrequency(e.target.value), children: FREQUENCIES.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })) }), _jsx(Field, { label: "Who", hint: "An email address. They are added to the event, not mailed yet.", children: (wiring) => (_jsxs("div", { className: "wtcal-invitee-add", children: [_jsx(Input, { ...wiring, block: true, type: "email", value: invitee, placeholder: "someone@example.org", onChange: (e) => setInvitee(e.target.value),
180
+ // Enter adds a person; without this it submits nothing and
181
+ // the address the person typed disappears on Save.
182
+ onKeyDown: (e) => {
183
+ if (e.key === 'Enter') {
184
+ e.preventDefault();
185
+ addInvitee();
186
+ }
187
+ } }), _jsx(Button, { kind: "default", onPress: addInvitee, disabled: invitee.trim() === '', children: "Add" })] })) }), participants.length > 0 && (_jsx("ul", { className: "wtcal-invitees", children: participants.map((person) => (_jsxs("li", { className: "wtcal-invitee", children: [_jsxs("span", { className: "wtcal-invitee-who", children: [person.name ?? addressOf(person), person.name !== undefined && (_jsx("span", { className: "wtcal-invitee-address", children: addressOf(person) }))] }), person.participationStatus !== undefined && (_jsx(Pill, { quiet: true, tone: STATUS_TONE[person.participationStatus], children: STATUS_WORD[person.participationStatus] })), _jsx(Button, { kind: "ghost", size: "sm", iconOnly: true, "aria-label": `Remove ${addressOf(person)}`, onPress: () => removeInvitee(person.calendarAddress), children: _jsx(Icon, { name: "close", size: "sm" }) })] }, person.calendarAddress))) })), participants.length > 0 && (_jsx("p", { className: "wtcal-editor-note", children: "Nobody is mailed unless you tick \u201CEmail everyone\u201D beside Save." })), _jsx(Field, { label: "Where", hint: "A room, an address, or a link.", children: (wiring) => (_jsx(Input, { ...wiring, block: true, value: location, onChange: (e) => setLocation(e.target.value) })) }), _jsx(Field, { label: "Notes", children: (wiring) => (_jsx(Textarea, { ...wiring, rows: 3, value: description, onChange: (e) => setDescription(e.target.value) })) }), failure !== null && (_jsx("p", { className: "wtcal-failure", role: "alert", children: failure }))] }) }));
188
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Sharing: who can see this calendar, and at which of two levels.
3
+ *
4
+ * A dialog rather than a pane, unlike `EventDetail`: this is a decision about
5
+ * the whole calendar, not about the week behind it, so there is nothing on the
6
+ * grid the person needs to keep looking at while they make it.
7
+ *
8
+ * **Every row here is the server's answer, never this component's hope.** The
9
+ * list is whatever the last `listCalendars()` returned, and a write re-reads
10
+ * it before the list changes. Nothing is added or removed optimistically, so a
11
+ * refused write leaves the person looking at what is actually granted -- the
12
+ * surface brief's one rule for this screen.
13
+ */
14
+ import type { CalendarClient } from '../types.ts';
15
+ export type ShareDialogProps = {
16
+ client: CalendarClient;
17
+ /** The calendar being shared. The first ship shares one calendar -- the
18
+ * person's own default -- so this comes from `useDefaultCalendarId`. */
19
+ calendarId: string;
20
+ /** Below `md`, the dialog becomes a bottom sheet, the same way the editor
21
+ * and the detail pane do. */
22
+ compact: boolean;
23
+ onClose: () => void;
24
+ };
25
+ export declare function ShareDialog({ client, calendarId, compact, onClose }: ShareDialogProps): import("react").JSX.Element;
@@ -0,0 +1,125 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Sharing: who can see this calendar, and at which of two levels.
4
+ *
5
+ * A dialog rather than a pane, unlike `EventDetail`: this is a decision about
6
+ * the whole calendar, not about the week behind it, so there is nothing on the
7
+ * grid the person needs to keep looking at while they make it.
8
+ *
9
+ * **Every row here is the server's answer, never this component's hope.** The
10
+ * list is whatever the last `listCalendars()` returned, and a write re-reads
11
+ * it before the list changes. Nothing is added or removed optimistically, so a
12
+ * refused write leaves the person looking at what is actually granted -- the
13
+ * surface brief's one rule for this screen.
14
+ */
15
+ import { Button, Empty, Field, Icon, Identity, Input, Modal, Pill, Select, Skeleton, } from '@wtfalch/design';
16
+ import { useCallback, useEffect, useState } from 'react';
17
+ /**
18
+ * The two levels, and the exact rights each one writes.
19
+ *
20
+ * Both are live-confirmed against Stalwart v0.16.20 and pinned in
21
+ * `wire-live-transcript.test.ts`: with `mayReadFreeBusy` alone, a colleague's
22
+ * `Principal/getAvailability` returns the busy period and nothing on it, and
23
+ * `CalendarEvent/query` against the calendar is refused `forbidden`. Adding
24
+ * `mayReadItems` is what opens the events themselves.
25
+ *
26
+ * The person is asked which, rather than one control deciding it for them,
27
+ * because these are two different things to hand somebody and it is the one
28
+ * choice on this screen they could regret.
29
+ */
30
+ const LEVELS = [
31
+ { value: 'busy', label: 'Busy times', rights: ['mayReadFreeBusy'] },
32
+ { value: 'events', label: 'Events', rights: ['mayReadFreeBusy', 'mayReadItems'] },
33
+ ];
34
+ const BUSY_LEVEL = LEVELS[0];
35
+ const EVENTS_LEVEL = LEVELS[1];
36
+ /** Which level a grant already on the server reads as. `mayReadItems` is the
37
+ * one right that separates them; any grant without it is the quieter one. */
38
+ function levelOf(grant) {
39
+ return grant.rights.includes('mayReadItems') ? EVENTS_LEVEL : BUSY_LEVEL;
40
+ }
41
+ export function ShareDialog({ client, calendarId, compact, onClose }) {
42
+ const [rows, setRows] = useState(undefined);
43
+ const [address, setAddress] = useState('');
44
+ const [level, setLevel] = useState(EVENTS_LEVEL.value);
45
+ const [busy, setBusy] = useState(false);
46
+ const [failure, setFailure] = useState(undefined);
47
+ /** Read the grants back, then put a name and an address on each one. A
48
+ * grant carries only an account id, which is not a thing to show a
49
+ * person. One lookup covers the whole list. */
50
+ const read = useCallback(async () => {
51
+ const calendars = await client.listCalendars();
52
+ const grants = calendars.find((one) => one.id === calendarId)?.shareWith ?? [];
53
+ const principals = await client.lookupPrincipals(grants.map((grant) => grant.accountId));
54
+ const byId = new Map(principals.map((principal) => [principal.accountId, principal]));
55
+ setRows(grants.map((grant) => ({ grant, principal: byId.get(grant.accountId) })));
56
+ }, [client, calendarId]);
57
+ useEffect(() => {
58
+ read().catch((error) => setFailure(messageOf(error)));
59
+ }, [read]);
60
+ const share = useCallback(async () => {
61
+ const typed = address.trim();
62
+ if (typed === '' || busy)
63
+ return;
64
+ setBusy(true);
65
+ setFailure(undefined);
66
+ try {
67
+ const principal = await client.resolvePrincipal(typed);
68
+ if (!principal) {
69
+ // Not an error from the server's point of view, and not one to this
70
+ // person either: they mistyped, or that colleague is on another
71
+ // server. Say which so the next attempt is better informed.
72
+ setFailure(`Nobody on this server has the address ${typed}.`);
73
+ return;
74
+ }
75
+ const rights = LEVELS.find((one) => one.value === level)?.rights ?? EVENTS_LEVEL.rights;
76
+ await client.shareCalendar(calendarId, { accountId: principal.accountId, rights });
77
+ await read();
78
+ setAddress('');
79
+ }
80
+ catch (error) {
81
+ setFailure(messageOf(error));
82
+ }
83
+ finally {
84
+ setBusy(false);
85
+ }
86
+ }, [address, busy, client, calendarId, level, read]);
87
+ const revoke = useCallback(async (accountId) => {
88
+ if (busy)
89
+ return;
90
+ setBusy(true);
91
+ setFailure(undefined);
92
+ try {
93
+ await client.unshareCalendar(calendarId, accountId);
94
+ await read();
95
+ }
96
+ catch (error) {
97
+ setFailure(messageOf(error));
98
+ }
99
+ finally {
100
+ setBusy(false);
101
+ }
102
+ }, [busy, client, calendarId, read]);
103
+ const count = rows?.length;
104
+ return (_jsx(Modal, { title: "Share this calendar", edge: compact ? 'bottom' : undefined, width: "32rem", onClose: busy ? undefined : onClose, closeDisabled: busy, footer:
105
+ // `is-compact` rides on this element, not on an ancestor: `Modal`
106
+ // renders through a portal outside `.wtcal`, so a `.wtcal.is-compact`
107
+ // selector aimed at it matches nothing.
108
+ _jsxs("div", { className: compact ? 'wtcal-share-actions is-compact' : 'wtcal-share-actions', children: [_jsx("span", { className: "wtcal-share-spacer" }), _jsx(Button, { kind: "ghost", onPress: onClose, disabled: busy, children: "Done" }), _jsx(Button, { kind: "primary", busy: busy, disabled: address.trim() === '', onPress: () => void share(), children: "Share" })] }), children: _jsxs("div", { className: compact ? 'wtcal-share is-compact' : 'wtcal-share', children: [_jsxs("section", { className: "wtcal-share-section", children: [_jsx("h3", { className: "wtcal-detail-label", children: count !== undefined && count > 0 ? `${count} with access` : 'Who has access' }), count === undefined ? (
109
+ // The list is a round trip away, and a heading over nothing reads
110
+ // as "nobody" until it suddenly does not. Two placeholder rows,
111
+ // the height of a real one, say the answer is still coming.
112
+ _jsxs("div", { className: "wtcal-share-people", "aria-busy": "true", "aria-label": "Loading who has access", children: [_jsx(Skeleton, { variant: "rounded", height: 9 }), _jsx(Skeleton, { variant: "rounded", height: 9 })] })) : count === 0 ? (_jsx(Empty, { className: "wtcal-share-empty", children: "Nobody yet. This calendar is yours alone until you share it." })) : (_jsx("ul", { className: "wtcal-share-people", children: (rows ?? []).map(({ grant, principal }) => (_jsxs("li", { className: "wtcal-share-person", children: [_jsx(Identity, { kind: "full", size: "sm", name: principal?.name ?? null, address: principal?.email ?? grant.accountId, aside: _jsx(Pill, { quiet: true, children: levelOf(grant).label }) }), _jsx(Button, { kind: "ghost", size: "sm", disabled: busy, "aria-label": `Stop sharing with ${principal?.email ?? grant.accountId}`, onPress: () => void revoke(grant.accountId), children: _jsx(Icon, { name: "close", size: "sm" }) })] }, grant.accountId))) }))] }), _jsxs("section", { className: "wtcal-share-section", children: [_jsx(Field, { label: "Share with", hint: "Their calendar address, on this server.", children: (wiring) => (_jsx(Input, { ...wiring, block: true, type: "email", value: address, placeholder: "someone@example.org", disabled: busy, onChange: (e) => setAddress(e.target.value), onKeyDown: (e) => {
113
+ if (e.key === 'Enter') {
114
+ e.preventDefault();
115
+ void share();
116
+ }
117
+ } })) }), _jsx(Field, { label: "They can see", hint: "Busy times says when you are free and nothing else. Events says what the meetings are.", children: (wiring) => (_jsx(Select, { ...wiring, block: true, value: level, disabled: busy, onChange: (e) => setLevel(e.target.value), children: LEVELS.map((one) => (_jsx("option", { value: one.value, children: one.label }, one.value))) })) })] }), failure !== undefined && _jsx("p", { className: "wtcal-failure", children: failure })] }) }));
118
+ }
119
+ /** The server's own words when it has them: `CalendarError` carries the
120
+ * server's description, which says more than "something went wrong". */
121
+ function messageOf(error) {
122
+ return error instanceof Error && error.message !== ''
123
+ ? error.message
124
+ : 'The server refused that, and nothing changed.';
125
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The calendar's own header: where you are, how to move, and the one thing
3
+ * this screen is for.
4
+ *
5
+ * react-big-calendar ships a toolbar of its own. It is replaced rather than
6
+ * themed, because it hardcodes a button group this design does not use, has no
7
+ * slot for a primary action, and collapses badly at phone width. Replacing it
8
+ * is the library's own documented seam (`components.toolbar`).
9
+ *
10
+ * At phone width the view switcher becomes a `Select`: five buttons in a row
11
+ * is four too many at 390px, and a native select is the control a phone
12
+ * already knows how to present.
13
+ */
14
+ import type { CalendarLocation } from '../types.ts';
15
+ export type ToolbarProps = {
16
+ view: CalendarLocation['view'];
17
+ date: Date;
18
+ compact: boolean;
19
+ account?: React.ReactNode;
20
+ onMove: (to: Date) => void;
21
+ onToday: () => void;
22
+ onView: (view: CalendarLocation['view']) => void;
23
+ onCreate: () => void;
24
+ /** Open the sharing dialog. Absent until the default calendar is known --
25
+ * there is nothing to share before then, and a control that answers
26
+ * nothing is worse than one that is not there yet. */
27
+ onShare?: () => void;
28
+ };
29
+ export declare function Toolbar({ view, date, compact, account, onMove, onToday, onView, onCreate, onShare, }: ToolbarProps): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The calendar's own header: where you are, how to move, and the one thing
4
+ * this screen is for.
5
+ *
6
+ * react-big-calendar ships a toolbar of its own. It is replaced rather than
7
+ * themed, because it hardcodes a button group this design does not use, has no
8
+ * slot for a primary action, and collapses badly at phone width. Replacing it
9
+ * is the library's own documented seam (`components.toolbar`).
10
+ *
11
+ * At phone width the view switcher becomes a `Select`: five buttons in a row
12
+ * is four too many at 390px, and a native select is the control a phone
13
+ * already knows how to present.
14
+ */
15
+ import { Button, Icon, Select } from '@wtfalch/design';
16
+ const VIEWS = [
17
+ { value: 'month', label: 'Month' },
18
+ { value: 'week', label: 'Week' },
19
+ { value: 'day', label: 'Day' },
20
+ { value: 'agenda', label: 'Agenda' },
21
+ ];
22
+ function shift(view, date, direction) {
23
+ const next = new Date(date);
24
+ if (view === 'day')
25
+ next.setDate(next.getDate() + direction);
26
+ else if (view === 'week')
27
+ next.setDate(next.getDate() + 7 * direction);
28
+ else if (view === 'agenda')
29
+ next.setDate(next.getDate() + 30 * direction);
30
+ else
31
+ next.setMonth(next.getMonth() + direction, 1);
32
+ return next;
33
+ }
34
+ /** What the header says you are looking at. The month view names a month, the
35
+ * day view names a day; saying "October 2026" above a single Tuesday is the
36
+ * kind of almost-right label that makes people check twice. */
37
+ function heading(view, date) {
38
+ if (view === 'day') {
39
+ return date.toLocaleDateString(undefined, { weekday: 'long', day: 'numeric', month: 'long' });
40
+ }
41
+ if (view === 'week') {
42
+ const start = new Date(date);
43
+ start.setDate(start.getDate() - start.getDay());
44
+ const end = new Date(start);
45
+ end.setDate(end.getDate() + 6);
46
+ const sameMonth = start.getMonth() === end.getMonth();
47
+ const left = start.toLocaleDateString(undefined, {
48
+ day: 'numeric',
49
+ month: sameMonth ? undefined : 'short',
50
+ });
51
+ const right = end.toLocaleDateString(undefined, { day: 'numeric', month: 'short' });
52
+ return `${left} – ${right} ${end.getFullYear()}`;
53
+ }
54
+ return date.toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
55
+ }
56
+ export function Toolbar({ view, date, compact, account, onMove, onToday, onView, onCreate, onShare, }) {
57
+ return (_jsxs("div", { className: "wtcal-toolbar", children: [_jsxs("div", { className: "wtcal-toolbar-where", children: [_jsxs("div", { className: "wtcal-toolbar-move", children: [_jsx(Button, { kind: "ghost", size: "sm", iconOnly: true, "aria-label": `Previous ${view}`, onPress: () => onMove(shift(view, date, -1)), children: _jsx(Icon, { name: "back", size: "sm" }) }), _jsx(Button, { kind: "ghost", size: "sm", iconOnly: true, "aria-label": `Next ${view}`, onPress: () => onMove(shift(view, date, 1)), children: _jsx(Icon, { name: "back", size: "sm", className: "wtcal-icon-flip" }) })] }), _jsx("h1", { className: "wtcal-toolbar-heading", children: heading(view, date) }), _jsx(Button, { kind: "ghost", size: "sm", onPress: onToday, children: "Today" })] }), _jsxs("div", { className: "wtcal-toolbar-actions", children: [compact ? (_jsx(Select, { size: "sm", "aria-label": "View", value: view, onChange: (e) => onView(e.target.value), children: VIEWS.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })) : (_jsx("fieldset", { className: "wtcal-toolbar-views", "aria-label": "View", children: VIEWS.map((option) => (_jsx(Button, { kind: option.value === view ? 'default' : 'ghost', size: "sm", "aria-pressed": option.value === view, onPress: () => onView(option.value), children: option.label }, option.value))) })), onShare !== undefined && (_jsx(Button, { kind: "ghost", size: "sm", onPress: onShare, children: "Share" })), _jsx(Button, { kind: "primary", size: "sm", onPress: onCreate, children: "New event" }), account !== undefined && _jsx("div", { className: "wtcal-toolbar-account", children: account })] })] }));
58
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@wtfalch/calendar/calendar/react` — the `Calendar` component.
3
+ *
4
+ * On `@wtfalch/design` and `@wtfalch/calendar/calendar`, and react-big-calendar
5
+ * for the grid itself (plan §7). Import
6
+ * `@wtfalch/calendar/calendar/calendar.css` after the design stylesheet.
7
+ */
8
+ export { Calendar } from './Calendar.tsx';
9
+ export type { CalendarLocation, CalendarProps } from '../types.ts';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@wtfalch/calendar/calendar/react` — the `Calendar` component.
3
+ *
4
+ * On `@wtfalch/design` and `@wtfalch/calendar/calendar`, and react-big-calendar
5
+ * for the grid itself (plan §7). Import
6
+ * `@wtfalch/calendar/calendar/calendar.css` after the design stylesheet.
7
+ */
8
+ export { Calendar } from "./Calendar.js";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * What both the detail pane and the editor need to say about a participant.
3
+ *
4
+ * These lived in `EventDetail` while it was the only thing that drew a
5
+ * participant. The editor now draws the same rows, and two copies of a status
6
+ * word are how one of them drifts into saying "Declined" where the other says
7
+ * "No" (MSG-055 slice 2, https://github.com/wtfalch/messaging/issues/158).
8
+ */
9
+ import type { CalendarParticipant } from '../types.ts';
10
+ /** `Pill`'s tone for each answer. "No answer yet" is `info`, not `warn`:
11
+ * silence is not a problem, it is just silence. */
12
+ export declare const STATUS_TONE: {
13
+ readonly accepted: "good";
14
+ readonly declined: "bad";
15
+ readonly tentative: "warn";
16
+ readonly 'needs-action': "info";
17
+ };
18
+ /** The answer in the words a person would use, not `PARTSTAT`'s. */
19
+ export declare const STATUS_WORD: {
20
+ readonly accepted: "Yes";
21
+ readonly declined: "No";
22
+ readonly tentative: "Maybe";
23
+ readonly 'needs-action': "No answer yet";
24
+ };
25
+ /** A calendar address arrives as `mailto:someone@example.org` off the wire;
26
+ * nobody wants to read the scheme. */
27
+ export declare function addressOf(participant: CalendarParticipant): string;
28
+ /** The inverse, for an address a person typed. The wire wants the scheme back
29
+ * on, and a person who types it anyway should not end up with it twice. */
30
+ export declare function mailtoOf(address: string): string;
31
+ /** Whether two calendar addresses name the same person, scheme and case
32
+ * aside. The wire is inconsistent about both, and an RSVP that fails to
33
+ * recognise its own row is an invite nobody can answer. */
34
+ export declare function sameAddress(a: string, b: string): boolean;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * What both the detail pane and the editor need to say about a participant.
3
+ *
4
+ * These lived in `EventDetail` while it was the only thing that drew a
5
+ * participant. The editor now draws the same rows, and two copies of a status
6
+ * word are how one of them drifts into saying "Declined" where the other says
7
+ * "No" (MSG-055 slice 2, https://github.com/wtfalch/messaging/issues/158).
8
+ */
9
+ /** `Pill`'s tone for each answer. "No answer yet" is `info`, not `warn`:
10
+ * silence is not a problem, it is just silence. */
11
+ export const STATUS_TONE = {
12
+ accepted: 'good',
13
+ declined: 'bad',
14
+ tentative: 'warn',
15
+ 'needs-action': 'info',
16
+ };
17
+ /** The answer in the words a person would use, not `PARTSTAT`'s. */
18
+ export const STATUS_WORD = {
19
+ accepted: 'Yes',
20
+ declined: 'No',
21
+ tentative: 'Maybe',
22
+ 'needs-action': 'No answer yet',
23
+ };
24
+ /** A calendar address arrives as `mailto:someone@example.org` off the wire;
25
+ * nobody wants to read the scheme. */
26
+ export function addressOf(participant) {
27
+ return participant.calendarAddress.replace(/^mailto:/i, '');
28
+ }
29
+ /** The inverse, for an address a person typed. The wire wants the scheme back
30
+ * on, and a person who types it anyway should not end up with it twice. */
31
+ export function mailtoOf(address) {
32
+ const bare = address.trim().replace(/^mailto:/i, '');
33
+ return `mailto:${bare}`;
34
+ }
35
+ /** Whether two calendar addresses name the same person, scheme and case
36
+ * aside. The wire is inconsistent about both, and an RSVP that fails to
37
+ * recognise its own row is an invite nobody can answer. */
38
+ export function sameAddress(a, b) {
39
+ return a.replace(/^mailto:/i, '').toLowerCase() === b.replace(/^mailto:/i, '').toLowerCase();
40
+ }