@shware/workflow-ui 1.0.1 → 2.0.1
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/README.md +10 -8
- package/dist/cli.mjs +12 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/config.d.mts +3 -6
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/index.d.mts +4 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +50 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/app/email-preview.ts +26 -5
- package/src/app/integrations/theme/root-provider.tsx +24 -12
- package/src/app/locales/en-US/common.ts +5 -2
- package/src/app/locales/zh-CN/common.ts +5 -2
- package/src/app/routes/emails.tsx +2 -2
- package/src/app/routes/settings.tsx +4 -1
- package/src/app/routes/workflows.tsx +1 -1
- package/src/components/date-range.tsx +10 -2
- package/src/components/dropdown/index.tsx +10 -2
- package/src/components/email-defaults.tsx +15 -7
- package/src/components/flag.tsx +10 -7
- package/src/components/menu/index.tsx +10 -2
- package/src/components/modal/index.tsx +2 -1
- package/src/components/profile-drawer.tsx +29 -15
- package/src/components/slack-preview.tsx +33 -30
- package/src/components/templates-page.tsx +23 -10
- package/src/config.ts +3 -2
- package/src/server/project.ts +7 -13
- package/src/server.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/workflow-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ShwareHQ/shware-sdk.git"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@floating-ui/react": "^0.27.20",
|
|
41
41
|
"@fontsource-variable/inter": "^5.3.0",
|
|
42
42
|
"@react-email/render": "^2.1.1",
|
|
43
|
-
"@shware/workflow": "
|
|
43
|
+
"@shware/workflow": "2.0.0",
|
|
44
44
|
"@tailwindcss/vite": "^4.3.3",
|
|
45
45
|
"@tanstack/react-query": "^5.104.3",
|
|
46
46
|
"@tanstack/react-router": "^1.170.45",
|
package/src/app/email-preview.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { render } from '@react-email/render';
|
|
2
|
-
import type
|
|
2
|
+
import { type EmailConfig, type EmailTemplate, resolveEmail } from '@shware/workflow';
|
|
3
|
+
import { EmailProvider } from '@shware/workflow/email-context';
|
|
3
4
|
import { useQuery } from '@tanstack/react-query';
|
|
4
5
|
import { createElement } from 'react';
|
|
5
6
|
import {
|
|
@@ -25,17 +26,37 @@ export type EmailPreviewResult =
|
|
|
25
26
|
* again, and a refusal is this render's result rather than an error sitting
|
|
26
27
|
* beside the last success. A definition parses its props first (see
|
|
27
28
|
* prepareEmail); a component that throws is a failure too.
|
|
29
|
+
*
|
|
30
|
+
* The component renders inside the `EmailProvider` the Worker's renderer gives it, with the
|
|
31
|
+
* template resolved against the config's `email` the same way (`resolveEmail`): a layout's
|
|
32
|
+
* unsubscribe link is the one the email would be sent with. The resolved URL is in the key, so a
|
|
33
|
+
* changed config default renders again.
|
|
28
34
|
*/
|
|
29
|
-
export function useEmailPreview(
|
|
35
|
+
export function useEmailPreview(
|
|
36
|
+
mod: EmailTemplate | undefined,
|
|
37
|
+
key: string,
|
|
38
|
+
config: EmailConfig,
|
|
39
|
+
props?: Props
|
|
40
|
+
) {
|
|
41
|
+
const email = mod === undefined ? undefined : resolveEmail(mod, config);
|
|
30
42
|
return useQuery({
|
|
31
|
-
queryKey: [
|
|
43
|
+
queryKey: [
|
|
44
|
+
'email-preview',
|
|
45
|
+
key,
|
|
46
|
+
entryIdentity(mod),
|
|
47
|
+
email?.unsubscribeUrl ?? null,
|
|
48
|
+
props ?? null,
|
|
49
|
+
],
|
|
32
50
|
queryFn: async (): Promise<EmailPreviewResult> => {
|
|
33
|
-
if (mod === undefined
|
|
51
|
+
if (mod === undefined || email === undefined) {
|
|
52
|
+
throw new Error(`no email registered for '${key}'`);
|
|
53
|
+
}
|
|
34
54
|
const prepared = prepareEmail(mod, props);
|
|
35
55
|
if (!prepared.ok) return { status: 'invalid', failure: prepared.failure };
|
|
36
56
|
const { component, props: parsed, subject } = prepared.email;
|
|
37
57
|
try {
|
|
38
|
-
|
|
58
|
+
const element = createElement(EmailProvider, { email }, createElement(component, parsed));
|
|
59
|
+
return { status: 'ok', html: await render(element), subject };
|
|
39
60
|
} catch (error) {
|
|
40
61
|
return { status: 'invalid', failure: renderFailure(error) };
|
|
41
62
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ReactNode,
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
useSyncExternalStore,
|
|
9
|
+
} from 'react';
|
|
2
10
|
|
|
3
11
|
/**
|
|
4
12
|
* Light / dark / follow-the-OS, applied as a `dark` class on <html>.
|
|
@@ -21,6 +29,16 @@ function readStored(): Theme {
|
|
|
21
29
|
const prefersDark = () =>
|
|
22
30
|
typeof matchMedia === 'undefined' ? false : matchMedia('(prefers-color-scheme: dark)').matches;
|
|
23
31
|
|
|
32
|
+
function subscribeSystemTheme(onChange: () => void) {
|
|
33
|
+
if (typeof matchMedia === 'undefined') return () => {};
|
|
34
|
+
const query = matchMedia('(prefers-color-scheme: dark)');
|
|
35
|
+
query.addEventListener('change', onChange);
|
|
36
|
+
return () => query.removeEventListener('change', onChange);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const subscribeExplicitTheme = () => () => {};
|
|
40
|
+
const getServerSystemTheme = () => false;
|
|
41
|
+
|
|
24
42
|
/** Runs before React mounts, so the first paint is already the right theme. */
|
|
25
43
|
export function applyStoredTheme() {
|
|
26
44
|
const theme = readStored();
|
|
@@ -42,17 +60,11 @@ const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);
|
|
|
42
60
|
|
|
43
61
|
export function ThemeProvider({ children }: { children: ReactNode }) {
|
|
44
62
|
const [theme, setThemeState] = useState<Theme>(readStored);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const query = matchMedia('(prefers-color-scheme: dark)');
|
|
51
|
-
const onChange = (event: MediaQueryListEvent) => setSystemDark(event.matches);
|
|
52
|
-
query.addEventListener('change', onChange);
|
|
53
|
-
setSystemDark(query.matches);
|
|
54
|
-
return () => query.removeEventListener('change', onChange);
|
|
55
|
-
}, [theme]);
|
|
63
|
+
const systemDark = useSyncExternalStore(
|
|
64
|
+
theme === 'system' ? subscribeSystemTheme : subscribeExplicitTheme,
|
|
65
|
+
prefersDark,
|
|
66
|
+
getServerSystemTheme
|
|
67
|
+
);
|
|
56
68
|
|
|
57
69
|
const resolved = theme === 'system' ? (systemDark ? 'dark' : 'light') : theme;
|
|
58
70
|
|
|
@@ -184,6 +184,7 @@ export default {
|
|
|
184
184
|
subject: 'Subject',
|
|
185
185
|
from: 'From',
|
|
186
186
|
replyTo: 'Reply to',
|
|
187
|
+
unsubscribeUrl: 'Unsubscribe link',
|
|
187
188
|
sentBy: 'Sent by',
|
|
188
189
|
rendering: 'Rendering…',
|
|
189
190
|
contentTitle: 'Title',
|
|
@@ -212,9 +213,11 @@ export default {
|
|
|
212
213
|
slackBlockUnsupported: 'A {{type}} block (not drawn in the preview)',
|
|
213
214
|
},
|
|
214
215
|
settings: {
|
|
215
|
-
emailDefaults: 'Email
|
|
216
|
+
emailDefaults: 'Email',
|
|
216
217
|
emailDefaultsHint:
|
|
217
|
-
'
|
|
218
|
+
'Shared by every email template — email in workflow.config.ts. Each template names its own sender, and its own unsubscribe link overrides this one.',
|
|
219
|
+
quickClick: 'Quick click',
|
|
220
|
+
quickClickValue: 'Within {{ms}} ms of delivery: a weak machine signal',
|
|
218
221
|
title: 'Settings',
|
|
219
222
|
language: 'Language',
|
|
220
223
|
languageHint: 'Applies to the studio interface only.',
|
|
@@ -183,6 +183,7 @@ export default {
|
|
|
183
183
|
subject: '主题',
|
|
184
184
|
from: '发件人',
|
|
185
185
|
replyTo: '回复至',
|
|
186
|
+
unsubscribeUrl: '退订链接',
|
|
186
187
|
sentBy: '发送方',
|
|
187
188
|
rendering: '渲染中…',
|
|
188
189
|
contentTitle: '标题',
|
|
@@ -207,9 +208,11 @@ export default {
|
|
|
207
208
|
slackBlockUnsupported: '{{type}} 块(预览中不绘制)',
|
|
208
209
|
},
|
|
209
210
|
settings: {
|
|
210
|
-
emailDefaults: '
|
|
211
|
+
emailDefaults: '邮件',
|
|
211
212
|
emailDefaultsHint:
|
|
212
|
-
'
|
|
213
|
+
'所有邮件模板共用,对应 workflow.config.ts 的 email。发件人由每个模板自己声明,模板自己的退订链接会覆盖这里的默认值。',
|
|
214
|
+
quickClick: '快速点击',
|
|
215
|
+
quickClickValue: '送达后 {{ms}} 毫秒内:较弱的机器信号',
|
|
213
216
|
title: '设置',
|
|
214
217
|
language: '语言',
|
|
215
218
|
languageHint: '仅影响 studio 界面文案。',
|
|
@@ -130,7 +130,7 @@ function EmailView() {
|
|
|
130
130
|
/* Only email renders a document; every other channel's content is data. */
|
|
131
131
|
const found = lookupTemplate(config, activeChannel, key);
|
|
132
132
|
const selected = found?.channel === 'email' ? found.entry : undefined;
|
|
133
|
-
const { data, error, isPending } = useEmailPreview(selected, key, previewProps);
|
|
133
|
+
const { data, error, isPending } = useEmailPreview(selected, key, config.email, previewProps);
|
|
134
134
|
|
|
135
135
|
return (
|
|
136
136
|
<div className="flex flex-1 flex-col">
|
|
@@ -169,7 +169,7 @@ function EmailView() {
|
|
|
169
169
|
defaultScheme={studioScheme}
|
|
170
170
|
selected={key}
|
|
171
171
|
selectedChannel={activeChannel}
|
|
172
|
-
|
|
172
|
+
emailConfig={config.email}
|
|
173
173
|
previewProps={previewProps}
|
|
174
174
|
onPreviewPropsChange={(props) =>
|
|
175
175
|
setOverride(props === undefined ? undefined : { id, props })
|
|
@@ -68,7 +68,10 @@ function Settings() {
|
|
|
68
68
|
</div>
|
|
69
69
|
</section>
|
|
70
70
|
|
|
71
|
-
<EmailDefaults
|
|
71
|
+
<EmailDefaults
|
|
72
|
+
unsubscribeUrl={config.email.unsubscribeUrl}
|
|
73
|
+
quickClickMs={config.email.tracking?.quickClickMs}
|
|
74
|
+
/>
|
|
72
75
|
|
|
73
76
|
<section
|
|
74
77
|
className="border-border bg-card mt-4 max-w-xl rounded-2xl border p-5"
|
|
@@ -251,7 +251,7 @@ function CanvasTab() {
|
|
|
251
251
|
const message = selected?.type === 'message' ? selected : undefined;
|
|
252
252
|
const emailModule =
|
|
253
253
|
message?.channel === 'email' ? lookup(config.emails, message.template) : undefined;
|
|
254
|
-
const emailPreview = useEmailPreview(emailModule, message?.template ?? '');
|
|
254
|
+
const emailPreview = useEmailPreview(emailModule, message?.template ?? '', config.email);
|
|
255
255
|
/* A push has no document: its notification is drawn into the OS banner. */
|
|
256
256
|
const pushModule =
|
|
257
257
|
message?.channel === 'push' ? lookup(config.pushes, message.template) : undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FloatingFocusManager,
|
|
3
|
+
type ReferenceType,
|
|
3
4
|
autoUpdate,
|
|
4
5
|
flip,
|
|
5
6
|
offset,
|
|
@@ -90,6 +91,13 @@ export function DateRangePicker({ value, onChange, className }: Props) {
|
|
|
90
91
|
whileElementsMounted: autoUpdate,
|
|
91
92
|
middleware: [offset(4), flip({ padding: 8 }), shift({ padding: 8 })],
|
|
92
93
|
});
|
|
94
|
+
const {
|
|
95
|
+
setFloating,
|
|
96
|
+
setReference,
|
|
97
|
+
}: {
|
|
98
|
+
setFloating: (this: void, node: HTMLElement | null) => void;
|
|
99
|
+
setReference: (this: void, node: ReferenceType | null) => void;
|
|
100
|
+
} = refs;
|
|
93
101
|
|
|
94
102
|
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
95
103
|
useClick(context),
|
|
@@ -116,7 +124,7 @@ export function DateRangePicker({ value, onChange, className }: Props) {
|
|
|
116
124
|
return (
|
|
117
125
|
<>
|
|
118
126
|
<Button
|
|
119
|
-
ref={
|
|
127
|
+
ref={setReference}
|
|
120
128
|
size="sm"
|
|
121
129
|
variant="outline"
|
|
122
130
|
className={cn('gap-2 font-normal', className)}
|
|
@@ -130,7 +138,7 @@ export function DateRangePicker({ value, onChange, className }: Props) {
|
|
|
130
138
|
{open && (
|
|
131
139
|
<FloatingFocusManager context={context} modal={false}>
|
|
132
140
|
<div
|
|
133
|
-
ref={
|
|
141
|
+
ref={setFloating}
|
|
134
142
|
style={{ ...floatingStyles, ...superellipse }}
|
|
135
143
|
className="border-border bg-card shadow-card-shadow z-50 w-64 rounded-xl border p-2 shadow-lg"
|
|
136
144
|
{...getFloatingProps()}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FloatingFocusManager,
|
|
3
|
+
type ReferenceType,
|
|
3
4
|
autoUpdate,
|
|
4
5
|
flip,
|
|
5
6
|
offset,
|
|
@@ -63,6 +64,13 @@ export function Dropdown({ value, options, onChange, placeholder, className }: P
|
|
|
63
64
|
}),
|
|
64
65
|
],
|
|
65
66
|
});
|
|
67
|
+
const {
|
|
68
|
+
setFloating,
|
|
69
|
+
setReference,
|
|
70
|
+
}: {
|
|
71
|
+
setFloating: (this: void, node: HTMLElement | null) => void;
|
|
72
|
+
setReference: (this: void, node: ReferenceType | null) => void;
|
|
73
|
+
} = refs;
|
|
66
74
|
|
|
67
75
|
const listRef = useRef<(HTMLElement | null)[]>([]);
|
|
68
76
|
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([
|
|
@@ -78,7 +86,7 @@ export function Dropdown({ value, options, onChange, placeholder, className }: P
|
|
|
78
86
|
return (
|
|
79
87
|
<>
|
|
80
88
|
<Button
|
|
81
|
-
ref={
|
|
89
|
+
ref={setReference}
|
|
82
90
|
size="sm"
|
|
83
91
|
variant="outline"
|
|
84
92
|
className={cn(
|
|
@@ -106,7 +114,7 @@ export function Dropdown({ value, options, onChange, placeholder, className }: P
|
|
|
106
114
|
{open && (
|
|
107
115
|
<FloatingFocusManager context={context} modal={false}>
|
|
108
116
|
<div
|
|
109
|
-
ref={
|
|
117
|
+
ref={setFloating}
|
|
110
118
|
style={floatingStyles}
|
|
111
119
|
className={cn(
|
|
112
120
|
'border-border bg-card z-50 max-w-96 min-w-64 overflow-y-auto rounded-xl border p-1',
|
|
@@ -2,20 +2,28 @@ import { useTranslation } from 'react-i18next';
|
|
|
2
2
|
import { superellipse } from './corner-shape';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* What every email template shares: `email` in workflow.config.ts — the
|
|
6
|
+
* unsubscribe link of templates that name none of their own, and how opens
|
|
7
|
+
* and clicks are judged. Senders are each template's own (its detail page
|
|
8
|
+
* shows them). Read-only — the config is where it changes; the studio
|
|
7
9
|
* refreshes when it does.
|
|
8
10
|
*/
|
|
9
11
|
export interface EmailDefaultsProps {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
unsubscribeUrl?: string | undefined;
|
|
13
|
+
quickClickMs?: number | undefined;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
/** The reporting classifier's default (`email.tracking.quickClickMs`). */
|
|
17
|
+
const QUICK_CLICK_MS = 1_000;
|
|
18
|
+
|
|
19
|
+
export function EmailDefaults({ unsubscribeUrl, quickClickMs }: EmailDefaultsProps) {
|
|
15
20
|
const { t } = useTranslation();
|
|
16
21
|
const rows = [
|
|
17
|
-
{ label: t('emails.
|
|
18
|
-
{
|
|
22
|
+
{ label: t('emails.unsubscribeUrl'), value: unsubscribeUrl },
|
|
23
|
+
{
|
|
24
|
+
label: t('settings.quickClick'),
|
|
25
|
+
value: t('settings.quickClickValue', { ms: quickClickMs ?? QUICK_CLICK_MS }),
|
|
26
|
+
},
|
|
19
27
|
];
|
|
20
28
|
|
|
21
29
|
return (
|
package/src/components/flag.tsx
CHANGED
|
@@ -19,22 +19,25 @@ export interface FlagProps {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function Flag({ code, className }: FlagProps) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const key = `../app/assets/flags/${code.toUpperCase()}.svg`;
|
|
23
|
+
const load = Object.hasOwn(FLAGS, key) ? FLAGS[key] : undefined;
|
|
24
|
+
const [loaded, setLoaded] = useState<{
|
|
25
|
+
load: typeof load;
|
|
26
|
+
Component: ComponentType<SVGProps<SVGSVGElement>>;
|
|
27
|
+
}>();
|
|
26
28
|
|
|
27
29
|
useEffect(() => {
|
|
30
|
+
if (load === undefined) return;
|
|
28
31
|
let alive = true;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (alive) setComponent(() => mod);
|
|
32
|
+
void load().then((Component) => {
|
|
33
|
+
if (alive) setLoaded({ load, Component });
|
|
32
34
|
});
|
|
33
35
|
return () => {
|
|
34
36
|
alive = false;
|
|
35
37
|
};
|
|
36
38
|
}, [load]);
|
|
37
39
|
|
|
40
|
+
const Component = loaded !== undefined && loaded.load === load ? loaded.Component : undefined;
|
|
38
41
|
if (Component === undefined) return null;
|
|
39
42
|
return <Component className={className} aria-hidden />;
|
|
40
43
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FloatingFocusManager,
|
|
3
|
+
type ReferenceType,
|
|
3
4
|
autoUpdate,
|
|
4
5
|
flip,
|
|
5
6
|
offset,
|
|
@@ -47,6 +48,13 @@ export function Menu({ items, className, ...aria }: Props) {
|
|
|
47
48
|
whileElementsMounted: autoUpdate,
|
|
48
49
|
middleware: [offset(4), flip({ padding: 8 }), shift({ padding: 8 })],
|
|
49
50
|
});
|
|
51
|
+
const {
|
|
52
|
+
setFloating,
|
|
53
|
+
setReference,
|
|
54
|
+
}: {
|
|
55
|
+
setFloating: (this: void, node: HTMLElement | null) => void;
|
|
56
|
+
setReference: (this: void, node: ReferenceType | null) => void;
|
|
57
|
+
} = refs;
|
|
50
58
|
|
|
51
59
|
const listRef = useRef<(HTMLElement | null)[]>([]);
|
|
52
60
|
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([
|
|
@@ -60,7 +68,7 @@ export function Menu({ items, className, ...aria }: Props) {
|
|
|
60
68
|
<>
|
|
61
69
|
<button
|
|
62
70
|
type="button"
|
|
63
|
-
ref={
|
|
71
|
+
ref={setReference}
|
|
64
72
|
className={cn(
|
|
65
73
|
'text-muted hover:bg-hover hover:text-primary flex size-8 items-center justify-center',
|
|
66
74
|
'rounded-lg transition-colors focus:outline-none',
|
|
@@ -79,7 +87,7 @@ export function Menu({ items, className, ...aria }: Props) {
|
|
|
79
87
|
{open && (
|
|
80
88
|
<FloatingFocusManager context={context} modal={false}>
|
|
81
89
|
<div
|
|
82
|
-
ref={
|
|
90
|
+
ref={setFloating}
|
|
83
91
|
style={floatingStyles}
|
|
84
92
|
className="border-border bg-card z-50 min-w-36 rounded-xl border p-1 shadow-lg"
|
|
85
93
|
{...getFloatingProps()}
|
|
@@ -32,6 +32,7 @@ export function Modal({ visible = false, className, disabled = false, children,
|
|
|
32
32
|
if (!open && !disabled) onCancel?.();
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
+
const { setFloating }: { setFloating: (this: void, node: HTMLElement | null) => void } = refs;
|
|
35
36
|
|
|
36
37
|
const { getFloatingProps } = useInteractions([
|
|
37
38
|
useDismiss(context, { enabled: !disabled }),
|
|
@@ -48,7 +49,7 @@ export function Modal({ visible = false, className, disabled = false, children,
|
|
|
48
49
|
>
|
|
49
50
|
<FloatingFocusManager context={context}>
|
|
50
51
|
<div
|
|
51
|
-
ref={
|
|
52
|
+
ref={setFloating}
|
|
52
53
|
style={superellipse}
|
|
53
54
|
className={cn(
|
|
54
55
|
'bg-card relative max-h-dvh max-w-dvw overflow-y-auto rounded-3xl',
|
|
@@ -118,7 +118,34 @@ function Row({
|
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
async function copyText(value: string): Promise<boolean> {
|
|
122
|
+
try {
|
|
123
|
+
await navigator.clipboard.writeText(value);
|
|
124
|
+
return true;
|
|
125
|
+
} catch {
|
|
126
|
+
// Clipboard permissions and embedded webviews can require the legacy fallback.
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const area = document.createElement('textarea');
|
|
130
|
+
const previousFocus = document.activeElement;
|
|
131
|
+
area.value = value;
|
|
132
|
+
area.readOnly = true;
|
|
133
|
+
area.style.position = 'fixed';
|
|
134
|
+
area.style.opacity = '0';
|
|
135
|
+
try {
|
|
136
|
+
document.body.append(area);
|
|
137
|
+
area.select();
|
|
138
|
+
// oxlint-disable-next-line typescript/no-deprecated -- Only used when the Clipboard API is unavailable or rejects permission.
|
|
139
|
+
return document.execCommand('copy');
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
} finally {
|
|
143
|
+
area.remove();
|
|
144
|
+
if (previousFocus instanceof HTMLElement) previousFocus.focus();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Copy-to-clipboard tail for identity rows, flipping to a check only after success. */
|
|
122
149
|
function CopyButton({ label, value }: { label: string; value: string }) {
|
|
123
150
|
const [copied, setCopied] = useState(false);
|
|
124
151
|
useEffect(() => {
|
|
@@ -132,20 +159,7 @@ function CopyButton({ label, value }: { label: string; value: string }) {
|
|
|
132
159
|
aria-label={label}
|
|
133
160
|
title={label}
|
|
134
161
|
onClick={() => {
|
|
135
|
-
void (
|
|
136
|
-
try {
|
|
137
|
-
await navigator.clipboard.writeText(value);
|
|
138
|
-
} catch {
|
|
139
|
-
/* Clipboard API can be permission-gated (embedded webviews); fall back. */
|
|
140
|
-
const area = document.createElement('textarea');
|
|
141
|
-
area.value = value;
|
|
142
|
-
document.body.append(area);
|
|
143
|
-
area.select();
|
|
144
|
-
document.execCommand('copy');
|
|
145
|
-
area.remove();
|
|
146
|
-
}
|
|
147
|
-
setCopied(true);
|
|
148
|
-
})();
|
|
162
|
+
void copyText(value).then(setCopied);
|
|
149
163
|
}}
|
|
150
164
|
className="text-muted hover:bg-hover hover:text-primary flex size-6 shrink-0 items-center justify-center rounded-md transition-colors"
|
|
151
165
|
style={superellipse}
|
|
@@ -36,38 +36,39 @@ const textOf = (value: unknown): TextObject | undefined => {
|
|
|
36
36
|
return typeof object.text === 'string' ? (object as TextObject) : undefined;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const linkClass = 'text-[#1d9bd1] hover:underline';
|
|
40
|
+
const Text = ({ value, className }: { value: TextObject | undefined; className?: string }) =>
|
|
41
|
+
value === undefined ? null : (
|
|
42
|
+
<div className={`break-words whitespace-pre-wrap ${className ?? ''}`}>
|
|
43
|
+
{value.type === 'mrkdwn' ? (
|
|
44
|
+
<ChatMarkup text={value.text} dialect="slack" linkClass={linkClass} />
|
|
45
|
+
) : (
|
|
46
|
+
value.text
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
const Button = ({ element, colors }: { element: Element; colors: (typeof PALETTE)['light'] }) => {
|
|
51
|
+
const style = element.style as string | undefined;
|
|
52
|
+
return (
|
|
53
|
+
<span
|
|
54
|
+
className="inline-flex h-8 items-center rounded-lg border px-3 text-[13px] font-bold"
|
|
55
|
+
style={
|
|
56
|
+
style === 'primary'
|
|
57
|
+
? { background: '#007a5a', borderColor: '#007a5a', color: '#fff' }
|
|
58
|
+
: style === 'danger'
|
|
59
|
+
? { background: '#e01e5a', borderColor: '#e01e5a', color: '#fff' }
|
|
60
|
+
: { borderColor: colors.border, color: colors.name }
|
|
61
|
+
}
|
|
62
|
+
>
|
|
63
|
+
{textOf(element.text)?.text}
|
|
64
|
+
</span>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
39
68
|
export function SlackPreview({ message, appName, scheme, zoom }: SlackPreviewProps) {
|
|
40
69
|
const { t } = useTranslation();
|
|
41
70
|
const colors = PALETTE[scheme];
|
|
42
71
|
const name = message.username ?? appName;
|
|
43
|
-
const linkClass = 'text-[#1d9bd1] hover:underline';
|
|
44
|
-
const Text = ({ value, className }: { value: TextObject | undefined; className?: string }) =>
|
|
45
|
-
value === undefined ? null : (
|
|
46
|
-
<div className={`break-words whitespace-pre-wrap ${className ?? ''}`}>
|
|
47
|
-
{value.type === 'mrkdwn' ? (
|
|
48
|
-
<ChatMarkup text={value.text} dialect="slack" linkClass={linkClass} />
|
|
49
|
-
) : (
|
|
50
|
-
value.text
|
|
51
|
-
)}
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
const Button = ({ element }: { element: Element }) => {
|
|
55
|
-
const style = element.style as string | undefined;
|
|
56
|
-
return (
|
|
57
|
-
<span
|
|
58
|
-
className="inline-flex h-8 items-center rounded-lg border px-3 text-[13px] font-bold"
|
|
59
|
-
style={
|
|
60
|
-
style === 'primary'
|
|
61
|
-
? { background: '#007a5a', borderColor: '#007a5a', color: '#fff' }
|
|
62
|
-
: style === 'danger'
|
|
63
|
-
? { background: '#e01e5a', borderColor: '#e01e5a', color: '#fff' }
|
|
64
|
-
: { borderColor: colors.border, color: colors.name }
|
|
65
|
-
}
|
|
66
|
-
>
|
|
67
|
-
{textOf(element.text)?.text}
|
|
68
|
-
</span>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
72
|
|
|
72
73
|
const blocks = (message.blocks ?? []) as Element[];
|
|
73
74
|
return (
|
|
@@ -154,7 +155,9 @@ export function SlackPreview({ message, appName, scheme, zoom }: SlackPreviewPro
|
|
|
154
155
|
className="size-[88px] shrink-0 rounded-lg object-cover"
|
|
155
156
|
/>
|
|
156
157
|
)}
|
|
157
|
-
{accessory?.type === 'button' &&
|
|
158
|
+
{accessory?.type === 'button' && (
|
|
159
|
+
<Button element={accessory} colors={colors} />
|
|
160
|
+
)}
|
|
158
161
|
</div>
|
|
159
162
|
);
|
|
160
163
|
}
|
|
@@ -187,7 +190,7 @@ export function SlackPreview({ message, appName, scheme, zoom }: SlackPreviewPro
|
|
|
187
190
|
{((block.elements as Element[] | undefined) ?? []).map((element, i) =>
|
|
188
191
|
element.type === 'button' ? (
|
|
189
192
|
// oxlint-disable-next-line react/no-array-index-key -- elements are positional
|
|
190
|
-
<Button key={i} element={element} />
|
|
193
|
+
<Button key={i} element={element} colors={colors} />
|
|
191
194
|
) : null
|
|
192
195
|
)}
|
|
193
196
|
</div>
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type DiscordTemplate,
|
|
3
|
+
type EmailConfig,
|
|
4
|
+
type EmailTemplate,
|
|
5
|
+
type PushTemplate,
|
|
6
|
+
type SlackTemplate,
|
|
7
|
+
formatEmailAddress,
|
|
8
|
+
resolveEmail,
|
|
9
|
+
} from '@shware/workflow';
|
|
2
10
|
import { Minus, Monitor, Moon, Plus, Smartphone, Sun } from 'lucide-react';
|
|
3
11
|
import { type ReactNode, useState } from 'react';
|
|
4
12
|
import { useTranslation } from 'react-i18next';
|
|
@@ -56,8 +64,8 @@ export interface TemplatesPageProps {
|
|
|
56
64
|
selectedChannel?: string | undefined;
|
|
57
65
|
/** Rendered output for the selected template, produced by the caller. */
|
|
58
66
|
preview: TemplatePreview;
|
|
59
|
-
/** The
|
|
60
|
-
|
|
67
|
+
/** The config's `email`: an email template's unsubscribe link falls back to its default. */
|
|
68
|
+
emailConfig?: EmailConfig;
|
|
61
69
|
/**
|
|
62
70
|
* In-memory props override for the selected template's preview; absent
|
|
63
71
|
* renders the template's own `preview`. Never written anywhere.
|
|
@@ -242,7 +250,7 @@ export function TemplatesPage({
|
|
|
242
250
|
selected,
|
|
243
251
|
selectedChannel,
|
|
244
252
|
preview,
|
|
245
|
-
|
|
253
|
+
emailConfig,
|
|
246
254
|
previewProps,
|
|
247
255
|
onPreviewPropsChange,
|
|
248
256
|
defaultScheme,
|
|
@@ -270,6 +278,8 @@ export function TemplatesPage({
|
|
|
270
278
|
const isPush = active?.channel === 'push';
|
|
271
279
|
const isEmail = active?.channel === 'email';
|
|
272
280
|
const activeEmail = active !== undefined && isEmail ? emails[active.key] : undefined;
|
|
281
|
+
/* What this template is sent with: its own sender, the unsubscribe link resolved like a send's. */
|
|
282
|
+
const resolved = activeEmail === undefined ? undefined : resolveEmail(activeEmail, emailConfig);
|
|
273
283
|
const activePush = active !== undefined && isPush ? pushes[active.key] : undefined;
|
|
274
284
|
const isDiscord = active?.channel === 'discord';
|
|
275
285
|
const isSlack = active?.channel === 'slack';
|
|
@@ -340,15 +350,18 @@ export function TemplatesPage({
|
|
|
340
350
|
{((isEmail && activeEmail !== undefined) || push !== undefined) && (
|
|
341
351
|
<div className="border-border bg-card border-b px-6 py-4">
|
|
342
352
|
<dl className="grid grid-cols-[max-content_1fr] gap-x-8 gap-y-2.5 text-sm">
|
|
343
|
-
{isEmail && activeEmail !== undefined && (
|
|
353
|
+
{isEmail && activeEmail !== undefined && resolved !== undefined && (
|
|
344
354
|
<>
|
|
345
|
-
<Field label={t('emails.from')}>
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
355
|
+
<Field label={t('emails.from')}>{formatEmailAddress(resolved.from)}</Field>
|
|
356
|
+
{resolved.replyTo !== undefined && (
|
|
357
|
+
<Field label={t('emails.replyTo')}>
|
|
358
|
+
{formatEmailAddress(resolved.replyTo)}
|
|
359
|
+
</Field>
|
|
350
360
|
)}
|
|
351
361
|
<Field label={t('emails.subject')}>{subject ?? activeEmail.subject}</Field>
|
|
362
|
+
<Field label={t('emails.unsubscribeUrl')}>
|
|
363
|
+
{resolved.unsubscribeUrl ?? t('common.none')}
|
|
364
|
+
</Field>
|
|
352
365
|
</>
|
|
353
366
|
)}
|
|
354
367
|
{push !== undefined && (
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DiscordTemplate,
|
|
3
|
+
EmailConfig,
|
|
3
4
|
EmailTemplate,
|
|
4
5
|
PushTemplate,
|
|
5
6
|
SegmentIR,
|
|
@@ -280,8 +281,8 @@ export interface ResolvedStudioConfig {
|
|
|
280
281
|
slacks: Record<string, SlackTemplate>;
|
|
281
282
|
/** Compiled named segments. */
|
|
282
283
|
segments: SegmentIR[];
|
|
283
|
-
/** The
|
|
284
|
-
|
|
284
|
+
/** The config's `email`: the default unsubscribe link, and how opens and clicks are judged. */
|
|
285
|
+
email: EmailConfig;
|
|
285
286
|
/** Set when the project failed to load or compile; the shell shows it instead of the views. */
|
|
286
287
|
error?: StudioError;
|
|
287
288
|
stats?: StatsSource;
|