@profitstudio/booking-engine 0.0.0-stage → 2.0.0-beta.2

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 (114) hide show
  1. package/CHANGELOG.md +578 -0
  2. package/LICENSE +21 -0
  3. package/README.md +18 -2
  4. package/THIRD_PARTY_NOTICES.md +41 -0
  5. package/bin/booking-engine.mjs +575 -0
  6. package/bin/connect.mjs +408 -0
  7. package/bin/photos.mjs +82 -0
  8. package/dist/admin/BookingAdmin.d.ts +29 -0
  9. package/dist/admin/BookingAdmin.js +338 -0
  10. package/dist/admin/admin.css +1423 -0
  11. package/dist/admin/alerts.d.ts +10 -0
  12. package/dist/admin/alerts.js +11 -0
  13. package/dist/admin/booking-detail.d.ts +47 -0
  14. package/dist/admin/booking-detail.js +159 -0
  15. package/dist/admin/content-inputs.d.ts +15 -0
  16. package/dist/admin/content-inputs.js +105 -0
  17. package/dist/admin/context.d.ts +41 -0
  18. package/dist/admin/context.js +8 -0
  19. package/dist/admin/drawer.d.ts +14 -0
  20. package/dist/admin/drawer.js +56 -0
  21. package/dist/admin/feedback.d.ts +32 -0
  22. package/dist/admin/feedback.js +70 -0
  23. package/dist/admin/fields.d.ts +27 -0
  24. package/dist/admin/fields.js +146 -0
  25. package/dist/admin/fonts/OFL-Geist-Mono.txt +93 -0
  26. package/dist/admin/fonts/OFL-Geist.txt +93 -0
  27. package/dist/admin/fonts/geist-latin-wght-normal.woff2 +0 -0
  28. package/dist/admin/fonts/geist-mono-latin-wght-normal.woff2 +0 -0
  29. package/dist/admin/icons.d.ts +66 -0
  30. package/dist/admin/icons.js +72 -0
  31. package/dist/admin/image-upload.d.ts +58 -0
  32. package/dist/admin/image-upload.js +111 -0
  33. package/dist/admin/index.d.ts +7 -0
  34. package/dist/admin/index.js +6 -0
  35. package/dist/admin/lucide.generated.d.ts +521 -0
  36. package/dist/admin/lucide.generated.js +76 -0
  37. package/dist/admin/sections/BookingsSection.d.ts +1 -0
  38. package/dist/admin/sections/BookingsSection.js +137 -0
  39. package/dist/admin/sections/EmailSection.d.ts +8 -0
  40. package/dist/admin/sections/EmailSection.js +184 -0
  41. package/dist/admin/sections/HoursSection.d.ts +1 -0
  42. package/dist/admin/sections/HoursSection.js +110 -0
  43. package/dist/admin/sections/OverviewSection.d.ts +1 -0
  44. package/dist/admin/sections/OverviewSection.js +427 -0
  45. package/dist/admin/sections/ServicesSection.d.ts +1 -0
  46. package/dist/admin/sections/ServicesSection.js +236 -0
  47. package/dist/admin/sections/SettingsSection.d.ts +10 -0
  48. package/dist/admin/sections/SettingsSection.js +96 -0
  49. package/dist/admin/sections/WebsiteSection.d.ts +1 -0
  50. package/dist/admin/sections/WebsiteSection.js +228 -0
  51. package/dist/admin/sections.d.ts +22 -0
  52. package/dist/admin/sections.js +29 -0
  53. package/dist/admin/setup.d.ts +1 -0
  54. package/dist/admin/setup.js +45 -0
  55. package/dist/admin/today.d.ts +43 -0
  56. package/dist/admin/today.js +115 -0
  57. package/dist/admin/ui.d.ts +134 -0
  58. package/dist/admin/ui.js +220 -0
  59. package/dist/calendar.d.ts +64 -0
  60. package/dist/calendar.js +139 -0
  61. package/dist/client.d.ts +147 -0
  62. package/dist/client.js +507 -0
  63. package/dist/config.d.ts +25 -0
  64. package/dist/config.js +120 -0
  65. package/dist/content/image.d.ts +20 -0
  66. package/dist/content/image.js +90 -0
  67. package/dist/content/resolve.d.ts +12 -0
  68. package/dist/content/resolve.js +73 -0
  69. package/dist/content/schema.d.ts +119 -0
  70. package/dist/content/schema.js +53 -0
  71. package/dist/content/store.d.ts +48 -0
  72. package/dist/content/store.js +123 -0
  73. package/dist/content/validate.d.ts +33 -0
  74. package/dist/content/validate.js +177 -0
  75. package/dist/errors.d.ts +19 -0
  76. package/dist/errors.js +94 -0
  77. package/dist/generated/manifest.d.ts +6 -0
  78. package/dist/generated/manifest.js +7 -0
  79. package/dist/index.d.ts +20 -0
  80. package/dist/index.js +20 -0
  81. package/dist/presets/hair-salon.d.ts +8 -0
  82. package/dist/presets/hair-salon.js +94 -0
  83. package/dist/presets/index.d.ts +5 -0
  84. package/dist/presets/index.js +6 -0
  85. package/dist/preview.d.ts +18 -0
  86. package/dist/preview.js +134 -0
  87. package/dist/semver.d.ts +16 -0
  88. package/dist/semver.js +55 -0
  89. package/dist/time.d.ts +31 -0
  90. package/dist/time.js +138 -0
  91. package/dist/types.d.ts +477 -0
  92. package/dist/types.js +3 -0
  93. package/dist/vite.d.ts +52 -0
  94. package/dist/vite.js +150 -0
  95. package/docs/BUILD-A-SITE.md +203 -0
  96. package/docs/EMAIL-SETUP.md +224 -0
  97. package/docs/INTEGRATION.md +1112 -0
  98. package/engine.manifest.json +90 -0
  99. package/functions/booking-mailer/deno.json +6 -0
  100. package/functions/booking-mailer/index.ts +44 -0
  101. package/functions/booking-mailer/mailer.js +156 -0
  102. package/functions/booking-mailer/providers/index.js +42 -0
  103. package/functions/booking-mailer/providers/resend.js +75 -0
  104. package/functions/booking-mailer/templates.js +345 -0
  105. package/migrations/0001_core.sql +1673 -0
  106. package/migrations/0002_security_hardening.sql +711 -0
  107. package/migrations/0003_private_definers_and_holds.sql +808 -0
  108. package/migrations/0004_verified_requests.sql +1702 -0
  109. package/migrations/0005_scoped_mailer_credential.sql +347 -0
  110. package/migrations/0006_trusted_client_ip.sql +56 -0
  111. package/migrations/0007_site_content.sql +380 -0
  112. package/migrations/0008_service_images_opening_times.sql +328 -0
  113. package/package.json +85 -4
  114. package/templates/BOOKING_ENGINE.md +61 -0
