@react-consulting/rc-kit 0.0.0-stage → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -2
  3. package/devkit/README.md +301 -0
  4. package/devkit/cli.test.ts +211 -0
  5. package/devkit/cli.ts +120 -0
  6. package/devkit/commands/build.ts +127 -0
  7. package/devkit/commands/checks.ts +123 -0
  8. package/devkit/commands/context.ts +47 -0
  9. package/devkit/commands/db.ts +154 -0
  10. package/devkit/commands/deploy.ts +46 -0
  11. package/devkit/commands/dev.ts +191 -0
  12. package/devkit/commands/doctor.ts +25 -0
  13. package/devkit/commands/kit.ts +45 -0
  14. package/devkit/commands/new.ts +81 -0
  15. package/devkit/commands/registry.ts +20 -0
  16. package/devkit/commands/secrets.ts +254 -0
  17. package/devkit/lib/args.ts +65 -0
  18. package/devkit/lib/audit.test.ts +405 -0
  19. package/devkit/lib/audit.ts +813 -0
  20. package/devkit/lib/config.test.ts +203 -0
  21. package/devkit/lib/config.ts +417 -0
  22. package/devkit/lib/database/index.test.ts +223 -0
  23. package/devkit/lib/database/index.ts +314 -0
  24. package/devkit/lib/database/neon.test.ts +233 -0
  25. package/devkit/lib/database/neon.ts +357 -0
  26. package/devkit/lib/database/prepare.ts +54 -0
  27. package/devkit/lib/deploy-config.test.ts +217 -0
  28. package/devkit/lib/deploy-config.ts +133 -0
  29. package/devkit/lib/deploy.test.ts +275 -0
  30. package/devkit/lib/deploy.ts +177 -0
  31. package/devkit/lib/dev-gateway.test.ts +128 -0
  32. package/devkit/lib/dev-gateway.ts +162 -0
  33. package/devkit/lib/dev-menu.test.ts +114 -0
  34. package/devkit/lib/dev-menu.ts +332 -0
  35. package/devkit/lib/dev-secrets.test.ts +156 -0
  36. package/devkit/lib/dev-secrets.ts +97 -0
  37. package/devkit/lib/dev.test.ts +194 -0
  38. package/devkit/lib/dev.ts +119 -0
  39. package/devkit/lib/doctor.test.ts +144 -0
  40. package/devkit/lib/doctor.ts +264 -0
  41. package/devkit/lib/env-file.test.ts +102 -0
  42. package/devkit/lib/env-file.ts +96 -0
  43. package/devkit/lib/glob.ts +31 -0
  44. package/devkit/lib/infisical.test.ts +208 -0
  45. package/devkit/lib/infisical.ts +139 -0
  46. package/devkit/lib/json-schema.ts +220 -0
  47. package/devkit/lib/jsonc.test.ts +53 -0
  48. package/devkit/lib/jsonc.ts +93 -0
  49. package/devkit/lib/kit-migrate.test.ts +212 -0
  50. package/devkit/lib/kit-migrate.ts +617 -0
  51. package/devkit/lib/kit-package.test.ts +83 -0
  52. package/devkit/lib/kit-package.ts +57 -0
  53. package/devkit/lib/kit-version.ts +22 -0
  54. package/devkit/lib/naming.test.ts +547 -0
  55. package/devkit/lib/naming.ts +796 -0
  56. package/devkit/lib/paths.ts +7 -0
  57. package/devkit/lib/process.ts +78 -0
  58. package/devkit/lib/project-checks.ts +86 -0
  59. package/devkit/lib/scaffold.test.ts +302 -0
  60. package/devkit/lib/scaffold.ts +315 -0
  61. package/devkit/lib/secrets.test.ts +101 -0
  62. package/devkit/lib/secrets.ts +125 -0
  63. package/devkit/lib/sourcemaps.test.ts +86 -0
  64. package/devkit/lib/sourcemaps.ts +98 -0
  65. package/devkit/lib/test-utils.ts +68 -0
  66. package/devkit/lib/workspace.ts +87 -0
  67. package/devkit/lib/wrangler.ts +231 -0
  68. package/docs/rc-config.md +93 -0
  69. package/package.json +86 -4
  70. package/presets/build.d.ts +15 -0
  71. package/presets/build.js +53 -0
  72. package/presets/vite-plus.d.ts +28 -0
  73. package/presets/vite-plus.js +153 -0
  74. package/registry/README.md +294 -0
  75. package/registry/public/r/avatar-stack.json +18 -0
  76. package/registry/public/r/avatar.json +20 -0
  77. package/registry/public/r/back-link.json +21 -0
  78. package/registry/public/r/badge.json +17 -0
  79. package/registry/public/r/button.json +18 -0
  80. package/registry/public/r/calendar-days.json +14 -0
  81. package/registry/public/r/calendar-popover.json +24 -0
  82. package/registry/public/r/calendar.json +23 -0
  83. package/registry/public/r/callout.json +20 -0
  84. package/registry/public/r/card.json +18 -0
  85. package/registry/public/r/character-counter.json +17 -0
  86. package/registry/public/r/checkbox.json +22 -0
  87. package/registry/public/r/choice-cards.json +22 -0
  88. package/registry/public/r/color-tag.json +17 -0
  89. package/registry/public/r/combobox.json +24 -0
  90. package/registry/public/r/confirm-button.json +24 -0
  91. package/registry/public/r/confirm-dialog.json +23 -0
  92. package/registry/public/r/copy-button.json +24 -0
  93. package/registry/public/r/date-picker.json +24 -0
  94. package/registry/public/r/date-range-picker.json +28 -0
  95. package/registry/public/r/detail-header.json +17 -0
  96. package/registry/public/r/detail-row.json +17 -0
  97. package/registry/public/r/dev-inbox-api.json +33 -0
  98. package/registry/public/r/dev-toolbar.json +109 -0
  99. package/registry/public/r/dev-tools-contract.json +15 -0
  100. package/registry/public/r/dialog.json +23 -0
  101. package/registry/public/r/empty-state.json +20 -0
  102. package/registry/public/r/error-state.json +23 -0
  103. package/registry/public/r/eyebrow.json +17 -0
  104. package/registry/public/r/fab.json +20 -0
  105. package/registry/public/r/field-error.json +17 -0
  106. package/registry/public/r/field-grid.json +17 -0
  107. package/registry/public/r/field.json +19 -0
  108. package/registry/public/r/file-picker.json +22 -0
  109. package/registry/public/r/filter-chips.json +17 -0
  110. package/registry/public/r/form-section.json +17 -0
  111. package/registry/public/r/form-sheet.json +22 -0
  112. package/registry/public/r/icon-button.json +23 -0
  113. package/registry/public/r/input.json +18 -0
  114. package/registry/public/r/label.json +18 -0
  115. package/registry/public/r/list-row.json +17 -0
  116. package/registry/public/r/loading-state.json +18 -0
  117. package/registry/public/r/localized-field.json +23 -0
  118. package/registry/public/r/markdown-text.json +17 -0
  119. package/registry/public/r/menu.json +21 -0
  120. package/registry/public/r/money-input.json +17 -0
  121. package/registry/public/r/month-day-select.json +18 -0
  122. package/registry/public/r/numbered-step.json +20 -0
  123. package/registry/public/r/page-actions.json +14 -0
  124. package/registry/public/r/page-header.json +17 -0
  125. package/registry/public/r/pending.json +17 -0
  126. package/registry/public/r/person-option.json +21 -0
  127. package/registry/public/r/popover.json +20 -0
  128. package/registry/public/r/progress-bar.json +17 -0
  129. package/registry/public/r/query-view.json +22 -0
  130. package/registry/public/r/registry.json +1352 -0
  131. package/registry/public/r/retry-button.json +21 -0
  132. package/registry/public/r/rich-text-editor.json +32 -0
  133. package/registry/public/r/save-bar.json +22 -0
  134. package/registry/public/r/search-input.json +23 -0
  135. package/registry/public/r/search-select.json +24 -0
  136. package/registry/public/r/section-tabs.json +17 -0
  137. package/registry/public/r/segmented.json +18 -0
  138. package/registry/public/r/select.json +23 -0
  139. package/registry/public/r/sheet.json +24 -0
  140. package/registry/public/r/skeleton.json +17 -0
  141. package/registry/public/r/spinner.json +20 -0
  142. package/registry/public/r/stale-notice.json +23 -0
  143. package/registry/public/r/stat-tile.json +23 -0
  144. package/registry/public/r/stepper.json +23 -0
  145. package/registry/public/r/suggestion-strip.json +21 -0
  146. package/registry/public/r/swatch-picker.json +22 -0
  147. package/registry/public/r/switch.json +21 -0
  148. package/registry/public/r/tabs.json +20 -0
  149. package/registry/public/r/textarea.json +18 -0
  150. package/registry/public/r/theme.json +15 -0
  151. package/registry/public/r/timezone-select.json +19 -0
  152. package/registry/public/r/toaster.json +21 -0
  153. package/registry/public/r/tooltip.json +17 -0
  154. package/registry/public/r/ui-labels.json +14 -0
  155. package/registry/public/r/use-copy-to-clipboard.json +20 -0
  156. package/registry/public/r/use-online.json +14 -0
  157. package/registry/public/r/use-stale-queries.json +17 -0
  158. package/registry/public/r/utils.json +18 -0
  159. package/registry/public/r/weekday-picker.json +19 -0
  160. package/registry/public/r/yes-no.json +20 -0
  161. package/registry/serve.ts +29 -0
  162. package/rules/architecture.md +47 -0
  163. package/rules/cloudflare.md +74 -0
  164. package/rules/code.md +12 -0
  165. package/rules/git.md +10 -0
  166. package/rules/index.md +14 -0
  167. package/rules/observability.md +13 -0
  168. package/rules/performance.md +39 -0
  169. package/rules/runtime.md +9 -0
  170. package/rules/secrets.md +11 -0
  171. package/rules/stack.md +33 -0
  172. package/rules/ui.md +23 -0
  173. package/runtime/ai.test.ts +106 -0
  174. package/runtime/ai.ts +125 -0
  175. package/runtime/observability/allowlists.ts +42 -0
  176. package/runtime/observability/anonymize.test.ts +111 -0
  177. package/runtime/observability/anonymize.ts +249 -0
  178. package/runtime/observability/browser.test.ts +46 -0
  179. package/runtime/observability/browser.ts +126 -0
  180. package/runtime/observability/server.test.ts +84 -0
  181. package/runtime/observability/server.ts +152 -0
  182. package/runtime/observability/tunnel.test.ts +276 -0
  183. package/runtime/observability/tunnel.ts +360 -0
  184. package/runtime/observability/user-agent.ts +51 -0
  185. package/schema/rc.config.schema.json +333 -0
  186. package/template/.gitattributes +1 -0
  187. package/template/.github/workflows/ci.yml +64 -0
  188. package/template/CLAUDE.md +48 -0
  189. package/template/README.md +50 -0
  190. package/template/apps/admin/.dev.vars.example +5 -0
  191. package/template/apps/admin/components.json +24 -0
  192. package/template/apps/admin/package.json +48 -0
  193. package/template/apps/admin/public/favicon.svg +1 -0
  194. package/template/apps/admin/src/components/app-shell.tsx +41 -0
  195. package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
  196. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
  197. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
  198. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
  199. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
  200. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
  201. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
  202. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
  203. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
  204. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
  205. package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
  206. package/template/apps/admin/src/components/login-form.tsx +115 -0
  207. package/template/apps/admin/src/components/login-sent.tsx +23 -0
  208. package/template/apps/admin/src/components/message-list.tsx +44 -0
  209. package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
  210. package/template/apps/admin/src/components/ui/button.tsx +87 -0
  211. package/template/apps/admin/src/components/ui/callout.tsx +84 -0
  212. package/template/apps/admin/src/components/ui/card.tsx +48 -0
  213. package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
  214. package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
  215. package/template/apps/admin/src/components/ui/field.tsx +100 -0
  216. package/template/apps/admin/src/components/ui/input.tsx +73 -0
  217. package/template/apps/admin/src/components/ui/label.tsx +39 -0
  218. package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
  219. package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
  220. package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
  221. package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
  222. package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
  223. package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
  224. package/template/apps/admin/src/lib/api.ts +39 -0
  225. package/template/apps/admin/src/lib/auth-client.ts +7 -0
  226. package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
  227. package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
  228. package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
  229. package/template/apps/admin/src/lib/messages.ts +5 -0
  230. package/template/apps/admin/src/lib/query-keys.ts +3 -0
  231. package/template/apps/admin/src/lib/security-headers.ts +18 -0
  232. package/template/apps/admin/src/lib/session.ts +27 -0
  233. package/template/apps/admin/src/lib/site-url.ts +7 -0
  234. package/template/apps/admin/src/lib/turnstile.ts +70 -0
  235. package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
  236. package/template/apps/admin/src/lib/utils.ts +6 -0
  237. package/template/apps/admin/src/routeTree.gen.ts +109 -0
  238. package/template/apps/admin/src/router.tsx +29 -0
  239. package/template/apps/admin/src/routes/__root.tsx +56 -0
  240. package/template/apps/admin/src/routes/_app/index.tsx +38 -0
  241. package/template/apps/admin/src/routes/_app.tsx +26 -0
  242. package/template/apps/admin/src/routes/login.tsx +48 -0
  243. package/template/apps/admin/src/styles/app.css +11 -0
  244. package/template/apps/admin/src/worker.ts +88 -0
  245. package/template/apps/admin/tsconfig.json +19 -0
  246. package/template/apps/admin/vite.config.ts +69 -0
  247. package/template/apps/admin/wrangler.jsonc +92 -0
  248. package/template/apps/web/.env.example +1 -0
  249. package/template/apps/web/astro.config.ts +46 -0
  250. package/template/apps/web/package.json +33 -0
  251. package/template/apps/web/public/favicon.svg +1 -0
  252. package/template/apps/web/src/components/ContactForm.astro +78 -0
  253. package/template/apps/web/src/env.d.ts +11 -0
  254. package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
  255. package/template/apps/web/src/lib/api.ts +8 -0
  256. package/template/apps/web/src/pages/api/messages.ts +32 -0
  257. package/template/apps/web/src/pages/index.astro +26 -0
  258. package/template/apps/web/src/pages/media/[...key].ts +4 -0
  259. package/template/apps/web/src/scripts/contact-form.ts +105 -0
  260. package/template/apps/web/src/scripts/error-reporting.ts +4 -0
  261. package/template/apps/web/src/scripts/turnstile.ts +177 -0
  262. package/template/apps/web/src/styles/global.css +11 -0
  263. package/template/apps/web/src/worker.ts +34 -0
  264. package/template/apps/web/tsconfig.json +11 -0
  265. package/template/apps/web/wrangler.jsonc +45 -0
  266. package/template/bun.lock +1925 -0
  267. package/template/bunfig.toml +2 -0
  268. package/template/gitignore +23 -0
  269. package/template/package.json +74 -0
  270. package/template/packages/api/components.json +21 -0
  271. package/template/packages/api/package.json +30 -0
  272. package/template/packages/api/src/client.ts +13 -0
  273. package/template/packages/api/src/cloudflare-env.d.ts +26 -0
  274. package/template/packages/api/src/emails/escape-html.ts +13 -0
  275. package/template/packages/api/src/emails/layout.ts +22 -0
  276. package/template/packages/api/src/emails/magic-link.ts +32 -0
  277. package/template/packages/api/src/emails/new-message.ts +32 -0
  278. package/template/packages/api/src/emails/send.ts +14 -0
  279. package/template/packages/api/src/lib/auth-guard.ts +16 -0
  280. package/template/packages/api/src/lib/auth.ts +108 -0
  281. package/template/packages/api/src/lib/context.ts +7 -0
  282. package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
  283. package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
  284. package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
  285. package/template/packages/api/src/lib/dev-inbox.ts +6 -0
  286. package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
  287. package/template/packages/api/src/lib/environment.ts +17 -0
  288. package/template/packages/api/src/lib/turnstile.ts +33 -0
  289. package/template/packages/api/src/media.ts +45 -0
  290. package/template/packages/api/src/routes/admin-messages.ts +21 -0
  291. package/template/packages/api/src/routes/dev.ts +31 -0
  292. package/template/packages/api/src/routes/health.ts +7 -0
  293. package/template/packages/api/src/routes/messages.ts +58 -0
  294. package/template/packages/api/src/schemas.ts +18 -0
  295. package/template/packages/api/src/server.ts +29 -0
  296. package/template/packages/api/tsconfig.json +10 -0
  297. package/template/packages/db/migrations/0001_init.sql +79 -0
  298. package/template/packages/db/package.json +34 -0
  299. package/template/packages/db/prisma/schema.prisma +95 -0
  300. package/template/packages/db/prisma.config.ts +9 -0
  301. package/template/packages/db/scripts/migrate.ts +15 -0
  302. package/template/packages/db/scripts/new-migration.ts +185 -0
  303. package/template/packages/db/scripts/reset.ts +54 -0
  304. package/template/packages/db/scripts/seed.ts +44 -0
  305. package/template/packages/db/scripts/wrangler.ts +35 -0
  306. package/template/packages/db/src/d1.ts +7 -0
  307. package/template/packages/db/src/migration-guard.test.ts +43 -0
  308. package/template/packages/db/src/migration-guard.ts +51 -0
  309. package/template/packages/db/src/new-migration.test.ts +16 -0
  310. package/template/packages/db/src/scope.ts +38 -0
  311. package/template/packages/db/src/seed.ts +30 -0
  312. package/template/packages/db/src/sql.ts +42 -0
  313. package/template/packages/db/tsconfig.json +8 -0
  314. package/template/packages/shared/components.json +21 -0
  315. package/template/packages/shared/package.json +33 -0
  316. package/template/packages/shared/src/edge/origins.ts +20 -0
  317. package/template/packages/shared/src/edge/turnstile.ts +11 -0
  318. package/template/packages/shared/src/locales.ts +13 -0
  319. package/template/packages/shared/src/message-rules.ts +16 -0
  320. package/template/packages/shared/src/messages.test.ts +26 -0
  321. package/template/packages/shared/src/messages.ts +30 -0
  322. package/template/packages/shared/src/observability/build-release.ts +9 -0
  323. package/template/packages/shared/src/observability/error-reporting.ts +31 -0
  324. package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
  325. package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
  326. package/template/packages/shared/src/observability/server-errors.ts +74 -0
  327. package/template/packages/shared/src/project.ts +1 -0
  328. package/template/packages/shared/src/styles/rc-theme.css +138 -0
  329. package/template/packages/shared/src/styles/theme.css +9 -0
  330. package/template/packages/shared/tsconfig.json +10 -0
  331. package/template/rc.config.json +25 -0
  332. package/template/scripts/bootstrap-local.ts +42 -0
  333. package/template/tsconfig.base.json +20 -0
  334. package/template/tsconfig.json +8 -0
  335. package/template/tsconfig.worker.json +7 -0
  336. package/template/turbo.json +40 -0
  337. package/template/vite.config.ts +8 -0
