@shware/workflow-ui 0.0.0-stage → 0.0.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 (363) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +180 -2
  3. package/dist/assets/iphone-17-pro-DzaacWSl.png +0 -0
  4. package/dist/assets/pixel-10-pro-back-7MDj1_lz.webp +0 -0
  5. package/dist/assets/pixel-10-pro-mask-Bi1deQ9Y.webp +0 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +673 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/config.d.mts +247 -0
  10. package/dist/config.d.mts.map +1 -0
  11. package/dist/config.mjs +27 -0
  12. package/dist/config.mjs.map +1 -0
  13. package/dist/index.d.mts +451 -0
  14. package/dist/index.d.mts.map +1 -0
  15. package/dist/index.mjs +2722 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/dist/postgres.d.mts +34 -0
  18. package/dist/postgres.d.mts.map +1 -0
  19. package/dist/postgres.mjs +313 -0
  20. package/dist/postgres.mjs.map +1 -0
  21. package/package.json +93 -3
  22. package/src/app/assets/devices/iphone-17-pro.png +0 -0
  23. package/src/app/assets/devices/pixel-10-pro-back.webp +0 -0
  24. package/src/app/assets/devices/pixel-10-pro-mask.webp +0 -0
  25. package/src/app/assets/flags/AC.svg +1 -0
  26. package/src/app/assets/flags/AD.svg +1 -0
  27. package/src/app/assets/flags/AE.svg +1 -0
  28. package/src/app/assets/flags/AF.svg +1 -0
  29. package/src/app/assets/flags/AG.svg +1 -0
  30. package/src/app/assets/flags/AI.svg +1 -0
  31. package/src/app/assets/flags/AL.svg +1 -0
  32. package/src/app/assets/flags/AM.svg +1 -0
  33. package/src/app/assets/flags/AO.svg +1 -0
  34. package/src/app/assets/flags/AQ.svg +1 -0
  35. package/src/app/assets/flags/AR.svg +1 -0
  36. package/src/app/assets/flags/AS.svg +1 -0
  37. package/src/app/assets/flags/AT.svg +1 -0
  38. package/src/app/assets/flags/AU.svg +1 -0
  39. package/src/app/assets/flags/AW.svg +1 -0
  40. package/src/app/assets/flags/AX.svg +1 -0
  41. package/src/app/assets/flags/AZ.svg +1 -0
  42. package/src/app/assets/flags/BA.svg +1 -0
  43. package/src/app/assets/flags/BB.svg +1 -0
  44. package/src/app/assets/flags/BD.svg +1 -0
  45. package/src/app/assets/flags/BE.svg +1 -0
  46. package/src/app/assets/flags/BF.svg +1 -0
  47. package/src/app/assets/flags/BG.svg +1 -0
  48. package/src/app/assets/flags/BH.svg +1 -0
  49. package/src/app/assets/flags/BI.svg +1 -0
  50. package/src/app/assets/flags/BJ.svg +1 -0
  51. package/src/app/assets/flags/BL.svg +1 -0
  52. package/src/app/assets/flags/BM.svg +1 -0
  53. package/src/app/assets/flags/BN.svg +1 -0
  54. package/src/app/assets/flags/BO.svg +1 -0
  55. package/src/app/assets/flags/BQ-BO.svg +1 -0
  56. package/src/app/assets/flags/BQ-SA.svg +1 -0
  57. package/src/app/assets/flags/BQ-SE.svg +1 -0
  58. package/src/app/assets/flags/BQ.svg +1 -0
  59. package/src/app/assets/flags/BR.svg +1 -0
  60. package/src/app/assets/flags/BS.svg +1 -0
  61. package/src/app/assets/flags/BT.svg +1 -0
  62. package/src/app/assets/flags/BV.svg +1 -0
  63. package/src/app/assets/flags/BW.svg +1 -0
  64. package/src/app/assets/flags/BY.svg +1 -0
  65. package/src/app/assets/flags/BZ.svg +1 -0
  66. package/src/app/assets/flags/CA.svg +1 -0
  67. package/src/app/assets/flags/CC.svg +1 -0
  68. package/src/app/assets/flags/CD.svg +1 -0
  69. package/src/app/assets/flags/CF.svg +1 -0
  70. package/src/app/assets/flags/CG.svg +1 -0
  71. package/src/app/assets/flags/CH.svg +1 -0
  72. package/src/app/assets/flags/CI.svg +1 -0
  73. package/src/app/assets/flags/CK.svg +1 -0
  74. package/src/app/assets/flags/CL.svg +1 -0
  75. package/src/app/assets/flags/CM.svg +1 -0
  76. package/src/app/assets/flags/CN.svg +1 -0
  77. package/src/app/assets/flags/CO.svg +1 -0
  78. package/src/app/assets/flags/CR.svg +1 -0
  79. package/src/app/assets/flags/CU.svg +1 -0
  80. package/src/app/assets/flags/CV.svg +1 -0
  81. package/src/app/assets/flags/CW.svg +1 -0
  82. package/src/app/assets/flags/CX.svg +1 -0
  83. package/src/app/assets/flags/CY.svg +1 -0
  84. package/src/app/assets/flags/CZ.svg +1 -0
  85. package/src/app/assets/flags/DE.svg +1 -0
  86. package/src/app/assets/flags/DJ.svg +1 -0
  87. package/src/app/assets/flags/DK.svg +1 -0
  88. package/src/app/assets/flags/DM.svg +1 -0
  89. package/src/app/assets/flags/DO.svg +1 -0
  90. package/src/app/assets/flags/DZ.svg +1 -0
  91. package/src/app/assets/flags/EC.svg +1 -0
  92. package/src/app/assets/flags/EE.svg +1 -0
  93. package/src/app/assets/flags/EG.svg +1 -0
  94. package/src/app/assets/flags/EH.svg +1 -0
  95. package/src/app/assets/flags/ER.svg +1 -0
  96. package/src/app/assets/flags/ES-CT.svg +1 -0
  97. package/src/app/assets/flags/ES.svg +1 -0
  98. package/src/app/assets/flags/ET.svg +1 -0
  99. package/src/app/assets/flags/EU.svg +1 -0
  100. package/src/app/assets/flags/FI.svg +1 -0
  101. package/src/app/assets/flags/FJ.svg +1 -0
  102. package/src/app/assets/flags/FK.svg +1 -0
  103. package/src/app/assets/flags/FM.svg +1 -0
  104. package/src/app/assets/flags/FO.svg +1 -0
  105. package/src/app/assets/flags/FR.svg +1 -0
  106. package/src/app/assets/flags/GA.svg +1 -0
  107. package/src/app/assets/flags/GB-ENG.svg +1 -0
  108. package/src/app/assets/flags/GB-NIR.svg +1 -0
  109. package/src/app/assets/flags/GB-SCT.svg +1 -0
  110. package/src/app/assets/flags/GB-WLS.svg +1 -0
  111. package/src/app/assets/flags/GB.svg +1 -0
  112. package/src/app/assets/flags/GD.svg +1 -0
  113. package/src/app/assets/flags/GE.svg +1 -0
  114. package/src/app/assets/flags/GF.svg +1 -0
  115. package/src/app/assets/flags/GG.svg +1 -0
  116. package/src/app/assets/flags/GH.svg +1 -0
  117. package/src/app/assets/flags/GI.svg +1 -0
  118. package/src/app/assets/flags/GL.svg +1 -0
  119. package/src/app/assets/flags/GM.svg +1 -0
  120. package/src/app/assets/flags/GN.svg +1 -0
  121. package/src/app/assets/flags/GP.svg +1 -0
  122. package/src/app/assets/flags/GQ.svg +1 -0
  123. package/src/app/assets/flags/GR.svg +1 -0
  124. package/src/app/assets/flags/GS.svg +1 -0
  125. package/src/app/assets/flags/GT.svg +1 -0
  126. package/src/app/assets/flags/GU.svg +1 -0
  127. package/src/app/assets/flags/GW.svg +1 -0
  128. package/src/app/assets/flags/GY.svg +1 -0
  129. package/src/app/assets/flags/HK.svg +1 -0
  130. package/src/app/assets/flags/HM.svg +1 -0
  131. package/src/app/assets/flags/HN.svg +1 -0
  132. package/src/app/assets/flags/HR.svg +1 -0
  133. package/src/app/assets/flags/HT.svg +1 -0
  134. package/src/app/assets/flags/HU.svg +1 -0
  135. package/src/app/assets/flags/IC.svg +1 -0
  136. package/src/app/assets/flags/ID.svg +1 -0
  137. package/src/app/assets/flags/IE.svg +1 -0
  138. package/src/app/assets/flags/IL.svg +1 -0
  139. package/src/app/assets/flags/IM.svg +1 -0
  140. package/src/app/assets/flags/IN.svg +1 -0
  141. package/src/app/assets/flags/IO.svg +1 -0
  142. package/src/app/assets/flags/IQ.svg +1 -0
  143. package/src/app/assets/flags/IR.svg +1 -0
  144. package/src/app/assets/flags/IS.svg +1 -0
  145. package/src/app/assets/flags/IT.svg +1 -0
  146. package/src/app/assets/flags/JE.svg +1 -0
  147. package/src/app/assets/flags/JM.svg +1 -0
  148. package/src/app/assets/flags/JO.svg +1 -0
  149. package/src/app/assets/flags/JP.svg +1 -0
  150. package/src/app/assets/flags/KE.svg +1 -0
  151. package/src/app/assets/flags/KG.svg +1 -0
  152. package/src/app/assets/flags/KH.svg +1 -0
  153. package/src/app/assets/flags/KI.svg +1 -0
  154. package/src/app/assets/flags/KM.svg +1 -0
  155. package/src/app/assets/flags/KN.svg +1 -0
  156. package/src/app/assets/flags/KP.svg +1 -0
  157. package/src/app/assets/flags/KR.svg +1 -0
  158. package/src/app/assets/flags/KW.svg +1 -0
  159. package/src/app/assets/flags/KY.svg +1 -0
  160. package/src/app/assets/flags/KZ.svg +1 -0
  161. package/src/app/assets/flags/LA.svg +1 -0
  162. package/src/app/assets/flags/LB.svg +1 -0
  163. package/src/app/assets/flags/LC.svg +1 -0
  164. package/src/app/assets/flags/LI.svg +1 -0
  165. package/src/app/assets/flags/LK.svg +1 -0
  166. package/src/app/assets/flags/LR.svg +1 -0
  167. package/src/app/assets/flags/LS.svg +1 -0
  168. package/src/app/assets/flags/LT.svg +1 -0
  169. package/src/app/assets/flags/LU.svg +1 -0
  170. package/src/app/assets/flags/LV.svg +1 -0
  171. package/src/app/assets/flags/LY.svg +1 -0
  172. package/src/app/assets/flags/MA.svg +1 -0
  173. package/src/app/assets/flags/MC.svg +1 -0
  174. package/src/app/assets/flags/MD.svg +1 -0
  175. package/src/app/assets/flags/ME.svg +1 -0
  176. package/src/app/assets/flags/MF.svg +1 -0
  177. package/src/app/assets/flags/MG.svg +1 -0
  178. package/src/app/assets/flags/MH.svg +1 -0
  179. package/src/app/assets/flags/MK.svg +1 -0
  180. package/src/app/assets/flags/ML.svg +1 -0
  181. package/src/app/assets/flags/MM.svg +1 -0
  182. package/src/app/assets/flags/MN.svg +1 -0
  183. package/src/app/assets/flags/MO.svg +1 -0
  184. package/src/app/assets/flags/MP.svg +1 -0
  185. package/src/app/assets/flags/MQ.svg +1 -0
  186. package/src/app/assets/flags/MR.svg +1 -0
  187. package/src/app/assets/flags/MS.svg +1 -0
  188. package/src/app/assets/flags/MT.svg +1 -0
  189. package/src/app/assets/flags/MU.svg +1 -0
  190. package/src/app/assets/flags/MV.svg +1 -0
  191. package/src/app/assets/flags/MW.svg +1 -0
  192. package/src/app/assets/flags/MX.svg +1 -0
  193. package/src/app/assets/flags/MY.svg +1 -0
  194. package/src/app/assets/flags/MZ.svg +1 -0
  195. package/src/app/assets/flags/NA.svg +1 -0
  196. package/src/app/assets/flags/NC.svg +1 -0
  197. package/src/app/assets/flags/NE.svg +1 -0
  198. package/src/app/assets/flags/NF.svg +1 -0
  199. package/src/app/assets/flags/NG.svg +1 -0
  200. package/src/app/assets/flags/NI.svg +1 -0
  201. package/src/app/assets/flags/NL.svg +1 -0
  202. package/src/app/assets/flags/NO.svg +1 -0
  203. package/src/app/assets/flags/NP.svg +1 -0
  204. package/src/app/assets/flags/NR.svg +1 -0
  205. package/src/app/assets/flags/NU.svg +1 -0
  206. package/src/app/assets/flags/NZ.svg +1 -0
  207. package/src/app/assets/flags/OM.svg +1 -0
  208. package/src/app/assets/flags/PA.svg +1 -0
  209. package/src/app/assets/flags/PE.svg +1 -0
  210. package/src/app/assets/flags/PF.svg +1 -0
  211. package/src/app/assets/flags/PG.svg +1 -0
  212. package/src/app/assets/flags/PH.svg +1 -0
  213. package/src/app/assets/flags/PK.svg +1 -0
  214. package/src/app/assets/flags/PL.svg +1 -0
  215. package/src/app/assets/flags/PM.svg +1 -0
  216. package/src/app/assets/flags/PN.svg +1 -0
  217. package/src/app/assets/flags/PR.svg +1 -0
  218. package/src/app/assets/flags/PS.svg +1 -0
  219. package/src/app/assets/flags/PT.svg +1 -0
  220. package/src/app/assets/flags/PW.svg +1 -0
  221. package/src/app/assets/flags/PY.svg +1 -0
  222. package/src/app/assets/flags/QA.svg +1 -0
  223. package/src/app/assets/flags/RE.svg +1 -0
  224. package/src/app/assets/flags/README.md +6 -0
  225. package/src/app/assets/flags/RO.svg +1 -0
  226. package/src/app/assets/flags/RS.svg +1 -0
  227. package/src/app/assets/flags/RU.svg +1 -0
  228. package/src/app/assets/flags/RW.svg +1 -0
  229. package/src/app/assets/flags/SA.svg +1 -0
  230. package/src/app/assets/flags/SB.svg +1 -0
  231. package/src/app/assets/flags/SC.svg +1 -0
  232. package/src/app/assets/flags/SD.svg +1 -0
  233. package/src/app/assets/flags/SE.svg +1 -0
  234. package/src/app/assets/flags/SG.svg +1 -0
  235. package/src/app/assets/flags/SH.svg +1 -0
  236. package/src/app/assets/flags/SI.svg +1 -0
  237. package/src/app/assets/flags/SJ.svg +1 -0
  238. package/src/app/assets/flags/SK.svg +1 -0
  239. package/src/app/assets/flags/SL.svg +1 -0
  240. package/src/app/assets/flags/SM.svg +1 -0
  241. package/src/app/assets/flags/SN.svg +1 -0
  242. package/src/app/assets/flags/SO.svg +1 -0
  243. package/src/app/assets/flags/SR.svg +1 -0
  244. package/src/app/assets/flags/SS.svg +1 -0
  245. package/src/app/assets/flags/ST.svg +1 -0
  246. package/src/app/assets/flags/SV.svg +1 -0
  247. package/src/app/assets/flags/SX.svg +1 -0
  248. package/src/app/assets/flags/SY.svg +1 -0
  249. package/src/app/assets/flags/SZ.svg +1 -0
  250. package/src/app/assets/flags/TA.svg +1 -0
  251. package/src/app/assets/flags/TC.svg +1 -0
  252. package/src/app/assets/flags/TD.svg +1 -0
  253. package/src/app/assets/flags/TF.svg +1 -0
  254. package/src/app/assets/flags/TG.svg +1 -0
  255. package/src/app/assets/flags/TH.svg +1 -0
  256. package/src/app/assets/flags/TJ.svg +1 -0
  257. package/src/app/assets/flags/TK.svg +1 -0
  258. package/src/app/assets/flags/TL.svg +1 -0
  259. package/src/app/assets/flags/TM.svg +1 -0
  260. package/src/app/assets/flags/TN.svg +1 -0
  261. package/src/app/assets/flags/TO.svg +1 -0
  262. package/src/app/assets/flags/TR.svg +1 -0
  263. package/src/app/assets/flags/TT.svg +1 -0
  264. package/src/app/assets/flags/TV.svg +1 -0
  265. package/src/app/assets/flags/TW.svg +1 -0
  266. package/src/app/assets/flags/TZ.svg +1 -0
  267. package/src/app/assets/flags/UA.svg +1 -0
  268. package/src/app/assets/flags/UG.svg +1 -0
  269. package/src/app/assets/flags/UM.svg +1 -0
  270. package/src/app/assets/flags/US.svg +1 -0
  271. package/src/app/assets/flags/UY.svg +1 -0
  272. package/src/app/assets/flags/UZ.svg +1 -0
  273. package/src/app/assets/flags/VA.svg +1 -0
  274. package/src/app/assets/flags/VC.svg +1 -0
  275. package/src/app/assets/flags/VE.svg +1 -0
  276. package/src/app/assets/flags/VG.svg +1 -0
  277. package/src/app/assets/flags/VI.svg +1 -0
  278. package/src/app/assets/flags/VN.svg +1 -0
  279. package/src/app/assets/flags/VU.svg +1 -0
  280. package/src/app/assets/flags/WF.svg +1 -0
  281. package/src/app/assets/flags/WS.svg +1 -0
  282. package/src/app/assets/flags/XA.svg +1 -0
  283. package/src/app/assets/flags/XC.svg +1 -0
  284. package/src/app/assets/flags/XK.svg +1 -0
  285. package/src/app/assets/flags/XO.svg +1 -0
  286. package/src/app/assets/flags/YE.svg +1 -0
  287. package/src/app/assets/flags/YT.svg +1 -0
  288. package/src/app/assets/flags/ZA.svg +1 -0
  289. package/src/app/assets/flags/ZM.svg +1 -0
  290. package/src/app/assets/flags/ZW.svg +1 -0
  291. package/src/app/email-preview.ts +46 -0
  292. package/src/app/index.css +203 -0
  293. package/src/app/index.html +12 -0
  294. package/src/app/integrations/i18n/react-i18next.d.ts +11 -0
  295. package/src/app/integrations/i18n/root-provider.tsx +62 -0
  296. package/src/app/integrations/tanstack-query/devtools.tsx +6 -0
  297. package/src/app/integrations/tanstack-query/root-provider.tsx +37 -0
  298. package/src/app/integrations/theme/root-provider.tsx +75 -0
  299. package/src/app/integrations/toast/toast-provider.tsx +46 -0
  300. package/src/app/locales/en-US/common.ts +268 -0
  301. package/src/app/locales/zh-CN/common.ts +263 -0
  302. package/src/app/main.tsx +40 -0
  303. package/src/app/page-chrome.tsx +79 -0
  304. package/src/app/router.tsx +40 -0
  305. package/src/app/routes/__root.tsx +293 -0
  306. package/src/app/routes/emails.tsx +199 -0
  307. package/src/app/routes/home.tsx +87 -0
  308. package/src/app/routes/index.ts +19 -0
  309. package/src/app/routes/metrics.tsx +541 -0
  310. package/src/app/routes/segment-overview.tsx +211 -0
  311. package/src/app/routes/segments.tsx +236 -0
  312. package/src/app/routes/settings.tsx +90 -0
  313. package/src/app/routes/workflows.tsx +348 -0
  314. package/src/app/studio.ts +16 -0
  315. package/src/app/svg.d.ts +17 -0
  316. package/src/app/virtual-config.d.ts +6 -0
  317. package/src/cli.ts +110 -0
  318. package/src/components/avatar.tsx +57 -0
  319. package/src/components/breadcrumb.tsx +49 -0
  320. package/src/components/button/index.tsx +86 -0
  321. package/src/components/channel-icon.ts +39 -0
  322. package/src/components/chat-markup.tsx +109 -0
  323. package/src/components/corner-shape.ts +13 -0
  324. package/src/components/date-range.tsx +181 -0
  325. package/src/components/discord-preview.tsx +165 -0
  326. package/src/components/dropdown/index.tsx +172 -0
  327. package/src/components/email-defaults.tsx +40 -0
  328. package/src/components/email-list.tsx +149 -0
  329. package/src/components/email-thumbnail.tsx +123 -0
  330. package/src/components/flag.tsx +40 -0
  331. package/src/components/input/index.tsx +40 -0
  332. package/src/components/input/search-input.tsx +24 -0
  333. package/src/components/layout.ts +403 -0
  334. package/src/components/menu/index.tsx +118 -0
  335. package/src/components/metric-card.tsx +321 -0
  336. package/src/components/modal/index.tsx +70 -0
  337. package/src/components/nav-drawer.tsx +84 -0
  338. package/src/components/node-inspector.tsx +242 -0
  339. package/src/components/profile-drawer.tsx +331 -0
  340. package/src/components/push-preview.tsx +470 -0
  341. package/src/components/push-thumbnail.tsx +78 -0
  342. package/src/components/segment-list.tsx +184 -0
  343. package/src/components/select/index.tsx +70 -0
  344. package/src/components/series-chart.tsx +120 -0
  345. package/src/components/slack-preview.tsx +223 -0
  346. package/src/components/sparkline.tsx +58 -0
  347. package/src/components/tabs/index.tsx +45 -0
  348. package/src/components/template-refs.ts +110 -0
  349. package/src/components/templates-page.tsx +601 -0
  350. package/src/components/textarea/index.tsx +37 -0
  351. package/src/components/thumbnail-window.tsx +65 -0
  352. package/src/components/workflow-canvas.tsx +503 -0
  353. package/src/components/workflow-list.tsx +231 -0
  354. package/src/config.ts +288 -0
  355. package/src/generate.ts +56 -0
  356. package/src/index.ts +35 -0
  357. package/src/postgres.ts +415 -0
  358. package/src/server/project.ts +290 -0
  359. package/src/server.ts +500 -0
  360. package/src/utils/cn.ts +6 -0
  361. package/src/utils/label.ts +12 -0
  362. package/src/utils/lookup.ts +11 -0
  363. package/src/utils/template-content.ts +213 -0
