@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.
- package/LICENSE +21 -0
- package/README.md +180 -2
- package/dist/assets/iphone-17-pro-DzaacWSl.png +0 -0
- package/dist/assets/pixel-10-pro-back-7MDj1_lz.webp +0 -0
- package/dist/assets/pixel-10-pro-mask-Bi1deQ9Y.webp +0 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +673 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/config.d.mts +247 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +27 -0
- package/dist/config.mjs.map +1 -0
- package/dist/index.d.mts +451 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2722 -0
- package/dist/index.mjs.map +1 -0
- package/dist/postgres.d.mts +34 -0
- package/dist/postgres.d.mts.map +1 -0
- package/dist/postgres.mjs +313 -0
- package/dist/postgres.mjs.map +1 -0
- package/package.json +93 -3
- package/src/app/assets/devices/iphone-17-pro.png +0 -0
- package/src/app/assets/devices/pixel-10-pro-back.webp +0 -0
- package/src/app/assets/devices/pixel-10-pro-mask.webp +0 -0
- package/src/app/assets/flags/AC.svg +1 -0
- package/src/app/assets/flags/AD.svg +1 -0
- package/src/app/assets/flags/AE.svg +1 -0
- package/src/app/assets/flags/AF.svg +1 -0
- package/src/app/assets/flags/AG.svg +1 -0
- package/src/app/assets/flags/AI.svg +1 -0
- package/src/app/assets/flags/AL.svg +1 -0
- package/src/app/assets/flags/AM.svg +1 -0
- package/src/app/assets/flags/AO.svg +1 -0
- package/src/app/assets/flags/AQ.svg +1 -0
- package/src/app/assets/flags/AR.svg +1 -0
- package/src/app/assets/flags/AS.svg +1 -0
- package/src/app/assets/flags/AT.svg +1 -0
- package/src/app/assets/flags/AU.svg +1 -0
- package/src/app/assets/flags/AW.svg +1 -0
- package/src/app/assets/flags/AX.svg +1 -0
- package/src/app/assets/flags/AZ.svg +1 -0
- package/src/app/assets/flags/BA.svg +1 -0
- package/src/app/assets/flags/BB.svg +1 -0
- package/src/app/assets/flags/BD.svg +1 -0
- package/src/app/assets/flags/BE.svg +1 -0
- package/src/app/assets/flags/BF.svg +1 -0
- package/src/app/assets/flags/BG.svg +1 -0
- package/src/app/assets/flags/BH.svg +1 -0
- package/src/app/assets/flags/BI.svg +1 -0
- package/src/app/assets/flags/BJ.svg +1 -0
- package/src/app/assets/flags/BL.svg +1 -0
- package/src/app/assets/flags/BM.svg +1 -0
- package/src/app/assets/flags/BN.svg +1 -0
- package/src/app/assets/flags/BO.svg +1 -0
- package/src/app/assets/flags/BQ-BO.svg +1 -0
- package/src/app/assets/flags/BQ-SA.svg +1 -0
- package/src/app/assets/flags/BQ-SE.svg +1 -0
- package/src/app/assets/flags/BQ.svg +1 -0
- package/src/app/assets/flags/BR.svg +1 -0
- package/src/app/assets/flags/BS.svg +1 -0
- package/src/app/assets/flags/BT.svg +1 -0
- package/src/app/assets/flags/BV.svg +1 -0
- package/src/app/assets/flags/BW.svg +1 -0
- package/src/app/assets/flags/BY.svg +1 -0
- package/src/app/assets/flags/BZ.svg +1 -0
- package/src/app/assets/flags/CA.svg +1 -0
- package/src/app/assets/flags/CC.svg +1 -0
- package/src/app/assets/flags/CD.svg +1 -0
- package/src/app/assets/flags/CF.svg +1 -0
- package/src/app/assets/flags/CG.svg +1 -0
- package/src/app/assets/flags/CH.svg +1 -0
- package/src/app/assets/flags/CI.svg +1 -0
- package/src/app/assets/flags/CK.svg +1 -0
- package/src/app/assets/flags/CL.svg +1 -0
- package/src/app/assets/flags/CM.svg +1 -0
- package/src/app/assets/flags/CN.svg +1 -0
- package/src/app/assets/flags/CO.svg +1 -0
- package/src/app/assets/flags/CR.svg +1 -0
- package/src/app/assets/flags/CU.svg +1 -0
- package/src/app/assets/flags/CV.svg +1 -0
- package/src/app/assets/flags/CW.svg +1 -0
- package/src/app/assets/flags/CX.svg +1 -0
- package/src/app/assets/flags/CY.svg +1 -0
- package/src/app/assets/flags/CZ.svg +1 -0
- package/src/app/assets/flags/DE.svg +1 -0
- package/src/app/assets/flags/DJ.svg +1 -0
- package/src/app/assets/flags/DK.svg +1 -0
- package/src/app/assets/flags/DM.svg +1 -0
- package/src/app/assets/flags/DO.svg +1 -0
- package/src/app/assets/flags/DZ.svg +1 -0
- package/src/app/assets/flags/EC.svg +1 -0
- package/src/app/assets/flags/EE.svg +1 -0
- package/src/app/assets/flags/EG.svg +1 -0
- package/src/app/assets/flags/EH.svg +1 -0
- package/src/app/assets/flags/ER.svg +1 -0
- package/src/app/assets/flags/ES-CT.svg +1 -0
- package/src/app/assets/flags/ES.svg +1 -0
- package/src/app/assets/flags/ET.svg +1 -0
- package/src/app/assets/flags/EU.svg +1 -0
- package/src/app/assets/flags/FI.svg +1 -0
- package/src/app/assets/flags/FJ.svg +1 -0
- package/src/app/assets/flags/FK.svg +1 -0
- package/src/app/assets/flags/FM.svg +1 -0
- package/src/app/assets/flags/FO.svg +1 -0
- package/src/app/assets/flags/FR.svg +1 -0
- package/src/app/assets/flags/GA.svg +1 -0
- package/src/app/assets/flags/GB-ENG.svg +1 -0
- package/src/app/assets/flags/GB-NIR.svg +1 -0
- package/src/app/assets/flags/GB-SCT.svg +1 -0
- package/src/app/assets/flags/GB-WLS.svg +1 -0
- package/src/app/assets/flags/GB.svg +1 -0
- package/src/app/assets/flags/GD.svg +1 -0
- package/src/app/assets/flags/GE.svg +1 -0
- package/src/app/assets/flags/GF.svg +1 -0
- package/src/app/assets/flags/GG.svg +1 -0
- package/src/app/assets/flags/GH.svg +1 -0
- package/src/app/assets/flags/GI.svg +1 -0
- package/src/app/assets/flags/GL.svg +1 -0
- package/src/app/assets/flags/GM.svg +1 -0
- package/src/app/assets/flags/GN.svg +1 -0
- package/src/app/assets/flags/GP.svg +1 -0
- package/src/app/assets/flags/GQ.svg +1 -0
- package/src/app/assets/flags/GR.svg +1 -0
- package/src/app/assets/flags/GS.svg +1 -0
- package/src/app/assets/flags/GT.svg +1 -0
- package/src/app/assets/flags/GU.svg +1 -0
- package/src/app/assets/flags/GW.svg +1 -0
- package/src/app/assets/flags/GY.svg +1 -0
- package/src/app/assets/flags/HK.svg +1 -0
- package/src/app/assets/flags/HM.svg +1 -0
- package/src/app/assets/flags/HN.svg +1 -0
- package/src/app/assets/flags/HR.svg +1 -0
- package/src/app/assets/flags/HT.svg +1 -0
- package/src/app/assets/flags/HU.svg +1 -0
- package/src/app/assets/flags/IC.svg +1 -0
- package/src/app/assets/flags/ID.svg +1 -0
- package/src/app/assets/flags/IE.svg +1 -0
- package/src/app/assets/flags/IL.svg +1 -0
- package/src/app/assets/flags/IM.svg +1 -0
- package/src/app/assets/flags/IN.svg +1 -0
- package/src/app/assets/flags/IO.svg +1 -0
- package/src/app/assets/flags/IQ.svg +1 -0
- package/src/app/assets/flags/IR.svg +1 -0
- package/src/app/assets/flags/IS.svg +1 -0
- package/src/app/assets/flags/IT.svg +1 -0
- package/src/app/assets/flags/JE.svg +1 -0
- package/src/app/assets/flags/JM.svg +1 -0
- package/src/app/assets/flags/JO.svg +1 -0
- package/src/app/assets/flags/JP.svg +1 -0
- package/src/app/assets/flags/KE.svg +1 -0
- package/src/app/assets/flags/KG.svg +1 -0
- package/src/app/assets/flags/KH.svg +1 -0
- package/src/app/assets/flags/KI.svg +1 -0
- package/src/app/assets/flags/KM.svg +1 -0
- package/src/app/assets/flags/KN.svg +1 -0
- package/src/app/assets/flags/KP.svg +1 -0
- package/src/app/assets/flags/KR.svg +1 -0
- package/src/app/assets/flags/KW.svg +1 -0
- package/src/app/assets/flags/KY.svg +1 -0
- package/src/app/assets/flags/KZ.svg +1 -0
- package/src/app/assets/flags/LA.svg +1 -0
- package/src/app/assets/flags/LB.svg +1 -0
- package/src/app/assets/flags/LC.svg +1 -0
- package/src/app/assets/flags/LI.svg +1 -0
- package/src/app/assets/flags/LK.svg +1 -0
- package/src/app/assets/flags/LR.svg +1 -0
- package/src/app/assets/flags/LS.svg +1 -0
- package/src/app/assets/flags/LT.svg +1 -0
- package/src/app/assets/flags/LU.svg +1 -0
- package/src/app/assets/flags/LV.svg +1 -0
- package/src/app/assets/flags/LY.svg +1 -0
- package/src/app/assets/flags/MA.svg +1 -0
- package/src/app/assets/flags/MC.svg +1 -0
- package/src/app/assets/flags/MD.svg +1 -0
- package/src/app/assets/flags/ME.svg +1 -0
- package/src/app/assets/flags/MF.svg +1 -0
- package/src/app/assets/flags/MG.svg +1 -0
- package/src/app/assets/flags/MH.svg +1 -0
- package/src/app/assets/flags/MK.svg +1 -0
- package/src/app/assets/flags/ML.svg +1 -0
- package/src/app/assets/flags/MM.svg +1 -0
- package/src/app/assets/flags/MN.svg +1 -0
- package/src/app/assets/flags/MO.svg +1 -0
- package/src/app/assets/flags/MP.svg +1 -0
- package/src/app/assets/flags/MQ.svg +1 -0
- package/src/app/assets/flags/MR.svg +1 -0
- package/src/app/assets/flags/MS.svg +1 -0
- package/src/app/assets/flags/MT.svg +1 -0
- package/src/app/assets/flags/MU.svg +1 -0
- package/src/app/assets/flags/MV.svg +1 -0
- package/src/app/assets/flags/MW.svg +1 -0
- package/src/app/assets/flags/MX.svg +1 -0
- package/src/app/assets/flags/MY.svg +1 -0
- package/src/app/assets/flags/MZ.svg +1 -0
- package/src/app/assets/flags/NA.svg +1 -0
- package/src/app/assets/flags/NC.svg +1 -0
- package/src/app/assets/flags/NE.svg +1 -0
- package/src/app/assets/flags/NF.svg +1 -0
- package/src/app/assets/flags/NG.svg +1 -0
- package/src/app/assets/flags/NI.svg +1 -0
- package/src/app/assets/flags/NL.svg +1 -0
- package/src/app/assets/flags/NO.svg +1 -0
- package/src/app/assets/flags/NP.svg +1 -0
- package/src/app/assets/flags/NR.svg +1 -0
- package/src/app/assets/flags/NU.svg +1 -0
- package/src/app/assets/flags/NZ.svg +1 -0
- package/src/app/assets/flags/OM.svg +1 -0
- package/src/app/assets/flags/PA.svg +1 -0
- package/src/app/assets/flags/PE.svg +1 -0
- package/src/app/assets/flags/PF.svg +1 -0
- package/src/app/assets/flags/PG.svg +1 -0
- package/src/app/assets/flags/PH.svg +1 -0
- package/src/app/assets/flags/PK.svg +1 -0
- package/src/app/assets/flags/PL.svg +1 -0
- package/src/app/assets/flags/PM.svg +1 -0
- package/src/app/assets/flags/PN.svg +1 -0
- package/src/app/assets/flags/PR.svg +1 -0
- package/src/app/assets/flags/PS.svg +1 -0
- package/src/app/assets/flags/PT.svg +1 -0
- package/src/app/assets/flags/PW.svg +1 -0
- package/src/app/assets/flags/PY.svg +1 -0
- package/src/app/assets/flags/QA.svg +1 -0
- package/src/app/assets/flags/RE.svg +1 -0
- package/src/app/assets/flags/README.md +6 -0
- package/src/app/assets/flags/RO.svg +1 -0
- package/src/app/assets/flags/RS.svg +1 -0
- package/src/app/assets/flags/RU.svg +1 -0
- package/src/app/assets/flags/RW.svg +1 -0
- package/src/app/assets/flags/SA.svg +1 -0
- package/src/app/assets/flags/SB.svg +1 -0
- package/src/app/assets/flags/SC.svg +1 -0
- package/src/app/assets/flags/SD.svg +1 -0
- package/src/app/assets/flags/SE.svg +1 -0
- package/src/app/assets/flags/SG.svg +1 -0
- package/src/app/assets/flags/SH.svg +1 -0
- package/src/app/assets/flags/SI.svg +1 -0
- package/src/app/assets/flags/SJ.svg +1 -0
- package/src/app/assets/flags/SK.svg +1 -0
- package/src/app/assets/flags/SL.svg +1 -0
- package/src/app/assets/flags/SM.svg +1 -0
- package/src/app/assets/flags/SN.svg +1 -0
- package/src/app/assets/flags/SO.svg +1 -0
- package/src/app/assets/flags/SR.svg +1 -0
- package/src/app/assets/flags/SS.svg +1 -0
- package/src/app/assets/flags/ST.svg +1 -0
- package/src/app/assets/flags/SV.svg +1 -0
- package/src/app/assets/flags/SX.svg +1 -0
- package/src/app/assets/flags/SY.svg +1 -0
- package/src/app/assets/flags/SZ.svg +1 -0
- package/src/app/assets/flags/TA.svg +1 -0
- package/src/app/assets/flags/TC.svg +1 -0
- package/src/app/assets/flags/TD.svg +1 -0
- package/src/app/assets/flags/TF.svg +1 -0
- package/src/app/assets/flags/TG.svg +1 -0
- package/src/app/assets/flags/TH.svg +1 -0
- package/src/app/assets/flags/TJ.svg +1 -0
- package/src/app/assets/flags/TK.svg +1 -0
- package/src/app/assets/flags/TL.svg +1 -0
- package/src/app/assets/flags/TM.svg +1 -0
- package/src/app/assets/flags/TN.svg +1 -0
- package/src/app/assets/flags/TO.svg +1 -0
- package/src/app/assets/flags/TR.svg +1 -0
- package/src/app/assets/flags/TT.svg +1 -0
- package/src/app/assets/flags/TV.svg +1 -0
- package/src/app/assets/flags/TW.svg +1 -0
- package/src/app/assets/flags/TZ.svg +1 -0
- package/src/app/assets/flags/UA.svg +1 -0
- package/src/app/assets/flags/UG.svg +1 -0
- package/src/app/assets/flags/UM.svg +1 -0
- package/src/app/assets/flags/US.svg +1 -0
- package/src/app/assets/flags/UY.svg +1 -0
- package/src/app/assets/flags/UZ.svg +1 -0
- package/src/app/assets/flags/VA.svg +1 -0
- package/src/app/assets/flags/VC.svg +1 -0
- package/src/app/assets/flags/VE.svg +1 -0
- package/src/app/assets/flags/VG.svg +1 -0
- package/src/app/assets/flags/VI.svg +1 -0
- package/src/app/assets/flags/VN.svg +1 -0
- package/src/app/assets/flags/VU.svg +1 -0
- package/src/app/assets/flags/WF.svg +1 -0
- package/src/app/assets/flags/WS.svg +1 -0
- package/src/app/assets/flags/XA.svg +1 -0
- package/src/app/assets/flags/XC.svg +1 -0
- package/src/app/assets/flags/XK.svg +1 -0
- package/src/app/assets/flags/XO.svg +1 -0
- package/src/app/assets/flags/YE.svg +1 -0
- package/src/app/assets/flags/YT.svg +1 -0
- package/src/app/assets/flags/ZA.svg +1 -0
- package/src/app/assets/flags/ZM.svg +1 -0
- package/src/app/assets/flags/ZW.svg +1 -0
- package/src/app/email-preview.ts +46 -0
- package/src/app/index.css +203 -0
- package/src/app/index.html +12 -0
- package/src/app/integrations/i18n/react-i18next.d.ts +11 -0
- package/src/app/integrations/i18n/root-provider.tsx +62 -0
- package/src/app/integrations/tanstack-query/devtools.tsx +6 -0
- package/src/app/integrations/tanstack-query/root-provider.tsx +37 -0
- package/src/app/integrations/theme/root-provider.tsx +75 -0
- package/src/app/integrations/toast/toast-provider.tsx +46 -0
- package/src/app/locales/en-US/common.ts +268 -0
- package/src/app/locales/zh-CN/common.ts +263 -0
- package/src/app/main.tsx +40 -0
- package/src/app/page-chrome.tsx +79 -0
- package/src/app/router.tsx +40 -0
- package/src/app/routes/__root.tsx +293 -0
- package/src/app/routes/emails.tsx +199 -0
- package/src/app/routes/home.tsx +87 -0
- package/src/app/routes/index.ts +19 -0
- package/src/app/routes/metrics.tsx +541 -0
- package/src/app/routes/segment-overview.tsx +211 -0
- package/src/app/routes/segments.tsx +236 -0
- package/src/app/routes/settings.tsx +90 -0
- package/src/app/routes/workflows.tsx +348 -0
- package/src/app/studio.ts +16 -0
- package/src/app/svg.d.ts +17 -0
- package/src/app/virtual-config.d.ts +6 -0
- package/src/cli.ts +110 -0
- package/src/components/avatar.tsx +57 -0
- package/src/components/breadcrumb.tsx +49 -0
- package/src/components/button/index.tsx +86 -0
- package/src/components/channel-icon.ts +39 -0
- package/src/components/chat-markup.tsx +109 -0
- package/src/components/corner-shape.ts +13 -0
- package/src/components/date-range.tsx +181 -0
- package/src/components/discord-preview.tsx +165 -0
- package/src/components/dropdown/index.tsx +172 -0
- package/src/components/email-defaults.tsx +40 -0
- package/src/components/email-list.tsx +149 -0
- package/src/components/email-thumbnail.tsx +123 -0
- package/src/components/flag.tsx +40 -0
- package/src/components/input/index.tsx +40 -0
- package/src/components/input/search-input.tsx +24 -0
- package/src/components/layout.ts +403 -0
- package/src/components/menu/index.tsx +118 -0
- package/src/components/metric-card.tsx +321 -0
- package/src/components/modal/index.tsx +70 -0
- package/src/components/nav-drawer.tsx +84 -0
- package/src/components/node-inspector.tsx +242 -0
- package/src/components/profile-drawer.tsx +331 -0
- package/src/components/push-preview.tsx +470 -0
- package/src/components/push-thumbnail.tsx +78 -0
- package/src/components/segment-list.tsx +184 -0
- package/src/components/select/index.tsx +70 -0
- package/src/components/series-chart.tsx +120 -0
- package/src/components/slack-preview.tsx +223 -0
- package/src/components/sparkline.tsx +58 -0
- package/src/components/tabs/index.tsx +45 -0
- package/src/components/template-refs.ts +110 -0
- package/src/components/templates-page.tsx +601 -0
- package/src/components/textarea/index.tsx +37 -0
- package/src/components/thumbnail-window.tsx +65 -0
- package/src/components/workflow-canvas.tsx +503 -0
- package/src/components/workflow-list.tsx +231 -0
- package/src/config.ts +288 -0
- package/src/generate.ts +56 -0
- package/src/index.ts +35 -0
- package/src/postgres.ts +415 -0
- package/src/server/project.ts +290 -0
- package/src/server.ts +500 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/label.ts +12 -0
- package/src/utils/lookup.ts +11 -0
- 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
|
+
}
|