@@ -0,0 +1,100 @@
1
+ import { createContext, type ReactNode, useContext } from "react"
2
+ import { FieldError } from "@/components/ui/field-error"
3
+ import { Label } from "@/components/ui/label"
4
+ import { cn } from "@/lib/utils"
5
+
6
+ interface FieldControl {
7
+ describedBy?: string
8
+ id: string
9
+ invalid: boolean
10
+ }
11
+
12
+ const FieldContext = createContext<FieldControl | null>(null)
13
+
14
+ /** Lets a control inside a Field pick up its hint, error and invalid state without prop drilling. */
15
+ export function useFieldControl(id: string | undefined) {
16
+ const field = useContext(FieldContext)
17
+
18
+ if (!(field && id === field.id)) {
19
+ return { describedBy: undefined, invalid: undefined }
20
+ }
21
+
22
+ return {
23
+ describedBy: field.describedBy,
24
+ invalid: field.invalid || undefined,
25
+ }
26
+ }
27
+
28
+ export function joinIds(...ids: (string | undefined)[]): string | undefined {
29
+ const joined = ids.filter(Boolean).join(" ")
30
+
31
+ return joined || undefined
32
+ }
33
+
34
+ export function FieldHint({
35
+ children,
36
+ id,
37
+ }: {
38
+ children: ReactNode
39
+ id?: string
40
+ }) {
41
+ return (
42
+ <p className="text-sm leading-snug text-ink-3" id={id}>
43
+ {children}
44
+ </p>
45
+ )
46
+ }
47
+
48
+ export interface FieldProps {
49
+ /** Sits at the end of the label row: a counter, a link, a small action. */
50
+ action?: ReactNode
51
+ children: ReactNode
52
+ className?: string
53
+ error?: string | null
54
+ hint?: ReactNode
55
+ htmlFor: string
56
+ label: string
57
+ optional?: boolean
58
+ required?: boolean
59
+ }
60
+
61
+ export function Field({
62
+ label,
63
+ htmlFor,
64
+ error,
65
+ hint,
66
+ action,
67
+ optional,
68
+ required,
69
+ children,
70
+ className,
71
+ }: FieldProps) {
72
+ const hintId = hint ? `${htmlFor}-hint` : undefined
73
+ const errorId = error ? `${htmlFor}-error` : undefined
74
+
75
+ return (
76
+ <FieldContext.Provider
77
+ value={{
78
+ describedBy: joinIds(errorId, hintId),
79
+ id: htmlFor,
80
+ invalid: Boolean(error),
81
+ }}
82
+ >
83
+ <div className={cn("flex min-w-0 flex-col gap-2", className)}>
84
+ <div className="flex min-h-5 items-end justify-between gap-3">
85
+ <Label htmlFor={htmlFor} optional={optional} required={required}>
86
+ {label}
87
+ </Label>
88
+ {action}
89
+ </div>
90
+ {children}
91
+ {error || hint ? (
92
+ <div className="flex flex-col gap-1">
93
+ <FieldError id={errorId}>{error}</FieldError>
94
+ {hint ? <FieldHint id={hintId}>{hint}</FieldHint> : null}
95
+ </div>
96
+ ) : null}
97
+ </div>
98
+ </FieldContext.Provider>
99
+ )
100
+ }
@@ -0,0 +1,73 @@
1
+ import type { ComponentProps, CSSProperties, InputHTMLAttributes } from "react"
2
+ import { joinIds, useFieldControl } from "@/components/ui/field"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ export interface InputProps extends ComponentProps<"input"> {
6
+ /** A short unit shown inside the end of the box: €, km, min. */
7
+ unit?: string
8
+ }
9
+
10
+ export const CONTROL_CLASS_NAME = cn(
11
+ "min-h-10 w-full rounded-md border border-line bg-surface text-base leading-snug text-ink sm:text-sm",
12
+ "transition-[border-color,box-shadow,background-color] duration-200 ease-out-expo",
13
+ "hover:border-line-strong",
14
+ "focus-visible:border-accent focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-accent/20",
15
+ "disabled:cursor-not-allowed disabled:border-dashed disabled:bg-paper disabled:text-ink-3 disabled:hover:border-line",
16
+ "aria-invalid:border-danger aria-invalid:focus-visible:ring-danger/20"
17
+ )
18
+
19
+ export function useControlAria({
20
+ id,
21
+ "aria-describedby": describedBy,
22
+ "aria-invalid": invalid,
23
+ }: {
24
+ "aria-describedby"?: string
25
+ "aria-invalid"?: InputHTMLAttributes<HTMLElement>["aria-invalid"]
26
+ id?: string
27
+ }) {
28
+ const field = useFieldControl(id)
29
+
30
+ return {
31
+ "aria-describedby": joinIds(describedBy, field.describedBy),
32
+ "aria-invalid": invalid ?? field.invalid,
33
+ }
34
+ }
35
+
36
+ export function Input({ className, unit, ...props }: InputProps) {
37
+ const aria = useControlAria(props)
38
+
39
+ if (!unit) {
40
+ return (
41
+ <input
42
+ className={cn(
43
+ CONTROL_CLASS_NAME,
44
+ "px-3 placeholder:text-ink-3",
45
+ className
46
+ )}
47
+ {...props}
48
+ {...aria}
49
+ />
50
+ )
51
+ }
52
+
53
+ const unitStyle = { "--unit-chars": unit.length } as CSSProperties
54
+
55
+ return (
56
+ <div className={cn("relative", className)} style={unitStyle}>
57
+ <input
58
+ className={cn(
59
+ CONTROL_CLASS_NAME,
60
+ "pr-[max(2.75rem,calc(var(--unit-chars)*1ch+1.5rem))] pl-3 placeholder:text-ink-3"
61
+ )}
62
+ {...props}
63
+ {...aria}
64
+ />
65
+ <span
66
+ aria-hidden="true"
67
+ className="pointer-events-none absolute inset-y-0 right-0 grid min-w-10 place-items-center px-3 text-sm font-medium text-ink-3"
68
+ >
69
+ {unit}
70
+ </span>
71
+ </div>
72
+ )
73
+ }
@@ -0,0 +1,39 @@
1
+ import type { LabelHTMLAttributes } from "react"
2
+ import { useUiLabels } from "@/lib/ui-labels"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
6
+ optional?: boolean
7
+ required?: boolean
8
+ }
9
+
10
+ export const LABEL_CLASS_NAME = "text-sm font-medium leading-5 text-ink"
11
+
12
+ export function Label({
13
+ className,
14
+ children,
15
+ optional = false,
16
+ required = false,
17
+ ...props
18
+ }: LabelProps) {
19
+ const labels = useUiLabels()
20
+
21
+ return (
22
+ <label className={cn(LABEL_CLASS_NAME, className)} {...props}>
23
+ {children}
24
+ {required ? (
25
+ <>
26
+ <span aria-hidden="true" className="ml-0.5 text-danger">
27
+ *
28
+ </span>
29
+ <span className="sr-only"> ({labels.required})</span>
30
+ </>
31
+ ) : null}
32
+ {optional && !required ? (
33
+ <span className="ml-1.5 text-xs font-normal text-ink-3">
34
+ {labels.optional}
35
+ </span>
36
+ ) : null}
37
+ </label>
38
+ )
39
+ }
@@ -0,0 +1,225 @@
1
+ import { cn } from "@/lib/utils"
2
+
3
+ export type SkeletonTone = "light" | "dark"
4
+
5
+ export function Skeleton({
6
+ className,
7
+ tone = "light",
8
+ }: {
9
+ className?: string
10
+ tone?: SkeletonTone
11
+ }) {
12
+ return (
13
+ <span
14
+ aria-hidden="true"
15
+ className={cn(
16
+ "shimmer block rounded-sm",
17
+ tone === "dark"
18
+ ? "bg-night-2 [--shimmer-color:var(--color-night-line)]"
19
+ : "bg-ink/6",
20
+ className
21
+ )}
22
+ />
23
+ )
24
+ }
25
+
26
+ function placeholders(count: number): string[] {
27
+ return Array.from({ length: count }, (_, index) => `placeholder-${index}`)
28
+ }
29
+
30
+ const TEXT_WIDTHS = ["w-full", "w-11/12", "w-4/5", "w-2/3", "w-1/2"]
31
+
32
+ export function SkeletonText({
33
+ lines = 3,
34
+ className,
35
+ }: {
36
+ className?: string
37
+ lines?: number
38
+ }) {
39
+ return (
40
+ <span aria-hidden="true" className={cn("flex flex-col gap-2", className)}>
41
+ {placeholders(lines).map((key, line) => (
42
+ <Skeleton
43
+ className={cn(
44
+ "h-3.5",
45
+ line === lines - 1 && lines > 1
46
+ ? "w-1/2"
47
+ : TEXT_WIDTHS[line % TEXT_WIDTHS.length]
48
+ )}
49
+ key={key}
50
+ />
51
+ ))}
52
+ </span>
53
+ )
54
+ }
55
+
56
+ export type SkeletonMedia = "avatar" | "icon" | "none"
57
+
58
+ /** Stand-in for a `divide-y` list of rows: optional square, two lines, a trailing meta. */
59
+ export function SkeletonRows({
60
+ count = 3,
61
+ media = "icon",
62
+ bordered = false,
63
+ className,
64
+ }: {
65
+ bordered?: boolean
66
+ className?: string
67
+ count?: number
68
+ media?: SkeletonMedia
69
+ }) {
70
+ return (
71
+ <ul
72
+ aria-hidden="true"
73
+ className={cn(
74
+ "divide-y divide-line",
75
+ bordered && "rounded-lg border border-line bg-surface",
76
+ className
77
+ )}
78
+ >
79
+ {placeholders(count).map((key) => (
80
+ <li className="flex items-center gap-3 px-5 py-4 sm:px-6" key={key}>
81
+ {media === "none" ? null : (
82
+ <Skeleton
83
+ className={cn(
84
+ "size-10 shrink-0",
85
+ media === "avatar" && "rounded-full"
86
+ )}
87
+ />
88
+ )}
89
+ <span className="flex min-w-0 flex-1 flex-col gap-2">
90
+ <Skeleton className="h-3.5 w-40 max-w-full" />
91
+ <Skeleton className="h-3 w-64 max-w-full" />
92
+ </span>
93
+ <Skeleton className="h-5 w-16 shrink-0 max-sm:hidden" />
94
+ </li>
95
+ ))}
96
+ </ul>
97
+ )
98
+ }
99
+
100
+ /** Stand-in for a row of `StatTile`s. */
101
+ export function SkeletonTiles({
102
+ count = 4,
103
+ className,
104
+ }: {
105
+ className?: string
106
+ count?: number
107
+ }) {
108
+ return (
109
+ <div
110
+ aria-hidden="true"
111
+ className={cn("grid grid-cols-2 gap-3 lg:grid-cols-4", className)}
112
+ >
113
+ {placeholders(count).map((key) => (
114
+ <div
115
+ className="flex min-h-32 flex-col justify-between rounded-lg border border-line bg-surface p-5"
116
+ key={key}
117
+ >
118
+ <Skeleton className="h-3 w-24" />
119
+ <Skeleton className="h-9 w-16" />
120
+ </div>
121
+ ))}
122
+ </div>
123
+ )
124
+ }
125
+
126
+ /** Stand-in for a `Card` with a header and a few rows. */
127
+ export function SkeletonCard({
128
+ rows = 3,
129
+ media = "none",
130
+ className,
131
+ }: {
132
+ className?: string
133
+ media?: SkeletonMedia
134
+ rows?: number
135
+ }) {
136
+ return (
137
+ <section
138
+ aria-hidden="true"
139
+ className={cn("rounded-lg border border-line bg-surface", className)}
140
+ >
141
+ <header className="flex flex-col gap-2 border-b border-line px-5 py-4 sm:px-6">
142
+ <Skeleton className="h-5 w-44 max-w-full" />
143
+ </header>
144
+ <SkeletonRows count={rows} media={media} />
145
+ </section>
146
+ )
147
+ }
148
+
149
+ /** Stand-in for a grid of picture cards. */
150
+ export function SkeletonGrid({
151
+ count = 6,
152
+ className,
153
+ }: {
154
+ className?: string
155
+ count?: number
156
+ }) {
157
+ return (
158
+ <div
159
+ aria-hidden="true"
160
+ className={cn(
161
+ "grid gap-3 sm:grid-cols-2 sm:gap-4 xl:grid-cols-3",
162
+ className
163
+ )}
164
+ >
165
+ {placeholders(count).map((key) => (
166
+ <div
167
+ className="flex flex-col overflow-hidden rounded-lg border border-line bg-surface"
168
+ key={key}
169
+ >
170
+ <Skeleton className="aspect-16/10 w-full rounded-none" />
171
+ <span className="flex flex-col gap-2 p-5">
172
+ <Skeleton className="h-5 w-40 max-w-full" />
173
+ <Skeleton className="h-3 w-56 max-w-full" />
174
+ </span>
175
+ </div>
176
+ ))}
177
+ </div>
178
+ )
179
+ }
180
+
181
+ /** Stand-in for a `PageHeader`. */
182
+ export function SkeletonPageHeader({ className }: { className?: string }) {
183
+ return (
184
+ <div
185
+ aria-hidden="true"
186
+ className={cn("mb-8 flex flex-col gap-3", className)}
187
+ >
188
+ <Skeleton className="h-3 w-28" />
189
+ <Skeleton className="h-9 w-72 max-w-full" />
190
+ <Skeleton className="h-4 w-full max-w-md" />
191
+ </div>
192
+ )
193
+ }
194
+
195
+ /** Stand-in for a detail page body: a main column and a side column of cards, one entry per card with its row count. */
196
+ export function SkeletonDetailColumns({
197
+ main = [4, 2],
198
+ side = [2, 3],
199
+ className,
200
+ }: {
201
+ className?: string
202
+ main?: number[]
203
+ side?: number[]
204
+ }) {
205
+ return (
206
+ <div
207
+ aria-hidden="true"
208
+ className={cn(
209
+ "grid gap-4 sm:gap-5 lg:grid-cols-[minmax(0,1fr)_22rem] lg:items-start",
210
+ className
211
+ )}
212
+ >
213
+ {[main, side].map((cards, column) => (
214
+ <div
215
+ className="flex flex-col gap-4 sm:gap-5"
216
+ key={column === 0 ? "main" : "side"}
217
+ >
218
+ {placeholders(cards.length).map((key, card) => (
219
+ <SkeletonCard key={key} rows={cards[card]} />
220
+ ))}
221
+ </div>
222
+ ))}
223
+ </div>
224
+ )
225
+ }
@@ -0,0 +1,12 @@
1
+ import { LoaderCircle } from "lucide-react"
2
+ import { cn } from "@/lib/utils"
3
+
4
+ export function Spinner({ className }: { className?: string }) {
5
+ return (
6
+ <LoaderCircle
7
+ aria-hidden="true"
8
+ className={cn("size-4 shrink-0 animate-spin", className)}
9
+ strokeWidth={2}
10
+ />
11
+ )
12
+ }
@@ -0,0 +1,33 @@
1
+ import { Toaster as SonnerToaster, type ToasterProps } from "sonner"
2
+
3
+ /** Mount once near the root; call `toast.success(…)`, `toast.error(…)` from `sonner` anywhere. */
4
+ export function Toaster(props: ToasterProps) {
5
+ return (
6
+ <SonnerToaster
7
+ closeButton
8
+ duration={3500}
9
+ position="top-right"
10
+ toastOptions={{
11
+ unstyled: true,
12
+ classNames: {
13
+ toast:
14
+ "flex w-full items-start gap-3 rounded-md border border-line border-l-4 bg-surface px-4 py-3 text-sm text-ink shadow-lg sm:w-96",
15
+ title: "font-semibold leading-snug",
16
+ description: "leading-snug text-ink-2",
17
+ icon: "mt-0.5 shrink-0",
18
+ actionButton:
19
+ "ml-auto shrink-0 rounded-sm px-2 py-1 text-sm font-medium text-accent hover:bg-accent-soft",
20
+ cancelButton:
21
+ "shrink-0 rounded-sm px-2 py-1 text-sm font-medium text-ink-2 hover:bg-ink/5",
22
+ closeButton:
23
+ "order-last -my-1 -mr-1 grid size-7 shrink-0 place-items-center rounded-sm text-ink-3 hover:bg-ink/5 hover:text-ink",
24
+ success: "border-l-success [&_[data-icon]]:text-success",
25
+ error: "border-l-danger [&_[data-icon]]:text-danger",
26
+ warning: "border-l-warn [&_[data-icon]]:text-warn",
27
+ info: "border-l-accent [&_[data-icon]]:text-accent",
28
+ },
29
+ }}
30
+ {...props}
31
+ />
32
+ )
33
+ }
@@ -0,0 +1,51 @@
1
+ import { Tooltip as BaseTooltip } from "@base-ui/react/tooltip"
2
+ import type { ReactElement, ReactNode } from "react"
3
+
4
+ export type TooltipSide = "top" | "bottom" | "left" | "right"
5
+
6
+ export interface TooltipProps {
7
+ children: ReactElement<Record<string, unknown>>
8
+ disabled?: boolean
9
+ label: string
10
+ /** False when the trigger already speaks for itself and the bubble only adds detail. */
11
+ nameTrigger?: boolean
12
+ side?: TooltipSide
13
+ }
14
+
15
+ export function TooltipProvider({ children }: { children: ReactNode }) {
16
+ return (
17
+ <BaseTooltip.Provider closeDelay={0} delay={350}>
18
+ {children}
19
+ </BaseTooltip.Provider>
20
+ )
21
+ }
22
+
23
+ /** Screen readers ignore the bubble, so the label also becomes the trigger's aria-label. */
24
+ export function Tooltip({
25
+ label,
26
+ side = "top",
27
+ disabled = false,
28
+ nameTrigger = true,
29
+ children,
30
+ }: TooltipProps) {
31
+ return (
32
+ <BaseTooltip.Root disabled={disabled}>
33
+ <BaseTooltip.Trigger
34
+ aria-label={nameTrigger ? label : undefined}
35
+ render={children}
36
+ />
37
+ <BaseTooltip.Portal>
38
+ <BaseTooltip.Positioner
39
+ className="z-70"
40
+ collisionPadding={8}
41
+ side={side}
42
+ sideOffset={6}
43
+ >
44
+ <BaseTooltip.Popup className="max-w-64 rounded-sm bg-ink px-2 py-1 text-xs font-medium leading-snug text-chalk shadow-md transition-[opacity,transform] duration-150 ease-out-expo data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 data-[starting-style]:data-[side=bottom]:-translate-y-0.5 data-[starting-style]:data-[side=top]:translate-y-0.5 motion-reduce:transition-none">
45
+ {label}
46
+ </BaseTooltip.Popup>
47
+ </BaseTooltip.Positioner>
48
+ </BaseTooltip.Portal>
49
+ </BaseTooltip.Root>
50
+ )
51
+ }
@@ -0,0 +1,25 @@
1
+ import { useQuery } from "@tanstack/react-query"
2
+ import { useMemo } from "react"
3
+ import type { DevToolsClient } from "@/lib/dev-tools-client"
4
+
5
+ const POLL_MS = 2500
6
+
7
+ export function useDevInbox(client: DevToolsClient) {
8
+ const query = useQuery({
9
+ queryFn: client.inbox,
10
+ queryKey: client.queryKeys.inbox,
11
+ refetchInterval: POLL_MS,
12
+ retry: false,
13
+ throwOnError: false,
14
+ })
15
+
16
+ const messages = useMemo(() => query.data ?? [], [query.data])
17
+ const unreadCount = useMemo(
18
+ () => messages.filter((message) => !message.readAt).length,
19
+ [messages]
20
+ )
21
+
22
+ return { messages, query, unreadCount }
23
+ }
24
+
25
+ export type DevInbox = ReturnType<typeof useDevInbox>
@@ -0,0 +1,48 @@
1
+ import { useCallback, useEffect, useState } from "react"
2
+
3
+ const STORAGE_KEY = "rc_dev_toolbar"
4
+
5
+ interface DevToolbarState {
6
+ open: boolean
7
+ tab: string
8
+ }
9
+
10
+ const DEFAULT_STATE: DevToolbarState = { open: false, tab: "inbox" }
11
+
12
+ function readState(): DevToolbarState {
13
+ try {
14
+ const stored = JSON.parse(
15
+ window.sessionStorage.getItem(STORAGE_KEY) ?? "null"
16
+ ) as Partial<DevToolbarState> | null
17
+
18
+ return {
19
+ open: stored?.open === true,
20
+ tab: typeof stored?.tab === "string" ? stored.tab : DEFAULT_STATE.tab,
21
+ }
22
+ } catch {
23
+ return DEFAULT_STATE
24
+ }
25
+ }
26
+
27
+ /** Signing in again reloads the page; the tab's session brings the toolbar back where it was. */
28
+ export function useDevToolbarState() {
29
+ const [state, setState] = useState(readState)
30
+
31
+ useEffect(() => {
32
+ try {
33
+ window.sessionStorage.setItem(STORAGE_KEY, JSON.stringify(state))
34
+ } catch {
35
+ // Storage can be unavailable (private mode); the toolbar still works.
36
+ }
37
+ }, [state])
38
+
39
+ const setOpen = useCallback((open: boolean) => {
40
+ setState((current) => ({ ...current, open }))
41
+ }, [])
42
+
43
+ const setTab = useCallback((tab: string) => {
44
+ setState((current) => ({ ...current, tab }))
45
+ }, [])
46
+
47
+ return { open: state.open, setOpen, setTab, tab: state.tab }
48
+ }
@@ -0,0 +1,39 @@
1
+ import { createApiClient } from "@tpl/api/client"
2
+
3
+ // Same origin in every environment: the admin Worker serves `/api/*` itself.
4
+ export const api = createApiClient(
5
+ typeof window === "undefined" ? "http://localhost" : window.location.origin
6
+ ).api
7
+
8
+ interface TEdenResult<T> {
9
+ data: T | null
10
+ error: { status: unknown; value: unknown } | null
11
+ }
12
+
13
+ export class ApiRequestError extends Error {
14
+ readonly status: number
15
+
16
+ constructor(message: string, status: number) {
17
+ super(message)
18
+ this.status = status
19
+ }
20
+ }
21
+
22
+ function messageOf(value: unknown): string {
23
+ if (value && typeof value === "object" && "message" in value) {
24
+ return String(value.message)
25
+ }
26
+
27
+ return "La requête a échoué."
28
+ }
29
+
30
+ /** Unwraps an Eden response so TanStack Query sees a thrown error instead of `{ error }`. */
31
+ export async function unwrap<T>(request: Promise<TEdenResult<T>>): Promise<T> {
32
+ const { data, error } = await request
33
+
34
+ if (error) {
35
+ throw new ApiRequestError(messageOf(error.value), Number(error.status))
36
+ }
37
+
38
+ return data as T
39
+ }
@@ -0,0 +1,7 @@
1
+ import { magicLinkClient } from "better-auth/client/plugins"
2
+ import { createAuthClient } from "better-auth/react"
3
+
4
+ export const authClient = createAuthClient({
5
+ basePath: "/api/auth",
6
+ plugins: [magicLinkClient()],
7
+ })