best-email-builder 0.20.0 → 0.22.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 (43) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/ai-server.js +3 -3
  3. package/dist/ai.js +6 -6
  4. package/dist/builder.js +8 -8
  5. package/dist/{chunk-RZPCNCWF.js → chunk-2XSNS7EW.js} +3 -3
  6. package/dist/{chunk-RZPCNCWF.js.map → chunk-2XSNS7EW.js.map} +1 -1
  7. package/dist/{chunk-ACJQTHMG.js → chunk-3FKHX47M.js} +62 -16
  8. package/dist/chunk-3FKHX47M.js.map +1 -0
  9. package/dist/{chunk-EAE6R7EQ.js → chunk-4SRNGFAV.js} +3 -3
  10. package/dist/{chunk-RCN6FCCK.js → chunk-7ZI7ZOYQ.js} +12 -12
  11. package/dist/chunk-7ZI7ZOYQ.js.map +1 -0
  12. package/dist/{chunk-FJ6IJO3K.js → chunk-C22PQBW4.js} +3 -3
  13. package/dist/{chunk-DLQYMFN7.js → chunk-HE2VAOLR.js} +25 -1
  14. package/dist/chunk-HE2VAOLR.js.map +1 -0
  15. package/dist/{chunk-Q2J547BE.js → chunk-IGC3I4XL.js} +2 -2
  16. package/dist/{chunk-THOQ3RVD.js → chunk-LQ3JCPZ2.js} +120 -4
  17. package/dist/chunk-LQ3JCPZ2.js.map +1 -0
  18. package/dist/{chunk-VLBVJJ4X.js → chunk-OSQ5YGHL.js} +2 -2
  19. package/dist/{chunk-LYGVIQGG.js → chunk-WWP3FQYO.js} +4 -4
  20. package/dist/{chunk-2N6YC6JN.js → chunk-XYXN3UBQ.js} +2 -2
  21. package/dist/index.js +10 -10
  22. package/dist/library.js +7 -5
  23. package/dist/server.js +5 -5
  24. package/dist/styles.css +1 -1
  25. package/dist/types/core/EmailEditor.d.ts +10 -3
  26. package/dist/types/core/constants.d.ts +1 -1
  27. package/dist/types/core/mjmlAttributes.d.ts +22 -0
  28. package/dist/types/engine/NativeAdapter.d.ts +1 -1
  29. package/dist/types/features/preview/PreviewButton.d.ts +11 -8
  30. package/dist/types/library.d.ts +1 -0
  31. package/dist/types/renderer/compileEditorMjml.d.ts +5 -1
  32. package/dist/types/renderer/mobileStyles.d.ts +20 -0
  33. package/package.json +1 -1
  34. package/dist/chunk-ACJQTHMG.js.map +0 -1
  35. package/dist/chunk-DLQYMFN7.js.map +0 -1
  36. package/dist/chunk-RCN6FCCK.js.map +0 -1
  37. package/dist/chunk-THOQ3RVD.js.map +0 -1
  38. /package/dist/{chunk-EAE6R7EQ.js.map → chunk-4SRNGFAV.js.map} +0 -0
  39. /package/dist/{chunk-FJ6IJO3K.js.map → chunk-C22PQBW4.js.map} +0 -0
  40. /package/dist/{chunk-Q2J547BE.js.map → chunk-IGC3I4XL.js.map} +0 -0
  41. /package/dist/{chunk-VLBVJJ4X.js.map → chunk-OSQ5YGHL.js.map} +0 -0
  42. /package/dist/{chunk-LYGVIQGG.js.map → chunk-WWP3FQYO.js.map} +0 -0
  43. /package/dist/{chunk-2N6YC6JN.js.map → chunk-XYXN3UBQ.js.map} +0 -0
@@ -6,28 +6,32 @@ import {
6
6
  useLayoutWidth,
7
7
  useSearchShortcut,
8
8
  withThumbnailImages
9
- } from "./chunk-RCN6FCCK.js";
9
+ } from "./chunk-7ZI7ZOYQ.js";
10
10
  import {
11
11
  BORDER_STYLES,
12
12
  BRAND_NOTES,
13
13
  LONGHAND_SPACING,
14
14
  MAX_BORDER,
15
15
  MJML_DEFAULTS,
16
+ MOBILE_PREFIX,
16
17
  compileEditorMjml,
17
18
  countImagesWithoutPicture,
18
19
  formatBorder,
19
20
  formatSpacing,
20
21
  logoWidthFor,
22
+ mobileOverrides,
21
23
  parseBorder,
22
24
  parseSpacing,
23
25
  toAttributes,
24
- toValues
25
- } from "./chunk-THOQ3RVD.js";
26
+ toMobileAttributes,
27
+ toValues,
28
+ withMobile
29
+ } from "./chunk-LQ3JCPZ2.js";
26
30
  import {
27
31
  cleanRichText,
28
32
  escapeText,
29
33
  textOfHtml
30
- } from "./chunk-Q2J547BE.js";
34
+ } from "./chunk-IGC3I4XL.js";
31
35
  import {
32
36
  Button,
33
37
  Dialog,
@@ -68,7 +72,7 @@ import {
68
72
  createHttpStorage,
69
73
  useT,
70
74
  useUi
71
- } from "./chunk-FJ6IJO3K.js";
75
+ } from "./chunk-C22PQBW4.js";
72
76
  import {
73
77
  BRAND_FONT_SIZES,
74
78
  DEFAULT_BUTTON_URL,
@@ -113,11 +117,11 @@ import {
113
117
  setAttributes,
114
118
  setContent,
115
119
  toProject
116
- } from "./chunk-RZPCNCWF.js";
120
+ } from "./chunk-2XSNS7EW.js";
117
121
  import {
118
122
  IMAGE_ATTRIBUTES,
119
123
  isSafeUrl
120
- } from "./chunk-VLBVJJ4X.js";
124
+ } from "./chunk-OSQ5YGHL.js";
121
125
  import {
122
126
  CUSTOM_GROUP,
123
127
  DEFAULT_VARIABLES,
@@ -133,7 +137,7 @@ import {
133
137
  translatorFor,
134
138
  validateCustomVariable,
135
139
  validateVariableEdit
136
- } from "./chunk-DLQYMFN7.js";
140
+ } from "./chunk-HE2VAOLR.js";
137
141
 