@@ -0,0 +1,10 @@
1
+ import type { AdminSettings } from '../types.js';
2
+ /**
3
+ * Where the database sends new-request alerts (booking.verify_booking): the
4
+ * alerts address, else the public business email. Null: nobody is told about
5
+ * a new request, so the dashboard asks for an address before online booking.
6
+ */
7
+ export declare function alertsAddress(settings: Pick<AdminSettings, 'ownerNotificationEmail' | 'publicEmail'>): string | null;
8
+ /** Email page sub-views (go('email', …)): focus the alerts address, or the test email. */
9
+ export declare const ALERTS_VIEW = "alerts";
10
+ export declare const TEST_EMAIL_VIEW = "test";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Where the database sends new-request alerts (booking.verify_booking): the
3
+ * alerts address, else the public business email. Null: nobody is told about
4
+ * a new request, so the dashboard asks for an address before online booking.
5
+ */
6
+ export function alertsAddress(settings) {
7
+ return settings.ownerNotificationEmail || settings.publicEmail || null;
8
+ }
9
+ /** Email page sub-views (go('email', …)): focus the alerts address, or the test email. */
10
+ export const ALERTS_VIEW = 'alerts';
11
+ export const TEST_EMAIL_VIEW = 'test';
@@ -0,0 +1,47 @@
1
+ import type { AdminBooking, AdminService, BookingStatus } from '../types.js';
2
+ import { type EmailDelivery } from './context.js';
3
+ import type { ConfirmInput } from './feedback.js';
4
+ export interface BookingAction {
5
+ status: Exclude<BookingStatus, 'pending'>;
6
+ label: string;
7
+ tone: 'primary' | 'danger' | 'secondary';
8
+ /** Asked first, for answers that email the customer and cannot be taken back. */
9
+ confirm?: ConfirmInput;
10
+ }
11
+ /** What an answer means for the customer's inbox — in the confirm dialogs. */
12
+ export declare const notifies: (b: AdminBooking, delivery?: EmailDelivery) => string;
13
+ /** The line under a request's answers. */
14
+ export declare const answerNote: (b: AdminBooking, delivery?: EmailDelivery) => string;
15
+ /** The answers that make sense for a booking right now. */
16
+ export declare function actionsFor(b: AdminBooking, now?: number, delivery?: EmailDelivery): BookingAction[];
17
+ /** The toast after an answer. */
18
+ export declare function doneMessage(b: AdminBooking, a: BookingAction, delivery?: EmailDelivery): {
19
+ title: string;
20
+ detail?: string;
21
+ };
22
+ /**
23
+ * Run an answer: ask first when needed, save it, tell the owner, recount the
24
+ * badge. Resolves to the updated booking, or an error message to show in place.
25
+ */
26
+ export declare function useBookingActions(): (b: AdminBooking, a: BookingAction,
27
+ /** Called once the owner has confirmed, just before saving (to show the button's spinner). */
28
+ onStart?: () => void) => Promise<{
29
+ booking?: AdminBooking;
30
+ error?: string;
31
+ skipped?: boolean;
32
+ }>;
33
+ /** "Today", "Tomorrow" or "Fri, Nov 6". */
34
+ export declare function dayWord(date: string, timezone: string, locale: string, options?: Intl.DateTimeFormatOptions): string;
35
+ /** A booking's price, honest about starting prices and prices on request. */
36
+ export declare function priceText(b: AdminBooking, services: AdminService[] | null, locale: string): string;
37
+ /** The detail panel for one booking. */
38
+ export declare function BookingDrawer({ booking, services, docked, onClose, onChanged, onPrevious, onNext, }: {
39
+ booking: AdminBooking;
40
+ services: AdminService[] | null;
41
+ docked?: boolean;
42
+ onClose: () => void;
43
+ /** After an answer is saved (with the updated booking). */
44
+ onChanged: (b: AdminBooking) => void;
45
+ onPrevious?: (() => void) | null;
46
+ onNext?: (() => void) | null;
47
+ }): import("react").JSX.Element;
@@ -0,0 +1,159 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // One booking, in detail, and the answers the owner can give. Shared by Today
3
+ // (requests panel, schedule) and Bookings (the list's detail panel). The only
4
+ // actions are the engine's: setBookingStatus → confirmed, cancelled, completed
5
+ // or no_show; plus email and phone links.
6
+ import { useRef, useState } from 'react';
7
+ import { formatClockTime, formatDate, formatDateTime, formatMoney, timeZoneLabel, todayInTimeZone, addDays } from '../time.js';
8
+ import { useAdmin } from './context.js';
9
+ import { Drawer } from './drawer.js';
10
+ import { Icon } from './icons.js';
11
+ import { holdState } from './today.js';
12
+ import { Button, IconButton, Notice, StatusBadge, firstName, formatMinutes, formatSpan, useNow } from './ui.js';
13
+ /** What an answer means for the customer's inbox — in the confirm dialogs. */
14
+ export const notifies = (b, delivery = 'live') => delivery === 'none'
15
+ ? 'No email is sent from this demo.'
16
+ : b.emailVerified
17
+ ? `${firstName(b.customer.name)} gets an email.`
18
+ : `${firstName(b.customer.name)}’s email address was never verified, so they are not emailed — contact them directly.`;
19
+ /** The line under a request's answers. */
20
+ export const answerNote = (b, delivery = 'live') => delivery === 'none'
21
+ ? 'No email is sent from this demo — answer here and see the result on the website.'
22
+ : b.emailVerified
23
+ ? `${b.customer.name} gets an email with your answer.`
24
+ : `${b.customer.name} is not emailed (unverified address).`;
25
+ /** The answers that make sense for a booking right now. */
26
+ export function actionsFor(b, now = Date.now(), delivery = 'live') {
27
+ const started = Date.parse(b.startsAt) <= now;
28
+ if (b.status === 'pending' || b.status === 'expired') {
29
+ return [
30
+ {
31
+ status: 'cancelled',
32
+ label: 'Decline',
33
+ tone: 'danger',
34
+ confirm: {
35
+ title: `Decline ${b.customer.name}’s request?`,
36
+ body: `The time opens again for other customers. ${notifies(b, delivery)}`,
37
+ confirmLabel: 'Decline request',
38
+ cancelLabel: 'Keep the request',
39
+ },
40
+ },
41
+ { status: 'confirmed', label: 'Confirm', tone: 'primary' },
42
+ ];
43
+ }
44
+ if (b.status === 'confirmed') {
45
+ const cancel = {
46
+ status: 'cancelled',
47
+ label: 'Cancel booking',
48
+ tone: 'danger',
49
+ confirm: {
50
+ title: `Cancel ${b.customer.name}’s appointment?`,
51
+ body: `The time opens again for other customers. ${notifies(b, delivery)}`,
52
+ confirmLabel: 'Cancel appointment',
53
+ cancelLabel: 'Keep it',
54
+ },
55
+ };
56
+ return started
57
+ ? [{ status: 'no_show', label: 'No-show', tone: 'secondary' }, { status: 'completed', label: 'Mark as done', tone: 'primary' }, cancel]
58
+ : [cancel];
59
+ }
60
+ return [];
61
+ }
62
+ /** The toast after an answer. */
63
+ export function doneMessage(b, a, delivery = 'live') {
64
+ const name = b.customer.name;
65
+ const emailed = delivery === 'live' && b.emailVerified ? `${firstName(name)} gets an email` : undefined;
66
+ if (a.status === 'confirmed')
67
+ return { title: `${name} confirmed`, detail: emailed };
68
+ if (a.status === 'cancelled')
69
+ return { title: b.status === 'confirmed' ? `${name}’s appointment cancelled` : `${name}’s request declined`, detail: emailed };
70
+ if (a.status === 'completed')
71
+ return { title: `${name} marked as done` };
72
+ return { title: `${name} marked as a no-show` };
73
+ }
74
+ /**
75
+ * Run an answer: ask first when needed, save it, tell the owner, recount the
76
+ * badge. Resolves to the updated booking, or an error message to show in place.
77
+ */
78
+ export function useBookingActions() {
79
+ const { engine, toast, confirm, refreshCounts, emailDelivery } = useAdmin();
80
+ return async (b, a, onStart) => {
81
+ if (a.confirm && !(await confirm(a.confirm)))
82
+ return { skipped: true };
83
+ onStart?.();
84
+ const r = await engine.admin.setBookingStatus(b.id, a.status);
85
+ if (!r.ok)
86
+ return { error: r.error.message };
87
+ toast({ kind: 'success', ...doneMessage(b, a, emailDelivery) });
88
+ refreshCounts();
89
+ return { booking: r.data };
90
+ };
91
+ }
92
+ /** "Today", "Tomorrow" or "Fri, Nov 6". */
93
+ export function dayWord(date, timezone, locale, options = { weekday: 'short', month: 'short', day: 'numeric' }) {
94
+ const today = todayInTimeZone(timezone);
95
+ if (date === today)
96
+ return 'Today';
97
+ if (date === addDays(today, 1))
98
+ return 'Tomorrow';
99
+ return formatDate(date, locale, options);
100
+ }
101
+ /** A booking's price, honest about starting prices and prices on request. */
102
+ export function priceText(b, services, locale) {
103
+ if (b.priceCents === null)
104
+ return 'Price on request';
105
+ const from = services?.find((s) => s.id === b.serviceId)?.priceFrom ? 'from ' : '';
106
+ return `${from}${formatMoney(b.priceCents, b.currency, locale)}`;
107
+ }
108
+ /** The detail panel for one booking. */
109
+ export function BookingDrawer({ booking, services, docked, onClose, onChanged, onPrevious, onNext, }) {
110
+ const { settings, emailDelivery } = useAdmin();
111
+ const run = useBookingActions();
112
+ const now = useNow(15_000);
113
+ const [busy, setBusy] = useState(null);
114
+ const [error, setError] = useState(null);
115
+ const titleRef = useRef(null);
116
+ const b = booking;
117
+ const tz = settings.timezone;
118
+ const locale = settings.locale;
119
+ const time = (hhmm) => formatClockTime(hhmm, locale);
120
+ const at = (iso) => formatDateTime(iso, tz, locale, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
121
+ const hold = b.status === 'pending' || b.status === 'expired' ? holdState(b, settings.pendingHoldMinutes, now) : null;
122
+ const actions = actionsFor(b, now, emailDelivery);
123
+ const minutes = Math.round((Date.parse(b.endsAt) - Date.parse(b.startsAt)) / 60_000);
124
+ const name = firstName(b.customer.name);
125
+ const phoneHref = b.customer.phone ? `tel:${b.customer.phone.replace(/[^\d+]/g, '')}` : null;
126
+ const primaryRow = actions.filter((a) => !(a.status === 'cancelled' && b.status === 'confirmed' && actions.length > 1));
127
+ const trailing = actions.find((a) => a.status === 'cancelled' && b.status === 'confirmed' && actions.length > 1);
128
+ const word = dayWord(b.date, tz, locale);
129
+ const longDate = formatDate(b.date, locale, { weekday: 'long', month: 'long', day: 'numeric' });
130
+ const dayLine = word === 'Today' || word === 'Tomorrow' ? `${word} · ${longDate}` : longDate;
131
+ async function act(a) {
132
+ setError(null);
133
+ const r = await run(b, a, () => setBusy(a.status));
134
+ setBusy(null);
135
+ if (r.error)
136
+ setError({ id: b.id, text: r.error });
137
+ if (r.booking)
138
+ onChanged(r.booking);
139
+ }
140
+ const shownError = error && error.id === b.id ? error.text : null;
141
+ return (_jsxs(Drawer, { docked: docked, onClose: onClose, labelledBy: "pbe-booking-title", focusRef: titleRef, restoreFocus: !docked, children: [_jsxs("div", { className: "pbe-drawer-bar", children: [_jsxs("span", { className: "pbe-drawer-kind", children: [_jsx(StatusBadge, { status: b.status }), _jsx("span", { className: "pbe-mono", children: b.reference })] }), _jsxs("div", { className: "pbe-drawer-nav", children: [onPrevious !== undefined ? _jsx(IconButton, { icon: "up", label: "Previous booking", disabled: !onPrevious, onClick: () => onPrevious?.() }) : null, onNext !== undefined ? _jsx(IconButton, { icon: "down", label: "Next booking", disabled: !onNext, onClick: () => onNext?.() }) : null, _jsx(IconButton, { icon: "close", label: "Close details", onClick: onClose })] })] }), _jsxs("div", { className: "pbe-drawer-body", children: [_jsxs("div", { children: [_jsx("h2", { id: "pbe-booking-title", className: "pbe-drawer-title", ref: titleRef, tabIndex: -1, children: b.customer.name }), _jsx("p", { className: "pbe-help", style: { marginTop: 4 }, children: b.source === 'website' ? 'Booked on your website' : 'Added in the dashboard' })] }), _jsxs("div", { className: "pbe-when", children: [_jsx("span", { className: "pbe-when-day", children: dayLine }), _jsxs("span", { className: "pbe-when-time", children: [time(b.time), " \u2013 ", time(b.endTime)] }), _jsxs("span", { className: "pbe-when-dur", children: [formatMinutes(minutes), " \u00B7 ", timeZoneLabel(tz, locale)] }), _jsxs("span", { className: "pbe-when-svc", children: [_jsx("b", { children: b.serviceName }), _jsx("span", { className: "pbe-tnum", children: priceText(b, services, locale) })] })] }), hold ? (_jsxs("div", { className: `pbe-hold-card${hold.ended ? ' pbe-hold-card--ended' : ''}`, children: [_jsx("span", { className: "pbe-hold-card-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "hold", size: 18 }) }), _jsx("div", { children: hold.ended ? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "pbe-hold-card-title", children: ["Hold ended ", _jsxs("span", { children: [b.holdExpiresAt ? formatSpan(now - Date.parse(b.holdExpiresAt)) : '', " ago"] })] }), _jsx("p", { className: "pbe-hold-card-text", children: "The time is open to other customers again. You can still confirm the request if nobody has booked it." })] })) : (_jsxs(_Fragment, { children: [_jsxs("p", { className: "pbe-hold-card-title", children: ["Time held \u00B7 ", _jsxs("span", { children: [formatSpan(hold.left), " left"] })] }), _jsxs("p", { className: "pbe-hold-card-text", children: ["Until", ' ', todayInTimeZone(tz, new Date(Date.parse(b.holdExpiresAt))) === todayInTimeZone(tz)
142
+ ? `${formatDateTime(b.holdExpiresAt, tz, locale, { hour: 'numeric', minute: '2-digit' })} today`
143
+ : formatDateTime(b.holdExpiresAt, tz, locale, { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }), ". If you have not answered by then, the request expires and ", time(b.time), " opens again."] })] })) })] })) : null, shownError ? _jsx(Notice, { kind: "error", children: shownError }) : null, _jsxs("section", { "aria-labelledby": "pbe-contact-title", children: [_jsx("h3", { id: "pbe-contact-title", className: "pbe-block-title", children: "Contact" }), _jsxs("div", { className: "pbe-contact", children: [_jsxs("a", { className: "pbe-contact-row", href: `mailto:${b.customer.email}`, children: [_jsx(Icon, { name: "email" }), _jsx("span", { className: "pbe-contact-value", children: b.customer.email }), _jsx("span", { className: "pbe-contact-action", children: "Email" })] }), phoneHref ? (_jsxs("a", { className: "pbe-contact-row", href: phoneHref, children: [_jsx(Icon, { name: "phone" }), _jsx("span", { className: "pbe-contact-value", children: b.customer.phone }), _jsx("span", { className: "pbe-contact-action", children: "Call" })] })) : null] })] }), _jsxs("dl", { className: "pbe-facts", children: [_jsx("dt", { children: "Reference" }), _jsxs("dd", { children: [_jsx("span", { className: "pbe-mono", children: b.reference }), _jsx(CopyButton, { text: b.reference })] }), _jsx("dt", { children: "Email" }), _jsx("dd", { children: b.emailVerified ? (_jsx("span", { className: "pbe-ok-text", children: "Verified with a code" })) : (_jsx("span", { className: "pbe-warn-text", children: "Not verified \u00B7 not emailed automatically" })) }), _jsx("dt", { children: "Note" }), _jsx("dd", { children: b.notes ? `“${b.notes}”` : _jsx("span", { className: "pbe-muted", children: "No note" }) })] }), _jsxs("section", { "aria-labelledby": "pbe-activity-title", children: [_jsx("h3", { id: "pbe-activity-title", className: "pbe-block-title", children: "Activity" }), _jsxs("ol", { className: "pbe-activity", children: [_jsxs("li", { children: [_jsx("span", { className: "pbe-act-dot", "aria-hidden": "true", children: _jsx(Icon, { name: "check" }) }), _jsxs("span", { children: [_jsx("b", { children: b.source === 'website' ? 'Requested' : 'Added' }), " ", b.source === 'website' ? 'on your website' : 'in the dashboard'] }), _jsx("time", { dateTime: b.createdAt, children: at(b.createdAt) })] }), b.emailVerified ? (_jsxs("li", { children: [_jsx("span", { className: "pbe-act-dot", "aria-hidden": "true", children: _jsx(Icon, { name: "check" }) }), _jsxs("span", { children: [_jsx("b", { children: "Email verified" }), " by ", name] }), _jsx("span", {})] })) : null, b.status === 'pending' || b.status === 'expired' ? (_jsxs(_Fragment, { children: [_jsxs("li", { children: [_jsx("span", { className: "pbe-act-dot pbe-act-dot--now", "aria-hidden": "true" }), _jsx("span", { children: _jsx("b", { children: "Waiting for your answer" }) }), _jsx("span", {})] }), b.holdExpiresAt ? (_jsxs("li", { children: [_jsx("span", { className: `pbe-act-dot${hold?.ended ? '' : ' pbe-act-dot--future'}`, "aria-hidden": "true", children: hold?.ended ? _jsx(Icon, { name: "check" }) : null }), _jsx("span", { children: hold?.ended ? 'Hold ended' : 'Hold ends' }), _jsx("time", { dateTime: b.holdExpiresAt, children: at(b.holdExpiresAt) })] })) : null] })) : (_jsxs("li", { children: [_jsx("span", { className: "pbe-act-dot", "aria-hidden": "true", children: _jsx(Icon, { name: "check" }) }), _jsx("span", { children: _jsx("b", { children: b.status === 'confirmed'
144
+ ? 'Confirmed'
145
+ : b.status === 'cancelled'
146
+ ? 'Cancelled'
147
+ : b.status === 'completed'
148
+ ? 'Marked as done'
149
+ : 'Marked as a no-show' }) }), _jsx("time", { dateTime: b.statusChangedAt, children: at(b.statusChangedAt) })] }))] })] })] }), actions.length ? (_jsxs("div", { className: "pbe-drawer-foot", children: [b.status === 'pending' || b.status === 'expired' ? (_jsx("p", { className: "pbe-drawer-foot-note", children: answerNote(b, emailDelivery) })) : null, _jsx("div", { className: `pbe-drawer-actions${primaryRow.length === 2 ? ' pbe-drawer-actions--weighted' : ''}`, children: primaryRow.map((a) => (_jsx(Button, { variant: a.tone === 'primary' ? 'primary' : a.tone === 'danger' ? 'danger-quiet' : 'secondary', icon: a.status === 'confirmed' || a.status === 'completed' ? 'check' : undefined, loading: busy === a.status, disabled: busy !== null && busy !== a.status, onClick: () => void act(a), children: a.status === 'confirmed' ? 'Confirm request' : a.label }, a.status))) }), trailing ? (_jsx(Button, { variant: "quiet", size: "sm", className: "pbe-button--danger-text", loading: busy === 'cancelled', disabled: busy !== null && busy !== 'cancelled', onClick: () => void act(trailing), children: trailing.label })) : null] })) : null] }));
150
+ }
151
+ function CopyButton({ text }) {
152
+ const [copied, setCopied] = useState(false);
153
+ return (_jsx(IconButton, { icon: copied ? 'check' : 'copy', size: "sm", label: copied ? 'Copied' : 'Copy reference', onClick: () => {
154
+ void navigator.clipboard?.writeText(text).then(() => {
155
+ setCopied(true);
156
+ window.setTimeout(() => setCopied(false), 1500);
157
+ });
158
+ } }));
159
+ }
@@ -0,0 +1,15 @@
1
+ import type { BookingEngine } from '../client.js';
2
+ import type { ContentField, ListItemField } from '../content/schema.js';
3
+ export interface InputProps<F> {
4
+ field: F;
5
+ value: unknown;
6
+ onChange: (value: unknown) => void;
7
+ problem?: string | null;
8
+ engine: BookingEngine;
9
+ /** Shown when the field still uses the website's default. */
10
+ isDefault?: boolean;
11
+ onReset?: () => void;
12
+ idPrefix?: string;
13
+ }
14
+ /** The input for any field type. */
15
+ export declare function ContentInput(props: InputProps<ContentField | ListItemField>): import("react").JSX.Element;
@@ -0,0 +1,105 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // Inputs for website content fields — one per field type. Plain text only:
3
+ // nothing the owner types is ever rendered as HTML, here or on the website.
4
+ import { useEffect, useId, useState } from 'react';
5
+ import { contrastRatio, emptyValue, isHexColor, isStoredImage, LIST_MAX, LONG_TEXT_MAX, TEXT_MAX } from '../content/validate.js';
6
+ import { Icon } from './icons.js';
7
+ import { IMAGE_PREPARATION_TEXT, IMAGE_TYPES_TEXT, ImageFrame, UploadProblem, useImageUpload } from './image-upload.js';
8
+ import { Badge, Button, IconButton } from './ui.js';
9
+ function Head({ htmlFor, label, isDefault, onReset, legend, extra }) {
10
+ return (_jsxs("div", { className: "pbe-field-head", children: [legend ? _jsx("legend", { children: label }) : _jsx("label", { htmlFor: htmlFor, children: label }), isDefault ? _jsx("span", { className: "pbe-tag", children: "Website default" }) : null, extra, onReset && !isDefault ? (_jsxs("button", { type: "button", className: "pbe-link-button pbe-link-button--quiet pbe-reset", onClick: onReset, children: [_jsx(Icon, { name: "reset" }), "Use default"] })) : null] }));
11
+ }
12
+ function Foot({ id, help, problem }) {
13
+ return (_jsxs(_Fragment, { children: [help ? (_jsx("p", { className: "pbe-help", id: `${id}-help`, children: help })) : null, problem ? (_jsxs("p", { className: "pbe-field-error", id: `${id}-error`, role: "alert", children: [_jsx(Icon, { name: "error" }), problem] })) : null] }));
14
+ }
15
+ const describedBy = (id, help, problem) => [help ? `${id}-help` : '', problem ? `${id}-error` : ''].filter(Boolean).join(' ') || undefined;
16
+ function TextInput({ field, value, onChange, problem, isDefault, onReset, idPrefix = '' }) {
17
+ const id = `pbe-c-${idPrefix}${field.id.replace(/\W/g, '-')}`;
18
+ const text = typeof value === 'string' ? value : '';
19
+ const limit = field.type === 'link' ? null : Math.min(field.maxLength ?? (field.type === 'text' ? TEXT_MAX : LONG_TEXT_MAX), 5000);
20
+ const counter = limit !== null ? (_jsxs("span", { className: `pbe-counter${text.trim().length > limit ? ' pbe-counter--over' : ''}`, "aria-live": "polite", children: [text.trim().length, "/", limit] })) : null;
21
+ const common = {
22
+ id,
23
+ value: text,
24
+ 'aria-invalid': problem ? true : undefined,
25
+ 'aria-describedby': describedBy(id, field.help, problem),
26
+ onChange: (e) => onChange(e.target.value),
27
+ };
28
+ return (_jsxs("div", { className: `pbe-field${problem ? ' pbe-field--error' : ''}`, children: [_jsx(Head, { htmlFor: id, label: field.label, isDefault: isDefault, onReset: onReset, extra: counter }), field.type === 'longText' ? (_jsx("textarea", { ...common, rows: field.rows ?? 4 })) : (_jsx("input", { ...common, type: "text", inputMode: field.type === 'link' ? 'url' : undefined, placeholder: field.type === 'text' ? field.placeholder : field.type === 'link' ? 'https://…' : undefined })), _jsx(Foot, { id: id, help: field.help ?? (field.type === 'link' ? 'A full https:// address, mailto:, tel:, #section or /page.' : undefined), problem: problem })] }));
29
+ }
30
+ function ImageInput({ field, value, onChange, problem, engine, isDefault, onReset, idPrefix = '' }) {
31
+ const id = `pbe-c-${idPrefix}${field.id.replace(/\W/g, '-')}`;
32
+ const stored = isStoredImage(value) ? value : null;
33
+ const fallback = isDefault ? field.default : null;
34
+ const src = stored ? engine.mediaUrl(stored.path) : fallback?.src ?? null;
35
+ const alt = stored ? stored.alt : fallback?.alt ?? '';
36
+ const upload = useImageUpload((file) => engine.admin.uploadSiteImage(file), (image) => onChange({ path: image.path, alt: stored?.alt ?? fallback?.alt ?? '', width: image.width, height: image.height }));
37
+ return (_jsxs("fieldset", { className: `pbe-fieldset${problem ? ' pbe-field--error' : ''}`, "aria-describedby": describedBy(id, field.help, problem), children: [_jsx(Head, { label: field.label, isDefault: isDefault, onReset: field.default ? onReset : undefined, legend: true }), _jsxs("div", { className: `pbe-image-field${upload.over ? ' pbe-image-field--over' : ''}`, ...upload.dropTarget, children: [_jsx(ImageFrame, { src: src, ratio: field.type === 'image' && field.aspectRatio ? field.aspectRatio : undefined }), _jsxs("div", { className: "pbe-image-actions", children: [_jsxs("div", { className: "pbe-form-actions", children: [upload.input, _jsx(Button, { icon: "upload", loading: upload.busy, onClick: upload.choose, children: src ? 'Replace image' : 'Upload image' }), src ? (_jsx(Button, { variant: "danger-quiet", disabled: upload.busy, onClick: () => onChange(null), children: "Remove" })) : null] }), stored ? (_jsxs("div", { className: "pbe-field", children: [_jsx("label", { htmlFor: `${id}-alt`, children: "Image description" }), _jsx("input", { id: `${id}-alt`, type: "text", value: stored.alt, maxLength: 300, "aria-describedby": `${id}-alt-help`, onChange: (e) => onChange({ ...stored, alt: e.target.value }) }), _jsx("p", { className: "pbe-help", id: `${id}-alt-help`, children: "What the photo shows, for people who cannot see it (e.g. \u201CTwo people talking at a table by the window\u201D)." })] })) : alt ? (_jsxs("p", { className: "pbe-help", children: ["Description: ", alt] })) : null, _jsxs("p", { className: "pbe-help", children: [IMAGE_TYPES_TEXT, ". ", IMAGE_PREPARATION_TEXT] }), _jsx(UploadProblem, { error: upload.error })] })] }), _jsx(Foot, { id: id, help: field.help, problem: problem })] }));
38
+ }
39
+ function ColorInput({ field, value, onChange, problem, isDefault, onReset }) {
40
+ const id = `pbe-c-${field.id.replace(/\W/g, '-')}`;
41
+ const color = typeof value === 'string' ? value : field.default;
42
+ const [text, setText] = useState(color);
43
+ // Follow outside changes (e.g. "Use default") without fighting the owner's typing.
44
+ useEffect(() => {
45
+ setText((current) => (current.trim().toLowerCase() === String(color).toLowerCase() ? current : color));
46
+ }, [color]);
47
+ const valid = isHexColor(color);
48
+ const ratio = valid && field.contrastWith ? contrastRatio(color, field.contrastWith) : null;
49
+ const readable = ratio !== null && field.minContrast ? ratio >= field.minContrast : null;
50
+ return (_jsxs("div", { className: `pbe-field${problem ? ' pbe-field--error' : ''}`, children: [_jsx(Head, { htmlFor: `${id}-hex`, label: field.label, isDefault: isDefault, onReset: onReset }), _jsxs("div", { className: "pbe-color-row", children: [_jsx("input", { type: "color", "aria-label": `${field.label} picker`, value: valid ? color : field.default, onChange: (e) => {
51
+ setText(e.target.value);
52
+ onChange(e.target.value);
53
+ } }), _jsx("input", { id: `${id}-hex`, type: "text", value: text, spellCheck: false, "aria-invalid": problem ? true : undefined, "aria-describedby": describedBy(id, field.help, problem), onChange: (e) => {
54
+ setText(e.target.value);
55
+ onChange(e.target.value.trim());
56
+ } }), ratio !== null && field.contrastWith ? (_jsxs("span", { className: "pbe-contrast", children: [_jsx("span", { className: "pbe-contrast-sample", style: { background: field.contrastWith, color: valid ? color : undefined }, "aria-hidden": "true", children: "Aa" }), _jsxs("span", { className: "pbe-tnum", children: [ratio.toFixed(1), ":1"] }), readable === null ? null : readable ? _jsx(Badge, { tone: "ok", children: "Readable" }) : _jsx(Badge, { tone: "danger", children: "Too faint" })] })) : null] }), _jsx(Foot, { id: id, help: field.help, problem: problem })] }));
57
+ }
58
+ function ChoiceInput({ field, value, onChange, problem, isDefault, onReset }) {
59
+ const name = useId();
60
+ const id = `pbe-c-${field.id.replace(/\W/g, '-')}`;
61
+ return (_jsxs("fieldset", { className: "pbe-fieldset", "aria-describedby": describedBy(id, field.help, problem), children: [_jsx(Head, { label: field.label, isDefault: isDefault, onReset: onReset, legend: true }), _jsx("div", { className: "pbe-choices", children: field.options.map((option) => (_jsxs("label", { className: "pbe-choice", children: [_jsx("input", { type: "radio", name: name, value: option.value, checked: value === option.value, onChange: () => onChange(option.value) }), _jsxs("span", { children: [_jsx("strong", { children: option.label }), option.description ? _jsx("span", { className: "pbe-help", children: option.description }) : null] })] }, option.value))) }), _jsx(Foot, { id: id, help: field.help, problem: problem })] }));
62
+ }
63
+ function ToggleInput({ field, value, onChange, idPrefix = '' }) {
64
+ const id = `pbe-c-${idPrefix}${field.id.replace(/\W/g, '-')}`;
65
+ return (_jsxs("div", { className: "pbe-switch-row", children: [_jsx("input", { id: id, type: "checkbox", role: "switch", className: "pbe-switch", checked: value === true, "aria-describedby": field.help ? `${id}-help` : undefined, onChange: (e) => onChange(e.target.checked) }), _jsxs("span", { className: "pbe-switch-text", children: [_jsx("label", { htmlFor: id, className: "pbe-switch-label", children: field.label }), field.help ? (_jsx("span", { className: "pbe-help", id: `${id}-help`, children: field.help })) : null] })] }));
66
+ }
67
+ function itemTitle(field, item, index) {
68
+ const firstText = field.fields.find((f) => f.type === 'text' || f.type === 'longText');
69
+ const text = firstText && typeof item[firstText.id] === 'string' ? item[firstText.id].trim() : '';
70
+ return text ? `${field.itemLabel} ${index + 1}: ${text}` : `${field.itemLabel} ${index + 1}`;
71
+ }
72
+ function ListInput({ field, value, onChange, problem, engine, isDefault, onReset }) {
73
+ const items = Array.isArray(value) ? value : [];
74
+ const max = Math.min(field.maxItems ?? LIST_MAX, 50);
75
+ const update = (index, key, v) => onChange(items.map((item, i) => (i === index ? { ...item, [key]: v } : item)));
76
+ const move = (index, by) => {
77
+ const next = [...items];
78
+ const [moved] = next.splice(index, 1);
79
+ next.splice(index + by, 0, moved);
80
+ onChange(next);
81
+ };
82
+ const blank = () => Object.fromEntries(field.fields.map((f) => [f.id, emptyValue(f)]));
83
+ const noun = field.itemLabel.toLowerCase();
84
+ return (_jsxs("fieldset", { className: "pbe-fieldset", children: [_jsx(Head, { label: field.label, isDefault: isDefault, onReset: onReset, legend: true }), field.help ? _jsx("p", { className: "pbe-help", children: field.help }) : null, _jsxs("div", { className: "pbe-list", children: [items.length === 0 ? (_jsx("p", { className: "pbe-empty pbe-empty--card pbe-empty--compact", children: _jsxs("span", { className: "pbe-empty-text", children: ["No ", noun, "s yet. The website hides this part until you add one."] }) })) : null, items.map((item, index) => (_jsxs("div", { className: "pbe-list-item", role: "group", "aria-label": `${field.itemLabel} ${index + 1}`, children: [_jsxs("div", { className: "pbe-list-item-head", children: [_jsx("strong", { children: itemTitle(field, item, index) }), _jsx(IconButton, { icon: "move-up", size: "sm", label: `Move ${noun} ${index + 1} up`, disabled: index === 0, onClick: () => move(index, -1) }), _jsx(IconButton, { icon: "move-down", size: "sm", label: `Move ${noun} ${index + 1} down`, disabled: index === items.length - 1, onClick: () => move(index, 1) }), _jsx(IconButton, { icon: "remove", size: "sm", label: `Remove ${noun} ${index + 1}`, onClick: () => onChange(items.filter((_, i) => i !== index)) })] }), field.fields.map((sub) => (_jsx(ContentInput, { field: sub, value: item[sub.id] === undefined ? emptyValue(sub) : item[sub.id], onChange: (v) => update(index, sub.id, v), engine: engine, idPrefix: `${field.id.replace(/\W/g, '-')}-${index}-` }, sub.id)))] }, index)))] }), problem ? (_jsxs("p", { className: "pbe-field-error", role: "alert", children: [_jsx(Icon, { name: "error" }), problem] })) : null, _jsxs("div", { className: "pbe-list-foot", children: [_jsxs(Button, { icon: "add", disabled: items.length >= max, onClick: () => onChange([...items, blank()]), children: ["Add ", noun] }), _jsxs("span", { className: "pbe-help", children: [items.length, " of at most ", max] })] })] }));
85
+ }
86
+ /** The input for any field type. */
87
+ export function ContentInput(props) {
88
+ const { field } = props;
89
+ switch (field.type) {
90
+ case 'text':
91
+ case 'longText':
92
+ case 'link':
93
+ return _jsx(TextInput, { ...props, field: field });
94
+ case 'image':
95
+ return _jsx(ImageInput, { ...props, field: field });
96
+ case 'color':
97
+ return _jsx(ColorInput, { ...props, field: field });
98
+ case 'choice':
99
+ return _jsx(ChoiceInput, { ...props, field: field });
100
+ case 'toggle':
101
+ return _jsx(ToggleInput, { ...props, field: field });
102
+ case 'list':
103
+ return _jsx(ListInput, { ...props, field: field });
104
+ }
105
+ }
@@ -0,0 +1,41 @@
1
+ import type { BookingEngine } from '../client.js';
2
+ import type { SiteContentSchema } from '../content/schema.js';
3
+ import type { AdminSettings, Preset } from '../types.js';
4
+ import type { ConfirmInput, ToastInput } from './feedback.js';
5
+ /** Whether this installation emails customers ('none': a demo — see BookingAdminProps.emailDelivery). */
6
+ export type EmailDelivery = 'live' | 'none';
7
+ /** What the navigation shows about the website (null until known, or without editable content). */
8
+ export interface WebsiteStatus {
9
+ version: number;
10
+ publishedAt: string | null;
11
+ hasUnpublishedChanges: boolean;
12
+ }
13
+ export interface AdminContextValue {
14
+ engine: BookingEngine;
15
+ settings: AdminSettings;
16
+ refreshSettings: () => Promise<void>;
17
+ presets: Preset[];
18
+ /** Open a section; `view` selects a sub-view (e.g. go('bookings', 'pending')). */
19
+ go: (sectionId: string, view?: string) => void;
20
+ /** The sub-view asked for with go(), if any. */
21
+ view: string | null;
22
+ /** Requests waiting for the owner (pending or lapsed), for badges; null while unknown. */
23
+ pendingCount: number | null;
24
+ /** Recount after a booking changes. */
25
+ refreshCounts: () => void;
26
+ /** The website's editable content, if it declared any. */
27
+ contentSchema: SiteContentSchema | null;
28
+ /** The public website (for "View website" and previews). */
29
+ siteUrl: string;
30
+ /** 'none' in a demo that never emails anyone: no copy may say a customer gets an email. */
31
+ emailDelivery: EmailDelivery;
32
+ /** Published version and draft state, for the navigation and Today. */
33
+ website: WebsiteStatus | null;
34
+ refreshWebsite: () => void;
35
+ /** Tell the owner what just happened (bottom of the screen, a few seconds). */
36
+ toast: (t: ToastInput) => void;
37
+ /** Ask before something that cannot be undone. Resolves true to go ahead. */
38
+ confirm: (c: ConfirmInput) => Promise<boolean>;
39
+ }
40
+ export declare const AdminContext: import("react").Context<AdminContextValue | null>;
41
+ export declare function useAdmin(): AdminContextValue;
@@ -0,0 +1,8 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const AdminContext = createContext(null);
3
+ export function useAdmin() {
4
+ const value = useContext(AdminContext);
5
+ if (!value)
6
+ throw new Error('Admin sections must be rendered inside <BookingAdmin>.');
7
+ return value;
8
+ }
@@ -0,0 +1,14 @@
1
+ import { type ReactNode, type RefObject } from 'react';
2
+ export declare function Drawer({ docked, onClose, labelledBy, focusRef, restoreFocus, children, label, }: {
3
+ docked?: boolean;
4
+ onClose: () => void;
5
+ /** Id of the panel's title. */
6
+ labelledBy?: string;
7
+ /** Accessible name when there is no visible title. */
8
+ label?: string;
9
+ /** What receives focus when the panel opens (usually its title). */
10
+ focusRef?: RefObject<HTMLElement | null>;
11
+ /** Give focus back to what had it before opening (off when the opener handles it). */
12
+ restoreFocus?: boolean;
13
+ children: ReactNode;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // The detail panel. Two presentations of the same content:
3
+ // - docked (Bookings on a wide screen): an inspector beside the list, which
4
+ // stays usable; Esc closes it and focus returns to where it came from;
5
+ // - modal (everywhere else; a full-height sheet on phones): a native <dialog>,
6
+ // so focus stays inside, the page behind is inert and Esc closes it.
7
+ import { useEffect, useRef } from 'react';
8
+ export function Drawer({ docked = false, onClose, labelledBy, focusRef, restoreFocus = true, children, label, }) {
9
+ const dialogRef = useRef(null);
10
+ const asideRef = useRef(null);
11
+ const closeRef = useRef(onClose);
12
+ closeRef.current = onClose;
13
+ // Remember what had focus, move focus in, and give it back on close.
14
+ useEffect(() => {
15
+ const before = document.activeElement;
16
+ const dialog = dialogRef.current;
17
+ if (!docked && dialog && !dialog.open)
18
+ dialog.showModal();
19
+ (focusRef?.current ?? dialog ?? asideRef.current)?.focus({ preventScroll: docked });
20
+ return () => {
21
+ if (dialog?.open)
22
+ dialog.close();
23
+ if (restoreFocus && before && document.contains(before))
24
+ before.focus({ preventScroll: true });
25
+ };
26
+ // Opening is a one-time event per mounted panel.
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, [docked]);
29
+ // The docked panel is not modal: Esc anywhere (outside other dialogs and fields) closes it.
30
+ useEffect(() => {
31
+ if (!docked)
32
+ return;
33
+ const onKey = (e) => {
34
+ if (e.key !== 'Escape' || e.defaultPrevented)
35
+ return;
36
+ if (document.querySelector('.pbe-admin dialog[open]'))
37
+ return;
38
+ if (e.target?.closest?.('input, textarea, select'))
39
+ return;
40
+ closeRef.current();
41
+ };
42
+ document.addEventListener('keydown', onKey);
43
+ return () => document.removeEventListener('keydown', onKey);
44
+ }, [docked]);
45
+ if (docked) {
46
+ return (_jsx("aside", { ref: asideRef, className: "pbe-drawer pbe-drawer--docked", "aria-labelledby": labelledBy, "aria-label": label, tabIndex: -1, children: children }));
47
+ }
48
+ return (_jsx("dialog", { ref: dialogRef, className: "pbe-drawer", "aria-labelledby": labelledBy, "aria-label": label, onCancel: (e) => {
49
+ e.preventDefault();
50
+ closeRef.current();
51
+ }, onClick: (e) => {
52
+ // A click on the backdrop lands on the dialog element itself.
53
+ if (e.target === e.currentTarget)
54
+ closeRef.current();
55
+ }, children: children }));
56
+ }
@@ -0,0 +1,32 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface ToastInput {
3
+ kind?: 'success' | 'error' | 'info';
4
+ title: string;
5
+ detail?: string;
6
+ }
7
+ interface Toast extends ToastInput {
8
+ id: number;
9
+ }
10
+ export declare function useToasts(): {
11
+ toasts: Toast[];
12
+ toast: (t: ToastInput) => void;
13
+ dismiss: (id: number) => void;
14
+ };
15
+ /** The live region: always in the page, so screen readers hear each new toast. */
16
+ export declare function ToastRegion({ toasts, dismiss }: {
17
+ toasts: Toast[];
18
+ dismiss: (id: number) => void;
19
+ }): import("react").JSX.Element;
20
+ export interface ConfirmInput {
21
+ title: string;
22
+ body: ReactNode;
23
+ /** The button that goes ahead, named after what it does ("Decline request"). */
24
+ confirmLabel: string;
25
+ cancelLabel?: string;
26
+ tone?: 'danger' | 'primary';
27
+ }
28
+ export declare function useConfirm(): {
29
+ confirm: (c: ConfirmInput) => Promise<boolean>;
30
+ dialog: ReactNode;
31
+ };
32
+ export {};
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Feedback for the owner: toasts (what just happened) and confirmation dialogs
3
+ // (before something that cannot be undone). Both live in the dashboard root so
4
+ // they share its tokens; the shell owns their state and passes the functions
5
+ // through the admin context.
6
+ import { useCallback, useEffect, useRef, useState } from 'react';
7
+ import { Icon } from './icons.js';
8
+ import { Button, IconButton } from './ui.js';
9
+ export function useToasts() {
10
+ const [toasts, setToasts] = useState([]);
11
+ const next = useRef(1);
12
+ const dismiss = useCallback((id) => setToasts((all) => all.filter((t) => t.id !== id)), []);
13
+ const toast = useCallback((t) => {
14
+ const id = next.current++;
15
+ setToasts((all) => [...all.slice(-2), { ...t, id }]);
16
+ }, []);
17
+ return { toasts, toast, dismiss };
18
+ }
19
+ function ToastItem({ toast, onDismiss }) {
20
+ const [paused, setPaused] = useState(false);
21
+ useEffect(() => {
22
+ if (paused)
23
+ return;
24
+ const id = window.setTimeout(onDismiss, toast.kind === 'error' ? 9000 : 5500);
25
+ return () => window.clearTimeout(id);
26
+ }, [paused, onDismiss, toast.kind]);
27
+ const kind = toast.kind ?? 'success';
28
+ return (_jsxs("div", { className: `pbe-toast pbe-toast--${kind}`, onMouseEnter: () => setPaused(true), onMouseLeave: () => setPaused(false), onFocus: () => setPaused(true), onBlur: () => setPaused(false), children: [_jsx("span", { className: "pbe-toast-icon", "aria-hidden": "true", children: _jsx(Icon, { name: kind === 'error' ? 'error' : kind === 'info' ? 'info' : 'check', size: 16 }) }), _jsxs("p", { className: "pbe-toast-text", children: [_jsx("span", { className: "pbe-toast-title", children: toast.title }), toast.detail ? (_jsxs(_Fragment, { children: [' ', _jsx("span", { className: "pbe-toast-detail", children: toast.detail })] })) : null] }), _jsx(IconButton, { icon: "close", label: "Dismiss", size: "sm", onClick: onDismiss })] }));
29
+ }
30
+ /** The live region: always in the page, so screen readers hear each new toast. */
31
+ export function ToastRegion({ toasts, dismiss }) {
32
+ return (_jsx("div", { className: "pbe-toasts", role: "status", "aria-live": "polite", "aria-label": "Notifications", children: toasts.map((t) => (_jsx(ToastItem, { toast: t, onDismiss: () => dismiss(t.id) }, t.id))) }));
33
+ }
34
+ export function useConfirm() {
35
+ const [pending, setPending] = useState(null);
36
+ const confirm = useCallback((c) => new Promise((resolve) => {
37
+ setPending({ ...c, resolve });
38
+ }), []);
39
+ const finish = useCallback((ok) => {
40
+ setPending((p) => {
41
+ p?.resolve(ok);
42
+ return null;
43
+ });
44
+ }, []);
45
+ return { confirm, dialog: pending ? _jsx(ConfirmDialog, { ...pending, onDone: finish }) : null };
46
+ }
47
+ function ConfirmDialog({ title, body, confirmLabel, cancelLabel = 'Cancel', tone = 'danger', onDone }) {
48
+ const ref = useRef(null);
49
+ const cancelRef = useRef(null);
50
+ useEffect(() => {
51
+ const dialog = ref.current;
52
+ if (!dialog)
53
+ return;
54
+ const before = document.activeElement;
55
+ if (!dialog.open)
56
+ dialog.showModal();
57
+ // The safe choice has focus: Enter never destroys anything by accident.
58
+ cancelRef.current?.focus();
59
+ return () => {
60
+ if (dialog.open)
61
+ dialog.close();
62
+ if (before && document.contains(before))
63
+ before.focus();
64
+ };
65
+ }, []);
66
+ return (_jsxs("dialog", { ref: ref, className: "pbe-dialog", role: "alertdialog", "aria-labelledby": "pbe-confirm-title", "aria-describedby": "pbe-confirm-body", onCancel: (e) => {
67
+ e.preventDefault();
68
+ onDone(false);
69
+ }, children: [_jsx("h2", { id: "pbe-confirm-title", className: "pbe-dialog-title", children: title }), _jsx("div", { id: "pbe-confirm-body", className: "pbe-dialog-body", children: body }), _jsxs("div", { className: "pbe-dialog-actions", children: [_jsx("button", { ref: cancelRef, type: "button", className: "pbe-button pbe-button--secondary", onClick: () => onDone(false), children: cancelLabel }), _jsx(Button, { variant: tone === 'danger' ? 'danger' : 'primary', onClick: () => onDone(true), children: confirmLabel })] })] }));
70
+ }
@@ -0,0 +1,27 @@
1
+ import type { SettingsPatch } from '../types.js';
2
+ export type SettingKey = keyof SettingsPatch;
3
+ export interface SettingOption {
4
+ value: string | number;
5
+ label: string;
6
+ }
7
+ export interface SettingField {
8
+ key: SettingKey;
9
+ label: string;
10
+ help: string;
11
+ kind: 'text' | 'email' | 'tel' | 'textarea' | 'number' | 'boolean' | 'select' | 'timezone' | 'currency';
12
+ options?: SettingOption[];
13
+ min?: number;
14
+ max?: number;
15
+ maxLength?: number;
16
+ placeholder?: string;
17
+ }
18
+ export interface SettingGroup {
19
+ id: string;
20
+ title: string;
21
+ intro: string;
22
+ fields: SettingField[];
23
+ }
24
+ export declare const BUSINESS_GROUP: SettingGroup;
25
+ export declare const POLICY_GROUP: SettingGroup;
26
+ export declare const EMAIL_GROUP: SettingGroup;
27
+ export declare const CURRENCY_SUGGESTIONS: string[];