@maildeno/editor 0.1.3 → 0.4.2

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 (169) hide show
  1. package/CHANGELOG.md +258 -0
  2. package/README.md +397 -381
  3. package/dist/RowPreviewChildren-DT0y0lKC.js +4 -0
  4. package/dist/RowPreviewChildren-OsbF7_vu.js +4 -0
  5. package/dist/RowPreviewLegacyComponent-BV4b5bHQ.js +487 -0
  6. package/dist/RowPreviewLegacyComponent-C08MGJVT.js +487 -0
  7. package/dist/RowPreviewRow-ByxeBYV8.js +112 -0
  8. package/dist/RowPreviewRow-N-hh5l_H.js +112 -0
  9. package/dist/adapters/errors.d.ts +59 -0
  10. package/dist/adapters/index.d.ts +31 -0
  11. package/dist/adapters/types.d.ts +68 -0
  12. package/dist/brand.d.ts +15 -0
  13. package/dist/components/DesktopOnlyNotice.vue.d.ts +20 -0
  14. package/dist/components/features/emailBuilder/EmailEditor.vue.d.ts +182 -0
  15. package/dist/components/features/emailBuilder/assistant/AssistantPanel.vue.d.ts +37 -0
  16. package/dist/components/features/emailBuilder/blocks/AnchorBlock.vue.d.ts +3 -0
  17. package/dist/components/features/emailBuilder/blocks/ButtonBlock.vue.d.ts +3 -0
  18. package/dist/components/features/emailBuilder/blocks/DividerBlock.vue.d.ts +3 -0
  19. package/dist/components/features/emailBuilder/blocks/HeadingBlock.vue.d.ts +3 -0
  20. package/dist/components/features/emailBuilder/blocks/ImageBlock.vue.d.ts +3 -0
  21. package/dist/components/features/emailBuilder/blocks/ListBlock.vue.d.ts +3 -0
  22. package/dist/components/features/emailBuilder/blocks/MenuBlock.vue.d.ts +3 -0
  23. package/dist/components/features/emailBuilder/blocks/ParagraphBlock.vue.d.ts +3 -0
  24. package/dist/components/features/emailBuilder/blocks/SocialsBlock.vue.d.ts +3 -0
  25. package/dist/components/features/emailBuilder/blocks/SpacerBlock.vue.d.ts +3 -0
  26. package/dist/components/features/emailBuilder/blocks/VideoBlock.vue.d.ts +3 -0
  27. package/dist/components/features/emailBuilder/canvas/Canvas.vue.d.ts +3 -0
  28. package/dist/components/features/emailBuilder/canvas/CanvasColumn.vue.d.ts +49 -0
  29. package/dist/components/features/emailBuilder/canvas/CanvasComponent.vue.d.ts +56 -0
  30. package/dist/components/features/emailBuilder/canvas/CanvasElement.vue.d.ts +21 -0
  31. package/dist/components/features/emailBuilder/canvas/CanvasRow.vue.d.ts +49 -0
  32. package/dist/components/features/emailBuilder/canvas/CanvasRowSpacer.vue.d.ts +40 -0
  33. package/dist/components/features/emailBuilder/health/HealthIndicator.vue.d.ts +3 -0
  34. package/dist/components/features/emailBuilder/layout/Header.vue.d.ts +54 -0
  35. package/dist/components/features/emailBuilder/layout/SendEmail.vue.d.ts +21 -0
  36. package/dist/components/features/emailBuilder/layout/SidebarLeft.vue.d.ts +3 -0
  37. package/dist/components/features/emailBuilder/layout/SidebarRight.vue.d.ts +3 -0
  38. package/dist/components/features/emailBuilder/panels/AnchorPanel.vue.d.ts +3 -0
  39. package/dist/components/features/emailBuilder/panels/ButtonPanel.vue.d.ts +3 -0
  40. package/dist/components/features/emailBuilder/panels/DividerPanel.vue.d.ts +3 -0
  41. package/dist/components/features/emailBuilder/panels/HeadingPanel.vue.d.ts +3 -0
  42. package/dist/components/features/emailBuilder/panels/ImagePanel.vue.d.ts +3 -0
  43. package/dist/components/features/emailBuilder/panels/ListPanel.vue.d.ts +3 -0
  44. package/dist/components/features/emailBuilder/panels/MenuPanel.vue.d.ts +3 -0
  45. package/dist/components/features/emailBuilder/panels/ParagraphPanel.vue.d.ts +3 -0
  46. package/dist/components/features/emailBuilder/panels/RowColumnPanel.vue.d.ts +13 -0
  47. package/dist/components/features/emailBuilder/panels/RowPanel.vue.d.ts +13 -0
  48. package/dist/components/features/emailBuilder/panels/RowSpacerPanel.vue.d.ts +13 -0
  49. package/dist/components/features/emailBuilder/panels/SocialsPanel.vue.d.ts +3 -0
  50. package/dist/components/features/emailBuilder/panels/SpacerPanel.vue.d.ts +3 -0
  51. package/dist/components/features/emailBuilder/panels/VideoPanel.vue.d.ts +3 -0
  52. package/dist/components/features/emailBuilder/panels/shared/DeviceTabs.vue.d.ts +19 -0
  53. package/dist/components/features/emailBuilder/panels/shared/LinkFieldMergeTags.vue.d.ts +31 -0
  54. package/dist/components/features/emailBuilder/panels/shared/OverrideBadge.vue.d.ts +9 -0
  55. package/dist/components/features/emailBuilder/panels/shared/PreviewBadge.vue.d.ts +11 -0
  56. package/dist/components/features/emailBuilder/panels/shared/TextFieldMergeTags.vue.d.ts +25 -0
  57. package/dist/components/features/emailBuilder/panels/ui/BoxStylingSection.vue.d.ts +7 -0
  58. package/dist/components/features/emailBuilder/panels/ui/PropertyAlignment.vue.d.ts +30 -0
  59. package/dist/components/features/emailBuilder/panels/ui/PropertyColor.vue.d.ts +75 -0
  60. package/dist/components/features/emailBuilder/panels/ui/PropertyGradientColor.vue.d.ts +27 -0
  61. package/dist/components/features/emailBuilder/panels/ui/PropertyNumberSlider.vue.d.ts +74 -0
  62. package/dist/components/features/emailBuilder/panels/ui/PropertySection.vue.d.ts +17 -0
  63. package/dist/components/features/emailBuilder/panels/ui/PropertySelect.vue.d.ts +74 -0
  64. package/dist/components/features/emailBuilder/panels/ui/PropertyTextStyle.vue.d.ts +52 -0
  65. package/dist/components/features/emailBuilder/panels/ui/PropertyTextStylePanel.vue.d.ts +72 -0
  66. package/dist/components/features/emailBuilder/panels/ui/PropertyToggle.vue.d.ts +45 -0
  67. package/dist/components/features/emailBuilder/panels/ui/PropertyVisibility.vue.d.ts +32 -0
  68. package/dist/components/features/emailBuilder/panels/ui/SpacingControl.vue.d.ts +19 -0
  69. package/dist/components/features/emailBuilder/panels/ui/color-picker/AlphaSlider.vue.d.ts +28 -0
  70. package/dist/components/features/emailBuilder/panels/ui/color-picker/ColorPickerPanel.vue.d.ts +31 -0
  71. package/dist/components/features/emailBuilder/panels/ui/color-picker/HueSlider.vue.d.ts +19 -0
  72. package/dist/components/features/emailBuilder/panels/ui/color-picker/RecentColors.vue.d.ts +20 -0
  73. package/dist/components/features/emailBuilder/panels/ui/color-picker/SVPanel.vue.d.ts +39 -0
  74. package/dist/components/features/emailBuilder/panels/ui/visibility-rule/Rule.vue.d.ts +28 -0
  75. package/dist/components/features/emailBuilder/preview/PreviewScreen.vue.d.ts +7 -0
  76. package/dist/components/features/emailBuilder/preview/ui/PreviewCanvas.vue.d.ts +10 -0
  77. package/dist/components/features/emailBuilder/preview/ui/PreviewCapabilityBadges.vue.d.ts +12 -0
  78. package/dist/components/features/emailBuilder/preview/ui/PreviewClientCard.vue.d.ts +20 -0
  79. package/dist/components/features/emailBuilder/preview/ui/PreviewClientList.vue.d.ts +21 -0
  80. package/dist/components/features/emailBuilder/preview/ui/PreviewClientPicker.vue.d.ts +16 -0
  81. package/dist/components/features/emailBuilder/preview/ui/PreviewComponent.vue.d.ts +10 -0
  82. package/dist/components/features/emailBuilder/preview/ui/PreviewDetailView.vue.d.ts +41 -0
  83. package/dist/components/features/emailBuilder/preview/ui/PreviewRendered.vue.d.ts +8 -0
  84. package/dist/components/features/emailBuilder/product/RowPreview.vue.d.ts +8 -0
  85. package/dist/components/features/emailBuilder/product/RowPreviewChildren.vue.d.ts +14 -0
  86. package/dist/components/features/emailBuilder/product/RowPreviewLegacyComponent.vue.d.ts +14 -0
  87. package/dist/components/features/emailBuilder/product/RowPreviewRow.vue.d.ts +9 -0
  88. package/dist/components/features/emailBuilder/product/SavedRowsPanel.vue.d.ts +3 -0
  89. package/dist/components/features/emailBuilder/product/SavedTemplatesPanel.vue.d.ts +13 -0
  90. package/dist/components/features/emailBuilder/product/VersionHistoryPanel.vue.d.ts +14 -0
  91. package/dist/components/features/emailBuilder/sidebar/SidebarBlockButton.vue.d.ts +35 -0
  92. package/dist/components/features/emailBuilder/tabs/GeneralTab.vue.d.ts +3 -0
  93. package/dist/components/features/emailBuilder/tabs/LayoutTab.vue.d.ts +3 -0
  94. package/dist/components/features/emailBuilder/tabs/content/ContentTab.vue.d.ts +3 -0
  95. package/dist/components/features/emailBuilder/tabs/content/LayersPanel.vue.d.ts +7 -0
  96. package/dist/components/features/emailBuilder/tabs/general/MergeTagsTab.vue.d.ts +3 -0
  97. package/dist/components/features/emailBuilder/tabs/general/StylesTab.vue.d.ts +3 -0
  98. package/dist/components/features/emailBuilder/tabs/general/VisibilityTab.vue.d.ts +3 -0
  99. package/dist/components/features/emailBuilder/tabs/general/VisibilityWrapESPTab.vue.d.ts +3 -0
  100. package/dist/components/features/emailBuilder/tabs/general/merge-tags/LinkTagTab.vue.d.ts +3 -0
  101. package/dist/components/features/emailBuilder/tabs/general/merge-tags/MergeTagTab.vue.d.ts +3 -0
  102. package/dist/components/features/emailBuilder/ui/LinkInputDialog.vue.d.ts +17 -0
  103. package/dist/components/features/emailBuilder/ui/canvas/CanvasRowDropZone.vue.d.ts +12 -0
  104. package/dist/components/features/emailBuilder/ui/canvas/DropZone.vue.d.ts +10 -0
  105. package/dist/components/features/emailBuilder/ui/canvas/Loader.vue.d.ts +19 -0
  106. package/dist/components/features/emailBuilder/ui/layers-panel/ComponentIcon.vue.d.ts +7 -0
  107. package/dist/components/features/emailBuilder/ui/layers-panel/LayerColumnChildren.vue.d.ts +42 -0
  108. package/dist/components/features/emailBuilder/ui/layers-panel/LayerDropLine.vue.d.ts +8 -0
  109. package/dist/components/features/emailBuilder/ui/renderers/AnchorRenderer.vue.d.ts +10 -0
  110. package/dist/components/features/emailBuilder/ui/renderers/DividerRenderer.vue.d.ts +10 -0
  111. package/dist/components/features/emailBuilder/ui/renderers/HeadingRenderer.vue.d.ts +10 -0
  112. package/dist/components/features/emailBuilder/ui/renderers/ImageRenderer.vue.d.ts +10 -0
  113. package/dist/components/features/emailBuilder/ui/renderers/ListRenderer.vue.d.ts +10 -0
  114. package/dist/components/features/emailBuilder/ui/renderers/MenuRenderer.vue.d.ts +10 -0
  115. package/dist/components/features/emailBuilder/ui/renderers/ParagraphRenderer.vue.d.ts +10 -0
  116. package/dist/components/features/emailBuilder/ui/renderers/SocialsRenderer.vue.d.ts +10 -0
  117. package/dist/components/features/emailBuilder/ui/renderers/SpacerRenderer.vue.d.ts +10 -0
  118. package/dist/components/features/emailBuilder/ui/renderers/VideoRenderer.vue.d.ts +10 -0
  119. package/dist/components/features/emailBuilder/ui/rich-text-editor/RichTextEditor.vue.d.ts +12 -0
  120. package/dist/components/features/emailBuilder/ui/rich-text-editor/pickers/MergeTagPicker.vue.d.ts +18 -0
  121. package/dist/components/features/emailBuilder/ui/rich-text-editor/pickers/RichTextColorPicker.vue.d.ts +15 -0
  122. package/dist/components/features/emailBuilder/ui/visibility/SupportBadge.vue.d.ts +10 -0
  123. package/dist/components/features/emailBuilder/ui/visibility/VisibilityPopover.vue.d.ts +45 -0
  124. package/dist/components/ui/ConfirmDialog.vue.d.ts +3 -0
  125. package/dist/components/ui/Icon.vue.d.ts +33 -0
  126. package/dist/components/ui/InfoDialog.vue.d.ts +12 -0
  127. package/dist/components/ui/Loading.vue.d.ts +6 -0
  128. package/dist/components/ui/ShadowSafeToast.vue.d.ts +3 -0
  129. package/dist/components/ui/primitives/Button.vue.d.ts +23 -0
  130. package/dist/components/ui/primitives/DatePicker.vue.d.ts +16 -0
  131. package/dist/components/ui/primitives/Dialog.vue.d.ts +34 -0
  132. package/dist/components/ui/primitives/InputText.vue.d.ts +29 -0
  133. package/dist/components/ui/primitives/Message.vue.d.ts +20 -0
  134. package/dist/components/ui/primitives/Select.vue.d.ts +22 -0
  135. package/dist/composables/emailBuilder/components/useSystemRows.d.ts +22 -0
  136. package/dist/composables/emailBuilder/core/ui/useLayerHoverScroll.d.ts +10 -10
  137. package/dist/composables/emailBuilder/core/useEmailBuilder.d.ts +18 -0
  138. package/dist/composables/emailBuilder/export/logic/espLogicWrapper.d.ts +4 -4
  139. package/dist/composables/emailBuilder/export/targets/templateSnapshot.d.ts +24 -0
  140. package/dist/composables/emailBuilder/persistence/useEmailBuilderPersistence.d.ts +1 -1
  141. package/dist/composables/system/useColorScheme.d.ts +16 -0
  142. package/dist/editor.css +1072 -682
  143. package/dist/element-C2ZH0Z_i.js +86561 -0
  144. package/dist/element-scoped-styles.css +1072 -682
  145. package/dist/element.d.ts +1 -1
  146. package/dist/element.js +5 -2
  147. package/dist/estree-DBJlF9un.js +4876 -0
  148. package/dist/html-3PMDtB0V.js +3123 -0
  149. package/dist/index-DhFg3uKs.js +75864 -0
  150. package/dist/index.d.ts +4 -2
  151. package/dist/index.js +16 -67053
  152. package/dist/init.d.ts +95 -2
  153. package/dist/init.js +166 -122
  154. package/dist/standalone-DKWMQftY.js +2391 -0
  155. package/dist/theme.d.ts +68 -17
  156. package/dist/types/assistant.d.ts +56 -0
  157. package/dist/typescript-l6-4tT8s.js +13240 -0
  158. package/package.json +6 -3
  159. package/dist/RowPreviewLegacyComponent-CXsY4P-R.js +0 -439
  160. package/dist/RowPreviewLegacyComponent-yjHSkZLz.js +0 -439
  161. package/dist/RowPreviewRow-CBfAnQ6o.js +0 -107
  162. package/dist/RowPreviewRow-CeowK6Q_.js +0 -107
  163. package/dist/composables/emailBuilder/transform/pipeline/optimizeAI.d.ts +0 -125
  164. package/dist/element-CMhqxYnE.js +0 -67099
  165. package/dist/estree-B67dfAo1.js +0 -7989
  166. package/dist/html-DGrfikay.js +0 -7353
  167. package/dist/standalone-Bd2oQFm3.js +0 -3639
  168. package/dist/typescript-C_Ru9PRN.js +0 -23184
  169. package/dist/vue.runtime.esm-bundler-CfYyFhW6.js +0 -9097
