@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
@@ -3,7 +3,7 @@ import * as React from "react";
3
3
  void React;
4
4
 
5
5
  import "./MarkdownView.css";
6
- import { lazy, Suspense } from "react";
6
+ import { lazy, type ReactNode, Suspense } from "react";
7
7
  import ReactMarkdown from "react-markdown";
8
8
  import remarkGfm from "remark-gfm";
9
9
 
@@ -46,8 +46,23 @@ export interface MarkdownViewProps {
46
46
  * this element rather than being inherited.
47
47
  */
48
48
  className?: string;
49
+ /**
50
+ * Renders every link instead of the default `<a href>`: an app routes an
51
+ * internal path through its own router link, or leaves a link it does not
52
+ * trust as plain text (an assistant's reply may carry a path that does not
53
+ * exist). Return `children` alone to drop the link.
54
+ */
55
+ renderLink?: MarkdownLinkRenderer;
49
56
  }
50
57
 
58
+ /**
59
+ * See {@link MarkdownViewProps.renderLink}.
60
+ */
61
+ export type MarkdownLinkRenderer = (link: {
62
+ href?: string;
63
+ children: ReactNode;
64
+ }) => ReactNode;
65
+
51
66
  /**
52
67
  * Renders markdown as formatted prose.
53
68
  *
@@ -154,14 +169,17 @@ export const MarkdownView = (props: MarkdownViewProps) => {
154
169
  <ol className="my-3 list-decimal space-y-1 pl-5">{children}</ol>
155
170
  ),
156
171
  li: ({ children }) => <li className="pl-1">{children}</li>,
157
- a: ({ href, children }) => (
158
- <a
159
- href={href}
160
- className="text-primary decoration-primary/50 hover:decoration-primary underline underline-offset-4"
161
- >
162
- {children}
163
- </a>
164
- ),
172
+ a: ({ href, children }) =>
173
+ props.renderLink ? (
174
+ props.renderLink({ href, children })
175
+ ) : (
176
+ <a
177
+ href={href}
178
+ className="text-primary decoration-primary/50 hover:decoration-primary underline underline-offset-4"
179
+ >
180
+ {children}
181
+ </a>
182
+ ),
165
183
  code: ({ children, className }) => {
166
184
  const isBlock =
167
185
  className?.includes("language-") || className?.includes("hljs");
@@ -12,9 +12,9 @@ export interface InviteOrganizationMember {
12
12
  * `metadata` is the application's own, stored on the invitation row and
13
13
  * handed back on `organization:invitation:accepted`. The framework never
14
14
  * reads it: it is how an application carries a fact of its own alongside the
15
- * rank - Alepha Club puts the club ROLES it is inviting somebody as there,
15
+ * rank - a sports app may put the ROLES it is inviting somebody as there,
16
16
  * because a rank says what you may do as staff and a role says whether you
17
- * are a coach, and the framework has no business knowing that club has
17
+ * are a coach, and the framework has no business knowing that the app has
18
18
  * coaches.
19
19
  *
20
20
  * Resolves `{ ok: true }` once sent, `{ ok: false, reason: "cancelled" }`
@@ -19,6 +19,7 @@ import {
19
19
  HoverCardTrigger,
20
20
  } from "../core/HoverCard.tsx";
21
21
  import {
22
+ SidebarMenuAction,
22
23
  SidebarMenuBadge,
23
24
  SidebarMenuButton,
24
25
  SidebarMenuItem,
@@ -144,6 +145,10 @@ export const AppShellSidebarNavItem = (props: AppShellSidebarNavItemProps) => {
144
145
  <SidebarMenuButton
145
146
  isActive={item.active}
146
147
  tooltip={typeof item.label === "string" ? item.label : undefined}
148
+ // The action is the button's SIBLING, so the pointer on the "+" has
149
+ // left the button: lit from the item instead, the row keeps its fill
150
+ // under the action's own, which composites a step darker on top.
151
+ className={item.action ? "group-hover/menu-item:bg-hover" : undefined}
147
152
  /*
148
153
  `aria-current` beside the styling's `data-active`, so a screen
149
154
  reader announces the page the reader is on, and a test can find the
@@ -173,11 +178,56 @@ export const AppShellSidebarNavItem = (props: AppShellSidebarNavItemProps) => {
173
178
  link
174
179
  );
175
180
 
181
+ const action = item.action;
182
+
176
183
  return (
177
184
  <SidebarMenuItem>
178
185
  {row}
179
186
  {item.badge != null && item.badge !== false && (
180
- <SidebarMenuBadge>{item.badge}</SidebarMenuBadge>
187
+ <SidebarMenuBadge
188
+ className={
189
+ // The action takes the badge's slot while it shows, so the two
190
+ // never paint over each other: the count at rest, the "+" under
191
+ // the pointer. The same breakpoint as `showOnHover`, which keeps
192
+ // the action always visible below `md`, where there is no hover.
193
+ action
194
+ ? "max-md:hidden md:group-hover/menu-item:opacity-0 md:group-has-[:focus-visible]/menu-item:opacity-0"
195
+ : undefined
196
+ }
197
+ >
198
+ {item.badge}
199
+ </SidebarMenuBadge>
200
+ )}
201
+ {action && (
202
+ <Tooltip>
203
+ <TooltipTrigger
204
+ render={
205
+ <SidebarMenuAction
206
+ showOnHover
207
+ aria-label={action.label}
208
+ onClick={(event) => {
209
+ // A POINTER click lets go of focus before the action
210
+ // runs. The action usually opens a dialog, which hands
211
+ // focus back to whatever held it on close: the "+", which
212
+ // then reads as keyboard focus, stays revealed, hides the count
213
+ // and draws a ring while the pointer is elsewhere. A
214
+ // keyboard press (`detail` 0) keeps it, so a keyboard
215
+ // reader lands back where they were.
216
+ if (event.detail > 0) event.currentTarget.blur();
217
+ action.onClick?.();
218
+ }}
219
+ render={
220
+ !action.onClick && action.href ? (
221
+ <Link href={action.href} />
222
+ ) : undefined
223
+ }
224
+ />
225
+ }
226
+ >
227
+ {renderNavIcon(action.icon ?? Plus, "size-4")}
228
+ </TooltipTrigger>
229
+ <TooltipContent side="inline-end">{action.label}</TooltipContent>
230
+ </Tooltip>
181
231
  )}
182
232
  </SidebarMenuItem>
183
233
  );
@@ -99,7 +99,13 @@ export const PlateTabBar = (props: PlateTabBarProps) => {
99
99
  // the fold reads the same either way.
100
100
  // `overflow-x-auto` so a bar wider than a phone scrolls sideways
101
101
  // instead of widening the page; the tabs never wrap or shrink.
102
- "bg-muted border-border flex gap-5 overflow-x-auto px-6 shadow-[inset_0_1px_0_0_var(--bevel)]",
102
+ // `overflow-x: auto` computes `overflow-y` as `auto` too, so the bar
103
+ // is a vertical scroller as well: anything a pixel taller than it
104
+ // shows a vertical scrollbar wherever scrollbars are always visible
105
+ // (macOS "always show", Windows). `overflow-y-hidden` stops that, and
106
+ // the tabs carry no negative bottom margin, which is what used to
107
+ // overflow by one pixel and hide half of the active underline.
108
+ "bg-muted border-border flex gap-5 overflow-x-auto overflow-y-hidden px-6 shadow-[inset_0_1px_0_0_var(--bevel)]",
103
109
  props.divided !== false && "border-t",
104
110
  )}
105
111
  role={navigates ? "navigation" : "tablist"}
@@ -107,7 +113,7 @@ export const PlateTabBar = (props: PlateTabBarProps) => {
107
113
  {props.tabs.map((tab) => {
108
114
  const active = tab.key === props.active;
109
115
  const className = cn(
110
- "-mb-px inline-flex h-[42px] shrink-0 items-center gap-[7px] border-b-2 text-[13.5px] font-medium whitespace-nowrap transition-colors",
116
+ "inline-flex h-[42px] shrink-0 items-center gap-[7px] border-b-2 text-[13.5px] font-medium whitespace-nowrap transition-colors",
111
117
  active
112
118
  ? "border-primary text-foreground"
113
119
  : "text-muted-foreground hover:text-foreground border-transparent",
@@ -0,0 +1,58 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Link } from "alepha/react/router";
6
+ import { ArrowLeft } from "lucide-react";
7
+ import type { ReactNode } from "react";
8
+
9
+ export interface SidebarBackHeaderProps {
10
+ /**
11
+ * Where the arrow leads: the application's home, out of a root shell such
12
+ * as `/account` or `/admin` that is not drawn inside the application's own
13
+ * chrome. Absent, there is no arrow, for an application with nowhere to
14
+ * go back to.
15
+ */
16
+ href?: string;
17
+ /**
18
+ * Names the arrow for assistive technology, since it shows only an icon.
19
+ */
20
+ label: string;
21
+ /**
22
+ * What the header says beside the arrow: an icon and a title, or a whole
23
+ * identity block. Hidden when the sidebar folds to its icon rail, where
24
+ * the arrow alone stays.
25
+ */
26
+ children: ReactNode;
27
+ }
28
+
29
+ /**
30
+ * A root shell's sidebar header with a way out: a back arrow to the
31
+ * application's home, then what the area is.
32
+ *
33
+ * `/account` and `/admin` own the viewport, so the application's sidebar and
34
+ * its links are gone while they are open, and the only other way back is an
35
+ * item inside the account menu. The arrow is a real `Link`, so home can also
36
+ * be opened in a new tab.
37
+ *
38
+ * Collapsed to the icon rail, the words go and the arrow stays: it is the
39
+ * one part of the header a reader still needs there.
40
+ */
41
+ export const SidebarBackHeader = (props: SidebarBackHeaderProps) => {
42
+ return (
43
+ <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">
44
+ {props.href && (
45
+ <Link
46
+ href={props.href}
47
+ aria-label={props.label}
48
+ className="text-muted-foreground hover:bg-hover hover:text-foreground flex size-7 shrink-0 items-center justify-center rounded-md transition-colors"
49
+ >
50
+ <ArrowLeft className="size-4 rtl:-scale-x-100" />
51
+ </Link>
52
+ )}
53
+ <div className="flex min-w-0 items-center gap-2 group-data-[collapsible=icon]:hidden">
54
+ {props.children}
55
+ </div>
56
+ </div>
57
+ );
58
+ };
@@ -41,6 +41,14 @@ export interface NavItem {
41
41
  * Optional trailing badge (e.g. unread count). Hidden when the sidebar is collapsed to icons.
42
42
  */
43
43
  badge?: ReactNode;
44
+ /**
45
+ * A trailing button revealed while the row is hovered or focused, a "+"
46
+ * by default: the place to create one more of what the entry lists. It
47
+ * takes the badge's slot while it shows, so a row with a count reads the
48
+ * count at rest and offers the action under the pointer. Leaf items only,
49
+ * and hidden when the sidebar is collapsed to icons.
50
+ */
51
+ action?: NavItemAction;
44
52
  /**
45
53
  * When true the item is rendered muted, navigation is blocked, and the
46
54
  * `tooltip` (if any) explains why. Use for paywalled / unavailable entries.
@@ -55,6 +63,29 @@ export interface NavItem {
55
63
  tooltip?: ReactNode;
56
64
  }
57
65
 
66
+ /**
67
+ * The hover action of a {@link NavItem}.
68
+ */
69
+ export interface NavItemAction {
70
+ /**
71
+ * Names the action for assistive technology and in its tooltip, since the
72
+ * button itself shows only an icon.
73
+ */
74
+ label: string;
75
+ /**
76
+ * Defaults to a plus.
77
+ */
78
+ icon?: IconType | ReactNode;
79
+ /**
80
+ * What a click does. Takes precedence over `href`.
81
+ */
82
+ onClick?: () => void;
83
+ /**
84
+ * Where a click goes, when the action is a page rather than a dialog.
85
+ */
86
+ href?: string;
87
+ }
88
+
58
89
  export interface NavGroup {
59
90
  label?: string;
60
91
  items: NavItem[];
@@ -27,7 +27,7 @@ export {
27
27
  type AppShellProps,
28
28
  type NavigationProgressOptions,
29
29
  } from "./AppShell.tsx";
30
- export type { NavGroup, NavItem } from "./appShellNav.tsx";
30
+ export type { NavGroup, NavItem, NavItemAction } from "./appShellNav.tsx";
31
31
  export { ButtonDark, type ButtonDarkProps } from "./ButtonDark.tsx";
32
32
  export { ButtonInbox, type ButtonInboxProps } from "./ButtonInbox.tsx";
33
33
  export { ButtonLanguage, type ButtonLanguageProps } from "./ButtonLanguage.tsx";
@@ -60,6 +60,10 @@ export {
60
60
  export { NavShell, type NavShellProps } from "./NavShell.tsx";
61
61
  export { PlateLayout, type PlateLayoutProps } from "./PlateLayout.tsx";
62
62
  export type { PlateTab } from "./PlateTabBar.tsx";
63
+ export {
64
+ SidebarBackHeader,
65
+ type SidebarBackHeaderProps,
66
+ } from "./SidebarBackHeader.tsx";
63
67
  export { SidebarNavAutoClose } from "./SidebarNavAutoClose.tsx";
64
68
  export { Spotlight, type SpotlightProps } from "./Spotlight.tsx";
65
69
  export { useDetailTab } from "./useDetailTab.tsx";
@@ -0,0 +1,95 @@
1
+ import type { Middleware } from "alepha";
2
+ import { $page, type PagePrimitive } from "alepha/react/router";
3
+
4
+ import type { SwaggerExplorerProps } from "./SwaggerExplorer.tsx";
5
+
6
+ export interface UiSwaggerOptions {
7
+ /**
8
+ * The page's name in the router, for `router.push(name)`.
9
+ *
10
+ * @default "swagger"
11
+ */
12
+ name?: string;
13
+
14
+ /**
15
+ * Where the explorer is mounted.
16
+ *
17
+ * @default "/docs"
18
+ */
19
+ path?: string;
20
+
21
+ /**
22
+ * Where the OpenAPI document is served: `<prefix>/json` of the app's
23
+ * `$swagger`, or any OpenAPI 3 document the browser may fetch.
24
+ *
25
+ * @default "/docs/json"
26
+ */
27
+ spec?: string;
28
+
29
+ /**
30
+ * The browser tab's title.
31
+ *
32
+ * @default "API"
33
+ */
34
+ title?: string;
35
+
36
+ /**
37
+ * Where to sign in, linked from a gated operation when nobody is signed in.
38
+ *
39
+ * @default "/auth/login"
40
+ */
41
+ signIn?: string;
42
+
43
+ /**
44
+ * Middlewares guarding the page, `[$secure({ roles: ["admin"] })]` for an
45
+ * explorer only the team should see. The OpenAPI document itself is served
46
+ * by `$swagger`: guard that route too, or the JSON stays public.
47
+ */
48
+ use?: Middleware[];
49
+ }
50
+
51
+ /**
52
+ * An API explorer page, reading the app's OpenAPI document.
53
+ *
54
+ * `alepha/server/swagger` serves the document only (`$swagger`, at
55
+ * `/docs/json` by default); this is the viewer, built on `@alepha/ui`. It
56
+ * lists the operations by tag with a search, and shows each in full:
57
+ * parameters, request body, responses, their schemas, and what Alepha
58
+ * declared about it (the action, who may call it, middlewares, declared
59
+ * errors, timeout) from the `x-alepha-*` extensions. Each operation can be
60
+ * called from a form built from its schemas, as the signed-in user (the
61
+ * session cookie) or with a token typed in, and a gated one says whether the
62
+ * viewer's permissions reach it.
63
+ *
64
+ * The page and the document share the `/docs` prefix by default, which is
65
+ * fine: the page is `/docs`, the document `/docs/json`.
66
+ *
67
+ * ```ts
68
+ * import { $swagger } from "alepha/server/swagger";
69
+ * import { $uiSwagger } from "@alepha/ui/swagger";
70
+ *
71
+ * class App {
72
+ * openapi = $swagger({ info: { title: "Shop API", version: "1.0.0" } });
73
+ * docs = $uiSwagger();
74
+ * }
75
+ * ```
76
+ *
77
+ * It carries the `$` prefix to sit with the framework's other declarations
78
+ * at a call site, but it is a plain function wrapping `$page`, like
79
+ * `$pageAdmin`. The page component is a lazy chunk, so an app pays for the
80
+ * explorer only when someone opens it.
81
+ */
82
+ export const $uiSwagger = (
83
+ options: UiSwaggerOptions = {},
84
+ ): PagePrimitive<any, SwaggerExplorerProps> => {
85
+ const specUrl = options.spec ?? "/docs/json";
86
+ const signIn = options.signIn ?? "/auth/login";
87
+ return $page<any, SwaggerExplorerProps>({
88
+ name: options.name ?? "swagger",
89
+ path: options.path ?? "/docs",
90
+ use: options.use,
91
+ head: { title: options.title ?? "API" },
92
+ props: () => ({ specUrl, signIn }),
93
+ lazy: () => import("./SwaggerExplorer.tsx"),
94
+ });
95
+ };
@@ -0,0 +1,300 @@
1
+ import type { OpenApiDocument, OpenApiOperation } from "alepha/server/swagger";
2
+
3
+ /**
4
+ * One operation of the document, with where it lives.
5
+ */
6
+ export interface SwaggerEntry {
7
+ /**
8
+ * Stable identifier: the `operationId`, else `METHOD path`.
9
+ */
10
+ id: string;
11
+ method: string;
12
+ path: string;
13
+ tag: string;
14
+ operation: OpenApiOperation;
15
+ }
16
+
17
+ /**
18
+ * The operations of one tag, in document order.
19
+ */
20
+ export interface SwaggerGroup {
21
+ tag: string;
22
+ entries: SwaggerEntry[];
23
+ }
24
+
25
+ /**
26
+ * What `$secure` and friends declared about an operation, from its
27
+ * `x-alepha-security` extension. `{}` means a signed-in user is enough.
28
+ */
29
+ export interface SwaggerSecurity {
30
+ roles?: string[];
31
+ permissions?: string[];
32
+ }
33
+
34
+ /**
35
+ * The Alepha extensions an operation may carry; see the OpenAPI guide.
36
+ */
37
+ export interface SwaggerAlephaMetadata {
38
+ action?: { name: string; group: string };
39
+ middlewares?: string[];
40
+ security?: SwaggerSecurity;
41
+ errors?: string[];
42
+ timeout?: number;
43
+ }
44
+
45
+ /**
46
+ * A read-only view of an OpenAPI document, shaped for the explorer.
47
+ *
48
+ * Plain data in, plain data out: it holds no React state, so a spec can
49
+ * build one from a literal document and every component reads the same
50
+ * answers.
51
+ */
52
+ export class OpenApiSpec {
53
+ /**
54
+ * The HTTP methods OpenAPI allows under a path, in the order the explorer
55
+ * lists them. Anything else under a path (`parameters`, `summary`, an
56
+ * extension) is not an operation.
57
+ */
58
+ public static readonly METHODS = [
59
+ "get",
60
+ "post",
61
+ "put",
62
+ "patch",
63
+ "delete",
64
+ "head",
65
+ "options",
66
+ "trace",
67
+ ];
68
+
69
+ public readonly document: OpenApiDocument;
70
+ public readonly entries: SwaggerEntry[];
71
+
72
+ constructor(document: OpenApiDocument) {
73
+ this.document = document;
74
+ this.entries = this.collect();
75
+ }
76
+
77
+ public get title(): string {
78
+ return this.document.info?.title ?? "API";
79
+ }
80
+
81
+ public get version(): string | undefined {
82
+ return this.document.info?.version;
83
+ }
84
+
85
+ public get description(): string | undefined {
86
+ return this.document.info?.description;
87
+ }
88
+
89
+ /**
90
+ * The operations grouped by their first tag, groups in first-seen order,
91
+ * keeping only those matching `query` (see {@link matches}).
92
+ */
93
+ public groups(query = ""): SwaggerGroup[] {
94
+ const groups = new Map<string, SwaggerEntry[]>();
95
+ for (const entry of this.entries) {
96
+ if (!this.matches(entry, query)) {
97
+ continue;
98
+ }
99
+ const list = groups.get(entry.tag) ?? [];
100
+ list.push(entry);
101
+ groups.set(entry.tag, list);
102
+ }
103
+ return [...groups].map(([tag, entries]) => ({ tag, entries }));
104
+ }
105
+
106
+ /**
107
+ * Whether an entry matches a free-text query: every whitespace-separated
108
+ * term must appear, case-insensitively, in its method, path, tag, summary,
109
+ * operation id or action name.
110
+ */
111
+ public matches(entry: SwaggerEntry, query: string): boolean {
112
+ const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
113
+ if (!terms.length) {
114
+ return true;
115
+ }
116
+ const meta = this.metadata(entry.operation);
117
+ const haystack = [
118
+ entry.method,
119
+ entry.path,
120
+ entry.tag,
121
+ entry.operation.summary,
122
+ entry.operation.operationId,
123
+ meta.action?.name,
124
+ ]
125
+ .filter(Boolean)
126
+ .join(" ")
127
+ .toLowerCase();
128
+ return terms.every((term) => haystack.includes(term));
129
+ }
130
+
131
+ public find(id: string | undefined): SwaggerEntry | undefined {
132
+ return id ? this.entries.find((entry) => entry.id === id) : undefined;
133
+ }
134
+
135
+ /**
136
+ * Follow a local `$ref` (`#/components/schemas/X`) to its target, at most
137
+ * once per call: the schema viewer resolves lazily, one level at a time, so
138
+ * a recursive schema never loops.
139
+ */
140
+ public resolve(schema: any): any {
141
+ const ref = schema?.$ref;
142
+ if (typeof ref !== "string" || !ref.startsWith("#/")) {
143
+ return schema;
144
+ }
145
+ let target: any = this.document;
146
+ for (const part of ref.slice(2).split("/")) {
147
+ target = target?.[part.replace(/~1/g, "/").replace(/~0/g, "~")];
148
+ }
149
+ return target ?? schema;
150
+ }
151
+
152
+ /**
153
+ * A copy of a schema with every local `$ref` inlined, down to `maxDepth`
154
+ * levels; past it a reference becomes `{}`, which is what keeps a recursive
155
+ * schema finite. For consumers that need the whole tree at once (the form
156
+ * builder), where the viewer resolves one level at a time.
157
+ */
158
+ public dereference(schema: any, maxDepth = 8, depth = 0): any {
159
+ if (!schema || typeof schema !== "object") {
160
+ return schema;
161
+ }
162
+ if (Array.isArray(schema)) {
163
+ return schema.map((it) => this.dereference(it, maxDepth, depth));
164
+ }
165
+ if (typeof schema.$ref === "string") {
166
+ if (depth >= maxDepth) {
167
+ return {};
168
+ }
169
+ return this.dereference(this.resolve(schema), maxDepth, depth + 1);
170
+ }
171
+ const out: Record<string, unknown> = {};
172
+ for (const [key, value] of Object.entries(schema)) {
173
+ out[key] = this.dereference(value, maxDepth, depth);
174
+ }
175
+ return out;
176
+ }
177
+
178
+ /**
179
+ * The name a `$ref` points at (`Product` for `#/components/schemas/Product`).
180
+ */
181
+ public refName(schema: any): string | undefined {
182
+ const ref = schema?.$ref;
183
+ return typeof ref === "string" ? ref.split("/").pop() : undefined;
184
+ }
185
+
186
+ /**
187
+ * A one-line type for a schema: `string<email>`, `Product` (a `$ref`, or a
188
+ * titled object), `array<Product>`, `"a" | "b"`, `string | null`.
189
+ */
190
+ public typeLabel(schema: any): string {
191
+ if (!schema || typeof schema !== "object") {
192
+ return "any";
193
+ }
194
+ const name = this.refName(schema);
195
+ if (name) {
196
+ return name;
197
+ }
198
+ // A titled schema the generator inlined (array items are not hoisted).
199
+ if (typeof schema.title === "string" && schema.properties) {
200
+ return schema.title;
201
+ }
202
+ if (Array.isArray(schema.enum)) {
203
+ return schema.enum.map((it: unknown) => JSON.stringify(it)).join(" | ");
204
+ }
205
+ if (schema.const !== undefined) {
206
+ return JSON.stringify(schema.const);
207
+ }
208
+ const variants = schema.oneOf ?? schema.anyOf;
209
+ if (Array.isArray(variants)) {
210
+ return variants.map((it: any) => this.typeLabel(it)).join(" | ");
211
+ }
212
+ if (Array.isArray(schema.allOf)) {
213
+ return schema.allOf.map((it: any) => this.typeLabel(it)).join(" & ");
214
+ }
215
+ const types: string[] = Array.isArray(schema.type)
216
+ ? schema.type
217
+ : schema.type
218
+ ? [schema.type]
219
+ : [];
220
+ const label = types
221
+ .map((type) => {
222
+ if (type === "array") {
223
+ return `array<${this.typeLabel(schema.items)}>`;
224
+ }
225
+ if (
226
+ type === "object" &&
227
+ schema.additionalProperties &&
228
+ !schema.properties
229
+ ) {
230
+ return `record<${this.typeLabel(schema.additionalProperties)}>`;
231
+ }
232
+ return schema.format ? `${type}<${schema.format}>` : type;
233
+ })
234
+ .join(" | ");
235
+ const nullable = schema.nullable ? " | null" : "";
236
+ return (label || (schema.properties ? "object" : "any")) + nullable;
237
+ }
238
+
239
+ /**
240
+ * Whether the viewer can open a schema further: an object with properties,
241
+ * an array of one, a reference, or a union.
242
+ */
243
+ public isExpandable(schema: any): boolean {
244
+ const target = this.resolve(schema);
245
+ if (!target || typeof target !== "object") {
246
+ return false;
247
+ }
248
+ if (target.properties && Object.keys(target.properties).length) {
249
+ return true;
250
+ }
251
+ if (target.items) {
252
+ return this.isExpandable(target.items);
253
+ }
254
+ return Array.isArray(target.oneOf ?? target.anyOf ?? target.allOf);
255
+ }
256
+
257
+ /**
258
+ * The `x-alepha-*` extensions of an operation, typed.
259
+ */
260
+ public metadata(operation: OpenApiOperation): SwaggerAlephaMetadata {
261
+ return {
262
+ action: operation["x-alepha-action"] as SwaggerAlephaMetadata["action"],
263
+ middlewares: operation["x-alepha-middlewares"] as string[] | undefined,
264
+ security: operation["x-alepha-security"] as SwaggerSecurity | undefined,
265
+ errors: operation["x-alepha-errors"] as string[] | undefined,
266
+ timeout: operation["x-alepha-timeout"] as number | undefined,
267
+ };
268
+ }
269
+
270
+ /**
271
+ * Whether the operation needs an identity: Alepha's own `x-alepha-security`
272
+ * when present, else a non-empty OpenAPI `security` requirement.
273
+ */
274
+ public isSecured(operation: OpenApiOperation): boolean {
275
+ if (operation["x-alepha-security"] !== undefined) {
276
+ return true;
277
+ }
278
+ return !!operation.security?.some((it) => Object.keys(it).length > 0);
279
+ }
280
+
281
+ protected collect(): SwaggerEntry[] {
282
+ const entries: SwaggerEntry[] = [];
283
+ for (const [path, item] of Object.entries(this.document.paths ?? {})) {
284
+ for (const method of OpenApiSpec.METHODS) {
285
+ const operation = (item as Record<string, OpenApiOperation>)?.[method];
286
+ if (!operation || typeof operation !== "object") {
287
+ continue;
288
+ }
289
+ entries.push({
290
+ id: operation.operationId ?? `${method.toUpperCase()} ${path}`,
291
+ method,
292
+ path,
293
+ tag: operation.tags?.[0] ?? "default",
294
+ operation,
295
+ });
296
+ }
297
+ }
298
+ return entries;
299
+ }
300
+ }