@shware/workflow-ui 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,65 @@
|
|
|
1
|
+
import { ArrowUpRight } from 'lucide-react';
|
|
2
|
+
import type { CSSProperties, ReactNode, Ref } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { cn } from '../utils/cn';
|
|
5
|
+
import { Button } from './button';
|
|
6
|
+
import { superellipse } from './corner-shape';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The inspector's preview window: a fixed-height box at the head of the card
|
|
10
|
+
* with, when the template is registered, a button beneath it that opens the
|
|
11
|
+
* full preview. What goes in the box is the channel's business.
|
|
12
|
+
*/
|
|
13
|
+
export function ThumbnailWindow({
|
|
14
|
+
ref,
|
|
15
|
+
className,
|
|
16
|
+
style,
|
|
17
|
+
onOpen,
|
|
18
|
+
children,
|
|
19
|
+
}: {
|
|
20
|
+
ref?: Ref<HTMLDivElement>;
|
|
21
|
+
className?: string;
|
|
22
|
+
style?: CSSProperties;
|
|
23
|
+
/** Omit when there is nothing to open — an unregistered template has no page. */
|
|
24
|
+
onOpen?: (() => void) | undefined;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}) {
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
return (
|
|
29
|
+
<div className="mb-4">
|
|
30
|
+
<div
|
|
31
|
+
ref={ref}
|
|
32
|
+
className={cn('border-border h-48 overflow-hidden rounded-xl border', className)}
|
|
33
|
+
style={{ ...superellipse, ...style }}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
{onOpen !== undefined && (
|
|
38
|
+
<Button size="xs" variant="secondary" className="mt-2 w-full gap-1" onClick={onOpen}>
|
|
39
|
+
{t('inspector.openTemplate')}
|
|
40
|
+
<ArrowUpRight className="size-3.5" strokeWidth={2} aria-hidden />
|
|
41
|
+
</Button>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A centred line for a window with nothing to draw: loading, unregistered, or failed. */
|
|
48
|
+
export function ThumbnailStatus({
|
|
49
|
+
tone = 'muted',
|
|
50
|
+
children,
|
|
51
|
+
}: {
|
|
52
|
+
tone?: 'muted' | 'error';
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
}) {
|
|
55
|
+
return (
|
|
56
|
+
<div
|
|
57
|
+
className={cn(
|
|
58
|
+
'flex h-full items-center justify-center px-4 text-center text-xs',
|
|
59
|
+
tone === 'error' ? 'text-red-600 dark:text-red-300' : 'text-muted'
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import type { WorkflowIR } from '@shware/workflow';
|
|
2
|
+
import {
|
|
3
|
+
Background,
|
|
4
|
+
BaseEdge,
|
|
5
|
+
Controls,
|
|
6
|
+
type Edge,
|
|
7
|
+
EdgeLabelRenderer,
|
|
8
|
+
type EdgeProps,
|
|
9
|
+
Handle,
|
|
10
|
+
type Node,
|
|
11
|
+
type NodeProps,
|
|
12
|
+
Position,
|
|
13
|
+
ReactFlow,
|
|
14
|
+
} from '@xyflow/react';
|
|
15
|
+
import {
|
|
16
|
+
AlarmClock,
|
|
17
|
+
AppWindow,
|
|
18
|
+
BellRing,
|
|
19
|
+
CalendarClock,
|
|
20
|
+
ClipboardList,
|
|
21
|
+
Filter,
|
|
22
|
+
GitBranch,
|
|
23
|
+
Hourglass,
|
|
24
|
+
LogOut,
|
|
25
|
+
type LucideIcon,
|
|
26
|
+
Mail,
|
|
27
|
+
MessageCircle,
|
|
28
|
+
MessageSquareText,
|
|
29
|
+
MessagesSquare,
|
|
30
|
+
Send,
|
|
31
|
+
Shuffle,
|
|
32
|
+
SquareFunction,
|
|
33
|
+
User,
|
|
34
|
+
Zap,
|
|
35
|
+
} from 'lucide-react';
|
|
36
|
+
import { type CSSProperties, createContext, useContext, useMemo } from 'react';
|
|
37
|
+
import type { NodeStats } from '../config';
|
|
38
|
+
import { superellipse } from './corner-shape';
|
|
39
|
+
import {
|
|
40
|
+
CARD_SIZE,
|
|
41
|
+
type CanvasEdge,
|
|
42
|
+
type CanvasNode,
|
|
43
|
+
type CanvasNodeData,
|
|
44
|
+
ICON_SIZE,
|
|
45
|
+
type NodeCategory,
|
|
46
|
+
type NodeIcon,
|
|
47
|
+
layout,
|
|
48
|
+
} from './layout';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Read-only workflow canvas: renders IR. Structure is code-owned, so the UI
|
|
52
|
+
* offers no editing.
|
|
53
|
+
*
|
|
54
|
+
* Rendering principle — HTML-first and pixel-exact: node cards and edge labels
|
|
55
|
+
* are always HTML (fonts and line heights on tailwind's scale, and new CSS such
|
|
56
|
+
* as corner-shape is available). SVG is kept only for what react-flow's
|
|
57
|
+
* architecture requires — the connector paths and their endpoint markers — with
|
|
58
|
+
* every parameter passed explicitly. SVG EdgeText is not used: its size follows
|
|
59
|
+
* the font's bounding box and cannot be pinned to exact pixels.
|
|
60
|
+
*/
|
|
61
|
+
export interface WorkflowCanvasProps {
|
|
62
|
+
ir: WorkflowIR;
|
|
63
|
+
/** Node id → users currently waiting there (from the engine's stats API); no badge without it. */
|
|
64
|
+
stats?: NodeStats;
|
|
65
|
+
/**
|
|
66
|
+
* Drives react-flow's own chrome (background dots, zoom controls). The card
|
|
67
|
+
* and connector colours come from CSS variables and follow the host's theme
|
|
68
|
+
* on their own; this is only for the parts react-flow paints itself. Passed
|
|
69
|
+
* in rather than sniffed from the DOM, so an embedding app stays in control.
|
|
70
|
+
*/
|
|
71
|
+
colorMode?: 'light' | 'dark';
|
|
72
|
+
/** Node id to show as selected; pairs with onSelectNode for an inspector panel. */
|
|
73
|
+
selectedId?: string | undefined;
|
|
74
|
+
/** Node clicked, or undefined when the click landed on empty canvas. */
|
|
75
|
+
onSelectNode?: (id: string | undefined) => void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The callback travels by context: react-flow node data should carry serializable data only. */
|
|
79
|
+
/** Same reason: selection is view state, not node data, so it must not enter the layout. */
|
|
80
|
+
const SelectedContext = createContext<string | undefined>(undefined);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* One hue per category, not per icon: six colours make a message, a wait and a
|
|
84
|
+
* branch tell themselves apart at a glance; fifteen would just be noise. Values
|
|
85
|
+
* live in CSS so they shift with the theme.
|
|
86
|
+
*/
|
|
87
|
+
const CATEGORY_COLOR: Record<NodeCategory, string> = {
|
|
88
|
+
trigger: 'var(--color-icon-trigger)',
|
|
89
|
+
message: 'var(--color-icon-message)',
|
|
90
|
+
delay: 'var(--color-icon-delay)',
|
|
91
|
+
control: 'var(--color-icon-control)',
|
|
92
|
+
data: 'var(--color-icon-data)',
|
|
93
|
+
exit: 'var(--color-icon-exit)',
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const ICONS: Record<NodeIcon, LucideIcon> = {
|
|
97
|
+
trigger: Zap,
|
|
98
|
+
email: Mail,
|
|
99
|
+
sms: MessageSquareText,
|
|
100
|
+
push: BellRing,
|
|
101
|
+
/*
|
|
102
|
+
* in_app moved off the speech bubble when discord arrived: the channel
|
|
103
|
+
* pickers already spend it on discord (see channel-icon.ts), and two
|
|
104
|
+
* identical glyphs on one canvas stop working as an index. A window is the
|
|
105
|
+
* truer mark for an in-product surface anyway.
|
|
106
|
+
*/
|
|
107
|
+
in_app: AppWindow,
|
|
108
|
+
slack: MessagesSquare,
|
|
109
|
+
discord: MessageCircle,
|
|
110
|
+
survey: ClipboardList,
|
|
111
|
+
delay: AlarmClock,
|
|
112
|
+
time_window: CalendarClock,
|
|
113
|
+
wait_until: Hourglass,
|
|
114
|
+
branch: GitBranch,
|
|
115
|
+
filter: Filter,
|
|
116
|
+
cohort: Shuffle,
|
|
117
|
+
exit: LogOut,
|
|
118
|
+
send_event: Send,
|
|
119
|
+
action: SquareFunction,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A 1px border and nothing else — no drop shadow. It takes --color-edge rather
|
|
124
|
+
* than --color-border, so a card's outline and the connectors between cards are
|
|
125
|
+
* the same weight: on a canvas the wiring is as much a first-class line as the
|
|
126
|
+
* boxes, and one darker step is what replaces the lift the shadow used to give.
|
|
127
|
+
* boxSizing is border-box, so the border sits inside CARD_SIZE and the layout
|
|
128
|
+
* stays on its 8px steps.
|
|
129
|
+
*/
|
|
130
|
+
const baseCard: CSSProperties = {
|
|
131
|
+
boxSizing: 'border-box',
|
|
132
|
+
background: 'var(--color-card)',
|
|
133
|
+
// Longhand, not the `border` shorthand: selection overrides borderColor alone,
|
|
134
|
+
// and React warns when a rerender mixes a shorthand with its longhand.
|
|
135
|
+
borderWidth: 1,
|
|
136
|
+
borderStyle: 'solid',
|
|
137
|
+
borderColor: 'var(--color-edge)',
|
|
138
|
+
fontFamily: "'Inter Variable', Inter, ui-sans-serif, system-ui, sans-serif",
|
|
139
|
+
overflow: 'hidden',
|
|
140
|
+
...superellipse,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** Flex column, centred: top and bottom whitespace stay equal without hand-balancing padding against line height. */
|
|
144
|
+
const cardStyle: CSSProperties = {
|
|
145
|
+
...baseCard,
|
|
146
|
+
display: 'flex',
|
|
147
|
+
flexDirection: 'column',
|
|
148
|
+
justifyContent: 'center',
|
|
149
|
+
width: CARD_SIZE.w,
|
|
150
|
+
height: CARD_SIZE.h,
|
|
151
|
+
padding: '0 16px',
|
|
152
|
+
borderRadius: 12,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The pill sits in a card-width box and centres itself in it. react-flow anchors
|
|
157
|
+
* handles at the measured box's midpoint, so letting the auto-width pill *be*
|
|
158
|
+
* the box put its centre wherever the label happened to end — a couple of
|
|
159
|
+
* pixels off the column the connectors run down.
|
|
160
|
+
*/
|
|
161
|
+
const iconWrapStyle: CSSProperties = {
|
|
162
|
+
display: 'flex',
|
|
163
|
+
justifyContent: 'center',
|
|
164
|
+
width: ICON_SIZE.w,
|
|
165
|
+
height: ICON_SIZE.h,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const iconStyle: CSSProperties = {
|
|
169
|
+
...baseCard,
|
|
170
|
+
display: 'flex',
|
|
171
|
+
alignItems: 'center',
|
|
172
|
+
justifyContent: 'center',
|
|
173
|
+
gap: 6,
|
|
174
|
+
// Width follows content; 12 on the icon side, 16 on the text side — optical balance for icon+label
|
|
175
|
+
width: 'fit-content',
|
|
176
|
+
height: ICON_SIZE.h,
|
|
177
|
+
padding: '0 16px 0 12px',
|
|
178
|
+
// Stadium pill: radius = half the height, with round corners restored (superellipse would flatten the ends)
|
|
179
|
+
borderRadius: 16,
|
|
180
|
+
...({ cornerShape: 'round' } as CSSProperties),
|
|
181
|
+
fontSize: 12,
|
|
182
|
+
lineHeight: '16px',
|
|
183
|
+
fontWeight: 600,
|
|
184
|
+
color: 'var(--color-secondary)',
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const headerStyle: CSSProperties = {
|
|
188
|
+
display: 'flex',
|
|
189
|
+
alignItems: 'center',
|
|
190
|
+
gap: 8,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const titleStyle: CSSProperties = {
|
|
194
|
+
flex: 1,
|
|
195
|
+
minWidth: 0,
|
|
196
|
+
fontSize: 14,
|
|
197
|
+
lineHeight: '20px',
|
|
198
|
+
fontWeight: 600,
|
|
199
|
+
color: 'var(--color-primary)',
|
|
200
|
+
whiteSpace: 'nowrap',
|
|
201
|
+
overflow: 'hidden',
|
|
202
|
+
textOverflow: 'ellipsis',
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const countStyle: CSSProperties = {
|
|
206
|
+
display: 'flex',
|
|
207
|
+
alignItems: 'center',
|
|
208
|
+
gap: 4,
|
|
209
|
+
fontSize: 14,
|
|
210
|
+
lineHeight: '20px',
|
|
211
|
+
fontWeight: 600,
|
|
212
|
+
color: 'var(--color-primary)',
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const subtitleStyle: CSSProperties = {
|
|
216
|
+
marginTop: 4,
|
|
217
|
+
fontSize: 12,
|
|
218
|
+
lineHeight: '16px',
|
|
219
|
+
color: 'var(--color-muted)',
|
|
220
|
+
whiteSpace: 'nowrap',
|
|
221
|
+
overflow: 'hidden',
|
|
222
|
+
textOverflow: 'ellipsis',
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const handleStyle: CSSProperties = { opacity: 0, width: 1, height: 1, minWidth: 0, minHeight: 0 };
|
|
226
|
+
|
|
227
|
+
/** Open-template button: a borderless icon button in the card's top-right corner. */
|
|
228
|
+
type WfNode = Node<CanvasNodeData, 'wf'>;
|
|
229
|
+
|
|
230
|
+
function WorkflowNode({ id, data }: NodeProps<WfNode>) {
|
|
231
|
+
const Icon = ICONS[data.icon];
|
|
232
|
+
/*
|
|
233
|
+
* Selection reads as a focused form control: the card's own border takes the
|
|
234
|
+
* accent and a translucent halo sits outside it. A solid ring on top of the
|
|
235
|
+
* existing border instead looked like two borders stacked.
|
|
236
|
+
*/
|
|
237
|
+
const selected =
|
|
238
|
+
useContext(SelectedContext) === id
|
|
239
|
+
? {
|
|
240
|
+
borderColor: 'var(--color-accent)',
|
|
241
|
+
boxShadow: '0 0 0 3px var(--color-accent-ring)',
|
|
242
|
+
}
|
|
243
|
+
: undefined;
|
|
244
|
+
|
|
245
|
+
const body =
|
|
246
|
+
data.variant === 'icon' ? (
|
|
247
|
+
// Small pill (exit): icon plus a short label, with reason in the tooltip
|
|
248
|
+
<div style={iconWrapStyle}>
|
|
249
|
+
<div
|
|
250
|
+
style={{ ...iconStyle, ...selected }}
|
|
251
|
+
title={data.subtitle ? `${data.title} · ${data.subtitle}` : data.title}
|
|
252
|
+
>
|
|
253
|
+
<Icon size={16} color={CATEGORY_COLOR[data.category]} strokeWidth={2} aria-hidden />
|
|
254
|
+
{data.title}
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
) : (
|
|
258
|
+
<div style={{ ...cardStyle, ...selected }}>
|
|
259
|
+
<div style={headerStyle}>
|
|
260
|
+
<Icon size={16} color={CATEGORY_COLOR[data.category]} strokeWidth={2} aria-hidden />
|
|
261
|
+
<span style={titleStyle}>{data.title}</span>
|
|
262
|
+
{data.count !== undefined && (
|
|
263
|
+
<span style={countStyle}>
|
|
264
|
+
<User size={16} color="var(--color-muted)" strokeWidth={2} aria-hidden />
|
|
265
|
+
{data.count}
|
|
266
|
+
</span>
|
|
267
|
+
)}
|
|
268
|
+
</div>
|
|
269
|
+
{data.subtitle !== undefined && <div style={subtitleStyle}>{data.subtitle}</div>}
|
|
270
|
+
</div>
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<>
|
|
275
|
+
<Handle type="target" position={Position.Top} style={handleStyle} isConnectable={false} />
|
|
276
|
+
{body}
|
|
277
|
+
<Handle type="source" position={Position.Bottom} style={handleStyle} isConnectable={false} />
|
|
278
|
+
</>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const nodeTypes = { wf: WorkflowNode };
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Edge label pill: 32px tall (8-grid), fully rounded, typography on tailwind's
|
|
286
|
+
* text-xs (12px / 16px). Border on --color-edge like every other outline on the
|
|
287
|
+
* canvas — cards, the exit pill and the connectors all draw at one weight.
|
|
288
|
+
*/
|
|
289
|
+
const edgeLabelStyle: CSSProperties = {
|
|
290
|
+
position: 'absolute',
|
|
291
|
+
display: 'flex',
|
|
292
|
+
alignItems: 'center',
|
|
293
|
+
height: 32,
|
|
294
|
+
padding: '0 12px',
|
|
295
|
+
borderRadius: 16,
|
|
296
|
+
background: 'var(--color-card)',
|
|
297
|
+
border: '1px solid var(--color-edge)',
|
|
298
|
+
fontFamily: "'Inter Variable', Inter, ui-sans-serif, system-ui, sans-serif",
|
|
299
|
+
fontSize: 12,
|
|
300
|
+
lineHeight: '16px',
|
|
301
|
+
fontWeight: 500,
|
|
302
|
+
color: 'var(--color-secondary)',
|
|
303
|
+
pointerEvents: 'none',
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
type WfEdge = Edge<{ anchor?: 'source' | 'target' }, 'wf'>;
|
|
307
|
+
|
|
308
|
+
/* ----------------------------- Connector routing ---------------------------- */
|
|
309
|
+
|
|
310
|
+
/** One bend radius for every corner. */
|
|
311
|
+
const BEND = 16;
|
|
312
|
+
/** How far a labelled fork runs straight down before it turns. */
|
|
313
|
+
const FORK_STEM = 28;
|
|
314
|
+
/** Where a label pill hangs below the deciding node. */
|
|
315
|
+
const LABEL_DROP = 56;
|
|
316
|
+
const DOT_R = 3.5;
|
|
317
|
+
/**
|
|
318
|
+
* react-flow anchors its 1px handles just outside the node box, so both ends of
|
|
319
|
+
* a connector stop one pixel short of the card: the line leaves the bottom edge
|
|
320
|
+
* with a visible hairline under it, and the endpoint dot floats above the top
|
|
321
|
+
* edge. Growing the path by this much at each end — and placing the dot's
|
|
322
|
+
* bottom at the same point — closes both seams.
|
|
323
|
+
*/
|
|
324
|
+
const HANDLE_INSET = 1;
|
|
325
|
+
|
|
326
|
+
/** Endpoint dot, sized off DOT_R so the SVG geometry and the HTML marker agree. */
|
|
327
|
+
const dotStyle: CSSProperties = {
|
|
328
|
+
position: 'absolute',
|
|
329
|
+
boxSizing: 'border-box',
|
|
330
|
+
width: DOT_R * 2,
|
|
331
|
+
height: DOT_R * 2,
|
|
332
|
+
borderRadius: '50%',
|
|
333
|
+
background: 'var(--color-card)',
|
|
334
|
+
border: '1px solid var(--color-edge)',
|
|
335
|
+
pointerEvents: 'none',
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Corner control-point factor. A circular arc's classic value is 0.552; pulling
|
|
339
|
+
* it out to 0.9 squares the shoulder off, approximating the look of
|
|
340
|
+
* corner-shape: superellipse. (CSS corner-shape does not apply to SVG paths, so
|
|
341
|
+
* the shape is built by hand from cubic béziers.)
|
|
342
|
+
*/
|
|
343
|
+
const SQUIRCLE = 0.9;
|
|
344
|
+
|
|
345
|
+
/** A superellipse shoulder bending from (x1,y1) through the corner (cx,cy) to (x2,y2). */
|
|
346
|
+
function corner(x1: number, y1: number, cx: number, cy: number, x2: number, y2: number): string {
|
|
347
|
+
const c1x = x1 + (cx - x1) * SQUIRCLE;
|
|
348
|
+
const c1y = y1 + (cy - y1) * SQUIRCLE;
|
|
349
|
+
const c2x = x2 + (cx - x2) * SQUIRCLE;
|
|
350
|
+
const c2y = y2 + (cy - y2) * SQUIRCLE;
|
|
351
|
+
return `C ${c1x} ${c1y}, ${c2x} ${c2y}, ${x2} ${y2}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Three-segment orthogonal route (down, across, down); `splitY` is where the horizontal run sits. */
|
|
355
|
+
function orthogonalPath(sx: number, sy: number, tx: number, ty: number, splitY: number): string {
|
|
356
|
+
const dx = tx - sx;
|
|
357
|
+
if (Math.abs(dx) < 1) return `M ${sx} ${sy} L ${tx} ${ty}`;
|
|
358
|
+
const dir = Math.sign(dx);
|
|
359
|
+
const r = Math.max(0, Math.min(BEND, Math.abs(dx) / 2, splitY - sy, ty - splitY));
|
|
360
|
+
return [
|
|
361
|
+
`M ${sx} ${sy}`,
|
|
362
|
+
`L ${sx} ${splitY - r}`,
|
|
363
|
+
corner(sx, splitY - r, sx, splitY, sx + dir * r, splitY),
|
|
364
|
+
`L ${tx - dir * r} ${splitY}`,
|
|
365
|
+
corner(tx - dir * r, splitY, tx, splitY, tx, splitY + r),
|
|
366
|
+
`L ${tx} ${ty}`,
|
|
367
|
+
].join(' ');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Custom edge with an HTML label: SVG EdgeText's height floats with the font's
|
|
372
|
+
* bounding box, and only HTML can be pinned to exact pixels.
|
|
373
|
+
*
|
|
374
|
+
* Labels anchor one of two ways — never at the path midpoint, since a short
|
|
375
|
+
* horizontal run would disappear entirely behind the pill:
|
|
376
|
+
* - target: above the arm's entry corner (a real arm; customer.io's position)
|
|
377
|
+
* - source: right below the deciding node (empty pass-through arm, which also
|
|
378
|
+
* keeps several merge-edge labels from colliding at the far end)
|
|
379
|
+
*/
|
|
380
|
+
function WorkflowEdge({
|
|
381
|
+
id,
|
|
382
|
+
sourceX,
|
|
383
|
+
sourceY,
|
|
384
|
+
targetX,
|
|
385
|
+
targetY,
|
|
386
|
+
label,
|
|
387
|
+
style,
|
|
388
|
+
data,
|
|
389
|
+
}: EdgeProps<WfEdge>) {
|
|
390
|
+
/*
|
|
391
|
+
* Both label anchors have to end up sitting ON their own line. A target
|
|
392
|
+
* anchor already does — the pill hangs in the target's column, which the path
|
|
393
|
+
* descends through. A source anchor hangs directly under the deciding node,
|
|
394
|
+
* where the path has already turned away at FORK_STEM, leaving the pill
|
|
395
|
+
* stranded in open space; so for those the stem runs all the way down to the
|
|
396
|
+
* pill and turns behind it.
|
|
397
|
+
*/
|
|
398
|
+
const anchoredAtSource = data?.anchor === 'source';
|
|
399
|
+
const splitY = label
|
|
400
|
+
? sourceY + (anchoredAtSource ? LABEL_DROP : FORK_STEM)
|
|
401
|
+
: (sourceY + targetY) / 2;
|
|
402
|
+
const path = orthogonalPath(
|
|
403
|
+
sourceX,
|
|
404
|
+
sourceY - HANDLE_INSET,
|
|
405
|
+
targetX,
|
|
406
|
+
targetY + HANDLE_INSET,
|
|
407
|
+
splitY
|
|
408
|
+
);
|
|
409
|
+
// The label hangs below the split line, pinned to its own arm's column
|
|
410
|
+
const labelPos = { x: anchoredAtSource ? sourceX : targetX, y: sourceY + LABEL_DROP };
|
|
411
|
+
return (
|
|
412
|
+
<>
|
|
413
|
+
<BaseEdge id={id} path={path} style={style} />
|
|
414
|
+
<EdgeLabelRenderer>
|
|
415
|
+
{/*
|
|
416
|
+
Connection point: a hollow dot instead of an arrowhead. Drawn as HTML
|
|
417
|
+
rather than SVG because SVG paints in document order — a long
|
|
418
|
+
pass-through connector running down the same column is a later sibling
|
|
419
|
+
and would draw straight through a dot belonging to an earlier edge.
|
|
420
|
+
The HTML layer sits above every path, so no line can cross it.
|
|
421
|
+
*/}
|
|
422
|
+
<div
|
|
423
|
+
style={{
|
|
424
|
+
...dotStyle,
|
|
425
|
+
transform: `translate(-50%, -50%) translate(${targetX}px, ${targetY + HANDLE_INSET - DOT_R}px)`,
|
|
426
|
+
}}
|
|
427
|
+
/>
|
|
428
|
+
{!!label && (
|
|
429
|
+
<div
|
|
430
|
+
style={{
|
|
431
|
+
...edgeLabelStyle,
|
|
432
|
+
transform: `translate(-50%, -50%) translate(${labelPos.x}px, ${labelPos.y}px)`,
|
|
433
|
+
}}
|
|
434
|
+
>
|
|
435
|
+
{label}
|
|
436
|
+
</div>
|
|
437
|
+
)}
|
|
438
|
+
</EdgeLabelRenderer>
|
|
439
|
+
</>
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const edgeTypes = { wf: WorkflowEdge };
|
|
444
|
+
|
|
445
|
+
export function WorkflowCanvas({
|
|
446
|
+
ir,
|
|
447
|
+
stats,
|
|
448
|
+
colorMode = 'light',
|
|
449
|
+
selectedId,
|
|
450
|
+
onSelectNode,
|
|
451
|
+
}: WorkflowCanvasProps) {
|
|
452
|
+
const { nodes, edges } = useMemo(() => layout(ir, stats), [ir, stats]);
|
|
453
|
+
return (
|
|
454
|
+
<SelectedContext value={selectedId}>
|
|
455
|
+
<CanvasSurface
|
|
456
|
+
nodes={nodes}
|
|
457
|
+
edges={edges}
|
|
458
|
+
colorMode={colorMode}
|
|
459
|
+
{...(onSelectNode !== undefined ? { onSelectNode } : {})}
|
|
460
|
+
/>
|
|
461
|
+
</SelectedContext>
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function CanvasSurface({
|
|
466
|
+
nodes,
|
|
467
|
+
edges,
|
|
468
|
+
colorMode,
|
|
469
|
+
onSelectNode,
|
|
470
|
+
}: {
|
|
471
|
+
nodes: CanvasNode[];
|
|
472
|
+
edges: CanvasEdge[];
|
|
473
|
+
colorMode: 'light' | 'dark';
|
|
474
|
+
onSelectNode?: (id: string | undefined) => void;
|
|
475
|
+
}) {
|
|
476
|
+
return (
|
|
477
|
+
<div style={{ width: '100%', height: '100%' }}>
|
|
478
|
+
<ReactFlow
|
|
479
|
+
nodes={nodes}
|
|
480
|
+
edges={edges}
|
|
481
|
+
nodeTypes={nodeTypes}
|
|
482
|
+
edgeTypes={edgeTypes}
|
|
483
|
+
colorMode={colorMode}
|
|
484
|
+
onNodeClick={(_event, node) => onSelectNode?.(node.id)}
|
|
485
|
+
onPaneClick={() => onSelectNode?.(undefined)}
|
|
486
|
+
// Overrides react-flow's own dark surface, which sits between our page and card
|
|
487
|
+
style={{ background: 'var(--color-canvas)' }}
|
|
488
|
+
fitView
|
|
489
|
+
minZoom={0.2}
|
|
490
|
+
nodesDraggable={false}
|
|
491
|
+
nodesConnectable={false}
|
|
492
|
+
elementsSelectable={false}
|
|
493
|
+
defaultEdgeOptions={{
|
|
494
|
+
type: 'wf',
|
|
495
|
+
style: { stroke: 'var(--color-edge)' },
|
|
496
|
+
}}
|
|
497
|
+
>
|
|
498
|
+
<Background gap={16} color="var(--color-grid)" />
|
|
499
|
+
<Controls showInteractive={false} />
|
|
500
|
+
</ReactFlow>
|
|
501
|
+
</div>
|
|
502
|
+
);
|
|
503
|
+
}
|