@astryxdesign/cli 0.6.5 → 0.6.6-canary.1f4eb3c

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 (433) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +58 -55
  3. package/api/build/_adapter.d.mts +55 -2
  4. package/api/build/_adapter.mjs +100 -10
  5. package/api/build/build.doc.mjs +2 -2
  6. package/api/build/build.test.mjs +111 -2
  7. package/api/build/build.type.d.mts +8 -0
  8. package/api/build/build.type.mjs +2 -0
  9. package/api/build/kit/kit.mjs +99 -22
  10. package/api/build/kit/rank.d.mts +32 -8
  11. package/api/build/kit/rank.mjs +291 -97
  12. package/api/build/kit/rank.test.mjs +231 -48
  13. package/api/build/kit/weights.d.mts +82 -0
  14. package/api/build/kit/weights.json +1 -0
  15. package/api/build/kit/weights.mjs +305 -0
  16. package/api/build/kit/weights.test.mjs +190 -0
  17. package/api/component/_adapter.d.mts +19 -0
  18. package/api/component/_adapter.mjs +33 -0
  19. package/api/component/component-replacement.test.mjs +603 -0
  20. package/api/component/component.mjs +49 -15
  21. package/api/component/component.test.mjs +32 -0
  22. package/api/component/component.type.d.mts +33 -3
  23. package/api/component/component.type.mjs +10 -3
  24. package/api/component/detail/blocks/blocks.d.mts +2 -1
  25. package/api/component/detail/blocks/blocks.mjs +5 -2
  26. package/api/component/detail/detail.mjs +5 -1
  27. package/api/component/detail/props/props.d.mts +2 -1
  28. package/api/component/detail/props/props.mjs +3 -2
  29. package/api/component/detail/showcase/showcase.d.mts +3 -1
  30. package/api/component/detail/showcase/showcase.mjs +3 -1
  31. package/api/component/detail/source/source.d.mts +3 -2
  32. package/api/component/detail/source/source.mjs +7 -3
  33. package/api/component/list/list.mjs +128 -10
  34. package/api/docs/_adapter.d.mts +11 -0
  35. package/api/docs/_adapter.mjs +25 -0
  36. package/api/docs/detail/detail.mjs +19 -3
  37. package/api/docs/detail/section/section.mjs +7 -1
  38. package/api/docs/docOverlays.test.mjs +10 -6
  39. package/api/docs/docs.d.mts +6 -0
  40. package/api/docs/docs.depth.test.mjs +134 -0
  41. package/api/docs/docs.doc.mjs +31 -2
  42. package/api/docs/docs.mjs +46 -1
  43. package/api/docs/docs.test.mjs +279 -0
  44. package/api/docs/docs.type.d.mts +81 -4
  45. package/api/docs/docs.type.mjs +41 -4
  46. package/api/docs/index/index.mjs +11 -2
  47. package/api/docs/index/index.test.mjs +7 -2
  48. package/api/docs/integration-tree.test.mjs +572 -0
  49. package/api/docs/integrationDocs.test.mjs +337 -0
  50. package/api/docs/node/node.d.mts +28 -3
  51. package/api/docs/node/node.mjs +149 -23
  52. package/api/doctor/_adapter.d.mts +43 -0
  53. package/api/doctor/_adapter.mjs +142 -0
  54. package/api/doctor/doctor.d.mts +0 -10
  55. package/api/doctor/doctor.doc.mjs +1 -3
  56. package/api/doctor/doctor.mjs +6 -123
  57. package/api/doctor/theme-checks.d.mts +12 -0
  58. package/api/doctor/theme-checks.mjs +1117 -0
  59. package/api/doctor/theme-checks.test.mjs +526 -0
  60. package/api/error.d.mts +22 -0
  61. package/api/error.mjs +42 -0
  62. package/api/gap-report/gap-report.d.mts +3 -1
  63. package/api/gap-report/gap-report.mjs +27 -3
  64. package/api/gap-report/gap-report.test.mjs +106 -0
  65. package/api/hook/_adapter.d.mts +1 -0
  66. package/api/hook/_adapter.mjs +3 -0
  67. package/api/hook/detail/detail.mjs +2 -2
  68. package/api/hook/detail/params/params.mjs +2 -2
  69. package/api/hook/hook.type.d.mts +12 -0
  70. package/api/hook/hook.type.mjs +3 -0
  71. package/api/hook/list/list.d.mts +1 -1
  72. package/api/hook/list/list.mjs +8 -8
  73. package/api/index.d.mts +1 -1
  74. package/api/index.mjs +4 -0
  75. package/api/init/run/run.d.mts +3 -5
  76. package/api/init/run/run.mjs +10 -11
  77. package/api/integration/__fixtures__/released-0.6.5-ocean.d.mts +14 -0
  78. package/api/integration/__fixtures__/released-0.6.5-ocean.mjs +15 -0
  79. package/api/integration/add-contribution.d.mts +2 -1
  80. package/api/integration/add-contribution.mjs +7 -3
  81. package/api/integration/add-contribution.test.mjs +3 -3
  82. package/api/integration/add-helpers.d.mts +26 -5
  83. package/api/integration/add-helpers.mjs +50 -5
  84. package/api/integration/add-theme.mjs +354 -28
  85. package/api/integration/add-theme.test.mjs +380 -16
  86. package/api/integration/authoring-checks.mjs +31 -8
  87. package/api/integration/authoring-checks.type.d.mts +8 -0
  88. package/api/integration/authoring-checks.type.mjs +7 -3
  89. package/api/integration/integration-authoring.type.d.mts +4 -1
  90. package/api/integration/integration-authoring.type.mjs +6 -1
  91. package/api/integration/integrationAdd.doc.mjs +6 -0
  92. package/api/integration/integrationAddTheme.doc.mjs +10 -0
  93. package/api/integration/integrationComponentConflicts.doc.mjs +6 -3
  94. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  95. package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
  96. package/api/integration/pack-check.component-replaces.test.mjs +126 -0
  97. package/api/integration/pack-check.d.mts +10 -0
  98. package/api/integration/pack-check.lifecycle-output.test.mjs +21 -2
  99. package/api/integration/pack-check.mjs +495 -4
  100. package/api/integration/pack-check.test.mjs +619 -10
  101. package/api/integration/validate-integration.d.mts +4 -2
  102. package/api/integration/validate-integration.mjs +7 -2
  103. package/api/integration/validate-integration.test.mjs +55 -0
  104. package/api/integration/validate-integration.type.d.mts +5 -0
  105. package/api/integration/validate-integration.type.mjs +5 -1
  106. package/api/integration/validateIntegration.doc.mjs +1 -1
  107. package/api/layout/expand/expand.mjs +12 -7
  108. package/api/layout/expand/expand.receipt.test.mjs +74 -0
  109. package/api/layout/layout.type.d.mts +1 -0
  110. package/api/layout/layout.type.mjs +1 -0
  111. package/api/layout/layoutExpand.doc.mjs +1 -1
  112. package/api/search/search.d.mts +39 -8
  113. package/api/search/search.doc.mjs +4 -4
  114. package/api/search/search.mjs +248 -66
  115. package/api/search/search.test.mjs +829 -0
  116. package/api/search/search.type.d.mts +6 -6
  117. package/api/search/search.type.mjs +5 -5
  118. package/api/swizzle/_adapter.d.mts +10 -0
  119. package/api/swizzle/_adapter.mjs +23 -0
  120. package/api/swizzle/copy/copy.d.mts +5 -6
  121. package/api/swizzle/copy/copy.mjs +95 -13
  122. package/api/swizzle/list/list.mjs +2 -2
  123. package/api/swizzle/swizzle.doc.mjs +4 -0
  124. package/api/swizzle/swizzle.test.mjs +55 -5
  125. package/api/swizzle/swizzle.type.d.mts +8 -0
  126. package/api/swizzle/swizzle.type.mjs +2 -0
  127. package/api/template/copy/copy.mjs +15 -8
  128. package/api/template/copy/copy.receipt.test.mjs +77 -0
  129. package/api/template/show/show.mjs +17 -4
  130. package/api/template/show/show.test.mjs +76 -0
  131. package/api/template/skeleton/skeleton.mjs +2 -1
  132. package/api/template/template-integration.test.mjs +14 -0
  133. package/api/template/template.d.mts +1 -1
  134. package/api/template/template.doc.mjs +6 -2
  135. package/api/template/template.mjs +2 -0
  136. package/api/template/template.type.d.mts +14 -0
  137. package/api/template/template.type.mjs +5 -0
  138. package/api/theme/_adapter.d.mts +106 -6
  139. package/api/theme/_adapter.mjs +687 -18
  140. package/api/theme/add/add.binary.test.mjs +76 -3
  141. package/api/theme/add/add.d.mts +5 -9
  142. package/api/theme/add/add.mjs +87 -64
  143. package/api/theme/add/add.rollback.test.mjs +9 -9
  144. package/api/theme/add/add.staging.test.mjs +9 -9
  145. package/api/theme/add/add.test.mjs +461 -55
  146. package/api/theme/add/add.types.test.mjs +151 -0
  147. package/api/theme/build/build.d.mts +50 -2
  148. package/api/theme/build/build.family.test.mjs +13 -4
  149. package/api/theme/build/build.icon-lineage.test.mjs +117 -0
  150. package/api/theme/build/build.icon-preservation.test.mjs +639 -0
  151. package/api/theme/build/build.mjs +463 -155
  152. package/api/theme/build/build.project-core.test.mjs +165 -0
  153. package/api/theme/build/build.test.mjs +220 -1
  154. package/api/theme/build/icon-imports.d.mts +47 -0
  155. package/api/theme/build/icon-imports.mjs +691 -0
  156. package/api/theme/eject/eject.binary.test.mjs +90 -0
  157. package/api/theme/eject/eject.d.mts +17 -0
  158. package/api/theme/eject/eject.mjs +65 -0
  159. package/api/theme/eject/eject.rollback.test.mjs +158 -0
  160. package/api/theme/eject/eject.staging.test.mjs +83 -0
  161. package/api/theme/eject/eject.test.mjs +160 -0
  162. package/api/theme/integration-themes.test.mjs +30 -6
  163. package/api/theme/list/list.d.mts +10 -0
  164. package/api/theme/list/list.mjs +75 -7
  165. package/api/theme/list/list.test.mjs +155 -4
  166. package/api/theme/remove/remove.d.mts +12 -0
  167. package/api/theme/remove/remove.mjs +15 -0
  168. package/api/theme/remove/remove.test.mjs +94 -0
  169. package/api/theme/template/template.mjs +3 -4
  170. package/api/theme/theme.d.mts +5 -2
  171. package/api/theme/theme.mjs +13 -8
  172. package/api/theme/theme.type.d.mts +106 -2
  173. package/api/theme/theme.type.mjs +54 -5
  174. package/api/theme/themeAdd.doc.d.mts +1 -3
  175. package/api/theme/themeAdd.doc.mjs +35 -22
  176. package/api/theme/themeBuild.doc.d.mts +4 -1
  177. package/api/theme/themeBuild.doc.mjs +15 -4
  178. package/api/theme/themeEject.doc.d.mts +8 -0
  179. package/api/theme/themeEject.doc.mjs +89 -0
  180. package/api/theme/themeListAvailable.doc.mjs +4 -4
  181. package/api/theme/themeListCopySources.doc.d.mts +8 -0
  182. package/api/theme/themeListCopySources.doc.mjs +60 -0
  183. package/api/theme/themeRemove.doc.d.mts +6 -0
  184. package/api/theme/themeRemove.doc.mjs +50 -0
  185. package/api/theme/themeTemplate.doc.mjs +4 -3
  186. package/api/theme/themeUse.doc.d.mts +6 -0
  187. package/api/theme/themeUse.doc.mjs +47 -0
  188. package/api/theme/use/use.d.mts +12 -0
  189. package/api/theme/use/use.mjs +15 -0
  190. package/api/theme/use/use.test.mjs +98 -0
  191. package/api/upgrade/_adapter.d.mts +1 -0
  192. package/api/upgrade/_adapter.mjs +3 -0
  193. package/api/upgrade/list/list.mjs +9 -3
  194. package/api/upgrade/run/run.mjs +20 -3
  195. package/api/upgrade/run/run.test.mjs +45 -1
  196. package/api/upgrade/upgrade.doc.mjs +1 -1
  197. package/api/upgrade/upgrade.type.d.mts +5 -0
  198. package/api/upgrade/upgrade.type.mjs +2 -0
  199. package/assets/codemods/integration-discovery.mjs +1 -1
  200. package/assets/codemods/integration-discovery.test.mjs +64 -0
  201. package/assets/codemods/transforms/next/__tests__/migrate-copied-themes-to-descriptors.test.mjs +129 -0
  202. package/assets/codemods/transforms/next/index.mjs +14 -1
  203. package/assets/codemods/transforms/next/migrate-copied-themes-to-descriptors.mjs +54 -0
  204. package/assets/docs/author-a-theme.doc.mjs +161 -0
  205. package/assets/docs/getting-started.doc.mjs +59 -15
  206. package/assets/docs/icons.doc.mjs +1 -0
  207. package/assets/docs/principles.doc.dense.mjs +2 -2
  208. package/assets/docs/principles.doc.mjs +2 -2
  209. package/assets/docs/principles.doc.zh.mjs +2 -2
  210. package/assets/docs/styling-libraries.doc.mjs +1 -1
  211. package/assets/docs/styling.doc.mjs +2 -2
  212. package/assets/docs/theme.doc.dense.mjs +10 -198
  213. package/assets/docs/theme.doc.mjs +13 -770
  214. package/assets/docs/theme.doc.zh.mjs +31 -12
  215. package/assets/docs/tokens.doc.mjs +4 -4
  216. package/assets/docs/tree/add-a-theme.doc.mjs +6 -2
  217. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  218. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  219. package/assets/docs/tree/checks.doc.mjs +6 -5
  220. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  221. package/assets/docs/tree/define-the-theme.doc.mjs +2 -2
  222. package/assets/docs/tree/document-the-theme.doc.mjs +4 -4
  223. package/assets/docs/tree/fonts-and-assets.doc.mjs +25 -20
  224. package/assets/docs/tree/headers-and-footers.doc.mjs +68 -0
  225. package/assets/docs/tree/layout-spacing.doc.mjs +168 -0
  226. package/assets/docs/tree/layout.doc.mjs +32 -0
  227. package/assets/docs/tree/replace-a-core-component.doc.mjs +21 -4
  228. package/assets/docs/tree/responsive.doc.mjs +102 -0
  229. package/assets/docs/tree/scaffold.doc.mjs +145 -0
  230. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  231. package/assets/docs/tree/side-panels.doc.mjs +82 -0
  232. package/assets/docs/tree/structure.doc.mjs +144 -0
  233. package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
  234. package/assets/docs/tree/themes.doc.mjs +2 -2
  235. package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
  236. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +22 -5
  237. package/assets/docs/tree/versioning.doc.mjs +11 -7
  238. package/assets/docs/use-a-theme.doc.mjs +97 -0
  239. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
  240. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
  241. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
  242. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
  243. package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
  244. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
  245. package/assets/templates/pages/blank/template.doc.mjs +3 -1
  246. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
  247. package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
  248. package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
  249. package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
  250. package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
  251. package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
  252. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
  253. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
  254. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
  255. package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
  256. package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
  257. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
  258. package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
  259. package/assets/templates/pages/documentation/template.doc.mjs +10 -1
  260. package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
  261. package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
  262. package/assets/templates/pages/editor/template.doc.mjs +9 -1
  263. package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
  264. package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
  265. package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
  266. package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
  267. package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
  268. package/assets/templates/pages/ide/template.doc.mjs +9 -1
  269. package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
  270. package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
  271. package/assets/templates/pages/library/template.doc.mjs +15 -1
  272. package/assets/templates/pages/login/template.doc.mjs +10 -1
  273. package/assets/templates/pages/login-card/template.doc.mjs +11 -1
  274. package/assets/templates/pages/login-split/template.doc.mjs +10 -1
  275. package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
  276. package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
  277. package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
  278. package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
  279. package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
  280. package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
  281. package/assets/templates/pages/settings/template.doc.mjs +3 -1
  282. package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
  283. package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
  284. package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
  285. package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
  286. package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
  287. package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
  288. package/assets/templates/pages/table/template.doc.mjs +11 -1
  289. package/assets/templates/pages/table-collapsible/page.tsx +1474 -0
  290. package/assets/templates/pages/table-collapsible/template.doc.mjs +12 -0
  291. package/assets/templates/pages/table-comparison/page.tsx +1449 -0
  292. package/assets/templates/pages/table-comparison/template.doc.mjs +12 -0
  293. package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
  294. package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
  295. package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
  296. package/assets/templates/pages/table-page/template.doc.mjs +20 -1
  297. package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
  298. package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
  299. package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
  300. package/assets/templates/themes/butter/icons.tsx +2 -0
  301. package/assets/templates/themes/chocolate/icons.tsx +2 -0
  302. package/assets/templates/themes/gothic/icons.tsx +2 -0
  303. package/assets/templates/themes/matcha/icons.tsx +2 -0
  304. package/assets/templates/themes/neutral/icons.tsx +2 -0
  305. package/assets/templates/themes/stone/icons.tsx +2 -0
  306. package/assets/templates/themes/y2k/icons.tsx +2 -0
  307. package/authoring/doctypes/command/command.doc.mjs +5 -0
  308. package/authoring/doctypes/command/type.ts +2 -0
  309. package/authoring/doctypes/component/component.doc.mjs +1 -1
  310. package/authoring/doctypes/component/type.ts +8 -4
  311. package/authoring/doctypes/template/parse.d.mts +2 -0
  312. package/authoring/doctypes/template/parse.mjs +1 -0
  313. package/authoring/doctypes/template/parse.test.mjs +21 -0
  314. package/authoring/doctypes/template/template.doc.mjs +6 -0
  315. package/authoring/doctypes/template/type.ts +10 -0
  316. package/authoring/integration/integration.doc.mjs +1 -1
  317. package/clients/cli/commands/build-theme.mjs +279 -30
  318. package/clients/cli/commands/build.mjs +7 -6
  319. package/clients/cli/commands/build.text-fields.test.mjs +1 -1
  320. package/clients/cli/commands/component/index.mjs +88 -12
  321. package/clients/cli/commands/component-replacement.text.test.mjs +271 -0
  322. package/clients/cli/commands/component.doc.mjs +9 -2
  323. package/clients/cli/commands/discover.mjs +29 -1
  324. package/clients/cli/commands/discover.no-source.test.mjs +75 -0
  325. package/clients/cli/commands/docs.depth.test.mjs +219 -0
  326. package/clients/cli/commands/docs.doc.mjs +15 -2
  327. package/clients/cli/commands/docs.mjs +273 -16
  328. package/clients/cli/commands/docs.test.mjs +382 -0
  329. package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
  330. package/clients/cli/commands/doctor.doc.mjs +1 -1
  331. package/clients/cli/commands/doctor.mjs +4 -4
  332. package/clients/cli/commands/doctor.test.mjs +9 -51
  333. package/clients/cli/commands/gap-report.doc.mjs +2 -2
  334. package/clients/cli/commands/gap-report.mjs +12 -0
  335. package/clients/cli/commands/gap-report.test.mjs +63 -0
  336. package/clients/cli/commands/hook/index.mjs +7 -2
  337. package/clients/cli/commands/import-hint-correctness.test.mjs +5 -5
  338. package/clients/cli/commands/init.next-steps.test.mjs +18 -23
  339. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  340. package/clients/cli/commands/integration-authoring.test.mjs +12 -2
  341. package/clients/cli/commands/integration-real-world.test.mjs +61 -12
  342. package/clients/cli/commands/integration.mjs +3 -1
  343. package/clients/cli/commands/layout-check.doc.mjs +1 -0
  344. package/clients/cli/commands/layout-expand.doc.mjs +4 -1
  345. package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
  346. package/clients/cli/commands/layout.doc.mjs +1 -0
  347. package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
  348. package/clients/cli/commands/layout.mjs +61 -4
  349. package/clients/cli/commands/no-prompt-wording.test.mjs +4 -4
  350. package/clients/cli/commands/search.doc.mjs +5 -4
  351. package/clients/cli/commands/search.mjs +30 -6
  352. package/clients/cli/commands/search.test.mjs +63 -17
  353. package/clients/cli/commands/swizzle.doc.mjs +12 -3
  354. package/clients/cli/commands/swizzle.mjs +2 -1
  355. package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
  356. package/clients/cli/commands/template.mjs +70 -6
  357. package/clients/cli/commands/template.show-media.test.mjs +62 -0
  358. package/clients/cli/commands/text-json-parity.test.mjs +40 -0
  359. package/clients/cli/commands/theme-add-lifecycle.test.mjs +132 -0
  360. package/clients/cli/commands/theme-add.doc.mjs +19 -19
  361. package/clients/cli/commands/theme-eject.doc.mjs +47 -0
  362. package/clients/cli/commands/theme-list.behavior.test.mjs +44 -0
  363. package/clients/cli/commands/theme-list.doc.mjs +2 -2
  364. package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -2
  365. package/clients/cli/commands/theme-remove.doc.mjs +22 -0
  366. package/clients/cli/commands/theme-template.doc.mjs +4 -3
  367. package/clients/cli/commands/theme-use.doc.mjs +22 -0
  368. package/clients/cli/commands/theme.doc.mjs +21 -16
  369. package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
  370. package/clients/cli/commands/upgrade.mjs +1 -1
  371. package/clients/cli/commands/write-failure.test.mjs +175 -0
  372. package/clients/cli/index.mjs +4 -1
  373. package/clients/cli/lib/component-format.mjs +19 -2
  374. package/clients/cli/lib/manifest.mjs +44 -165
  375. package/clients/cli/lib/manifest.test.mjs +98 -7
  376. package/clients/cli/lib/resolve-theme.mjs +80 -78
  377. package/clients/cli/lib/resolve-theme.test.mjs +523 -27
  378. package/foundation/agent-docs/agent-docs.mjs +31 -28
  379. package/foundation/agent-docs/agent-docs.test.mjs +1163 -0
  380. package/foundation/agent-docs/app-theme-workflow.test.mjs +13 -0
  381. package/foundation/config/project.d.mts +20 -5
  382. package/foundation/config/project.mjs +43 -6
  383. package/foundation/config/theme-private-vars.d.mts +12 -0
  384. package/foundation/config/theme-private-vars.mjs +107 -0
  385. package/foundation/config/theme-private-vars.test.mjs +55 -0
  386. package/foundation/config/theme-state.d.mts +145 -0
  387. package/foundation/config/theme-state.mjs +417 -0
  388. package/foundation/config/theme-state.test.mjs +182 -0
  389. package/foundation/discovery/component-discovery.d.mts +5 -2
  390. package/foundation/discovery/component-discovery.mjs +12 -6
  391. package/foundation/discovery/component-replacement.d.mts +91 -0
  392. package/foundation/discovery/component-replacement.mjs +417 -0
  393. package/foundation/discovery/component-replacement.test.mjs +480 -0
  394. package/foundation/discovery/docs-output-budget.d.mts +6 -2
  395. package/foundation/discovery/docs-output-budget.mjs +2 -1
  396. package/foundation/discovery/docs-section-key.d.mts +4 -2
  397. package/foundation/discovery/docs-section-key.mjs +1 -1
  398. package/foundation/discovery/module-exports.d.mts +10 -0
  399. package/foundation/discovery/module-exports.mjs +146 -0
  400. package/foundation/discovery/package-exports.d.mts +29 -0
  401. package/foundation/discovery/package-exports.mjs +200 -0
  402. package/foundation/discovery/template-adapter.d.mts +14 -0
  403. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
  404. package/foundation/discovery/template-adapter.mjs +21 -1
  405. package/foundation/discovery/theme-discovery.d.mts +78 -5
  406. package/foundation/discovery/theme-discovery.mjs +143 -18
  407. package/foundation/discovery/theme-discovery.test.mjs +9 -3
  408. package/foundation/discovery/theme-imports.d.mts +15 -0
  409. package/foundation/discovery/theme-imports.mjs +217 -0
  410. package/foundation/discovery/theme-imports.test.mjs +173 -0
  411. package/foundation/doc-compiler/doc-loads.test.mjs +18 -8
  412. package/foundation/doc-compiler/inputs.mjs +2 -1
  413. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  414. package/foundation/doc-compiler/lenses.d.mts +4 -2
  415. package/foundation/doc-compiler/lenses.mjs +1 -1
  416. package/foundation/doc-compiler/tree.test.mjs +649 -0
  417. package/foundation/fs/module-loader.d.mts +9 -0
  418. package/foundation/fs/module-loader.mjs +71 -2
  419. package/foundation/integrations/cli-requirement.d.mts +79 -13
  420. package/foundation/integrations/cli-requirement.mjs +115 -22
  421. package/foundation/integrations/cli-requirement.test.mjs +205 -8
  422. package/foundation/integrations/contribution-inventory.mjs +3 -3
  423. package/foundation/response/base.d.ts +9 -3
  424. package/foundation/response/json.d.mts +7 -4
  425. package/foundation/response/json.mjs +10 -6
  426. package/foundation/response/response-types.doc.d.mts +5 -5
  427. package/foundation/response/response-types.doc.mjs +50 -35
  428. package/foundation/response/response.doc.mjs +18 -4
  429. package/foundation/text/copyright-header.mjs +1 -1
  430. package/foundation/text/copyright-header.test.mjs +1 -1
  431. package/package.json +9 -9
  432. package/assets/docs/layout.doc.dense.mjs +0 -388
  433. package/assets/docs/layout.doc.mjs +0 -550
