best-email-builder 0.15.0 → 0.17.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 (110) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/README.md +16 -7
  3. package/THIRD-PARTY-NOTICES.md +34 -0
  4. package/dist/ai-server.js +7 -3
  5. package/dist/ai-server.js.map +1 -1
  6. package/dist/ai.js +91 -99
  7. package/dist/ai.js.map +1 -1
  8. package/dist/builder.js +8 -8
  9. package/dist/{chunk-XALUYZYQ.js → chunk-2F7P4FXX.js} +2 -2
  10. package/dist/{chunk-RG2DTGST.js → chunk-4AUHYQPE.js} +7 -5
  11. package/dist/chunk-4AUHYQPE.js.map +1 -0
  12. package/dist/{chunk-6ZX3VYE4.js → chunk-5OUMNUJS.js} +143 -19
  13. package/dist/chunk-5OUMNUJS.js.map +1 -0
  14. package/dist/{chunk-ND3B5TL7.js → chunk-DOK6E6GK.js} +38 -13
  15. package/dist/chunk-DOK6E6GK.js.map +1 -0
  16. package/dist/{chunk-RZ3O4MH5.js → chunk-FPJF77MO.js} +329 -18
  17. package/dist/chunk-FPJF77MO.js.map +1 -0
  18. package/dist/{chunk-6LTSEPQX.js → chunk-PCLRIXAQ.js} +2 -2
  19. package/dist/{chunk-GHFNJY4O.js → chunk-QDAVDMA4.js} +2 -2
  20. package/dist/{chunk-AT4EB2NS.js → chunk-U3BA4NK3.js} +311 -3
  21. package/dist/chunk-U3BA4NK3.js.map +1 -0
  22. package/dist/{chunk-QXE6LJG5.js → chunk-V2PO42EN.js} +4 -4
  23. package/dist/{chunk-QXE6LJG5.js.map → chunk-V2PO42EN.js.map} +1 -1
  24. package/dist/{chunk-OK3EIEUA.js → chunk-X4WTY6LC.js} +2449 -1006
  25. package/dist/chunk-X4WTY6LC.js.map +1 -0
  26. package/dist/{chunk-I6FP6BBI.js → chunk-ZRER4JD4.js} +268 -55
  27. package/dist/chunk-ZRER4JD4.js.map +1 -0
  28. package/dist/de-BNFO6VLR.js +1875 -0
  29. package/dist/de-BNFO6VLR.js.map +1 -0
  30. package/dist/en-PBUZLCBA.js +1875 -0
  31. package/dist/en-PBUZLCBA.js.map +1 -0
  32. package/dist/es-M7A73ED7.js +1875 -0
  33. package/dist/es-M7A73ED7.js.map +1 -0
  34. package/dist/fr-SUFB35ZZ.js +1875 -0
  35. package/dist/fr-SUFB35ZZ.js.map +1 -0
  36. package/dist/index.js +10 -10
  37. package/dist/library.js +5 -5
  38. package/dist/pt-OEAULFDA.js +1875 -0
  39. package/dist/pt-OEAULFDA.js.map +1 -0
  40. package/dist/ru-ZCORYHGA.js +1875 -0
  41. package/dist/ru-ZCORYHGA.js.map +1 -0
  42. package/dist/server.js +63 -16
  43. package/dist/server.js.map +1 -1
  44. package/dist/styles.css +1 -1
  45. package/dist/types/ai/errors.d.ts +19 -7
  46. package/dist/types/ai/index.d.ts +1 -0
  47. package/dist/types/ai/languagetool.d.ts +46 -0
  48. package/dist/types/ai/rewrite.d.ts +9 -7
  49. package/dist/types/ai/server.d.ts +1 -0
  50. package/dist/types/ai/subjects.d.ts +1 -0
  51. package/dist/types/blocks/navbar/index.d.ts +1 -1
  52. package/dist/types/blocks/shared.d.ts +12 -9
  53. package/dist/types/blocks/social/index.d.ts +7 -3
  54. package/dist/types/core/EmailEditor.d.ts +154 -12
  55. package/dist/types/core/blockBox.d.ts +12 -0
  56. package/dist/types/core/constants.d.ts +1 -1
  57. package/dist/types/core/mjmlAttributes.d.ts +37 -0
  58. package/dist/types/core/textFormat.d.ts +4 -0
  59. package/dist/types/defaultEditor.d.ts +3 -1
  60. package/dist/types/engine/NativeAdapter.d.ts +5 -2
  61. package/dist/types/engine/canvas/CanvasView.d.ts +39 -1
  62. package/dist/types/engine/canvas/canvasStyles.d.ts +1 -1
  63. package/dist/types/engine/canvas/icons.d.ts +1 -8
  64. package/dist/types/engine/canvasMjml.d.ts +4 -2
  65. package/dist/types/engine/mjml.d.ts +7 -0
  66. package/dist/types/features/emoji/EmojiPanel.d.ts +3 -0
  67. package/dist/types/features/emoji/data/de.d.ts +2 -0
  68. package/dist/types/features/emoji/data/en.d.ts +2 -0
  69. package/dist/types/features/emoji/data/es.d.ts +2 -0
  70. package/dist/types/features/emoji/data/fr.d.ts +2 -0
  71. package/dist/types/features/emoji/data/pt.d.ts +2 -0
  72. package/dist/types/features/emoji/data/ru.d.ts +2 -0
  73. package/dist/types/features/emoji/data/zh.d.ts +2 -0
  74. package/dist/types/features/emoji/emojis.d.ts +33 -0
  75. package/dist/types/features/emoji/index.d.ts +2 -0
  76. package/dist/types/features/variables/VariableDialog.d.ts +9 -1
  77. package/dist/types/features/variables/VariablesPanel.d.ts +28 -0
  78. package/dist/types/features/variables/catalog.d.ts +12 -4
  79. package/dist/types/renderer/columnAlignment.d.ts +10 -0
  80. package/dist/types/renderer/compileEditorMjml.d.ts +2 -0
  81. package/dist/types/server/compileMjml.d.ts +5 -0
  82. package/dist/types/server/handler.d.ts +1 -1
  83. package/dist/types/server/render.d.ts +15 -4
  84. package/dist/types/server/sendTest.d.ts +2 -2
  85. package/dist/types/server/variables.d.ts +5 -0
  86. package/dist/types/storage/client.d.ts +6 -0
  87. package/dist/types/ui/BlockSidebar.d.ts +34 -0
  88. package/dist/types/ui/BoxModel.d.ts +39 -0
  89. package/dist/types/ui/CanvasAddMenu.d.ts +14 -0
  90. package/dist/types/ui/CanvasPanel.d.ts +19 -0
  91. package/dist/types/ui/TextRibbon.d.ts +25 -0
  92. package/dist/types/ui/fields.d.ts +16 -1
  93. package/dist/types/ui/primitives/color-picker.d.ts +18 -4
  94. package/dist/types/ui/primitives/misc.d.ts +3 -1
  95. package/dist/types/ui/primitives/overlays.d.ts +1 -0
  96. package/dist/types/ui/useEmailEditorState.d.ts +1 -0
  97. package/dist/zh-KPGU7EQG.js +1875 -0
  98. package/dist/zh-KPGU7EQG.js.map +1 -0
  99. package/package.json +2 -1
  100. package/dist/chunk-6ZX3VYE4.js.map +0 -1
  101. package/dist/chunk-AT4EB2NS.js.map +0 -1
  102. package/dist/chunk-I6FP6BBI.js.map +0 -1
  103. package/dist/chunk-ND3B5TL7.js.map +0 -1
  104. package/dist/chunk-OK3EIEUA.js.map +0 -1
  105. package/dist/chunk-RG2DTGST.js.map +0 -1
  106. package/dist/chunk-RZ3O4MH5.js.map +0 -1
  107. package/dist/types/features/variables/VariablesBar.d.ts +0 -23
  108. /package/dist/{chunk-XALUYZYQ.js.map → chunk-2F7P4FXX.js.map} +0 -0
  109. /package/dist/{chunk-6LTSEPQX.js.map → chunk-PCLRIXAQ.js.map} +0 -0
  110. /package/dist/{chunk-GHFNJY4O.js.map → chunk-QDAVDMA4.js.map} +0 -0
