create-ailk 0.36.0 → 0.37.1

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 (101) hide show
  1. package/README.md +20 -2
  2. package/component-catalog.json +40 -1
  3. package/component-catalog.md +7 -5
  4. package/dist/add-route.d.ts +5 -0
  5. package/dist/add-route.js +10 -2
  6. package/dist/surfaces.js +60 -19
  7. package/dist/sync-routes.d.ts +15 -1
  8. package/dist/sync-routes.js +58 -6
  9. package/dist/template-record.d.ts +11 -0
  10. package/dist/template-record.js +18 -0
  11. package/dist/update.d.ts +33 -1
  12. package/dist/update.js +439 -56
  13. package/package.json +3 -3
  14. package/templates/.env.example +17 -0
  15. package/templates/apps/api/.env.example +38 -0
  16. package/templates/apps/api/CLAUDE.md +3 -0
  17. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  18. package/templates/apps/mcp/CLAUDE.md +1 -1
  19. package/templates/apps/web/CLAUDE.md +28 -1
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  22. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  38. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  39. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  40. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  45. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  46. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  47. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  50. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  54. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  59. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  60. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  62. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  63. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  64. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  65. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  70. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  71. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  72. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  73. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  75. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  76. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  77. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  79. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  80. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  81. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  82. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  83. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  84. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  85. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  86. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  87. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  88. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  89. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  90. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  91. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  92. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  93. package/templates/apps/web/lib/account-config.ts +132 -8
  94. package/templates/apps/web/lib/auth-routes.ts +11 -6
  95. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  96. package/templates/apps/web/messages/en.json +156 -80
  97. package/versions.json +48 -48
  98. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  99. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  101. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -1,276 +0,0 @@
