@alepha/ui 0.35.0 → 0.36.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 (264) hide show
  1. package/README.md +54 -1
  2. package/dist/account/AccountBrand.d.ts +10 -3
  3. package/dist/account/AccountBrand.d.ts.map +1 -1
  4. package/dist/account/AccountBrand.js +12 -6
  5. package/dist/account/AccountBrand.js.map +1 -1
  6. package/dist/account/AccountLayout.d.ts.map +1 -1
  7. package/dist/account/AccountLayout.js +1 -1
  8. package/dist/account/AccountLayout.js.map +1 -1
  9. package/dist/admin/AdminUserDetail.d.ts +3 -3
  10. package/dist/admin/AdminUserDetail.js +3 -3
  11. package/dist/admin/AdminUserDetail.js.map +1 -1
  12. package/dist/ai/AiChat.d.ts +36 -6
  13. package/dist/ai/AiChat.d.ts.map +1 -1
  14. package/dist/ai/AiChat.js +101 -63
  15. package/dist/ai/AiChat.js.map +1 -1
  16. package/dist/ai/AiChatComposer.d.ts +22 -0
  17. package/dist/ai/AiChatComposer.d.ts.map +1 -0
  18. package/dist/ai/AiChatComposer.js +75 -0
  19. package/dist/ai/AiChatComposer.js.map +1 -0
  20. package/dist/ai/AiChatConfirmCard.d.ts +5 -2
  21. package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
  22. package/dist/ai/AiChatConfirmCard.js +7 -6
  23. package/dist/ai/AiChatConfirmCard.js.map +1 -1
  24. package/dist/ai/AiChatConfirmFields.d.ts +9 -0
  25. package/dist/ai/AiChatConfirmFields.d.ts.map +1 -0
  26. package/dist/ai/AiChatConfirmFields.js +45 -0
  27. package/dist/ai/AiChatConfirmFields.js.map +1 -0
  28. package/dist/ai/AiChatEmpty.d.ts +26 -0
  29. package/dist/ai/AiChatEmpty.d.ts.map +1 -0
  30. package/dist/ai/AiChatEmpty.js +47 -0
  31. package/dist/ai/AiChatEmpty.js.map +1 -0
  32. package/dist/ai/AiChatHistory.d.ts +3 -2
  33. package/dist/ai/AiChatHistory.d.ts.map +1 -1
  34. package/dist/ai/AiChatHistory.js +51 -22
  35. package/dist/ai/AiChatHistory.js.map +1 -1
  36. package/dist/ai/AiChatMessage.d.ts +14 -0
  37. package/dist/ai/AiChatMessage.d.ts.map +1 -1
  38. package/dist/ai/AiChatMessage.js +20 -12
  39. package/dist/ai/AiChatMessage.js.map +1 -1
  40. package/dist/ai/index.d.ts +3 -0
  41. package/dist/ai/index.d.ts.map +1 -1
  42. package/dist/ai/index.js +4 -1
  43. package/dist/ai/useAiChat.d.ts +4 -0
  44. package/dist/ai/useAiChat.d.ts.map +1 -1
  45. package/dist/ai/useAiChat.js +15 -1
  46. package/dist/ai/useAiChat.js.map +1 -1
  47. package/dist/core/Sidebar.js +2 -2
  48. package/dist/core/Sidebar.js.map +1 -1
  49. package/dist/core/index.d.ts +1 -0
  50. package/dist/core/index.d.ts.map +1 -1
  51. package/dist/core/index.js +2 -1
  52. package/dist/core/useToast.d.ts +22 -1
  53. package/dist/core/useToast.d.ts.map +1 -1
  54. package/dist/core/useToast.js +4 -1
  55. package/dist/core/useToast.js.map +1 -1
  56. package/dist/core/useUndoable.d.ts +93 -0
  57. package/dist/core/useUndoable.d.ts.map +1 -0
  58. package/dist/core/useUndoable.js +172 -0
  59. package/dist/core/useUndoable.js.map +1 -0
  60. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  61. package/dist/i18n/fr/uiFr.js +50 -1
  62. package/dist/i18n/fr/uiFr.js.map +1 -1
  63. package/dist/markdown/MarkdownView.d.ts +15 -0
  64. package/dist/markdown/MarkdownView.d.ts.map +1 -1
  65. package/dist/markdown/MarkdownView.js +4 -1
  66. package/dist/markdown/MarkdownView.js.map +1 -1
  67. package/dist/organizations/useInviteOrganizationMember.d.ts +2 -2
  68. package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
  69. package/dist/shell/AppShellSidebarNavItem.d.ts.map +1 -1
  70. package/dist/shell/AppShellSidebarNavItem.js +25 -2
  71. package/dist/shell/AppShellSidebarNavItem.js.map +1 -1
  72. package/dist/shell/PlateTabBar.d.ts.map +1 -1
  73. package/dist/shell/PlateTabBar.js +2 -2
  74. package/dist/shell/PlateTabBar.js.map +1 -1
  75. package/dist/shell/SidebarBackHeader.d.ts +35 -0
  76. package/dist/shell/SidebarBackHeader.d.ts.map +1 -0
  77. package/dist/shell/SidebarBackHeader.js +34 -0
  78. package/dist/shell/SidebarBackHeader.js.map +1 -0
  79. package/dist/shell/appShellNav.d.ts +30 -0
  80. package/dist/shell/appShellNav.d.ts.map +1 -1
  81. package/dist/shell/appShellNav.js.map +1 -1
  82. package/dist/shell/index.d.ts +2 -1
  83. package/dist/shell/index.d.ts.map +1 -1
  84. package/dist/shell/index.js +2 -1
  85. package/dist/swagger/$uiSwagger.d.ts +75 -0
  86. package/dist/swagger/$uiSwagger.d.ts.map +1 -0
  87. package/dist/swagger/$uiSwagger.js +51 -0
  88. package/dist/swagger/$uiSwagger.js.map +1 -0
  89. package/dist/swagger/OpenApiSpec.d.ts +113 -0
  90. package/dist/swagger/OpenApiSpec.d.ts.map +1 -0
  91. package/dist/swagger/OpenApiSpec.js +186 -0
  92. package/dist/swagger/OpenApiSpec.js.map +1 -0
  93. package/dist/swagger/SwaggerAccessBadge.d.ts +16 -0
  94. package/dist/swagger/SwaggerAccessBadge.d.ts.map +1 -0
  95. package/dist/swagger/SwaggerAccessBadge.js +40 -0
  96. package/dist/swagger/SwaggerAccessBadge.js.map +1 -0
  97. package/dist/swagger/SwaggerAlephaMeta.d.ts +11 -0
  98. package/dist/swagger/SwaggerAlephaMeta.d.ts.map +1 -0
  99. package/dist/swagger/SwaggerAlephaMeta.js +103 -0
  100. package/dist/swagger/SwaggerAlephaMeta.js.map +1 -0
  101. package/dist/swagger/SwaggerCredentials.d.ts +11 -0
  102. package/dist/swagger/SwaggerCredentials.d.ts.map +1 -0
  103. package/dist/swagger/SwaggerCredentials.js +35 -0
  104. package/dist/swagger/SwaggerCredentials.js.map +1 -0
  105. package/dist/swagger/SwaggerExplorer.d.ts +31 -0
  106. package/dist/swagger/SwaggerExplorer.d.ts.map +1 -0
  107. package/dist/swagger/SwaggerExplorer.js +156 -0
  108. package/dist/swagger/SwaggerExplorer.js.map +1 -0
  109. package/dist/swagger/SwaggerMethodBadge.d.ts +10 -0
  110. package/dist/swagger/SwaggerMethodBadge.d.ts.map +1 -0
  111. package/dist/swagger/SwaggerMethodBadge.js +27 -0
  112. package/dist/swagger/SwaggerMethodBadge.js.map +1 -0
  113. package/dist/swagger/SwaggerNav.d.ts +16 -0
  114. package/dist/swagger/SwaggerNav.d.ts.map +1 -0
  115. package/dist/swagger/SwaggerNav.js +63 -0
  116. package/dist/swagger/SwaggerNav.js.map +1 -0
  117. package/dist/swagger/SwaggerOperationView.d.ts +22 -0
  118. package/dist/swagger/SwaggerOperationView.d.ts.map +1 -0
  119. package/dist/swagger/SwaggerOperationView.js +89 -0
  120. package/dist/swagger/SwaggerOperationView.js.map +1 -0
  121. package/dist/swagger/SwaggerParameters.d.ts +11 -0
  122. package/dist/swagger/SwaggerParameters.d.ts.map +1 -0
  123. package/dist/swagger/SwaggerParameters.js +80 -0
  124. package/dist/swagger/SwaggerParameters.js.map +1 -0
  125. package/dist/swagger/SwaggerRequestBuilder.d.ts +83 -0
  126. package/dist/swagger/SwaggerRequestBuilder.d.ts.map +1 -0
  127. package/dist/swagger/SwaggerRequestBuilder.js +231 -0
  128. package/dist/swagger/SwaggerRequestBuilder.js.map +1 -0
  129. package/dist/swagger/SwaggerResponseView.d.ts +25 -0
  130. package/dist/swagger/SwaggerResponseView.d.ts.map +1 -0
  131. package/dist/swagger/SwaggerResponseView.js +94 -0
  132. package/dist/swagger/SwaggerResponseView.js.map +1 -0
  133. package/dist/swagger/SwaggerResponses.d.ts +12 -0
  134. package/dist/swagger/SwaggerResponses.d.ts.map +1 -0
  135. package/dist/swagger/SwaggerResponses.js +75 -0
  136. package/dist/swagger/SwaggerResponses.js.map +1 -0
  137. package/dist/swagger/SwaggerSchemaView.d.ts +19 -0
  138. package/dist/swagger/SwaggerSchemaView.d.ts.map +1 -0
  139. package/dist/swagger/SwaggerSchemaView.js +98 -0
  140. package/dist/swagger/SwaggerSchemaView.js.map +1 -0
  141. package/dist/swagger/SwaggerSection.d.ts +14 -0
  142. package/dist/swagger/SwaggerSection.d.ts.map +1 -0
  143. package/dist/swagger/SwaggerSection.js +23 -0
  144. package/dist/swagger/SwaggerSection.js.map +1 -0
  145. package/dist/swagger/SwaggerTryIt.d.ts +31 -0
  146. package/dist/swagger/SwaggerTryIt.d.ts.map +1 -0
  147. package/dist/swagger/SwaggerTryIt.js +68 -0
  148. package/dist/swagger/SwaggerTryIt.js.map +1 -0
  149. package/dist/swagger/SwaggerTryItForm.d.ts +20 -0
  150. package/dist/swagger/SwaggerTryItForm.d.ts.map +1 -0
  151. package/dist/swagger/SwaggerTryItForm.js +52 -0
  152. package/dist/swagger/SwaggerTryItForm.js.map +1 -0
  153. package/dist/swagger/index.d.ts +29 -0
  154. package/dist/swagger/index.d.ts.map +1 -0
  155. package/dist/swagger/index.js +18 -0
  156. package/dist/swagger/useSwaggerAccess.d.ts +24 -0
  157. package/dist/swagger/useSwaggerAccess.d.ts.map +1 -0
  158. package/dist/swagger/useSwaggerAccess.js +33 -0
  159. package/dist/swagger/useSwaggerAccess.js.map +1 -0
  160. package/dist/table/DataTable.d.ts.map +1 -1
  161. package/dist/table/DataTable.js +50 -13
  162. package/dist/table/DataTable.js.map +1 -1
  163. package/dist/table/DataTableBody.d.ts +18 -1
  164. package/dist/table/DataTableBody.d.ts.map +1 -1
  165. package/dist/table/DataTableBody.js +83 -58
  166. package/dist/table/DataTableBody.js.map +1 -1
  167. package/dist/table/DataTableRowActionsInline.d.ts +17 -0
  168. package/dist/table/DataTableRowActionsInline.d.ts.map +1 -0
  169. package/dist/table/DataTableRowActionsInline.js +45 -0
  170. package/dist/table/DataTableRowActionsInline.js.map +1 -0
  171. package/dist/table/PermissionMatrix.d.ts +4 -4
  172. package/dist/table/PermissionMatrix.js +2 -2
  173. package/dist/table/PermissionMatrix.js.map +1 -1
  174. package/dist/table/dataTableBaseProps.d.ts +31 -0
  175. package/dist/table/dataTableBaseProps.d.ts.map +1 -1
  176. package/dist/table/dataTableTypes.d.ts +16 -2
  177. package/dist/table/dataTableTypes.d.ts.map +1 -1
  178. package/dist/table/useDataTableData.d.ts +3 -0
  179. package/dist/table/useDataTableData.d.ts.map +1 -1
  180. package/dist/table/useDataTableData.js +9 -2
  181. package/dist/table/useDataTableData.js.map +1 -1
  182. package/dist/table/useDataTableRefresh.d.ts +1 -0
  183. package/dist/table/useDataTableRefresh.d.ts.map +1 -1
  184. package/dist/table/useDataTableRefresh.js +13 -1
  185. package/dist/table/useDataTableRefresh.js.map +1 -1
  186. package/dist/table/useOptimisticRows.d.ts +64 -0
  187. package/dist/table/useOptimisticRows.d.ts.map +1 -0
  188. package/dist/table/useOptimisticRows.js +185 -0
  189. package/dist/table/useOptimisticRows.js.map +1 -0
  190. package/dist/table/useRowMotion.d.ts +27 -0
  191. package/dist/table/useRowMotion.d.ts.map +1 -0
  192. package/dist/table/useRowMotion.js +112 -0
  193. package/dist/table/useRowMotion.js.map +1 -0
  194. package/docs/packages-alepha-ui-core.md +1 -0
  195. package/docs/packages-alepha-ui-overview.md +53 -1
  196. package/docs/packages-alepha-ui-swagger.md +35 -0
  197. package/package.json +11 -3
  198. package/src/account/AccountBrand.tsx +25 -6
  199. package/src/account/AccountLayout.tsx +5 -1
  200. package/src/admin/AdminUserDetail.tsx +3 -3
  201. package/src/admin/__tests__/AdminUserDetail.spec.ts +2 -2
  202. package/src/ai/AiChat.tsx +160 -82
  203. package/src/ai/AiChatComposer.tsx +117 -0
  204. package/src/ai/AiChatConfirmCard.tsx +7 -5
  205. package/src/ai/AiChatConfirmFields.tsx +65 -0
  206. package/src/ai/AiChatEmpty.tsx +73 -0
  207. package/src/ai/AiChatHistory.tsx +64 -28
  208. package/src/ai/AiChatMessage.tsx +41 -14
  209. package/src/ai/__tests__/AiChat.browser.spec.tsx +146 -5
  210. package/src/ai/index.ts +3 -0
  211. package/src/ai/useAiChat.ts +18 -0
  212. package/src/core/Sidebar.tsx +2 -2
  213. package/src/core/__tests__/useUndoable.browser.spec.tsx +201 -0
  214. package/src/core/index.ts +7 -0
  215. package/src/core/useToast.tsx +30 -2
  216. package/src/core/useUndoable.tsx +285 -0
  217. package/src/form/__tests__/ControlChoices.browser.spec.tsx +2 -1
  218. package/src/i18n/fr/uiFr.ts +52 -0
  219. package/src/markdown/MarkdownView.tsx +27 -9
  220. package/src/organizations/useInviteOrganizationMember.ts +2 -2
  221. package/src/shell/AppShellSidebarNavItem.tsx +51 -1
  222. package/src/shell/PlateTabBar.tsx +8 -2
  223. package/src/shell/SidebarBackHeader.tsx +58 -0
  224. package/src/shell/appShellNav.tsx +31 -0
  225. package/src/shell/index.ts +5 -1
  226. package/src/swagger/$uiSwagger.tsx +95 -0
  227. package/src/swagger/OpenApiSpec.ts +300 -0
  228. package/src/swagger/SwaggerAccessBadge.tsx +64 -0
  229. package/src/swagger/SwaggerAlephaMeta.tsx +141 -0
  230. package/src/swagger/SwaggerCredentials.tsx +44 -0
  231. package/src/swagger/SwaggerExplorer.tsx +208 -0
  232. package/src/swagger/SwaggerMethodBadge.tsx +32 -0
  233. package/src/swagger/SwaggerNav.tsx +92 -0
  234. package/src/swagger/SwaggerOperationView.tsx +102 -0
  235. package/src/swagger/SwaggerParameters.tsx +74 -0
  236. package/src/swagger/SwaggerRequestBuilder.ts +331 -0
  237. package/src/swagger/SwaggerResponseView.tsx +107 -0
  238. package/src/swagger/SwaggerResponses.tsx +83 -0
  239. package/src/swagger/SwaggerSchemaView.tsx +134 -0
  240. package/src/swagger/SwaggerSection.tsx +29 -0
  241. package/src/swagger/SwaggerTryIt.tsx +95 -0
  242. package/src/swagger/SwaggerTryItForm.tsx +87 -0
  243. package/src/swagger/__tests__/$uiSwagger.spec.ts +52 -0
  244. package/src/swagger/__tests__/OpenApiSpec.spec.ts +139 -0
  245. package/src/swagger/__tests__/SwaggerAccess.browser.spec.tsx +124 -0
  246. package/src/swagger/__tests__/SwaggerOperationView.browser.spec.tsx +194 -0
  247. package/src/swagger/__tests__/SwaggerRequestBuilder.spec.ts +250 -0
  248. package/src/swagger/index.ts +75 -0
  249. package/src/swagger/useSwaggerAccess.ts +59 -0
  250. package/src/table/DataTable.tsx +85 -34
  251. package/src/table/DataTableBody.tsx +51 -7
  252. package/src/table/DataTableRowActionsInline.tsx +80 -0
  253. package/src/table/PermissionMatrix.tsx +4 -4
  254. package/src/table/__tests__/DataTableEmptyState.browser.spec.tsx +1 -1
  255. package/src/table/__tests__/DataTableListMode.browser.spec.tsx +174 -0
  256. package/src/table/__tests__/DataTableOptimistic.browser.spec.tsx +173 -0
  257. package/src/table/__tests__/PermissionMatrix.browser.spec.tsx +2 -2
  258. package/src/table/__tests__/queryFilters.spec.ts +10 -12
  259. package/src/table/dataTableBaseProps.ts +31 -0
  260. package/src/table/dataTableTypes.ts +16 -2
  261. package/src/table/useDataTableData.ts +18 -2
  262. package/src/table/useDataTableRefresh.ts +26 -2
  263. package/src/table/useOptimisticRows.ts +265 -0
  264. package/src/table/useRowMotion.ts +152 -0
