@maildeno/editor 0.1.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.
- package/LICENSE +21 -0
- package/README.md +426 -0
- package/dist/RowPreviewLegacyComponent-CXsY4P-R.js +439 -0
- package/dist/RowPreviewLegacyComponent-osWbuByc.js +439 -0
- package/dist/RowPreviewRow-D-U1mV4v.js +107 -0
- package/dist/RowPreviewRow-MSc_unf3.js +107 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/localStorageAdapter.d.ts +6 -0
- package/dist/adapters/types.d.ts +83 -0
- package/dist/baseStyles.d.ts +13 -0
- package/dist/blocks/canvasStyleHelpers.d.ts +17 -0
- package/dist/blocks/definitions/anchor.d.ts +2 -0
- package/dist/blocks/definitions/button.d.ts +2 -0
- package/dist/blocks/definitions/divider.d.ts +2 -0
- package/dist/blocks/definitions/heading.d.ts +2 -0
- package/dist/blocks/definitions/image.d.ts +2 -0
- package/dist/blocks/definitions/list.d.ts +2 -0
- package/dist/blocks/definitions/menu.d.ts +2 -0
- package/dist/blocks/definitions/paragraph.d.ts +2 -0
- package/dist/blocks/definitions/socials.d.ts +2 -0
- package/dist/blocks/definitions/spacer.d.ts +2 -0
- package/dist/blocks/definitions/video.d.ts +2 -0
- package/dist/blocks/index.d.ts +8 -0
- package/dist/blocks/registry.d.ts +23 -0
- package/dist/blocks/types.d.ts +73 -0
- package/dist/composables/emailBuilder/components/useComponentStyleEditor.d.ts +72 -0
- package/dist/composables/emailBuilder/components/useProductRowActions.d.ts +3 -0
- package/dist/composables/emailBuilder/components/useProductRows.d.ts +59 -0
- package/dist/composables/emailBuilder/core/config/componentConfig.d.ts +29 -0
- package/dist/composables/emailBuilder/core/link-tags/useLinkTagInsert.d.ts +13 -0
- package/dist/composables/emailBuilder/core/merge-tags/mergeTagDefinitions.d.ts +64 -0
- package/dist/composables/emailBuilder/core/merge-tags/resolveMergeTags.d.ts +27 -0
- package/dist/composables/emailBuilder/core/ui/useLayerHoverScroll.d.ts +20 -0
- package/dist/composables/emailBuilder/core/ui/useLayoutDrag.d.ts +85 -0
- package/dist/composables/emailBuilder/core/ui/useRichTextEditors.d.ts +6 -0
- package/dist/composables/emailBuilder/core/ui/visibilityBadgeHelpers.d.ts +22 -0
- package/dist/composables/emailBuilder/core/useEmailBuilder.d.ts +274 -0
- package/dist/composables/emailBuilder/core/useEmailBuilderDefault.d.ts +507 -0
- package/dist/composables/emailBuilder/core/useEmailBuilderOperations.d.ts +31 -0
- package/dist/composables/emailBuilder/core/useEmailBuilderVisibility.d.ts +31 -0
- package/dist/composables/emailBuilder/export/actions/download.d.ts +24 -0
- package/dist/composables/emailBuilder/export/generators/html.d.ts +3 -0
- package/dist/composables/emailBuilder/export/generators/mjml.d.ts +6 -0
- package/dist/composables/emailBuilder/export/generators/react-email.d.ts +61 -0
- package/dist/composables/emailBuilder/export/helpers/generatorHelpers.d.ts +53 -0
- package/dist/composables/emailBuilder/export/logic/espLogicWrapper.d.ts +76 -0
- package/dist/composables/emailBuilder/export/logic/reactLogicWrapper.d.ts +31 -0
- package/dist/composables/emailBuilder/export/merge-tags/mergeTagMapper.d.ts +42 -0
- package/dist/composables/emailBuilder/export/merge-tags/reactMergeTagMapper.d.ts +26 -0
- package/dist/composables/emailBuilder/export/shared/containers.d.ts +18 -0
- package/dist/composables/emailBuilder/export/shared/styles.d.ts +12 -0
- package/dist/composables/emailBuilder/export/shared/tagIdentifier.d.ts +1 -0
- package/dist/composables/emailBuilder/export/targets/htmlExport.d.ts +20 -0
- package/dist/composables/emailBuilder/export/targets/jsonExport.d.ts +28 -0
- package/dist/composables/emailBuilder/export/targets/mjmlExport.d.ts +19 -0
- package/dist/composables/emailBuilder/export/targets/reactEmailExport.d.ts +20 -0
- package/dist/composables/emailBuilder/export/transformers/espWrapper.d.ts +2 -0
- package/dist/composables/emailBuilder/export/transformers/formatting.d.ts +3 -0
- package/dist/composables/emailBuilder/export/transformers/minify.d.ts +33 -0
- package/dist/composables/emailBuilder/export/transformers/tagMapper.d.ts +29 -0
- package/dist/composables/emailBuilder/export/types/export.d.ts +24 -0
- package/dist/composables/emailBuilder/export/useEmailExportEngine.d.ts +63 -0
- package/dist/composables/emailBuilder/export/useEmailExportMobileStyles.d.ts +3 -0
- package/dist/composables/emailBuilder/export/useExportSettings.d.ts +5 -0
- package/dist/composables/emailBuilder/health/accessibilityChecker.d.ts +64 -0
- package/dist/composables/emailBuilder/health/healthIndicator.d.ts +19 -0
- package/dist/composables/emailBuilder/history/useEmailBuilderHistory.d.ts +26 -0
- package/dist/composables/emailBuilder/history/useHistory.d.ts +16 -0
- package/dist/composables/emailBuilder/persistence/useEmailBuilderPersistence.d.ts +38 -0
- package/dist/composables/emailBuilder/preview/useClientPreview.d.ts +127 -0
- package/dist/composables/emailBuilder/transform/pipeline/hydrate.d.ts +54 -0
- package/dist/composables/emailBuilder/transform/pipeline/optimize.d.ts +101 -0
- package/dist/composables/emailBuilder/transform/pipeline/optimizeAI.d.ts +125 -0
- package/dist/composables/emailBuilder/types/emailBuilder.d.ts +79 -0
- package/dist/composables/system/useColor.d.ts +26 -0
- package/dist/composables/system/useDeviceDetection.d.ts +5 -0
- package/dist/composables/system/useGoogleFonts.d.ts +11 -0
- package/dist/composables/system/useImageUpload.d.ts +23 -0
- package/dist/composables/system/useSavedRowsPanel.d.ts +35 -0
- package/dist/composables/ui/useConfirm.d.ts +33 -0
- package/dist/composables/ui/useInfoDialog.d.ts +22 -0
- package/dist/composables/ui/useTeleportTarget.d.ts +49 -0
- package/dist/composables/ui/useToast.d.ts +32 -0
- package/dist/devStyleMirror.d.ts +20 -0
- package/dist/documentScopedStyles.d.ts +39 -0
- package/dist/editor.css +2411 -0
- package/dist/element-DN22fZmQ.js +72000 -0
- package/dist/element-scoped-styles.css +2411 -0
- package/dist/element.d.ts +6 -0
- package/dist/element.js +2 -0
- package/dist/esp/registry.d.ts +33 -0
- package/dist/estree-C12ASyI-.js +7993 -0
- package/dist/html-DGrfikay.js +7353 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +71955 -0
- package/dist/init.d.ts +85 -0
- package/dist/init.js +130 -0
- package/dist/lightDom.d.ts +30 -0
- package/dist/merge-tags/registry.d.ts +33 -0
- package/dist/shadowStyles.d.ts +8 -0
- package/dist/standalone-Bd2oQFm3.js +3639 -0
- package/dist/theme.d.ts +132 -0
- package/dist/typescript-D-z2dDu9.js +23190 -0
- package/dist/utils/generateId.d.ts +1 -0
- package/dist/utils/shadowDom.d.ts +30 -0
- package/dist/vue.runtime.esm-bundler-DwQEK7WO.js +9028 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 - present, Noruwa Obaseki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
# @maildeno/editor — Vue
|
|
2
|
+
|
|
3
|
+
A drag-and-drop email template editor for Vue 3 apps.
|
|
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
|
|
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
|
+
## Full example
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import { ref } from "vue";
|
|
31
|
+
import { EmailEditor } from "@maildeno/editor";
|
|
32
|
+
import { myAdapter } from "./adapter";
|
|
33
|
+
|
|
34
|
+
const editor = ref<InstanceType<typeof EmailEditor> | null>(null);
|
|
35
|
+
|
|
36
|
+
function handleSave({ templateId }: { templateId: string | null }) {
|
|
37
|
+
// Persist which template is open, however you track it
|
|
38
|
+
router.replace(`/editor/${templateId}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function handleSendTestEmail(payload: {
|
|
42
|
+
to: string; subject: string; html: string;
|
|
43
|
+
}) {
|
|
44
|
+
await fetch("/api/send-test", { method: "POST", body: JSON.stringify(payload) });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function publish() {
|
|
48
|
+
const html = editor.value?.getHtml();
|
|
49
|
+
if (!html) return; // empty canvas
|
|
50
|
+
await fetch("/api/campaigns", { method: "POST", body: JSON.stringify({ html }) });
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<div style="display: flex; flex-direction: column; height: 100vh">
|
|
56
|
+
<button @click="publish">Publish</button>
|
|
57
|
+
|
|
58
|
+
<EmailEditor
|
|
59
|
+
ref="editor"
|
|
60
|
+
style="flex: 1; min-height: 0"
|
|
61
|
+
template-id="welcome_email"
|
|
62
|
+
:storage-adapter="myAdapter"
|
|
63
|
+
:theme="{ primaryColor: '#6366f1' }"
|
|
64
|
+
:capabilities="{ export: ['html', 'json'] }"
|
|
65
|
+
:on-send-test-email="handleSendTestEmail"
|
|
66
|
+
@save="handleSave"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
</template>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Props and events
|
|
73
|
+
|
|
74
|
+
| Prop | Type |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `templateId` | `string` |
|
|
77
|
+
| `storageAdapter` | `EditorStorageAdapter` |
|
|
78
|
+
| `theme` | `{ primaryColor?, surfaceColor? }` |
|
|
79
|
+
| `capabilities` | `{ export?: Array<"html"\|"mjml"\|"react"\|"json"> }` |
|
|
80
|
+
| `onSendTestEmail` | `(payload) => Promise<void>` |
|
|
81
|
+
|
|
82
|
+
| Event | Payload |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `@save` | `{ templateId: string \| null }` |
|
|
85
|
+
|
|
86
|
+
Reading content out uses a template ref:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const editor = ref();
|
|
90
|
+
editor.value.getHtml("prune");
|
|
91
|
+
editor.value.getMjml();
|
|
92
|
+
editor.value.getReactEmail();
|
|
93
|
+
editor.value.getJson();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Theming is reactive through the `theme` prop — change it and the editor
|
|
97
|
+
re-themes live; no imperative call needed.
|
|
98
|
+
|
|
99
|
+
## Alternative: `init()`
|
|
100
|
+
|
|
101
|
+
The same API the React and vanilla guides use also works in Vue:
|
|
102
|
+
|
|
103
|
+
```vue
|
|
104
|
+
<script setup lang="ts">
|
|
105
|
+
import { onMounted, onBeforeUnmount, ref } from "vue";
|
|
106
|
+
import { init, type EditorHandle } from "@maildeno/editor/init";
|
|
107
|
+
|
|
108
|
+
const container = ref<HTMLDivElement | null>(null);
|
|
109
|
+
let handle: EditorHandle | null = null;
|
|
110
|
+
|
|
111
|
+
onMounted(async () => {
|
|
112
|
+
handle = await init({ container: container.value! });
|
|
113
|
+
});
|
|
114
|
+
onBeforeUnmount(() => handle?.destroy());
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<template>
|
|
118
|
+
<div ref="container" />
|
|
119
|
+
</template>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Prefer the component unless you specifically need style isolation.** `init()`
|
|
123
|
+
bundles its own Vue so it can run on framework-free pages — calling it from a
|
|
124
|
+
Vue app ships two Vue runtimes (~60 kB gzipped plus a second reactivity graph).
|
|
125
|
+
The component uses the Vue you already have, and gives you reactive props,
|
|
126
|
+
template refs, normal event binding and devtools visibility.
|
|
127
|
+
|
|
128
|
+
The one case where `init()` wins: it renders in a shadow root, so your app's
|
|
129
|
+
global CSS can't reach the editor. If your stylesheets conflict with it, that
|
|
130
|
+
isolation is worth the duplicate runtime.
|
|
131
|
+
|
|
132
|
+
## Feature reference
|
|
133
|
+
|
|
134
|
+
Everything below is identical across frameworks. Only the mounting differs.
|
|
135
|
+
|
|
136
|
+
### The editor at a glance
|
|
137
|
+
|
|
138
|
+
- **Drag-and-drop block editor** — paragraph, heading, image, video, list, button, anchor, divider, spacer, menu, socials, plus custom blocks you register.
|
|
139
|
+
- **Four export formats** — HTML, MJML, React Email (`.tsx`), JSON.
|
|
140
|
+
- **ESP-aware conditional logic** — visibility rules compile to the right syntax for Klaviyo, Mailchimp, Braze, SFMC, HubSpot, Iterable, Handlebars and more.
|
|
141
|
+
- **Merge tags** with an in-editor picker.
|
|
142
|
+
- **Saved templates and saved rows** — reusable snippets and full documents.
|
|
143
|
+
- **Desktop/mobile styling** — per-block mobile overrides.
|
|
144
|
+
- **Undo/redo**, autosave draft recovery, and a preview with client-specific rendering checks.
|
|
145
|
+
- **Zero backend required** — defaults to `localStorage`; bring an adapter to use your own.
|
|
146
|
+
|
|
147
|
+
### Configuration
|
|
148
|
+
|
|
149
|
+
| Option | Type | Purpose |
|
|
150
|
+
| --- | --- | --- |
|
|
151
|
+
| `templateId` | `string` | Load an existing template on mount. Omit to start blank. |
|
|
152
|
+
| `storageAdapter` | `EditorStorageAdapter` | Where templates, rows and images persist. Omit for `localStorage`. |
|
|
153
|
+
| `theme` | `{ primaryColor?, surfaceColor? }` | Brand colour, expanded into a full 50–950 shade scale. |
|
|
154
|
+
| `capabilities` | `{ export?: Array<"html"\|"mjml"\|"react"\|"json"> }` | Restrict which export formats appear. Omit for all four. |
|
|
155
|
+
| `onSendTestEmail` | `(payload) => Promise<void>` | Enables the "Send test" button. Hidden entirely when omitted. |
|
|
156
|
+
|
|
157
|
+
### Getting content out
|
|
158
|
+
|
|
159
|
+
Four getters, available on the handle (`init()`) or a template ref (Vue component):
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
getHtml(mode?) // production-ready HTML email
|
|
163
|
+
getMjml(mode?) // MJML source
|
|
164
|
+
getReactEmail(mode?) // React Email .tsx source
|
|
165
|
+
getJson() // the template as a plain object
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`mode` is `"prune"` (default) or `"wrap"`, and only matters if you use ESP conditional visibility:
|
|
169
|
+
|
|
170
|
+
- **`"prune"`** evaluates conditions against the current preview context and outputs only the branches that match. Use it for a concrete send.
|
|
171
|
+
- **`"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.
|
|
172
|
+
|
|
173
|
+
They all return `null` when the canvas is empty, so check before using:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
const html = handle.getHtml();
|
|
177
|
+
if (!html) return; // nothing built yet
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`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.
|
|
181
|
+
|
|
182
|
+
### Storage adapter
|
|
183
|
+
|
|
184
|
+
The editor never talks to your backend directly. Implement this and it uses your storage for everything:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import type { EditorStorageAdapter } from "@maildeno/editor";
|
|
188
|
+
|
|
189
|
+
const adapter: EditorStorageAdapter = {
|
|
190
|
+
// ── Templates ──────────────────────────────────────────────
|
|
191
|
+
async loadTemplate(templateId) {
|
|
192
|
+
if (!templateId) return null; // null = start blank
|
|
193
|
+
const res = await fetch(`/api/templates/${templateId}`);
|
|
194
|
+
if (!res.ok) return null;
|
|
195
|
+
const t = await res.json();
|
|
196
|
+
return { rows: t.rows, canvasStyles: t.canvasStyles, name: t.name };
|
|
197
|
+
},
|
|
198
|
+
async saveTemplate(snapshot, templateId) {
|
|
199
|
+
const res = await fetch(`/api/templates/${templateId ?? ""}`, {
|
|
200
|
+
method: templateId ? "PUT" : "POST",
|
|
201
|
+
body: JSON.stringify(snapshot),
|
|
202
|
+
});
|
|
203
|
+
return { templateId: (await res.json()).id }; // editor stamps this for later saves
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
// ── Optional: powers the "Saved templates" panel ───────────
|
|
207
|
+
// Return summaries, not full documents — listing shouldn't fetch every
|
|
208
|
+
// template's rows. Omit both and the panel says listing isn't supported.
|
|
209
|
+
async listTemplates() {
|
|
210
|
+
return fetch("/api/templates").then((r) => r.json());
|
|
211
|
+
// -> [{ templateId, name, updatedAt }]
|
|
212
|
+
},
|
|
213
|
+
async deleteTemplate(id) {
|
|
214
|
+
await fetch(`/api/templates/${id}`, { method: "DELETE" });
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
// ── Saved rows (reusable snippets) ─────────────────────────
|
|
218
|
+
async listSavedRows() {
|
|
219
|
+
return fetch("/api/saved-rows").then((r) => r.json());
|
|
220
|
+
},
|
|
221
|
+
async saveSavedRow(row, name) {
|
|
222
|
+
return fetch("/api/saved-rows", {
|
|
223
|
+
method: "POST", body: JSON.stringify({ row, name }),
|
|
224
|
+
}).then((r) => r.json());
|
|
225
|
+
},
|
|
226
|
+
async deleteSavedRow(id) {
|
|
227
|
+
await fetch(`/api/saved-rows/${id}`, { method: "DELETE" });
|
|
228
|
+
},
|
|
229
|
+
async renameSavedRow(id, name) {
|
|
230
|
+
await fetch(`/api/saved-rows/${id}`, {
|
|
231
|
+
method: "PATCH", body: JSON.stringify({ name }),
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
// Synchronous — it runs during a drag, so it can't await. Read from
|
|
235
|
+
// whatever you already have client-side (e.g. your last listSavedRows result).
|
|
236
|
+
cloneSavedRowForCanvas(id) {
|
|
237
|
+
return structuredClone(rowCache.get(id) ?? null);
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
// ── Images ─────────────────────────────────────────────────
|
|
241
|
+
// Called when a user drops or picks an image. Return a public URL.
|
|
242
|
+
async uploadImage(file) {
|
|
243
|
+
const form = new FormData();
|
|
244
|
+
form.append("file", file);
|
|
245
|
+
const { url } = await fetch("/api/upload", { method: "POST", body: form })
|
|
246
|
+
.then((r) => r.json());
|
|
247
|
+
return url;
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
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.
|
|
253
|
+
|
|
254
|
+
### Partial adapters
|
|
255
|
+
|
|
256
|
+
Every method is optional. Anything you leave out falls back to the built-in
|
|
257
|
+
localStorage adapter, so you can override only the parts you need:
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
// Upload images to your own storage; keep everything else local.
|
|
261
|
+
init({
|
|
262
|
+
storageAdapter: {
|
|
263
|
+
async uploadImage(file) {
|
|
264
|
+
const form = new FormData();
|
|
265
|
+
form.append("file", file);
|
|
266
|
+
const { url } = await fetch("/api/upload", { method: "POST", body: form })
|
|
267
|
+
.then((r) => r.json());
|
|
268
|
+
return url;
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The fallback is per-method, not per-area. If you implement `saveTemplate`
|
|
275
|
+
against your own backend but leave `listTemplates` out, the saved-templates
|
|
276
|
+
panel will list localStorage templates rather than yours — the editor warns
|
|
277
|
+
about that specific mismatch in development. Implement `listTemplates` and
|
|
278
|
+
`deleteTemplate` alongside `loadTemplate`/`saveTemplate` to keep them
|
|
279
|
+
consistent.
|
|
280
|
+
|
|
281
|
+
### Sending email
|
|
282
|
+
|
|
283
|
+
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:
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
// client
|
|
287
|
+
onSendTestEmail: async ({ to, subject, html }) => {
|
|
288
|
+
await fetch("/api/send-test", {
|
|
289
|
+
method: "POST",
|
|
290
|
+
body: JSON.stringify({ to, subject, html }),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
// server — Resend shown; Postmark/SendGrid are the same shape
|
|
297
|
+
import { Resend } from "resend";
|
|
298
|
+
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
299
|
+
|
|
300
|
+
export async function POST(req) {
|
|
301
|
+
const { to, subject, html } = await req.json();
|
|
302
|
+
await resend.emails.send({ from: "you@yourdomain.com", to, subject, html });
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
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.
|
|
307
|
+
|
|
308
|
+
### Theming
|
|
309
|
+
|
|
310
|
+
One hex re-themes the whole editor coherently:
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
setTheme({ primary: "#6366f1" });
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Every surface reads from semantic tokens, so you can override just the parts
|
|
317
|
+
you care about without redefining the rest:
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
setTheme({
|
|
321
|
+
// Core — everything else derives from these
|
|
322
|
+
primary: "#e11d48",
|
|
323
|
+
background: "#f8fafc",
|
|
324
|
+
surface: "#ffffff",
|
|
325
|
+
text: "#111827",
|
|
326
|
+
border: "#e5e7eb",
|
|
327
|
+
|
|
328
|
+
// Individual surfaces
|
|
329
|
+
headerBg: "#111827",
|
|
330
|
+
headerText: "#f9fafb",
|
|
331
|
+
sidebarBg: "#ffffff",
|
|
332
|
+
canvasBg: "#f1f5f9",
|
|
333
|
+
inputBg: "#ffffff",
|
|
334
|
+
inputText: "#111827",
|
|
335
|
+
overlayBg: "#ffffff", // dialogs, toasts, dropdowns, date picker
|
|
336
|
+
toolbarBg: "#ffffff", // floating + rich-text toolbars
|
|
337
|
+
|
|
338
|
+
// The Save / Update button
|
|
339
|
+
buttonPrimaryBg: "#e11d48",
|
|
340
|
+
buttonPrimaryText: "#ffffff",
|
|
341
|
+
buttonPrimaryHoverBg: "#be123c",
|
|
342
|
+
|
|
343
|
+
// Dark mode — has its own complete defaults, so override only what differs
|
|
344
|
+
dark: {
|
|
345
|
+
primary: "#fb7185",
|
|
346
|
+
headerBg: "#0b0f19",
|
|
347
|
+
buttonPrimaryText: "#1e1b4b",
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Dark mode activates when the editor element carries the `dark` class:
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
handle.element.classList.toggle("dark");
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**Anything you leave out keeps its default**, so a partial theme is always
|
|
359
|
+
coherent rather than half-applied. Two things worth knowing:
|
|
360
|
+
|
|
361
|
+
- Set `onPrimary` (or `buttonPrimaryText`) when using a light brand colour, or
|
|
362
|
+
the primary button's label will be low-contrast against it.
|
|
363
|
+
- Severity tints for toasts and messages (`successBg`, `dangerFg`, …) have
|
|
364
|
+
separate dark defaults, so they don't leave pale panels sitting on a dark
|
|
365
|
+
surface.
|
|
366
|
+
|
|
367
|
+
Multiple editors on one page theme independently.
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
### Extension points
|
|
371
|
+
|
|
372
|
+
All three are additive — no need to fork or edit built-ins.
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
import { registerBlock, registerESPSyntax, registerMergeTags } from "@maildeno/editor";
|
|
376
|
+
|
|
377
|
+
// A custom block type
|
|
378
|
+
registerBlock({
|
|
379
|
+
name: "product-card",
|
|
380
|
+
label: "Product Card",
|
|
381
|
+
icon: "<svg …>",
|
|
382
|
+
schema: { /* default props */ },
|
|
383
|
+
renderCanvas: ProductCardCanvas, // Vue component shown in the editor
|
|
384
|
+
renderSettings: ProductCardPanel, // Vue component for the right panel
|
|
385
|
+
renderEmail: {
|
|
386
|
+
html: (props, ctx) => `<table>…</table>`,
|
|
387
|
+
mjml: (props, ctx) => `<mj-section>…</mj-section>`,
|
|
388
|
+
reactEmail: (props, ctx) => `<Section>…</Section>`,
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
// Conditional syntax for an ESP that isn't built in
|
|
393
|
+
registerESPSyntax("my-esp", {
|
|
394
|
+
wrapOpenTag: (expr) => `{% if ${expr} %}`,
|
|
395
|
+
wrapCloseTag: () => `{% endif %}`,
|
|
396
|
+
wrapMergeTag: (key, fallback) =>
|
|
397
|
+
fallback ? `{{ ${key} | default: "${fallback}" }}` : `{{ ${key} }}`,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// Extra merge tags in the picker
|
|
401
|
+
registerMergeTags([
|
|
402
|
+
{ key: "customer.first_name" },
|
|
403
|
+
{ key: "order.total" },
|
|
404
|
+
]);
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Call these **before** the editor mounts.
|
|
408
|
+
|
|
409
|
+
### Persisting which template is open
|
|
410
|
+
|
|
411
|
+
The editor doesn't own that decision. Listen for `save` and store the id however you track it:
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
handle.on("save", ({ templateId }) => {
|
|
415
|
+
router.replace(`/editor/${templateId}`); // or your DB, or app state
|
|
416
|
+
});
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Pass it back as `templateId` next time to reopen.
|
|
420
|
+
|
|
421
|
+
### Practical notes
|
|
422
|
+
|
|
423
|
+
- **The container needs a real height.** The editor fills its parent; `height: 100vh` or a sized flex child both work. A container with no height renders nothing visible.
|
|
424
|
+
- **`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.
|
|
425
|
+
- **Desktop only.** The editor shows a notice on small screens rather than attempting a mobile drag-and-drop UI.
|
|
426
|
+
- **Autosave** keeps a local draft, so a refresh mid-edit recovers. "New template" clears it deliberately.
|