138
142
  // src/core/events.js
139
143
  function createEmitter({ onError } = {}) {
@@ -215,11 +219,14 @@ function createEmailEditor({ adapter, blocks, features = null, t = identity }) {
215
219
  function toEmailSelection(selection) {
216
220
  if (!selection) return null;
217
221
  const block = blockForTag(selection.tagName);
222
+ const raw = selection.attributes || {};
223
+ const shown = adapter.getDevice?.() === "mobile" ? { ...selection, attributes: withMobile(raw) } : selection;
218
224
  return {
219
- ...selection,
225
+ ...shown,
220
226
  blockId: block?.id || null,
221
227
  label: labelFor(selection, block),
222
- ...valuesOf(selection, block)
228
+ mobileOverrides: [...mobileOverrides(raw)],
229
+ ...valuesOf(shown, block)
223
230
  };
224
231
  }
225
232
  let brand = null;
@@ -345,7 +352,17 @@ function createEmailEditor({ adapter, blocks, features = null, t = identity }) {
345
352
  getRootId: () => status === "ready" ? adapter.getRootId() : null,
346
353
  updateProperties(values, id = null) {
347
354
  requireReady("updateProperties");
348
- adapter.updateProperties(Array.isArray(id) ? id : targetOf(id, "updateProperties"), toAttributes(values));
355
+ const ids = Array.isArray(id) ? id : [targetOf(id, "updateProperties")];
356
+ const attributes = toAttributes(values);
357
+ const tag = adapter.getDevice?.() === "mobile" ? adapter.describe(ids[0])?.tagName : null;
358
+ adapter.updateProperties(Array.isArray(id) ? ids : ids[0], tag ? toMobileAttributes(attributes, tag) : attributes);
359
+ },
360
+ /** The phone looks like the computer again: the element's phone values go. */
361
+ clearMobileStyles(id = null) {
362
+ requireReady("clearMobileStyles");
363
+ const target = targetOf(id, "clearMobileStyles");
364
+ const keys = Object.keys(adapter.describe(target)?.attributes || {}).filter((key) => key.startsWith(MOBILE_PREFIX));
365
+ if (keys.length) adapter.updateProperties(target, Object.fromEntries(keys.map((key) => [key, null])));
349
366
  },
350
367
  /** `reveal`: its words come in one after the other on the canvas (a text the AI wrote). */
351
368
  setContent(content, id = null, options = {}) {
@@ -6117,7 +6134,7 @@ function ItemChoices({ label, choices, onPick }) {
6117
6134
 
6118
6135
  // src/ui/PropertiesPanel.jsx
6119
6136
  import { useMemo as useMemo5, useRef as useRef10 } from "react";
6120
- import { Trash2 as Trash24, X as X2 } from "lucide-react";
6137
+ import { Smartphone, Trash2 as Trash24, X as X2 } from "lucide-react";
6121
6138
 
6122
6139
  // src/ui/fields.jsx
6123
6140
  import { useEffect as useEffect9, useRef as useRef7, useState as useState11 } from "react";
@@ -7311,6 +7328,33 @@ function PropertyGroups({ editor, element, block, idPrefix, services = null, hid
7311
7328
  ] }, group);
7312
7329
  });
7313
7330
  }
7331
+ var STYLE_LABELS = { "font-weight": "Bold", "font-style": "Italic", "text-decoration": "Underline" };
7332
+ function MobileStyles({ editor, element, block }) {
7333
+ const t = useT();
7334
+ const labelOf2 = (key) => block?.properties?.find((property) => property.key === key)?.label || STYLE_LABELS[key] || key;
7335
+ return /* @__PURE__ */ jsxs16("section", { className: "eb:space-y-2 eb:rounded-lg2 eb:border eb:border-primary/30 eb:bg-primary/5 eb:p-3", "data-testid": "eb-mobile-styles", children: [
7336
+ /* @__PURE__ */ jsxs16("p", { className: "eb:flex eb:items-start eb:gap-2 eb:text-[12px] eb:leading-relaxed eb:text-foreground-lighter", children: [
7337
+ /* @__PURE__ */ jsx17(Smartphone, { className: "eb:mt-0.5 eb:size-3.5 eb:shrink-0 eb:text-primary", "aria-hidden": "true" }),
7338
+ t("Mobile view: the styles you change here apply to phones only. Links and pictures are the same on every screen.")
7339
+ ] }),
7340
+ element.mobileOverrides.length > 0 && /* @__PURE__ */ jsxs16(Fragment7, { children: [
7341
+ /* @__PURE__ */ jsx17("ul", { "aria-label": t("Different on phones"), className: "eb:flex eb:flex-wrap eb:gap-1", children: element.mobileOverrides.map((key) => /* @__PURE__ */ jsxs16("li", { className: "eb:inline-flex eb:h-6 eb:items-center eb:gap-0.5 eb:rounded-md eb:bg-background eb:pr-0.5 eb:pl-2 eb:text-[12px] eb:text-foreground eb:ring-1 eb:ring-border", children: [
7342
+ t(labelOf2(key)),
7343
+ /* @__PURE__ */ jsx17(
7344
+ Button,
7345
+ {
7346
+ variant: "ghost",
7347
+ size: "icon-xs",
7348
+ "aria-label": t("Back to the desktop value: {name}", { name: t(labelOf2(key)) }),
7349
+ onClick: () => editor.updateProperties({ [key]: null }, element.id),
7350
+ children: /* @__PURE__ */ jsx17(X2, {})
7351
+ }
7352
+ )
7353
+ ] }, key)) }),
7354
+ /* @__PURE__ */ jsx17(Button, { variant: "outline", size: "sm-compact", onClick: () => editor.clearMobileStyles(element.id), children: t("Same as desktop") })
7355
+ ] })
7356
+ ] });
7357
+ }
7314
7358
  var LABEL_PROPERTY = { key: "content", label: "Label", type: "text", group: GROUPS.content };
7315
7359
  var REWRITABLE_TAGS = /* @__PURE__ */ new Set(["mj-text", "mj-button"]);
7316
7360
  function PanelHeader({ title, onClose, closeLabel = "Deselect" }) {
@@ -7464,6 +7508,7 @@ function PropertiesPanel({
7464
7508
  }
7465
7509
  )
7466
7510
  ] }) : /* @__PURE__ */ jsxs16("div", { className: "eb:space-y-4 eb:p-4", children: [
7511
+ editor.getDevice() === "mobile" && /* @__PURE__ */ jsx17(MobileStyles, { editor, element: selection, block }),
7467
7512
  selection.content !== null && selection.content !== void 0 && /* @__PURE__ */ jsxs16("section", { className: "eb:space-y-3", children: [
7468
7513
  /* @__PURE__ */ jsx17(SectionLabel, { children: t(GROUPS.content) }),
7469
7514
  /* @__PURE__ */ jsx17(
@@ -7485,7 +7530,7 @@ function PropertiesPanel({
7485
7530
  }
7486
7531
 
7487
7532
  // src/ui/Toolbar.jsx
7488
- import { ArrowLeft, Monitor, Redo2, Smartphone, Undo2 } from "lucide-react";
7533
+ import { ArrowLeft, Monitor, Redo2, Smartphone as Smartphone2, Undo2 } from "lucide-react";
7489
7534
  import { Fragment as Fragment8, jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
7490
7535
  function Toolbar({
7491
7536
  title,
@@ -7534,7 +7579,7 @@ function Toolbar({
7534
7579
  !compact && t("Desktop")
7535
7580
  ] }),
7536
7581
  /* @__PURE__ */ jsxs17(TabsTrigger, { value: "mobile", disabled: !ready, "aria-label": compact ? t("Mobile") : void 0, children: [
7537
- /* @__PURE__ */ jsx18(Smartphone, {}),
7582
+ /* @__PURE__ */ jsx18(Smartphone2, {}),
7538
7583
  !compact && t("Mobile")
7539
7584
  ] })
7540
7585
  ] }) })
@@ -7721,7 +7766,8 @@ function useEmailEditorState(editor) {
7721
7766
  editor.on("selection", (selection) => patch({ selection })),
7722
7767
  editor.on("format", (format) => patch({ format })),
7723
7768
  editor.on("history", ({ canUndo, canRedo }) => patch({ canUndo, canRedo })),
7724
- editor.on("device", (device) => patch({ device })),
7769
+ // The Mobile view shows the selection as a phone has it.
7770
+ editor.on("device", (device) => patch({ device, selection: editor.getSelection() })),
7725
7771
  editor.on("change", () => {
7726
7772
  setState((s) => ({ ...s, changes: s.changes + 1 }));
7727
7773
  measure();
@@ -8581,4 +8627,4 @@ export {
8581
8627
  EmailBuilder,
8582
8628
  EmailBuilderBoundary
8583
8629
  };
8584
- //# sourceMappingURL=chunk-ACJQTHMG.js.map
8630
+ //# sourceMappingURL=chunk-3FKHX47M.js.map