best-email-builder 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/ai-server.js +3 -3
  3. package/dist/ai.js +6 -6
  4. package/dist/builder.js +11 -8
  5. package/dist/{chunk-C22PQBW4.js → chunk-5ZL3YA33.js} +15 -4
  6. package/dist/chunk-5ZL3YA33.js.map +1 -0
  7. package/dist/{chunk-2XSNS7EW.js → chunk-AABKWP7D.js} +3 -3
  8. package/dist/{chunk-2XSNS7EW.js.map → chunk-AABKWP7D.js.map} +1 -1
  9. package/dist/{chunk-WWP3FQYO.js → chunk-BGRCQ7FC.js} +4 -4
  10. package/dist/{chunk-HE2VAOLR.js → chunk-BNCV6YFL.js} +127 -7
  11. package/dist/chunk-BNCV6YFL.js.map +1 -0
  12. package/dist/{chunk-IGC3I4XL.js → chunk-DVC7C52B.js} +2 -2
  13. package/dist/{chunk-XYXN3UBQ.js → chunk-HBFZQGE7.js} +2 -2
  14. package/dist/{chunk-3FKHX47M.js → chunk-LZYH2DE7.js} +565 -636
  15. package/dist/chunk-LZYH2DE7.js.map +1 -0
  16. package/dist/{chunk-OSQ5YGHL.js → chunk-QY67KPCS.js} +2 -2
  17. package/dist/chunk-SNQ37KCQ.js +768 -0
  18. package/dist/chunk-SNQ37KCQ.js.map +1 -0
  19. package/dist/{chunk-4SRNGFAV.js → chunk-YKPRHFMR.js} +3 -3
  20. package/dist/{chunk-LQ3JCPZ2.js → chunk-ZRMXUM2K.js} +2 -2
  21. package/dist/index.js +10 -10
  22. package/dist/library.js +7 -5
  23. package/dist/server.js +99 -16
  24. package/dist/server.js.map +1 -1
  25. package/dist/styles.css +1 -1
  26. package/dist/types/builder.d.ts +1 -0
  27. package/dist/types/core/constants.d.ts +1 -1
  28. package/dist/types/engine/NativeAdapter.d.ts +1 -1
  29. package/dist/types/features/preview/PreviewButton.d.ts +4 -3
  30. package/dist/types/features/test-email/TestEmailDialog.d.ts +29 -0
  31. package/dist/types/library.d.ts +1 -0
  32. package/dist/types/server/handler.d.ts +45 -0
  33. package/dist/types/server/render.d.ts +6 -2
  34. package/dist/types/server/sendTest.d.ts +21 -3
  35. package/dist/types/storage/client.d.ts +39 -5
  36. package/package.json +1 -1
  37. package/dist/chunk-3FKHX47M.js.map +0 -1
  38. package/dist/chunk-7ZI7ZOYQ.js +0 -294
  39. package/dist/chunk-7ZI7ZOYQ.js.map +0 -1
  40. package/dist/chunk-C22PQBW4.js.map +0 -1
  41. package/dist/chunk-HE2VAOLR.js.map +0 -1
  42. package/dist/types/features/test-email/TestEmailButton.d.ts +0 -3
  43. /package/dist/{chunk-WWP3FQYO.js.map → chunk-BGRCQ7FC.js.map} +0 -0
  44. /package/dist/{chunk-IGC3I4XL.js.map → chunk-DVC7C52B.js.map} +0 -0
  45. /package/dist/{chunk-XYXN3UBQ.js.map → chunk-HBFZQGE7.js.map} +0 -0
  46. /package/dist/{chunk-OSQ5YGHL.js.map → chunk-QY67KPCS.js.map} +0 -0
  47. /package/dist/{chunk-4SRNGFAV.js.map → chunk-YKPRHFMR.js.map} +0 -0
  48. /package/dist/{chunk-LQ3JCPZ2.js.map → chunk-ZRMXUM2K.js.map} +0 -0
