@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,601 @@
|
|
|
1
|
+
import type { DiscordTemplate, EmailTemplate, PushTemplate, SlackTemplate } from '@shware/workflow';
|
|
2
|
+
import { Minus, Monitor, Moon, Plus, Smartphone, Sun } from 'lucide-react';
|
|
3
|
+
import { type ReactNode, useState } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { cn } from '../utils/cn';
|
|
6
|
+
import {
|
|
7
|
+
type Props,
|
|
8
|
+
type TemplateFailure,
|
|
9
|
+
previewPropsOf,
|
|
10
|
+
resolveDiscord,
|
|
11
|
+
resolvePush,
|
|
12
|
+
resolveSlack,
|
|
13
|
+
} from '../utils/template-content';
|
|
14
|
+
import { superellipse } from './corner-shape';
|
|
15
|
+
import { DiscordPreview } from './discord-preview';
|
|
16
|
+
import { DARK_SIMULATION } from './email-thumbnail';
|
|
17
|
+
import { PushPreview } from './push-preview';
|
|
18
|
+
import { SlackPreview } from './slack-preview';
|
|
19
|
+
import type { TemplateRefInfo } from './template-refs';
|
|
20
|
+
import { Textarea } from './textarea';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Template preview page: the list on the left comes from IR, the react-email
|
|
24
|
+
* component renders on the right. The email render is the caller's (it owns
|
|
25
|
+
* the query); exactly one of `html` and `failure` describes this render.
|
|
26
|
+
*/
|
|
27
|
+
export interface TemplatePreview {
|
|
28
|
+
html?: string;
|
|
29
|
+
subject?: string;
|
|
30
|
+
/** The template refused its props, or failed to render — field paths included. */
|
|
31
|
+
failure?: TemplateFailure;
|
|
32
|
+
/** Anything else that stopped the render. */
|
|
33
|
+
error?: string;
|
|
34
|
+
loading: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type { TemplateFailure } from '../utils/template-content';
|
|
38
|
+
|
|
39
|
+
export interface TemplatesPageProps {
|
|
40
|
+
refs: TemplateRefInfo[];
|
|
41
|
+
/** The project's email registry; keys match the DSL's template keys. */
|
|
42
|
+
emails: Record<string, EmailTemplate | undefined>;
|
|
43
|
+
/** The project's push registry, same contract as `emails` for the push channel. */
|
|
44
|
+
pushes?: Record<string, PushTemplate | undefined>;
|
|
45
|
+
/** The project's Discord and Slack webhook registries. */
|
|
46
|
+
discords?: Record<string, DiscordTemplate | undefined>;
|
|
47
|
+
slacks?: Record<string, SlackTemplate | undefined>;
|
|
48
|
+
/** App identity on the push mockups; defaults to the project title upstream. */
|
|
49
|
+
appName?: string;
|
|
50
|
+
selected: string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Channel of the selected template. One key can be registered in more than
|
|
53
|
+
* one registry (an email and a push both called `checkout_reminder`), so the
|
|
54
|
+
* key alone does not say which one is meant; absent picks the first match.
|
|
55
|
+
*/
|
|
56
|
+
selectedChannel?: string | undefined;
|
|
57
|
+
/** Rendered output for the selected template, produced by the caller. */
|
|
58
|
+
preview: TemplatePreview;
|
|
59
|
+
/** The project's envelope (`emails.from` / `replyTo`): every email is sent with it. */
|
|
60
|
+
emailDefaults?: { from?: string; replyTo?: string };
|
|
61
|
+
/**
|
|
62
|
+
* In-memory props override for the selected template's preview; absent
|
|
63
|
+
* renders the template's own `preview`. Never written anywhere.
|
|
64
|
+
*/
|
|
65
|
+
previewProps?: Props | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Called as the props editor changes (undefined: back to the template's
|
|
68
|
+
* `preview`). The editor only appears when this is provided.
|
|
69
|
+
*/
|
|
70
|
+
onPreviewPropsChange?: (props: Props | undefined) => void;
|
|
71
|
+
/**
|
|
72
|
+
* The preview stage's starting light/dark, normally the studio's own theme.
|
|
73
|
+
* The toolbar toggle overrides it for this visit only — leaving the page
|
|
74
|
+
* drops the override, so the stage always reopens matching the studio.
|
|
75
|
+
*/
|
|
76
|
+
defaultScheme?: 'light' | 'dark';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* One label/value row. A fragment rather than a wrapper so the rows land
|
|
81
|
+
* directly in the parent grid: the label column then sizes to the longest label
|
|
82
|
+
* — a custom header name can be any length and must not wrap — and every row
|
|
83
|
+
* stays aligned with the others. One face, one size throughout.
|
|
84
|
+
*/
|
|
85
|
+
function Field({ label, children }: { label: string; children: ReactNode }) {
|
|
86
|
+
return (
|
|
87
|
+
<>
|
|
88
|
+
<dt className="text-muted whitespace-nowrap">{label}</dt>
|
|
89
|
+
<dd className="text-secondary min-w-0 break-words">{children}</dd>
|
|
90
|
+
</>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* The frame is sized to its document and never scrolls itself — the page is
|
|
96
|
+
* the one scroller. Without this a document whose real height has a
|
|
97
|
+
* fractional part overflows the integer height we set by a fraction of a
|
|
98
|
+
* pixel, which is nothing at all with overlay scrollbars and a permanent bar
|
|
99
|
+
* for anyone whose OS always shows them. The thumbnail carries the same line
|
|
100
|
+
* for the same reason.
|
|
101
|
+
*/
|
|
102
|
+
const NO_SCROLL = '<style>html,body{overflow:hidden}</style>';
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
* Rough dark-mode simulation, the invert-and-rotate trick: emails carry their
|
|
106
|
+
* own fixed colours, so this approximates what Gmail-style forced dark does to
|
|
107
|
+
* them. Images are re-inverted to keep their real colours.
|
|
108
|
+
*/
|
|
109
|
+
/*
|
|
110
|
+
* The explicit white background matters: email bodies are often transparent,
|
|
111
|
+
* and the white behind them is the iframe element's own — outside the
|
|
112
|
+
* document, where the filter cannot reach. Painting it inside makes it flip.
|
|
113
|
+
*/
|
|
114
|
+
/** A refused render: which phase, then every failing field path with its message. */
|
|
115
|
+
export function TemplateFailurePanel({ failure }: { failure: TemplateFailure }) {
|
|
116
|
+
const { t } = useTranslation();
|
|
117
|
+
return (
|
|
118
|
+
<div
|
|
119
|
+
role="alert"
|
|
120
|
+
className="mx-auto max-w-xl rounded-2xl border border-red-200 bg-red-50 p-6 text-sm text-red-700 dark:border-red-400/20 dark:bg-red-400/10 dark:text-red-300"
|
|
121
|
+
style={superellipse}
|
|
122
|
+
>
|
|
123
|
+
<p className="font-medium">{t(`emails.failure.${failure.phase}`)}</p>
|
|
124
|
+
<ul className="mt-2 flex flex-col gap-1">
|
|
125
|
+
{failure.issues.map((issue, index) => (
|
|
126
|
+
<li key={`${issue.path}:${index}`}>
|
|
127
|
+
{issue.path !== '' && <code className="mr-2 font-mono">{issue.path}</code>}
|
|
128
|
+
{issue.message}
|
|
129
|
+
</li>
|
|
130
|
+
))}
|
|
131
|
+
</ul>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The preview props as JSON, editable in memory. Text that is not a JSON
|
|
138
|
+
* object is reported here and handed up as a failure, so the preview never
|
|
139
|
+
* goes on showing the last good render as if it were this one.
|
|
140
|
+
*/
|
|
141
|
+
function PreviewPropsEditor({
|
|
142
|
+
initial,
|
|
143
|
+
onChange,
|
|
144
|
+
onInvalid,
|
|
145
|
+
onReset,
|
|
146
|
+
}: {
|
|
147
|
+
initial: Props;
|
|
148
|
+
onChange: (props: Props) => void;
|
|
149
|
+
onInvalid: (message: string) => void;
|
|
150
|
+
onReset: () => void;
|
|
151
|
+
}) {
|
|
152
|
+
const { t } = useTranslation();
|
|
153
|
+
/*
|
|
154
|
+
* The text is the user's once they type, and derived from `initial` until
|
|
155
|
+
* then — so an HMR change to the template's `preview` still shows here, and
|
|
156
|
+
* the component never remounts mid-edit (a remount loses the caret).
|
|
157
|
+
*/
|
|
158
|
+
const [draft, setDraft] = useState<string | undefined>(undefined);
|
|
159
|
+
const text = draft ?? JSON.stringify(initial, null, 2);
|
|
160
|
+
return (
|
|
161
|
+
<div className="border-border bg-card border-b px-6 py-4">
|
|
162
|
+
<div className="flex items-center justify-between">
|
|
163
|
+
<label htmlFor="preview-props" className="text-muted text-sm">
|
|
164
|
+
{t('emails.previewProps')}
|
|
165
|
+
</label>
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
onClick={() => {
|
|
169
|
+
setDraft(undefined);
|
|
170
|
+
onReset();
|
|
171
|
+
}}
|
|
172
|
+
className="text-muted hover:text-primary text-xs transition-colors"
|
|
173
|
+
>
|
|
174
|
+
{t('emails.previewPropsReset')}
|
|
175
|
+
</button>
|
|
176
|
+
</div>
|
|
177
|
+
<Textarea
|
|
178
|
+
id="preview-props"
|
|
179
|
+
size="sm"
|
|
180
|
+
rows={Math.min(8, Math.max(2, text.split('\n').length))}
|
|
181
|
+
spellCheck={false}
|
|
182
|
+
className="mt-2 w-full font-mono text-xs"
|
|
183
|
+
value={text}
|
|
184
|
+
onChange={(event) => {
|
|
185
|
+
const next = event.target.value;
|
|
186
|
+
setDraft(next);
|
|
187
|
+
let parsed: unknown;
|
|
188
|
+
try {
|
|
189
|
+
parsed = JSON.parse(next);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
onInvalid(error instanceof Error ? error.message : String(error));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
195
|
+
onInvalid(t('emails.previewPropsNotObject'));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
onChange(parsed as Props);
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
<p className="text-muted mt-1.5 text-xs">{t('emails.previewPropsHint')}</p>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** One control on the floating preview toolbar: a round 32px icon button. */
|
|
207
|
+
function ToolButton({
|
|
208
|
+
active = false,
|
|
209
|
+
label,
|
|
210
|
+
onClick,
|
|
211
|
+
children,
|
|
212
|
+
}: {
|
|
213
|
+
active?: boolean;
|
|
214
|
+
label: string;
|
|
215
|
+
onClick: () => void;
|
|
216
|
+
children: ReactNode;
|
|
217
|
+
}) {
|
|
218
|
+
return (
|
|
219
|
+
<button
|
|
220
|
+
type="button"
|
|
221
|
+
title={label}
|
|
222
|
+
aria-label={label}
|
|
223
|
+
aria-pressed={active}
|
|
224
|
+
onClick={onClick}
|
|
225
|
+
className={cn(
|
|
226
|
+
'flex size-8 items-center justify-center rounded-full transition-colors',
|
|
227
|
+
active ? 'bg-selected text-primary' : 'text-muted hover:bg-hover hover:text-primary'
|
|
228
|
+
)}
|
|
229
|
+
>
|
|
230
|
+
{children}
|
|
231
|
+
</button>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function TemplatesPage({
|
|
236
|
+
refs,
|
|
237
|
+
emails,
|
|
238
|
+
pushes = {},
|
|
239
|
+
discords = {},
|
|
240
|
+
slacks = {},
|
|
241
|
+
appName,
|
|
242
|
+
selected,
|
|
243
|
+
selectedChannel,
|
|
244
|
+
preview,
|
|
245
|
+
emailDefaults,
|
|
246
|
+
previewProps,
|
|
247
|
+
onPreviewPropsChange,
|
|
248
|
+
defaultScheme,
|
|
249
|
+
}: TemplatesPageProps) {
|
|
250
|
+
const { t } = useTranslation();
|
|
251
|
+
/* Preview chrome: how the rendered email is framed, not what is in it. */
|
|
252
|
+
/*
|
|
253
|
+
* The stage follows the studio theme until the toggle is clicked; the click
|
|
254
|
+
* is an override held in state only, so a fresh visit follows the theme
|
|
255
|
+
* again — and an untouched stage keeps following live theme switches.
|
|
256
|
+
*/
|
|
257
|
+
const [schemeOverride, setSchemeOverride] = useState<'light' | 'dark' | undefined>(undefined);
|
|
258
|
+
const scheme = schemeOverride ?? defaultScheme ?? 'light';
|
|
259
|
+
const setScheme = setSchemeOverride;
|
|
260
|
+
const [device, setDevice] = useState<'desktop' | 'mobile'>('desktop');
|
|
261
|
+
const [zoom, setZoom] = useState(1);
|
|
262
|
+
/* Exactly the template asked for: an unknown key says so rather than showing another's content. */
|
|
263
|
+
const active = refs.find(
|
|
264
|
+
(ref) =>
|
|
265
|
+
ref.key === selected && (selectedChannel === undefined || ref.channel === selectedChannel)
|
|
266
|
+
);
|
|
267
|
+
/* Editor text that is not a JSON object: shown in place of any render. */
|
|
268
|
+
const [jsonError, setJsonError] = useState<{ for: string; message: string } | undefined>();
|
|
269
|
+
/* Each channel reads its own registry, so a push key never shadows an email one. */
|
|
270
|
+
const isPush = active?.channel === 'push';
|
|
271
|
+
const isEmail = active?.channel === 'email';
|
|
272
|
+
const activeEmail = active !== undefined && isEmail ? emails[active.key] : undefined;
|
|
273
|
+
const activePush = active !== undefined && isPush ? pushes[active.key] : undefined;
|
|
274
|
+
const isDiscord = active?.channel === 'discord';
|
|
275
|
+
const isSlack = active?.channel === 'slack';
|
|
276
|
+
const isChat = isDiscord || isSlack;
|
|
277
|
+
const activeDiscord = active !== undefined && isDiscord ? discords[active.key] : undefined;
|
|
278
|
+
const activeSlack = active !== undefined && isSlack ? slacks[active.key] : undefined;
|
|
279
|
+
const { html, subject, error, loading } = preview;
|
|
280
|
+
const activeId = active === undefined ? '' : `${active.channel}:${active.key}`;
|
|
281
|
+
/* Leaving a template drops its JSON error: coming back remounts the editor with fresh text. */
|
|
282
|
+
if (jsonError !== undefined && jsonError.for !== activeId) setJsonError(undefined);
|
|
283
|
+
const propsFailure: TemplateFailure | undefined =
|
|
284
|
+
jsonError?.for === activeId
|
|
285
|
+
? { phase: 'json', issues: [{ path: '', message: jsonError.message }] }
|
|
286
|
+
: undefined;
|
|
287
|
+
/* Exactly one of these describes this render; a failure is never shown beside a success. */
|
|
288
|
+
const failure = propsFailure ?? preview.failure;
|
|
289
|
+
|
|
290
|
+
/*
|
|
291
|
+
* The notification, from the same validated content a send uses — the props
|
|
292
|
+
* override when there is one, the template's `preview` otherwise.
|
|
293
|
+
*/
|
|
294
|
+
const pushResolution =
|
|
295
|
+
active !== undefined && activePush !== undefined
|
|
296
|
+
? resolvePush(activePush, active.key, previewProps)
|
|
297
|
+
: undefined;
|
|
298
|
+
const push =
|
|
299
|
+
propsFailure === undefined && pushResolution?.ok === true ? pushResolution.push : undefined;
|
|
300
|
+
const pushFailure =
|
|
301
|
+
propsFailure ?? (pushResolution?.ok === false ? pushResolution.failure : undefined);
|
|
302
|
+
|
|
303
|
+
/* A chat message, from the same checked content a send posts. */
|
|
304
|
+
const discordResolution =
|
|
305
|
+
active !== undefined && activeDiscord !== undefined
|
|
306
|
+
? resolveDiscord(activeDiscord, active.key, previewProps)
|
|
307
|
+
: undefined;
|
|
308
|
+
const slackResolution =
|
|
309
|
+
active !== undefined && activeSlack !== undefined
|
|
310
|
+
? resolveSlack(activeSlack, active.key, previewProps)
|
|
311
|
+
: undefined;
|
|
312
|
+
const chatResolution = discordResolution ?? slackResolution;
|
|
313
|
+
const chatFailure =
|
|
314
|
+
propsFailure ?? (chatResolution?.ok === false ? chatResolution.failure : undefined);
|
|
315
|
+
const chatReady = propsFailure === undefined && chatResolution?.ok === true;
|
|
316
|
+
|
|
317
|
+
const editedEntry = isPush
|
|
318
|
+
? activePush
|
|
319
|
+
: isDiscord
|
|
320
|
+
? activeDiscord
|
|
321
|
+
: isSlack
|
|
322
|
+
? activeSlack
|
|
323
|
+
: activeEmail;
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<div className="flex flex-1">
|
|
327
|
+
{/* Preview; the template list lives on the /emails index and the header dropdown. */}
|
|
328
|
+
<section className="bg-page flex min-w-0 flex-1 flex-col">
|
|
329
|
+
{active === undefined ? (
|
|
330
|
+
<div className="text-muted flex flex-1 items-center justify-center text-sm">
|
|
331
|
+
{selected === undefined ? t('emails.empty') : t('emails.notFound', { key: selected })}
|
|
332
|
+
</div>
|
|
333
|
+
) : (
|
|
334
|
+
<>
|
|
335
|
+
{/*
|
|
336
|
+
The envelope: one face, one size, roomy rows — a read-only
|
|
337
|
+
summary reads better as a calm table. Every email goes out with
|
|
338
|
+
the project's envelope; a push's "envelope" is its content.
|
|
339
|
+
*/}
|
|
340
|
+
{((isEmail && activeEmail !== undefined) || push !== undefined) && (
|
|
341
|
+
<div className="border-border bg-card border-b px-6 py-4">
|
|
342
|
+
<dl className="grid grid-cols-[max-content_1fr] gap-x-8 gap-y-2.5 text-sm">
|
|
343
|
+
{isEmail && activeEmail !== undefined && (
|
|
344
|
+
<>
|
|
345
|
+
<Field label={t('emails.from')}>
|
|
346
|
+
{emailDefaults?.from ?? t('common.none')}
|
|
347
|
+
</Field>
|
|
348
|
+
{emailDefaults?.replyTo !== undefined && (
|
|
349
|
+
<Field label={t('emails.replyTo')}>{emailDefaults.replyTo}</Field>
|
|
350
|
+
)}
|
|
351
|
+
<Field label={t('emails.subject')}>{subject ?? activeEmail.subject}</Field>
|
|
352
|
+
</>
|
|
353
|
+
)}
|
|
354
|
+
{push !== undefined && (
|
|
355
|
+
<>
|
|
356
|
+
<Field label={t('emails.contentTitle')}>{push.title}</Field>
|
|
357
|
+
<Field label={t('emails.contentBody')}>{push.body}</Field>
|
|
358
|
+
{push.image !== undefined && (
|
|
359
|
+
<Field label={t('emails.contentImage')}>{push.image}</Field>
|
|
360
|
+
)}
|
|
361
|
+
</>
|
|
362
|
+
)}
|
|
363
|
+
</dl>
|
|
364
|
+
</div>
|
|
365
|
+
)}
|
|
366
|
+
|
|
367
|
+
{onPreviewPropsChange !== undefined && editedEntry !== undefined && (
|
|
368
|
+
<PreviewPropsEditor
|
|
369
|
+
/* A fresh editor per template only: the key must not change while someone types. */
|
|
370
|
+
key={activeId}
|
|
371
|
+
/* What the preview renders: the props handed in, else the template's own `preview`. */
|
|
372
|
+
initial={previewProps ?? previewPropsOf(editedEntry)}
|
|
373
|
+
onChange={(next) => {
|
|
374
|
+
setJsonError(undefined);
|
|
375
|
+
onPreviewPropsChange(next);
|
|
376
|
+
}}
|
|
377
|
+
onInvalid={(message) => setJsonError({ for: activeId, message })}
|
|
378
|
+
onReset={() => {
|
|
379
|
+
setJsonError(undefined);
|
|
380
|
+
onPreviewPropsChange(undefined);
|
|
381
|
+
}}
|
|
382
|
+
/>
|
|
383
|
+
)}
|
|
384
|
+
|
|
385
|
+
{/*
|
|
386
|
+
Dot grid with the workflow canvas's look (its two themes' exact
|
|
387
|
+
canvas/grid colours, 16px gap), marking everything around the
|
|
388
|
+
rendered email as the studio's surface. It follows the toolbar's
|
|
389
|
+
light/dark toggle rather than the studio theme, so flipping the
|
|
390
|
+
simulated client mode visibly flips the whole stage.
|
|
391
|
+
*/}
|
|
392
|
+
<div
|
|
393
|
+
className="relative flex flex-1 flex-col"
|
|
394
|
+
style={{
|
|
395
|
+
backgroundColor: scheme === 'dark' ? '#000' : 'var(--color-gray-50)',
|
|
396
|
+
/* 0.5px radius: react-flow draws its dots at r=0.5 for zoom 1. */
|
|
397
|
+
backgroundImage: `radial-gradient(${
|
|
398
|
+
scheme === 'dark' ? 'var(--color-gray-700)' : 'var(--color-gray-400)'
|
|
399
|
+
} 0.5px, transparent 0.5px)`,
|
|
400
|
+
backgroundSize: '16px 16px',
|
|
401
|
+
}}
|
|
402
|
+
>
|
|
403
|
+
{/* The stage grows with the email and the page scrolls it (see
|
|
404
|
+
__root); the toolbar below rides along as `sticky`. */}
|
|
405
|
+
<div className="flex-1 p-6 pb-4">
|
|
406
|
+
{isChat ? (
|
|
407
|
+
(isDiscord ? activeDiscord : activeSlack) === undefined ? (
|
|
408
|
+
<div
|
|
409
|
+
className="border-border bg-card mx-auto max-w-xl rounded-2xl border border-dashed p-8 text-center"
|
|
410
|
+
style={superellipse}
|
|
411
|
+
>
|
|
412
|
+
<p className="text-primary text-sm font-medium">
|
|
413
|
+
{t('emails.notRegistered')}
|
|
414
|
+
</p>
|
|
415
|
+
<p className="text-muted mt-2 text-sm">
|
|
416
|
+
{t('emails.chatNotRegisteredHint', {
|
|
417
|
+
key: active.key,
|
|
418
|
+
channel: isDiscord ? 'discord' : 'slack',
|
|
419
|
+
})}
|
|
420
|
+
</p>
|
|
421
|
+
</div>
|
|
422
|
+
) : chatFailure !== undefined ? (
|
|
423
|
+
<TemplateFailurePanel failure={chatFailure} />
|
|
424
|
+
) : discordResolution?.ok === true ? (
|
|
425
|
+
<DiscordPreview
|
|
426
|
+
message={discordResolution.message}
|
|
427
|
+
appName={appName ?? 'App'}
|
|
428
|
+
scheme={scheme}
|
|
429
|
+
zoom={zoom}
|
|
430
|
+
/>
|
|
431
|
+
) : slackResolution?.ok === true ? (
|
|
432
|
+
<SlackPreview
|
|
433
|
+
message={slackResolution.message}
|
|
434
|
+
appName={appName ?? 'App'}
|
|
435
|
+
scheme={scheme}
|
|
436
|
+
zoom={zoom}
|
|
437
|
+
/>
|
|
438
|
+
) : null
|
|
439
|
+
) : isPush ? (
|
|
440
|
+
activePush === undefined ? (
|
|
441
|
+
<div
|
|
442
|
+
className="border-border bg-card mx-auto max-w-xl rounded-2xl border border-dashed p-8 text-center"
|
|
443
|
+
style={superellipse}
|
|
444
|
+
>
|
|
445
|
+
<p className="text-primary text-sm font-medium">
|
|
446
|
+
{t('emails.notRegistered')}
|
|
447
|
+
</p>
|
|
448
|
+
<p className="text-muted mt-2 text-sm">
|
|
449
|
+
{t('emails.pushNotRegisteredHint', { key: active.key })}
|
|
450
|
+
</p>
|
|
451
|
+
</div>
|
|
452
|
+
) : pushFailure !== undefined ? (
|
|
453
|
+
<TemplateFailurePanel failure={pushFailure} />
|
|
454
|
+
) : (
|
|
455
|
+
<PushPreview
|
|
456
|
+
appName={appName ?? 'App'}
|
|
457
|
+
title={push?.title ?? ''}
|
|
458
|
+
body={push?.body ?? ''}
|
|
459
|
+
scheme={scheme}
|
|
460
|
+
zoom={zoom}
|
|
461
|
+
/>
|
|
462
|
+
)
|
|
463
|
+
) : activeEmail === undefined ? (
|
|
464
|
+
<div
|
|
465
|
+
className="border-border bg-card mx-auto max-w-xl rounded-2xl border border-dashed p-8 text-center"
|
|
466
|
+
style={superellipse}
|
|
467
|
+
>
|
|
468
|
+
<p className="text-primary text-sm font-medium">{t('emails.notRegistered')}</p>
|
|
469
|
+
<p className="text-muted mt-2 text-sm">
|
|
470
|
+
{t('emails.notRegisteredHint', { key: active.key })}
|
|
471
|
+
</p>
|
|
472
|
+
</div>
|
|
473
|
+
) : failure !== undefined ? (
|
|
474
|
+
<TemplateFailurePanel failure={failure} />
|
|
475
|
+
) : loading ? (
|
|
476
|
+
<div className="text-muted text-center text-sm">{t('emails.rendering')}</div>
|
|
477
|
+
) : error !== undefined ? (
|
|
478
|
+
<div
|
|
479
|
+
className="mx-auto max-w-xl rounded-2xl border border-red-200 bg-red-50 p-6 text-sm text-red-700 dark:border-red-400/20 dark:bg-red-400/10 dark:text-red-300"
|
|
480
|
+
style={superellipse}
|
|
481
|
+
>
|
|
482
|
+
{error}
|
|
483
|
+
</div>
|
|
484
|
+
) : (
|
|
485
|
+
<iframe
|
|
486
|
+
title={`${active.key} preview`}
|
|
487
|
+
srcDoc={`${html ?? ''}${NO_SCROLL}${scheme === 'dark' ? DARK_SIMULATION : ''}`}
|
|
488
|
+
/*
|
|
489
|
+
* Sized to its document rather than the pane, so long emails
|
|
490
|
+
* scroll in the outer container — which can pad past the
|
|
491
|
+
* floating toolbar; an iframe scrolling internally cannot.
|
|
492
|
+
*/
|
|
493
|
+
onLoad={(event) => {
|
|
494
|
+
const frame = event.currentTarget;
|
|
495
|
+
const root = frame.contentDocument?.documentElement ?? undefined;
|
|
496
|
+
if (root === undefined) return;
|
|
497
|
+
/* getBoundingClientRect keeps the fraction scrollHeight rounds off; ceil it. */
|
|
498
|
+
const height = Math.ceil(root.getBoundingClientRect().height);
|
|
499
|
+
if (height > 0) frame.style.height = `${height}px`;
|
|
500
|
+
}}
|
|
501
|
+
/*
|
|
502
|
+
* Square corners — this box IS the email's viewport, not a
|
|
503
|
+
* studio card. Border and fill follow the toolbar's
|
|
504
|
+
* light/dark toggle with the stage, not the studio theme.
|
|
505
|
+
*/
|
|
506
|
+
className="mx-auto min-h-40 border"
|
|
507
|
+
style={{
|
|
508
|
+
borderColor:
|
|
509
|
+
scheme === 'dark' ? 'var(--color-gray-700)' : 'var(--color-gray-300)',
|
|
510
|
+
backgroundColor: '#fff',
|
|
511
|
+
width: device === 'mobile' ? 375 : '100%',
|
|
512
|
+
maxWidth: device === 'mobile' ? 375 : 672,
|
|
513
|
+
transform: `scale(${zoom})`,
|
|
514
|
+
transformOrigin: 'top center',
|
|
515
|
+
}}
|
|
516
|
+
/>
|
|
517
|
+
)}
|
|
518
|
+
</div>
|
|
519
|
+
|
|
520
|
+
{/*
|
|
521
|
+
Floating preview toolbar: client scheme, device width, zoom.
|
|
522
|
+
Sticky rather than absolute — the stage is no longer a fixed
|
|
523
|
+
frame, so anchoring to its bottom would park the toolbar at the
|
|
524
|
+
end of a long email instead of keeping it to hand. The wrapper
|
|
525
|
+
spans the stage and must not swallow clicks meant for it.
|
|
526
|
+
*/}
|
|
527
|
+
{(isChat
|
|
528
|
+
? chatReady
|
|
529
|
+
: isPush
|
|
530
|
+
? push !== undefined
|
|
531
|
+
: activeEmail !== undefined &&
|
|
532
|
+
!loading &&
|
|
533
|
+
error === undefined &&
|
|
534
|
+
failure === undefined) && (
|
|
535
|
+
<div className="pointer-events-none sticky bottom-0 z-10 flex justify-center pt-2 pb-4">
|
|
536
|
+
<div className="border-border bg-card pointer-events-auto flex items-center gap-0.5 rounded-full border p-1 shadow-lg">
|
|
537
|
+
<ToolButton
|
|
538
|
+
active={scheme === 'light'}
|
|
539
|
+
label={t('emails.previewLight')}
|
|
540
|
+
onClick={() => setScheme('light')}
|
|
541
|
+
>
|
|
542
|
+
<Sun size={16} strokeWidth={2} aria-hidden />
|
|
543
|
+
</ToolButton>
|
|
544
|
+
<ToolButton
|
|
545
|
+
active={scheme === 'dark'}
|
|
546
|
+
label={t('emails.previewDark')}
|
|
547
|
+
onClick={() => setScheme('dark')}
|
|
548
|
+
>
|
|
549
|
+
<Moon size={16} strokeWidth={2} aria-hidden />
|
|
550
|
+
</ToolButton>
|
|
551
|
+
{/* Device widths are an email concern; a push shows both platforms, a chat message its client. */}
|
|
552
|
+
{isEmail && (
|
|
553
|
+
<>
|
|
554
|
+
<div className="bg-border mx-1 h-4 w-px" />
|
|
555
|
+
<ToolButton
|
|
556
|
+
active={device === 'desktop'}
|
|
557
|
+
label={t('emails.previewDesktop')}
|
|
558
|
+
onClick={() => setDevice('desktop')}
|
|
559
|
+
>
|
|
560
|
+
<Monitor size={16} strokeWidth={2} aria-hidden />
|
|
561
|
+
</ToolButton>
|
|
562
|
+
<ToolButton
|
|
563
|
+
active={device === 'mobile'}
|
|
564
|
+
label={t('emails.previewMobile')}
|
|
565
|
+
onClick={() => setDevice('mobile')}
|
|
566
|
+
>
|
|
567
|
+
<Smartphone size={16} strokeWidth={2} aria-hidden />
|
|
568
|
+
</ToolButton>
|
|
569
|
+
</>
|
|
570
|
+
)}
|
|
571
|
+
<div className="bg-border mx-1 h-4 w-px" />
|
|
572
|
+
<ToolButton
|
|
573
|
+
label={t('emails.zoomOut')}
|
|
574
|
+
onClick={() => setZoom((level) => Math.max(0.5, level - 0.25))}
|
|
575
|
+
>
|
|
576
|
+
<Minus size={16} strokeWidth={2} aria-hidden />
|
|
577
|
+
</ToolButton>
|
|
578
|
+
<button
|
|
579
|
+
type="button"
|
|
580
|
+
title={t('emails.zoomReset')}
|
|
581
|
+
onClick={() => setZoom(1)}
|
|
582
|
+
className="text-secondary hover:text-primary w-11 text-center text-xs font-medium tabular-nums transition-colors"
|
|
583
|
+
>
|
|
584
|
+
{Math.round(zoom * 100)}%
|
|
585
|
+
</button>
|
|
586
|
+
<ToolButton
|
|
587
|
+
label={t('emails.zoomIn')}
|
|
588
|
+
onClick={() => setZoom((level) => Math.min(1.5, level + 0.25))}
|
|
589
|
+
>
|
|
590
|
+
<Plus size={16} strokeWidth={2} aria-hidden />
|
|
591
|
+
</ToolButton>
|
|
592
|
+
</div>
|
|
593
|
+
</div>
|
|
594
|
+
)}
|
|
595
|
+
</div>
|
|
596
|
+
</>
|
|
597
|
+
)}
|
|
598
|
+
</section>
|
|
599
|
+
</div>
|
|
600
|
+
);
|
|
601
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ComponentProps } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ported from the design system in the template project — same API, so the two
|
|
6
|
+
* stay diffable. Colours resolve through the studio's CSS variables
|
|
7
|
+
* (`--color-textfield`, `--color-placeholder`, `--color-accent`).
|
|
8
|
+
*/
|
|
9
|
+
export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
10
|
+
|
|
11
|
+
interface Props extends Omit<ComponentProps<'textarea'>, 'size'> {
|
|
12
|
+
size?: Size;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const SIZE_STYLE: Record<Size, string> = {
|
|
17
|
+
xs: 'px-2 py-[5px] text-xs rounded-md focus-visible:ring-2',
|
|
18
|
+
sm: 'px-2 py-[7px] text-sm rounded-lg focus-visible:ring-3',
|
|
19
|
+
md: 'px-3 py-[9px] text-sm rounded-xl focus-visible:ring-3',
|
|
20
|
+
lg: 'px-4 py-[11px] text-md rounded-xl focus-visible:ring-4',
|
|
21
|
+
xl: 'px-4 py-[13px] text-lg rounded-2xl focus-visible:ring-4',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function Textarea({ size = 'md', className, ...props }: Props) {
|
|
25
|
+
return (
|
|
26
|
+
<textarea
|
|
27
|
+
{...props}
|
|
28
|
+
className={cn(
|
|
29
|
+
'transition-colors duration-100 focus:outline-none',
|
|
30
|
+
'placeholder-placeholder bg-textfield focus-visible:border-accent border',
|
|
31
|
+
'dark:focus-visible:ring-accent/50 focus-visible:ring-accent/40',
|
|
32
|
+
SIZE_STYLE[size],
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|