@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,403 @@
1
+ import type { ConditionIR, NodeIR, WorkflowIR } from '@shware/workflow';
2
+ import type { NodeStats } from '../config';
3
+
4
+ /**
5
+ * Tree layout: IR → react-flow nodes and edges.
6
+ *
7
+ * IR is a structured tree rather than an arbitrary graph, so dagre/elkjs are
8
+ * unnecessary: a vertical spine, branch columns fanning out left and right,
9
+ * and rejoin edges — customer.io's look, computed in a single recursion.
10
+ * Layout is a pure function: the same IR (plus optional stats) always yields
11
+ * the same picture.
12
+ */
13
+
14
+ export type NodeCategory = 'trigger' | 'message' | 'delay' | 'control' | 'data' | 'exit';
15
+
16
+ export type NodeIcon =
17
+ | 'trigger'
18
+ | 'email'
19
+ | 'sms'
20
+ | 'push'
21
+ | 'in_app'
22
+ | 'slack'
23
+ | 'discord'
24
+ | 'survey'
25
+ | 'delay'
26
+ | 'time_window'
27
+ | 'wait_until'
28
+ | 'branch'
29
+ | 'filter'
30
+ | 'cohort'
31
+ | 'exit'
32
+ | 'send_event'
33
+ | 'action';
34
+
35
+ export interface CanvasNodeData extends Record<string, unknown> {
36
+ title: string;
37
+ subtitle?: string;
38
+ category: NodeCategory;
39
+ /** card: the regular card (icon + title + subtitle + count badge); icon: icon-only pill (exit). */
40
+ variant: 'card' | 'icon';
41
+ icon: NodeIcon;
42
+ /** How many users currently sit on this node (runtime stats, injected via `stats`). */
43
+ count?: number;
44
+ }
45
+
46
+ /** Card sizes: the single source shared by layout and renderer, all on the 16/8 grid. */
47
+ export const CARD_SIZE = { w: 288, h: 64 } as const;
48
+ /**
49
+ * The icon variant renders as an auto-width pill, so only its height is known
50
+ * here. It is laid out in a card-width box and centred inside it: guessing the
51
+ * pill's width instead put its visual centre a couple of pixels off the column
52
+ * the connectors are drawn down, which reads as a crooked line.
53
+ */
54
+ export const ICON_SIZE = { w: CARD_SIZE.w, h: 32 } as const;
55
+
56
+ export interface CanvasNode {
57
+ id: string;
58
+ type: 'wf';
59
+ position: { x: number; y: number };
60
+ data: CanvasNodeData;
61
+ }
62
+
63
+ export interface CanvasEdge {
64
+ id: string;
65
+ source: string;
66
+ target: string;
67
+ label?: string;
68
+ /** Label anchor: `target` = the arm's entry corner (real arm); `source` = just below the deciding node (empty pass-through arm). */
69
+ data?: { anchor: 'source' | 'target' };
70
+ }
71
+
72
+ /**
73
+ * Tiered spacing: straight sequences stay tight, forks open up (room for the
74
+ * rounded split, the hanging labels, and a future insert-action button), and
75
+ * rejoins get slightly more than a sequence gap so merge lines have space.
76
+ */
77
+ const W = CARD_SIZE.w;
78
+ const VGAP = 48; // node → node inside a sequence
79
+ const FORK_GAP = 112; // branching node's bottom → arm top (stem splits at 28, labels hang at 56)
80
+ const REJOIN_EXTRA = 24; // added on top of VGAP at a rejoin
81
+ const HGAP = 88;
82
+
83
+ function nodeSize(n: NodeIR): { w: number; h: number } {
84
+ return n.type === 'exit' ? ICON_SIZE : CARD_SIZE;
85
+ }
86
+
87
+ /** Common abstraction for nodes with child groups: branch cases/otherwise, cohort arms, waitUntil's timeout lane. */
88
+ interface Group {
89
+ label: string;
90
+ nodes: NodeIR[];
91
+ }
92
+
93
+ /** Property operator → label symbol (math signs for eq/ne/gt/lt; set and text operators keep short words). */
94
+ const OP_LABEL: Record<string, string> = {
95
+ eq: '=',
96
+ ne: '≠',
97
+ gt: '>',
98
+ lt: '<',
99
+ between: 'between',
100
+ in_array: 'in',
101
+ not_in_array: 'not in',
102
+ exists: 'exists',
103
+ not_exists: 'not exists',
104
+ contains: 'contains',
105
+ not_contains: 'not contains',
106
+ };
107
+
108
+ function conditionLabel(c: ConditionIR, fallback: string): string {
109
+ if (c.type === 'segment') return c.segment;
110
+ if (c.type === 'not') return `not ${conditionLabel(c.condition, fallback)}`;
111
+ if (c.type === 'property') {
112
+ const op = OP_LABEL[c.op] ?? c.op;
113
+ const value =
114
+ c.op === 'between'
115
+ ? `${c.values?.[0]} – ${c.values?.[1]}`
116
+ : c.op === 'in_array' || c.op === 'not_in_array'
117
+ ? `[${c.values?.join(', ')}]`
118
+ : c.value !== undefined
119
+ ? String(c.value)
120
+ : '';
121
+ return value === '' ? `${c.path} ${op}` : `${c.path} ${op} ${value}`;
122
+ }
123
+ if (c.type === 'performed') return `did ${c.event}`;
124
+ if (c.type === 'reachable') return `reachable by ${c.channel}`;
125
+ if (c.type === 'and' || c.type === 'or') {
126
+ return c.conditions.map((child) => conditionLabel(child, fallback)).join(` ${c.type} `);
127
+ }
128
+ return fallback;
129
+ }
130
+
131
+ function groupsOf(n: NodeIR): Group[] | null {
132
+ switch (n.type) {
133
+ case 'branch': {
134
+ const groups = n.cases.map((c, i) => ({
135
+ label: c.label ?? conditionLabel(c.condition, `case ${i + 1}`),
136
+ nodes: c.flow,
137
+ }));
138
+ groups.push({ label: 'else', nodes: n.otherwise ?? [] });
139
+ return groups;
140
+ }
141
+ case 'cohort':
142
+ return n.arms.map((a) => ({ label: `${a.name} · ${a.weight}%`, nodes: a.flow }));
143
+ case 'wait_until':
144
+ if (Array.isArray(n.onTimeout)) {
145
+ return [
146
+ { label: 'met', nodes: [] },
147
+ { label: 'timeout', nodes: n.onTimeout },
148
+ ];
149
+ }
150
+ return null;
151
+ default:
152
+ return null;
153
+ }
154
+ }
155
+
156
+ function seqWidth(nodes: NodeIR[]): number {
157
+ return nodes.length === 0 ? W : Math.max(...nodes.map(nodeWidth));
158
+ }
159
+
160
+ function nodeWidth(n: NodeIR): number {
161
+ const groups = groupsOf(n);
162
+ if (!groups) return nodeSize(n).w;
163
+ return (
164
+ groups.reduce((sum, g) => sum + Math.max(W, seqWidth(g.nodes)), 0) + HGAP * (groups.length - 1)
165
+ );
166
+ }
167
+
168
+ const CHANNEL_TITLE: Record<string, string> = {
169
+ email: 'Email',
170
+ sms: 'SMS',
171
+ push: 'Push Notification',
172
+ in_app: 'In-App Message',
173
+ slack: 'Slack Message',
174
+ discord: 'Discord Message',
175
+ survey: 'Survey',
176
+ };
177
+
178
+ function nodeData(n: NodeIR): CanvasNodeData {
179
+ switch (n.type) {
180
+ case 'message':
181
+ return {
182
+ title: CHANNEL_TITLE[n.channel] ?? n.channel,
183
+ subtitle: n.devices === 'latest' ? `${n.template} · latest device` : n.template,
184
+ category: 'message',
185
+ variant: 'card',
186
+ icon: n.channel,
187
+ };
188
+ case 'delay':
189
+ return {
190
+ title: 'Time Delay',
191
+ subtitle: `Wait ${n.duration.value}`,
192
+ category: 'delay',
193
+ variant: 'card',
194
+ icon: 'delay',
195
+ };
196
+ case 'random_delay':
197
+ return {
198
+ title: 'Randomized Delay',
199
+ subtitle: `Wait ${n.min.value} – ${n.max.value}`,
200
+ category: 'delay',
201
+ variant: 'card',
202
+ icon: 'delay',
203
+ };
204
+ case 'time_window':
205
+ return {
206
+ title: 'Time Window',
207
+ subtitle: `${n.days.join(' ')} ${n.between[0]}–${n.between[1]}`,
208
+ category: 'delay',
209
+ variant: 'card',
210
+ icon: 'time_window',
211
+ };
212
+ case 'wait_until':
213
+ return {
214
+ title: `Wait until ${conditionLabel(n.condition, '…')}`,
215
+ subtitle: `timeout ${n.timeout.value}`,
216
+ category: 'delay',
217
+ variant: 'card',
218
+ icon: 'wait_until',
219
+ };
220
+ case 'branch': {
221
+ const arms = n.cases.length + 1;
222
+ return {
223
+ title: n.label ?? (n.cases.length > 1 ? 'Multi-Split Branch' : 'True/False Branch'),
224
+ subtitle: `${arms} arms, first match`,
225
+ category: 'control',
226
+ variant: 'card',
227
+ icon: 'branch',
228
+ };
229
+ }
230
+ case 'filter':
231
+ return {
232
+ title: 'Filter',
233
+ subtitle: n.reason ?? 'only continue if…',
234
+ category: 'control',
235
+ variant: 'card',
236
+ icon: 'filter',
237
+ };
238
+ case 'cohort':
239
+ return {
240
+ title: 'Random Cohort',
241
+ subtitle: n.arms.map((a) => `${a.name} ${a.weight}%`).join(' / '),
242
+ category: 'control',
243
+ variant: 'card',
244
+ icon: 'cohort',
245
+ };
246
+ case 'exit':
247
+ return {
248
+ title: 'Exit',
249
+ // reason stays off the canvas and lives in the hover tooltip
250
+ ...(n.reason !== undefined ? { subtitle: n.reason } : {}),
251
+ category: 'exit',
252
+ variant: 'icon',
253
+ icon: 'exit',
254
+ };
255
+ case 'send_event':
256
+ return {
257
+ title: 'Send Event',
258
+ subtitle: n.event,
259
+ category: 'data',
260
+ variant: 'card',
261
+ icon: 'send_event',
262
+ };
263
+ case 'action':
264
+ return {
265
+ title: 'Custom Action',
266
+ subtitle: n.action,
267
+ category: 'data',
268
+ variant: 'card',
269
+ icon: 'action',
270
+ };
271
+ }
272
+ }
273
+
274
+ interface Tail {
275
+ id: string;
276
+ label?: string;
277
+ anchor?: 'source' | 'target';
278
+ }
279
+
280
+ export function layout(
281
+ ir: WorkflowIR,
282
+ stats?: NodeStats
283
+ ): { nodes: CanvasNode[]; edges: CanvasEdge[] } {
284
+ const nodes: CanvasNode[] = [];
285
+ const edges: CanvasEdge[] = [];
286
+ let edgeSeq = 0;
287
+
288
+ const addNode = (id: string, x: number, y: number, data: CanvasNodeData): void => {
289
+ const count = stats?.[id];
290
+ nodes.push({
291
+ id,
292
+ type: 'wf',
293
+ position: { x, y },
294
+ data: count === undefined ? data : { ...data, count },
295
+ });
296
+ };
297
+
298
+ const addEdges = (tails: Tail[], target: string): void => {
299
+ for (const t of tails) {
300
+ edges.push({
301
+ id: `e${edgeSeq++}`,
302
+ source: t.id,
303
+ target,
304
+ ...(t.label !== undefined ? { label: t.label } : {}),
305
+ ...(t.anchor !== undefined ? { data: { anchor: t.anchor } } : {}),
306
+ });
307
+ }
308
+ };
309
+
310
+ /** Lay out one sequence recursively: `cx` is the centre line; returns the bottom y and the tails that continue downward. */
311
+ function layoutSeq(
312
+ seq: NodeIR[],
313
+ cx: number,
314
+ y: number,
315
+ incoming: Tail[]
316
+ ): {
317
+ bottom: number;
318
+ tails: Tail[];
319
+ } {
320
+ let curY = y;
321
+ let tails = incoming;
322
+
323
+ for (const n of seq) {
324
+ const size = nodeSize(n);
325
+ addNode(n.id, cx - size.w / 2, curY, nodeData(n));
326
+ addEdges(tails, n.id);
327
+ const bottom = curY + size.h;
328
+
329
+ if (n.type === 'exit') {
330
+ tails = []; // terminal: nothing connects downward
331
+ curY = bottom + VGAP;
332
+ continue;
333
+ }
334
+
335
+ const groups = groupsOf(n);
336
+ if (!groups) {
337
+ tails = [{ id: n.id }];
338
+ curY = bottom + VGAP;
339
+ continue;
340
+ }
341
+
342
+ const widths = groups.map((g) => Math.max(W, seqWidth(g.nodes)));
343
+ const total = widths.reduce((a, b) => a + b, 0) + HGAP * (groups.length - 1);
344
+ let gx = cx - total / 2;
345
+ const groupTop = bottom + FORK_GAP;
346
+ let maxBottom = groupTop;
347
+ const groupTails: Tail[] = [];
348
+
349
+ groups.forEach((g, gi) => {
350
+ const center = gx + (widths[gi] ?? W) / 2;
351
+ if (g.nodes.length === 0) {
352
+ // Empty group: the parent rejoins straight down, so anchor the label right below it
353
+ groupTails.push({ id: n.id, label: g.label, anchor: 'source' });
354
+ } else {
355
+ const r = layoutSeq(g.nodes, center, groupTop, [
356
+ { id: n.id, label: g.label, anchor: 'target' },
357
+ ]);
358
+ groupTails.push(...r.tails);
359
+ maxBottom = Math.max(maxBottom, r.bottom);
360
+ }
361
+ gx += (widths[gi] ?? W) + HGAP;
362
+ });
363
+
364
+ tails = groupTails;
365
+ curY = maxBottom + REJOIN_EXTRA;
366
+ }
367
+
368
+ return { bottom: curY, tails };
369
+ }
370
+
371
+ // Trigger node
372
+ const t = ir.trigger;
373
+ const triggerSubtitle =
374
+ t.type === 'event'
375
+ ? `${t.event}${t.filter ? ' · +filter' : ''}`
376
+ : t.type === 'segment'
377
+ ? `enters ${t.segment}`
378
+ : t.type === 'date'
379
+ ? t.at
380
+ : 'webhook';
381
+ addNode('__trigger', -CARD_SIZE.w / 2, 0, {
382
+ title: 'Trigger',
383
+ subtitle: triggerSubtitle,
384
+ category: 'trigger',
385
+ variant: 'card',
386
+ icon: 'trigger',
387
+ });
388
+
389
+ const { bottom, tails } = layoutSeq(ir.flow, 0, CARD_SIZE.h + VGAP, [{ id: '__trigger' }]);
390
+
391
+ // Closing Exit node (customer.io's explicit terminus); unnecessary when every path exits early
392
+ if (tails.length > 0) {
393
+ addNode('__end', -ICON_SIZE.w / 2, bottom, {
394
+ title: 'Exit',
395
+ category: 'exit',
396
+ variant: 'icon',
397
+ icon: 'exit',
398
+ });
399
+ addEdges(tails, '__end');
400
+ }
401
+
402
+ return { nodes, edges };
403
+ }
@@ -0,0 +1,118 @@
1
+ import {
2
+ FloatingFocusManager,
3
+ autoUpdate,
4
+ flip,
5
+ offset,
6
+ shift,
7
+ useClick,
8
+ useDismiss,
9
+ useFloating,
10
+ useInteractions,
11
+ useListNavigation,
12
+ useRole,
13
+ } from '@floating-ui/react';
14
+ import { Ellipsis } from 'lucide-react';
15
+ import { useRef, useState } from 'react';
16
+ import { cn } from '../../utils/cn';
17
+ import { superellipse } from '../corner-shape';
18
+
19
+ /**
20
+ * Row-level overflow menu: a three-dot trigger opening a floating action list.
21
+ * Clicks never reach the row underneath — the trigger stops propagation and
22
+ * the panel renders in place above everything — so a menu inside a clickable
23
+ * table row stays safe.
24
+ */
25
+ export interface MenuItem {
26
+ key: string;
27
+ label: string;
28
+ onSelect: () => void;
29
+ /** Destructive actions render in the danger colour. */
30
+ danger?: boolean;
31
+ }
32
+
33
+ interface Props {
34
+ items: MenuItem[];
35
+ 'aria-label'?: string;
36
+ className?: string;
37
+ }
38
+
39
+ export function Menu({ items, className, ...aria }: Props) {
40
+ const [open, setOpen] = useState(false);
41
+ const [activeIndex, setActiveIndex] = useState<number | null>(null);
42
+
43
+ const { refs, floatingStyles, context } = useFloating({
44
+ open,
45
+ onOpenChange: setOpen,
46
+ placement: 'bottom-end',
47
+ whileElementsMounted: autoUpdate,
48
+ middleware: [offset(4), flip({ padding: 8 }), shift({ padding: 8 })],
49
+ });
50
+
51
+ const listRef = useRef<(HTMLElement | null)[]>([]);
52
+ const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([
53
+ useClick(context),
54
+ useDismiss(context),
55
+ useRole(context, { role: 'menu' }),
56
+ useListNavigation(context, { listRef, activeIndex, onNavigate: setActiveIndex }),
57
+ ]);
58
+
59
+ return (
60
+ <>
61
+ <button
62
+ type="button"
63
+ ref={refs.setReference}
64
+ className={cn(
65
+ 'text-muted hover:bg-hover hover:text-primary flex size-8 items-center justify-center',
66
+ 'rounded-lg transition-colors focus:outline-none',
67
+ className
68
+ )}
69
+ style={superellipse}
70
+ {...aria}
71
+ {...getReferenceProps({
72
+ onClick(e) {
73
+ e.stopPropagation();
74
+ },
75
+ })}
76
+ >
77
+ <Ellipsis size={16} strokeWidth={2} aria-hidden />
78
+ </button>
79
+ {open && (
80
+ <FloatingFocusManager context={context} modal={false}>
81
+ <div
82
+ ref={refs.setFloating}
83
+ style={floatingStyles}
84
+ className="border-border bg-card z-50 min-w-36 rounded-xl border p-1 shadow-lg"
85
+ {...getFloatingProps()}
86
+ >
87
+ {items.map((item, index) => (
88
+ <button
89
+ key={item.key}
90
+ type="button"
91
+ role="menuitem"
92
+ ref={(node) => {
93
+ listRef.current[index] = node;
94
+ }}
95
+ tabIndex={activeIndex === index ? 0 : -1}
96
+ className={cn(
97
+ 'flex w-full items-center rounded-lg px-2.5 py-1.5 text-left text-sm',
98
+ item.danger === true ? 'text-red-500' : 'text-primary',
99
+ activeIndex === index && 'bg-selected'
100
+ )}
101
+ style={superellipse}
102
+ {...getItemProps({
103
+ onClick(e) {
104
+ e.stopPropagation();
105
+ setOpen(false);
106
+ item.onSelect();
107
+ },
108
+ })}
109
+ >
110
+ {item.label}
111
+ </button>
112
+ ))}
113
+ </div>
114
+ </FloatingFocusManager>
115
+ )}
116
+ </>
117
+ );
118
+ }