@@ -0,0 +1,321 @@
1
+ import { ArrowDown, ArrowUp, type LucideIcon, Minus } from 'lucide-react';
2
+ import { Fragment, type PointerEvent, useId, useState } from 'react';
3
+ import { cn } from '../utils/cn';
4
+ import { superellipse } from './corner-shape';
5
+
6
+ /**
7
+ * One metric of the delivery funnel: what it is worth right now, which way it
8
+ * moved, and its shape over the queried range.
9
+ *
10
+ * Four of these replace the single four-series line chart. That chart made the
11
+ * drop-off between the stages legible and nothing else — every series but the
12
+ * first was pinned to the floor by a shared y axis, so a 2% swing in clicks was
13
+ * invisible. Each card gets its own scale instead, which is what you want once
14
+ * the funnel's shape is a known quantity and the question becomes "is today
15
+ * normal for this stage".
16
+ *
17
+ * Hand-drawn SVG, like every other chart here — see the note in sparkline.tsx.
18
+ */
19
+
20
+ /** Which way a delta points; `flat` is an exact zero, not a rounding of one. */
21
+ export type Trend = 'up' | 'down' | 'flat';
22
+
23
+ /**
24
+ * One plotted line.
25
+ *
26
+ * A card plots either one series or a total and the parts it decomposes into
27
+ * (email opens split into human and machine). The parts are not independent
28
+ * measurements, which is why they arrive as a list on one card rather than as
29
+ * cards of their own: they only mean anything read against the total.
30
+ */
31
+ export interface MetricSeries {
32
+ /** Named in the hover readout, beside its colour swatch. */
33
+ label: string;
34
+ /** One value per bucket, oldest first; as long as `dates`. */
35
+ values: readonly number[];
36
+ }
37
+
38
+ export interface MetricCardProps {
39
+ label: string;
40
+ /** The current bucket, already formatted ('9,280', '26.2%'). */
41
+ value: string;
42
+ /** Period-over-period change, already formatted and signed. */
43
+ delta?: { text: string; trend: Trend };
44
+ /**
45
+ * Bucket dates, oldest first, already formatted: the card has no business
46
+ * knowing the locale, and the hover readout is the only place they are read.
47
+ */
48
+ dates: readonly string[];
49
+ /**
50
+ * Head series first. It gets the strongest shade and the gradient fill; any
51
+ * that follow are its components and share its y scale — plotted against
52
+ * scales of their own, two halves would not visibly add up to the whole.
53
+ */
54
+ series: readonly MetricSeries[];
55
+ /** Formats the extremes in the plot's corners, and the values under the cursor. */
56
+ format: (value: number) => string;
57
+ }
58
+
59
+ /**
60
+ * viewBox units; `preserveAspectRatio="none"` stretches them to the card.
61
+ *
62
+ * The height doubles as the plot's pixel height, which is what lets the hover
63
+ * indicator place its dots with a y taken straight from the viewBox. The two
64
+ * are the same number on purpose — move one and the other has to follow, or
65
+ * the curve stretches vertically and the dots leave it.
66
+ */
67
+ const VIEW_WIDTH = 320;
68
+ const VIEW_HEIGHT = 120;
69
+ /** Headroom above the peak so the max label never sits on the curve. */
70
+ const TOP_PAD = 22;
71
+
72
+ /**
73
+ * Successive series, each mixed further toward the card it sits on.
74
+ *
75
+ * Mixing with the surface — rather than stepping down a fixed ramp — is what
76
+ * makes one set of shades work in both themes: it pales toward the white card
77
+ * in light mode and darkens toward the near-black one in dark mode, so the
78
+ * head series is the highest-contrast line either way and the components read
79
+ * as subordinate to it. A second hue was the other option and is not on the
80
+ * table: accent is the only colour in the studio.
81
+ */
82
+ const seriesColor = (index: number): string =>
83
+ `color-mix(in oklab, var(--color-accent) ${Math.round(100 * 0.7 ** index)}%, var(--color-card))`;
84
+
85
+ interface Point {
86
+ x: number;
87
+ y: number;
88
+ }
89
+
90
+ /**
91
+ * A cardinal spline through every point. The samples are daily counts, not a
92
+ * continuous signal, so the curve is a reading aid rather than interpolation —
93
+ * which is why it is allowed to overshoot slightly between points.
94
+ */
95
+ function splinePath(points: readonly Point[]): string {
96
+ if (points.length === 0) return '';
97
+ const first = points[0];
98
+ let d = `M ${first.x.toFixed(1)} ${first.y.toFixed(1)}`;
99
+ for (let i = 0; i < points.length - 1; i++) {
100
+ /* Clamped neighbours, so the end segments bend the same way as the middle. */
101
+ const p0 = points[Math.max(0, i - 1)];
102
+ const p1 = points[i];
103
+ const p2 = points[i + 1];
104
+ const p3 = points[Math.min(points.length - 1, i + 2)];
105
+ const c1x = p1.x + (p2.x - p0.x) / 6;
106
+ const c1y = p1.y + (p2.y - p0.y) / 6;
107
+ const c2x = p2.x - (p3.x - p1.x) / 6;
108
+ const c2y = p2.y - (p3.y - p1.y) / 6;
109
+ d += ` C ${c1x.toFixed(1)} ${c1y.toFixed(1)}, ${c2x.toFixed(1)} ${c2y.toFixed(1)}, ${p2.x.toFixed(1)} ${p2.y.toFixed(1)}`;
110
+ }
111
+ return d;
112
+ }
113
+
114
+ const TREND_STYLE: Record<Trend, string> = {
115
+ up: 'text-emerald-600 dark:text-emerald-400',
116
+ down: 'text-red-600 dark:text-red-400',
117
+ flat: 'text-secondary',
118
+ };
119
+
120
+ const TREND_ICON: Record<Trend, LucideIcon> = { up: ArrowUp, down: ArrowDown, flat: Minus };
121
+
122
+ export function MetricCard({ label, value, delta, dates, series, format }: MetricCardProps) {
123
+ const gradientId = useId();
124
+ /** Which bucket the cursor is over; null once it leaves the plot. */
125
+ const [active, setActive] = useState<number | null>(null);
126
+
127
+ /* One scale for every line on the card: the components sum to the head
128
+ series, and a shared axis is the only way that addition is visible. */
129
+ const all = series.flatMap((one) => [...one.values]);
130
+ const max = Math.max(...all, 0);
131
+ const min = Math.min(...all, max);
132
+ /* A flat series has no range to scale against; park it on the baseline. */
133
+ const span = max - min || 1;
134
+ const stepX = dates.length > 1 ? VIEW_WIDTH / (dates.length - 1) : 0;
135
+ const yOf = (point: number) => TOP_PAD + (1 - (point - min) / span) * (VIEW_HEIGHT - TOP_PAD);
136
+ const plotted = series.map((one) =>
137
+ one.values.map((point, index) => ({ x: index * stepX, y: yOf(point) }))
138
+ );
139
+
140
+ const head = plotted.length > 0 ? plotted[0] : [];
141
+ const line = splinePath(head);
142
+ /* The fill closes the curve to the bottom edge and back to where it started.
143
+ Only the head series gets one: three stacked washes would muddy the plot
144
+ and the components are read as lines against the total, not as volumes. */
145
+ const area = line === '' ? '' : `${line} L ${VIEW_WIDTH} ${VIEW_HEIGHT} L 0 ${VIEW_HEIGHT} Z`;
146
+
147
+ const DeltaIcon = delta ? TREND_ICON[delta.trend] : undefined;
148
+
149
+ /* The series can be replaced under a held cursor — a new granularity, a new
150
+ channel — so a stale index is a live possibility, not a defensive fiction. */
151
+ const hovered = active !== null && active < dates.length ? active : undefined;
152
+
153
+ /**
154
+ * Cursor → bucket. The plot is `preserveAspectRatio="none"`, so its viewBox
155
+ * is stretched to whatever width the card ended up with; only the rendered
156
+ * box knows the real scale, and reading x in viewBox units would leave the
157
+ * indicator a growing distance behind the pointer.
158
+ */
159
+ const trackPointer = (event: PointerEvent<HTMLDivElement>) => {
160
+ const { left, width } = event.currentTarget.getBoundingClientRect();
161
+ if (width === 0 || dates.length === 0) return;
162
+ const index = Math.round(((event.clientX - left) / width) * (dates.length - 1));
163
+ setActive(Math.min(Math.max(index, 0), dates.length - 1));
164
+ };
165
+
166
+ return (
167
+ <section
168
+ className="border-border bg-card flex flex-col overflow-hidden rounded-2xl border"
169
+ style={superellipse}
170
+ >
171
+ <div className="px-4 pt-4">
172
+ <h3 className="text-sm font-medium">{label}</h3>
173
+ </div>
174
+
175
+ <div className="flex flex-wrap items-baseline gap-x-2 gap-y-1 px-4 pt-3">
176
+ <span className="text-2xl font-semibold tracking-tight tabular-nums">{value}</span>
177
+ {delta !== undefined && DeltaIcon !== undefined && (
178
+ <span className={cn('inline-flex items-center gap-1 text-xs', TREND_STYLE[delta.trend])}>
179
+ <DeltaIcon size={12} strokeWidth={2.5} aria-hidden />
180
+ {delta.text}
181
+ </span>
182
+ )}
183
+ </div>
184
+
185
+ <div
186
+ className="relative mt-3"
187
+ onPointerMove={trackPointer}
188
+ onPointerLeave={() => setActive(null)}
189
+ >
190
+ <svg
191
+ viewBox={`0 0 ${VIEW_WIDTH} ${VIEW_HEIGHT}`}
192
+ preserveAspectRatio="none"
193
+ className="block w-full"
194
+ style={{ height: VIEW_HEIGHT }}
195
+ role="img"
196
+ aria-label={label}
197
+ >
198
+ <defs>
199
+ <linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
200
+ <stop offset="0%" stopColor="var(--color-accent)" stopOpacity={0.22} />
201
+ <stop offset="100%" stopColor="var(--color-accent)" stopOpacity={0} />
202
+ </linearGradient>
203
+ </defs>
204
+ {area !== '' && <path d={area} fill={`url(#${gradientId})`} />}
205
+ {/* Components first, head last: where they cross, the total is the
206
+ line you want on top. */}
207
+ {plotted
208
+ .map((points, index) => ({ d: splinePath(points), index }))
209
+ .filter((entry) => entry.d !== '')
210
+ .reverse()
211
+ .map((entry) => (
212
+ <path
213
+ key={entry.index}
214
+ d={entry.d}
215
+ fill="none"
216
+ style={{ stroke: seriesColor(entry.index) }}
217
+ strokeWidth={1.75}
218
+ strokeLinejoin="round"
219
+ strokeLinecap="round"
220
+ /* The viewBox is stretched, so the stroke must opt out of scaling. */
221
+ vectorEffect="non-scaling-stroke"
222
+ />
223
+ ))}
224
+ </svg>
225
+ {all.length > 0 && (
226
+ <>
227
+ <span className="text-muted pointer-events-none absolute top-0 left-4 text-xs tabular-nums">
228
+ {format(max)}
229
+ </span>
230
+ <span className="text-muted pointer-events-none absolute right-4 bottom-1 text-xs tabular-nums">
231
+ {format(min)}
232
+ </span>
233
+ </>
234
+ )}
235
+ {hovered !== undefined && (
236
+ <HoverReadout
237
+ x={dates.length > 1 ? hovered / (dates.length - 1) : 0}
238
+ date={dates[hovered]}
239
+ rows={series.map((one, index) => ({
240
+ color: seriesColor(index),
241
+ label: one.label,
242
+ value: format(one.values[hovered]),
243
+ y: plotted[index][hovered].y,
244
+ }))}
245
+ />
246
+ )}
247
+ </div>
248
+ </section>
249
+ );
250
+ }
251
+
252
+ /** One line of the readout: which series, what it read, and where its dot goes. */
253
+ interface ReadoutRow {
254
+ color: string;
255
+ label: string;
256
+ value: string;
257
+ /** Plot pixels from the top — the viewBox height is the rendered height. */
258
+ y: number;
259
+ }
260
+
261
+ /**
262
+ * Rule, dots and panel for the bucket under the cursor.
263
+ *
264
+ * HTML rather than SVG: a circle drawn in the stretched viewBox renders as an
265
+ * ellipse and the panel would shear with it. A percentage rides the same
266
+ * stretch the curve does, so `x` is a 0–1 fraction of the plot's width, while
267
+ * each `y` is plain pixels.
268
+ *
269
+ * Every card uses the same layout, one line per series, whether it plots one
270
+ * or three. A single line's swatch and name are redundant on their own card,
271
+ * but four cards sit side by side: reading across them, a row that suddenly
272
+ * loses its columns costs more than the redundancy does.
273
+ */
274
+ function HoverReadout({ x, date, rows }: { x: number; date: string; rows: readonly ReadoutRow[] }) {
275
+ const left = `${x * 100}%`;
276
+ return (
277
+ <div aria-hidden className="pointer-events-none">
278
+ <div className="bg-border absolute inset-y-0 w-px" style={{ left }} />
279
+ {rows.map((row) => (
280
+ <div
281
+ key={row.label}
282
+ className="border-card absolute size-2.5 rounded-full border-2"
283
+ style={{ left, top: row.y, background: row.color, transform: 'translate(-50%, -50%)' }}
284
+ />
285
+ ))}
286
+ {/*
287
+ Anchored by the same fraction it sits at: the panel hugs the left edge
288
+ at the start of the series and the right edge at the end, so the card
289
+ never clips it.
290
+
291
+ `w-max` is load-bearing. The date spans all three columns, but the
292
+ middle one is `1fr`, and a flexible track takes no min-content
293
+ contribution from a spanning item — so a shrink-to-fit panel sizes
294
+ itself to the data row alone and the date spills out the side. Sizing
295
+ to max-content measures the date too; the `1fr` then hands the slack to
296
+ the label, which keeps the value flush right.
297
+ */}
298
+ <div
299
+ className="border-border bg-card shadow-card-shadow absolute top-0 grid w-max items-center gap-x-3 gap-y-1 rounded-lg border px-2.5 py-2 text-xs shadow-md"
300
+ style={{
301
+ ...superellipse,
302
+ left,
303
+ transform: `translateX(-${x * 100}%)`,
304
+ gridTemplateColumns: 'auto 1fr auto',
305
+ }}
306
+ >
307
+ <div className="col-span-full font-medium whitespace-nowrap">{date}</div>
308
+ {rows.map((row) => (
309
+ <Fragment key={row.label}>
310
+ <span
311
+ className="size-3 rounded-sm"
312
+ style={{ ...superellipse, background: row.color }}
313
+ />
314
+ <span className="text-secondary whitespace-nowrap">{row.label}</span>
315
+ <span className="text-right font-medium tabular-nums">{row.value}</span>
316
+ </Fragment>
317
+ ))}
318
+ </div>
319
+ </div>
320
+ );
321
+ }
@@ -0,0 +1,70 @@
1
+ import {
2
+ FloatingFocusManager,
3
+ FloatingOverlay,
4
+ FloatingPortal,
5
+ useDismiss,
6
+ useFloating,
7
+ useInteractions,
8
+ useRole,
9
+ } from '@floating-ui/react';
10
+ import type { ReactNode } from 'react';
11
+ import { cn } from '../../utils/cn';
12
+ import { superellipse } from '../corner-shape';
13
+
14
+ /**
15
+ * Same API as the template project's Modal so the two stay diffable, but built
16
+ * on floating-ui (which the studio already ships for the Dropdown) instead of
17
+ * headlessui — one positioning library, not two.
18
+ */
19
+ interface Props {
20
+ visible?: boolean;
21
+ children: ReactNode;
22
+ className?: string;
23
+ /** Blocks dismissal (Esc, outside press) while a save is in flight. */
24
+ disabled?: boolean;
25
+ onCancel?: () => void;
26
+ }
27
+
28
+ export function Modal({ visible = false, className, disabled = false, children, onCancel }: Props) {
29
+ const { refs, context } = useFloating({
30
+ open: visible,
31
+ onOpenChange: (open) => {
32
+ if (!open && !disabled) onCancel?.();
33
+ },
34
+ });
35
+
36
+ const { getFloatingProps } = useInteractions([
37
+ useDismiss(context, { enabled: !disabled }),
38
+ useRole(context),
39
+ ]);
40
+
41
+ if (!visible) return null;
42
+
43
+ return (
44
+ <FloatingPortal>
45
+ <FloatingOverlay
46
+ lockScroll
47
+ className="z-50 flex items-center justify-center bg-black/10 backdrop-blur-xs dark:bg-white/10"
48
+ >
49
+ <FloatingFocusManager context={context}>
50
+ <div
51
+ ref={refs.setFloating}
52
+ style={superellipse}
53
+ className={cn(
54
+ 'bg-card relative max-h-dvh max-w-dvw overflow-y-auto rounded-3xl',
55
+ 'shadow-lg dark:shadow-gray-700',
56
+ className
57
+ )}
58
+ {...getFloatingProps()}
59
+ >
60
+ {children}
61
+ </div>
62
+ </FloatingFocusManager>
63
+ </FloatingOverlay>
64
+ </FloatingPortal>
65
+ );
66
+ }
67
+
68
+ export function ModalTitle({ children }: { children: ReactNode }) {
69
+ return <h2 className="text-primary text-lg font-semibold">{children}</h2>;
70
+ }
@@ -0,0 +1,84 @@
1
+ import { Workflow } from 'lucide-react';
2
+ import { type ReactNode, useEffect } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { superellipse } from './corner-shape';
5
+
6
+ /**
7
+ * The shell's navigation, as a panel over the left edge, for viewports too
8
+ * narrow to give it a column.
9
+ *
10
+ * The rail costs 64px whether or not anyone is looking at it; on a 375px
11
+ * screen that is a fifth of the width spent on five icons. Below `md` the rail
12
+ * is gone entirely and this takes over, opened from the header's menu button —
13
+ * same items, same brand, only summoned instead of resident.
14
+ *
15
+ * Shaped after ProfileDrawer (scrim at z-20, panel at z-30, translated rather
16
+ * than mounted so it slides): the header is `sticky z-20`, so a scrim at the
17
+ * same level but later in the tree dims it too, which is what a modal nav
18
+ * wants — nothing behind it should look reachable.
19
+ */
20
+ export interface NavDrawerProps {
21
+ open: boolean;
22
+ onClose: () => void;
23
+ /** The nav links. The caller wires each one to also close the drawer. */
24
+ children: ReactNode;
25
+ }
26
+
27
+ export function NavDrawer({ open, onClose, children }: NavDrawerProps) {
28
+ const { t } = useTranslation();
29
+
30
+ /* Escape closes it: navigation is a detour, never a state to be trapped in. */
31
+ useEffect(() => {
32
+ if (!open) return;
33
+ const onKey = (event: KeyboardEvent) => {
34
+ if (event.key === 'Escape') onClose();
35
+ };
36
+ document.addEventListener('keydown', onKey);
37
+ return () => document.removeEventListener('keydown', onKey);
38
+ }, [open, onClose]);
39
+
40
+ return (
41
+ /* `md:hidden` on both halves: above the breakpoint the rail is back and
42
+ this must not be openable, reachable by tab, or left hanging open by a
43
+ resize. */
44
+ <>
45
+ {/* The scrim only exists while open, so it never eats clicks on the page. */}
46
+ {open && (
47
+ <button
48
+ type="button"
49
+ aria-label={t('common.close')}
50
+ onClick={onClose}
51
+ className="fixed inset-0 z-20 cursor-default bg-gray-950/20 md:hidden dark:bg-gray-950/50"
52
+ />
53
+ )}
54
+
55
+ {/*
56
+ `inert` rather than `aria-hidden`: translated off-screen the panel is
57
+ still displayed, so its links kept taking focus — tabbing from the menu
58
+ button walked through five invisible destinations. `inert` takes them
59
+ out of the tab order and the accessibility tree together, which is what
60
+ `aria-hidden` alone only claimed to do.
61
+ */}
62
+ <aside
63
+ inert={!open}
64
+ className={`border-border bg-card fixed inset-y-0 left-0 z-30 flex w-60 max-w-[80%] flex-col border-r shadow-xl transition-transform duration-200 ease-out md:hidden ${
65
+ open ? 'translate-x-0' : '-translate-x-full'
66
+ }`}
67
+ >
68
+ {/* The rail's brand block, at the rail's height, so opening the drawer
69
+ lands the logo exactly where the header would have drawn it. */}
70
+ <div className="flex h-14 shrink-0 items-center gap-2.5 px-4">
71
+ <div
72
+ className="bg-primary flex size-7 shrink-0 items-center justify-center rounded-lg"
73
+ style={superellipse}
74
+ >
75
+ <Workflow className="text-card size-4" strokeWidth={2} />
76
+ </div>
77
+ <strong className="text-sm font-semibold whitespace-nowrap">Workflow Studio</strong>
78
+ </div>
79
+
80
+ <nav className="flex flex-col gap-1.5 p-3 pt-1">{children}</nav>
81
+ </aside>
82
+ </>
83
+ );
84
+ }