package/README.md CHANGED
@@ -22,7 +22,7 @@ bugfixes arrive through normal dependency updates.
22
22
 
23
23
  ## Import paths
24
24
 
25
- The package is sixteen modules, one subpath each. The primitives are the package
25
+ The package is nineteen modules, one subpath each. The primitives are the package
26
26
  root; everything heavier is a subpath of its own, so an app loads only what it
27
27
  renders:
28
28
 
@@ -58,6 +58,7 @@ the module map and that `@alepha/ui` (the root) imports no other module.
58
58
  | `@alepha/ui/auth` | `AuthRouter` and its pages, `TurnstileWidget` |
59
59
  | `@alepha/ui/account` | `AccountRouter`, `$pageAccount`, and the account pages |
60
60
  | `@alepha/ui/admin` | `AdminRouter`, `$pageAdmin`, the admin pages and `AdminAnalytics` |
61
+ | `@alepha/ui/swagger` | `$uiSwagger`, the API explorer page over the app's OpenAPI document, and its parts. See the section below |
61
62
  | `@alepha/ui/chart` | The recharts wrapper (`ChartContainer` and its parts). Opt-in |
62
63
  | `@alepha/ui/command` | The command palette on Base UI's `Autocomplete` (`Command`, `CommandDialog`), ranked by cmdk's scorer. Opt-in |
63
64
  | `@alepha/ui/calendar` | The react-day-picker wrapper (`Calendar`). Opt-in |
@@ -258,6 +259,57 @@ place anything, and node width comes from a generated per-character width table
258
259
  measured against Inter at one size; inheriting the surrounding face would make
259
260
  text and box disagree, differently on every surface.
260
261
 
262
+ ## API explorer
263
+
264
+ `alepha/server/swagger` serves the OpenAPI document and nothing else
265
+ (`$swagger`, at `/docs/json`). `@alepha/ui/swagger` is the viewer:
266
+
267
+ ```ts
268
+ import { $uiSwagger } from "@alepha/ui/swagger";
269
+ import { $swagger } from "alepha/server/swagger";
270
+
271
+ class App {
272
+ openapi = $swagger({ info: { title: "Shop API", version: "1.0.0" } });
273
+ docs = $uiSwagger();
274
+ }
275
+ ```
276
+
277
+ `$uiSwagger()` mounts a page at `/docs` reading `/docs/json` (`path`, `spec`,
278
+ `title`, `name`, `signIn` and `use` change that). The page is its own lazy
279
+ chunk, so an app pays for it only when someone opens it. It shows:
280
+
281
+ - the operations by tag, with a search over method, path, summary and action
282
+ name, an operation linkable by its hash (`/docs#createOrder`);
283
+ - each operation in full: parameters, request body, responses and a tree of
284
+ their schemas, plus what Alepha declared about it from the `x-alepha-*`
285
+ extensions (the action, the roles and permissions it requires, its
286
+ middlewares, declared errors, timeout);
287
+ - a **Try it** form built from the schemas with the `Control` components: a
288
+ field per parameter, the body field by field or as raw JSON, a file input
289
+ per binary part of a multipart body. The response shows its status, time,
290
+ size, headers and body, and a streamed body (server-sent events, a chunked
291
+ download) as it arrives;
292
+ - whether the viewer may call each gated operation: sign in first, allowed,
293
+ or not allowed, read from the signed-in user's action registry (the answer
294
+ `useAuth().has()` gives).
295
+
296
+ Requests go out as the viewer: same-origin, the browser sends the session
297
+ cookie and the server turns it into the `Authorization` it checks, with no
298
+ token to paste. The **Credentials** panel takes a bearer token or API key to
299
+ send instead, for an app without sign-in or to call as another principal; it
300
+ is kept in memory until the page reloads.
301
+
302
+ The document is read in the browser, never by a page loader: on a Worker, a
303
+ server render fetching its own origin is a self-subrequest, which fails. On
304
+ Cloudflare with `run_worker_first`, list `/docs/json` so the request reaches
305
+ the worker.
306
+
307
+ Guard the page with `use: [$secure({ roles: ["admin"] })]` when only the
308
+ team should see it, and remember that the document is a route of its own:
309
+ `$swagger` does not hide it. The components (`SwaggerExplorer`,
310
+ `SwaggerOperationView`, `SwaggerTryIt`, `OpenApiSpec`, ...) are exported for
311
+ an app that lays the explorer out itself.
312
+
261
313
  ## Command palette
262
314
 
263
315
  `@alepha/ui/command` is Base UI's `Autocomplete`, rendered inline: a search
@@ -352,3 +404,4 @@ shell. Load the stylesheet once, at the app's entry: `@alepha/ui/styles.css`.
352
404
 
