@shware/workflow-ui 0.0.0-stage → 0.1.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,242 @@
1
+ import type { ConditionIR, NodeIR } from '@shware/workflow';
2
+ import { X } from 'lucide-react';
3
+ import type { ReactNode } from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { superellipse } from './corner-shape';
6
+
7
+ /**
8
+ * Details for one canvas node: its parameters, the literals inside its
9
+ * conditions, and where in source it was built.
10
+ *
11
+ * Read-only by design. Source is edited in the editor; Vite picks the change
12
+ * up and the canvas redraws, so the panel only ever reflects what is on disk.
13
+ */
14
+ export interface NodeSource {
15
+ /** Path on disk, relative to the project. */
16
+ file: string;
17
+ line: number;
18
+ }
19
+
20
+ export interface NodeInspectorProps {
21
+ node: NodeIR;
22
+ /**
23
+ * Where the node was built, resolved by the host. Optional: a lookup that
24
+ * fails or is still pending just leaves the row out.
25
+ */
26
+ source?: NodeSource;
27
+ onClose: () => void;
28
+ /**
29
+ * What the node sends, rendered: an email thumbnail for a message node. The
30
+ * host owns the template registry and the render, so it passes the result.
31
+ */
32
+ preview?: ReactNode;
33
+ }
34
+
35
+ /** Label / value row, matching the email envelope table. */
36
+ function Field({ label, children }: { label: string; children: ReactNode }) {
37
+ return (
38
+ <>
39
+ <dt className="text-muted whitespace-nowrap">{label}</dt>
40
+ <dd className="text-secondary min-w-0 break-words">{children}</dd>
41
+ </>
42
+ );
43
+ }
44
+
45
+ /** The scalar parameters a node shows. Union rather than string, so the i18n key stays statically checked. */
46
+ export type NodeFieldKey =
47
+ | 'duration'
48
+ | 'min'
49
+ | 'max'
50
+ | 'timeout'
51
+ | 'from'
52
+ | 'to'
53
+ | 'tz'
54
+ | 'reason'
55
+ | 'value'
56
+ | 'within'
57
+ | 'count';
58
+
59
+ export interface NodeField {
60
+ /** i18n key under `inspector.field`. */
61
+ key: NodeFieldKey;
62
+ value: string;
63
+ /** Shown before the label when the field belongs to a condition, not the node. */
64
+ scope?: string | undefined;
65
+ }
66
+
67
+ export function ownFieldsOf(node: NodeIR): NodeField[] {
68
+ switch (node.type) {
69
+ case 'delay':
70
+ return [{ key: 'duration', value: node.duration.value }];
71
+ case 'random_delay':
72
+ return [
73
+ { key: 'min', value: node.min.value },
74
+ { key: 'max', value: node.max.value },
75
+ ];
76
+ case 'wait_until':
77
+ return [{ key: 'timeout', value: node.timeout.value }];
78
+ case 'time_window':
79
+ return [
80
+ { key: 'from', value: node.between[0] },
81
+ { key: 'to', value: node.between[1] },
82
+ { key: 'tz', value: node.tz },
83
+ ];
84
+ case 'filter':
85
+ return node.reason === undefined ? [] : [{ key: 'reason', value: node.reason }];
86
+ case 'exit':
87
+ return node.reason === undefined ? [] : [{ key: 'reason', value: node.reason }];
88
+ default:
89
+ return [];
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Literals inside a node's condition — `eq(u.plan, 'pro')` shows `pro`,
95
+ * `performed(e.login, { within: '7 days' })` shows the window. The property
96
+ * path and the event are already on the canvas card, so only the values are
97
+ * listed here.
98
+ */
99
+ function conditionFields(condition: ConditionIR, scope: string): NodeField[] {
100
+ const own: NodeField[] = [];
101
+
102
+ if (
103
+ (condition.type === 'property' || condition.type === 'payload') &&
104
+ condition.value !== undefined
105
+ ) {
106
+ own.push({ key: 'value', value: String(condition.value), scope });
107
+ }
108
+ if (condition.type === 'performed') {
109
+ if (condition.within !== undefined) {
110
+ own.push({ key: 'within', value: condition.within.value, scope });
111
+ }
112
+ if (condition.count !== undefined) {
113
+ own.push({ key: 'count', value: String(condition.count), scope });
114
+ }
115
+ }
116
+
117
+ if (condition.type === 'and' || condition.type === 'or') {
118
+ return [
119
+ ...own,
120
+ ...condition.conditions.flatMap((child, index) =>
121
+ conditionFields(child, `${scope}[${index}]`)
122
+ ),
123
+ ];
124
+ }
125
+ if (condition.type === 'not') return [...own, ...conditionFields(condition.condition, scope)];
126
+ return own;
127
+ }
128
+
129
+ /** Every field a node shows: its own scalars plus the literals inside its conditions. */
130
+ export function fieldsOf(node: NodeIR): NodeField[] {
131
+ return [...ownFieldsOf(node), ...conditionFieldsOf(node)];
132
+ }
133
+
134
+ /** Conditions attached to a node, flattened with a label saying which one. */
135
+ export function conditionFieldsOf(node: NodeIR): NodeField[] {
136
+ switch (node.type) {
137
+ case 'filter':
138
+ return conditionFields(node.condition, 'filter');
139
+ case 'wait_until':
140
+ return conditionFields(node.condition, 'until');
141
+ case 'branch':
142
+ return node.cases.flatMap((branchCase, index) =>
143
+ conditionFields(branchCase.condition, branchCase.label ?? `case ${index}`)
144
+ );
145
+ default:
146
+ return [];
147
+ }
148
+ }
149
+
150
+ /** Read-only summary rows, per node type. */
151
+ function summary(node: NodeIR): { label: string; value: string }[] {
152
+ switch (node.type) {
153
+ case 'message':
154
+ return [
155
+ { label: 'channel', value: node.channel },
156
+ { label: 'template', value: node.template },
157
+ ];
158
+ case 'branch':
159
+ return node.cases.map((branchCase, index) => ({
160
+ label: `case ${index}`,
161
+ value: branchCase.label ?? '—',
162
+ }));
163
+ case 'cohort':
164
+ return node.arms.map((arm) => ({
165
+ label: arm.name,
166
+ value: `${arm.weight / 100}%`,
167
+ }));
168
+ case 'send_event':
169
+ return [{ label: 'event', value: node.event }];
170
+ case 'action':
171
+ return [
172
+ { label: 'action', value: node.action },
173
+ ...(node.codeHash !== undefined
174
+ ? [{ label: 'code', value: node.codeHash.slice(0, 12) }]
175
+ : []),
176
+ ];
177
+ default:
178
+ return [];
179
+ }
180
+ }
181
+
182
+ export function NodeInspector({ node, source, onClose, preview }: NodeInspectorProps) {
183
+ const { t } = useTranslation();
184
+ const fields = fieldsOf(node);
185
+
186
+ return (
187
+ <aside
188
+ className="border-border bg-card flex max-h-full w-80 flex-col overflow-hidden rounded-2xl border shadow-[0_4px_12px_var(--color-card-shadow)]"
189
+ style={superellipse}
190
+ >
191
+ <div className="flex h-12 shrink-0 items-center gap-3 pr-2.5 pl-4">
192
+ <span className="text-primary flex-1 text-sm font-semibold">
193
+ {t(`inspector.type.${node.type}`)}
194
+ </span>
195
+ <button
196
+ type="button"
197
+ onClick={onClose}
198
+ className="text-muted hover:bg-hover hover:text-primary flex size-7 items-center justify-center rounded-lg transition-colors"
199
+ style={superellipse}
200
+ aria-label={t('inspector.close')}
201
+ >
202
+ <X className="size-4" strokeWidth={2} />
203
+ </button>
204
+ </div>
205
+
206
+ <div className="min-h-0 flex-1 overflow-auto p-4 pt-0">
207
+ {preview}
208
+
209
+ <dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1.5 text-xs">
210
+ <Field label={t('inspector.id')}>
211
+ <span className="font-mono text-xs">{node.id}</span>
212
+ </Field>
213
+ {node.label !== undefined && <Field label={t('inspector.label')}>{node.label}</Field>}
214
+ {summary(node).map((row) => (
215
+ <Field key={row.label} label={row.label}>
216
+ <span className="font-mono text-xs">{row.value}</span>
217
+ </Field>
218
+ ))}
219
+ {fields.map((field, index) => (
220
+ <Field
221
+ key={`${field.scope ?? ''}:${field.key}:${index}`}
222
+ label={
223
+ field.scope === undefined
224
+ ? t(`inspector.field.${field.key}`)
225
+ : `${field.scope} · ${t(`inspector.field.${field.key}`)}`
226
+ }
227
+ >
228
+ <span className="font-mono text-xs">{field.value}</span>
229
+ </Field>
230
+ ))}
231
+ {source !== undefined && (
232
+ <Field label={t('inspector.source')}>
233
+ <span className="font-mono text-xs">
234
+ {source.file}:{source.line}
235
+ </span>
236
+ </Field>
237
+ )}
238
+ </dl>
239
+ </div>
240
+ </aside>
241
+ );
242
+ }
@@ -0,0 +1,331 @@
1
+ import { Check, ChevronDown, Copy, X } from 'lucide-react';
2
+ import { type ReactNode, useEffect, useState } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import type { Profile } from '../config';
5
+ import { cn } from '../utils/cn';
6
+ import { Avatar } from './avatar';
7
+ import { superellipse } from './corner-shape';
8
+ import { Flag } from './flag';
9
+
10
+ /**
11
+ * A profile's full record, in a panel over the right edge.
12
+ *
13
+ * A drawer rather than a route because the list is the context: you scan the
14
+ * table, open one person to check a property, and go back to scanning. Pushing
15
+ * that through navigation would lose the scroll position every time.
16
+ *
17
+ * Properties are grouped into the analytics package's tag families (source,
18
+ * device, utm — see TrackTags) plus the identity fields; anything the schema
19
+ * does not know lands in Others, so nothing a project stores is ever hidden.
20
+ * All keys are snake_case, matching how the SDK writes user properties.
21
+ */
22
+ export interface ProfileDrawerProps {
23
+ profile: Profile | undefined;
24
+ onClose: () => void;
25
+ }
26
+
27
+ /** Property keys per section, in display order. Labels come from i18n by the same key. */
28
+ const SOURCE_FIELDS = [
29
+ 'country',
30
+ 'region',
31
+ 'city',
32
+ 'platform',
33
+ 'language',
34
+ 'time_zone',
35
+ 'release',
36
+ ] as const;
37
+ const DEVICE_FIELDS = [
38
+ 'device',
39
+ 'os',
40
+ 'browser',
41
+ 'screen_resolution',
42
+ 'device_pixel_ratio',
43
+ ] as const;
44
+ /* Identity keys consumed by the User Data section rather than listed in Others. */
45
+ const USER_FIELDS = ['name', 'first_name', 'last_name', 'email', 'company'];
46
+
47
+ /** Values come from the user's own store, so render them without assuming a shape. */
48
+ function formatValue(value: unknown): string {
49
+ if (value === null || value === undefined || value === '') return '—';
50
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
51
+ return String(value);
52
+ }
53
+ return JSON.stringify(value);
54
+ }
55
+
56
+ /** One collapsible family of rows; the chevron mirrors the envelope panel's. */
57
+ function Section({
58
+ title,
59
+ open,
60
+ onToggle,
61
+ children,
62
+ }: {
63
+ title: string;
64
+ open: boolean;
65
+ onToggle: () => void;
66
+ children: ReactNode;
67
+ }) {
68
+ /* Top border, inset by the drawer's padding — the divider stops short of the edges. */
69
+ return (
70
+ <section className="border-border border-t py-4">
71
+ <button
72
+ type="button"
73
+ aria-expanded={open}
74
+ onClick={onToggle}
75
+ className="flex w-full items-center justify-between text-left"
76
+ >
77
+ <span className="text-primary text-sm font-semibold">{title}</span>
78
+ <ChevronDown
79
+ size={16}
80
+ strokeWidth={2}
81
+ aria-hidden
82
+ className={cn('text-muted transition-transform', open && 'rotate-180')}
83
+ />
84
+ </button>
85
+ {open && (
86
+ <dl className="mt-3 grid grid-cols-[max-content_1fr] items-center gap-x-6 gap-y-2 text-sm">
87
+ {children}
88
+ </dl>
89
+ )}
90
+ </section>
91
+ );
92
+ }
93
+
94
+ /** Label left, value right-aligned; missing values render as a dash. */
95
+ function Row({
96
+ label,
97
+ value,
98
+ action,
99
+ leading,
100
+ }: {
101
+ label: string;
102
+ value: unknown;
103
+ action?: ReactNode;
104
+ /** Sits just before the value — the country row's flag. */
105
+ leading?: ReactNode;
106
+ }) {
107
+ return (
108
+ <>
109
+ <dt className="text-muted whitespace-nowrap">{label}</dt>
110
+ <dd className="text-secondary flex min-w-0 items-center justify-end gap-1.5">
111
+ {leading}
112
+ <span className="min-w-0 truncate text-right" title={formatValue(value)}>
113
+ {formatValue(value)}
114
+ </span>
115
+ {action}
116
+ </dd>
117
+ </>
118
+ );
119
+ }
120
+
121
+ /** Copy-to-clipboard tail for identity rows, flipping to a check as feedback. */
122
+ function CopyButton({ label, value }: { label: string; value: string }) {
123
+ const [copied, setCopied] = useState(false);
124
+ useEffect(() => {
125
+ if (!copied) return;
126
+ const timer = setTimeout(() => setCopied(false), 1500);
127
+ return () => clearTimeout(timer);
128
+ }, [copied]);
129
+ return (
130
+ <button
131
+ type="button"
132
+ aria-label={label}
133
+ title={label}
134
+ onClick={() => {
135
+ void (async () => {
136
+ try {
137
+ await navigator.clipboard.writeText(value);
138
+ } catch {
139
+ /* Clipboard API can be permission-gated (embedded webviews); fall back. */
140
+ const area = document.createElement('textarea');
141
+ area.value = value;
142
+ document.body.append(area);
143
+ area.select();
144
+ document.execCommand('copy');
145
+ area.remove();
146
+ }
147
+ setCopied(true);
148
+ })();
149
+ }}
150
+ className="text-muted hover:bg-hover hover:text-primary flex size-6 shrink-0 items-center justify-center rounded-md transition-colors"
151
+ style={superellipse}
152
+ >
153
+ {copied ? (
154
+ <Check size={14} strokeWidth={2} aria-hidden />
155
+ ) : (
156
+ <Copy size={14} strokeWidth={2} aria-hidden />
157
+ )}
158
+ </button>
159
+ );
160
+ }
161
+
162
+ export function ProfileDrawer({ profile, onClose }: ProfileDrawerProps) {
163
+ const { t } = useTranslation();
164
+ const open = profile !== undefined;
165
+ /* Closed sections by title key; everything starts expanded, like the reference. */
166
+ const [closed, setClosed] = useState<Record<string, boolean>>({});
167
+ const toggle = (key: string) => setClosed((state) => ({ ...state, [key]: !state[key] }));
168
+
169
+ /* Escape closes it: the panel is a detail view, not a decision the user is trapped in. */
170
+ useEffect(() => {
171
+ if (!open) return;
172
+ const onKey = (event: KeyboardEvent) => {
173
+ if (event.key === 'Escape') onClose();
174
+ };
175
+ document.addEventListener('keydown', onKey);
176
+ return () => document.removeEventListener('keydown', onKey);
177
+ }, [open, onClose]);
178
+
179
+ const properties = profile?.properties ?? {};
180
+ const prop = (key: string) => properties[key];
181
+
182
+ /* Identity, assembled with fallbacks: `name`, else first + last. Strings only. */
183
+ const nameProp = prop('name');
184
+ const name =
185
+ typeof nameProp === 'string' && nameProp !== ''
186
+ ? nameProp
187
+ : [prop('first_name'), prop('last_name')]
188
+ .filter((part): part is string => typeof part === 'string')
189
+ .join(' ') || undefined;
190
+ const emailProp = prop('email');
191
+ const email = profile?.email ?? (typeof emailProp === 'string' ? emailProp : undefined);
192
+
193
+ const utmKeys = Object.keys(properties).filter((key) => key.startsWith('utm_'));
194
+ const consumed = new Set([...USER_FIELDS, ...SOURCE_FIELDS, ...DEVICE_FIELDS, ...utmKeys]);
195
+ const others = Object.entries(properties).filter(([key]) => !consumed.has(key));
196
+
197
+ /* Copy only rows that hold a real value; a dash is nothing to copy. */
198
+ const copyAction = (value: unknown) =>
199
+ typeof value === 'string' && value !== '' ? (
200
+ <CopyButton label={t('profiles.copy')} value={value} />
201
+ ) : undefined;
202
+
203
+ return (
204
+ <>
205
+ {/* The scrim only exists while open, so it never eats clicks on the table. */}
206
+ {open && (
207
+ <button
208
+ type="button"
209
+ aria-label={t('common.close')}
210
+ onClick={onClose}
211
+ className="fixed inset-0 z-20 cursor-default bg-gray-950/20 dark:bg-gray-950/50"
212
+ />
213
+ )}
214
+
215
+ <aside
216
+ aria-hidden={!open}
217
+ className={`border-border bg-card fixed inset-y-0 right-0 z-30 flex w-96 max-w-full flex-col border-l shadow-xl transition-transform duration-200 ease-out ${
218
+ open ? 'translate-x-0' : 'translate-x-full'
219
+ }`}
220
+ >
221
+ {/* No bottom border: the first section's inset top border draws the divider. */}
222
+ <div className="flex h-14 shrink-0 items-center gap-3 px-5">
223
+ {/* Keyed by profile so a stale image error never sticks to the next person. */}
224
+ <Avatar
225
+ key={profile?.id}
226
+ picture={prop('picture')}
227
+ label={name ?? email ?? profile?.id ?? '?'}
228
+ />
229
+ <div className="min-w-0 flex-1">
230
+ <div className="truncate text-sm font-semibold">
231
+ {name ?? email ?? profile?.id ?? ''}
232
+ </div>
233
+ <div className="text-muted truncate text-xs">
234
+ {name !== undefined ? (email ?? profile?.id ?? '') : (profile?.id ?? '')}
235
+ </div>
236
+ </div>
237
+ <button
238
+ type="button"
239
+ onClick={onClose}
240
+ aria-label={t('common.close')}
241
+ className="text-muted hover:bg-hover hover:text-primary flex size-8 shrink-0 items-center justify-center rounded-lg transition-colors"
242
+ style={superellipse}
243
+ >
244
+ <X className="size-4" strokeWidth={2} />
245
+ </button>
246
+ </div>
247
+
248
+ <div className="min-h-0 flex-1 overflow-auto px-5">
249
+ {/* No top padding: the first section's border should sit right under the header. */}
250
+ <div className="pb-4">
251
+ <Section
252
+ title={t('profiles.sections.user')}
253
+ open={!closed.user}
254
+ onToggle={() => toggle('user')}
255
+ >
256
+ <Row label={t('profiles.id')} value={profile?.id} action={copyAction(profile?.id)} />
257
+ <Row label={t('profiles.fields.name')} value={name} action={copyAction(name)} />
258
+ <Row label={t('profiles.email')} value={email} action={copyAction(email)} />
259
+ <Row
260
+ label={t('profiles.fields.company')}
261
+ value={prop('company')}
262
+ action={copyAction(prop('company'))}
263
+ />
264
+ </Section>
265
+
266
+ <Section
267
+ title={t('profiles.sections.source')}
268
+ open={!closed.source}
269
+ onToggle={() => toggle('source')}
270
+ >
271
+ {SOURCE_FIELDS.map((key) => {
272
+ const value = prop(key);
273
+ const flag =
274
+ key === 'country' && typeof value === 'string' && value.length === 2 ? (
275
+ /*
276
+ * Inset hairline: all-white flags (JP, …) need an edge on a
277
+ * light card. The box is exactly 3:2 like the SVGs, so the
278
+ * flag fills it and the ring sits flush on the flag's edge
279
+ * — a mismatched ratio letterboxes and detaches the ring.
280
+ */
281
+ <Flag
282
+ code={value}
283
+ className="h-3 w-[18px] shrink-0 rounded-[2px] ring-1 ring-gray-950/20 ring-inset dark:ring-white/20"
284
+ />
285
+ ) : undefined;
286
+ return (
287
+ <Row key={key} label={t(`profiles.fields.${key}`)} value={value} leading={flag} />
288
+ );
289
+ })}
290
+ </Section>
291
+
292
+ <Section
293
+ title={t('profiles.sections.device')}
294
+ open={!closed.device}
295
+ onToggle={() => toggle('device')}
296
+ >
297
+ {DEVICE_FIELDS.map((key) => (
298
+ <Row key={key} label={t(`profiles.fields.${key}`)} value={prop(key)} />
299
+ ))}
300
+ </Section>
301
+
302
+ <Section
303
+ title={t('profiles.sections.utm')}
304
+ open={!closed.utm}
305
+ onToggle={() => toggle('utm')}
306
+ >
307
+ {(utmKeys.length > 0
308
+ ? utmKeys
309
+ : ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content']
310
+ ).map((key) => (
311
+ <Row key={key} label={key} value={prop(key)} />
312
+ ))}
313
+ </Section>
314
+
315
+ {others.length > 0 && (
316
+ <Section
317
+ title={t('profiles.sections.others')}
318
+ open={!closed.others}
319
+ onToggle={() => toggle('others')}
320
+ >
321
+ {others.map(([key, value]) => (
322
+ <Row key={key} label={key} value={value} />
323
+ ))}
324
+ </Section>
325
+ )}
326
+ </div>
327
+ </div>
328
+ </aside>
329
+ </>
330
+ );
331
+ }