package/dist/ai.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cleanRichText
3
- } from "./chunk-6LTSEPQX.js";
3
+ } from "./chunk-PCLRIXAQ.js";
4
4
  import {
5
5
  Button,
6
6
  Dialog,
@@ -20,8 +20,8 @@ import {
20
20
  cn,
21
21
  createHttpCaller,
22
22
  useUi
23
- } from "./chunk-ND3B5TL7.js";
24
- import "./chunk-6ZX3VYE4.js";
23
+ } from "./chunk-DOK6E6GK.js";
24
+ import "./chunk-5OUMNUJS.js";
25
25
  import {
26
26
  AGENT_ERROR_CODES,
27
27
  AGENT_PROTOCOL,
@@ -30,6 +30,7 @@ import {
30
30
  DEFAULT_CLAUDE_MODEL,
31
31
  EmailGenerationError,
32
32
  GENERATION_ERRORS,
33
+ LANGUAGETOOL_PUBLIC_API,
33
34
  MAX_REWRITE_INSTRUCTION,
34
35
  REWRITE_ACTIONS,
35
36
  REWRITE_LANGUAGES,
@@ -37,6 +38,7 @@ import {
37
38
  claudeEmailModel,
38
39
  claudeProvider,
39
40
  createEmailGenerator,
41
+ createLanguageToolProofreader,
40
42
  diffWords,
41
43
  emailWords,
42
44
  failureCode,
@@ -44,9 +46,9 @@ import {
44
46
  providerEmailModel,
45
47
  resolveProvider,
46
48
  visibleText
47
- } from "./chunk-I6FP6BBI.js";
48
- import "./chunk-XALUYZYQ.js";
49
- import "./chunk-RZ3O4MH5.js";
49
+ } from "./chunk-ZRER4JD4.js";
50
+ import "./chunk-2F7P4FXX.js";
51
+ import "./chunk-FPJF77MO.js";
50
52
 
51
53
  // src/ai/keys.js
52
54
  var STORAGE_PREFIX = "best-email-builder:ai-key:";
@@ -332,8 +334,8 @@ function ModelPicker({ aiKey, provider, apiKey, address = "", delay = 0, value,
332
334
  };
333
335
  const optionId = (at) => `${listId}-${at}`;
334
336
  const badges = (model) => /* @__PURE__ */ jsxs(Fragment, { children: [
335
- model.free && /* @__PURE__ */ jsx("span", { className: "eb:shrink-0 eb:rounded-full eb:bg-success/10 eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-success", children: t("Free") }),
336
- model.id === provider.model && /* @__PURE__ */ jsx("span", { className: "eb:shrink-0 eb:rounded-full eb:bg-muted eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-foreground-lighter", children: t("Default") })
337
+ model.free && /* @__PURE__ */ jsx("span", { className: "eb:shrink-0 eb:rounded-md eb:bg-success/10 eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-success", children: t("Free") }),
338
+ model.id === provider.model && /* @__PURE__ */ jsx("span", { className: "eb:shrink-0 eb:rounded-md eb:bg-muted eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-foreground-lighter", children: t("Default") })
337
339
  ] });
338
340
  const status = {
339
341
  loading: /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -359,7 +361,7 @@ function ModelPicker({ aiKey, provider, apiKey, address = "", delay = 0, value,
359
361
  "aria-describedby": hintId,
360
362
  onClick: () => onOpenChange(!open),
361
363
  className: cn(
362
- "eb:flex eb:h-9 eb:w-full eb:min-w-0 eb:items-center eb:gap-2 eb:rounded-md eb:border eb:border-input eb:bg-transparent eb:px-3 eb:text-left eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
364
+ "eb:flex eb:h-9 eb:w-full eb:min-w-0 eb:items-center eb:gap-2 eb:rounded-lg2 eb:border eb:border-input eb:bg-transparent eb:px-3 eb:text-left eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
363
365
  open && "eb:border-ring"
364
366
  ),
365
367
  "data-testid": "eb-ai-connect-model",
@@ -373,7 +375,7 @@ function ModelPicker({ aiKey, provider, apiKey, address = "", delay = 0, value,
373
375
  open && /* @__PURE__ */ jsxs(
374
376
  "div",
375
377
  {
376
- className: "eb:flex eb:flex-col eb:overflow-hidden eb:rounded-md eb:border eb:border-border eb:bg-background",
378
+ className: "eb:flex eb:flex-col eb:overflow-hidden eb:rounded-lg2 eb:border eb:border-border eb:bg-background",
377
379
  onKeyDown: (event) => event.key === "Escape" && close(),
378
380
  "data-eb-models": "",
379
381
  "data-testid": "eb-ai-connect-models",
@@ -399,7 +401,7 @@ function ModelPicker({ aiKey, provider, apiKey, address = "", delay = 0, value,
399
401
  autoCapitalize: "off",
400
402
  autoCorrect: "off",
401
403
  spellCheck: false,
402
- className: "eb:h-8 eb:w-full eb:rounded-md eb:bg-surface-75 eb:pr-2 eb:pl-7 eb:text-[13px] eb:text-foreground eb:outline-none eb:placeholder:text-foreground-muted eb:focus-visible:ring-2 eb:focus-visible:ring-ring/40",
404
+ className: "eb:h-8 eb:w-full eb:rounded-lg2 eb:bg-surface-75 eb:pr-2 eb:pl-7 eb:text-[13px] eb:text-foreground eb:outline-none eb:placeholder:text-foreground-muted eb:focus-visible:ring-2 eb:focus-visible:ring-ring/40",
403
405
  "data-testid": "eb-ai-connect-model-search"
404
406
  }
405
407
  )
@@ -411,7 +413,7 @@ function ModelPicker({ aiKey, provider, apiKey, address = "", delay = 0, value,
411
413
  "aria-pressed": freeOnly,
412
414
  onClick: () => setFreeOnly((on) => !on),
413
415
  className: cn(
414
- "eb:inline-flex eb:h-8 eb:shrink-0 eb:items-center eb:rounded-md eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
416
+ "eb:inline-flex eb:h-8 eb:shrink-0 eb:items-center eb:rounded-lg2 eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
415
417
  freeOnly ? "eb:border-success/40 eb:bg-success/10 eb:text-success" : "eb:border-border eb:text-foreground-lighter eb:hover:bg-muted"
416
418
  ),
417
419
  children: t("Free only")
@@ -597,7 +599,7 @@ function ConnectAi({ aiKey }) {
597
599
  tabIndex: checked ? 0 : -1,
598
600
  onClick: () => choose(provider.id),
599
601
  className: cn(
600
- "eb:flex eb:min-w-0 eb:flex-col eb:gap-0.5 eb:rounded-md eb:border eb:px-2.5 eb:py-2 eb:text-left eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
602
+ "eb:flex eb:min-w-0 eb:flex-col eb:gap-0.5 eb:rounded-lg2 eb:border eb:px-2.5 eb:py-2 eb:text-left eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
601
603
  checked ? "eb:border-primary eb:bg-primary/10" : "eb:border-border eb:hover:bg-muted"
602
604
  ),
603
605
  children: [
@@ -613,7 +615,7 @@ function ConnectAi({ aiKey }) {
613
615
  })
614
616
  }
615
617
  ),
616
- refused && /* @__PURE__ */ jsxs2("p", { role: "alert", className: "eb:flex eb:items-start eb:gap-2 eb:rounded-md eb:border eb:border-destructive/30 eb:bg-destructive/10 eb:px-3 eb:py-2 eb:text-[12.5px] eb:text-destructive", children: [
618
+ refused && /* @__PURE__ */ jsxs2("p", { role: "alert", className: "eb:flex eb:items-start eb:gap-2 eb:rounded-lg2 eb:border eb:border-destructive/30 eb:bg-destructive/10 eb:px-3 eb:py-2 eb:text-[12.5px] eb:text-destructive", children: [
617
619
  /* @__PURE__ */ jsx2(TriangleAlert, { className: "eb:mt-px eb:size-3.5 eb:shrink-0", "aria-hidden": "true" }),
618
620
  t("{provider} refused the last key. Paste another one.", { provider: name })
619
621
  ] }),
@@ -635,7 +637,7 @@ function ConnectAi({ aiKey }) {
635
637
  ]
636
638
  }
637
639
  ) }),
638
- free && /* @__PURE__ */ jsx2("span", { className: "eb:rounded-full eb:bg-success/10 eb:px-2.5 eb:py-1 eb:text-[11.5px] eb:font-medium eb:text-success", children: t(free) })
640
+ free && /* @__PURE__ */ jsx2("span", { className: "eb:rounded-md eb:bg-success/10 eb:px-2.5 eb:py-1 eb:text-[11.5px] eb:font-medium eb:text-success", children: t(free) })
639
641
  ] }),
640
642
  needsAddress && /* @__PURE__ */ jsxs2("div", { className: "eb:flex eb:flex-col eb:gap-1.5", children: [
641
643
  /* @__PURE__ */ jsx2(Label, { htmlFor: addressId, children: t("API address") }),
@@ -686,7 +688,7 @@ function ConnectAi({ aiKey }) {
686
688
  "button",
687
689
  {
688
690
  type: "button",
689
- className: "eb:absolute eb:top-1/2 eb:right-1 eb:flex eb:size-7 eb:-translate-y-1/2 eb:items-center eb:justify-center eb:rounded eb:text-foreground-muted eb:transition-colors eb:outline-none eb:hover:bg-muted eb:hover:text-foreground eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
691
+ className: "eb:absolute eb:top-1/2 eb:right-1 eb:flex eb:size-7 eb:-translate-y-1/2 eb:items-center eb:justify-center eb:rounded-md eb:text-foreground-muted eb:transition-colors eb:outline-none eb:hover:bg-muted eb:hover:text-foreground eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
690
692
  onClick: () => setShown((current) => !current),
691
693
  "aria-label": shown ? t("Hide the key") : t("Show the key"),
692
694
  "aria-pressed": shown,
@@ -864,7 +866,7 @@ function ProofreadButton({ context, proofread }) {
864
866
  /* @__PURE__ */ jsx3(Dialog, { open, onOpenChange: close, children: /* @__PURE__ */ jsxs3(DialogContent, { className: "eb:flex eb:max-h-[calc(100dvh-2rem)] eb:flex-col eb:gap-0 eb:p-0 eb:sm:max-w-xl", "data-testid": "eb-proofread", children: [
865
867
  /* @__PURE__ */ jsxs3(DialogHeader, { className: "eb:gap-1.5 eb:px-6 eb:pt-6 eb:pb-4", children: [
866
868
  /* @__PURE__ */ jsx3(DialogTitle, { children: t("Proofread the email") }),
867
- /* @__PURE__ */ jsx3(DialogDescription, { children: t("AI looks for spelling, grammar and punctuation mistakes in every text. Nothing changes until you apply it.") })
869
+ /* @__PURE__ */ jsx3(DialogDescription, { children: t("Every text is checked for spelling, grammar and punctuation mistakes. Nothing changes until you apply it.") })
868
870
  ] }),
869
871
  /* @__PURE__ */ jsxs3("div", { className: "eb:min-h-0 eb:flex-1 eb:overflow-y-auto eb:border-t eb:border-border eb:px-6 eb:py-4", children: [
870
872
  busy && /* @__PURE__ */ jsxs3("p", { className: "eb:flex eb:items-center eb:gap-2 eb:py-6 eb:text-[13px] eb:text-foreground-muted", role: "status", "aria-live": "polite", children: [
@@ -882,7 +884,7 @@ function ProofreadButton({ context, proofread }) {
882
884
  fixes && fixes.length > 0 && /* @__PURE__ */ jsx3("ul", { className: "eb:flex eb:flex-col eb:gap-2.5", "aria-label": t("Corrections"), children: fixes.map((fix) => /* @__PURE__ */ jsxs3(
883
885
  "li",
884
886
  {
885
- className: cn("eb:rounded-md eb:border eb:border-border eb:p-3", fix.state !== "open" && "eb:bg-muted/40"),
887
+ className: cn("eb:rounded-lg2 eb:border eb:border-border eb:p-3", fix.state !== "open" && "eb:bg-muted/40"),
886
888
  "data-testid": "eb-proofread-fix",
887
889
  "data-state": fix.state,
888
890
  children: [
@@ -931,17 +933,17 @@ function around(text, first, last) {
931
933
  }
932
934
 
933
935
  // src/ai/RewriteText.jsx
934
- import { useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
935
- import { ChevronDown as ChevronDown2, Languages, Loader2 as Loader22, PenLine, Sparkles, TriangleAlert as TriangleAlert3 } from "lucide-react";
936
+ import { useCallback, useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
937
+ import { ChevronDown as ChevronDown2, Languages, Loader2 as Loader22, Sparkles, TriangleAlert as TriangleAlert3 } from "lucide-react";
936
938
 
937
939
  // src/ai/chip.js
938
940
  var chipClassName = (selected = false) => cn(
939
- "eb:inline-flex eb:h-[22px] eb:items-center eb:gap-1 eb:rounded-full eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:disabled:opacity-50",
941
+ "eb:inline-flex eb:h-[22px] eb:items-center eb:gap-1 eb:rounded-md eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:disabled:opacity-50",
940
942
  selected ? "eb:border-primary eb:bg-primary eb:text-primary-foreground" : "eb:border-border eb:bg-background eb:text-foreground eb:hover:border-primary/50 eb:hover:bg-primary/5"
941
943
  );
942
944
 
943
945
  // src/ai/RewriteText.jsx
944
- import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
946
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
945
947
  function nativeName(code) {
946
948
  try {
947
949
  const name = new Intl.DisplayNames([code], { type: "language" }).of(code) || code;
@@ -957,14 +959,19 @@ function RewriteText({ editor, selection, rewrite }) {
957
959
  null
958
960
  );
959
961
  const [error, setError] = useState4("");
960
- const [instruction, setInstruction] = useState4("");
961
- const [topic, setTopic] = useState4("");
962
+ const [request, setRequest] = useState4("");
962
963
  const abortRef = useRef4(
963
964
  /** @type {AbortController|null} */
964
965
  null
965
966
  );
966
967
  const label = selection.tagName === "mj-button";
967
- useEffect4(() => () => abortRef.current?.abort(), []);
968
+ const stop = useCallback(() => {
969
+ if (!abortRef.current) return;
970
+ abortRef.current.abort();
971
+ abortRef.current = null;
972
+ editor.showWorking(null);
973
+ }, [editor]);
974
+ useEffect4(() => stop, [stop]);
968
975
  const currentText2 = () => {
969
976
  const element = editor.getElement(selection.id);
970
977
  return (label ? element?.content : element?.html) ?? "";
@@ -972,10 +979,12 @@ function RewriteText({ editor, selection, rewrite }) {
972
979
  const run = async (action, extra = {}) => {
973
980
  if (running) return;
974
981
  const text = currentText2();
982
+ const writing = action === "custom";
975
983
  setError("");
976
984
  setRunning(action);
977
985
  const controller = new AbortController();
978
986
  abortRef.current = controller;
987
+ editor.showWorking(selection.id);
979
988
  try {
980
989
  const result = await rewrite({ action, text, format: label ? "plain" : "html", ...extra }, { signal: controller.signal });
981
990
  if (controller.signal.aborted) return;
@@ -983,98 +992,79 @@ function RewriteText({ editor, selection, rewrite }) {
983
992
  setError(t("The text changed in the meantime, so it was left as it is."));
984
993
  return;
985
994
  }
986
- editor.setContent(label ? result.text : cleanRichText(result.text, document), selection.id);
987
- if (action === "custom") setInstruction("");
988
- if (action === "write") setTopic("");
989
- notify("success", action === "write" ? t("Text written. Ctrl+Z brings back the previous one.") : t("Text rewritten. Ctrl+Z brings back the previous one."));
995
+ editor.setContent(label ? result.text : cleanRichText(result.text, document), selection.id, { reveal: true });
996
+ if (action === "custom") setRequest("");
997
+ notify("success", writing ? t("Text written. Ctrl+Z brings back the previous one.") : t("Text rewritten. Ctrl+Z brings back the previous one."));
990
998
  } catch (err) {
991
999
  if (!controller.signal.aborted) {
992
- setError(err?.message ? t(err.message) : action === "write" ? t("The text could not be written.") : t("The text could not be rewritten."));
1000
+ setError(err?.message ? t(err.message) : writing ? t("The text could not be written.") : t("The text could not be rewritten."));
993
1001
  }
994
1002
  } finally {
995
- if (abortRef.current === controller) abortRef.current = null;
1003
+ if (abortRef.current === controller) {
1004
+ abortRef.current = null;
1005
+ editor.showWorking(null);
1006
+ }
996
1007
  setRunning(null);
997
1008
  }
998
1009
  };
999
1010
  const cancel = () => {
1000
- abortRef.current?.abort();
1011
+ stop();
1001
1012
  setRunning(null);
1002
1013
  };
1003
- const write = () => {
1004
- const subject = topic.trim();
1005
- if (!subject) return;
1014
+ const ask = () => {
1015
+ const words = request.trim();
1016
+ if (!words) return;
1006
1017
  const size = Number.parseFloat(String(editor.getElement(selection.id)?.attributes?.["font-size"] || ""));
1007
1018
  const own = visibleText(currentText2());
1008
- const words = emailWords(editor.exportMjml());
1009
- run("write", {
1010
- instruction: subject,
1011
- context: own ? words.replace(own, "").trim() : words,
1019
+ const email = emailWords(editor.exportMjml());
1020
+ run("custom", {
1021
+ instruction: words,
1022
+ context: own ? email.replace(own, "").trim() : email,
1012
1023
  role: size >= 20 ? "heading" : "text",
1013
1024
  language: String(locale || "en").slice(0, 2)
1014
1025
  });
1015
1026
  };
1016
1027
  const busy = Boolean(running);
1017
1028
  const spinner = /* @__PURE__ */ jsx4(Loader22, { className: "eb:size-3 eb:animate-spin", "aria-hidden": "true" });
1018
- return /* @__PURE__ */ jsxs4(Fragment3, { children: [
1019
- !label && /* @__PURE__ */ jsxs4("section", { className: "eb:space-y-2.5", "aria-label": t("Write with AI"), "data-testid": "eb-write", children: [
1020
- /* @__PURE__ */ jsxs4(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
1021
- /* @__PURE__ */ jsx4(PenLine, { className: "eb:size-3", "aria-hidden": "true" }),
1022
- t("Write with AI")
1023
- ] }),
1024
- /* @__PURE__ */ jsx4(
1025
- PromptForm,
1026
- {
1027
- value: topic,
1028
- onChange: setTopic,
1029
- onSubmit: write,
1030
- placeholder: t("What should it say? e.g. the sale ends Sunday"),
1031
- label: t("What the text is about"),
1032
- busy,
1033
- submitLabel: t("Write"),
1034
- children: running === "write" ? /* @__PURE__ */ jsx4(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx4(PenLine, {})
1035
- }
1036
- )
1029
+ return /* @__PURE__ */ jsxs4("section", { className: "eb:space-y-2.5", "aria-label": t("Write with AI"), "data-testid": "eb-rewrite", children: [
1030
+ /* @__PURE__ */ jsxs4(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
1031
+ /* @__PURE__ */ jsx4(Sparkles, { className: "eb:size-3", "aria-hidden": "true" }),
1032
+ t("Write with AI")
1037
1033
  ] }),
1038
- /* @__PURE__ */ jsxs4("section", { className: "eb:space-y-2.5", "aria-label": t("Rewrite with AI"), "data-testid": "eb-rewrite", children: [
1039
- /* @__PURE__ */ jsxs4(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
1040
- /* @__PURE__ */ jsx4(Sparkles, { className: "eb:size-3", "aria-hidden": "true" }),
1041
- t("Rewrite with AI")
1042
- ] }),
1043
- /* @__PURE__ */ jsxs4("div", { className: "eb:flex eb:flex-wrap eb:gap-1.5", children: [
1044
- REWRITE_ACTIONS.map((action) => /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), disabled: busy, onClick: () => run(action.id), children: [
1045
- running === action.id && spinner,
1046
- t(action.label)
1047
- ] }, action.id)),
1048
- /* @__PURE__ */ jsxs4(DropdownMenu, { children: [
1049
- /* @__PURE__ */ jsx4(DropdownMenuTrigger, { asChild: true, disabled: busy, children: /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), children: [
1050
- running === "translate" ? spinner : /* @__PURE__ */ jsx4(Languages, { className: "eb:size-3", "aria-hidden": "true" }),
1051
- t("Translate"),
1052
- /* @__PURE__ */ jsx4(ChevronDown2, { className: "eb:size-3", "aria-hidden": "true" })
1053
- ] }) }),
1054
- /* @__PURE__ */ jsx4(DropdownMenuContent, { align: "start", "aria-label": t("Translate into"), children: REWRITE_LANGUAGES.map((code) => /* @__PURE__ */ jsx4(DropdownMenuItem, { lang: code, onSelect: () => run("translate", { targetLanguage: code }), children: nativeName(code) }, code)) })
1055
- ] })
1056
- ] }),
1057
- /* @__PURE__ */ jsx4(
1058
- PromptForm,
1059
- {
1060
- value: instruction,
1061
- onChange: setInstruction,
1062
- onSubmit: () => run("custom", { instruction: instruction.trim() }),
1063
- placeholder: t("Or say what to change\u2026"),
1064
- label: t("What to change"),
1065
- busy,
1066
- submitLabel: t("Rewrite"),
1067
- children: running === "custom" ? /* @__PURE__ */ jsx4(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx4(Sparkles, {})
1068
- }
1069
- ),
1070
- running && /* @__PURE__ */ jsxs4("p", { className: "eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted", role: "status", "aria-live": "polite", children: [
1071
- running === "write" ? t("Writing\u2026") : t("Rewriting\u2026"),
1072
- /* @__PURE__ */ jsx4(Button, { type: "button", variant: "link", size: "xs", className: "eb:h-auto eb:px-0", onClick: cancel, children: t("Cancel") })
1073
- ] }),
1074
- error && /* @__PURE__ */ jsxs4("p", { role: "alert", className: "eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive", children: [
1075
- /* @__PURE__ */ jsx4(TriangleAlert3, { className: "eb:mt-px eb:size-3.5 eb:shrink-0", "aria-hidden": "true" }),
1076
- error
1034
+ /* @__PURE__ */ jsx4(
1035
+ PromptForm,
1036
+ {
1037
+ value: request,
1038
+ onChange: setRequest,
1039
+ onSubmit: ask,
1040
+ placeholder: t("What should it say, or what should change? e.g. the sale ends Sunday"),
1041
+ label: t("Ask the AI"),
1042
+ busy,
1043
+ submitLabel: t("Write"),
1044
+ children: running === "custom" ? /* @__PURE__ */ jsx4(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx4(Sparkles, {})
1045
+ }
1046
+ ),
1047
+ /* @__PURE__ */ jsxs4("div", { className: "eb:flex eb:flex-wrap eb:gap-1.5", children: [
1048
+ REWRITE_ACTIONS.map((action) => /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), disabled: busy, onClick: () => run(action.id), children: [
1049
+ running === action.id && spinner,
1050
+ t(action.label)
1051
+ ] }, action.id)),
1052
+ /* @__PURE__ */ jsxs4(DropdownMenu, { children: [
1053
+ /* @__PURE__ */ jsx4(DropdownMenuTrigger, { asChild: true, disabled: busy, children: /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), children: [
1054
+ running === "translate" ? spinner : /* @__PURE__ */ jsx4(Languages, { className: "eb:size-3", "aria-hidden": "true" }),
1055
+ t("Translate"),
1056
+ /* @__PURE__ */ jsx4(ChevronDown2, { className: "eb:size-3", "aria-hidden": "true" })
1057
+ ] }) }),
1058
+ /* @__PURE__ */ jsx4(DropdownMenuContent, { align: "start", "aria-label": t("Translate into"), children: REWRITE_LANGUAGES.map((code) => /* @__PURE__ */ jsx4(DropdownMenuItem, { lang: code, onSelect: () => run("translate", { targetLanguage: code }), children: nativeName(code) }, code)) })
1077
1059
  ] })
1060
+ ] }),
1061
+ running && /* @__PURE__ */ jsxs4("p", { className: "eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted", role: "status", "aria-live": "polite", children: [
1062
+ running === "custom" ? t("Writing\u2026") : t("Rewriting\u2026"),
1063
+ /* @__PURE__ */ jsx4(Button, { type: "button", variant: "link", size: "xs", className: "eb:h-auto eb:px-0", onClick: cancel, children: t("Cancel") })
1064
+ ] }),
1065
+ error && /* @__PURE__ */ jsxs4("p", { role: "alert", className: "eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive", children: [
1066
+ /* @__PURE__ */ jsx4(TriangleAlert3, { className: "eb:mt-px eb:size-3.5 eb:shrink-0", "aria-hidden": "true" }),
1067
+ error
1078
1068
  ] })
1079
1069
  ] });
1080
1070
  }
@@ -1238,7 +1228,7 @@ function SubjectIdeas({ editor, meta, onSubject, suggest, variables = null }) {
1238
1228
  running ? spinner : /* @__PURE__ */ jsx5(Sparkles2, { className: "eb:size-3", "aria-hidden": "true" }),
1239
1229
  t("Suggest subjects")
1240
1230
  ] }),
1241
- ideas && /* @__PURE__ */ jsxs5("div", { className: "eb:space-y-2 eb:rounded-md eb:border eb:border-border eb:p-1.5", children: [
1231
+ ideas && /* @__PURE__ */ jsxs5("div", { className: "eb:space-y-2 eb:rounded-lg2 eb:border eb:border-border eb:p-1.5", children: [
1242
1232
  /* @__PURE__ */ jsx5("div", { role: "radiogroup", "aria-label": t("Subject ideas"), className: "eb:space-y-0.5", onKeyDown, children: options.map((option, index) => {
1243
1233
  const chosen = index === checked;
1244
1234
  return /* @__PURE__ */ jsxs5(
@@ -1249,7 +1239,7 @@ function SubjectIdeas({ editor, meta, onSubject, suggest, variables = null }) {
1249
1239
  "aria-checked": chosen,
1250
1240
  tabIndex: index === tabStop ? 0 : -1,
1251
1241
  className: cn(
1252
- "eb:flex eb:w-full eb:items-start eb:gap-2 eb:rounded eb:px-2 eb:py-1.5 eb:text-left eb:text-[12.5px] eb:leading-snug eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
1242
+ "eb:flex eb:w-full eb:items-start eb:gap-2 eb:rounded-md eb:px-2 eb:py-1.5 eb:text-left eb:text-[12.5px] eb:leading-snug eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
1253
1243
  chosen ? "eb:bg-primary/10 eb:text-foreground" : "eb:text-foreground-lighter eb:hover:bg-muted"
1254
1244
  ),
1255
1245
  onClick: () => onSubject(option.text),
@@ -1437,6 +1427,7 @@ export {
1437
1427
  DEFAULT_CLAUDE_MODEL,
1438
1428
  EmailGenerationError,
1439
1429
  GENERATION_ERRORS,
1430
+ LANGUAGETOOL_PUBLIC_API,
1440
1431
  REWRITE_ACTIONS,
1441
1432
  REWRITE_LANGUAGES,
1442
1433
  agentEmailModel,
@@ -1444,6 +1435,7 @@ export {
1444
1435
  claudeProvider,
1445
1436
  createAi,
1446
1437
  createEmailGenerator,
1438
+ createLanguageToolProofreader,
1447
1439
  diffWords,
1448
1440
  emailWords,
1449
1441
  failureCode,