@boxcc/maildeno-editor 0.0.0-stage → 0.4.13

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 (57) hide show
  1. package/CHANGELOG.md +479 -0
  2. package/README.md +441 -2
  3. package/dist/DatePicker-AdfGW0Tw.js +5347 -0
  4. package/dist/DatePicker-aNFlsoOb.js +5347 -0
  5. package/dist/Dialog-By0JLN8s.js +6294 -0
  6. package/dist/HealthIndicator-4Iw6N-g_.js +1216 -0
  7. package/dist/HealthIndicator-ZohgzF2_.js +1217 -0
  8. package/dist/PopperContent-N2nAEFeH.js +2538 -0
  9. package/dist/PopperContent-eLmz1Gjd.js +2578 -0
  10. package/dist/PreviewCanvas-DzpLghCo.js +534 -0
  11. package/dist/PreviewCanvas-QN4C68KA.js +534 -0
  12. package/dist/RichTextEditor-CmM4XRFC.js +12218 -0
  13. package/dist/RichTextEditor-Cz1-_ZtA.js +12217 -0
  14. package/dist/RowPreviewChildren-BYaMZID3.js +4 -0
  15. package/dist/RowPreviewChildren-_A9gPQCs.js +4 -0
  16. package/dist/RowPreviewLegacyComponent-Df_1HTly.js +403 -0
  17. package/dist/RowPreviewLegacyComponent-NECG3wpn.js +403 -0
  18. package/dist/RowPreviewRow-DPaSbxmB.js +81 -0
  19. package/dist/RowPreviewRow-Dx4ExtSN.js +81 -0
  20. package/dist/SavedRowsPanel-DqSHB6Jk.js +492 -0
  21. package/dist/SavedRowsPanel-DyXjSOEt.js +493 -0
  22. package/dist/_plugin-vue_export-helper-Dj7HTbfw.js +8 -0
  23. package/dist/adapters/errors.d.ts +59 -0
  24. package/dist/adapters/localStorageAdapter.d.ts +6 -0
  25. package/dist/adapters/types.d.ts +151 -0
  26. package/dist/babel-DV7WPQI0.js +10043 -0
  27. package/dist/blocks/registry.d.ts +23 -0
  28. package/dist/blocks/types.d.ts +73 -0
  29. package/dist/borderRadius-CkSa1lQ9.js +75 -0
  30. package/dist/components/features/emailBuilder/EmailEditor.vue.d.ts +182 -0
  31. package/dist/composables/emailBuilder/export/logic/espLogicWrapper.d.ts +76 -0
  32. package/dist/composables/emailBuilder/persistence/useEmailBuilderPersistence.d.ts +38 -0
  33. package/dist/composables/emailBuilder/transform/pipeline/optimize.d.ts +100 -0
  34. package/dist/composables/system/useColorScheme.d.ts +16 -0
  35. package/dist/element-B3gq8Xvd.js +21500 -0
  36. package/dist/element.d.ts +6 -0
  37. package/dist/element.js +5 -0
  38. package/dist/esp/registry.d.ts +33 -0
  39. package/dist/estree-DY9POgc0.js +8195 -0
  40. package/dist/html-wb0gSX1o.js +7273 -0
  41. package/dist/index.d.ts +17 -0
  42. package/dist/index.js +14992 -0
  43. package/dist/init.d.ts +178 -0
  44. package/dist/init.js +137 -0
  45. package/dist/maildeno-editor.css +2 -0
  46. package/dist/merge-tags/registry.d.ts +33 -0
  47. package/dist/mergeTagDefinitions-Cler19nv.js +27 -0
  48. package/dist/standalone-DHvJ30Td.js +3554 -0
  49. package/dist/theme.d.ts +206 -0
  50. package/dist/types/assistant.d.ts +56 -0
  51. package/dist/useEmailBuilder-B19p-2yp.js +4924 -0
  52. package/dist/useEmailBuilder-BR4wfai1.js +4924 -0
  53. package/dist/useToast-DD11IxqP.js +194 -0
  54. package/dist/utils/border.d.ts +15 -0
  55. package/dist/utils/borderRadius.d.ts +10 -0
  56. package/dist/vue.runtime.esm-bundler-D2AjRP90.js +6117 -0
  57. package/package.json +100 -4