353
405
  - [`useDialog`](https://alepha.dev/docs/reference-react-hooks-usedialog) - Imperative dialog API. Returns an object with:
354
406
  - [`useIsMobile`](https://alepha.dev/docs/reference-react-hooks-useismobile) - The shadcn version this started from seeds `undefined` and fills it in from
407
+ - [`useUndoable`](https://alepha.dev/docs/reference-react-hooks-useundoable) - Optimistic writes with an Undo toast.
@@ -4,11 +4,18 @@ export interface AccountBrandProps {
4
4
  * says whose area this is and what it is.
5
5
  */
6
6
  subtitle?: string;
7
+ /**
8
+ * Route name the header's back arrow leads to: the application's home,
9
+ * since the account shell hides the application's own chrome.
10
+ *
11
+ * @default "home"
12
+ */
13
+ homeRouteName?: string;
7
14
  }
8
15
  /**
9
- * The account sidebar's default header: the signed-in user's avatar and
10
- * display name, collapsing to the avatar alone when the sidebar folds to its
11
- * icon rail.
16
+ * The account sidebar's default header: a back arrow home, then the
17
+ * signed-in user's avatar and display name, collapsing to the arrow alone
18
+ * when the sidebar folds to its icon rail.
12
19
  *
13
20
  * The account area is the user's own, so the header says whose it is rather
14
21
  * than repeating the application's name. An application that wants its own
@@ -1 +1 @@
1
- {"version":3,"file":"AccountBrand.d.ts","sourceRoot":"","sources":["../../src/account/AccountBrand.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,UAAW,iBAAiB,gCAuBpD,CAAC"}
1
+ {"version":3,"file":"AccountBrand.d.ts","sourceRoot":"","sources":["../../src/account/AccountBrand.tsx"],"names":[],"mappings":"AAOA,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,UAAW,iBAAiB,gCAiCpD,CAAC"}
@@ -1,12 +1,14 @@
1
1
  import { UserAvatar } from "../core/UserAvatar.js";
2
+ import { SidebarBackHeader } from "../shell/SidebarBackHeader.js";
3
+ import { useRouter } from "alepha/react/router";
2
4
  import { useI18n } from "alepha/react/i18n";
3
5
  import { jsx, jsxs } from "react/jsx-runtime";
4
6
  import { useAuth } from "alepha/react/auth";
5
7
  // src/account/AccountBrand.tsx
6
8
  /**
7
- * The account sidebar's default header: the signed-in user's avatar and
8
- * display name, collapsing to the avatar alone when the sidebar folds to its
9
- * icon rail.
9
+ * The account sidebar's default header: a back arrow home, then the
10
+ * signed-in user's avatar and display name, collapsing to the arrow alone
11
+ * when the sidebar folds to its icon rail.
10
12
  *
11
13
  * The account area is the user's own, so the header says whose it is rather
12
14
  * than repeating the application's name. An application that wants its own
@@ -20,16 +22,20 @@ import { useAuth } from "alepha/react/auth";
20
22
  const AccountBrand = (props) => {
21
23
  const auth = useAuth();
22
24
  const { tr } = useI18n();
25
+ const router = useRouter();
26
+ const homeName = props.homeRouteName ?? "home";
27
+ const home = router.pages.some((page) => page.name === homeName) ? homeName : void 0;
23
28
  const user = auth.user;
24
29
  const name = user?.name ?? user?.username ?? user?.email ?? "";
25
- return /* @__PURE__ */ jsxs("div", {
26
- className: "flex min-w-0 items-center gap-2 px-2 py-1.5 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:gap-0 group-data-[collapsible=icon]:px-0",
30
+ return /* @__PURE__ */ jsxs(SidebarBackHeader, {
31
+ href: home ? router.path(home) : void 0,
32
+ label: tr("account.nav.backToSite", { default: "Back to site" }),
27
33
  children: [/* @__PURE__ */ jsx(UserAvatar, {
28
34
  fileId: user?.picture,
29
35
  className: "size-7",
30
36
  alt: name
31
37
  }), /* @__PURE__ */ jsxs("div", {
32
- className: "flex min-w-0 flex-col group-data-[collapsible=icon]:hidden",
38
+ className: "flex min-w-0 flex-col",
33
39
  children: [/* @__PURE__ */ jsx("span", {
34
40
  className: "truncate text-sm font-semibold tracking-tight",
35
41
  "data-testid": "account-brand-name",
@@ -1 +1 @@
1
- {"version":3,"file":"AccountBrand.js","names":[],"sources":["../../src/account/AccountBrand.tsx"],"sourcesContent":["import { useAuth } from \"alepha/react/auth\";\nimport { useI18n } from \"alepha/react/i18n\";\n\nimport { UserAvatar } from \"../core/UserAvatar.tsx\";\n\nexport interface AccountBrandProps {\n /**\n * Line under the name. Defaults to the translated \"Account\", so the header\n * says whose area this is and what it is.\n */\n subtitle?: string;\n}\n\n/**\n * The account sidebar's default header: the signed-in user's avatar and\n * display name, collapsing to the avatar alone when the sidebar folds to its\n * icon rail.\n *\n * The account area is the user's own, so the header says whose it is rather\n * than repeating the application's name. An application that wants its own\n * mark there passes `brand` on `accountRouterOptionsAtom`, as Lore does.\n *\n * ⚠️ Imported only from `AccountLayout`, the lazy chunk. `AccountRouter` is\n * evaluated eagerly in the server graph, where a component import would drag\n * this file into the migration generator's classic-JSX `tsx` run (see the\n * router's own JSDoc).\n */\nexport const AccountBrand = (props: AccountBrandProps) => {\n const auth = useAuth();\n const { tr } = useI18n();\n const user = auth.user;\n const name = user?.name ?? user?.username ?? user?.email ?? \"\";\n\n return (\n <div className=\"flex min-w-0 items-center gap-2 px-2 py-1.5 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:gap-0 group-data-[collapsible=icon]:px-0\">\n <UserAvatar fileId={user?.picture} className=\"size-7\" alt={name} />\n <div className=\"flex min-w-0 flex-col group-data-[collapsible=icon]:hidden\">\n <span\n className=\"truncate text-sm font-semibold tracking-tight\"\n data-testid=\"account-brand-name\"\n >\n {name}\n </span>\n <span className=\"text-muted-foreground truncate text-xs\">\n {props.subtitle ??\n tr(\"account.brand.subtitle\", { default: \"Account\" })}\n </span>\n </div>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,UAA6B;CACxD,MAAM,OAAO,QAAQ;CACrB,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,OAAO,KAAK;CAClB,MAAM,OAAO,MAAM,QAAQ,MAAM,YAAY,MAAM,SAAS;CAE5D,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,oBAAC,YAAD;GAAY,QAAQ,MAAM;GAAS,WAAU;GAAS,KAAK;EAAO,CAAA,GAClE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,oBAAC,QAAD;IACE,WAAU;IACV,eAAY;IAEX,UAAA;GACG,CAAA,GACN,oBAAC,QAAD;IAAM,WAAU;IACb,UAAA,MAAM,YACL,GAAG,0BAA0B,EAAE,SAAS,UAAU,CAAC;GACjD,CAAA,CACH;EACF,CAAA,CAAA;;AAET"}
1
+ {"version":3,"file":"AccountBrand.js","names":[],"sources":["../../src/account/AccountBrand.tsx"],"sourcesContent":["import { useAuth } from \"alepha/react/auth\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { useRouter } from \"alepha/react/router\";\n\nimport { UserAvatar } from \"../core/UserAvatar.tsx\";\nimport { SidebarBackHeader } from \"../shell/SidebarBackHeader.tsx\";\n\nexport interface AccountBrandProps {\n /**\n * Line under the name. Defaults to the translated \"Account\", so the header\n * says whose area this is and what it is.\n */\n subtitle?: string;\n /**\n * Route name the header's back arrow leads to: the application's home,\n * since the account shell hides the application's own chrome.\n *\n * @default \"home\"\n */\n homeRouteName?: string;\n}\n\n/**\n * The account sidebar's default header: a back arrow home, then the\n * signed-in user's avatar and display name, collapsing to the arrow alone\n * when the sidebar folds to its icon rail.\n *\n * The account area is the user's own, so the header says whose it is rather\n * than repeating the application's name. An application that wants its own\n * mark there passes `brand` on `accountRouterOptionsAtom`, as Lore does.\n *\n * ⚠️ Imported only from `AccountLayout`, the lazy chunk. `AccountRouter` is\n * evaluated eagerly in the server graph, where a component import would drag\n * this file into the migration generator's classic-JSX `tsx` run (see the\n * router's own JSDoc).\n */\nexport const AccountBrand = (props: AccountBrandProps) => {\n const auth = useAuth();\n const { tr } = useI18n();\n const router = useRouter<any>();\n // `router.path` throws on a name the application never declared, and an\n // application without a home page has nowhere for the arrow to go.\n const homeName = props.homeRouteName ?? \"home\";\n const home = router.pages.some((page) => page.name === homeName)\n ? homeName\n : undefined;\n const user = auth.user;\n const name = user?.name ?? user?.username ?? user?.email ?? \"\";\n\n return (\n <SidebarBackHeader\n href={home ? router.path(home) : undefined}\n label={tr(\"account.nav.backToSite\", { default: \"Back to site\" })}\n >\n <UserAvatar fileId={user?.picture} className=\"size-7\" alt={name} />\n <div className=\"flex min-w-0 flex-col\">\n <span\n className=\"truncate text-sm font-semibold tracking-tight\"\n data-testid=\"account-brand-name\"\n >\n {name}\n </span>\n <span className=\"text-muted-foreground truncate text-xs\">\n {props.subtitle ??\n tr(\"account.brand.subtitle\", { default: \"Account\" })}\n </span>\n </div>\n </SidebarBackHeader>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,gBAAgB,UAA6B;CACxD,MAAM,OAAO,QAAQ;CACrB,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,SAAS,UAAe;CAG9B,MAAM,WAAW,MAAM,iBAAiB;CACxC,MAAM,OAAO,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,QAAQ,IAC3D,WACA,KAAA;CACJ,MAAM,OAAO,KAAK;CAClB,MAAM,OAAO,MAAM,QAAQ,MAAM,YAAY,MAAM,SAAS;CAE5D,OACE,qBAAC,mBAAD;EACE,MAAM,OAAO,OAAO,KAAK,IAAI,IAAI,KAAA;EACjC,OAAO,GAAG,0BAA0B,EAAE,SAAS,eAAe,CAAC;EAFjE,UAAA,CAIE,oBAAC,YAAD;GAAY,QAAQ,MAAM;GAAS,WAAU;GAAS,KAAK;EAAO,CAAA,GAClE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,oBAAC,QAAD;IACE,WAAU;IACV,eAAY;IAEX,UAAA;GACG,CAAA,GACN,oBAAC,QAAD;IAAM,WAAU;IACb,UAAA,MAAM,YACL,GAAG,0BAA0B,EAAE,SAAS,UAAU,CAAC;GACjD,CAAA,CACH;EACY,CAAA,CAAA;;AAEvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountLayout.d.ts","sourceRoot":"","sources":["../../src/account/AccountLayout.tsx"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa,mCA8CzB,CAAC;eAEa,aAAa"}
1
+ {"version":3,"file":"AccountLayout.d.ts","sourceRoot":"","sources":["../../src/account/AccountLayout.tsx"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa,mCAkDzB,CAAC;eAEa,aAAa"}
@@ -53,7 +53,7 @@ const AccountLayout = () => {
53
53
  variant: "floating",
54
54
  fill: true,
55
55
  extraNav: options.extraNav,
56
- brand: options.brand ?? /* @__PURE__ */ jsx(AccountBrand, {}),
56
+ brand: options.brand ?? /* @__PURE__ */ jsx(AccountBrand, { homeRouteName: options.homeRouteName }),
57
57
  topbarActions: /* @__PURE__ */ jsxs("div", {
58
58
  className: "flex items-center gap-1",
59
59
  children: [
@@ -1 +1 @@
1
- {"version":3,"file":"AccountLayout.js","names":[],"sources":["../../src/account/AccountLayout.tsx"],"sourcesContent":["import { useStore } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { ColorScheme } from \"alepha/react/ui\";\nimport { Search } from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { cn } from \"../core/utils.ts\";\nimport { ButtonSettings } from \"../shell/ButtonSettings.tsx\";\nimport { NavShell } from \"../shell/NavShell.tsx\";\nimport { Spotlight } from \"../shell/Spotlight.tsx\";\nimport { AccountBackToSiteMenuItem } from \"./AccountBackToSiteMenuItem.tsx\";\nimport { AccountBrand } from \"./AccountBrand.tsx\";\nimport { accountRouterOptionsAtom } from \"./AccountRouterOptions.tsx\";\n\n/**\n * The account shell: the account counterpart of `AdminLayout`, a root,\n * full-viewport `NavShell` with a floating sidebar and its own topbar.\n *\n * The sidebar and breadcrumbs are derived from the route subtree anchored at\n * `account`: every page carries its own `nav`, so a page added with\n * `$pageAccount` appears without registering anywhere.\n *\n * It is a root shell, never adopted into the application's layout, and that\n * decides four things:\n *\n * - `<ColorScheme />` is mounted here, because nothing else above `/account`\n * applies the dark-mode class to `<html>`. `colorScheme: false` opts out.\n * - `AppShell` (not `embedded`) mounts `DialogProvider`, `Toaster` and\n * `ActionErrorToaster`, so the pages' `useDialog()` and toasts work with no\n * provider from the application. An application that still adopted this\n * layout under its own `Toaster` would show every toast twice, which is\n * why adoption is no longer a way to mount it.\n * - `h-svh` on the wrapper plus `fill` on `NavShell` bounds `main`, so a\n * table page scrolls its own body and a form page (`AccountPage\n * variant=\"form\"`) scrolls its column, while the sidebar and topbar stay.\n * - The topbar is `AdminLayout`'s arrangement: a ⌘K trigger for a Spotlight\n * scoped to `account`, then `ButtonSettings`. The trigger renders outside\n * the replaceable `topbarActions` cluster, since its open state lives here.\n * The menu's way out is `AccountBackToSiteMenuItem`, not the admin item\n * `AdminLayout` relabels: that one is gated on `admin:ui`, so most people\n * in `/account` would never see it. The admin item stays \"Admin Panel\".\n */\nexport const AccountLayout = () => {\n const [options] = useStore(accountRouterOptionsAtom);\n const [spotlightOpen, setSpotlightOpen] = useState(false);\n const { tr } = useI18n();\n\n return (\n <div className={cn(\"flex h-svh flex-col\", options.className)}>\n {options.colorScheme !== false && <ColorScheme />}\n <NavShell\n root=\"account\"\n variant=\"floating\"\n fill\n extraNav={options.extraNav}\n brand={options.brand ?? <AccountBrand />}\n topbarActions={\n <div className=\"flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setSpotlightOpen(true)}\n className=\"text-muted-foreground hover:bg-hover hover:text-foreground hidden h-8 items-center gap-2 rounded-md border px-2 text-sm transition-colors sm:flex\"\n >\n <Search className=\"size-4 shrink-0\" />\n <span>{tr(\"nav.spotlight.search\", { default: \"Search…\" })}</span>\n <kbd className=\"bg-muted text-muted-foreground pointer-events-none ml-2 hidden rounded px-1.5 font-mono text-[10px] md:inline\">\n ⌘K\n </kbd>\n </button>\n <div\n aria-hidden=\"true\"\n className=\"bg-border mx-1 h-5 w-px shrink-0\"\n />\n {options.topbarActions ?? (\n <ButtonSettings loginRouteName={options.loginRouteName}>\n <AccountBackToSiteMenuItem routeName={options.homeRouteName} />\n </ButtonSettings>\n )}\n </div>\n }\n />\n <Spotlight\n root=\"account\"\n open={spotlightOpen}\n onOpenChange={setSpotlightOpen}\n />\n </div>\n );\n};\n\nexport default AccountLayout;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,sBAAsB;CACjC,MAAM,CAAC,WAAW,SAAS,wBAAwB;CACnD,MAAM,CAAC,eAAe,oBAAoB,SAAS,KAAK;CACxD,MAAM,EAAE,OAAO,QAAQ;CAEvB,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,uBAAuB,QAAQ,SAAS;EAA3D,UAAA;GACG,QAAQ,gBAAgB,SAAS,oBAAC,aAAD,CAAc,CAAA;GAChD,oBAAC,UAAD;IACE,MAAK;IACL,SAAQ;IACR,MAAA;IACA,UAAU,QAAQ;IAClB,OAAO,QAAQ,SAAS,oBAAC,cAAD,CAAe,CAAA;IACvC,eACE,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA;MACE,qBAAC,UAAD;OACE,MAAK;OACL,eAAe,iBAAiB,IAAI;OACpC,WAAU;OAHZ,UAAA;QAKE,oBAAC,QAAD,EAAQ,WAAU,kBAAmB,CAAA;QACrC,oBAAC,QAAD,EAAA,UAAO,GAAG,wBAAwB,EAAE,SAAS,UAAU,CAAC,EAAQ,CAAA;QAChE,oBAAC,OAAD;SAAK,WAAU;SAAgH,UAAA;QAE1H,CAAA;OACC;;MACR,oBAAC,OAAD;OACE,eAAY;OACZ,WAAU;MACX,CAAA;MACA,QAAQ,iBACP,oBAAC,gBAAD;OAAgB,gBAAgB,QAAQ;OACtC,UAAA,oBAAC,2BAAD,EAA2B,WAAW,QAAQ,cAAgB,CAAA;MAChD,CAAA;KAEf;;GAER,CAAA;GACD,oBAAC,WAAD;IACE,MAAK;IACL,MAAM;IACN,cAAc;GACf,CAAA;EACE;;AAET"}
1
+ {"version":3,"file":"AccountLayout.js","names":[],"sources":["../../src/account/AccountLayout.tsx"],"sourcesContent":["import { useStore } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { ColorScheme } from \"alepha/react/ui\";\nimport { Search } from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { cn } from \"../core/utils.ts\";\nimport { ButtonSettings } from \"../shell/ButtonSettings.tsx\";\nimport { NavShell } from \"../shell/NavShell.tsx\";\nimport { Spotlight } from \"../shell/Spotlight.tsx\";\nimport { AccountBackToSiteMenuItem } from \"./AccountBackToSiteMenuItem.tsx\";\nimport { AccountBrand } from \"./AccountBrand.tsx\";\nimport { accountRouterOptionsAtom } from \"./AccountRouterOptions.tsx\";\n\n/**\n * The account shell: the account counterpart of `AdminLayout`, a root,\n * full-viewport `NavShell` with a floating sidebar and its own topbar.\n *\n * The sidebar and breadcrumbs are derived from the route subtree anchored at\n * `account`: every page carries its own `nav`, so a page added with\n * `$pageAccount` appears without registering anywhere.\n *\n * It is a root shell, never adopted into the application's layout, and that\n * decides four things:\n *\n * - `<ColorScheme />` is mounted here, because nothing else above `/account`\n * applies the dark-mode class to `<html>`. `colorScheme: false` opts out.\n * - `AppShell` (not `embedded`) mounts `DialogProvider`, `Toaster` and\n * `ActionErrorToaster`, so the pages' `useDialog()` and toasts work with no\n * provider from the application. An application that still adopted this\n * layout under its own `Toaster` would show every toast twice, which is\n * why adoption is no longer a way to mount it.\n * - `h-svh` on the wrapper plus `fill` on `NavShell` bounds `main`, so a\n * table page scrolls its own body and a form page (`AccountPage\n * variant=\"form\"`) scrolls its column, while the sidebar and topbar stay.\n * - The topbar is `AdminLayout`'s arrangement: a ⌘K trigger for a Spotlight\n * scoped to `account`, then `ButtonSettings`. The trigger renders outside\n * the replaceable `topbarActions` cluster, since its open state lives here.\n * The menu's way out is `AccountBackToSiteMenuItem`, not the admin item\n * `AdminLayout` relabels: that one is gated on `admin:ui`, so most people\n * in `/account` would never see it. The admin item stays \"Admin Panel\".\n */\nexport const AccountLayout = () => {\n const [options] = useStore(accountRouterOptionsAtom);\n const [spotlightOpen, setSpotlightOpen] = useState(false);\n const { tr } = useI18n();\n\n return (\n <div className={cn(\"flex h-svh flex-col\", options.className)}>\n {options.colorScheme !== false && <ColorScheme />}\n <NavShell\n root=\"account\"\n variant=\"floating\"\n fill\n extraNav={options.extraNav}\n brand={\n options.brand ?? (\n <AccountBrand homeRouteName={options.homeRouteName} />\n )\n }\n topbarActions={\n <div className=\"flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setSpotlightOpen(true)}\n className=\"text-muted-foreground hover:bg-hover hover:text-foreground hidden h-8 items-center gap-2 rounded-md border px-2 text-sm transition-colors sm:flex\"\n >\n <Search className=\"size-4 shrink-0\" />\n <span>{tr(\"nav.spotlight.search\", { default: \"Search…\" })}</span>\n <kbd className=\"bg-muted text-muted-foreground pointer-events-none ml-2 hidden rounded px-1.5 font-mono text-[10px] md:inline\">\n ⌘K\n </kbd>\n </button>\n <div\n aria-hidden=\"true\"\n className=\"bg-border mx-1 h-5 w-px shrink-0\"\n />\n {options.topbarActions ?? (\n <ButtonSettings loginRouteName={options.loginRouteName}>\n <AccountBackToSiteMenuItem routeName={options.homeRouteName} />\n </ButtonSettings>\n )}\n </div>\n }\n />\n <Spotlight\n root=\"account\"\n open={spotlightOpen}\n onOpenChange={setSpotlightOpen}\n />\n </div>\n );\n};\n\nexport default AccountLayout;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,sBAAsB;CACjC,MAAM,CAAC,WAAW,SAAS,wBAAwB;CACnD,MAAM,CAAC,eAAe,oBAAoB,SAAS,KAAK;CACxD,MAAM,EAAE,OAAO,QAAQ;CAEvB,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,uBAAuB,QAAQ,SAAS;EAA3D,UAAA;GACG,QAAQ,gBAAgB,SAAS,oBAAC,aAAD,CAAc,CAAA;GAChD,oBAAC,UAAD;IACE,MAAK;IACL,SAAQ;IACR,MAAA;IACA,UAAU,QAAQ;IAClB,OACE,QAAQ,SACN,oBAAC,cAAD,EAAc,eAAe,QAAQ,cAAgB,CAAA;IAGzD,eACE,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA;MACE,qBAAC,UAAD;OACE,MAAK;OACL,eAAe,iBAAiB,IAAI;OACpC,WAAU;OAHZ,UAAA;QAKE,oBAAC,QAAD,EAAQ,WAAU,kBAAmB,CAAA;QACrC,oBAAC,QAAD,EAAA,UAAO,GAAG,wBAAwB,EAAE,SAAS,UAAU,CAAC,EAAQ,CAAA;QAChE,oBAAC,OAAD;SAAK,WAAU;SAAgH,UAAA;QAE1H,CAAA;OACC;;MACR,oBAAC,OAAD;OACE,eAAY;OACZ,WAAU;MACX,CAAA;MACA,QAAQ,iBACP,oBAAC,gBAAD;OAAgB,gBAAgB,QAAQ;OACtC,UAAA,oBAAC,2BAAD,EAA2B,WAAW,QAAQ,cAAgB,CAAA;MAChD,CAAA;KAEf;;GAER,CAAA;GACD,oBAAC,WAAD;IACE,MAAK;IACL,MAAM;IACN,cAAc;GACf,CAAA;EACE;;AAET"}
@@ -16,9 +16,9 @@ export interface AdminUserDetailProps {
16
16
  * `AdminRouter`'s own route declares) and falling back to `:id` (the name
17
17
  * this component read exclusively before `AdminRouter` existed).
18
18
  *
19
- * The fallback exists for `~/git/club/apps/platform`, which vendors
20
- * `@alepha/ui` and declares its own user-detail route as `/users/:id` against
21
- * this same component. Without it, that application's next upgrade of
19
+ * The fallback exists for downstream apps that vendor `@alepha/ui`
20
+ * and declare their own user-detail route as `/users/:id` against
21
+ * this same component. Without it, such an application's next upgrade of
22
22
  * `@alepha/ui` would resolve `userId` to `undefined`, fall through to the
23
23
  * empty string, and load `AdminUserDetail` with no id at all instead of
24
24
  * failing to build.
@@ -30,9 +30,9 @@ import { HttpError } from "alepha/server";
30
30
  * `AdminRouter`'s own route declares) and falling back to `:id` (the name
31
31
  * this component read exclusively before `AdminRouter` existed).
32
32
  *
33
- * The fallback exists for `~/git/club/apps/platform`, which vendors
34
- * `@alepha/ui` and declares its own user-detail route as `/users/:id` against
35
- * this same component. Without it, that application's next upgrade of
33
+ * The fallback exists for downstream apps that vendor `@alepha/ui`
34
+ * and declare their own user-detail route as `/users/:id` against
35
+ * this same component. Without it, such an application's next upgrade of
36
36
  * `@alepha/ui` would resolve `userId` to `undefined`, fall through to the
37
37
  * empty string, and load `AdminUserDetail` with no id at all instead of
38
38
  * failing to build.
@@ -1 +1 @@
1
- {"version":3,"file":"AdminUserDetail.js","names":[],"sources":["../../src/admin/AdminUserDetail.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { AlephaError } from \"alepha\";\nimport type { AdminAuditController } from \"alepha/api/audits\";\nimport type {\n AdminIdentityController,\n AdminSessionController,\n AdminUserController,\n IdentityResource,\n RealmController,\n SessionResource,\n} from \"alepha/api/users\";\nimport { useAction, useClient, useQuery } from \"alepha/react\";\nimport { useAuth } from \"alepha/react/auth\";\nimport { FormValidationError, useForm, useFormState } from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { useRouter, useRouterState } from \"alepha/react/router\";\nimport { HttpError } from \"alepha/server\";\nimport {\n History,\n Monitor,\n ShieldCheck,\n Trash2,\n User,\n UserCheck,\n UserX,\n} from \"lucide-react\";\nimport { useCallback, useState } from \"react\";\n\nimport { PROVIDER_LABELS } from \"../auth/providerLabels.ts\";\nimport { Button } from \"../core/Button.tsx\";\nimport { useDialog } from \"../core/useDialog.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { DetailLayout, type DetailTab } from \"../shell/DetailLayout.tsx\";\nimport { useDetailTab } from \"../shell/useDetailTab.tsx\";\nimport { AdminUserAvatarControl } from \"./AdminUserAvatarControl.tsx\";\nimport { AdminUserDetailAuditsTab } from \"./AdminUserDetailAuditsTab.tsx\";\nimport { AdminUserDetailIdentityAside } from \"./AdminUserDetailIdentityAside.tsx\";\nimport { AdminUserDetailOverviewTab } from \"./AdminUserDetailOverviewTab.tsx\";\nimport { AdminUserDetailPasswordDialog } from \"./AdminUserDetailPasswordDialog.tsx\";\nimport { passwordSchema } from \"./adminUserDetailPasswordSchema.ts\";\nimport {\n type ProfileIssue,\n profileIssues,\n profilePolicy,\n profileUpdateBody,\n} from \"./adminUserDetailProfilePolicy.ts\";\nimport {\n type ProfileForm,\n profileSchema,\n} from \"./adminUserDetailProfileSchema.ts\";\nimport { AdminUserDetailSecurityTab } from \"./AdminUserDetailSecurityTab.tsx\";\nimport { AdminUserDetailSessionsTab } from \"./AdminUserDetailSessionsTab.tsx\";\n\nexport interface AdminUserDetailProps {\n /**\n * Realm name to scope all admin queries. Defaults to the configured\n * user realm.\n */\n userRealmName?: string;\n /**\n * Path to the users list page, for the \"Back\" link. Defaults to\n * `/admin/users`.\n */\n backPath?: string;\n}\n\ntype TabKey = \"overview\" | \"security\" | \"sessions\" | \"audits\";\n\n/**\n * Resolves the id param for this page, preferring `:userId` (the param name\n * `AdminRouter`'s own route declares) and falling back to `:id` (the name\n * this component read exclusively before `AdminRouter` existed).\n *\n * The fallback exists for `~/git/club/apps/platform`, which vendors\n * `@alepha/ui` and declares its own user-detail route as `/users/:id` against\n * this same component. Without it, that application's next upgrade of\n * `@alepha/ui` would resolve `userId` to `undefined`, fall through to the\n * empty string, and load `AdminUserDetail` with no id at all instead of\n * failing to build.\n */\nexport const resolveUserDetailId = (params: {\n userId?: string;\n id?: string;\n}): string => String(params.userId ?? params.id ?? \"\");\n\n/**\n * Composition root for the admin user detail page.\n *\n * Owns the data (queries, forms, mutations) and the shell — top bar, tab\n * selection, identity aside. Each tab body lives in its own file beside this\n * one; they render what they are given and hold no fetching of their own.\n */\nexport const AdminUserDetail = (props: AdminUserDetailProps) => {\n const router = useRouter();\n const routerState = useRouterState();\n const userId = resolveUserDetailId(routerState.params);\n const userClient = useClient<AdminUserController>();\n const sessionClient = useClient<AdminSessionController>();\n const identityClient = useClient<AdminIdentityController>();\n const auditClient = useClient<AdminAuditController>();\n const realmClient = useClient<RealmController>();\n const { tr } = useI18n();\n const toast = useToast();\n const { user: currentUser } = useAuth();\n const dialog = useDialog();\n\n const [passwordOpen, setPasswordOpen] = useState(false);\n const [tab, setTab] = useDetailTab<TabKey>(\"overview\");\n\n const isSelf = currentUser?.id === userId;\n const backPath = props.backPath ?? \"/admin/users\";\n\n // -- Load user, roles, identities -----------------------------------------\n // All three are read-only fetches via useQuery: each runs on mount, re-runs\n // when realm/id change, aborts on unmount via the passed signal, and exposes\n // refetch() — so the mutations below just call the relevant refetch()\n // instead of bumping a manual reload key.\n\n // ⚠️ Every query keyed on `userId` is gated on it being non-empty.\n //\n // `resolveUserDetailId` falls back to `\"\"` on purpose, so a vendored\n // consumer declaring `/users/:id` keeps working — but the fallback used to\n // be dispatched anyway. `useRouterState` is a GLOBAL store, so navigating\n // away re-renders this component with the next route's params before it\n // unmounts: `userId` becomes `\"\"`, the dep changes, and the query re-runs\n // with it. The batch then posts `params: { id: \"\" }` and the server answers\n // `Invalid GUID at /id` — blight #358, seven hits, and #118 before it on\n // the previous bundle.\n //\n // Skipping the request is also what makes the fallback fail VISIBLY: with\n // nothing in flight, `loading` is false and `user` is undefined, so the\n // `notFound` branch below renders instead of a 400 nobody sees.\n const hasUserId = userId !== \"\";\n\n const userQuery = useQuery(\n {\n enabled: hasUserId,\n handler: ({ signal }) =>\n userClient.getUser(\n {\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n },\n { request: { signal } },\n ),\n onError: (err) => {\n toast.error(\n tr(\"admin.userDetail.loadError\", { default: \"Failed to load user\" }),\n );\n console.error(err);\n },\n },\n [userClient, userId, props.userRealmName],\n );\n const user = userQuery.data;\n\n const rolesQuery = useQuery(\n {\n handler: ({ signal }) =>\n userClient.findRoles(\n { query: { userRealmName: props.userRealmName } },\n { request: { signal } },\n ),\n // Role metadata is non-blocking — swallow errors so the page still loads.\n onError: () => {},\n },\n [userClient, props.userRealmName],\n );\n const availableRoles = rolesQuery.data ?? [];\n\n const identitiesQuery = useQuery(\n {\n // Same gate: this one sends `userId` as a filter, so an empty one asks\n // for every identity in the realm rather than failing.\n enabled: hasUserId,\n handler: ({ signal }) =>\n identityClient.findIdentities(\n { query: { userId, size: 100, userRealmName: props.userRealmName } },\n { request: { signal } },\n ),\n // Identities may fail if the controller isn't mounted — non-blocking.\n onError: () => {},\n },\n [identityClient, userId, props.userRealmName],\n );\n const identities = identitiesQuery.data?.content ?? [];\n\n const realmQuery = useQuery(\n {\n // The realm config query param is `realmName`; the admin endpoints\n // spell the same thing `userRealmName`.\n handler: ({ signal }) =>\n realmClient.getRealmConfig(\n { query: { realmName: props.userRealmName } },\n { request: { signal } },\n ),\n // Realm settings only shape which profile fields are offered — a\n // failure must not block the page. `profilePolicy` degrades to\n // \"everything optional\" without them.\n onError: () => {},\n },\n [realmClient, props.userRealmName],\n );\n\n // What the realm collects decides what this form offers and demands.\n // Hardcoding \"email is required\" here made every save fail — a role change\n // included — on a realm that signs users in by username alone.\n const policy = profilePolicy(realmQuery.data?.settings, user);\n\n // -- Profile form ---------------------------------------------------------\n\n const issueMessage = (issue: ProfileIssue): string => {\n if (issue.field === \"username\") {\n return issue.reason === \"required\"\n ? tr(\"admin.userDetail.usernameRequired\", {\n default: \"Username is required\",\n })\n : tr(\"admin.userDetail.usernameCannotBeCleared\", {\n default: \"Username cannot be removed once set\",\n });\n }\n return issue.reason === \"required\"\n ? tr(\"admin.userDetail.emailRequired\", {\n default: \"Email is required\",\n })\n : tr(\"admin.userDetail.emailCannotBeCleared\", {\n default: \"Email cannot be removed once set\",\n });\n };\n\n const form = useForm({\n schema: profileSchema,\n initialValues: {\n username: user?.username ?? \"\",\n email: user?.email ?? \"\",\n firstName: user?.firstName ?? \"\",\n lastName: user?.lastName ?? \"\",\n emailVerified: user?.emailVerified ?? false,\n roles: user?.roles ?? [],\n },\n handler: async (values: ProfileForm) => {\n // Field guards live in the handler, not in the schema, so useForm's\n // initial decode doesn't crash on the empty mount.\n const issue = profileIssues(values, policy, user)[0];\n if (issue) {\n throw new FormValidationError({\n message: issueMessage(issue),\n path: `/${issue.field}`,\n });\n }\n\n const body = profileUpdateBody(values, policy, user);\n\n try {\n await userClient.updateUser({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n body,\n });\n toast.success(\n tr(\"admin.userDetail.saved\", { default: \"Profile saved\" }),\n );\n await userQuery.refetch();\n } catch (err) {\n // Throw, never toast. `ActionErrorToaster`, which `AppShell` mounts,\n // already turns an unhandled action error into exactly one toast, and\n // it reads `error.message` - the very string this used to pass to\n // `toast.error` for an `HttpError`. So a refused duplicate email\n // arrived twice, as two identical stacked toasts.\n //\n // What is left here is the other half of the job: making sure the\n // error carries a sentence worth showing. An `HttpError` already does\n // (it is the server's own wording, and \"Email already exists\" is\n // exactly what the operator needs to read), so it travels as-is.\n // Anything else is transport or a bug, whose message - \"Failed to\n // fetch\" - says nothing about this form, so it gets replaced.\n //\n // Same division of labour as the auth forms in this package: the\n // handler throws, the toaster shows.\n throw err instanceof HttpError\n ? err\n : new AlephaError(\n tr(\"admin.userDetail.saveError\", {\n default: \"Failed to save profile\",\n }),\n { cause: err },\n );\n }\n },\n });\n\n // No `useEffect` re-seeding the form from `userQuery.data` here: the same\n // object is already `useForm`'s `initialValues` above, and `useForm` re-seeds\n // itself when it changes - keeping the fields the user has edited, which the\n // hand-rolled effect could not do. It re-seeded wholesale, so anything typed\n // between pressing Save and the refetch landing was overwritten by data that\n // predates it.\n\n // -- Set password ---------------------------------------------------------\n\n const passwordForm = useForm({\n schema: passwordSchema,\n handler: async ({ password }) => {\n await userClient.setUserPassword({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n body: { password },\n });\n toast.success(\n tr(\"admin.userDetail.passwordSet\", {\n default: \"Password updated\",\n }),\n );\n passwordForm.input.password.set?.(\"\");\n setPasswordOpen(false);\n },\n });\n const { loading: passwordSubmitting } = useFormState(passwordForm, [\n \"loading\",\n ]);\n\n // -- Enable/disable -------------------------------------------------------\n\n const toggleEnabled = useAction(\n {\n handler: async () => {\n if (!user || isSelf) return;\n const enable = !user.enabled;\n const label =\n user.email ||\n user.username ||\n tr(\"admin.userDetail.thisUser\", {\n default: \"this user\",\n });\n const ok = await dialog.confirm({\n title: enable\n ? tr(\"admin.userDetail.enableTitle\", { default: \"Enable user\" })\n : tr(\"admin.userDetail.disableTitle\", { default: \"Disable user\" }),\n description: enable\n ? tr(\"admin.userDetail.enableConfirm\", {\n default: `Enable ${label}?`,\n args: [String(label)],\n })\n : tr(\"admin.userDetail.disableConfirm\", {\n default: `Disable ${label}? They will no longer be able to sign in.`,\n args: [String(label)],\n }),\n destructive: !enable,\n });\n if (!ok) return;\n await userClient.updateUser({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n body: { enabled: enable },\n });\n await userQuery.refetch();\n toast.success(\n enable\n ? tr(\"admin.userDetail.enabled\", { default: \"User enabled\" })\n : tr(\"admin.userDetail.disabled\", { default: \"User disabled\" }),\n );\n },\n },\n [user, isSelf],\n );\n\n // -- Delete ---------------------------------------------------------------\n\n const deleteUser = useAction(\n {\n handler: async () => {\n if (!user || isSelf) return;\n const label =\n user.email ||\n user.username ||\n tr(\"admin.userDetail.thisUser\", {\n default: \"this user\",\n });\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.deleteTitle\", { default: \"Delete user\" }),\n description: tr(\"admin.userDetail.deleteConfirm\", {\n default: `Permanently delete ${label}? This action cannot be undone.`,\n args: [String(label)],\n }),\n destructive: true,\n confirmLabel: tr(\"admin.userDetail.deleteCta\", { default: \"Delete\" }),\n });\n if (!ok) return;\n await userClient.deleteUser({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n });\n toast.success(\n tr(\"admin.userDetail.deleted\", { default: \"User deleted\" }),\n );\n await router.push(backPath);\n },\n },\n [user, isSelf],\n );\n\n // -- Remove social auth ---------------------------------------------------\n\n const removeIdentity = useAction<[IdentityResource]>(\n {\n handler: async (_ctx, identity) => {\n const provider =\n PROVIDER_LABELS[identity.provider] ?? identity.provider;\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.removeIdentityTitle\", {\n default: \"Remove connection\",\n }),\n description: tr(\"admin.userDetail.removeIdentityConfirm\", {\n default: `Remove the ${provider} connection? The user will no longer be able to sign in with it.`,\n args: [provider],\n }),\n destructive: true,\n });\n if (!ok) return;\n await identityClient.deleteIdentity({\n params: { id: identity.id },\n query: { userRealmName: props.userRealmName },\n });\n toast.success(\n tr(\"admin.userDetail.identityRemoved\", {\n default: \"Connection removed\",\n }),\n );\n await identitiesQuery.refetch();\n },\n },\n [props.userRealmName],\n );\n\n // -- Clear the second factor ----------------------------------------------\n\n /*\n * Same endpoint as `removeIdentity`: a TOTP enrollment is an identity row,\n * and `admin:identity:delete` already means \"can take away a way into this\n * account\". What differs is what the operator is told: this does not remove\n * a sign-in method, it removes the check that sits after one, so the wording\n * of `removeIdentity` would be actively wrong here.\n *\n * It is also the single action an attacker holding an admin session wants\n * most, which is why it confirms rather than firing on one click.\n */\n const clearTotp = useAction<[IdentityResource]>(\n {\n handler: async (_ctx, identity) => {\n // Named, the same way `toggleEnabled` and `remove` name theirs. An\n // admin can have several user pages open, and this is the one action\n // whose confirmation must leave no doubt about whose account it is.\n const label =\n user?.email ||\n user?.username ||\n tr(\"admin.userDetail.thisUser\", { default: \"this user\" });\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.clearTotpTitle\", {\n default: \"Clear second factor\",\n }),\n description: tr(\"admin.userDetail.clearTotpConfirm\", {\n default: `${label} will sign in with their password alone until they enroll an authenticator app again. Do this only when they have lost both the device and their recovery codes.`,\n args: [String(label)],\n }),\n destructive: true,\n });\n if (!ok) return;\n await identityClient.deleteIdentity({\n params: { id: identity.id },\n query: { userRealmName: props.userRealmName },\n });\n toast.success(\n tr(\"admin.userDetail.totpCleared\", {\n default: \"Second factor cleared\",\n }),\n );\n await identitiesQuery.refetch();\n },\n },\n [props.userRealmName],\n );\n\n // -- Sessions / audits fetchers -------------------------------------------\n\n const sessionsFetcher = useCallback(\n (params: { page: number; size: number; sort?: string }) =>\n sessionClient.findSessions({\n query: { ...params, userId, userRealmName: props.userRealmName },\n }),\n [sessionClient, userId, props.userRealmName],\n );\n\n const auditsFetcher = useCallback(\n (params: { page: number; size: number; sort?: string }) =>\n auditClient.findByUser({ params: { userId }, query: params }),\n [auditClient, userId],\n );\n\n const revokeSession = useAction<[SessionResource, () => void]>(\n {\n handler: async (_ctx, s, refresh) => {\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.revokeTitle\", {\n default: \"Revoke session\",\n }),\n description: tr(\"admin.userDetail.revokeConfirm\", {\n default:\n \"Revoke this session? The user will be signed out on the matching device.\",\n }),\n destructive: true,\n });\n if (!ok) return;\n await sessionClient.deleteSession({\n params: { id: s.id },\n query: { userRealmName: props.userRealmName },\n });\n refresh();\n },\n },\n [props.userRealmName],\n );\n\n const bulkRevokeSessions = useAction<\n [SessionResource[], { refresh: () => void; clearSelection: () => void }]\n >(\n {\n handler: async (_ctx, items, ctx) => {\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.bulkRevokeTitle\", {\n default: \"Revoke sessions\",\n }),\n description: tr(\"admin.userDetail.bulkRevokeConfirm\", {\n default: `Revoke ${items.length} sessions?`,\n args: [String(items.length)],\n }),\n destructive: true,\n });\n if (!ok) return;\n await sessionClient.deleteSessions({\n query: { userRealmName: props.userRealmName },\n body: { ids: items.map((s) => s.id) },\n });\n ctx.clearSelection();\n ctx.refresh();\n },\n },\n [props.userRealmName],\n );\n\n // -- Render ---------------------------------------------------------------\n\n // A `credentials` identity means a password is set. Password sign-in lives\n // in its own card; the social providers are everything else.\n const hasPassword = identities.some((id) => id.provider === \"credentials\");\n const socialIdentities = identities.filter(\n (id) => id.provider !== \"credentials\",\n );\n\n const tabs: DetailTab[] = [\n {\n value: \"overview\",\n icon: User,\n label: tr(\"admin.userDetail.tabOverview\", { default: \"Overview\" }),\n },\n {\n value: \"security\",\n icon: ShieldCheck,\n label: tr(\"admin.userDetail.tabSecurity\", { default: \"Security\" }),\n },\n {\n value: \"sessions\",\n icon: Monitor,\n label: tr(\"admin.userDetail.tabSessions\", { default: \"Sessions\" }),\n },\n {\n value: \"audits\",\n icon: History,\n label: tr(\"admin.userDetail.tabAudits\", { default: \"Audit log\" }),\n },\n ];\n\n return (\n <>\n <DetailLayout\n loading={userQuery.loading && !user}\n notFound={\n user\n ? undefined\n : {\n message: tr(\"admin.userDetail.notFound\", {\n default: \"User not found.\",\n }),\n backLabel: tr(\"admin.userDetail.back\", {\n default: \"Back to users\",\n }),\n onBack: () => void router.push(backPath),\n }\n }\n aside={\n user ? (\n <div className=\"flex flex-col gap-3\">\n <AdminUserDetailIdentityAside user={user} />\n {/* Under the aside rather than inside it: `DetailAside` renders\n rows of facts, and this is an action on the picture above\n it. It hides itself when the realm has avatars off - the\n endpoint is unregistered there, so `can()` is false. */}\n <AdminUserAvatarControl\n user={user}\n onChanged={() => void userQuery.refetch()}\n />\n </div>\n ) : null\n }\n tabs={tabs}\n tab={tab}\n onTabChange={(v) => setTab(v as TabKey)}\n actions={\n <>\n <Button\n variant=\"outlined\"\n size=\"lg\"\n loading={toggleEnabled.loading}\n disabled={isSelf}\n onClick={() => toggleEnabled.run()}\n >\n {user?.enabled ? (\n <>\n <UserX className=\"size-4\" />\n {tr(\"admin.userDetail.disable\", { default: \"Disable\" })}\n </>\n ) : (\n <>\n <UserCheck className=\"size-4\" />\n {tr(\"admin.userDetail.enable\", { default: \"Enable\" })}\n </>\n )}\n </Button>\n <Button\n variant=\"outlined\"\n intent=\"danger\"\n size=\"lg\"\n loading={deleteUser.loading}\n disabled={isSelf}\n onClick={() => deleteUser.run()}\n >\n <Trash2 className=\"size-4\" />\n {tr(\"admin.userDetail.delete\", { default: \"Delete user\" })}\n </Button>\n </>\n }\n >\n {tab === \"overview\" && (\n <AdminUserDetailOverviewTab\n form={form}\n availableRoles={availableRoles}\n policy={policy}\n />\n )}\n\n {tab === \"security\" && (\n <AdminUserDetailSecurityTab\n hasPassword={hasPassword}\n socialIdentities={socialIdentities}\n removeIdentity={removeIdentity}\n clearTotp={clearTotp}\n onChangePassword={() => setPasswordOpen(true)}\n />\n )}\n\n {tab === \"sessions\" && (\n <AdminUserDetailSessionsTab\n userId={userId}\n fetch={sessionsFetcher}\n revokeSession={revokeSession}\n bulkRevokeSessions={bulkRevokeSessions}\n />\n )}\n\n {tab === \"audits\" && (\n <AdminUserDetailAuditsTab userId={userId} fetch={auditsFetcher} />\n )}\n </DetailLayout>\n\n <AdminUserDetailPasswordDialog\n open={passwordOpen}\n onOpenChange={setPasswordOpen}\n form={passwordForm}\n submitting={passwordSubmitting}\n />\n </>\n );\n};\n\nexport default AdminUserDetail;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAa,uBAAuB,WAGtB,OAAO,OAAO,UAAU,OAAO,MAAM,EAAE;;;;;;;;AASrD,MAAa,mBAAmB,UA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;IACR;GACT,CAAA;GAGF,QAAQ,cACP,oBAAC,4BAAD;IACe;IACK;IACF;IACL;IACX,wBAAwB,gBAAgB,IAAI;GAC7C,CAAA;GAGF,QAAQ,cACP,oBAAC,4BAAD;IACU;IACR,OAAO;IACQ;IACK;GACrB,CAAA;GAGF,QAAQ,YACP,oBAAC,0BAAD;IAAkC;IAAQ,OAAO;GAAgB,CAAA;EAEvD;CAEd,CAAA,GAAA,oBAAC,+BAAD;EACE,MAAM;EACN,cAAc;EACd,MAAM;EACN,YAAY;CACb,CAAA,CACD,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"AdminUserDetail.js","names":[],"sources":["../../src/admin/AdminUserDetail.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { AlephaError } from \"alepha\";\nimport type { AdminAuditController } from \"alepha/api/audits\";\nimport type {\n AdminIdentityController,\n AdminSessionController,\n AdminUserController,\n IdentityResource,\n RealmController,\n SessionResource,\n} from \"alepha/api/users\";\nimport { useAction, useClient, useQuery } from \"alepha/react\";\nimport { useAuth } from \"alepha/react/auth\";\nimport { FormValidationError, useForm, useFormState } from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { useRouter, useRouterState } from \"alepha/react/router\";\nimport { HttpError } from \"alepha/server\";\nimport {\n History,\n Monitor,\n ShieldCheck,\n Trash2,\n User,\n UserCheck,\n UserX,\n} from \"lucide-react\";\nimport { useCallback, useState } from \"react\";\n\nimport { PROVIDER_LABELS } from \"../auth/providerLabels.ts\";\nimport { Button } from \"../core/Button.tsx\";\nimport { useDialog } from \"../core/useDialog.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { DetailLayout, type DetailTab } from \"../shell/DetailLayout.tsx\";\nimport { useDetailTab } from \"../shell/useDetailTab.tsx\";\nimport { AdminUserAvatarControl } from \"./AdminUserAvatarControl.tsx\";\nimport { AdminUserDetailAuditsTab } from \"./AdminUserDetailAuditsTab.tsx\";\nimport { AdminUserDetailIdentityAside } from \"./AdminUserDetailIdentityAside.tsx\";\nimport { AdminUserDetailOverviewTab } from \"./AdminUserDetailOverviewTab.tsx\";\nimport { AdminUserDetailPasswordDialog } from \"./AdminUserDetailPasswordDialog.tsx\";\nimport { passwordSchema } from \"./adminUserDetailPasswordSchema.ts\";\nimport {\n type ProfileIssue,\n profileIssues,\n profilePolicy,\n profileUpdateBody,\n} from \"./adminUserDetailProfilePolicy.ts\";\nimport {\n type ProfileForm,\n profileSchema,\n} from \"./adminUserDetailProfileSchema.ts\";\nimport { AdminUserDetailSecurityTab } from \"./AdminUserDetailSecurityTab.tsx\";\nimport { AdminUserDetailSessionsTab } from \"./AdminUserDetailSessionsTab.tsx\";\n\nexport interface AdminUserDetailProps {\n /**\n * Realm name to scope all admin queries. Defaults to the configured\n * user realm.\n */\n userRealmName?: string;\n /**\n * Path to the users list page, for the \"Back\" link. Defaults to\n * `/admin/users`.\n */\n backPath?: string;\n}\n\ntype TabKey = \"overview\" | \"security\" | \"sessions\" | \"audits\";\n\n/**\n * Resolves the id param for this page, preferring `:userId` (the param name\n * `AdminRouter`'s own route declares) and falling back to `:id` (the name\n * this component read exclusively before `AdminRouter` existed).\n *\n * The fallback exists for downstream apps that vendor `@alepha/ui`\n * and declare their own user-detail route as `/users/:id` against\n * this same component. Without it, such an application's next upgrade of\n * `@alepha/ui` would resolve `userId` to `undefined`, fall through to the\n * empty string, and load `AdminUserDetail` with no id at all instead of\n * failing to build.\n */\nexport const resolveUserDetailId = (params: {\n userId?: string;\n id?: string;\n}): string => String(params.userId ?? params.id ?? \"\");\n\n/**\n * Composition root for the admin user detail page.\n *\n * Owns the data (queries, forms, mutations) and the shell — top bar, tab\n * selection, identity aside. Each tab body lives in its own file beside this\n * one; they render what they are given and hold no fetching of their own.\n */\nexport const AdminUserDetail = (props: AdminUserDetailProps) => {\n const router = useRouter();\n const routerState = useRouterState();\n const userId = resolveUserDetailId(routerState.params);\n const userClient = useClient<AdminUserController>();\n const sessionClient = useClient<AdminSessionController>();\n const identityClient = useClient<AdminIdentityController>();\n const auditClient = useClient<AdminAuditController>();\n const realmClient = useClient<RealmController>();\n const { tr } = useI18n();\n const toast = useToast();\n const { user: currentUser } = useAuth();\n const dialog = useDialog();\n\n const [passwordOpen, setPasswordOpen] = useState(false);\n const [tab, setTab] = useDetailTab<TabKey>(\"overview\");\n\n const isSelf = currentUser?.id === userId;\n const backPath = props.backPath ?? \"/admin/users\";\n\n // -- Load user, roles, identities -----------------------------------------\n // All three are read-only fetches via useQuery: each runs on mount, re-runs\n // when realm/id change, aborts on unmount via the passed signal, and exposes\n // refetch() — so the mutations below just call the relevant refetch()\n // instead of bumping a manual reload key.\n\n // ⚠️ Every query keyed on `userId` is gated on it being non-empty.\n //\n // `resolveUserDetailId` falls back to `\"\"` on purpose, so a vendored\n // consumer declaring `/users/:id` keeps working — but the fallback used to\n // be dispatched anyway. `useRouterState` is a GLOBAL store, so navigating\n // away re-renders this component with the next route's params before it\n // unmounts: `userId` becomes `\"\"`, the dep changes, and the query re-runs\n // with it. The batch then posts `params: { id: \"\" }` and the server answers\n // `Invalid GUID at /id` — blight #358, seven hits, and #118 before it on\n // the previous bundle.\n //\n // Skipping the request is also what makes the fallback fail VISIBLY: with\n // nothing in flight, `loading` is false and `user` is undefined, so the\n // `notFound` branch below renders instead of a 400 nobody sees.\n const hasUserId = userId !== \"\";\n\n const userQuery = useQuery(\n {\n enabled: hasUserId,\n handler: ({ signal }) =>\n userClient.getUser(\n {\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n },\n { request: { signal } },\n ),\n onError: (err) => {\n toast.error(\n tr(\"admin.userDetail.loadError\", { default: \"Failed to load user\" }),\n );\n console.error(err);\n },\n },\n [userClient, userId, props.userRealmName],\n );\n const user = userQuery.data;\n\n const rolesQuery = useQuery(\n {\n handler: ({ signal }) =>\n userClient.findRoles(\n { query: { userRealmName: props.userRealmName } },\n { request: { signal } },\n ),\n // Role metadata is non-blocking — swallow errors so the page still loads.\n onError: () => {},\n },\n [userClient, props.userRealmName],\n );\n const availableRoles = rolesQuery.data ?? [];\n\n const identitiesQuery = useQuery(\n {\n // Same gate: this one sends `userId` as a filter, so an empty one asks\n // for every identity in the realm rather than failing.\n enabled: hasUserId,\n handler: ({ signal }) =>\n identityClient.findIdentities(\n { query: { userId, size: 100, userRealmName: props.userRealmName } },\n { request: { signal } },\n ),\n // Identities may fail if the controller isn't mounted — non-blocking.\n onError: () => {},\n },\n [identityClient, userId, props.userRealmName],\n );\n const identities = identitiesQuery.data?.content ?? [];\n\n const realmQuery = useQuery(\n {\n // The realm config query param is `realmName`; the admin endpoints\n // spell the same thing `userRealmName`.\n handler: ({ signal }) =>\n realmClient.getRealmConfig(\n { query: { realmName: props.userRealmName } },\n { request: { signal } },\n ),\n // Realm settings only shape which profile fields are offered — a\n // failure must not block the page. `profilePolicy` degrades to\n // \"everything optional\" without them.\n onError: () => {},\n },\n [realmClient, props.userRealmName],\n );\n\n // What the realm collects decides what this form offers and demands.\n // Hardcoding \"email is required\" here made every save fail — a role change\n // included — on a realm that signs users in by username alone.\n const policy = profilePolicy(realmQuery.data?.settings, user);\n\n // -- Profile form ---------------------------------------------------------\n\n const issueMessage = (issue: ProfileIssue): string => {\n if (issue.field === \"username\") {\n return issue.reason === \"required\"\n ? tr(\"admin.userDetail.usernameRequired\", {\n default: \"Username is required\",\n })\n : tr(\"admin.userDetail.usernameCannotBeCleared\", {\n default: \"Username cannot be removed once set\",\n });\n }\n return issue.reason === \"required\"\n ? tr(\"admin.userDetail.emailRequired\", {\n default: \"Email is required\",\n })\n : tr(\"admin.userDetail.emailCannotBeCleared\", {\n default: \"Email cannot be removed once set\",\n });\n };\n\n const form = useForm({\n schema: profileSchema,\n initialValues: {\n username: user?.username ?? \"\",\n email: user?.email ?? \"\",\n firstName: user?.firstName ?? \"\",\n lastName: user?.lastName ?? \"\",\n emailVerified: user?.emailVerified ?? false,\n roles: user?.roles ?? [],\n },\n handler: async (values: ProfileForm) => {\n // Field guards live in the handler, not in the schema, so useForm's\n // initial decode doesn't crash on the empty mount.\n const issue = profileIssues(values, policy, user)[0];\n if (issue) {\n throw new FormValidationError({\n message: issueMessage(issue),\n path: `/${issue.field}`,\n });\n }\n\n const body = profileUpdateBody(values, policy, user);\n\n try {\n await userClient.updateUser({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n body,\n });\n toast.success(\n tr(\"admin.userDetail.saved\", { default: \"Profile saved\" }),\n );\n await userQuery.refetch();\n } catch (err) {\n // Throw, never toast. `ActionErrorToaster`, which `AppShell` mounts,\n // already turns an unhandled action error into exactly one toast, and\n // it reads `error.message` - the very string this used to pass to\n // `toast.error` for an `HttpError`. So a refused duplicate email\n // arrived twice, as two identical stacked toasts.\n //\n // What is left here is the other half of the job: making sure the\n // error carries a sentence worth showing. An `HttpError` already does\n // (it is the server's own wording, and \"Email already exists\" is\n // exactly what the operator needs to read), so it travels as-is.\n // Anything else is transport or a bug, whose message - \"Failed to\n // fetch\" - says nothing about this form, so it gets replaced.\n //\n // Same division of labour as the auth forms in this package: the\n // handler throws, the toaster shows.\n throw err instanceof HttpError\n ? err\n : new AlephaError(\n tr(\"admin.userDetail.saveError\", {\n default: \"Failed to save profile\",\n }),\n { cause: err },\n );\n }\n },\n });\n\n // No `useEffect` re-seeding the form from `userQuery.data` here: the same\n // object is already `useForm`'s `initialValues` above, and `useForm` re-seeds\n // itself when it changes - keeping the fields the user has edited, which the\n // hand-rolled effect could not do. It re-seeded wholesale, so anything typed\n // between pressing Save and the refetch landing was overwritten by data that\n // predates it.\n\n // -- Set password ---------------------------------------------------------\n\n const passwordForm = useForm({\n schema: passwordSchema,\n handler: async ({ password }) => {\n await userClient.setUserPassword({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n body: { password },\n });\n toast.success(\n tr(\"admin.userDetail.passwordSet\", {\n default: \"Password updated\",\n }),\n );\n passwordForm.input.password.set?.(\"\");\n setPasswordOpen(false);\n },\n });\n const { loading: passwordSubmitting } = useFormState(passwordForm, [\n \"loading\",\n ]);\n\n // -- Enable/disable -------------------------------------------------------\n\n const toggleEnabled = useAction(\n {\n handler: async () => {\n if (!user || isSelf) return;\n const enable = !user.enabled;\n const label =\n user.email ||\n user.username ||\n tr(\"admin.userDetail.thisUser\", {\n default: \"this user\",\n });\n const ok = await dialog.confirm({\n title: enable\n ? tr(\"admin.userDetail.enableTitle\", { default: \"Enable user\" })\n : tr(\"admin.userDetail.disableTitle\", { default: \"Disable user\" }),\n description: enable\n ? tr(\"admin.userDetail.enableConfirm\", {\n default: `Enable ${label}?`,\n args: [String(label)],\n })\n : tr(\"admin.userDetail.disableConfirm\", {\n default: `Disable ${label}? They will no longer be able to sign in.`,\n args: [String(label)],\n }),\n destructive: !enable,\n });\n if (!ok) return;\n await userClient.updateUser({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n body: { enabled: enable },\n });\n await userQuery.refetch();\n toast.success(\n enable\n ? tr(\"admin.userDetail.enabled\", { default: \"User enabled\" })\n : tr(\"admin.userDetail.disabled\", { default: \"User disabled\" }),\n );\n },\n },\n [user, isSelf],\n );\n\n // -- Delete ---------------------------------------------------------------\n\n const deleteUser = useAction(\n {\n handler: async () => {\n if (!user || isSelf) return;\n const label =\n user.email ||\n user.username ||\n tr(\"admin.userDetail.thisUser\", {\n default: \"this user\",\n });\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.deleteTitle\", { default: \"Delete user\" }),\n description: tr(\"admin.userDetail.deleteConfirm\", {\n default: `Permanently delete ${label}? This action cannot be undone.`,\n args: [String(label)],\n }),\n destructive: true,\n confirmLabel: tr(\"admin.userDetail.deleteCta\", { default: \"Delete\" }),\n });\n if (!ok) return;\n await userClient.deleteUser({\n params: { id: userId },\n query: { userRealmName: props.userRealmName },\n });\n toast.success(\n tr(\"admin.userDetail.deleted\", { default: \"User deleted\" }),\n );\n await router.push(backPath);\n },\n },\n [user, isSelf],\n );\n\n // -- Remove social auth ---------------------------------------------------\n\n const removeIdentity = useAction<[IdentityResource]>(\n {\n handler: async (_ctx, identity) => {\n const provider =\n PROVIDER_LABELS[identity.provider] ?? identity.provider;\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.removeIdentityTitle\", {\n default: \"Remove connection\",\n }),\n description: tr(\"admin.userDetail.removeIdentityConfirm\", {\n default: `Remove the ${provider} connection? The user will no longer be able to sign in with it.`,\n args: [provider],\n }),\n destructive: true,\n });\n if (!ok) return;\n await identityClient.deleteIdentity({\n params: { id: identity.id },\n query: { userRealmName: props.userRealmName },\n });\n toast.success(\n tr(\"admin.userDetail.identityRemoved\", {\n default: \"Connection removed\",\n }),\n );\n await identitiesQuery.refetch();\n },\n },\n [props.userRealmName],\n );\n\n // -- Clear the second factor ----------------------------------------------\n\n /*\n * Same endpoint as `removeIdentity`: a TOTP enrollment is an identity row,\n * and `admin:identity:delete` already means \"can take away a way into this\n * account\". What differs is what the operator is told: this does not remove\n * a sign-in method, it removes the check that sits after one, so the wording\n * of `removeIdentity` would be actively wrong here.\n *\n * It is also the single action an attacker holding an admin session wants\n * most, which is why it confirms rather than firing on one click.\n */\n const clearTotp = useAction<[IdentityResource]>(\n {\n handler: async (_ctx, identity) => {\n // Named, the same way `toggleEnabled` and `remove` name theirs. An\n // admin can have several user pages open, and this is the one action\n // whose confirmation must leave no doubt about whose account it is.\n const label =\n user?.email ||\n user?.username ||\n tr(\"admin.userDetail.thisUser\", { default: \"this user\" });\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.clearTotpTitle\", {\n default: \"Clear second factor\",\n }),\n description: tr(\"admin.userDetail.clearTotpConfirm\", {\n default: `${label} will sign in with their password alone until they enroll an authenticator app again. Do this only when they have lost both the device and their recovery codes.`,\n args: [String(label)],\n }),\n destructive: true,\n });\n if (!ok) return;\n await identityClient.deleteIdentity({\n params: { id: identity.id },\n query: { userRealmName: props.userRealmName },\n });\n toast.success(\n tr(\"admin.userDetail.totpCleared\", {\n default: \"Second factor cleared\",\n }),\n );\n await identitiesQuery.refetch();\n },\n },\n [props.userRealmName],\n );\n\n // -- Sessions / audits fetchers -------------------------------------------\n\n const sessionsFetcher = useCallback(\n (params: { page: number; size: number; sort?: string }) =>\n sessionClient.findSessions({\n query: { ...params, userId, userRealmName: props.userRealmName },\n }),\n [sessionClient, userId, props.userRealmName],\n );\n\n const auditsFetcher = useCallback(\n (params: { page: number; size: number; sort?: string }) =>\n auditClient.findByUser({ params: { userId }, query: params }),\n [auditClient, userId],\n );\n\n const revokeSession = useAction<[SessionResource, () => void]>(\n {\n handler: async (_ctx, s, refresh) => {\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.revokeTitle\", {\n default: \"Revoke session\",\n }),\n description: tr(\"admin.userDetail.revokeConfirm\", {\n default:\n \"Revoke this session? The user will be signed out on the matching device.\",\n }),\n destructive: true,\n });\n if (!ok) return;\n await sessionClient.deleteSession({\n params: { id: s.id },\n query: { userRealmName: props.userRealmName },\n });\n refresh();\n },\n },\n [props.userRealmName],\n );\n\n const bulkRevokeSessions = useAction<\n [SessionResource[], { refresh: () => void; clearSelection: () => void }]\n >(\n {\n handler: async (_ctx, items, ctx) => {\n const ok = await dialog.confirm({\n title: tr(\"admin.userDetail.bulkRevokeTitle\", {\n default: \"Revoke sessions\",\n }),\n description: tr(\"admin.userDetail.bulkRevokeConfirm\", {\n default: `Revoke ${items.length} sessions?`,\n args: [String(items.length)],\n }),\n destructive: true,\n });\n if (!ok) return;\n await sessionClient.deleteSessions({\n query: { userRealmName: props.userRealmName },\n body: { ids: items.map((s) => s.id) },\n });\n ctx.clearSelection();\n ctx.refresh();\n },\n },\n [props.userRealmName],\n );\n\n // -- Render ---------------------------------------------------------------\n\n // A `credentials` identity means a password is set. Password sign-in lives\n // in its own card; the social providers are everything else.\n const hasPassword = identities.some((id) => id.provider === \"credentials\");\n const socialIdentities = identities.filter(\n (id) => id.provider !== \"credentials\",\n );\n\n const tabs: DetailTab[] = [\n {\n value: \"overview\",\n icon: User,\n label: tr(\"admin.userDetail.tabOverview\", { default: \"Overview\" }),\n },\n {\n value: \"security\",\n icon: ShieldCheck,\n label: tr(\"admin.userDetail.tabSecurity\", { default: \"Security\" }),\n },\n {\n value: \"sessions\",\n icon: Monitor,\n label: tr(\"admin.userDetail.tabSessions\", { default: \"Sessions\" }),\n },\n {\n value: \"audits\",\n icon: History,\n label: tr(\"admin.userDetail.tabAudits\", { default: \"Audit log\" }),\n },\n ];\n\n return (\n <>\n <DetailLayout\n loading={userQuery.loading && !user}\n notFound={\n user\n ? undefined\n : {\n message: tr(\"admin.userDetail.notFound\", {\n default: \"User not found.\",\n }),\n backLabel: tr(\"admin.userDetail.back\", {\n default: \"Back to users\",\n }),\n onBack: () => void router.push(backPath),\n }\n }\n aside={\n user ? (\n <div className=\"flex flex-col gap-3\">\n <AdminUserDetailIdentityAside user={user} />\n {/* Under the aside rather than inside it: `DetailAside` renders\n rows of facts, and this is an action on the picture above\n it. It hides itself when the realm has avatars off - the\n endpoint is unregistered there, so `can()` is false. */}\n <AdminUserAvatarControl\n user={user}\n onChanged={() => void userQuery.refetch()}\n />\n </div>\n ) : null\n }\n tabs={tabs}\n tab={tab}\n onTabChange={(v) => setTab(v as TabKey)}\n actions={\n <>\n <Button\n variant=\"outlined\"\n size=\"lg\"\n loading={toggleEnabled.loading}\n disabled={isSelf}\n onClick={() => toggleEnabled.run()}\n >\n {user?.enabled ? (\n <>\n <UserX className=\"size-4\" />\n {tr(\"admin.userDetail.disable\", { default: \"Disable\" })}\n </>\n ) : (\n <>\n <UserCheck className=\"size-4\" />\n {tr(\"admin.userDetail.enable\", { default: \"Enable\" })}\n </>\n )}\n </Button>\n <Button\n variant=\"outlined\"\n intent=\"danger\"\n size=\"lg\"\n loading={deleteUser.loading}\n disabled={isSelf}\n onClick={() => deleteUser.run()}\n >\n <Trash2 className=\"size-4\" />\n {tr(\"admin.userDetail.delete\", { default: \"Delete user\" })}\n </Button>\n </>\n }\n >\n {tab === \"overview\" && (\n <AdminUserDetailOverviewTab\n form={form}\n availableRoles={availableRoles}\n policy={policy}\n />\n )}\n\n {tab === \"security\" && (\n <AdminUserDetailSecurityTab\n hasPassword={hasPassword}\n socialIdentities={socialIdentities}\n removeIdentity={removeIdentity}\n clearTotp={clearTotp}\n onChangePassword={() => setPasswordOpen(true)}\n />\n )}\n\n {tab === \"sessions\" && (\n <AdminUserDetailSessionsTab\n userId={userId}\n fetch={sessionsFetcher}\n revokeSession={revokeSession}\n bulkRevokeSessions={bulkRevokeSessions}\n />\n )}\n\n {tab === \"audits\" && (\n <AdminUserDetailAuditsTab userId={userId} fetch={auditsFetcher} />\n )}\n </DetailLayout>\n\n <AdminUserDetailPasswordDialog\n open={passwordOpen}\n onOpenChange={setPasswordOpen}\n form={passwordForm}\n submitting={passwordSubmitting}\n />\n </>\n );\n};\n\nexport default AdminUserDetail;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAa,uBAAuB,WAGtB,OAAO,OAAO,UAAU,OAAO,MAAM,EAAE;;;;;;;;AASrD,MAAa,mBAAmB,UAAgC;CAC9D,MAAM,SAAS,UAAU;CACzB,MAAM,cAAc,eAAe;CACnC,MAAM,SAAS,oBAAoB,YAAY,MAAM;CACrD,MAAM,aAAa,UAA+B;CAClD,MAAM,gBAAgB,UAAkC;CACxD,MAAM,iBAAiB,UAAmC;CAC1D,MAAM,cAAc,UAAgC;CACpD,MAAM,cAAc,UAA2B;CAC/C,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,QAAQ,SAAS;CACvB,MAAM,EAAE,MAAM,gBAAgB,QAAQ;CACtC,MAAM,SAAS,UAAU;CAEzB,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,CAAC,KAAK,UAAU,aAAqB,UAAU;CAErD,MAAM,SAAS,aAAa,OAAO;CACnC,MAAM,WAAW,MAAM,YAAY;CAsBnC,MAAM,YAAY,WAAW;CAE7B,MAAM,YAAY,SAChB;EACE,SAAS;EACT,UAAU,EAAE,aACV,WAAW,QACT;GACE,QA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vB,UAAU;GACV,eAAe,cAAc,IAAI;GAEhC,UAAA,MAAM,UACL,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,OAAD,EAAO,WAAU,SAAU,CAAA,GAC1B,GAAG,4BAA4B,EAAE,SAAS,UAAU,CAAC,CACtD,EAAA,CAAA,IAEF,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,WAAD,EAAW,WAAU,SAAU,CAAA,GAC9B,GAAG,2BAA2B,EAAE,SAAS,SAAS,CAAC,CACpD,EAAA,CAAA;EAEE,CAAA,GACR,qBAAC,QAAD;GACE,SAAQ;GACR,QAAO;GACP,MAAK;GACL,SAAS,WAAW;GACpB,UAAU;GACV,eAAe,WAAW,IAAI;GANhC,UAAA,CAQE,oBAAC,QAAD,EAAQ,WAAU,SAAU,CAAA,GAC3B,GAAG,2BAA2B,EAAE,SAAS,cAAc,CAAC,CACnD;EACR,CAAA,CAAA,EAAA,CAAA;EAjEN,UAAA;GAoEG,QAAQ,cACP,oBAAC,4BAAD;IACQ;IACU;IACR;GACT,CAAA;GAGF,QAAQ,cACP,oBAAC,4BAAD;IACe;IACK;IACF;IACL;IACX,wBAAwB,gBAAgB,IAAI;GAC7C,CAAA;GAGF,QAAQ,cACP,oBAAC,4BAAD;IACU;IACR,OAAO;IACQ;IACK;GACrB,CAAA;GAGF,QAAQ,YACP,oBAAC,0BAAD;IAAkC;IAAQ,OAAO;GAAgB,CAAA;EAEvD;CAEd,CAAA,GAAA,oBAAC,+BAAD;EACE,MAAM;EACN,cAAc;EACd,MAAM;EACN,YAAY;CACb,CAAA,CACD,EAAA,CAAA;AAEN"}
@@ -1,3 +1,8 @@
1
+ import { type ComponentType } from "react";
2
+ import { type MarkdownLinkRenderer } from "../markdown/MarkdownView.tsx";
3
+ import { type AiChatConfirmCardProps } from "./AiChatConfirmCard.tsx";
4
+ import { type AiChatSuggestion } from "./AiChatEmpty.tsx";
5
+ import { type AiChatToolLabel } from "./AiChatMessage.tsx";
1
6
  import { type UseAiChatOptions } from "./useAiChat.ts";
2
7
  export interface AiChatProps extends UseAiChatOptions {
3
8
  open: boolean;
@@ -7,15 +12,36 @@ export interface AiChatProps extends UseAiChatOptions {
7
12
  */
8
13
  title?: string;
9
14
  /**
10
- * Show the list of past conversations. Default true.
15
+ * Offer the list of past conversations, in a header menu. Default true.
11
16
  */
12
17
  history?: boolean;
18
+ /**
19
+ * Questions a new conversation offers to start from.
20
+ */
21
+ suggestions?: AiChatSuggestion[];
22
+ /**
23
+ * Names each tool step in the user's words ("Searched clients"), running
24
+ * and done. Without it a step shows the tool's own name.
25
+ */
26
+ toolLabel?: AiChatToolLabel;
27
+ /**
28
+ * A confirmation card per tool name, in place of the generic field list:
29
+ * an app shows a booking as a booking. It gets the pending call as the
30
+ * server stored it, and the approve and deny callbacks.
31
+ */
32
+ confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;
33
+ /**
34
+ * How links in the assistant's replies render (`MarkdownView`'s
35
+ * `renderLink`): route the paths the app knows, leave the rest as text.
36
+ */
37
+ renderLink?: MarkdownLinkRenderer;
13
38
  }
14
39
  /**
15
- * The assistant in a drawer: streamed markdown replies, the conversation
16
- * history, and a confirmation card for every mutation the assistant wants to
17
- * run. It knows the page through `useAiContext()`, and runs `navigate` and
18
- * `fillForm` for the model.
40
+ * The assistant in a drawer: a quiet header (history menu, new
41
+ * conversation, close), the conversation with its tool steps and a
42
+ * confirmation card for every mutation the assistant wants to run, and a
43
+ * composer that sends on Enter and stops a running turn. It knows the page
44
+ * through `useAiContext()`, and runs `navigate` and `fillForm` for the model.
19
45
  *
20
46
  * Needs `AlephaApiAi` on the server and a `$ai` declared by the app.
21
47
  *
@@ -23,7 +49,11 @@ export interface AiChatProps extends UseAiChatOptions {
23
49
  * ```tsx
24
50
  * const [open, setOpen] = useState(false);
25
51
  * <Button onClick={() => setOpen(true)}>Ask</Button>
26
- * <AiChat open={open} onOpenChange={setOpen} />
52
+ * <AiChat
53
+ * open={open}
54
+ * onOpenChange={setOpen}
55
+ * suggestions={[{ label: "Who still owes today?" }]}
56
+ * />
27
57
  * ```
28
58
  */
29
59
  export declare const AiChat: (props: AiChatProps) => import("react").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"AiChat.d.ts","sourceRoot":"","sources":["../../src/ai/AiChat.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AAElE,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACnD,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM,UAAW,WAAW,gCAqGxC,CAAC"}
1
+ {"version":3,"file":"AiChat.d.ts","sourceRoot":"","sources":["../../src/ai/AiChat.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAqB,MAAM,OAAO,CAAC;AAW9D,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AAElE,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACnD,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;O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