@semics-tech/emdash-events 1.0.0-rc.0 → 1.0.0-rc.10
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 +3 -2
- package/dist/index.mjs +25 -1
- package/dist/manifest.json +25 -1
- package/dist/plugin.mjs +6 -6
- package/dist/ts/astro/lib/page.d.ts +44 -0
- package/dist/ts/astro/lib/page.js +122 -0
- package/dist/ts/integration/index.d.ts +4 -0
- package/dist/ts/integration/index.js +2 -0
- package/emdash-plugin.jsonc +16 -0
- package/package.json +7 -2
- package/src/astro/AttendeeList.astro +154 -0
- package/src/astro/BookingPage.astro +82 -9
- package/src/astro/BookingStatus.astro +147 -51
- package/src/astro/BookingWidget.astro +307 -35
- package/src/astro/CancelBooking.astro +80 -0
- package/src/astro/PageBrand.astro +18 -0
- package/src/astro/PageOrganiser.astro +22 -0
- package/src/astro/TicketPass.astro +131 -33
- package/src/astro/lib/attendees.ts +218 -0
- package/src/astro/lib/list.ts +22 -0
- package/src/astro/lib/page.ts +142 -0
- package/src/astro/lib/pass.ts +9 -0
- package/src/astro/lib/payment.ts +6 -10
- package/src/astro/lib/picker.ts +245 -0
- package/src/astro/lib/widget.ts +75 -2
- package/src/astro/virtual.d.ts +2 -0
- package/src/client/booking.ts +3 -1
- package/src/client/forget-form.ts +16 -0
- package/src/client/picker.ts +154 -0
- package/src/client/print.ts +12 -0
- package/src/i18n/ar.ts +63 -1
- package/src/i18n/en.ts +61 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The booking form's day-then-time picker (T130, EV-FR-17): pure helpers for `<BookingWidget>`.
|
|
3
|
+
*
|
|
4
|
+
* An event with a slot schedule, or with more than one start on a local day, is booked by picking a
|
|
5
|
+
* day on a month calendar, then one of that day's times. The page renders both the calendar and, for
|
|
6
|
+
* visitors without JavaScript, a plain `<select>` of the same month's dates grouped by day
|
|
7
|
+
* (`<optgroup>`); `src/client/picker.ts` swaps one for the other. Days are the event's local days
|
|
8
|
+
* (`timezone`, else UTC), so a slot at 23:30 in New York sits on that evening's day, and both runs of a
|
|
9
|
+
* repeated DST hour stay on their day.
|
|
10
|
+
*
|
|
11
|
+
* Paging: `public/event` answers up to 200 upcoming open slots from `from` (closed ones never), with
|
|
12
|
+
* `more` when there are further ones. The widget shows one month, starting at its `booking_from.<eventId>` query
|
|
13
|
+
* parameter (a local `YYYY-MM-DD`, today when absent or past); it asks the core from that day's earliest
|
|
14
|
+
* possible local midnight (UTC+14) and skips what falls before the day. A truncated answer's last day
|
|
15
|
+
* may be partial, so it is left for the next page, which starts on it.
|
|
16
|
+
*/
|
|
17
|
+
import { translator } from "../../i18n/index";
|
|
18
|
+
import { anchorId, WIDGET_PARAMS } from "./widget";
|
|
19
|
+
|
|
20
|
+
/** The query parameter holding the first local day the picker shows (prefix: one per widget). */
|
|
21
|
+
export const PICKER_PARAM = "booking_from";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One widget's `booking_from` parameter, keyed by its event (`booking_from.<eventId>`, T134), so two
|
|
25
|
+
* pickers on a page page independently, with or without JavaScript (paging is a plain link).
|
|
26
|
+
*/
|
|
27
|
+
export const pickerParam = (eventId: string) => `${PICKER_PARAM}.${eventId.replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
|
28
|
+
|
|
29
|
+
const DAY_KEY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
30
|
+
const HOUR = 3_600_000;
|
|
31
|
+
/** The earliest a local midnight can be, relative to UTC midnight of the same date (UTC+14). */
|
|
32
|
+
const EARLIEST_OFFSET = 14 * HOUR;
|
|
33
|
+
|
|
34
|
+
export interface PickerOccurrence {
|
|
35
|
+
id: string;
|
|
36
|
+
startsAt: string;
|
|
37
|
+
endsAt?: string | null;
|
|
38
|
+
available?: number | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PickerSlot {
|
|
42
|
+
id: string;
|
|
43
|
+
/** The start's local time (`09:30`). */
|
|
44
|
+
time: string;
|
|
45
|
+
/** "3 places left" or "Full"; empty when the core does not say. */
|
|
46
|
+
places: string;
|
|
47
|
+
full: boolean;
|
|
48
|
+
/** What a screen reader hears: time and places. */
|
|
49
|
+
label: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PickerDay {
|
|
53
|
+
/** The local day, `YYYY-MM-DD`. */
|
|
54
|
+
key: string;
|
|
55
|
+
/** Day of the month. */
|
|
56
|
+
day: number;
|
|
57
|
+
/** The full date ("Wednesday 4 November 2026"). */
|
|
58
|
+
label: string;
|
|
59
|
+
/** The day button's accessible name: the date, plus "fully booked" when no slot has room. */
|
|
60
|
+
buttonLabel: string;
|
|
61
|
+
slots: PickerSlot[];
|
|
62
|
+
/** Some slot has room. */
|
|
63
|
+
open: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A calendar cell: a day of the month (with no slots: `slots` is empty), or `null` before/after it. */
|
|
67
|
+
export type PickerCell = PickerDay | null;
|
|
68
|
+
|
|
69
|
+
export interface PickerView {
|
|
70
|
+
month: { key: string; label: string };
|
|
71
|
+
weekdays: Array<{ short: string; long: string }>;
|
|
72
|
+
/** Weeks of seven cells, Monday first. */
|
|
73
|
+
weeks: PickerCell[][];
|
|
74
|
+
/** The month's days that have slots, earliest first. */
|
|
75
|
+
days: PickerDay[];
|
|
76
|
+
/** The day button that takes focus first (roving tabindex): the first open day, else the first day. */
|
|
77
|
+
focusDay?: string;
|
|
78
|
+
/** `booking_from` values for the earlier and later pages. */
|
|
79
|
+
prev?: string;
|
|
80
|
+
next?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function formatter(locale: string, zone: string, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {
|
|
84
|
+
try {
|
|
85
|
+
return new Intl.DateTimeFormat(locale, { ...options, timeZone: zone });
|
|
86
|
+
} catch {
|
|
87
|
+
return new Intl.DateTimeFormat(locale, { ...options, timeZone: "UTC" });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
92
|
+
|
|
93
|
+
/** The local day (`YYYY-MM-DD`) of an instant in a zone (UTC for an unknown zone). */
|
|
94
|
+
export function localDay(ms: number, zone: string): string {
|
|
95
|
+
const parts = formatter("en-US", zone, { year: "numeric", month: "2-digit", day: "2-digit" }).formatToParts(ms);
|
|
96
|
+
const get = (type: string) => Number(parts.find((p) => p.type === type)?.value);
|
|
97
|
+
return `${get("year")}-${pad(get("month"))}-${pad(get("day"))}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A real calendar date `YYYY-MM-DD` as UTC midnight (ms), else `null`. */
|
|
101
|
+
function dayMs(key: string | null | undefined): number | null {
|
|
102
|
+
const m = DAY_KEY.exec(key ?? "");
|
|
103
|
+
if (!m) return null;
|
|
104
|
+
const ms = Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
105
|
+
return new Date(ms).toISOString().slice(0, 10) === key ? ms : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const keyOf = (ms: number) => new Date(ms).toISOString().slice(0, 10);
|
|
109
|
+
const monthFirst = (month: string, delta = 0) => {
|
|
110
|
+
const [y, m] = month.split("-").map(Number) as [number, number];
|
|
111
|
+
return keyOf(Date.UTC(y, m - 1 + delta, 1));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Whether the form books through the picker: a slot schedule, or two starts on one local day. */
|
|
115
|
+
export function usesPicker(
|
|
116
|
+
event: { occurrences?: PickerOccurrence[]; slots?: boolean; timezone?: string } | undefined,
|
|
117
|
+
zone = event?.timezone ?? "UTC",
|
|
118
|
+
): boolean {
|
|
119
|
+
if (!event) return false;
|
|
120
|
+
if (event.slots === true) return true;
|
|
121
|
+
const seen = new Set<string>();
|
|
122
|
+
for (const o of event.occurrences ?? []) {
|
|
123
|
+
const day = localDay(Date.parse(o.startsAt), zone);
|
|
124
|
+
if (seen.has(day)) return true;
|
|
125
|
+
seen.add(day);
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The occurrences grouped by local day, earliest first, with their times and places left. */
|
|
131
|
+
export function groupByDay(occurrences: readonly PickerOccurrence[], zone: string, locale: string): PickerDay[] {
|
|
132
|
+
const { t, plural } = translator(locale);
|
|
133
|
+
const time = formatter(locale, zone, { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
|
|
134
|
+
const date = formatter(locale, "UTC", { dateStyle: "full" });
|
|
135
|
+
const days = new Map<string, PickerDay>();
|
|
136
|
+
const sorted = occurrences
|
|
137
|
+
.map((o) => ({ o, ms: Date.parse(o.startsAt) }))
|
|
138
|
+
.filter(({ ms }) => Number.isFinite(ms))
|
|
139
|
+
.sort((a, b) => a.ms - b.ms);
|
|
140
|
+
for (const { o, ms } of sorted) {
|
|
141
|
+
const key = localDay(ms, zone);
|
|
142
|
+
let day = days.get(key);
|
|
143
|
+
if (!day) {
|
|
144
|
+
const label = date.format(dayMs(key) ?? ms);
|
|
145
|
+
day = { key, day: Number(key.slice(8)), label, buttonLabel: label, slots: [], open: false };
|
|
146
|
+
days.set(key, day);
|
|
147
|
+
}
|
|
148
|
+
const known = typeof o.available === "number";
|
|
149
|
+
const full = known && (o.available as number) <= 0;
|
|
150
|
+
const places = !known ? "" : full ? t("widget.picker.full") : plural("widget.picker.left", o.available as number);
|
|
151
|
+
const at = time.format(ms);
|
|
152
|
+
day.slots.push({ id: o.id, time: at, places, full, label: places ? `${at}, ${places}` : at });
|
|
153
|
+
if (!full) day.open = true;
|
|
154
|
+
}
|
|
155
|
+
for (const day of days.values()) {
|
|
156
|
+
if (!day.open) day.buttonLabel = t("widget.picker.dayFull", { date: day.label });
|
|
157
|
+
}
|
|
158
|
+
return [...days.values()];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The `from` to ask `public/event` for, for a `booking_from` day: its earliest possible local midnight. */
|
|
162
|
+
export function pickerFetchFrom(start: string | null | undefined): string | undefined {
|
|
163
|
+
const ms = dayMs(start);
|
|
164
|
+
return ms === null ? undefined : new Date(ms - EARLIEST_OFFSET).toISOString();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A link to another page of one event's picker: the current page's query without widget errors (other
|
|
169
|
+
* widgets' pages kept), and that widget's anchor.
|
|
170
|
+
*/
|
|
171
|
+
export function pickerHref(url: URL, start: string, eventId: string): string {
|
|
172
|
+
const next = new URL(url.href);
|
|
173
|
+
for (const name of Object.values(WIDGET_PARAMS)) next.searchParams.delete(name);
|
|
174
|
+
next.searchParams.set(pickerParam(eventId), start);
|
|
175
|
+
return `${next.pathname}${next.search}#${anchorId(eventId)}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface PickerOptions {
|
|
179
|
+
zone: string;
|
|
180
|
+
locale: string;
|
|
181
|
+
/** The `booking_from` parameter (a local `YYYY-MM-DD`), if any. */
|
|
182
|
+
start: string | null | undefined;
|
|
183
|
+
now: number;
|
|
184
|
+
/** `public/event` said there are more slots after the ones it sent. */
|
|
185
|
+
more?: boolean;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** One month of the picker: its calendar, its days with slots, and the paging links. */
|
|
189
|
+
export function pickerView(occurrences: readonly PickerOccurrence[], opts: PickerOptions): PickerView {
|
|
190
|
+
const today = localDay(opts.now, opts.zone);
|
|
191
|
+
const asked = dayMs(opts.start) === null ? today : (opts.start as string);
|
|
192
|
+
const start = asked > today ? asked : today;
|
|
193
|
+
const startMonth = start.slice(0, 7);
|
|
194
|
+
|
|
195
|
+
const grouped = groupByDay(occurrences, opts.zone, opts.locale).filter((d) => d.key >= start);
|
|
196
|
+
const partial = opts.more && grouped.length > 1 ? grouped.pop() : undefined;
|
|
197
|
+
const month = grouped.some((d) => d.key.startsWith(startMonth))
|
|
198
|
+
? startMonth
|
|
199
|
+
: (grouped[0]?.key.slice(0, 7) ?? startMonth);
|
|
200
|
+
const days = grouped.filter((d) => d.key.startsWith(month));
|
|
201
|
+
const following = monthFirst(month, 1);
|
|
202
|
+
|
|
203
|
+
let next: string | undefined;
|
|
204
|
+
if (partial?.key.startsWith(month)) next = partial.key;
|
|
205
|
+
else if (partial || grouped.some((d) => d.key >= following)) next = following;
|
|
206
|
+
|
|
207
|
+
let prev: string | undefined;
|
|
208
|
+
if (start > today) {
|
|
209
|
+
const back = start > monthFirst(startMonth) ? monthFirst(startMonth) : monthFirst(startMonth, -1);
|
|
210
|
+
prev = back > today ? back : today;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const [y, m] = month.split("-").map(Number) as [number, number];
|
|
214
|
+
const first = Date.UTC(y, m - 1, 1);
|
|
215
|
+
const length = new Date(Date.UTC(y, m, 0)).getUTCDate();
|
|
216
|
+
const byDay = new Map(days.map((d) => [d.day, d]));
|
|
217
|
+
const date = formatter(opts.locale, "UTC", { dateStyle: "full" });
|
|
218
|
+
const cells: PickerCell[] = Array.from({ length: (new Date(first).getUTCDay() + 6) % 7 }, () => null);
|
|
219
|
+
for (let d = 1; d <= length; d++) {
|
|
220
|
+
const key = `${month}-${pad(d)}`;
|
|
221
|
+
const label = date.format(Date.UTC(y, m - 1, d));
|
|
222
|
+
cells.push(byDay.get(d) ?? { key, day: d, label, buttonLabel: label, slots: [], open: false });
|
|
223
|
+
}
|
|
224
|
+
while (cells.length % 7 !== 0) cells.push(null);
|
|
225
|
+
const weeks = Array.from({ length: cells.length / 7 }, (_, i) => cells.slice(i * 7, i * 7 + 7));
|
|
226
|
+
|
|
227
|
+
const short = formatter(opts.locale, "UTC", { weekday: "short" });
|
|
228
|
+
const long = formatter(opts.locale, "UTC", { weekday: "long" });
|
|
229
|
+
// 5 January 2026 is a Monday.
|
|
230
|
+
const weekdays = Array.from({ length: 7 }, (_, i) => {
|
|
231
|
+
const ms = Date.UTC(2026, 0, 5 + i);
|
|
232
|
+
return { short: short.format(ms), long: long.format(ms) };
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const focus = days.find((d) => d.open) ?? days[0];
|
|
236
|
+
return {
|
|
237
|
+
month: { key: month, label: formatter(opts.locale, "UTC", { month: "long", year: "numeric" }).format(first) },
|
|
238
|
+
weekdays,
|
|
239
|
+
weeks,
|
|
240
|
+
days,
|
|
241
|
+
...(focus ? { focusDay: focus.key } : {}),
|
|
242
|
+
...(prev ? { prev } : {}),
|
|
243
|
+
...(next ? { next } : {}),
|
|
244
|
+
};
|
|
245
|
+
}
|
package/src/astro/lib/widget.ts
CHANGED
|
@@ -26,11 +26,20 @@ export interface PublicEvent {
|
|
|
26
26
|
minPerOrder?: number | null;
|
|
27
27
|
maxPerOrder?: number | null;
|
|
28
28
|
}>;
|
|
29
|
+
/** Upcoming open dates, earliest first: up to 200 from the asked `from` (T130). */
|
|
29
30
|
occurrences?: Array<{ id: string; startsAt: string; endsAt?: string | null; available?: number | null }>;
|
|
31
|
+
/** More dates follow the ones sent: ask again `from` a later day (T130). */
|
|
32
|
+
more?: boolean;
|
|
33
|
+
/** The event sells slots of a schedule (T129): the form uses the day-then-time picker (T130). */
|
|
34
|
+
slots?: boolean;
|
|
30
35
|
/** Public Turnstile site key, when the site owner configured one. */
|
|
31
36
|
turnstileSiteKey?: string;
|
|
32
37
|
/** True when the event requires a signed waiver (T066): the booking form then asks for attendees. */
|
|
33
38
|
waiver?: boolean;
|
|
39
|
+
/** Events Pro: that waiver is signed per attendee, so its seat rules can be checked before reserving. */
|
|
40
|
+
waiverEach?: boolean;
|
|
41
|
+
/** Events Pro (T160): the waiver is signed after payment (`waiverTiming: "after-payment"`), for a paid order. */
|
|
42
|
+
waiverAfter?: boolean;
|
|
34
43
|
/** True when the core takes promo codes (Events Pro, T078): the widget then shows a code field. */
|
|
35
44
|
promoCodes?: boolean;
|
|
36
45
|
/** True when a sold-out event takes a waitlist (T081): the widget then shows a "Join the waitlist" form. */
|
|
@@ -39,6 +48,18 @@ export interface PublicEvent {
|
|
|
39
48
|
questions?: PublicQuestion[];
|
|
40
49
|
}
|
|
41
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Ticket type names by id from a `public/event` answer, for `<BookingStatus>` (T134): the booking's
|
|
53
|
+
* lines carry only ids (UUIDs for types made in the editor). A hidden type is not listed there.
|
|
54
|
+
*/
|
|
55
|
+
/** Whether the booking page hands the booking to the suite's reconciliation: lookups, or void intents (T152). */
|
|
56
|
+
export const reconcileWanted = (b: Pick<BookingView, "waiver"> | undefined): boolean =>
|
|
57
|
+
Boolean(b?.waiver?.lookups || b?.waiver?.voids);
|
|
58
|
+
|
|
59
|
+
export function ticketNames(event: Pick<PublicEvent, "ticketTypes"> | undefined): Record<string, string> {
|
|
60
|
+
return Object.fromEntries((event?.ticketTypes ?? []).map((t) => [t.id, t.name]));
|
|
61
|
+
}
|
|
62
|
+
|
|
42
63
|
/** One custom question as `public/event` lists it (EV-FR-15). */
|
|
43
64
|
export interface PublicQuestion {
|
|
44
65
|
id: string;
|
|
@@ -57,6 +78,14 @@ export interface BookingView {
|
|
|
57
78
|
lines: Array<{ ticketTypeId: string; qty: number }>;
|
|
58
79
|
totals: { totalMinor: number; currency: string };
|
|
59
80
|
holdExpiresAt?: string;
|
|
81
|
+
/** The event's public info: the booked session (`startsAt`, in `timezone`) and `venue` lead the page (T157); `slug` for "Book again". */
|
|
82
|
+
event?: { title?: string; startsAt?: string; timezone?: string | null; venue?: string | null; slug?: string | null };
|
|
83
|
+
/** Why the organiser declined (`status: "declined"`), when they said. */
|
|
84
|
+
declineReason?: string | null;
|
|
85
|
+
/** Declined, a price was due and no money was taken (`closeBooking`). */
|
|
86
|
+
notCharged?: boolean;
|
|
87
|
+
/** Expired, this means it ran out waiting for the organiser's decision (Pro: not one approved but left unpaid). */
|
|
88
|
+
undecided?: boolean;
|
|
60
89
|
/** `qr`: Events Pro's QR matrix of `code` (T082), drawn by `<TicketPass>`; Free sends none. */
|
|
61
90
|
attendees: Array<{ name: string; ticketTypeId?: string; status: string; code?: string; qr?: unknown }>;
|
|
62
91
|
canCancel: boolean;
|
|
@@ -65,9 +94,18 @@ export interface BookingView {
|
|
|
65
94
|
calendar?: { query?: string };
|
|
66
95
|
/**
|
|
67
96
|
* While a waiver booking waits for signatures (T066): the refs still unsigned, and with Pro a signed
|
|
68
|
-
* receipt-lookup request for each, which the suite's reconciliation sends to e-sign.
|
|
97
|
+
* receipt-lookup request for each, which the suite's reconciliation sends to e-sign. Once the booking
|
|
98
|
+
* has ended (expired, cancelled), Pro lists instead a void intent per seat not signed (T152).
|
|
99
|
+
*/
|
|
100
|
+
waiver?: { refs: string[]; lookups?: Record<string, string>; voids?: Record<string, string> };
|
|
101
|
+
/** Events Pro (T160): the booking's waiver comes after payment, so a paid booking is confirmed with seats still to sign. */
|
|
102
|
+
waiverAfter?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Events Pro (T133): a waiver booking's attendee signing list. Each attendee then also carries
|
|
105
|
+
* `seat`, `signing`, `signs`, `email` and `minor` (`SigningAttendee` in `lib/attendees.ts`);
|
|
106
|
+
* `editable` says whether names and emails may still be changed, until `editUntil`.
|
|
69
107
|
*/
|
|
70
|
-
|
|
108
|
+
signingList?: { editable: boolean; editUntil?: string };
|
|
71
109
|
}
|
|
72
110
|
|
|
73
111
|
/** A custom question's field is `q:<question id>` (T080). */
|
|
@@ -263,11 +301,13 @@ const STATUSES = [
|
|
|
263
301
|
"held",
|
|
264
302
|
"awaiting_signature",
|
|
265
303
|
"awaiting_payment",
|
|
304
|
+
"awaiting_approval",
|
|
266
305
|
"confirmed",
|
|
267
306
|
"expired",
|
|
268
307
|
"cancelled",
|
|
269
308
|
"refunded",
|
|
270
309
|
"refunded_unavailable",
|
|
310
|
+
"declined",
|
|
271
311
|
] as const;
|
|
272
312
|
|
|
273
313
|
/** A booking status for people, in the locale's language; an unknown status is shown as it is. */
|
|
@@ -276,3 +316,36 @@ export const statusLabel = (status: string, locale?: string) =>
|
|
|
276
316
|
|
|
277
317
|
/** English status labels (the 1.0 API; components use `statusLabel`). */
|
|
278
318
|
export const STATUS_LABELS: Record<string, string> = Object.fromEntries(STATUSES.map((s) => [s, statusLabel(s, "en")]));
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The booking as it stands at `now`: a hold past its deadline has lapsed even before the sweeper moves it (the core
|
|
322
|
+
* refuses anything on it, and the waiver page already says so), so the page shows it as expired.
|
|
323
|
+
*/
|
|
324
|
+
export function asOfNow<T extends Pick<BookingView, "status" | "holdExpiresAt" | "canCancel">>(
|
|
325
|
+
booking: T,
|
|
326
|
+
now: number,
|
|
327
|
+
): T {
|
|
328
|
+
const until = booking.holdExpiresAt ? Date.parse(booking.holdExpiresAt) : Number.NaN;
|
|
329
|
+
if (!(until <= now)) return booking;
|
|
330
|
+
const { holdExpiresAt: _gone, ...rest } = booking;
|
|
331
|
+
return { ...rest, status: "expired", canCancel: false } as T;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** What a booking that ended without going ahead should say beyond its status (declined, or lapsed). */
|
|
335
|
+
export function endedNotes(
|
|
336
|
+
booking: Pick<BookingView, "status" | "declineReason" | "notCharged" | "undecided"> & {
|
|
337
|
+
totals?: BookingView["totals"];
|
|
338
|
+
},
|
|
339
|
+
locale?: string,
|
|
340
|
+
) {
|
|
341
|
+
if (booking.status === "expired") {
|
|
342
|
+
if (booking.undecided) return [t(locale, "booking.undecided")];
|
|
343
|
+
// A paid one has the payment section's "This booking expired": only what that does not say.
|
|
344
|
+
return [t(locale, booking.totals?.totalMinor ? "booking.signAgain" : "booking.lapsed")];
|
|
345
|
+
}
|
|
346
|
+
if (booking.status !== "declined") return [];
|
|
347
|
+
return [
|
|
348
|
+
...(booking.declineReason ? [t(locale, "booking.declinedReason", { reason: booking.declineReason })] : []),
|
|
349
|
+
...(booking.notCharged ? [t(locale, "booking.notCharged")] : []),
|
|
350
|
+
];
|
|
351
|
+
}
|
package/src/astro/virtual.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Provided by the integration's Vite plugin (`eventsIntegration({ pluginId })`).
|
|
2
2
|
declare module "virtual:semics-events/config" {
|
|
3
3
|
export const pluginId: string;
|
|
4
|
+
/** How the site dresses the plugin's own pages (`eventsIntegration({ page })`). */
|
|
5
|
+
export const page: import("./lib/page").PageOptions;
|
|
4
6
|
/** The e-sign core's plugin id, or `null` when e-sign is not configured (`eventsIntegration({ esignPluginId })`). */
|
|
5
7
|
export const esignPluginId: string | null;
|
|
6
8
|
/**
|
package/src/client/booking.ts
CHANGED
|
@@ -104,7 +104,9 @@ function showErrors(form: HTMLFormElement, bad: readonly BookingField[]): void {
|
|
|
104
104
|
}
|
|
105
105
|
const first = bad[0] && form.querySelector<HTMLElement>(`[data-field="${bad[0]}"]`);
|
|
106
106
|
if (!first) return;
|
|
107
|
-
|
|
107
|
+
// A fieldset: its first live input, or the day picker's focusable day (T130).
|
|
108
|
+
const live = 'input:not([disabled]), button[tabindex="0"]'; // i18n-ignore
|
|
109
|
+
const target = first.matches("fieldset") ? first.querySelector<HTMLElement>(live) : first;
|
|
108
110
|
target?.focus();
|
|
109
111
|
}
|
|
110
112
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgets what the suite's booking form kept for a refusal (`keep-form.ts` in the suite): a person who reaches the
|
|
3
|
+
* booking page has got past the form, and on a shared device their details must not linger. Self-contained.
|
|
4
|
+
*/
|
|
5
|
+
export function forgetKeptForms(storage: Pick<Storage, "length" | "key" | "removeItem">): void {
|
|
6
|
+
for (let i = storage.length - 1; i >= 0; i--) {
|
|
7
|
+
const key = storage.key(i);
|
|
8
|
+
if (key?.startsWith("semics-waiver-form:")) storage.removeItem(key);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
if (typeof document !== "undefined") forgetKeptForms(sessionStorage);
|
|
14
|
+
} catch {
|
|
15
|
+
// Storage is blocked: nothing was kept either.
|
|
16
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The booking form's day-then-time picker (T130, EV-FR-17). `<BookingWidget>` renders the month
|
|
3
|
+
* calendar (`[data-picker]`, hidden) beside a plain `<select name="occurrenceId">` grouped by day
|
|
4
|
+
* (`[data-picker-fallback]`), so the form works without this script. With it, the calendar replaces the
|
|
5
|
+
* select: a day button (`data-day`) shows that day's times (`[data-times]`, a radio group of buttons,
|
|
6
|
+
* full ones `aria-disabled`), and choosing a time sets the select, which is what the form posts.
|
|
7
|
+
*
|
|
8
|
+
* Keyboard: roving tabindex over the day buttons (arrows by a day, up and down by a week, Home/End; to
|
|
9
|
+
* the next day that has slots), and over a day's times (arrows, wrapping, skipping full ones). Text
|
|
10
|
+
* only comes from the page's markup; this script writes none. Self-contained (no imports).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const DELTAS: Record<string, number> = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: 7, ArrowUp: -7 };
|
|
14
|
+
|
|
15
|
+
/** The day (of `days`, ascending) a key moves to from `current`, or `null` to stay. */
|
|
16
|
+
export function stepDay(days: readonly number[], current: number, key: string, rtl: boolean): number | null {
|
|
17
|
+
// i18n-ignore
|
|
18
|
+
if (key === "Home") return days[0] ?? null;
|
|
19
|
+
// i18n-ignore
|
|
20
|
+
if (key === "End") return days[days.length - 1] ?? null;
|
|
21
|
+
let delta = DELTAS[key];
|
|
22
|
+
if (delta === undefined) return null;
|
|
23
|
+
if (rtl && Math.abs(delta) === 1) delta = -delta;
|
|
24
|
+
const target = current + delta;
|
|
25
|
+
const found = delta > 0 ? days.find((d) => d >= target) : [...days].reverse().find((d) => d <= target);
|
|
26
|
+
return found ?? null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The time (index into `open`) a key moves to from `current`, wrapping and skipping full ones. */
|
|
30
|
+
export function stepRadio(open: readonly boolean[], current: number, key: string, rtl: boolean): number | null {
|
|
31
|
+
let delta = DELTAS[key];
|
|
32
|
+
if (delta === undefined) return null;
|
|
33
|
+
delta = Math.sign(delta);
|
|
34
|
+
if (rtl && (key === "ArrowLeft" || key === "ArrowRight")) delta = -delta;
|
|
35
|
+
const n = open.length;
|
|
36
|
+
for (let i = 1; i <= n; i++) {
|
|
37
|
+
const at = (((current + delta * i) % n) + n) % n;
|
|
38
|
+
if (open[at] && at !== current) return at;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const isRtl = (el: Element) => getComputedStyle(el).direction === "rtl";
|
|
44
|
+
|
|
45
|
+
/** Wire one picker. Safe to call twice. */
|
|
46
|
+
export function enhancePicker(picker: HTMLElement): void {
|
|
47
|
+
if (picker.dataset.enhanced) return;
|
|
48
|
+
const form = picker.closest("form");
|
|
49
|
+
const select = form?.querySelector<HTMLSelectElement>('select[name="occurrenceId"]');
|
|
50
|
+
if (!form || !select) return;
|
|
51
|
+
picker.dataset.enhanced = "1";
|
|
52
|
+
const fallback = form.querySelector<HTMLElement>("[data-picker-fallback]");
|
|
53
|
+
if (fallback) fallback.hidden = true;
|
|
54
|
+
select.required = false;
|
|
55
|
+
picker.hidden = false;
|
|
56
|
+
|
|
57
|
+
const dayButtons = Array.from(picker.querySelectorAll<HTMLButtonElement>("button[data-day]"));
|
|
58
|
+
const groups = Array.from(picker.querySelectorAll<HTMLElement>("[data-times]"));
|
|
59
|
+
const hint = picker.querySelector<HTMLElement>("[data-picker-hint]");
|
|
60
|
+
const radios = (group: HTMLElement) => Array.from(group.querySelectorAll<HTMLButtonElement>('[role="radio"]'));
|
|
61
|
+
const isOpen = (b: HTMLElement) => b.getAttribute("aria-disabled") !== "true";
|
|
62
|
+
|
|
63
|
+
// The picker's own changes, which `showSelected` (below) need not follow.
|
|
64
|
+
let own = false;
|
|
65
|
+
const setSelect = (value: string) => {
|
|
66
|
+
if (select.value === value) return;
|
|
67
|
+
select.value = value;
|
|
68
|
+
own = true;
|
|
69
|
+
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
70
|
+
own = false;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const chooseTime = (button: HTMLButtonElement, focus: boolean) => {
|
|
74
|
+
if (!isOpen(button)) return;
|
|
75
|
+
for (const group of groups) {
|
|
76
|
+
for (const r of radios(group)) {
|
|
77
|
+
const on = r === button;
|
|
78
|
+
r.setAttribute("aria-checked", on ? "true" : "false");
|
|
79
|
+
if (group.contains(button)) r.tabIndex = on ? 0 : -1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (focus) button.focus();
|
|
83
|
+
setSelect(button.dataset.occurrence ?? "");
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const showDay = (button: HTMLButtonElement, focus: boolean) => {
|
|
87
|
+
const key = button.dataset.day ?? "";
|
|
88
|
+
for (const b of dayButtons) {
|
|
89
|
+
b.setAttribute("aria-pressed", b === button ? "true" : "false");
|
|
90
|
+
b.tabIndex = b === button ? 0 : -1;
|
|
91
|
+
}
|
|
92
|
+
if (focus) button.focus();
|
|
93
|
+
let keep = false;
|
|
94
|
+
for (const group of groups) {
|
|
95
|
+
const mine = group.dataset.times === key;
|
|
96
|
+
group.hidden = !mine;
|
|
97
|
+
if (mine) keep = radios(group).some((r) => r.dataset.occurrence === select.value);
|
|
98
|
+
}
|
|
99
|
+
if (hint) hint.hidden = true;
|
|
100
|
+
if (!keep) {
|
|
101
|
+
for (const group of groups) for (const r of radios(group)) r.setAttribute("aria-checked", "false");
|
|
102
|
+
setSelect("");
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
for (const button of dayButtons) {
|
|
107
|
+
button.addEventListener("click", () => showDay(button, false));
|
|
108
|
+
button.addEventListener("keydown", (event) => {
|
|
109
|
+
const days = dayButtons.map((b) => Number(b.dataset.n));
|
|
110
|
+
const to = stepDay(days, Number(button.dataset.n), event.key, isRtl(picker));
|
|
111
|
+
if (to === null) return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
const target = dayButtons.find((b) => Number(b.dataset.n) === to);
|
|
114
|
+
if (target) {
|
|
115
|
+
for (const b of dayButtons) b.tabIndex = b === target ? 0 : -1;
|
|
116
|
+
target.focus();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const group of groups) {
|
|
121
|
+
const list = radios(group);
|
|
122
|
+
for (const [i, radio] of list.entries()) {
|
|
123
|
+
radio.addEventListener("click", () => chooseTime(radio, false));
|
|
124
|
+
radio.addEventListener("keydown", (event) => {
|
|
125
|
+
const to = stepRadio(list.map(isOpen), i, event.key, isRtl(picker));
|
|
126
|
+
if (to === null) return;
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const target = list[to];
|
|
129
|
+
if (target) chooseTime(target, true);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// A value the browser kept (back/forward, a failed submit): show its day and time. Also when a script sets
|
|
135
|
+
// the select later and says so with `change` (the suite's refused-form restore, whose script may run after
|
|
136
|
+
// this one, T157); the picker's own changes are skipped.
|
|
137
|
+
const showSelected = () => {
|
|
138
|
+
if (own) return;
|
|
139
|
+
const kept =
|
|
140
|
+
select.value && picker.querySelector<HTMLButtonElement>(`[data-occurrence="${CSS.escape(select.value)}"]`);
|
|
141
|
+
const keptDay =
|
|
142
|
+
kept && dayButtons.find((b) => b.dataset.day === kept.closest<HTMLElement>("[data-times]")?.dataset.times);
|
|
143
|
+
if (kept && keptDay) {
|
|
144
|
+
showDay(keptDay, false);
|
|
145
|
+
chooseTime(kept, false);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
select.addEventListener("change", showSelected);
|
|
149
|
+
showSelected();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (typeof document !== "undefined") {
|
|
153
|
+
for (const picker of document.querySelectorAll<HTMLElement>("[data-picker]")) enhancePicker(picker);
|
|
154
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Print or save as PDF" on the booking page (T157): the button stays hidden without JavaScript (it could do
|
|
3
|
+
* nothing there; the browser's own Print still uses the page's print stylesheet). Self-contained; no text.
|
|
4
|
+
*/
|
|
5
|
+
export function wirePrint(doc: Document, print: () => void): void {
|
|
6
|
+
for (const button of doc.querySelectorAll<HTMLButtonElement>("button[data-print]")) {
|
|
7
|
+
button.hidden = false;
|
|
8
|
+
button.addEventListener("click", () => print());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (typeof document !== "undefined") wirePrint(document, () => window.print());
|