package/README.md CHANGED
@@ -1,3 +1,442 @@
1
- # Temporary Holding Version
1
+ # @maildeno/editor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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 React
15
+
16
+ ```tsx
17
+ import { useEffect, useRef } from "react";
18
+ import { init, type EditorHandle } from "@maildeno/editor/init";
19
+
20
+ export default function Editor() {
21
+ const container = useRef<HTMLDivElement>(null);
22
+ const handle = useRef<EditorHandle | null>(null);
23
+
24
+ useEffect(() => {
25
+ let cancelled = false;
26
+
27
+ const setup = async () => {
28
+ try {
29
+ const editor = await init({
30
+ container: container.current!,
31
+ capabilities: {
32
+ export: ["html", "mjml", "json"],
33
+ },
34
+ onSave: ({ templateId }) => {
35
+ console.log("Saved", templateId);
36
+
37
+ const html = handle.current?.getHtml(); // handle.current?.getReactEmail() or handle.current?.getMjml()
38
+ console.log("HTML:", html);
39
+ },
40
+ });
41
+
42
+ if (cancelled) {
43
+ editor.destroy();
44
+ return;
45
+ }
46
+
47
+ handle.current = editor;
48
+ } catch (error) {
49
+ if (!cancelled) {
50
+ console.error("Failed to initialize Maildeno editor:", error);
51
+ }
52
+ }
53
+ };
54
+
55
+ setup();
56
+
57
+ return () => {
58
+ cancelled = true;
59
+ handle.current?.destroy();
60
+ handle.current = null;
61
+ };
62
+ }, []);
63
+
64
+ return <div ref={container} />;
65
+ }
66
+ ```
67
+
68
+ > This mounts **read-only** — no `onSave` means no Save button. See
69
+ > [Persisting which template is open](#persisting-which-template-is-open) to
70
+ > enable saving.
71
+
72
+ ## `EditorHandle`
73
+
74
+ `init()` resolves to this once the editor has mounted:
75
+
76
+ | Member | Description |
77
+ | --- | --- |
78
+ | `element` | The underlying `<maildeno-editor>` DOM node. |
79
+ | `on(event, fn)` / `off(event, fn)` | Subscribe to editor events. Currently `"save"`. Only fires if `onSave` was passed to `init()` at mount time — subscribing after the fact doesn't retroactively enable saving or reveal a button that was never rendered. |
80
+ | `setTheme(theme)` | Re-theme live, any time after mount. |
81
+ | `getHtml(mode?)` | Current template as an HTML email string, or `null` if empty. |
82
+ | `getMjml(mode?)` | Current template as MJML. |
83
+ | `getReactEmail(mode?)` | Current template as React Email `.tsx` source. |
84
+ | `getJson()` | Current template as a plain object. |
85
+ | `setJson(data, opts?)` | Replace the canvas. Accepts what `getJson()` returns, so `setJson(getJson())` round-trips. `opts.history` is `"undoable"` (default) or `"reset"`. |
86
+ | `getSelection()` | `{ id, type }` for the selected block, or `null`. `type` is the block type (`"paragraph"`, `"image"`…). |
87
+ | `setSelection(id)` | Select by id, or clear with `null`. Returns `false` if no block has that id. |
88
+ | `onChange(cb)` | Runs `cb` after each committed change. Returns an unsubscribe function. |
89
+ | `destroy()` | Unmount and clean up. Always call this on unmount. |
90
+
91
+
92
+ ### Getting content out
93
+
94
+ Four getters, available on the handle (`init()`) or a template ref (Vue component):
95
+
96
+ ```ts
97
+ getHtml(mode?) // production-ready HTML email
98
+ getMjml(mode?) // MJML source
99
+ getReactEmail(mode?) // React Email .tsx source
100
+ getJson() // the template as a plain object
101
+ ```
102
+
103
+ `mode` is `"prune"` (default) or `"wrap"`, and only matters if you use ESP conditional visibility:
104
+
105
+ - **`"prune"`** evaluates conditions against the current preview context and outputs only the branches that match. Use it for a concrete send.
106
+ - **`"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.
107
+
108
+ They all return `null` when the canvas is empty, so check before using:
109
+
110
+ ```ts
111
+ const html = handle.getHtml();
112
+ if (!html) return; // nothing built yet
113
+ ```
114
+
115
+ `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.
116
+
117
+ ## Minimal usage Vue
118
+
119
+ ```vue
120
+ <script setup lang="ts">
121
+ import { EmailEditor } from "@maildeno/editor";
122
+ </script>
123
+
124
+ <template>
125
+ <EmailEditor />
126
+ </template>
127
+ ```
128
+
129
+ ## Props and events
130
+
131
+ | Prop | Type |
132
+ | --- | --- |
133
+ | `templateId` | `string` |
134
+ | `storageAdapter` | `EditorStorageAdapter` |
135
+ | `theme` | `{ primaryColor?, surfaceColor? }` |
136
+ | `capabilities` | `{ export?: Array<"html"\|"mjml"\|"react"\|"json"> }` |
137
+ | `onSendTestEmail` | `(payload) => Promise<void>` |
138
+ | `brandName` | `string` |
139
+ | `versions` | `boolean` |
140
+ | `assistant` | `AssistantMount` |
141
+
142
+ | Event | Payload |
143
+ | --- | --- |
144
+ | `@save` | `{ templateId: string \| null }` |
145
+
146
+ > **`@save`'s presence controls whether the Save button renders at all.** Bind a
147
+ > listener — `@save="..."` on the Vue component, or `onSave` in `init()`'s config
148
+ > object — and the Save button, save-status indicator, and autosave timer all
149
+ > appear. Omit it and the editor mounts **read-only**, useful for previews or
150
+ > guest embeds. (Vue compiles `@save="fn"` down to an `onSave` prop internally,
151
+ > so this is the same mechanism on both paths, not two separate features.) See
152
+ > [Persisting which template is open](#persisting-which-template-is-open) below.
153
+
154
+ Reading content out uses a template ref:
155
+
156
+ ```ts
157
+ const editor = ref();
158
+ editor.value.getHtml("prune");
159
+ editor.value.getMjml();
160
+ editor.value.getReactEmail();
161
+ editor.value.getJson();
162
+ ```
163
+
164
+
165
+ ## Feature reference
166
+
167
+ Everything below is identical across frameworks. Only the mounting differs.
168
+
169
+ ### The editor at a glance
170
+
171
+ - **Drag-and-drop block editor** — paragraph, heading, image, video, list, button, anchor, divider, spacer, menu, socials, plus custom blocks you register.
172
+ - **Four export formats** — HTML, MJML, React Email (`.tsx`), JSON.
173
+ - **ESP-aware conditional logic** — visibility rules compile to the right syntax for Klaviyo, Mailchimp, Braze, SFMC, HubSpot, Iterable, Handlebars and more.
174
+ - **Merge tags** with an in-editor picker.
175
+ - **Saved templates and saved rows** — reusable snippets and full documents.
176
+ - **Desktop/mobile styling** — per-block mobile overrides.
177
+ - **Undo/redo**, autosave draft recovery, and a preview with client-specific rendering checks.
178
+ - **Zero backend required** — defaults to `localStorage`; bring an adapter to use your own.
179
+
180
+
181
+ ### Storage adapter
182
+
183
+ The editor never talks to your backend directly. Implement this and it uses your storage for everything:
184
+
185
+ ```ts
186
+ import type { EditorStorageAdapter } from "@maildeno/editor";
187
+
188
+ const adapter: EditorStorageAdapter = {
189
+ // ── Templates ──────────────────────────────────────────────
190
+ async loadTemplate(templateId) {
191
+ if (!templateId) return null; // null = start blank
192
+ const res = await fetch(`/api/templates/${templateId}`);
193
+ if (!res.ok) return null;
194
+ const t = await res.json();
195
+ return { rows: t.rows, canvasStyles: t.canvasStyles, name: t.name };
196
+ },
197
+ async saveTemplate(snapshot, templateId) {
198
+ const res = await fetch(`/api/templates/${templateId ?? ""}`, {
199
+ method: templateId ? "PUT" : "POST",
200
+ body: JSON.stringify(snapshot),
201
+ });
202
+ return { templateId: (await res.json()).id }; // editor stamps this for later saves
203
+ },
204
+
205
+ // ── Optional: powers the "Saved templates" panel ───────────
206
+ // Return summaries, not full documents — listing shouldn't fetch every
207
+ // template's rows. Omit both and the panel says listing isn't supported.
208
+ async listTemplates() {
209
+ return fetch("/api/templates").then((r) => r.json());
210
+ // -> [{ templateId, name, updatedAt }]
211
+ },
212
+ async deleteTemplate(id) {
213
+ await fetch(`/api/templates/${id}`, { method: "DELETE" });
214
+ },
215
+
216
+ // ── Saved rows (reusable snippets) ─────────────────────────
217
+ // Optional second, read-only row library — an org's shared blocks.
218
+ // Shown in a "Shared" tab beside the user's own rows, and only when
219
+ // this returns something, so omitting it changes nothing. There is no
220
+ // save/rename/delete counterpart: curating a shared library is an admin
221
+ // concern the editor has no user model to express.
222
+ async listSystemSavedRows() {
223
+ return api.get("/org/saved-rows");
224
+ },
225
+
226
+ async listSavedRows() {
227
+ return fetch("/api/saved-rows").then((r) => r.json());
228
+ },
229
+ async saveSavedRow(row, name) {
230
+ return fetch("/api/saved-rows", {
231
+ method: "POST", body: JSON.stringify({ row, name }),
232
+ }).then((r) => r.json());
233
+ },
234
+ async deleteSavedRow(id) {
235
+ await fetch(`/api/saved-rows/${id}`, { method: "DELETE" });
236
+ },
237
+ async renameSavedRow(id, name) {
238
+ await fetch(`/api/saved-rows/${id}`, {
239
+ method: "PATCH", body: JSON.stringify({ name }),
240
+ });
241
+ },
242
+ // Synchronous — it runs during a drag, so it can't await. Read from
243
+ // whatever you already have client-side (e.g. your last listSavedRows result).
244
+ cloneSavedRowForCanvas(id) {
245
+ return structuredClone(rowCache.get(id) ?? null);
246
+ },
247
+
248
+ // ── Images ─────────────────────────────────────────────────
249
+ // Called when a user drops or picks an image. Return a public URL.
250
+ async uploadImage(file) {
251
+ const form = new FormData();
252
+ form.append("file", file);
253
+ const { url } = await fetch("/api/upload", { method: "POST", body: form })
254
+ .then((r) => r.json());
255
+ return url;
256
+ },
257
+ };
258
+ ```
259
+
260
+ 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.
261
+
262
+ ### Partial adapters
263
+
264
+ Every method is optional. Anything you leave out falls back to the built-in
265
+ localStorage adapter, so you can override only the parts you need:
266
+
267
+ ```ts
268
+ // Upload images to your own storage; keep everything else local.
269
+ init({
270
+ storageAdapter: {
271
+ async uploadImage(file) {
272
+ const form = new FormData();
273
+ form.append("file", file);
274
+ const { url } = await fetch("/api/upload", { method: "POST", body: form })
275
+ .then((r) => r.json());
276
+ return url;
277
+ },
278
+ },
279
+ });
280
+ ```
281
+
282
+ The fallback is per-method, not per-area. If you implement `saveTemplate`
283
+ against your own backend but leave `listTemplates` out, the saved-templates
284
+ panel will list localStorage templates rather than yours — the editor warns
285
+ about that specific mismatch in development. Implement `listTemplates` and
286
+ `deleteTemplate` alongside `loadTemplate`/`saveTemplate` to keep them
287
+ consistent.
288
+
289
+ ### Sending email
290
+
291
+ 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:
292
+
293
+ ```ts
294
+ // client
295
+ onSendTestEmail: async ({ to, subject, html }) => {
296
+ await fetch("/api/send-test", {
297
+ method: "POST",
298
+ body: JSON.stringify({ to, subject, html }),
299
+ });
300
+ }
301
+ ```
302
+
303
+ ```ts
304
+ // server — Resend shown; Postmark/SendGrid are the same shape
305
+ import { Resend } from "resend";
306
+ const resend = new Resend(process.env.RESEND_API_KEY);
307
+
308
+ export async function POST(req) {
309
+ const { to, subject, html } = await req.json();
310
+ await resend.emails.send({ from: "you@yourdomain.com", to, subject, html });
311
+ }
312
+ ```
313
+
314
+ 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.
315
+
316
+ ### Theming
317
+
318
+ One hex re-themes the whole editor coherently:
319
+
320
+ ```ts
321
+ setTheme({ primary: "#6366f1" });
322
+ ```
323
+
324
+ Every surface reads from semantic tokens, so you can override just the parts
325
+ you care about without redefining the rest:
326
+
327
+ ```ts
328
+ setTheme({
329
+ // Core — everything else derives from these
330
+ primary: "#e11d48",
331
+ background: "#f8fafc",
332
+ surface: "#ffffff",
333
+ text: "#111827",
334
+ border: "#e5e7eb",
335
+
336
+ // Individual surfaces
337
+ headerBg: "#111827",
338
+ headerText: "#f9fafb",
339
+ sidebarBg: "#ffffff",
340
+ canvasBg: "#f1f5f9",
341
+ inputBg: "#ffffff",
342
+ inputText: "#111827",
343
+ overlayBg: "#ffffff", // dialogs, toasts, dropdowns, date picker
344
+ toolbarBg: "#ffffff", // floating + rich-text toolbars
345
+
346
+ // The Save / Update button
347
+ buttonPrimaryBg: "#e11d48",
348
+ buttonPrimaryText: "#ffffff",
349
+ buttonPrimaryHoverBg: "#be123c",
350
+
351
+ // Dark mode — has its own complete defaults, so override only what differs
352
+ dark: {
353
+ primary: "#fb7185",
354
+ headerBg: "#0b0f19",
355
+ buttonPrimaryText: "#1e1b4b",
356
+ },
357
+ });
358
+ ```
359
+
360
+ Dark mode activates when the editor element carries the `dark` class:
361
+
362
+ ```ts
363
+ handle.element.classList.toggle("dark");
364
+ ```
365
+
366
+ **Anything you leave out keeps its default**, so a partial theme is always
367
+ coherent rather than half-applied. Two things worth knowing:
368
+
369
+ - Set `onPrimary` (or `buttonPrimaryText`) when using a light brand colour, or
370
+ the primary button's label will be low-contrast against it.
371
+ - Severity tints for toasts and messages (`successBg`, `dangerFg`, …) have
372
+ separate dark defaults, so they don't leave pale panels sitting on a dark
373
+ surface.
374
+
375
+ Multiple editors on one page theme independently.
376
+
377
+
378
+ ### Extension points
379
+
380
+ All three are additive — no need to fork or edit built-ins.
381
+
382
+ ```ts
383
+ import { registerBlock, registerESPSyntax, registerMergeTags } from "@maildeno/editor";
384
+
385
+ // A custom block type
386
+ registerBlock({
387
+ name: "product-card",
388
+ label: "Product Card",
389
+ icon: "<svg …>",
390
+ schema: { /* default props */ },
391
+ renderCanvas: ProductCardCanvas, // Vue component shown in the editor
392
+ renderSettings: ProductCardPanel, // Vue component for the right panel
393
+ renderEmail: {
394
+ html: (props, ctx) => `<table>…</table>`,
395
+ mjml: (props, ctx) => `<mj-section>…</mj-section>`,
396
+ reactEmail: (props, ctx) => `<Section>…</Section>`,
397
+ },
398
+ });
399
+
400
+ // Conditional syntax for an ESP that isn't built in
401
+ registerESPSyntax("my-esp", {
402
+ wrapOpenTag: (expr) => `{% if ${expr} %}`,
403
+ wrapCloseTag: () => `{% endif %}`,
404
+ wrapMergeTag: (key, fallback) =>
405
+ fallback ? `{{ ${key} | default: "${fallback}" }}` : `{{ ${key} }}`,
406
+ });
407
+
408
+ // Extra merge tags in the picker
409
+ registerMergeTags([
410
+ { key: "customer.first_name" },
411
+ { key: "order.total" },
412
+ ]);
413
+ ```
414
+
415
+ Call these **before** the editor mounts.
416
+
417
+ ### Persisting which template is open
418
+
419
+ This requires `onSave` to have been passed to `init()` at mount time (or `@save`
420
+ bound on the Vue component) — that's what reveals the Save button in the first
421
+ place. `handle.on("save", ...)` added after mount subscribes to an event that
422
+ will never fire if `onSave` wasn't part of the original `init()` call.
423
+
424
+ ```ts
425
+ init({
426
+ container: "#editor",
427
+ onSave: ({ templateId }) => {
428
+ router.replace(`/editor/${templateId}`); // or your DB, or app state
429
+ },
430
+ });
431
+ ```
432
+
433
+ The editor doesn't own persisting *which* template is open beyond that — store
434
+ the id however your app already tracks routes or state, and pass it back as
435
+ `templateId` next time to reopen the same document.
436
+
437
+ ### Practical notes
438
+
439
+ - **The container needs a real height.** The editor fills its parent; `height: 100vh` or a sized flex child both work.
440
+ - **`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.
441
+ - **Desktop only.** The editor shows a notice on small screens rather than attempting a mobile drag-and-drop UI.
442
+ - **Autosave** keeps a local draft, so a refresh mid-edit recovers. "New template" clears it deliberately.