@@ -0,0 +1,1474 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * Four kinds of financial account on one page, each in a collapsible Card with
7
+ * a table of its own — because a credit card and a checking account do not
8
+ * share a column grid.
9
+ *
10
+ * This is the grouping shape for heterogeneous records. `useTableGroupedRows`
11
+ * is the right tool when every group is the same kind of thing and grouping is
12
+ * just a sort you can collapse: issues by status, orders by month, rows by
13
+ * owner. One table, one header, section rows in between. It is the wrong tool
14
+ * the moment the groups stop agreeing on what the columns mean. Utilization is
15
+ * a credit-card idea, pending payout is a processor idea, and cost basis is an
16
+ * investment idea; forcing all three into one grid produces a table that is
17
+ * mostly em-dashes, with a header row that is true of no row beneath it.
18
+ *
19
+ * So each group owns a table. The Card supplies the boundary the shared header
20
+ * row used to supply, and the Collapsible trigger carries the group's name,
21
+ * count, and running total, so a collapsed group still answers the question
22
+ * most people came for.
23
+ *
24
+ * The `table-grouped` template is the other half of this pair: one collection
25
+ * of like rows, split into collapsible sections that all share a column set.
26
+ * Reach for that one when the rows agree and this one when they do not.
27
+ *
28
+ * ## Extending this template
29
+ *
30
+ * **The test for splitting is column divergence, not group count.** Two groups
31
+ * with different columns belong in separate tables; twelve groups with
32
+ * identical columns belong in one table with the plugin. If you find yourself
33
+ * adding a column that only applies to some groups and writing a fallback dash
34
+ * for the rest, that is the signal to split. Conversely, if these four tables
35
+ * ever converge on the same columns, collapse them back — this layout costs a
36
+ * Card and a header per group, and that is only worth paying for real
37
+ * structural difference.
38
+ *
39
+ * **Each table is data-driven, and that is the payoff.** Because the groups are
40
+ * separate tables, every one of them can use `data` + `columns` with
41
+ * `renderCell`, which is the RSC-friendly path and the one that gets headers,
42
+ * widths, and plugins for free. The single-table version of this page has to
43
+ * drop to children mode to emit section rows, and loses all of that.
44
+ *
45
+ * **What the four tables do share, they share by position.** Every table runs
46
+ * name → qualifier → figures → change, on the same column widths, so the eye
47
+ * can travel straight down the page across four different schemas. That is the
48
+ * whole reason Utilization sits ahead of Balance rather than after it.
49
+ *
50
+ * **The trigger is a button, so it holds no buttons.** Group name, count, and
51
+ * total are text and icons only. Per-account actions live in the rows, and
52
+ * anything that acts on a whole group belongs in the page header rather than
53
+ * inside the trigger — nesting a control inside the trigger makes the click
54
+ * target ambiguous and is invalid HTML besides.
55
+ *
56
+ * **Open state is controlled, not `defaultIsOpen`.** The page owns a Set of
57
+ * open group ids, which is what lets Expand all / Collapse all work and what
58
+ * you would persist per user. Uncontrolled Collapsibles are fine for a static
59
+ * FAQ; they cannot participate in a page-level control.
60
+ *
61
+ * **Money is stored in cents.** Every amount is an integer and only the display
62
+ * step formats, so group totals and the header's net position stay exact. Net
63
+ * position deliberately subtracts card balances — it is a derived figure, never
64
+ * a stored one, so adding an account updates it with no other edit.
65
+ *
66
+ * **One time range drives the whole page.** The selector under the chart is
67
+ * page state, not chart state: the Change column, every detail chart, and the
68
+ * header's delta all read it from context. A page where the chart says "3M"
69
+ * and the table says something else is a page with two different answers to
70
+ * the same question.
71
+ */
72
+
73
+ import {
74
+ createContext,
75
+ useContext,
76
+ useEffect,
77
+ useLayoutEffect,
78
+ useMemo,
79
+ useRef,
80
+ useState,
81
+ } from 'react';
82
+ import * as stylex from '@stylexjs/stylex';
83
+ import {
84
+ Area,
85
+ AreaChart,
86
+ ReferenceLine,
87
+ ResponsiveContainer,
88
+ Tooltip,
89
+ XAxis,
90
+ YAxis,
91
+ } from 'recharts';
92
+
93
+ import {
94
+ HStack,
95
+ Layout,
96
+ LayoutContent,
97
+ LayoutHeader,
98
+ StackItem,
99
+ VStack,
100
+ } from '@astryxdesign/core/Layout';
101
+ import {colorVars, radiusVars} from '@astryxdesign/core/theme/tokens.stylex';
102
+ import {Heading, Text} from '@astryxdesign/core/Text';
103
+ import {Badge} from '@astryxdesign/core/Badge';
104
+ import {Button} from '@astryxdesign/core/Button';
105
+ import {Card} from '@astryxdesign/core/Card';
106
+ import {Collapsible} from '@astryxdesign/core/Collapsible';
107
+ import {Icon} from '@astryxdesign/core/Icon';
108
+ import {ProgressBar} from '@astryxdesign/core/ProgressBar';
109
+ import {Skeleton} from '@astryxdesign/core/Skeleton';
110
+ import {
111
+ SegmentedControl,
112
+ SegmentedControlItem,
113
+ } from '@astryxdesign/core/SegmentedControl';
114
+ import {Token} from '@astryxdesign/core/Token';
115
+ import {
116
+ Table,
117
+ pixel,
118
+ proportional,
119
+ useTableRowExpansion,
120
+ useTableSortable,
121
+ useTableSortableState,
122
+ } from '@astryxdesign/core/Table';
123
+ import type {TableColumn, TableSortComparator} from '@astryxdesign/core/Table';
124
+ import {
125
+ ArrowsRightLeftIcon,
126
+ BuildingLibraryIcon,
127
+ CreditCardIcon,
128
+ PresentationChartLineIcon,
129
+ } from '@heroicons/react/24/outline';
130
+
131
+ // ============= SHARED VOCABULARY =============
132
+
133
+ /** Everything the page-level machinery needs from a row, whatever group it is
134
+ * in: an id to key its history by, and the drift that history follows. */
135
+ interface AccountRecord extends Record<string, unknown> {
136
+ id: string;
137
+ /** Direction and strength of the account's drift, as a daily fraction. Feeds
138
+ * the generated history, so an account's chart and its Change agree. */
139
+ trend: number;
140
+ }
141
+
142
+ // Pinned locale keeps the rendered output identical in every environment.
143
+ const currency = new Intl.NumberFormat('en-US', {
144
+ style: 'currency',
145
+ currency: 'USD',
146
+ });
147
+
148
+ function money(cents: number): string {
149
+ return currency.format(cents / 100);
150
+ }
151
+
152
+ function sum<T>(rows: T[], pick: (row: T) => number): number {
153
+ return rows.reduce((total, row) => total + pick(row), 0);
154
+ }
155
+
156
+ /**
157
+ * Every numeric cell on the page. Alignment is deliberately not its job: the
158
+ * column's `align: 'end'` puts a `text-align` on the `<th>` as well as the
159
+ * `<td>`, so the header travels with its figures instead of hugging the far
160
+ * side of them. Doing it in the cell would right-align the numbers and leave
161
+ * the header behind. All this adds is tabular digits, so a column of money
162
+ * lines up digit for digit.
163
+ *
164
+ * There is no muted variant. A figure in a table is a value, and values are
165
+ * primary text — the de-emphasis that used to sit on the comparison columns
166
+ * made them read as annotations on the column beside them rather than as
167
+ * numbers in their own right.
168
+ */
169
+ function Figure({children}: {children: string}) {
170
+ return <Text hasTabularNumbers>{children}</Text>;
171
+ }
172
+
173
+ // ============= TIME RANGE =============
174
+
175
+ const RANGE_IDS = ['1W', '1M', '3M', 'YTD', '1Y'] as const;
176
+ type RangeId = (typeof RANGE_IDS)[number];
177
+
178
+ /** Pinned so the generated series, the axis labels and the "as of" dates are
179
+ * the same on every render and in every environment. */
180
+ const TODAY = Date.UTC(2025, 8, 30);
181
+
182
+ const RANGE_DAYS: Record<RangeId, number> = {
183
+ '1W': 7,
184
+ '1M': 30,
185
+ '3M': 90,
186
+ // Days elapsed in the pinned year, so YTD means what it says on this date.
187
+ YTD: 273,
188
+ '1Y': 365,
189
+ };
190
+
191
+ /**
192
+ * The selected window, read by the Change column and by every detail chart.
193
+ * Context rather than prop-drilling because the readers are cells — four
194
+ * column definitions deep, in four separate tables, none of which the page
195
+ * renders directly.
196
+ */
197
+ const RangeContext = createContext<RangeId>('YTD');
198
+ const useRange = () => useContext(RangeContext);
199
+
200
+ const SERIES_DAYS = RANGE_DAYS['1Y'];
201
+
202
+ const dayFormat = new Intl.DateTimeFormat('en-US', {
203
+ month: 'short',
204
+ day: 'numeric',
205
+ timeZone: 'UTC',
206
+ });
207
+
208
+ function dayLabel(daysAgo: number): string {
209
+ const date = new Date(TODAY);
210
+ date.setUTCDate(date.getUTCDate() - daysAgo);
211
+ return dayFormat.format(date);
212
+ }
213
+
214
+ /** FNV-1a over the account id, so each account's walk is its own but stable. */
215
+ function seedFrom(id: string): number {
216
+ let hash = 2166136261;
217
+ for (let index = 0; index < id.length; index++) {
218
+ hash ^= id.charCodeAt(index);
219
+ hash = Math.imul(hash, 16777619);
220
+ }
221
+ return hash >>> 0;
222
+ }
223
+
224
+ /**
225
+ * A year of daily values ending at the account's current figure.
226
+ *
227
+ * Built backwards from today so the last point is always the real number on
228
+ * the row — the alternative is a series that drifts to something close to it
229
+ * and a table that disagrees with its own chart. xorshift rather than
230
+ * `Math.random` because a template that renders differently on the server and
231
+ * the client is a hydration error waiting to happen.
232
+ */
233
+ function historyFor<T extends AccountRecord>(
234
+ rows: T[],
235
+ pick: (row: T) => number,
236
+ volatility: number,
237
+ ): Array<[string, number[]]> {
238
+ return rows.map(row => {
239
+ let state = seedFrom(row.id) || 1;
240
+ const random = () => {
241
+ state ^= state << 13;
242
+ state ^= state >>> 17;
243
+ state ^= state << 5;
244
+ return ((state >>> 0) % 10000) / 10000 - 0.5;
245
+ };
246
+
247
+ const series = new Array<number>(SERIES_DAYS);
248
+ let value = pick(row);
249
+ series[SERIES_DAYS - 1] = value;
250
+ for (let day = SERIES_DAYS - 2; day >= 0; day--) {
251
+ value /= 1 + row.trend + random() * volatility;
252
+ series[day] = Math.max(1, Math.round(value));
253
+ }
254
+ return [row.id, series];
255
+ });
256
+ }
257
+
258
+ function windowOf(id: string, range: RangeId): number[] {
259
+ return HISTORY[id].slice(-RANGE_DAYS[range]);
260
+ }
261
+
262
+ /**
263
+ * The Change column is a percentage, not an amount. Four groups whose headline
264
+ * figures span two orders of magnitude cannot be compared in dollars — a
265
+ * $5,000 move is most of a vendor card and a rounding error on the treasury
266
+ * sweep. A percentage is the one form of "how much did this move" that means
267
+ * the same thing in every one of these tables, which is what makes it worth a
268
+ * column in all four.
269
+ */
270
+ function changePercentOf(id: string, range: RangeId): number {
271
+ const points = windowOf(id, range);
272
+ const start = points[0];
273
+ if (start === 0) {
274
+ return 0;
275
+ }
276
+ return ((points[points.length - 1] - start) / Math.abs(start)) * 100;
277
+ }
278
+
279
+ const percentFormat = new Intl.NumberFormat('en-US', {
280
+ minimumFractionDigits: 1,
281
+ maximumFractionDigits: 1,
282
+ });
283
+
284
+ // ============= CHART VOCABULARY =============
285
+
286
+ const UP_COLOR = 'var(--color-data-categorical-green, #0B991F)';
287
+ const DOWN_COLOR = 'var(--color-data-categorical-red, #F5394F)';
288
+ const GRID_COLOR = 'var(--color-border, rgba(5, 54, 89, 0.1))';
289
+ // Text tokens rather than the categorical pair the charts stroke with: these
290
+ // carry text contrast, which a 12px label needs and a 1.5px line does not.
291
+ const TEXT_UP_COLOR = 'var(--color-text-green, #0B991F)';
292
+ const TEXT_DOWN_COLOR = 'var(--color-text-red, #F5394F)';
293
+ const AXIS_TICK = {
294
+ fontSize: 'var(--font-size-sm, 12px)',
295
+ fill: 'var(--color-text-secondary, #4E606F)',
296
+ };
297
+
298
+ /** Tooltips and readouts have no room for cents. */
299
+ const wholeCurrency = new Intl.NumberFormat('en-US', {
300
+ style: 'currency',
301
+ currency: 'USD',
302
+ maximumFractionDigits: 0,
303
+ });
304
+
305
+ /** Five evenly spaced dates, whether the window is a week or a year. */
306
+ function axisTicks(count: number): number[] {
307
+ const stops = Math.min(5, count);
308
+ if (stops < 2) {
309
+ return [0];
310
+ }
311
+ return Array.from({length: stops}, (_, stop) =>
312
+ Math.round((stop * (count - 1)) / (stops - 1)),
313
+ );
314
+ }
315
+
316
+ /**
317
+ * The width of the box the cards are laid out in, tracked as it changes.
318
+ *
319
+ * A media query answers a question about the window, and this template is not
320
+ * always the window: the docsite preview puts it in a dialog and the catalog
321
+ * draws it through `scale(0.5)`. Both leave `matchMedia` describing a viewport
322
+ * the cards cannot see. `@container` asks the right question, but its answer
323
+ * never leaves CSS and what changes here is the column *list*, which only
324
+ * React can do — so the box is measured.
325
+ *
326
+ * `offsetWidth` for the first read rather than `getBoundingClientRect`: the
327
+ * observer reports the box as laid out and ignores an ancestor transform,
328
+ * while the rect bakes it in, so mixing the two under the catalog's scale
329
+ * opens at half the real width and corrects an instant later.
330
+ */
331
+ function useSurfaceWidth() {
332
+ const ref = useRef<HTMLElement>(null);
333
+ const [width, setWidth] = useState(0);
334
+
335
+ useLayoutEffect(() => {
336
+ const node = ref.current;
337
+ if (!node) {
338
+ return;
339
+ }
340
+ setWidth(node.offsetWidth);
341
+
342
+ const observer = new ResizeObserver(entries => {
343
+ const entry = entries[0];
344
+ if (entry) {
345
+ setWidth(entry.contentRect.width);
346
+ }
347
+ });
348
+ observer.observe(node);
349
+ return () => observer.disconnect();
350
+ }, []);
351
+
352
+ return [ref, width] as const;
353
+ }
354
+
355
+ /**
356
+ * Below this the widest table — credit cards, carrying three money columns
357
+ * and a change — has less room than its fixed widths ask for, and every table
358
+ * switches together so the four cards stay legible as one page rather than
359
+ * four differently-shaped ones.
360
+ */
361
+ const COMPACT_BELOW_PX = 720;
362
+
363
+ /**
364
+ * Every column the compact layout drops, folded into the one that survives:
365
+ * the figure the group is headlined by, and beneath it the direction and size
366
+ * of its move. The arrow states the sign that the colour also states, so the
367
+ * cell still reads where the colour does not.
368
+ */
369
+ function CompactValueCell({
370
+ id,
371
+ amountCents,
372
+ isLiability,
373
+ }: {
374
+ id: string;
375
+ amountCents: number;
376
+ isLiability?: boolean;
377
+ }) {
378
+ const range = useRange();
379
+ const percent = changePercentOf(id, range);
380
+ const isUp = percent >= 0;
381
+ const isGood = isLiability ? !isUp : isUp;
382
+ return (
383
+ <VStack gap={0} hAlign="end">
384
+ <Figure>{money(amountCents)}</Figure>
385
+ {/* Colour on the row so the icon and the figure inherit one value,
386
+ rather than being told the same thing twice — Text has no success
387
+ or error of its own to be told with. */}
388
+ <HStack
389
+ gap={0.5}
390
+ vAlign="center"
391
+ xstyle={styles.delta(isGood ? TEXT_UP_COLOR : TEXT_DOWN_COLOR)}>
392
+ <Icon
393
+ icon={isUp ? 'arrowUp' : 'arrowDown'}
394
+ size="xsm"
395
+ color="inherit"
396
+ />
397
+ <Text type="supporting" color="inherit">
398
+ {percentFormat.format(Math.abs(percent))}%
399
+ </Text>
400
+ </HStack>
401
+ </VStack>
402
+ );
403
+ }
404
+
405
+ function ChangeCell({id, isLiability}: {id: string; isLiability?: boolean}) {
406
+ const range = useRange();
407
+ const percent = changePercentOf(id, range);
408
+ const isUp = percent >= 0;
409
+ const isGood = isLiability ? !isUp : isUp;
410
+ return (
411
+ // A Token is a flex box and fills the cell, so `text-align` from the
412
+ // column's align cannot place it — the row does that here instead.
413
+ <HStack hAlign="end">
414
+ <Token
415
+ size="sm"
416
+ color={isGood ? 'green' : 'red'}
417
+ label={`${isUp ? '+' : '−'}${percentFormat.format(Math.abs(percent))}%`}
418
+ />
419
+ </HStack>
420
+ );
421
+ }
422
+
423
+ // ============= GROUP 1 — BANK ACCOUNTS =============
424
+
425
+ interface BankAccount extends AccountRecord {
426
+ name: string;
427
+ institution: string;
428
+ mask: string;
429
+ kind: 'Checking' | 'Savings' | 'Money market';
430
+ availableCents: number;
431
+ }
432
+
433
+ const BANK_ACCOUNTS: BankAccount[] = [
434
+ {
435
+ id: 'bank-1',
436
+ name: 'Operating',
437
+ institution: 'First Meridian Bank',
438
+ mask: '••4417',
439
+ kind: 'Checking',
440
+ availableCents: 84_215_600,
441
+ trend: 0.00022,
442
+ },
443
+ {
444
+ id: 'bank-2',
445
+ name: 'Payroll',
446
+ institution: 'First Meridian Bank',
447
+ mask: '••8830',
448
+ kind: 'Checking',
449
+ availableCents: 21_940_800,
450
+ trend: 0.00004,
451
+ },
452
+ {
453
+ id: 'bank-3',
454
+ name: 'Tax reserve',
455
+ institution: 'Harborline Credit Union',
456
+ mask: '••1265',
457
+ kind: 'Savings',
458
+ availableCents: 47_500_000,
459
+ trend: 0.00009,
460
+ },
461
+ {
462
+ id: 'bank-4',
463
+ name: 'Treasury sweep',
464
+ institution: 'Northgate Financial',
465
+ mask: '••7702',
466
+ kind: 'Money market',
467
+ availableCents: 132_800_000,
468
+ trend: 0.00033,
469
+ },
470
+ ];
471
+
472
+ const bankColumns: TableColumn<BankAccount>[] = [
473
+ {
474
+ key: 'name',
475
+ sortable: true,
476
+ header: 'Account',
477
+ width: proportional(2),
478
+ renderCell: account => (
479
+ <VStack gap={0}>
480
+ <Text>{account.name}</Text>
481
+ <Text type="supporting">
482
+ {account.institution} · {account.mask}
483
+ </Text>
484
+ </VStack>
485
+ ),
486
+ },
487
+ {
488
+ key: 'kind',
489
+ sortable: true,
490
+ header: 'Type',
491
+ width: pixel(150),
492
+ renderCell: account => <Text>{account.kind}</Text>,
493
+ },
494
+ {
495
+ key: 'available',
496
+ sortable: true,
497
+ header: 'Available',
498
+ width: pixel(150),
499
+ align: 'end',
500
+ renderCell: account => <Figure>{money(account.availableCents)}</Figure>,
501
+ },
502
+ {
503
+ key: 'change',
504
+ sortable: true,
505
+ header: 'Change',
506
+ width: pixel(110),
507
+ align: 'end',
508
+ renderCell: account => <ChangeCell id={account.id} />,
509
+ },
510
+ ];
511
+
512
+ // The name cell is reused rather than restated, so the two layouts cannot
513
+ // drift apart in the one column they share.
514
+ const bankCompactColumns: TableColumn<BankAccount>[] = [
515
+ bankColumns[0],
516
+ {
517
+ key: 'available',
518
+ sortable: true,
519
+ header: 'Available',
520
+ width: pixel(150),
521
+ align: 'end',
522
+ renderCell: account => (
523
+ <CompactValueCell id={account.id} amountCents={account.availableCents} />
524
+ ),
525
+ },
526
+ ];
527
+
528
+ const bankComparators: Partial<
529
+ Record<string, TableSortComparator<BankAccount>>
530
+ > = {
531
+ name: (a, b) => a.name.localeCompare(b.name),
532
+ kind: (a, b) => a.kind.localeCompare(b.kind),
533
+ available: (a, b) => a.availableCents - b.availableCents,
534
+ };
535
+
536
+ // ============= GROUP 2 — CREDIT CARDS =============
537
+
538
+ interface CreditCardAccount extends AccountRecord {
539
+ name: string;
540
+ issuer: string;
541
+ mask: string;
542
+ balanceCents: number;
543
+ limitCents: number;
544
+ }
545
+
546
+ const CREDIT_CARDS: CreditCardAccount[] = [
547
+ {
548
+ id: 'card-1',
549
+ name: 'Corporate — Engineering',
550
+ issuer: 'Meridian Business Card',
551
+ mask: '••2041',
552
+ balanceCents: 4_182_300,
553
+ limitCents: 15_000_000,
554
+ trend: 0.00042,
555
+ },
556
+ {
557
+ id: 'card-2',
558
+ name: 'Corporate — Travel',
559
+ issuer: 'Meridian Business Card',
560
+ mask: '••6688',
561
+ balanceCents: 9_640_500,
562
+ limitCents: 12_000_000,
563
+ trend: 0.00071,
564
+ },
565
+ {
566
+ id: 'card-3',
567
+ name: 'Vendor payments',
568
+ issuer: 'Northgate Commercial',
569
+ mask: '••3319',
570
+ balanceCents: 1_205_000,
571
+ limitCents: 25_000_000,
572
+ trend: -0.00018,
573
+ },
574
+ ];
575
+
576
+ /**
577
+ * Bar and reading on one line, because they are one fact. ProgressBar's own
578
+ * `hasValueLabel` stacks the number above the track, which costs a second row
579
+ * in every card row and leaves the widest column on the page mostly empty; the
580
+ * component's guidance is to compose the reading alongside instead.
581
+ *
582
+ * Neutral, and neutral for all three. Colour-coding utilization turns a
583
+ * measurement into a verdict, and the thresholds that verdict needs are a
584
+ * policy this page does not have — 80% on a card kept deliberately near its
585
+ * limit is not the same event as 80% on one that is usually idle. Neutral over
586
+ * accent for the same reason one step further on: the accent is the page's
587
+ * emphasis colour, and there is nothing here to emphasise. The number is right
588
+ * beside the bar.
589
+ */
590
+ function UtilizationCell({card}: {card: CreditCardAccount}) {
591
+ const percent = Math.round((card.balanceCents / card.limitCents) * 100);
592
+ return (
593
+ <HStack gap={2} vAlign="center">
594
+ <StackItem size="fill">
595
+ <ProgressBar
596
+ label={`${card.name} utilization`}
597
+ isLabelHidden
598
+ value={percent}
599
+ variant="neutral"
600
+ />
601
+ </StackItem>
602
+ <Text hasTabularNumbers>{percent}%</Text>
603
+ </HStack>
604
+ );
605
+ }
606
+
607
+ const creditCardColumns: TableColumn<CreditCardAccount>[] = [
608
+ {
609
+ key: 'name',
610
+ sortable: true,
611
+ header: 'Card',
612
+ width: proportional(2),
613
+ renderCell: card => (
614
+ <VStack gap={0}>
615
+ <Text>{card.name}</Text>
616
+ <Text type="supporting">
617
+ {card.issuer} · {card.mask}
618
+ </Text>
619
+ </VStack>
620
+ ),
621
+ },
622
+ // Utilization sits where every other group puts its qualifier — bank's type,
623
+ // the processor's merchant id — so the money columns start at the same place
624
+ // in all four tables and the eye can run straight down the page.
625
+ {
626
+ key: 'utilization',
627
+ sortable: true,
628
+ header: 'Utilization',
629
+ width: pixel(150),
630
+ renderCell: card => <UtilizationCell card={card} />,
631
+ },
632
+ {
633
+ key: 'balance',
634
+ sortable: true,
635
+ header: 'Balance',
636
+ width: pixel(150),
637
+ align: 'end',
638
+ renderCell: card => <Figure>{money(card.balanceCents)}</Figure>,
639
+ },
640
+ {
641
+ key: 'limit',
642
+ sortable: true,
643
+ header: 'Limit',
644
+ width: pixel(150),
645
+ align: 'end',
646
+ renderCell: card => <Figure>{money(card.limitCents)}</Figure>,
647
+ },
648
+ {
649
+ key: 'change',
650
+ sortable: true,
651
+ header: 'Change',
652
+ width: pixel(110),
653
+ align: 'end',
654
+ // The only group whose Change column is read inversely: a balance that
655
+ // grew is a debt that grew.
656
+ renderCell: card => <ChangeCell id={card.id} isLiability />,
657
+ },
658
+ ];
659
+
660
+ const creditCardCompactColumns: TableColumn<CreditCardAccount>[] = [
661
+ creditCardColumns[0],
662
+ {
663
+ key: 'balance',
664
+ sortable: true,
665
+ header: 'Balance',
666
+ width: pixel(150),
667
+ align: 'end',
668
+ renderCell: card => (
669
+ <CompactValueCell
670
+ id={card.id}
671
+ amountCents={card.balanceCents}
672
+ isLiability
673
+ />
674
+ ),
675
+ },
676
+ ];
677
+
678
+ const creditCardComparators: Partial<
679
+ Record<string, TableSortComparator<CreditCardAccount>>
680
+ > = {
681
+ name: (a, b) => a.name.localeCompare(b.name),
682
+ // Utilization is a ratio, not a balance — sorting it by balance would put a
683
+ // maxed-out small card below a barely-touched large one.
684
+ utilization: (a, b) =>
685
+ a.balanceCents / a.limitCents - b.balanceCents / b.limitCents,
686
+ balance: (a, b) => a.balanceCents - b.balanceCents,
687
+ limit: (a, b) => a.limitCents - b.limitCents,
688
+ };
689
+
690
+ // ============= GROUP 3 — PAYMENT PROCESSORS =============
691
+
692
+ interface ProcessorAccount extends AccountRecord {
693
+ name: string;
694
+ merchantId: string;
695
+ pendingPayoutCents: number;
696
+ feesMtdCents: number;
697
+ }
698
+
699
+ const PROCESSORS: ProcessorAccount[] = [
700
+ {
701
+ id: 'proc-1',
702
+ name: 'Stripe',
703
+ merchantId: 'acct_1Qf82LmR',
704
+ pendingPayoutCents: 18_442_900,
705
+ feesMtdCents: 612_400,
706
+ trend: 0.00058,
707
+ },
708
+ {
709
+ id: 'proc-2',
710
+ name: 'PayPal Commerce',
711
+ merchantId: 'MRC-88214-XT',
712
+ pendingPayoutCents: 3_218_650,
713
+ feesMtdCents: 148_900,
714
+ trend: -0.00024,
715
+ },
716
+ {
717
+ id: 'proc-3',
718
+ name: 'Adyen',
719
+ merchantId: 'AD-NORTHWIND-01',
720
+ pendingPayoutCents: 7_905_100,
721
+ feesMtdCents: 233_050,
722
+ trend: 0.00031,
723
+ },
724
+ ];
725
+
726
+ const processorColumns: TableColumn<ProcessorAccount>[] = [
727
+ {
728
+ key: 'name',
729
+ sortable: true,
730
+ header: 'Processor',
731
+ width: proportional(2),
732
+ renderCell: processor => (
733
+ <VStack gap={0}>
734
+ <Text>{processor.name}</Text>
735
+ <Text type="supporting">{processor.merchantId}</Text>
736
+ </VStack>
737
+ ),
738
+ },
739
+ {
740
+ key: 'pendingPayout',
741
+ sortable: true,
742
+ header: 'Pending payout',
743
+ width: pixel(150),
744
+ align: 'end',
745
+ renderCell: processor => (
746
+ <Figure>{money(processor.pendingPayoutCents)}</Figure>
747
+ ),
748
+ },
749
+ {
750
+ key: 'feesMtd',
751
+ sortable: true,
752
+ header: 'Fees (MTD)',
753
+ width: pixel(150),
754
+ align: 'end',
755
+ renderCell: processor => <Figure>{money(processor.feesMtdCents)}</Figure>,
756
+ },
757
+ {
758
+ key: 'change',
759
+ sortable: true,
760
+ header: 'Change',
761
+ width: pixel(110),
762
+ align: 'end',
763
+ renderCell: processor => <ChangeCell id={processor.id} />,
764
+ },
765
+ ];
766
+
767
+ const processorCompactColumns: TableColumn<ProcessorAccount>[] = [
768
+ processorColumns[0],
769
+ {
770
+ key: 'pendingPayout',
771
+ sortable: true,
772
+ header: 'Pending payout',
773
+ width: pixel(150),
774
+ align: 'end',
775
+ renderCell: processor => (
776
+ <CompactValueCell
777
+ id={processor.id}
778
+ amountCents={processor.pendingPayoutCents}
779
+ />
780
+ ),
781
+ },
782
+ ];
783
+
784
+ const processorComparators: Partial<
785
+ Record<string, TableSortComparator<ProcessorAccount>>
786
+ > = {
787
+ name: (a, b) => a.name.localeCompare(b.name),
788
+ pendingPayout: (a, b) => a.pendingPayoutCents - b.pendingPayoutCents,
789
+ feesMtd: (a, b) => a.feesMtdCents - b.feesMtdCents,
790
+ };
791
+
792
+ // ============= GROUP 4 — INVESTMENT ACCOUNTS =============
793
+
794
+ interface InvestmentAccount extends AccountRecord {
795
+ name: string;
796
+ custodian: string;
797
+ marketValueCents: number;
798
+ costBasisCents: number;
799
+ }
800
+
801
+ const INVESTMENTS: InvestmentAccount[] = [
802
+ {
803
+ id: 'inv-1',
804
+ name: 'Short-duration treasuries',
805
+ custodian: 'Northgate Asset Management',
806
+ marketValueCents: 245_180_000,
807
+ costBasisCents: 240_000_000,
808
+ trend: 0.00012,
809
+ },
810
+ {
811
+ id: 'inv-2',
812
+ name: 'Corporate bond ladder',
813
+ custodian: 'Northgate Asset Management',
814
+ marketValueCents: 98_420_000,
815
+ costBasisCents: 100_000_000,
816
+ trend: -0.00006,
817
+ },
818
+ {
819
+ id: 'inv-3',
820
+ name: 'Money market fund',
821
+ custodian: 'Harborline Capital',
822
+ marketValueCents: 61_050_000,
823
+ costBasisCents: 61_000_000,
824
+ trend: 0.00003,
825
+ },
826
+ ];
827
+
828
+ const investmentColumns: TableColumn<InvestmentAccount>[] = [
829
+ {
830
+ key: 'name',
831
+ sortable: true,
832
+ header: 'Account',
833
+ width: proportional(2),
834
+ renderCell: account => (
835
+ <VStack gap={0}>
836
+ <Text>{account.name}</Text>
837
+ <Text type="supporting">{account.custodian}</Text>
838
+ </VStack>
839
+ ),
840
+ },
841
+ {
842
+ key: 'marketValue',
843
+ sortable: true,
844
+ header: 'Market value',
845
+ width: pixel(150),
846
+ align: 'end',
847
+ renderCell: account => <Figure>{money(account.marketValueCents)}</Figure>,
848
+ },
849
+ {
850
+ key: 'costBasis',
851
+ sortable: true,
852
+ header: 'Cost basis',
853
+ width: pixel(150),
854
+ align: 'end',
855
+ renderCell: account => <Figure>{money(account.costBasisCents)}</Figure>,
856
+ },
857
+ {
858
+ key: 'change',
859
+ sortable: true,
860
+ header: 'Change',
861
+ width: pixel(110),
862
+ align: 'end',
863
+ renderCell: account => <ChangeCell id={account.id} />,
864
+ },
865
+ ];
866
+
867
+ const investmentCompactColumns: TableColumn<InvestmentAccount>[] = [
868
+ investmentColumns[0],
869
+ {
870
+ key: 'marketValue',
871
+ sortable: true,
872
+ header: 'Market value',
873
+ width: pixel(150),
874
+ align: 'end',
875
+ renderCell: account => (
876
+ <CompactValueCell
877
+ id={account.id}
878
+ amountCents={account.marketValueCents}
879
+ />
880
+ ),
881
+ },
882
+ ];
883
+
884
+ const investmentComparators: Partial<
885
+ Record<string, TableSortComparator<InvestmentAccount>>
886
+ > = {
887
+ name: (a, b) => a.name.localeCompare(b.name),
888
+ marketValue: (a, b) => a.marketValueCents - b.marketValueCents,
889
+ costBasis: (a, b) => a.costBasisCents - b.costBasisCents,
890
+ };
891
+
892
+ /** Every row id on the page, so a page-level control can address the details
893
+ * and not just the cards holding them. */
894
+ const ALL_ROW_IDS = [
895
+ ...BANK_ACCOUNTS,
896
+ ...CREDIT_CARDS,
897
+ ...PROCESSORS,
898
+ ...INVESTMENTS,
899
+ ].map(record => record.id);
900
+
901
+ // ============= DERIVED HISTORY =============
902
+
903
+ /**
904
+ * A year of daily values per account. Built once at module scope: the numbers
905
+ * are a pure function of the pinned data, so recomputing them per render would
906
+ * be work with no possible different answer.
907
+ *
908
+ * The volatilities differ by group because the accounts do. A payout balance
909
+ * that empties on a schedule is genuinely choppier than a bond ladder, and
910
+ * giving them the same noise makes every chart on the page the same chart.
911
+ */
912
+ const HISTORY: Record<string, number[]> = Object.fromEntries([
913
+ ...historyFor(BANK_ACCOUNTS, account => account.availableCents, 0.014),
914
+ ...historyFor(CREDIT_CARDS, card => card.balanceCents, 0.016),
915
+ ...historyFor(PROCESSORS, processor => processor.pendingPayoutCents, 0.04),
916
+ ...historyFor(INVESTMENTS, account => account.marketValueCents, 0.008),
917
+ ]);
918
+
919
+ // ============= DETAIL PANEL =============
920
+
921
+ /**
922
+ * The account's shape over the selected window, given the width the metadata
923
+ * beside it does not need. At sparkline size the line was a gesture; at this
924
+ * size the dates underneath mean something and a reading of the value is worth
925
+ * following, so it carries an axis and a tooltip.
926
+ *
927
+ * `syncId` is what links it to its siblings: every chart in a group shares
928
+ * one, so pointing at a date in one open row draws the cursor at that date in
929
+ * every other open row of the same category. Recharts syncs on index, which is
930
+ * sound here only because every account in a group is sampled over the same
931
+ * window — same length, same days, same order.
932
+ */
933
+ const CHART_HEIGHT = 132;
934
+
935
+ /**
936
+ * How long the row this content sits in takes to open.
937
+ *
938
+ * The animating element is an ancestor, so its `transitionend` never reaches
939
+ * us — bubbling runs child to parent. Walking up to read the duration off
940
+ * whichever ancestor actually carries the transition costs one pass and keeps
941
+ * this honest: reduced motion zeroes the token and a theme override changes
942
+ * it, and both are picked up without knowing a class name.
943
+ */
944
+ function openDurationMs(from: HTMLElement | null): number {
945
+ for (let el = from; el; el = el.parentElement) {
946
+ const style = getComputedStyle(el);
947
+ if (style.transitionProperty.includes('grid-template-rows')) {
948
+ return parseFloat(style.transitionDuration) * 1000;
949
+ }
950
+ }
951
+ return 0;
952
+ }
953
+
954
+ /**
955
+ * Recharts costs around 400ms of main thread to mount, and spending it while
956
+ * the row is still growing starves the open: measured 9-12 frames across a
957
+ * transition with budget for roughly 40. So hold a skeleton of the chart's
958
+ * exact height until the row has finished opening, then swap. The row animates
959
+ * over a cheap box, and the chart mounts into a panel that is already still.
960
+ * The chart arrives at the same moment either way — only the jank moves off
961
+ * the animation.
962
+ */
963
+ function useSettledAfterOpen(): [
964
+ React.RefObject<HTMLDivElement | null>,
965
+ boolean,
966
+ ] {
967
+ const ref = useRef<HTMLDivElement>(null);
968
+ const [isSettled, setIsSettled] = useState(false);
969
+
970
+ useEffect(() => {
971
+ const duration = openDurationMs(ref.current);
972
+ // Nothing to protect when there is no animation.
973
+ if (duration === 0) {
974
+ setIsSettled(true);
975
+ return;
976
+ }
977
+ const timer = setTimeout(() => setIsSettled(true), duration);
978
+ return () => clearTimeout(timer);
979
+ }, []);
980
+
981
+ return [ref, isSettled];
982
+ }
983
+
984
+ function DetailChart({
985
+ id,
986
+ group,
987
+ isLiability,
988
+ }: {
989
+ id: string;
990
+ group: GroupId;
991
+ isLiability?: boolean;
992
+ }) {
993
+ const [hostRef, isSettled] = useSettledAfterOpen();
994
+ const range = useRange();
995
+ const points = windowOf(id, range);
996
+ const delta = points[points.length - 1] - points[0];
997
+ const isGood = isLiability ? delta <= 0 : delta >= 0;
998
+ const color = isGood ? UP_COLOR : DOWN_COLOR;
999
+ const data = points.map((value, day) => ({
1000
+ day,
1001
+ label: dayLabel(points.length - 1 - day),
1002
+ value: value / 100,
1003
+ }));
1004
+ const ticks = axisTicks(data.length);
1005
+ // One gradient per account, because two charts sharing a fill id take
1006
+ // whichever definition the DOM happens to hold — and open two rows of
1007
+ // opposite sign and that is a green area under a red line.
1008
+ const fillId = `detail-fill-${id}`;
1009
+
1010
+ return (
1011
+ <VStack gap={0} ref={hostRef}>
1012
+ {!isSettled ? (
1013
+ <Skeleton width="100%" height={CHART_HEIGHT} radius={2} />
1014
+ ) : (
1015
+ <ResponsiveContainer width="100%" height={CHART_HEIGHT}>
1016
+ <AreaChart data={data} syncId={group} margin={{top: 4, right: 4}}>
1017
+ <defs>
1018
+ <linearGradient id={fillId} x1="0" y1="0" x2="0" y2="1">
1019
+ <stop offset="0%" stopColor={color} stopOpacity={0.2} />
1020
+ <stop offset="100%" stopColor={color} stopOpacity={0} />
1021
+ </linearGradient>
1022
+ </defs>
1023
+ {/* No CartesianGrid and no axis line. A rule at every Y tick reads
1024
+ as a table ruled behind a table, and an axis line at the bottom
1025
+ marks the frame rather than anything in the data. The one rule
1026
+ worth drawing is where the window opened: everything above it is
1027
+ the gain the Change column reports, everything below the loss. */}
1028
+ <XAxis
1029
+ dataKey="day"
1030
+ type="number"
1031
+ domain={[0, data.length - 1]}
1032
+ ticks={ticks}
1033
+ tickFormatter={(day: number) => data[day]?.label ?? ''}
1034
+ tick={AXIS_TICK}
1035
+ axisLine={false}
1036
+ tickLine={false}
1037
+ interval="preserveStartEnd"
1038
+ />
1039
+ <ReferenceLine
1040
+ y={data[0].value}
1041
+ stroke={GRID_COLOR}
1042
+ strokeDasharray="3 3"
1043
+ />
1044
+ <YAxis hide domain={['dataMin', 'dataMax']} />
1045
+ <Tooltip content={<DetailTooltip color={color} />} />
1046
+ <Area
1047
+ type="linear"
1048
+ dataKey="value"
1049
+ stroke={color}
1050
+ strokeWidth={1.5}
1051
+ fill={`url(#${fillId})`}
1052
+ dot={false}
1053
+ activeDot={{r: 3, strokeWidth: 0}}
1054
+ isAnimationActive={false}
1055
+ />
1056
+ </AreaChart>
1057
+ </ResponsiveContainer>
1058
+ )}
1059
+ </VStack>
1060
+ );
1061
+ }
1062
+
1063
+ function DetailTooltip({
1064
+ active,
1065
+ payload,
1066
+ color,
1067
+ }: {
1068
+ active?: boolean;
1069
+ payload?: Array<{payload: {label: string; value: number}}>;
1070
+ color?: string;
1071
+ }) {
1072
+ if (!active || !payload?.length) {
1073
+ return null;
1074
+ }
1075
+ const point = payload[0].payload;
1076
+ return (
1077
+ <Card padding={3}>
1078
+ <VStack gap={1}>
1079
+ <Text type="supporting" color="secondary">
1080
+ {point.label}
1081
+ </Text>
1082
+ <HStack gap={2} vAlign="center">
1083
+ <HStack xstyle={styles.swatch(color ?? UP_COLOR)} />
1084
+ <Text weight="semibold" hasTabularNumbers>
1085
+ {wholeCurrency.format(point.value)}
1086
+ </Text>
1087
+ </HStack>
1088
+ </VStack>
1089
+ </Card>
1090
+ );
1091
+ }
1092
+
1093
+ // ============= GROUP SHELL =============
1094
+
1095
+ const GROUP_IDS = ['bank', 'cards', 'processors', 'investments'] as const;
1096
+ type GroupId = (typeof GROUP_IDS)[number];
1097
+
1098
+ /**
1099
+ * Square side of the category tile in the group header. 24px is not a look, it
1100
+ * is an alignment: the tile plus the 8px gap after it is exactly the inset the
1101
+ * cells below give their own text, so the group name starts on the same x as
1102
+ * the first column's header and rows. It is also the size of the row-expansion
1103
+ * chevron buttons, and it sits at their x — so the group's disclosure and its
1104
+ * rows' disclosures form one column down the left edge of the card.
1105
+ */
1106
+ const TILE_SIZE = 24;
1107
+
1108
+ const styles = stylex.create({
1109
+ // The page is a wash so the group cards read as surfaces sitting on it
1110
+ // rather than as outlines drawn on the same sheet. Body is the right token
1111
+ // for that: a theme that wants its cards to contrast sets it away from
1112
+ // --color-background-card, and one that wants them flush sets it equal and
1113
+ // separates them by border instead. Either way the page follows the theme.
1114
+ wash: {
1115
+ backgroundColor: colorVars['--color-background-body'],
1116
+ },
1117
+ delta: (color: string) => ({color}),
1118
+ swatch: (color: string) => ({
1119
+ width: 8,
1120
+ height: 8,
1121
+ borderRadius: '50%',
1122
+ backgroundColor: color,
1123
+ flexShrink: 0,
1124
+ }),
1125
+ categoryTile: {
1126
+ display: 'grid',
1127
+ placeItems: 'center',
1128
+ width: TILE_SIZE,
1129
+ height: TILE_SIZE,
1130
+ flexShrink: 0,
1131
+ borderRadius: radiusVars['--radius-inner'],
1132
+ backgroundColor: colorVars['--color-background-muted'],
1133
+ },
1134
+ });
1135
+
1136
+ function AccountGroup({
1137
+ icon,
1138
+ title,
1139
+ count,
1140
+ summaryLabel,
1141
+ summaryValue,
1142
+ isOpen,
1143
+ onOpenChange,
1144
+ children,
1145
+ }: {
1146
+ icon: React.ComponentType<React.SVGProps<SVGSVGElement>>;
1147
+ title: string;
1148
+ count: number;
1149
+ summaryLabel: string;
1150
+ summaryValue: string;
1151
+ isOpen: boolean;
1152
+ onOpenChange: (open: boolean) => void;
1153
+ children: React.ReactNode;
1154
+ }) {
1155
+ return (
1156
+ // 8px on the Card and nothing on the Collapsible: one content line for the
1157
+ // header and the table both, and the table's rows then inset themselves by
1158
+ // their own cell padding on top of it.
1159
+ <Card padding={2}>
1160
+ <Collapsible
1161
+ isOpen={isOpen}
1162
+ onOpenChange={onOpenChange}
1163
+ trigger={
1164
+ // paddingBlock, because the trigger has none of its own: its height
1165
+ // is exactly the 24px tile, so the only space above the group name
1166
+ // was the Card's 8px. The column header below it is a table cell and
1167
+ // brings its own inset, which is what made the row read as pinned to
1168
+ // the top edge even though the two gaps measured the same.
1169
+ <HStack
1170
+ gap={2}
1171
+ vAlign="center"
1172
+ hAlign="between"
1173
+ paddingBlock={2}
1174
+ paddingInline={2}>
1175
+ <HStack gap={2} vAlign="center">
1176
+ <HStack xstyle={styles.categoryTile}>
1177
+ <Icon icon={icon} size="sm" />
1178
+ </HStack>
1179
+ <Text weight="semibold">{title}</Text>
1180
+ <Badge variant="neutral" label={String(count)} />
1181
+ </HStack>
1182
+ <HStack gap={2} vAlign="center">
1183
+ {/* Body rather than supporting: it is the label on the one
1184
+ figure a collapsed group still shows, so it has to survive
1185
+ being read at a glance from across the page. */}
1186
+ <Text color="secondary">{summaryLabel}</Text>
1187
+ <Text weight="semibold" hasTabularNumbers>
1188
+ {summaryValue}
1189
+ </Text>
1190
+ </HStack>
1191
+ </HStack>
1192
+ }>
1193
+ {/* The trigger is a row of text and the table opens with a row of
1194
+ text, so without this they read as one block with a hairline in
1195
+ it. 12px is enough to say the header is a header. */}
1196
+ <VStack paddingBlockStart={3}>{children}</VStack>
1197
+ </Collapsible>
1198
+ </Card>
1199
+ );
1200
+ }
1201
+
1202
+ /**
1203
+ * The four tables differ in their columns and in nothing else, so the plugin
1204
+ * wiring lives here once rather than four times.
1205
+ *
1206
+ * The built-in expansion plugin owns the disclosure chevron and its muted
1207
+ * detail surface, so every table exposes the same interaction and panel
1208
+ * treatment without custom row event handling.
1209
+ */
1210
+ function GroupTable<T extends AccountRecord>({
1211
+ data,
1212
+ columns,
1213
+ comparators,
1214
+ expandedRows,
1215
+ onToggleRow,
1216
+ renderExpanded,
1217
+ }: {
1218
+ data: T[];
1219
+ columns: TableColumn<T>[];
1220
+ comparators: Partial<Record<string, TableSortComparator<T>>>;
1221
+ expandedRows: Set<string>;
1222
+ onToggleRow: (key: string) => void;
1223
+ renderExpanded: (item: T) => React.ReactNode;
1224
+ }) {
1225
+ const range = useRange();
1226
+
1227
+ // Change is the one column whose value is not in the row — it is derived
1228
+ // from the page's range. The sort memo keys on data identity, so a range
1229
+ // switch has to hand it a different array or the rows would keep the order
1230
+ // computed from the old window while showing figures from the new one.
1231
+ const rows = useMemo(() => data.slice(), [data, range]);
1232
+
1233
+ const sortComparators = useMemo(
1234
+ () => ({
1235
+ ...comparators,
1236
+ change: (a: T, b: T) =>
1237
+ changePercentOf(a.id, range) - changePercentOf(b.id, range),
1238
+ }),
1239
+ [comparators, range],
1240
+ );
1241
+
1242
+ const {sortedData, sortConfig} = useTableSortableState<T>({
1243
+ data: rows,
1244
+ comparators: sortComparators,
1245
+ });
1246
+ const sort = useTableSortable<T>(sortConfig);
1247
+
1248
+ const expansion = useTableRowExpansion<T>({
1249
+ expandedKeys: expandedRows,
1250
+ onToggle: onToggleRow,
1251
+ getRowKey: item => item.id,
1252
+ renderExpanded,
1253
+ });
1254
+
1255
+ return (
1256
+ <Table
1257
+ data={sortedData}
1258
+ columns={columns}
1259
+ idKey="id"
1260
+ density="compact"
1261
+ dividers="rows"
1262
+ plugins={{sort, expansion}}
1263
+ />
1264
+ );
1265
+ }
1266
+
1267
+ // ============= PAGE =============
1268
+
1269
+ export default function ConnectedAccountsTemplate() {
1270
+ const [openGroups, setOpenGroups] = useState<Set<GroupId>>(
1271
+ () => new Set(GROUP_IDS),
1272
+ );
1273
+
1274
+ // Lifted out of the chart because it is not the chart's setting — it is the
1275
+ // page's. Year to date is the default because it is the window accounts are
1276
+ // actually reasoned about in, and it is long enough that a monthly cycle
1277
+ // shows up several times rather than once or twice.
1278
+ const [range, setRange] = useState<RangeId>('YTD');
1279
+
1280
+ // One Set for all four tables, not one per group. Row ids are unique across
1281
+ // the page, so a single Set is unambiguous, and it is what a "collapse every
1282
+ // open detail" control or a persisted view would need to read.
1283
+ const [expandedRows, setExpandedRows] = useState<Set<string>>(
1284
+ () => new Set(),
1285
+ );
1286
+
1287
+ const toggleRow = (key: string) => {
1288
+ setExpandedRows(previous => {
1289
+ const next = new Set(previous);
1290
+ if (next.has(key)) {
1291
+ next.delete(key);
1292
+ } else {
1293
+ next.add(key);
1294
+ }
1295
+ return next;
1296
+ });
1297
+ };
1298
+
1299
+ const toggleGroup = (id: GroupId) => (open: boolean) => {
1300
+ setOpenGroups(previous => {
1301
+ const next = new Set(previous);
1302
+ if (open) {
1303
+ next.add(id);
1304
+ } else {
1305
+ next.delete(id);
1306
+ }
1307
+ return next;
1308
+ });
1309
+ };
1310
+
1311
+ const totals = useMemo(() => {
1312
+ const banks = sum(BANK_ACCOUNTS, account => account.availableCents);
1313
+ const cards = sum(CREDIT_CARDS, card => card.balanceCents);
1314
+ const pending = sum(PROCESSORS, p => p.pendingPayoutCents);
1315
+ const investments = sum(INVESTMENTS, i => i.marketValueCents);
1316
+ return {
1317
+ banks,
1318
+ cards,
1319
+ pending,
1320
+ investments,
1321
+ // Outstanding card balances are a liability, so they come off the top.
1322
+ net: banks + pending + investments - cards,
1323
+ };
1324
+ }, []);
1325
+
1326
+ const [contentRef, contentWidth] = useSurfaceWidth();
1327
+ // Zero is the width before the first measurement, not a narrow box, and
1328
+ // treating it as narrow would flash the compact tables on every mount.
1329
+ const isCompact = contentWidth > 0 && contentWidth < COMPACT_BELOW_PX;
1330
+
1331
+ // "All open" has to mean the details too. A control labelled Expand all that
1332
+ // opens four cards and leaves thirteen collapsed rows inside them has not
1333
+ // expanded all, and its next click would read as Collapse all while most of
1334
+ // the page is still shut.
1335
+ const isEverythingOpen =
1336
+ openGroups.size === GROUP_IDS.length &&
1337
+ expandedRows.size === ALL_ROW_IDS.length;
1338
+
1339
+ const toggleEverything = () => {
1340
+ const open = !isEverythingOpen;
1341
+ setOpenGroups(open ? new Set(GROUP_IDS) : new Set());
1342
+ setExpandedRows(open ? new Set(ALL_ROW_IDS) : new Set());
1343
+ };
1344
+
1345
+ return (
1346
+ <RangeContext.Provider value={range}>
1347
+ <Layout
1348
+ height="auto"
1349
+ contentWidth={1200}
1350
+ xstyle={styles.wash}
1351
+ header={
1352
+ <LayoutHeader padding={4}>
1353
+ <HStack gap={3} vAlign="center" wrap="wrap">
1354
+ <StackItem size="fill">
1355
+ <VStack gap={0.5}>
1356
+ <Heading level={1}>Connected accounts</Heading>
1357
+ <Text type="supporting">
1358
+ Net position {money(totals.net)} across 13 accounts
1359
+ </Text>
1360
+ </VStack>
1361
+ </StackItem>
1362
+ <Button
1363
+ label={isEverythingOpen ? 'Collapse all' : 'Expand all'}
1364
+ variant="ghost"
1365
+ onClick={toggleEverything}
1366
+ />
1367
+ {/* The range belongs to the page, not to any one table, so it
1368
+ sits with the page title rather than inside a card. */}
1369
+ <SegmentedControl
1370
+ value={range}
1371
+ onChange={value => setRange(value as RangeId)}
1372
+ label="Time range">
1373
+ {RANGE_IDS.map(id => (
1374
+ <SegmentedControlItem key={id} value={id} label={id} />
1375
+ ))}
1376
+ </SegmentedControl>
1377
+ </HStack>
1378
+ </LayoutHeader>
1379
+ }
1380
+ content={
1381
+ <LayoutContent padding={4}>
1382
+ <VStack gap={4} ref={contentRef}>
1383
+ <AccountGroup
1384
+ icon={BuildingLibraryIcon}
1385
+ title="Bank accounts"
1386
+ count={BANK_ACCOUNTS.length}
1387
+ summaryLabel="Available"
1388
+ summaryValue={money(totals.banks)}
1389
+ isOpen={openGroups.has('bank')}
1390
+ onOpenChange={toggleGroup('bank')}>
1391
+ <GroupTable<BankAccount>
1392
+ data={BANK_ACCOUNTS}
1393
+ columns={isCompact ? bankCompactColumns : bankColumns}
1394
+ comparators={bankComparators}
1395
+ expandedRows={expandedRows}
1396
+ onToggleRow={toggleRow}
1397
+ renderExpanded={account => (
1398
+ <DetailChart id={account.id} group="bank" />
1399
+ )}
1400
+ />
1401
+ </AccountGroup>
1402
+
1403
+ <AccountGroup
1404
+ icon={CreditCardIcon}
1405
+ title="Credit cards"
1406
+ count={CREDIT_CARDS.length}
1407
+ summaryLabel="Outstanding"
1408
+ summaryValue={money(totals.cards)}
1409
+ isOpen={openGroups.has('cards')}
1410
+ onOpenChange={toggleGroup('cards')}>
1411
+ <GroupTable<CreditCardAccount>
1412
+ data={CREDIT_CARDS}
1413
+ columns={
1414
+ isCompact ? creditCardCompactColumns : creditCardColumns
1415
+ }
1416
+ comparators={creditCardComparators}
1417
+ expandedRows={expandedRows}
1418
+ onToggleRow={toggleRow}
1419
+ renderExpanded={card => (
1420
+ <DetailChart id={card.id} group="cards" isLiability />
1421
+ )}
1422
+ />
1423
+ </AccountGroup>
1424
+
1425
+ <AccountGroup
1426
+ icon={ArrowsRightLeftIcon}
1427
+ title="Payment processors"
1428
+ count={PROCESSORS.length}
1429
+ summaryLabel="Pending payout"
1430
+ summaryValue={money(totals.pending)}
1431
+ isOpen={openGroups.has('processors')}
1432
+ onOpenChange={toggleGroup('processors')}>
1433
+ <GroupTable<ProcessorAccount>
1434
+ data={PROCESSORS}
1435
+ columns={
1436
+ isCompact ? processorCompactColumns : processorColumns
1437
+ }
1438
+ comparators={processorComparators}
1439
+ expandedRows={expandedRows}
1440
+ onToggleRow={toggleRow}
1441
+ renderExpanded={processor => (
1442
+ <DetailChart id={processor.id} group="processors" />
1443
+ )}
1444
+ />
1445
+ </AccountGroup>
1446
+
1447
+ <AccountGroup
1448
+ icon={PresentationChartLineIcon}
1449
+ title="Investment accounts"
1450
+ count={INVESTMENTS.length}
1451
+ summaryLabel="Market value"
1452
+ summaryValue={money(totals.investments)}
1453
+ isOpen={openGroups.has('investments')}
1454
+ onOpenChange={toggleGroup('investments')}>
1455
+ <GroupTable<InvestmentAccount>
1456
+ data={INVESTMENTS}
1457
+ columns={
1458
+ isCompact ? investmentCompactColumns : investmentColumns
1459
+ }
1460
+ comparators={investmentComparators}
1461
+ expandedRows={expandedRows}
1462
+ onToggleRow={toggleRow}
1463
+ renderExpanded={account => (
1464
+ <DetailChart id={account.id} group="investments" />
1465
+ )}
1466
+ />
1467
+ </AccountGroup>
1468
+ </VStack>
1469
+ </LayoutContent>
1470
+ }
1471
+ />
1472
+ </RangeContext.Provider>
1473
+ );
1474
+ }