1
- "use client"; // reads meeting types and slots on demand and posts a controlled form
2
-
3
- /**
4
- * ScheduleService — the New menu's Schedule service popup (#8233, spec D5,
5
- * D8, D10; AC-MAA-10). On open it reads the meeting types the provider
6
- * offers its clients (`readMeetingTypes`) and lists only those; picking one
7
- * reads that type's open times for the next 14 days in the browser's time
8
- * zone (`readSlots`, which computes the range on the server). Book posts the
9
- * type, the slot's start as served, the time zone and optional notes to
10
- * `member.book` — no name and no email: the server takes the verified email
11
- * and the name from the session.
12
- *
13
- * With no type offered it says no times are offered and, when Send message
14
- * is on the menu, offers to switch to it. A taken slot (`slot_unavailable`)
15
- * re-reads the picked type's times and keeps the type and the notes; every
16
- * other refusal shows its plain message with everything kept.
17
- */
18
-
19
- import {
20
- Button,
21
- Label,
22
- RadioGroup,
23
- RadioGroupItem,
24
- Text,
25
- Textarea,
26
- } from "@working-theory/ui/primitives";
27
- import type { MemberMeetingType, SchedulingSlot } from "@working-theory/validation";
28
- import {
29
- startTransition,
30
- useActionState,
31
- useId,
32
- useMemo,
33
- useRef,
34
- useState,
35
- type FormEvent,
36
- type ReactElement,
37
- } from "react";
38
-
39
- import { bookService, readMeetingTypes, readSlots, type NewActionState } from "../new-actions";
40
- import {
41
- NewPopupRefusal,
42
- NewPopupStatus,
43
- useNewMenuPopup,
44
- useOpenRead,
45
- type NewPopupLabels,
46
- } from "../new-menu";
47
-
48
- export interface ScheduleServiceLabels extends NewPopupLabels {
49
- service: string;
50
- /** Carries a literal `{minutes}`, filled per type here. */
51
- duration: string;
52
- time: string;
53
- notes: string;
54
- submit: string;
55
- none: string;
56
- suggest: string;
57
- noSlots: string;
58
- }
59
-
60
- export interface ScheduleServiceProps {
61
- locale: string;
62
- labels: ScheduleServiceLabels;
63
- }
64
-
65
- const SEND_MESSAGE = "send-message";
66
-
67
- export function ScheduleService({ locale, labels }: ScheduleServiceProps): ReactElement {
68
- const popup = useNewMenuPopup();
69
- const [read, retry] = useOpenRead(readMeetingTypes);
70
- if (read === "loading" || read.kind === "error") {
71
- return <NewPopupStatus failed={read !== "loading"} labels={labels} onRetry={retry} />;
72
- }
73
- if (read.items.length === 0) {
74
- return (
75
- <div className="flex flex-col gap-4" data-testid="new-schedule-none">
76
- <Text as="p" variant="body-sm">
77
- {labels.none}
78
- </Text>
79
- {popup.has(SEND_MESSAGE) ? (
80
- <div>
81
- <Button
82
- variant="outline"
83
- className="max-md:min-h-11"
84
- onClick={() => popup.open(SEND_MESSAGE)}
85
- data-testid="new-schedule-suggest"
86
- >
87
- {labels.suggest}
88
- </Button>
89
- </div>
90
- ) : null}
91
- </div>
92
- );
93
- }
94
- return <BookingForm types={read.items} locale={locale} labels={labels} />;
95
- }
96
-
97
- type Slots = { kind: "idle" | "loading" | "error" } | { kind: "ok"; slots: SchedulingSlot[] };
98
-
99
- function BookingForm({
100
- types,
101
- locale,
102
- labels,
103
- }: {
104
- types: readonly MemberMeetingType[];
105
- locale: string;
106
- labels: ScheduleServiceLabels;
107
- }): ReactElement {
108
- const popup = useNewMenuPopup();
109
- const id = useId();
110
- const timeZone = useMemo(() => Intl.DateTimeFormat().resolvedOptions().timeZone, []);
111
- const [slug, setSlug] = useState("");
112
- const [start, setStart] = useState("");
113
- const [notes, setNotes] = useState("");
114
- const [slots, setSlots] = useState<Slots>({ kind: "idle" });
115
- // Only the newest slots read lands: a quick second pick never shows the first's times.
116
- const latestRead = useRef(0);
117
-
118
- const loadSlots = (picked: string): void => {
119
- const readId = ++latestRead.current;
120
- setSlots({ kind: "loading" });
121
- const land = (next: Slots): void => {
122
- if (readId === latestRead.current) setSlots(next);
123
- };
124
- readSlots({ slug: picked, timeZone }).then(
125
- (result) => land(result.kind === "ok" ? { kind: "ok", slots: result.slots } : { kind: "error" }),
126
- () => land({ kind: "error" }),
127
- );
128
- };
129
-
130
- const [state, dispatch, pending] = useActionState<NewActionState, FormData>(
131
- async (prev, formData) => {
132
- const next = await bookService(prev, formData);
133
- if (next.kind === "success") popup.close(true);
134
- if (next.kind === "error" && next.code === "slot_unavailable") {
135
- const picked = formData.get("slug");
136
- setStart("");
137
- if (typeof picked === "string") loadSlots(picked);
138
- }
139
- return next;
140
- },
141
- { kind: "idle" },
142
- );
143
-
144
- const onSubmit = (event: FormEvent<HTMLFormElement>): void => {
145
- event.preventDefault();
146
- const formData = new FormData();
147
- formData.set("slug", slug);
148
- formData.set("start", start);
149
- formData.set("timeZone", timeZone);
150
- formData.set("notes", notes);
151
- startTransition(() => dispatch(formData));
152
- };
153
-
154
- const dayFormat = new Intl.DateTimeFormat(locale, {
155
- weekday: "long",
156
- month: "long",
157
- day: "numeric",
158
- timeZone,
159
- });
160
- const timeFormat = new Intl.DateTimeFormat(locale, { timeStyle: "short", timeZone });
161
- const days: { day: string; slots: { slot: SchedulingSlot; index: number }[] }[] = [];
162
- if (slots.kind === "ok") {
163
- slots.slots.forEach((slot, index) => {
164
- const day = dayFormat.format(new Date(slot.start));
165
- const last = days[days.length - 1];
166
- if (last?.day === day) last.slots.push({ slot, index });
167
- else days.push({ day, slots: [{ slot, index }] });
168
- });
169
- }
170
-
171
- return (
172
- <form onSubmit={onSubmit} className="flex flex-col gap-4" data-testid="new-schedule-form">
173
- <div className="flex flex-col gap-2">
174
- <Text as="p" id={`${id}-service`} variant="body-sm" className="font-semibold">
175
- {labels.service}
176
- </Text>
177
- <RadioGroup
178
- aria-labelledby={`${id}-service`}
179
- value={slug}
180
- onValueChange={(picked) => {
181
- setSlug(picked);
182
- setStart("");
183
- loadSlots(picked);
184
- }}
185
- >
186
- {types.map((type) => (
187
- <div key={type.slug} className="flex min-h-11 items-center gap-3">
188
- <RadioGroupItem
189
- id={`${id}-type-${type.slug}`}
190
- value={type.slug}
191
- data-testid={`new-schedule-type-${type.slug}`}
192
- />
193
- <Label htmlFor={`${id}-type-${type.slug}`} className="flex flex-wrap gap-x-2">
194
- {type.title}{" "}
195
- <Text as="span" variant="caption">
196
- {labels.duration.replace("{minutes}", String(type.durationMinutes))}
197
- </Text>
198
- </Label>
199
- </div>
200
- ))}
201
- </RadioGroup>
202
- </div>
203
-
204
- {slots.kind === "loading" || slots.kind === "error" ? (
205
- <NewPopupStatus
206
- failed={slots.kind === "error"}
207
- labels={labels}
208
- onRetry={() => loadSlots(slug)}
209
- />
210
- ) : null}
211
- {slots.kind === "ok" && slots.slots.length === 0 ? (
212
- <Text as="p" variant="body-sm" data-testid="new-schedule-no-slots">
213
- {labels.noSlots}
214
- </Text>
215
- ) : null}
216
- {days.length > 0 ? (
217
- <div className="flex flex-col gap-2">
218
- <Text as="p" id={`${id}-time`} variant="body-sm" className="font-semibold">
219
- {labels.time}
220
- </Text>
221
- <RadioGroup aria-labelledby={`${id}-time`} value={start} onValueChange={setStart}>
222
- {days.map(({ day, slots: daySlots }) => (
223
- <div key={day} className="flex flex-col gap-1">
224
- <Text as="p" variant="caption">
225
- {day}
226
- </Text>
227
- {daySlots.map(({ slot, index }) => (
228
- <div key={slot.start} className="flex min-h-11 items-center gap-3">
229
- <RadioGroupItem
230
- id={`${id}-slot-${index}`}
231
- value={slot.start}
232
- data-testid={`new-schedule-slot-${index}`}
233
- />
234
- <Label htmlFor={`${id}-slot-${index}`}>
235
- {timeFormat.format(new Date(slot.start))}
236
- </Label>
237
- </div>
238
- ))}
239
- </div>
240
- ))}
241
- </RadioGroup>
242
- </div>
243
- ) : null}
244
-
245
- <div className="flex flex-col gap-2">
246
- <div className="flex items-baseline gap-2">
247
- <Label htmlFor={`${id}-notes`}>{labels.notes}</Label>
248
- <Text as="span" variant="caption">
249
- {labels.optional}
250
- </Text>
251
- </div>
252
- <Textarea
253
- id={`${id}-notes`}
254
- name="notes"
255
- rows={3}
256
- value={notes}
257
- onChange={(event) => setNotes(event.target.value)}
258
- data-testid="new-schedule-notes"
259
- />
260
- </div>
261
-
262
- {state.kind === "error" ? <NewPopupRefusal code={state.code} labels={labels} /> : null}
263
- <div>
264
- <Button
265
- type="submit"
266
- disabled={pending || slug === "" || start === ""}
267
- // 44px on a phone (a touch-first context); the 36px primary from md up.
268
- className="max-md:min-h-11"
269
- data-testid="new-schedule-submit"
270
- >
271
- {pending ? labels.submitting : labels.submit}
272
- </Button>
273
- </div>
274
- </form>
275
- );
276
- }
@@ -1,128 +0,0 @@
1
- "use client"; // a controlled form posting through the New menu's server action
2
-
3
- /**
4
- * SendMessage — the New menu's Send message popup (#8233, spec D9, D10): a
5
- * subject, a body (line breaks kept) and an optional link, posted to
6
- * `member.sendMessage` by `sendMessage` (`../new-actions.ts`). No name and no
7
- * email: the server takes both from the session.
8
- *
9
- * Every field is controlled and the form posts what the state holds, so a
10
- * refusal — a non-https link above all — shows its plain message with every
11
- * typed value still in place. The link is sent as typed; the server's https
12
- * rule is the only one. A success closes the popup and refreshes the Inbox.
13
- */
14
-
15
- import { Button, Input, Label, Text, Textarea } from "@working-theory/ui/primitives";
16
- import { MESSAGE_BODY_MAX, MESSAGE_SUBJECT_MAX } from "@working-theory/validation";
17
- import {
18
- startTransition,
19
- useActionState,
20
- useId,
21
- useState,
22
- type FormEvent,
23
- type ReactElement,
24
- } from "react";
25
-
26
- import { sendMessage, type NewActionState } from "../new-actions";
27
- import { NewPopupRefusal, useNewMenuPopup, type NewPopupLabels } from "../new-menu";
28
-
29
- export interface SendMessageLabels extends NewPopupLabels {
30
- subject: string;
31
- body: string;
32
- link: string;
33
- linkHelp: string;
34
- submit: string;
35
- }
36
-
37
- export interface SendMessageProps {
38
- locale: string;
39
- labels: SendMessageLabels;
40
- }
41
-
42
- export function SendMessage({ labels }: SendMessageProps): ReactElement {
43
- const popup = useNewMenuPopup();
44
- const id = useId();
45
- const [subject, setSubject] = useState("");
46
- const [body, setBody] = useState("");
47
- const [link, setLink] = useState("");
48
- const [state, dispatch, pending] = useActionState<NewActionState, FormData>(
49
- async (prev, formData) => {
50
- const next = await sendMessage(prev, formData);
51
- if (next.kind === "success") popup.close(true);
52
- return next;
53
- },
54
- { kind: "idle" },
55
- );
56
-
57
- const onSubmit = (event: FormEvent<HTMLFormElement>): void => {
58
- event.preventDefault();
59
- const formData = new FormData();
60
- formData.set("subject", subject);
61
- formData.set("body", body);
62
- formData.set("link", link);
63
- startTransition(() => dispatch(formData));
64
- };
65
-
66
- return (
67
- <form onSubmit={onSubmit} className="flex flex-col gap-4" data-testid="new-message-form">
68
- <div className="flex flex-col gap-2">
69
- <Label htmlFor={`${id}-subject`}>{labels.subject}</Label>
70
- <Input
71
- id={`${id}-subject`}
72
- name="subject"
73
- value={subject}
74
- maxLength={MESSAGE_SUBJECT_MAX}
75
- required
76
- onChange={(event) => setSubject(event.target.value)}
77
- data-testid="new-message-subject"
78
- />
79
- </div>
80
- <div className="flex flex-col gap-2">
81
- <Label htmlFor={`${id}-body`}>{labels.body}</Label>
82
- <Textarea
83
- id={`${id}-body`}
84
- name="body"
85
- value={body}
86
- rows={5}
87
- maxLength={MESSAGE_BODY_MAX}
88
- required
89
- onChange={(event) => setBody(event.target.value)}
90
- data-testid="new-message-body"
91
- />
92
- </div>
93
- <div className="flex flex-col gap-2">
94
- <div className="flex items-baseline gap-2">
95
- <Label htmlFor={`${id}-link`}>{labels.link}</Label>
96
- <Text as="span" variant="caption">
97
- {labels.optional}
98
- </Text>
99
- </div>
100
- <Input
101
- id={`${id}-link`}
102
- name="link"
103
- type="text"
104
- inputMode="url"
105
- value={link}
106
- aria-describedby={`${id}-link-help`}
107
- onChange={(event) => setLink(event.target.value)}
108
- data-testid="new-message-link"
109
- />
110
- <Text as="p" id={`${id}-link-help`} variant="caption">
111
- {labels.linkHelp}
112
- </Text>
113
- </div>
114
- {state.kind === "error" ? <NewPopupRefusal code={state.code} labels={labels} /> : null}
115
- <div>
116
- <Button
117
- type="submit"
118
- disabled={pending}
119
- // 44px on a phone (a touch-first context); the 36px primary from md up.
120
- className="max-md:min-h-11"
121
- data-testid="new-message-submit"
122
- >
123
- {pending ? labels.submitting : labels.submit}
124
- </Button>
125
- </div>
126
- </form>
127
- );
128
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * `siteThemeModeCount` (#7742 D2 / AC-2): a design pinned to light has one
3
- * colour mode whatever its palette declares; without the pin, the declared
4
- * palette decides, as before.
5
- */
6
- import type { SiteChrome } from "../../../../../../lib/site-chrome";
7
-
8
- const mockSiteChrome: SiteChrome = {
9
- nav: "full",
10
- footer: "columns",
11
- announcementBanner: false,
12
- home: "default",
13
- };
14
- // eslint-disable-next-line no-restricted-syntax -- #507: `site-chrome.ts` is a generated data module with no external boundary to mock instead; this is the seam theme-modes.ts itself reads.
15
- jest.mock("../../../../../../lib/site-chrome", () => ({
16
- __esModule: true,
17
- siteChrome: mockSiteChrome,
18
- }));
19
-
20
- // Both palettes declared — the count is 2 without the pin.
21
- // eslint-disable-next-line no-restricted-syntax -- #507: the one seam onto `_site.mdx`; the palette is the test's to set.
22
- jest.mock("../../../../../../lib/site-theme", () => ({
23
- __esModule: true,
24
- loadSiteBrandTokens: () => ({ colors: { light: { bg: "#ffffff" }, dark: { bg: "#000000" } } }),
25
- }));
26
-
27
- import { siteThemeModeCount } from "../theme-modes";
28
-
29
- afterEach(() => {
30
- delete mockSiteChrome.colorMode;
31
- });
32
-
33
- describe("siteThemeModeCount (#7742 D2)", () => {
34
- it('colorMode: "light" gives 1 even when both palettes are declared', () => {
35
- mockSiteChrome.colorMode = "light";
36
- expect(siteThemeModeCount()).toBe(1);
37
- });
38
-
39
- it("without colorMode the same palette gives 2", () => {
40
- expect(siteThemeModeCount()).toBe(2);
41
- });
42
- });
@@ -1,40 +0,0 @@
1
- /**
2
- * theme-modes.ts — how many color modes the site's theme defines (#7430,
3
- * operator fold-in 2026-10-01: the color-mode control renders only on a
4
- * site whose theme has more than one).
5
- *
6
- * Read from the same `content/_site.mdx` overlay the locale layout applies
7
- * (`loadSiteBrandTokens`):
8
- *
9
- * - no `theme:` colours (the default palette, light AND dark) → 2;
10
- * - colours declared for both `light` and `dark` → 2;
11
- * - colours declared for ONE mode only → 1. A site that designs a single
12
- * palette (samhenry's light-only DESIGN.md) declares just that mode, and
13
- * the other mode's defaults are not its design.
14
- *
15
- * A theme the loader rejects counts as the default (2): the layout surfaces
16
- * that error itself, and settings must not be where it first appears.
17
- *
18
- * A design that pins the mode (`colorMode: "light"`, #7742 D2) has one mode
19
- * whatever its palette declares, so the settings control hides there too.
20
- */
21
-
22
- import { siteChrome, type SiteChrome } from "../../../../../lib/site-chrome";
23
- import { loadSiteBrandTokens } from "../../../../../lib/site-theme";
24
-
25
- /** Widened as the locale layout reads it: an older generated file has no `colorMode`. */
26
- const chrome: SiteChrome & { colorMode?: "light" } = siteChrome;
27
-
28
- export function siteThemeModeCount(): 1 | 2 {
29
- if (chrome.colorMode === "light") return 1;
30
- try {
31
- const colors = loadSiteBrandTokens()?.["colors"];
32
- if (typeof colors !== "object" || colors === null) return 2;
33
- const declared = (["light", "dark"] as const).filter(
34
- (mode) => (colors as Record<string, unknown>)[mode] !== undefined,
35
- );
36
- return declared.length === 1 ? 1 : 2;
37
- } catch {
38
- return 2;
39
- }
40
- }