package/README.md CHANGED
@@ -1,381 +1,397 @@
1
- # @maildeno/editor
2
-
3
- A drag-and-drop email template editor.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install @maildeno/editor
9
- ```
10
-
11
- One package, no peer dependencies, no CSS import. The editor injects its own
12
- styling when it mounts.
13
-
14
- ## Minimal usage Vue
15
-
16
- ```vue
17
- <script setup lang="ts">
18
- import { EmailEditor } from "@maildeno/editor";
19
- </script>
20
-
21
- <template>
22
- <EmailEditor />
23
- </template>
24
- ```
25
-
26
- ## Props and events
27
-
28
- | Prop | Type |
29
- | --- | --- |
30
- | `templateId` | `string` |
31
- | `storageAdapter` | `EditorStorageAdapter` |
32
- | `theme` | `{ primaryColor?, surfaceColor? }` |
33
- | `capabilities` | `{ export?: Array<"html"\|"mjml"\|"react"\|"json"> }` |
34
- | `onSendTestEmail` | `(payload) => Promise<void>` |
35
-
36
- | Event | Payload |
37
- | --- | --- |
38
- | `@save` | `{ templateId: string \| null }` |
39
-
40
- Reading content out uses a template ref:
41
-
42
- ```ts
43
- const editor = ref();
44
- editor.value.getHtml("prune");
45
- editor.value.getMjml();
46
- editor.value.getReactEmail();
47
- editor.value.getJson();
48
- ```
49
-
50
- ## Minimal usage React
51
-
52
- ```tsx
53
- import { useEffect, useRef } from "react";
54
- import { init, type EditorHandle } from "@maildeno/editor/init";
55
-
56
- export default function Editor() {
57
- const container = useRef<HTMLDivElement>(null);
58
- const handle = useRef<EditorHandle | null>(null);
59
-
60
- useEffect(() => {
61
- let cancelled = false;
62
-
63
- init({ container: container.current! }).then((h) => {
64
- // React 18 StrictMode mounts effects twice in development. Without
65
- // this guard the first instance is orphaned and never destroyed.
66
- if (cancelled) return h.destroy();
67
- handle.current = h;
68
- });
69
-
70
- return () => {
71
- cancelled = true;
72
- handle.current?.destroy();
73
- };
74
- }, []);
75
-
76
- return <div ref={container} />;
77
- }
78
- ```
79
-
80
- ## `EditorHandle`
81
-
82
- `init()` resolves to this once the editor has mounted:
83
-
84
- | Member | Description |
85
- | --- | --- |
86
- | `element` | The underlying `<maildeno-editor>` DOM node. |
87
- | `on(event, fn)` / `off(event, fn)` | Subscribe to editor events. Currently `"save"`. |
88
- | `setTheme(theme)` | Re-theme live, any time after mount. |
89
- | `getHtml(mode?)` | Current template as an HTML email string, or `null` if empty. |
90
- | `getMjml(mode?)` | Current template as MJML. |
91
- | `getReactEmail(mode?)` | Current template as React Email `.tsx` source. |
92
- | `getJson()` | Current template as a plain object. |
93
- | `destroy()` | Unmount and clean up. Always call this on unmount. |
94
-
95
-
96
- ### Getting content out
97
-
98
- Four getters, available on the handle (`init()`) or a template ref (Vue component):
99
-
100
- ```ts
101
- getHtml(mode?) // production-ready HTML email
102
- getMjml(mode?) // MJML source
103
- getReactEmail(mode?) // React Email .tsx source
104
- getJson() // the template as a plain object
105
- ```
106
-
107
- `mode` is `"prune"` (default) or `"wrap"`, and only matters if you use ESP conditional visibility:
108
-
109
- - **`"prune"`** evaluates conditions against the current preview context and outputs only the branches that match. Use it for a concrete send.
110
- - **`"wrap"`** keeps every branch, wrapped in your ESP's conditional syntax. Use it when handing the HTML to an ESP that will do the evaluation itself.
111
-
112
- They all return `null` when the canvas is empty, so check before using:
113
-
114
- ```ts
115
- const html = handle.getHtml();
116
- if (!html) return; // nothing built yet
117
- ```
118
-
119
- `getJson()` returns the portable template format — `template_id`, `template_name`, `canvas`, `rows`, `schema_version`. Store it and pass it back via your adapter's `loadTemplate` to restore exactly.
120
-
121
- ## Feature reference
122
-
123
- Everything below is identical across frameworks. Only the mounting differs.
124
-
125
- ### The editor at a glance
126
-
127
- - **Drag-and-drop block editor** — paragraph, heading, image, video, list, button, anchor, divider, spacer, menu, socials, plus custom blocks you register.
128
- - **Four export formats** — HTML, MJML, React Email (`.tsx`), JSON.
129
- - **ESP-aware conditional logic** — visibility rules compile to the right syntax for Klaviyo, Mailchimp, Braze, SFMC, HubSpot, Iterable, Handlebars and more.
130
- - **Merge tags** with an in-editor picker.
131
- - **Saved templates and saved rows** — reusable snippets and full documents.
132
- - **Desktop/mobile styling** per-block mobile overrides.
133
- - **Undo/redo**, autosave draft recovery, and a preview with client-specific rendering checks.
134
- - **Zero backend required** — defaults to `localStorage`; bring an adapter to use your own.
135
-
136
-
137
- ### Storage adapter
138
-
139
- The editor never talks to your backend directly. Implement this and it uses your storage for everything:
140
-
141
- ```ts
142
- import type { EditorStorageAdapter } from "@maildeno/editor";
143
-
144
- const adapter: EditorStorageAdapter = {
145
- // ── Templates ──────────────────────────────────────────────
146
- async loadTemplate(templateId) {
147
- if (!templateId) return null; // null = start blank
148
- const res = await fetch(`/api/templates/${templateId}`);
149
- if (!res.ok) return null;
150
- const t = await res.json();
151
- return { rows: t.rows, canvasStyles: t.canvasStyles, name: t.name };
152
- },
153
- async saveTemplate(snapshot, templateId) {
154
- const res = await fetch(`/api/templates/${templateId ?? ""}`, {
155
- method: templateId ? "PUT" : "POST",
156
- body: JSON.stringify(snapshot),
157
- });
158
- return { templateId: (await res.json()).id }; // editor stamps this for later saves
159
- },
160
-
161
- // ── Optional: powers the "Saved templates" panel ───────────
162
- // Return summaries, not full documents — listing shouldn't fetch every
163
- // template's rows. Omit both and the panel says listing isn't supported.
164
- async listTemplates() {
165
- return fetch("/api/templates").then((r) => r.json());
166
- // -> [{ templateId, name, updatedAt }]
167
- },
168
- async deleteTemplate(id) {
169
- await fetch(`/api/templates/${id}`, { method: "DELETE" });
170
- },
171
-
172
- // ── Saved rows (reusable snippets) ─────────────────────────
173
- async listSavedRows() {
174
- return fetch("/api/saved-rows").then((r) => r.json());
175
- },
176
- async saveSavedRow(row, name) {
177
- return fetch("/api/saved-rows", {
178
- method: "POST", body: JSON.stringify({ row, name }),
179
- }).then((r) => r.json());
180
- },
181
- async deleteSavedRow(id) {
182
- await fetch(`/api/saved-rows/${id}`, { method: "DELETE" });
183
- },
184
- async renameSavedRow(id, name) {
185
- await fetch(`/api/saved-rows/${id}`, {
186
- method: "PATCH", body: JSON.stringify({ name }),
187
- });
188
- },
189
- // Synchronous — it runs during a drag, so it can't await. Read from
190
- // whatever you already have client-side (e.g. your last listSavedRows result).
191
- cloneSavedRowForCanvas(id) {
192
- return structuredClone(rowCache.get(id) ?? null);
193
- },
194
-
195
- // ── Images ─────────────────────────────────────────────────
196
- // Called when a user drops or picks an image. Return a public URL.
197
- async uploadImage(file) {
198
- const form = new FormData();
199
- form.append("file", file);
200
- const { url } = await fetch("/api/upload", { method: "POST", body: form })
201
- .then((r) => r.json());
202
- return url;
203
- },
204
- };
205
- ```
206
-
207
- Without an adapter, everything persists to `localStorage` — fine for demos, but images are stored as base64 data URIs, which will hit the ~5 MB quota quickly on image-heavy templates.
208
-
209
- ### Partial adapters
210
-
211
- Every method is optional. Anything you leave out falls back to the built-in
212
- localStorage adapter, so you can override only the parts you need:
213
-
214
- ```ts
215
- // Upload images to your own storage; keep everything else local.
216
- init({
217
- storageAdapter: {
218
- async uploadImage(file) {
219
- const form = new FormData();
220
- form.append("file", file);
221
- const { url } = await fetch("/api/upload", { method: "POST", body: form })
222
- .then((r) => r.json());
223
- return url;
224
- },
225
- },
226
- });
227
- ```
228
-
229
- The fallback is per-method, not per-area. If you implement `saveTemplate`
230
- against your own backend but leave `listTemplates` out, the saved-templates
231
- panel will list localStorage templates rather than yours the editor warns
232
- about that specific mismatch in development. Implement `listTemplates` and
233
- `deleteTemplate` alongside `loadTemplate`/`saveTemplate` to keep them
234
- consistent.
235
-
236
- ### Sending email
237
-
238
- The editor hands you `{ to, subject, html }` and stops there. Your ESP key must never reach the browser, so the send happens on your server:
239
-
240
- ```ts
241
- // client
242
- onSendTestEmail: async ({ to, subject, html }) => {
243
- await fetch("/api/send-test", {
244
- method: "POST",
245
- body: JSON.stringify({ to, subject, html }),
246
- });
247
- }
248
- ```
249
-
250
- ```ts
251
- // server — Resend shown; Postmark/SendGrid are the same shape
252
- import { Resend } from "resend";
253
- const resend = new Resend(process.env.RESEND_API_KEY);
254
-
255
- export async function POST(req) {
256
- const { to, subject, html } = await req.json();
257
- await resend.emails.send({ from: "you@yourdomain.com", to, subject, html });
258
- }
259
- ```
260
-
261
- This is the **test-send** button only — one recipient, manual click. For a real campaign, pull the HTML yourself (`getHtml()`) and drive your own send to a list.
262
-
263
- ### Theming
264
-
265
- One hex re-themes the whole editor coherently:
266
-
267
- ```ts
268
- setTheme({ primary: "#6366f1" });
269
- ```
270
-
271
- Every surface reads from semantic tokens, so you can override just the parts
272
- you care about without redefining the rest:
273
-
274
- ```ts
275
- setTheme({
276
- // Core — everything else derives from these
277
- primary: "#e11d48",
278
- background: "#f8fafc",
279
- surface: "#ffffff",
280
- text: "#111827",
281
- border: "#e5e7eb",
282
-
283
- // Individual surfaces
284
- headerBg: "#111827",
285
- headerText: "#f9fafb",
286
- sidebarBg: "#ffffff",
287
- canvasBg: "#f1f5f9",
288
- inputBg: "#ffffff",
289
- inputText: "#111827",
290
- overlayBg: "#ffffff", // dialogs, toasts, dropdowns, date picker
291
- toolbarBg: "#ffffff", // floating + rich-text toolbars
292
-
293
- // The Save / Update button
294
- buttonPrimaryBg: "#e11d48",
295
- buttonPrimaryText: "#ffffff",
296
- buttonPrimaryHoverBg: "#be123c",
297
-
298
- // Dark mode — has its own complete defaults, so override only what differs
299
- dark: {
300
- primary: "#fb7185",
301
- headerBg: "#0b0f19",
302
- buttonPrimaryText: "#1e1b4b",
303
- },
304
- });
305
- ```
306
-
307
- Dark mode activates when the editor element carries the `dark` class:
308
-
309
- ```ts
310
- handle.element.classList.toggle("dark");
311
- ```
312
-
313
- **Anything you leave out keeps its default**, so a partial theme is always
314
- coherent rather than half-applied. Two things worth knowing:
315
-
316
- - Set `onPrimary` (or `buttonPrimaryText`) when using a light brand colour, or
317
- the primary button's label will be low-contrast against it.
318
- - Severity tints for toasts and messages (`successBg`, `dangerFg`, …) have
319
- separate dark defaults, so they don't leave pale panels sitting on a dark
320
- surface.
321
-
322
- Multiple editors on one page theme independently.
323
-
324
-
325
- ### Extension points
326
-
327
- All three are additive — no need to fork or edit built-ins.
328
-
329
- ```ts
330
- import { registerBlock, registerESPSyntax, registerMergeTags } from "@maildeno/editor";
331
-
332
- // A custom block type
333
- registerBlock({
334
- name: "product-card",
335
- label: "Product Card",
336
- icon: "<svg …>",
337
- schema: { /* default props */ },
338
- renderCanvas: ProductCardCanvas, // Vue component shown in the editor
339
- renderSettings: ProductCardPanel, // Vue component for the right panel
340
- renderEmail: {
341
- html: (props, ctx) => `<table>…</table>`,
342
- mjml: (props, ctx) => `<mj-section>…</mj-section>`,
343
- reactEmail: (props, ctx) => `<Section>…</Section>`,
344
- },
345
- });
346
-
347
- // Conditional syntax for an ESP that isn't built in
348
- registerESPSyntax("my-esp", {
349
- wrapOpenTag: (expr) => `{% if ${expr} %}`,
350
- wrapCloseTag: () => `{% endif %}`,
351
- wrapMergeTag: (key, fallback) =>
352
- fallback ? `{{ ${key} | default: "${fallback}" }}` : `{{ ${key} }}`,
353
- });
354
-
355
- // Extra merge tags in the picker
356
- registerMergeTags([
357
- { key: "customer.first_name" },
358
- { key: "order.total" },
359
- ]);
360
- ```
361
-
362
- Call these **before** the editor mounts.
363
-
364
- ### Persisting which template is open
365
-
366
- The editor doesn't own that decision. Listen for `save` and store the id however you track it:
367
-
368
- ```ts
369
- handle.on("save", ({ templateId }) => {
370
- router.replace(`/editor/${templateId}`); // or your DB, or app state
371
- });
372
- ```
373
-
374
- Pass it back as `templateId` next time to reopen.
375
-
376
- ### Practical notes
377
-
378
- - **The container needs a real height.** The editor fills its parent; `height: 100vh` or a sized flex child both work.
379
- - **`transform`, `filter`, `perspective` or `will-change` on any ancestor** breaks `position: fixed` inside it — floating toolbars and pickers will land in the wrong place. Avoid them above the mount point.
380
- - **Desktop only.** The editor shows a notice on small screens rather than attempting a mobile drag-and-drop UI.
381
- - **Autosave** keeps a local draft, so a refresh mid-edit recovers. "New template" clears it deliberately.
1
+ # @maildeno/editor
2
+
3
+ A drag-and-drop email template editor.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @maildeno/editor
9
+ ```
10
+
11
+ One package, no peer dependencies, no CSS import. The editor injects its own
12
+ styling when it mounts.
13
+
14
+ ## Minimal usage Vue
15
+
16
+ ```vue
17
+ <script setup lang="ts">
18
+ import { EmailEditor } from "@maildeno/editor";
19
+ </script>
20
+
21
+ <template>
22
+ <EmailEditor />
23
+ </template>
24
+ ```
25
+
26
+ ## Props and events
27
+
28
+ | Prop | Type |
29
+ | --- | --- |
30
+ | `templateId` | `string` |
31
+ | `storageAdapter` | `EditorStorageAdapter` |
32
+ | `theme` | `{ primaryColor?, surfaceColor? }` |
33
+ | `capabilities` | `{ export?: Array<"html"\|"mjml"\|"react"\|"json"> }` |
34
+ | `onSendTestEmail` | `(payload) => Promise<void>` |
35
+ | `brandName` | `string` |
36
+ | `versions` | `boolean` |
37
+ | `assistant` | `AssistantMount` |
38
+
39
+ | Event | Payload |
40
+ | --- | --- |
41
+ | `@save` | `{ templateId: string \| null }` |
42
+
43
+ Reading content out uses a template ref:
44
+
45
+ ```ts
46
+ const editor = ref();
47
+ editor.value.getHtml("prune");
48
+ editor.value.getMjml();
49
+ editor.value.getReactEmail();
50
+ editor.value.getJson();
51
+ ```
52
+
53
+ ## Minimal usage React
54
+
55
+ ```tsx
56
+ import { useEffect, useRef } from "react";
57
+ import { init, type EditorHandle } from "@maildeno/editor/init";
58
+
59
+ export default function Editor() {
60
+ const container = useRef<HTMLDivElement>(null);
61
+ const handle = useRef<EditorHandle | null>(null);
62
+
63
+ useEffect(() => {
64
+ let cancelled = false;
65
+
66
+ init({ container: container.current! }).then((h) => {
67
+ // React 18 StrictMode mounts effects twice in development. Without
68
+ // this guard the first instance is orphaned and never destroyed.
69
+ if (cancelled) return h.destroy();
70
+ handle.current = h;
71
+ });
72
+
73
+ return () => {
74
+ cancelled = true;
75
+ handle.current?.destroy();
76
+ };
77
+ }, []);
78
+
79
+ return <div ref={container} />;
80
+ }
81
+ ```
82
+
83
+ ## `EditorHandle`
84
+
85
+ `init()` resolves to this once the editor has mounted:
86
+
87
+ | Member | Description |
88
+ | --- | --- |
89
+ | `element` | The underlying `<maildeno-editor>` DOM node. |
90
+ | `on(event, fn)` / `off(event, fn)` | Subscribe to editor events. Currently `"save"`. |
91
+ | `setTheme(theme)` | Re-theme live, any time after mount. |
92
+ | `getHtml(mode?)` | Current template as an HTML email string, or `null` if empty. |
93
+ | `getMjml(mode?)` | Current template as MJML. |
94
+ | `getReactEmail(mode?)` | Current template as React Email `.tsx` source. |
95
+ | `getJson()` | Current template as a plain object. |
96
+ | `setJson(data, opts?)` | Replace the canvas. Accepts what `getJson()` returns, so `setJson(getJson())` round-trips. `opts.history` is `"undoable"` (default) or `"reset"`. |
97
+ | `getSelection()` | `{ id, type }` for the selected block, or `null`. `type` is the block type (`"paragraph"`, `"image"`…). |
98
+ | `setSelection(id)` | Select by id, or clear with `null`. Returns `false` if no block has that id. |
99
+ | `onChange(cb)` | Runs `cb` after each committed change. Returns an unsubscribe function. |
100
+ | `destroy()` | Unmount and clean up. Always call this on unmount. |
101
+
102
+
103
+ ### Getting content out
104
+
105
+ Four getters, available on the handle (`init()`) or a template ref (Vue component):
106
+
107
+ ```ts
108
+ getHtml(mode?) // production-ready HTML email
109
+ getMjml(mode?) // MJML source
110
+ getReactEmail(mode?) // React Email .tsx source
111
+ getJson() // the template as a plain object
112
+ ```
113
+
114
+ `mode` is `"prune"` (default) or `"wrap"`, and only matters if you use ESP conditional visibility:
115
+
116
+ - **`"prune"`** evaluates conditions against the current preview context and outputs only the branches that match. Use it for a concrete send.
117
+ - **`"wrap"`** keeps every branch, wrapped in your ESP's conditional syntax. Use it when handing the HTML to an ESP that will do the evaluation itself.
118
+
119
+ They all return `null` when the canvas is empty, so check before using:
120
+
121
+ ```ts
122
+ const html = handle.getHtml();
123
+ if (!html) return; // nothing built yet
124
+ ```
125
+
126
+ `getJson()` returns the portable template format — `template_id`, `template_name`, `canvas`, `rows`, `schema_version`. Store it and pass it back via your adapter's `loadTemplate` to restore exactly.
127
+
128
+ ## Feature reference
129
+
130
+ Everything below is identical across frameworks. Only the mounting differs.
131
+
132
+ ### The editor at a glance
133
+
134
+ - **Drag-and-drop block editor** — paragraph, heading, image, video, list, button, anchor, divider, spacer, menu, socials, plus custom blocks you register.
135
+ - **Four export formats** — HTML, MJML, React Email (`.tsx`), JSON.
136
+ - **ESP-aware conditional logic** — visibility rules compile to the right syntax for Klaviyo, Mailchimp, Braze, SFMC, HubSpot, Iterable, Handlebars and more.
137
+ - **Merge tags** with an in-editor picker.
138
+ - **Saved templates and saved rows** — reusable snippets and full documents.
139
+ - **Desktop/mobile styling** per-block mobile overrides.
140
+ - **Undo/redo**, autosave draft recovery, and a preview with client-specific rendering checks.
141
+ - **Zero backend required** — defaults to `localStorage`; bring an adapter to use your own.
142
+
143
+
144
+ ### Storage adapter
145
+
146
+ The editor never talks to your backend directly. Implement this and it uses your storage for everything:
147
+
148
+ ```ts
149
+ import type { EditorStorageAdapter } from "@maildeno/editor";
150
+
151
+ const adapter: EditorStorageAdapter = {
152
+ // ── Templates ──────────────────────────────────────────────
153
+ async loadTemplate(templateId) {
154
+ if (!templateId) return null; // null = start blank
155
+ const res = await fetch(`/api/templates/${templateId}`);
156
+ if (!res.ok) return null;
157
+ const t = await res.json();
158
+ return { rows: t.rows, canvasStyles: t.canvasStyles, name: t.name };
159
+ },
160
+ async saveTemplate(snapshot, templateId) {
161
+ const res = await fetch(`/api/templates/${templateId ?? ""}`, {
162
+ method: templateId ? "PUT" : "POST",
163
+ body: JSON.stringify(snapshot),
164
+ });
165
+ return { templateId: (await res.json()).id }; // editor stamps this for later saves
166
+ },
167
+
168
+ // ── Optional: powers the "Saved templates" panel ───────────
169
+ // Return summaries, not full documents — listing shouldn't fetch every
170
+ // template's rows. Omit both and the panel says listing isn't supported.
171
+ async listTemplates() {
172
+ return fetch("/api/templates").then((r) => r.json());
173
+ // -> [{ templateId, name, updatedAt }]
174
+ },
175
+ async deleteTemplate(id) {
176
+ await fetch(`/api/templates/${id}`, { method: "DELETE" });
177
+ },
178
+
179
+ // ── Saved rows (reusable snippets) ─────────────────────────
180
+ // Optional second, read-only row library — an org's shared blocks.
181
+ // Shown in a "Shared" tab beside the user's own rows, and only when
182
+ // this returns something, so omitting it changes nothing. There is no
183
+ // save/rename/delete counterpart: curating a shared library is an admin
184
+ // concern the editor has no user model to express.
185
+ async listSystemSavedRows() {
186
+ return api.get("/org/saved-rows");
187
+ },
188
+
189
+ async listSavedRows() {
190
+ return fetch("/api/saved-rows").then((r) => r.json());
191
+ },
192
+ async saveSavedRow(row, name) {
193
+ return fetch("/api/saved-rows", {
194
+ method: "POST", body: JSON.stringify({ row, name }),
195
+ }).then((r) => r.json());
196
+ },
197
+ async deleteSavedRow(id) {
198
+ await fetch(`/api/saved-rows/${id}`, { method: "DELETE" });
199
+ },
200
+ async renameSavedRow(id, name) {
201
+ await fetch(`/api/saved-rows/${id}`, {
202
+ method: "PATCH", body: JSON.stringify({ name }),
203
+ });
204
+ },
205
+ // Synchronous — it runs during a drag, so it can't await. Read from
206
+ // whatever you already have client-side (e.g. your last listSavedRows result).
207
+ cloneSavedRowForCanvas(id) {
208
+ return structuredClone(rowCache.get(id) ?? null);
209
+ },
210
+
211
+ // ── Images ─────────────────────────────────────────────────
212
+ // Called when a user drops or picks an image. Return a public URL.
213
+ async uploadImage(file) {
214
+ const form = new FormData();
215
+ form.append("file", file);
216
+ const { url } = await fetch("/api/upload", { method: "POST", body: form })
217
+ .then((r) => r.json());
218
+ return url;
219
+ },
220
+ };
221
+ ```
222
+
223
+ Without an adapter, everything persists to `localStorage` — fine for demos, but images are stored as base64 data URIs, which will hit the ~5 MB quota quickly on image-heavy templates.
224
+
225
+ ### Partial adapters
226
+
227
+ Every method is optional. Anything you leave out falls back to the built-in
228
+ localStorage adapter, so you can override only the parts you need:
229
+
230
+ ```ts
231
+ // Upload images to your own storage; keep everything else local.
232
+ init({
233
+ storageAdapter: {
234
+ async uploadImage(file) {
235
+ const form = new FormData();
236
+ form.append("file", file);
237
+ const { url } = await fetch("/api/upload", { method: "POST", body: form })
238
+ .then((r) => r.json());
239
+ return url;
240
+ },
241
+ },
242
+ });
243
+ ```
244
+
245
+ The fallback is per-method, not per-area. If you implement `saveTemplate`
246
+ against your own backend but leave `listTemplates` out, the saved-templates
247
+ panel will list localStorage templates rather than yours — the editor warns
248
+ about that specific mismatch in development. Implement `listTemplates` and
249
+ `deleteTemplate` alongside `loadTemplate`/`saveTemplate` to keep them
250
+ consistent.
251
+
252
+ ### Sending email
253
+
254
+ The editor hands you `{ to, subject, html }` and stops there. Your ESP key must never reach the browser, so the send happens on your server:
255
+
256
+ ```ts
257
+ // client
258
+ onSendTestEmail: async ({ to, subject, html }) => {
259
+ await fetch("/api/send-test", {
260
+ method: "POST",
261
+ body: JSON.stringify({ to, subject, html }),
262
+ });
263
+ }
264
+ ```
265
+
266
+ ```ts
267
+ // server — Resend shown; Postmark/SendGrid are the same shape
268
+ import { Resend } from "resend";
269
+ const resend = new Resend(process.env.RESEND_API_KEY);
270
+
271
+ export async function POST(req) {
272
+ const { to, subject, html } = await req.json();
273
+ await resend.emails.send({ from: "you@yourdomain.com", to, subject, html });
274
+ }
275
+ ```
276
+
277
+ This is the **test-send** button only — one recipient, manual click. For a real campaign, pull the HTML yourself (`getHtml()`) and drive your own send to a list.
278
+
279
+ ### Theming
280
+
281
+ One hex re-themes the whole editor coherently:
282
+
283
+ ```ts
284
+ setTheme({ primary: "#6366f1" });
285
+ ```
286
+
287
+ Every surface reads from semantic tokens, so you can override just the parts
288
+ you care about without redefining the rest:
289
+
290
+ ```ts
291
+ setTheme({
292
+ // Core — everything else derives from these
293
+ primary: "#e11d48",
294
+ background: "#f8fafc",
295
+ surface: "#ffffff",
296
+ text: "#111827",
297
+ border: "#e5e7eb",
298
+
299
+ // Individual surfaces
300
+ headerBg: "#111827",
301
+ headerText: "#f9fafb",
302
+ sidebarBg: "#ffffff",
303
+ canvasBg: "#f1f5f9",
304
+ inputBg: "#ffffff",
305
+ inputText: "#111827",
306
+ overlayBg: "#ffffff", // dialogs, toasts, dropdowns, date picker
307
+ toolbarBg: "#ffffff", // floating + rich-text toolbars
308
+
309
+ // The Save / Update button
310
+ buttonPrimaryBg: "#e11d48",
311
+ buttonPrimaryText: "#ffffff",
312
+ buttonPrimaryHoverBg: "#be123c",
313
+
314
+ // Dark mode has its own complete defaults, so override only what differs
315
+ dark: {
316
+ primary: "#fb7185",
317
+ headerBg: "#0b0f19",
318
+ buttonPrimaryText: "#1e1b4b",
319
+ },
320
+ });
321
+ ```
322
+
323
+ Dark mode activates when the editor element carries the `dark` class:
324
+
325
+ ```ts
326
+ handle.element.classList.toggle("dark");
327
+ ```
328
+
329
+ **Anything you leave out keeps its default**, so a partial theme is always
330
+ coherent rather than half-applied. Two things worth knowing:
331
+
332
+ - Set `onPrimary` (or `buttonPrimaryText`) when using a light brand colour, or
333
+ the primary button's label will be low-contrast against it.
334
+ - Severity tints for toasts and messages (`successBg`, `dangerFg`, …) have
335
+ separate dark defaults, so they don't leave pale panels sitting on a dark
336
+ surface.
337
+
338
+ Multiple editors on one page theme independently.
339
+
340
+
341
+ ### Extension points
342
+
343
+ All three are additive — no need to fork or edit built-ins.
344
+
345
+ ```ts
346
+ import { registerBlock, registerESPSyntax, registerMergeTags } from "@maildeno/editor";
347
+
348
+ // A custom block type
349
+ registerBlock({
350
+ name: "product-card",
351
+ label: "Product Card",
352
+ icon: "<svg …>",
353
+ schema: { /* default props */ },
354
+ renderCanvas: ProductCardCanvas, // Vue component shown in the editor
355
+ renderSettings: ProductCardPanel, // Vue component for the right panel
356
+ renderEmail: {
357
+ html: (props, ctx) => `<table>…</table>`,
358
+ mjml: (props, ctx) => `<mj-section>…</mj-section>`,
359
+ reactEmail: (props, ctx) => `<Section>…</Section>`,
360
+ },
361
+ });
362
+
363
+ // Conditional syntax for an ESP that isn't built in
364
+ registerESPSyntax("my-esp", {
365
+ wrapOpenTag: (expr) => `{% if ${expr} %}`,
366
+ wrapCloseTag: () => `{% endif %}`,
367
+ wrapMergeTag: (key, fallback) =>
368
+ fallback ? `{{ ${key} | default: "${fallback}" }}` : `{{ ${key} }}`,
369
+ });
370
+
371
+ // Extra merge tags in the picker
372
+ registerMergeTags([
373
+ { key: "customer.first_name" },
374
+ { key: "order.total" },
375
+ ]);
376
+ ```
377
+
378
+ Call these **before** the editor mounts.
379
+
380
+ ### Persisting which template is open
381
+
382
+ The editor doesn't own that decision. Listen for `save` and store the id however you track it:
383
+
384
+ ```ts
385
+ handle.on("save", ({ templateId }) => {
386
+ router.replace(`/editor/${templateId}`); // or your DB, or app state
387
+ });
388
+ ```
389
+
390
+ Pass it back as `templateId` next time to reopen.
391
+
392
+ ### Practical notes
393
+
394
+ - **The container needs a real height.** The editor fills its parent; `height: 100vh` or a sized flex child both work.
395
+ - **`transform`, `filter`, `perspective` or `will-change` on any ancestor** breaks `position: fixed` inside it — floating toolbars and pickers will land in the wrong place. Avoid them above the mount point.
396
+ - **Desktop only.** The editor shows a notice on small screens rather than attempting a mobile drag-and-drop UI.
397
+ - **Autosave** keeps a local draft, so a refresh mid-edit recovers. "New template" clears it deliberately.