@@ -0,0 +1,768 @@
1
+ import {
2
+ DARK_PAGE,
3
+ simulateDarkMode
4
+ } from "./chunk-UFKCLU2D.js";
5
+ import {
6
+ Button,
7
+ Dialog,
8
+ DialogContent,
9
+ DialogDescription,
10
+ DialogHeader,
11
+ DialogTitle,
12
+ FilterChip,
13
+ Input,
14
+ Label,
15
+ SectionLabel,
16
+ Select,
17
+ SelectContent,
18
+ SelectItem,
19
+ SelectTrigger,
20
+ SelectValue,
21
+ Tabs,
22
+ TabsList,
23
+ TabsTrigger,
24
+ cn,
25
+ useUi
26
+ } from "./chunk-5ZL3YA33.js";
27
+ import {
28
+ EMAIL_MOBILE_WIDTH
29
+ } from "./chunk-AABKWP7D.js";
30
+
31
+ // src/features/preview/PreviewButton.jsx
32
+ import { useMemo, useRef, useState } from "react";
33
+ import { AlertTriangle, Braces, CheckCircle2, Eye, Info, Loader2, Monitor, Moon, RefreshCw, Smartphone, Sun } from "lucide-react";
34
+
35
+ // src/core/scrollbars.js
36
+ var FRAME_SCROLLBAR_CSS = `
37
+ ::-webkit-scrollbar{width:5.6px;height:5.6px;background:transparent}
38
+ ::-webkit-scrollbar-button{display:none;width:0;height:0}
39
+ ::-webkit-scrollbar-track,::-webkit-scrollbar-track-piece,::-webkit-scrollbar-corner{background:transparent;border:0;box-shadow:none}
40
+ ::-webkit-scrollbar-thumb{background-color:rgba(156,163,175,.45);border:1.4px solid transparent;background-clip:content-box;border-radius:9999px;min-height:2rem;min-width:2rem}
41
+ ::-webkit-scrollbar-thumb:hover{background-color:rgba(107,114,128,.7)}
42
+ @supports not selector(::-webkit-scrollbar){*{scrollbar-width:thin;scrollbar-color:rgba(156,163,175,.45) transparent}}
43
+ @media (hover:hover) and (pointer:fine){
44
+ ::-webkit-scrollbar-thumb{background-color:transparent}
45
+ *:hover::-webkit-scrollbar-thumb{background-color:rgba(156,163,175,.45)}
46
+ *:hover::-webkit-scrollbar-thumb:hover{background-color:rgba(107,114,128,.7)}
47
+ @supports not selector(::-webkit-scrollbar){*{scrollbar-color:transparent transparent}*:hover{scrollbar-color:rgba(156,163,175,.45) transparent}}
48
+ }`;
49
+
50
+ // src/features/preview/PreviewButton.jsx
51
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
52
+ var LEVEL_ICON = { warning: AlertTriangle, info: Info };
53
+ function QualityList({ quality = [], warnings = [] }) {
54
+ const { t } = useUi();
55
+ if (!quality.length && !warnings.length) {
56
+ return /* @__PURE__ */ jsxs("p", { className: "eb:flex eb:items-center eb:gap-1.5 eb:text-[12px] eb:text-foreground-lighter", children: [
57
+ /* @__PURE__ */ jsx(CheckCircle2, { className: "eb:size-3.5 eb:text-success", "aria-hidden": "true" }),
58
+ t("Nothing to fix.")
59
+ ] });
60
+ }
61
+ return /* @__PURE__ */ jsxs("ul", { className: "eb:space-y-1.5", "aria-label": t("Points to check"), children: [
62
+ quality.map((issue) => {
63
+ const Icon = LEVEL_ICON[issue.level] || Info;
64
+ return /* @__PURE__ */ jsxs("li", { className: "eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-foreground", children: [
65
+ /* @__PURE__ */ jsx(
66
+ Icon,
67
+ {
68
+ className: cn(
69
+ "eb:mt-0.5 eb:size-3.5 eb:shrink-0",
70
+ issue.level === "warning" ? "eb:text-warning" : "eb:text-foreground-muted"
71
+ ),
72
+ "aria-hidden": "true"
73
+ }
74
+ ),
75
+ issue.message
76
+ ] }, issue.code);
77
+ }),
78
+ warnings.slice(0, 5).map((w, i) => /* @__PURE__ */ jsxs("li", { className: "eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-foreground-lighter", children: [
79
+ /* @__PURE__ */ jsx(Info, { className: "eb:mt-0.5 eb:size-3.5 eb:shrink-0 eb:text-foreground-muted", "aria-hidden": "true" }),
80
+ "MJML: ",
81
+ w.message
82
+ ] }, `mjml-${i}`))
83
+ ] });
84
+ }
85
+ var PREVIEW_SCROLLBAR_CSS = `<style data-preview-scrollbar>${FRAME_SCROLLBAR_CSS}</style>`;
86
+ var withPreviewScrollbars = (html) => !html ? "" : /<\/head>/i.test(html) ? html.replace(/<\/head>/i, `${PREVIEW_SCROLLBAR_CSS}</head>`) : PREVIEW_SCROLLBAR_CSS + html;
87
+ function EmailPreview({ html, loading = false, error = null, device = "desktop", onDeviceChange, onRefresh, hint = true, actions = null }) {
88
+ const { t } = useUi();
89
+ const isMobile = device === "mobile";
90
+ const [scheme, setScheme] = useState("light");
91
+ const dark = scheme === "dark";
92
+ const srcDoc = useMemo(() => withPreviewScrollbars(dark ? simulateDarkMode(html) : html), [html, dark]);
93
+ return /* @__PURE__ */ jsxs("div", { className: "eb:flex eb:h-full eb:min-h-0 eb:flex-col", children: [
94
+ /* @__PURE__ */ jsxs("div", { className: "eb:mb-2 eb:flex eb:shrink-0 eb:flex-wrap eb:items-center eb:gap-2", children: [
95
+ /* @__PURE__ */ jsx(Tabs, { value: device, onValueChange: (value) => onDeviceChange?.(value), children: /* @__PURE__ */ jsxs(TabsList, { "aria-label": t("Device"), children: [
96
+ /* @__PURE__ */ jsxs(TabsTrigger, { value: "desktop", children: [
97
+ /* @__PURE__ */ jsx(Monitor, {}),
98
+ t("Desktop")
99
+ ] }),
100
+ /* @__PURE__ */ jsxs(TabsTrigger, { value: "mobile", children: [
101
+ /* @__PURE__ */ jsx(Smartphone, {}),
102
+ t("Mobile")
103
+ ] })
104
+ ] }) }),
105
+ /* @__PURE__ */ jsx(Tabs, { value: scheme, onValueChange: setScheme, children: /* @__PURE__ */ jsxs(TabsList, { "aria-label": t("Color scheme"), children: [
106
+ /* @__PURE__ */ jsx(TabsTrigger, { value: "light", "aria-label": t("Light mode"), title: t("Light mode"), children: /* @__PURE__ */ jsx(Sun, {}) }),
107
+ /* @__PURE__ */ jsx(TabsTrigger, { value: "dark", "aria-label": t("Dark mode"), title: t("Dark mode"), children: /* @__PURE__ */ jsx(Moon, {}) })
108
+ ] }) }),
109
+ /* @__PURE__ */ jsx("span", { className: "eb:flex-1" }),
110
+ actions,
111
+ onRefresh && /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm-compact", onClick: onRefresh, disabled: loading, children: [
112
+ loading ? /* @__PURE__ */ jsx(Loader2, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx(RefreshCw, {}),
113
+ t("Refresh")
114
+ ] })
115
+ ] }),
116
+ /* @__PURE__ */ jsx("div", { className: "eb:flex eb:min-h-0 eb:flex-1 eb:flex-col eb:overflow-hidden eb:rounded-lg2 eb:border eb:border-border eb:bg-surface-75 eb:p-3", children: error ? /* @__PURE__ */ jsx("div", { className: "eb:flex eb:h-full eb:items-center eb:justify-center eb:p-6 eb:text-center eb:text-[13px] eb:text-destructive", children: error }) : !srcDoc ? /* @__PURE__ */ jsx("div", { className: "eb:flex eb:h-full eb:items-center eb:justify-center eb:p-6 eb:text-center eb:text-[13px] eb:text-foreground-lighter", children: loading ? t("Rendering\u2026") : t("Nothing to show yet.") }) : (
117
+ // Narrows and widens like the editor's canvas (width .35s ease).
118
+ /* @__PURE__ */ jsx(
119
+ "div",
120
+ {
121
+ className: cn(
122
+ "eb:mx-auto eb:flex eb:min-h-0 eb:max-w-full eb:flex-1 eb:transition-[width,box-shadow] eb:duration-[350ms] eb:ease-in-out eb:motion-reduce:transition-none",
123
+ isMobile && "eb:shadow-sm"
124
+ ),
125
+ style: { width: isMobile ? EMAIL_MOBILE_WIDTH : "100%", background: dark ? DARK_PAGE : "#ffffff" },
126
+ "data-device": device,
127
+ "data-scheme": scheme,
128
+ children: /* @__PURE__ */ jsx(
129
+ "iframe",
130
+ {
131
+ sandbox: "",
132
+ srcDoc,
133
+ title: t("Email preview"),
134
+ className: "eb:block eb:min-h-0 eb:w-full eb:flex-1 eb:border-0",
135
+ style: { background: dark ? DARK_PAGE : "#ffffff" }
136
+ }
137
+ )
138
+ }
139
+ )
140
+ ) }),
141
+ dark ? /* @__PURE__ */ jsx("p", { className: "eb:mt-2 eb:shrink-0 eb:text-[11px] eb:leading-relaxed eb:text-foreground-lighter", "data-testid": "eb-dark-hint", children: t("Dark mode as Gmail and Outlook apps show it: light backgrounds turn dark, dark text turns light, images stay as they are.") }) : hint && /* @__PURE__ */ jsx("p", { className: "eb:mt-2 eb:shrink-0 eb:text-[11px] eb:leading-relaxed eb:text-foreground-lighter", children: t("Indicative preview \u2014 check it with \u201CSend test\u201D.") })
142
+ ] });
143
+ }
144
+ function PreviewButton({ context }) {
145
+ const { editor, ready, meta, storage } = context;
146
+ const { t } = useUi();
147
+ const [open, setOpen] = useState(false);
148
+ const [device, setDevice] = useState("desktop");
149
+ const [state, setState] = useState({ loading: false, html: "", subject: null, preheader: null, warnings: [], quality: [], error: null, samples: true });
150
+ const [samples, setSamples] = useState(true);
151
+ const run = useRef(0);
152
+ const refresh = async (withSamples = samples) => {
153
+ const current = ++run.current;
154
+ setState((s) => ({ ...s, loading: true, error: null }));
155
+ try {
156
+ const data = await storage.render({
157
+ mjml: editor.exportMjml(),
158
+ subject: meta.subject,
159
+ preheader: meta.preheader,
160
+ ...withSamples ? {} : { samples: false }
161
+ });
162
+ if (current !== run.current) return;
163
+ setState({
164
+ loading: false,
165
+ html: data.html,
166
+ // Subject and preview text with their variables filled, when the backend returns them.
167
+ subject: data.subject ?? null,
168
+ preheader: data.preheader ?? null,
169
+ warnings: data.warnings || [],
170
+ quality: data.quality || [],
171
+ error: null,
172
+ // What the frame shows, not what was just asked for.
173
+ samples: withSamples
174
+ });
175
+ } catch (error) {
176
+ if (current !== run.current) return;
177
+ setState({ loading: false, html: "", subject: null, preheader: null, warnings: [], quality: [], error: error.message, samples: withSamples });
178
+ }
179
+ };
180
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
181
+ /* @__PURE__ */ jsxs(
182
+ Button,
183
+ {
184
+ variant: "outline",
185
+ size: "sm-compact",
186
+ disabled: !ready,
187
+ onClick: () => {
188
+ setOpen(true);
189
+ void refresh();
190
+ },
191
+ children: [
192
+ /* @__PURE__ */ jsx(Eye, {}),
193
+ t("Preview")
194
+ ]
195
+ }
196
+ ),
197
+ /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { className: "eb:flex eb:h-[85vh] eb:max-h-[85vh] eb:flex-col eb:gap-4 eb:sm:max-w-[67.2rem]", children: [
198
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsxs("div", { className: "eb:flex eb:items-center eb:gap-3", children: [
199
+ /* @__PURE__ */ jsx("span", { className: "eb:flex eb:size-10 eb:shrink-0 eb:items-center eb:justify-center eb:rounded-lg2 eb:bg-primary/10 eb:text-primary", children: /* @__PURE__ */ jsx(Eye, { className: "eb:size-5" }) }),
200
+ /* @__PURE__ */ jsxs("div", { children: [
201
+ /* @__PURE__ */ jsx(DialogTitle, { className: "eb:text-base eb:font-normal", children: t("Email preview") }),
202
+ /* @__PURE__ */ jsx(DialogDescription, { className: "eb:text-[13px]", children: state.samples ? t("Final rendering, variables filled with samples.") : t("Final rendering, variables shown as tags.") })
203
+ ] })
204
+ ] }) }),
205
+ /* @__PURE__ */ jsxs("div", { className: "eb:grid eb:min-h-0 eb:flex-1 eb:grid-cols-1 eb:grid-rows-[minmax(0,1fr)_auto] eb:gap-4 eb:md:grid-cols-[minmax(0,1fr)_260px] eb:md:grid-rows-1", children: [
206
+ /* @__PURE__ */ jsx(
207
+ EmailPreview,
208
+ {
209
+ html: state.html,
210
+ loading: state.loading,
211
+ error: state.error,
212
+ device,
213
+ onDeviceChange: setDevice,
214
+ onRefresh: () => void refresh(),
215
+ actions: /* @__PURE__ */ jsxs(
216
+ FilterChip,
217
+ {
218
+ pressed: samples,
219
+ onClick: () => {
220
+ setSamples(!samples);
221
+ void refresh(!samples);
222
+ },
223
+ children: [
224
+ /* @__PURE__ */ jsx(Braces, { className: "eb:size-3" }),
225
+ t("Fictitious values")
226
+ ]
227
+ }
228
+ ),
229
+ hint: typeof storage.sendTest === "function"
230
+ }
231
+ ),
232
+ /* @__PURE__ */ jsxs("aside", { className: "eb:max-h-48 eb:min-h-0 eb:space-y-5 eb:overflow-y-auto eb:md:max-h-none", "aria-busy": state.loading, children: [
233
+ /* @__PURE__ */ jsxs("section", { className: "eb:space-y-2", children: [
234
+ /* @__PURE__ */ jsx(SectionLabel, { children: t("Inbox") }),
235
+ /* @__PURE__ */ jsxs("div", { className: "eb:rounded-lg2 eb:border eb:border-border eb:bg-surface-75 eb:px-3 eb:py-2.5", children: [
236
+ /* @__PURE__ */ jsx("p", { className: "eb:text-[13px] eb:font-medium eb:text-foreground", children: (state.subject ?? meta.subject) || t("No subject") }),
237
+ /* @__PURE__ */ jsx("p", { className: "eb:text-[12px] eb:text-foreground-muted", children: (state.preheader ?? meta.preheader) || t("No preview text") })
238
+ ] })
239
+ ] }),
240
+ /* @__PURE__ */ jsxs("section", { className: "eb:space-y-2", children: [
241
+ /* @__PURE__ */ jsx(SectionLabel, { children: t("To check") }),
242
+ !state.loading && !state.error && /* @__PURE__ */ jsx(QualityList, { quality: state.quality, warnings: state.warnings })
243
+ ] })
244
+ ] })
245
+ ] })
246
+ ] }) })
247
+ ] });
248
+ }
249
+
250
+ // src/features/test-email/TestEmailDialog.jsx
251
+ import { useEffect, useRef as useRef2, useState as useState2 } from "react";
252
+ import { CheckCircle2 as CheckCircle22, Eye as Eye2, Loader2 as Loader22, Plus, Search, Send, X, XCircle } from "lucide-react";
253
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
254
+ var KEY = "best-email-builder:test-addresses";
255
+ var MAX_RECIPIENTS = 10;
256
+ var EMAIL_SHAPE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
257
+ var ALL = "*";
258
+ var SENDING_STEP_MS = 1200;
259
+ var NOBODY = "";
260
+ var typed = (email) => ({ key: `e:${email}`, email });
261
+ var picked = (contact) => ({
262
+ key: `c:${contact.id}`,
263
+ email: String(contact.email || "").trim().toLowerCase(),
264
+ contactId: String(contact.id),
265
+ label: contact.label || null,
266
+ detail: contact.detail || null
267
+ });
268
+ var splitAddresses = (text) => String(text || "").split(/[,;\s]+/).map((a) => a.trim().toLowerCase()).filter((a) => EMAIL_SHAPE.test(a));
269
+ function readRecipients(fallback) {
270
+ let saved = null;
271
+ try {
272
+ saved = window.localStorage.getItem(KEY);
273
+ } catch {
274
+ }
275
+ return [...new Set(splitAddresses(saved ?? fallback.join(",")))].slice(0, MAX_RECIPIENTS).map(typed);
276
+ }
277
+ function rememberAddresses(recipients) {
278
+ try {
279
+ window.localStorage.setItem(
280
+ KEY,
281
+ recipients.filter((r) => !r.contactId).map((r) => r.email).join(", ")
282
+ );
283
+ } catch {
284
+ }
285
+ }
286
+ var EMPTY_RENDER = { loading: false, html: "", subject: null, preheader: null, values: null, warnings: [], quality: [], error: null };
287
+ function TestEmailDialog({ open, onOpenChange, storage, getMjml, meta = {}, testRecipients = [] }) {
288
+ const { t, notify } = useUi();
289
+ const setOpen = onOpenChange;
290
+ const canPreview = typeof storage.render === "function";
291
+ const canSearch = typeof storage.searchContacts === "function";
292
+ const canList = canSearch && typeof storage.contactLists === "function";
293
+ const [mjml, setMjml] = useState2("");
294
+ const [recipients, setRecipients] = useState2([]);
295
+ const [focus, setFocus] = useState2(
296
+ /** @type {string|null} */
297
+ null
298
+ );
299
+ const [lists, setLists] = useState2({ loading: false, items: [], error: null });
300
+ const [list, setList] = useState2(ALL);
301
+ const [query, setQuery] = useState2("");
302
+ const [found, setFound] = useState2({ loading: false, items: [], error: null });
303
+ const [addresses, setAddresses] = useState2("");
304
+ const [device, setDevice] = useState2("desktop");
305
+ const [renders, setRenders] = useState2(
306
+ /** @type {Record<string, any>} */
307
+ {}
308
+ );
309
+ const [round, setRound] = useState2(0);
310
+ const [sending, setSending] = useState2(false);
311
+ const [report, setReport] = useState2(null);
312
+ const rendering = useRef2(/* @__PURE__ */ new Set());
313
+ const generation = useRef2(0);
314
+ const focused = recipients.find((r) => r.key === focus) || recipients[0] || null;
315
+ const shownKey = focused?.key ?? NOBODY;
316
+ const shown = renders[shownKey] || (canPreview && mjml ? { ...EMPTY_RENDER, loading: true } : EMPTY_RENDER);
317
+ const full = recipients.length >= MAX_RECIPIENTS;
318
+ useEffect(() => {
319
+ if (!open || !canList) return void 0;
320
+ const controller = new AbortController();
321
+ setLists((s) => ({ ...s, loading: true, error: null }));
322
+ storage.contactLists({ signal: controller.signal }).then((items) => setLists({ loading: false, items: Array.isArray(items) ? items : [], error: null })).catch((error) => {
323
+ if (!controller.signal.aborted) setLists({ loading: false, items: [], error: error.message });
324
+ });
325
+ return () => controller.abort();
326
+ }, [open, canList, storage]);
327
+ useEffect(() => {
328
+ if (!open || !canSearch) return void 0;
329
+ const controller = new AbortController();
330
+ setFound((s) => ({ ...s, loading: true, error: null }));
331
+ const timer = setTimeout(() => {
332
+ storage.searchContacts(query, { list: list === ALL ? null : list, signal: controller.signal }).then((items) => setFound({ loading: false, items: Array.isArray(items) ? items : [], error: null })).catch((error) => {
333
+ if (!controller.signal.aborted) setFound({ loading: false, items: [], error: error.message });
334
+ });
335
+ }, 250);
336
+ return () => {
337
+ clearTimeout(timer);
338
+ controller.abort();
339
+ };
340
+ }, [open, canSearch, storage, query, list]);
341
+ const renderFor = (r) => {
342
+ const key = r?.key ?? NOBODY;
343
+ if (!canPreview || !mjml || renders[key] && !renders[key].error || rendering.current.has(key)) return;
344
+ rendering.current.add(key);
345
+ const run = generation.current;
346
+ storage.render({
347
+ mjml,
348
+ subject: meta.subject,
349
+ preheader: meta.preheader,
350
+ contactId: r?.contactId ?? null,
351
+ email: r && !r.contactId ? r.email : null
352
+ }).then((data) => ({ ...EMPTY_RENDER, ...data, warnings: data.warnings || [], quality: data.quality || [] })).catch((error) => ({ ...EMPTY_RENDER, error: error.message })).then((result) => {
353
+ if (run !== generation.current) return;
354
+ rendering.current.delete(key);
355
+ setRenders((all) => ({ ...all, [key]: result }));
356
+ });
357
+ };
358
+ useEffect(() => {
359
+ if (open) renderFor(focused);
360
+ }, [open, focused?.key, mjml, round]);
361
+ const refresh = () => {
362
+ generation.current += 1;
363
+ rendering.current.clear();
364
+ setRenders({});
365
+ setMjml(getMjml());
366
+ setRound((n) => n + 1);
367
+ };
368
+ const addAll = (list2) => {
369
+ setReport(null);
370
+ const next = [...recipients];
371
+ let last = null;
372
+ for (const recipient of list2) {
373
+ const at = next.findIndex((r) => r.key === recipient.key || r.email === recipient.email);
374
+ const same = next[at];
375
+ if (same && recipient.contactId && !same.contactId) {
376
+ next[at] = recipient;
377
+ last = recipient.key;
378
+ } else if (same) last = same.key;
379
+ else if (next.length < MAX_RECIPIENTS) {
380
+ next.push(recipient);
381
+ last = recipient.key;
382
+ }
383
+ }
384
+ setRecipients(next);
385
+ if (last) setFocus(last);
386
+ };
387
+ const remove = (key) => {
388
+ setReport(null);
389
+ setRecipients(recipients.filter((r) => r.key !== key));
390
+ if (focus === key) setFocus(null);
391
+ };
392
+ const toggle = (contact) => {
393
+ if (sending) return;
394
+ const there = recipients.find((r) => r.contactId === String(contact.id));
395
+ if (there) remove(there.key);
396
+ else addAll([picked(contact)]);
397
+ };
398
+ const addTyped = () => {
399
+ if (sending) return;
400
+ const tokens = addresses.split(/[,;\s]+/).map((a) => a.trim().toLowerCase()).filter(Boolean);
401
+ const valid = tokens.filter((a) => EMAIL_SHAPE.test(a));
402
+ if (!valid.length) return;
403
+ addAll(valid.map(typed));
404
+ setAddresses(tokens.filter((a) => !EMAIL_SHAPE.test(a)).join(", "));
405
+ };
406
+ const send = async () => {
407
+ if (!recipients.length) return;
408
+ rememberAddresses(recipients);
409
+ setSending(true);
410
+ setReport(null);
411
+ const order = recipients.map((r) => r.key);
412
+ let step = 0;
413
+ setFocus(order[0]);
414
+ const timer = setInterval(() => {
415
+ step = (step + 1) % order.length;
416
+ setFocus(order[step]);
417
+ }, SENDING_STEP_MS);
418
+ try {
419
+ const result = await storage.sendTest({
420
+ mjml: getMjml(),
421
+ subject: meta.subject,
422
+ preheader: meta.preheader,
423
+ emails: recipients.filter((r) => !r.contactId).map((r) => r.email),
424
+ contacts: recipients.filter((r) => r.contactId).map((r) => r.contactId)
425
+ });
426
+ setReport(result);
427
+ if (result.failed > 0) notify("warning", t("{sent} sent, {failed} failed.", { sent: result.sent, failed: result.failed }));
428
+ else notify("success", t("{sent} test(s) sent \u2014 check your inbox.", { sent: result.sent }));
429
+ } catch (error) {
430
+ notify("error", error.message);
431
+ } finally {
432
+ clearInterval(timer);
433
+ setSending(false);
434
+ }
435
+ };
436
+ const resultOf = (r) => r.contactId && report?.skipped?.includes(r.contactId) ? { ok: false, error: t("This contact is no longer available") } : report?.results?.find((x) => x.email === r.email) || null;
437
+ const ROW = "eb:flex eb:w-full eb:items-center eb:gap-1.5 eb:rounded-lg2 eb:px-2 eb:py-1.5 eb:text-left eb:hover:bg-surface-200 eb:disabled:opacity-50";
438
+ const contactsSection = canSearch && /* @__PURE__ */ jsxs2("section", { className: "eb:flex eb:min-h-0 eb:flex-1 eb:flex-col eb:gap-1.5", children: [
439
+ /* @__PURE__ */ jsxs2(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
440
+ t("Contact lists"),
441
+ found.loading && found.items.length > 0 && /* @__PURE__ */ jsx2(Loader22, { className: "eb:size-3 eb:animate-spin", "aria-label": t("Searching\u2026") })
442
+ ] }),
443
+ canList && /* @__PURE__ */ jsxs2(Select, { value: list, onValueChange: setList, disabled: lists.loading, children: [
444
+ /* @__PURE__ */ jsx2(SelectTrigger, { "aria-label": t("Contact lists"), className: "eb:h-8 eb:text-[12px]", children: /* @__PURE__ */ jsx2(SelectValue, {}) }),
445
+ /* @__PURE__ */ jsxs2(SelectContent, { children: [
446
+ /* @__PURE__ */ jsx2(SelectItem, { value: ALL, children: t("All contacts") }),
447
+ lists.items.map((l) => /* @__PURE__ */ jsxs2(SelectItem, { value: String(l.id), children: [
448
+ [l.name, l.detail].filter(Boolean).join(" \xB7 "),
449
+ l.count != null && /* @__PURE__ */ jsxs2("span", { className: "eb:text-foreground-muted", children: [
450
+ " (",
451
+ l.count,
452
+ ")"
453
+ ] })
454
+ ] }, l.id))
455
+ ] })
456
+ ] }),
457
+ lists.error && /* @__PURE__ */ jsx2("p", { className: "eb:text-[12px] eb:text-destructive", children: lists.error }),
458
+ /* @__PURE__ */ jsxs2("div", { className: "eb:relative", children: [
459
+ /* @__PURE__ */ jsx2(
460
+ Search,
461
+ {
462
+ className: "eb:pointer-events-none eb:absolute eb:top-1/2 eb:left-2.5 eb:size-3.5 eb:-translate-y-1/2 eb:text-foreground-muted",
463
+ "aria-hidden": "true"
464
+ }
465
+ ),
466
+ /* @__PURE__ */ jsx2(
467
+ Input,
468
+ {
469
+ value: query,
470
+ onChange: (e) => setQuery(e.target.value),
471
+ "aria-label": t("Find a contact"),
472
+ placeholder: t("Name, company or address"),
473
+ className: "eb:h-8 eb:pl-8",
474
+ autoComplete: "off"
475
+ }
476
+ )
477
+ ] }),
478
+ /* @__PURE__ */ jsxs2("ul", { className: "eb:min-h-24 eb:flex-1 eb:space-y-0.5 eb:overflow-y-auto", "aria-label": t("Search results"), "data-testid": "eb-test-contacts", children: [
479
+ found.items.map((contact) => {
480
+ const added = recipients.some((r) => r.contactId === String(contact.id));
481
+ return /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsxs2("button", { type: "button", disabled: sending || full && !added, onClick: () => toggle(contact), "aria-pressed": added, className: ROW, children: [
482
+ /* @__PURE__ */ jsxs2("span", { className: "eb:min-w-0 eb:flex-1", children: [
483
+ /* @__PURE__ */ jsx2("span", { className: "eb:block eb:truncate eb:text-[12px] eb:text-foreground", children: contact.label || contact.email }),
484
+ /* @__PURE__ */ jsx2("span", { className: "eb:block eb:truncate eb:text-[11px] eb:text-foreground-muted", children: [contact.label ? contact.email : null, contact.detail].filter(Boolean).join(" \xB7 ") })
485
+ ] }),
486
+ added ? /* @__PURE__ */ jsx2(CheckCircle22, { className: "eb:size-3.5 eb:shrink-0 eb:text-success", "aria-label": t("Added") }) : /* @__PURE__ */ jsx2(Plus, { className: "eb:size-3.5 eb:shrink-0 eb:text-foreground-muted", "aria-hidden": "true" })
487
+ ] }) }, contact.id);
488
+ }),
489
+ !found.loading && !found.error && !found.items.length && /* @__PURE__ */ jsx2("li", { className: "eb:px-2 eb:py-1.5 eb:text-[12px] eb:text-foreground-lighter", children: t("No contact found.") }),
490
+ found.loading && !found.items.length && /* @__PURE__ */ jsxs2("li", { className: "eb:flex eb:items-center eb:gap-1.5 eb:px-2 eb:py-1.5 eb:text-[12px] eb:text-foreground-lighter", children: [
491
+ /* @__PURE__ */ jsx2(Loader22, { className: "eb:size-3.5 eb:animate-spin", "aria-hidden": "true" }),
492
+ t("Searching\u2026")
493
+ ] }),
494
+ found.error && /* @__PURE__ */ jsx2("li", { className: "eb:px-2 eb:py-1.5 eb:text-[12px] eb:text-destructive", children: found.error })
495
+ ] })
496
+ ] });
497
+ const recipientsSection = /* @__PURE__ */ jsxs2("section", { className: cn("eb:flex eb:min-h-0 eb:flex-col eb:gap-1.5", canSearch ? "eb:max-h-[35%] eb:shrink-0" : "eb:flex-1"), children: [
498
+ /* @__PURE__ */ jsxs2(SectionLabel, { children: [
499
+ t("Recipients"),
500
+ " \xB7 ",
501
+ recipients.length,
502
+ "/",
503
+ MAX_RECIPIENTS
504
+ ] }),
505
+ recipients.length ? /* @__PURE__ */ jsx2("ul", { className: "eb:min-h-0 eb:space-y-1 eb:overflow-y-auto", "data-testid": "eb-test-recipients", children: recipients.map((r) => {
506
+ const result = resultOf(r);
507
+ const current = canPreview && focused?.key === r.key;
508
+ return /* @__PURE__ */ jsxs2(
509
+ "li",
510
+ {
511
+ className: cn(
512
+ "eb:flex eb:items-center eb:gap-1 eb:rounded-lg2 eb:border eb:px-1.5 eb:py-1",
513
+ current ? "eb:border-primary/40 eb:bg-primary/5" : "eb:border-border"
514
+ ),
515
+ children: [
516
+ /* @__PURE__ */ jsxs2(
517
+ "button",
518
+ {
519
+ type: "button",
520
+ className: "eb:flex eb:min-w-0 eb:flex-1 eb:items-center eb:gap-1.5 eb:text-left",
521
+ onClick: () => setFocus(r.key),
522
+ "aria-pressed": current,
523
+ title: canPreview ? t("Preview with these values") : void 0,
524
+ disabled: !canPreview || sending,
525
+ children: [
526
+ sending ? /* @__PURE__ */ jsx2(Loader22, { className: "eb:size-3.5 eb:shrink-0 eb:animate-spin eb:text-foreground-muted", "aria-hidden": "true" }) : result ? result.ok ? /* @__PURE__ */ jsx2(CheckCircle22, { className: "eb:size-3.5 eb:shrink-0 eb:text-success", "aria-label": t("Sent") }) : /* @__PURE__ */ jsx2(XCircle, { className: "eb:size-3.5 eb:shrink-0 eb:text-destructive", "aria-label": result.error || "" }) : canPreview && /* @__PURE__ */ jsx2(
527
+ Eye2,
528
+ {
529
+ className: cn("eb:size-3.5 eb:shrink-0", current ? "eb:text-primary" : "eb:text-foreground-muted/50"),
530
+ "aria-hidden": "true"
531
+ }
532
+ ),
533
+ /* @__PURE__ */ jsxs2("span", { className: "eb:min-w-0", children: [
534
+ /* @__PURE__ */ jsx2("span", { className: "eb:block eb:truncate eb:text-[12px] eb:text-foreground", children: r.label || r.email }),
535
+ /* @__PURE__ */ jsx2("span", { className: "eb:block eb:truncate eb:text-[11px] eb:text-foreground-muted", children: r.contactId ? r.email : t("Sample values") }),
536
+ result?.error && /* @__PURE__ */ jsx2("span", { className: "eb:block eb:text-[11px] eb:text-destructive", children: result.error })
537
+ ] })
538
+ ]
539
+ }
540
+ ),
541
+ /* @__PURE__ */ jsx2(
542
+ Button,
543
+ {
544
+ variant: "ghost",
545
+ size: "icon-xs",
546
+ "aria-label": t("Remove {email}", { email: r.email }),
547
+ title: t("Remove"),
548
+ onClick: () => remove(r.key),
549
+ disabled: sending,
550
+ children: /* @__PURE__ */ jsx2(X, {})
551
+ }
552
+ )
553
+ ]
554
+ },
555
+ r.key
556
+ );
557
+ }) }) : /* @__PURE__ */ jsx2("p", { className: "eb:text-[12px] eb:text-foreground-lighter", children: t("No recipient yet.") }),
558
+ report?.invalid?.map((email) => /* @__PURE__ */ jsx2("p", { className: "eb:text-[12px] eb:text-foreground-muted", children: t("Ignored (invalid): {email}", { email }) }, `invalid-${email}`))
559
+ ] });
560
+ const addressesSection = /* @__PURE__ */ jsxs2("section", { className: "eb:flex eb:shrink-0 eb:flex-col eb:gap-1.5", children: [
561
+ /* @__PURE__ */ jsx2(Label, { htmlFor: "eb-test-addresses", children: t("Addresses") }),
562
+ /* @__PURE__ */ jsxs2("div", { className: "eb:flex eb:gap-1.5", children: [
563
+ /* @__PURE__ */ jsx2(
564
+ Input,
565
+ {
566
+ id: "eb-test-addresses",
567
+ value: addresses,
568
+ onChange: (e) => setAddresses(e.target.value),
569
+ onKeyDown: (e) => {
570
+ if (e.key !== "Enter") return;
571
+ e.preventDefault();
572
+ addTyped();
573
+ },
574
+ placeholder: "jane@example.com, john@example.com",
575
+ className: "eb:h-8",
576
+ autoComplete: "off",
577
+ disabled: full || sending
578
+ }
579
+ ),
580
+ /* @__PURE__ */ jsxs2(
581
+ Button,
582
+ {
583
+ variant: "outline",
584
+ size: "sm-compact",
585
+ className: "eb:h-8",
586
+ onClick: addTyped,
587
+ disabled: full || sending || !splitAddresses(addresses).length,
588
+ children: [
589
+ /* @__PURE__ */ jsx2(Plus, {}),
590
+ t("Add")
591
+ ]
592
+ }
593
+ )
594
+ ] }),
595
+ full && /* @__PURE__ */ jsx2("p", { className: "eb:text-[11px] eb:text-foreground-muted", children: t("{max} test addresses at most", { max: MAX_RECIPIENTS }) })
596
+ ] });
597
+ useEffect(() => {
598
+ if (!open) return;
599
+ setRecipients(readRecipients(testRecipients));
600
+ setFocus(null);
601
+ setQuery("");
602
+ setAddresses("");
603
+ setReport(null);
604
+ setList(ALL);
605
+ generation.current += 1;
606
+ rendering.current.clear();
607
+ setRenders({});
608
+ setMjml(getMjml());
609
+ }, [open]);
610
+ return /* @__PURE__ */ jsx2(Dialog, { open, onOpenChange: (next) => !sending && setOpen(next), children: /* @__PURE__ */ jsxs2(
611
+ DialogContent,
612
+ {
613
+ className: cn(
614
+ "eb:flex eb:flex-col eb:gap-4",
615
+ canPreview ? "eb:h-[88vh] eb:max-h-[88vh] eb:sm:max-w-[92rem]" : "eb:max-h-[85vh] eb:sm:max-w-[460px]"
616
+ ),
617
+ children: [
618
+ /* @__PURE__ */ jsx2(DialogHeader, { children: /* @__PURE__ */ jsxs2("div", { className: "eb:flex eb:items-center eb:gap-3", children: [
619
+ /* @__PURE__ */ jsx2("span", { className: "eb:flex eb:size-10 eb:shrink-0 eb:items-center eb:justify-center eb:rounded-lg2 eb:bg-primary/10 eb:text-primary", children: /* @__PURE__ */ jsx2(Send, { className: "eb:size-5" }) }),
620
+ /* @__PURE__ */ jsxs2("div", { children: [
621
+ /* @__PURE__ */ jsx2(DialogTitle, { className: "eb:text-base eb:font-normal", children: t("Send a test") }),
622
+ /* @__PURE__ */ jsx2(DialogDescription, { className: "eb:text-[13px]", "aria-live": "polite", children: sending && focused ? t("Sending to {email}\u2026", { email: focused.email }) : canSearch ? t("The email on screen, with each contact\u2019s values.") : t("The email on screen, to reviewers\u2019 addresses.") })
623
+ ] })
624
+ ] }) }),
625
+ /* @__PURE__ */ jsxs2(
626
+ "div",
627
+ {
628
+ className: cn(
629
+ "eb:grid eb:min-h-0 eb:flex-1 eb:gap-4",
630
+ canPreview && "eb:grid-rows-[minmax(0,1fr)_minmax(0,1fr)] eb:md:grid-cols-[minmax(0,1fr)_320px] eb:md:grid-rows-1 eb:xl:grid-cols-[minmax(0,1fr)_576px]"
631
+ ),
632
+ children: [
633
+ canPreview && /* @__PURE__ */ jsx2(
634
+ EmailPreview,
635
+ {
636
+ html: shown.html,
637
+ loading: shown.loading,
638
+ error: shown.error,
639
+ device,
640
+ onDeviceChange: setDevice,
641
+ onRefresh: sending ? void 0 : refresh,
642
+ hint: false
643
+ }
644
+ ),
645
+ /* @__PURE__ */ jsxs2("aside", { className: "eb:flex eb:min-h-0 eb:flex-col eb:gap-3", "aria-label": t("Recipients"), children: [
646
+ contactsSection,
647
+ recipientsSection,
648
+ addressesSection,
649
+ /* @__PURE__ */ jsxs2("div", { className: "eb:flex eb:shrink-0 eb:justify-end eb:gap-2", children: [
650
+ /* @__PURE__ */ jsx2(Button, { variant: "outline", onClick: () => setOpen(false), disabled: sending, children: t("Close") }),
651
+ /* @__PURE__ */ jsxs2(Button, { onClick: send, disabled: sending || !recipients.length, children: [
652
+ sending ? /* @__PURE__ */ jsx2(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx2(Send, {}),
653
+ t("Send")
654
+ ] })
655
+ ] })
656
+ ] })
657
+ ]
658
+ }
659
+ )
660
+ ]
661
+ }
662
+ ) });
663
+ }
664
+ function TestEmailButton({ context }) {
665
+ const { editor, ready, meta, storage, testRecipients = [] } = context;
666
+ const { t } = useUi();
667
+ const [open, setOpen] = useState2(false);
668
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
669
+ /* @__PURE__ */ jsxs2(Button, { variant: "outline", size: "sm-compact", disabled: !ready, onClick: () => setOpen(true), children: [
670
+ /* @__PURE__ */ jsx2(Send, {}),
671
+ t("Test")
672
+ ] }),
673
+ /* @__PURE__ */ jsx2(
674
+ TestEmailDialog,
675
+ {
676
+ open,
677
+ onOpenChange: setOpen,
678
+ storage,
679
+ getMjml: () => editor.exportMjml(),
680
+ meta,
681
+ testRecipients
682
+ }
683
+ )
684
+ ] });
685
+ }
686
+
687
+ // src/features/templates/thumbnails.js
688
+ var THUMBNAIL_IMAGE = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 300'%3E%3Crect width='600' height='300' fill='%23dfe6f0'/%3E%3C/svg%3E";
689
+ function withThumbnailImages(mjml) {
690
+ return String(mjml || "").replace(/<mj-image(?![^>]*\ssrc=)([^>]*)>/g, `<mj-image src="${THUMBNAIL_IMAGE}"$1>`);
691
+ }
692
+ function withPlaceholderImages(html) {
693
+ return String(html || "").replace(/<img(?![^>]*\ssrc=)(\s[^>]*)?>/g, (_m, attrs = "") => `<img src="${THUMBNAIL_IMAGE}"${attrs}>`);
694
+ }
695
+
696
+ // src/ui/primitives/searchShortcut.jsx
697
+ import { useEffect as useEffect2 } from "react";
698
+ import { jsx as jsx3 } from "react/jsx-runtime";
699
+ var apple = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent || "");
700
+ var SEARCH_KEYS = "Control+K Meta+K";
701
+ function useSearchShortcut(inputRef) {
702
+ useEffect2(() => {
703
+ const onKey = (event) => {
704
+ const input = inputRef.current;
705
+ if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "k") return;
706
+ if (!input?.isConnected || input.disabled) return;
707
+ event.preventDefault();
708
+ input.focus();
709
+ input.select();
710
+ };
711
+ window.addEventListener("keydown", onKey);
712
+ return () => window.removeEventListener("keydown", onKey);
713
+ }, [inputRef]);
714
+ }
715
+ function SearchKeyHint({ className, children = null }) {
716
+ return /* @__PURE__ */ jsx3(
717
+ "kbd",
718
+ {
719
+ className: cn(
720
+ "eb:pointer-events-none eb:inline-flex eb:h-5 eb:items-center eb:rounded-md eb:border eb:border-border eb:bg-surface-100 eb:px-1.5 eb:font-mono eb:text-[10px] eb:text-foreground-muted",
721
+ className
722
+ ),
723
+ "aria-hidden": "true",
724
+ "data-testid": "eb-search-keys",
725
+ children: children ?? (apple() ? "\u2318K" : "Ctrl K")
726
+ }
727
+ );
728
+ }
729
+
730
+ // src/ui/useLayoutWidth.js
731
+ import { useEffect as useEffect3, useState as useState3 } from "react";
732
+ var LAYOUT_BREAKPOINTS = { wide: 1180, medium: 760 };
733
+ function layoutFor(width) {
734
+ if (width >= LAYOUT_BREAKPOINTS.wide) return "wide";
735
+ if (width >= LAYOUT_BREAKPOINTS.medium) return "medium";
736
+ return "narrow";
737
+ }
738
+ function useLayoutWidth(ref) {
739
+ const [layout, setLayout] = useState3(
740
+ /** @type {'wide'|'medium'|'narrow'} */
741
+ "wide"
742
+ );
743
+ useEffect3(() => {
744
+ const el = ref.current;
745
+ if (!el || typeof ResizeObserver === "undefined") return void 0;
746
+ const measure = () => setLayout(layoutFor(el.getBoundingClientRect().width));
747
+ measure();
748
+ const observer = new ResizeObserver(measure);
749
+ observer.observe(el);
750
+ return () => observer.disconnect();
751
+ }, [ref]);
752
+ return layout;
753
+ }
754
+
755
+ export {
756
+ FRAME_SCROLLBAR_CSS,
757
+ EmailPreview,
758
+ PreviewButton,
759
+ TestEmailDialog,
760
+ TestEmailButton,
761
+ withThumbnailImages,
762
+ withPlaceholderImages,
763
+ SEARCH_KEYS,
764
+ useSearchShortcut,
765
+ SearchKeyHint,
766
+ useLayoutWidth
767
+ };
768
+ //# sourceMappingURL=chunk-SNQ37KCQ.js.map