@maildeno/editor 0.1.4 → 0.4.3

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 (152) hide show
  1. package/CHANGELOG.md +304 -0
  2. package/README.md +397 -381
  3. package/dist/{RowPreviewLegacyComponent-yjHSkZLz.js → RowPreviewLegacyComponent-BFvLnPiK.js} +1 -1
  4. package/dist/{RowPreviewRow-D-wmhbhZ.js → RowPreviewRow-D-6koDUR.js} +2 -2
  5. package/dist/adapters/errors.d.ts +59 -0
  6. package/dist/adapters/index.d.ts +31 -0
  7. package/dist/adapters/types.d.ts +68 -0
  8. package/dist/brand.d.ts +15 -0
  9. package/dist/components/DesktopOnlyNotice.vue.d.ts +20 -0
  10. package/dist/components/features/emailBuilder/EmailEditor.vue.d.ts +182 -0
  11. package/dist/components/features/emailBuilder/assistant/AssistantPanel.vue.d.ts +37 -0
  12. package/dist/components/features/emailBuilder/blocks/AnchorBlock.vue.d.ts +3 -0
  13. package/dist/components/features/emailBuilder/blocks/ButtonBlock.vue.d.ts +3 -0
  14. package/dist/components/features/emailBuilder/blocks/DividerBlock.vue.d.ts +3 -0
  15. package/dist/components/features/emailBuilder/blocks/HeadingBlock.vue.d.ts +3 -0
  16. package/dist/components/features/emailBuilder/blocks/ImageBlock.vue.d.ts +3 -0
  17. package/dist/components/features/emailBuilder/blocks/ListBlock.vue.d.ts +3 -0
  18. package/dist/components/features/emailBuilder/blocks/MenuBlock.vue.d.ts +3 -0
  19. package/dist/components/features/emailBuilder/blocks/ParagraphBlock.vue.d.ts +3 -0
  20. package/dist/components/features/emailBuilder/blocks/SocialsBlock.vue.d.ts +3 -0
  21. package/dist/components/features/emailBuilder/blocks/SpacerBlock.vue.d.ts +3 -0
  22. package/dist/components/features/emailBuilder/blocks/VideoBlock.vue.d.ts +3 -0
  23. package/dist/components/features/emailBuilder/canvas/Canvas.vue.d.ts +3 -0
  24. package/dist/components/features/emailBuilder/canvas/CanvasColumn.vue.d.ts +49 -0
  25. package/dist/components/features/emailBuilder/canvas/CanvasComponent.vue.d.ts +56 -0
  26. package/dist/components/features/emailBuilder/canvas/CanvasElement.vue.d.ts +21 -0
  27. package/dist/components/features/emailBuilder/canvas/CanvasRow.vue.d.ts +49 -0
  28. package/dist/components/features/emailBuilder/canvas/CanvasRowSpacer.vue.d.ts +40 -0
  29. package/dist/components/features/emailBuilder/health/HealthIndicator.vue.d.ts +3 -0
  30. package/dist/components/features/emailBuilder/layout/Header.vue.d.ts +54 -0
  31. package/dist/components/features/emailBuilder/layout/SendEmail.vue.d.ts +21 -0
  32. package/dist/components/features/emailBuilder/layout/SidebarLeft.vue.d.ts +3 -0
  33. package/dist/components/features/emailBuilder/layout/SidebarRight.vue.d.ts +3 -0
  34. package/dist/components/features/emailBuilder/panels/AnchorPanel.vue.d.ts +3 -0
  35. package/dist/components/features/emailBuilder/panels/ButtonPanel.vue.d.ts +3 -0
  36. package/dist/components/features/emailBuilder/panels/DividerPanel.vue.d.ts +3 -0
  37. package/dist/components/features/emailBuilder/panels/HeadingPanel.vue.d.ts +3 -0
  38. package/dist/components/features/emailBuilder/panels/ImagePanel.vue.d.ts +3 -0
  39. package/dist/components/features/emailBuilder/panels/ListPanel.vue.d.ts +3 -0
  40. package/dist/components/features/emailBuilder/panels/MenuPanel.vue.d.ts +3 -0
  41. package/dist/components/features/emailBuilder/panels/ParagraphPanel.vue.d.ts +3 -0
  42. package/dist/components/features/emailBuilder/panels/RowColumnPanel.vue.d.ts +13 -0
  43. package/dist/components/features/emailBuilder/panels/RowPanel.vue.d.ts +13 -0
  44. package/dist/components/features/emailBuilder/panels/RowSpacerPanel.vue.d.ts +13 -0
  45. package/dist/components/features/emailBuilder/panels/SocialsPanel.vue.d.ts +3 -0
  46. package/dist/components/features/emailBuilder/panels/SpacerPanel.vue.d.ts +3 -0
  47. package/dist/components/features/emailBuilder/panels/VideoPanel.vue.d.ts +3 -0
  48. package/dist/components/features/emailBuilder/panels/shared/DeviceTabs.vue.d.ts +19 -0
  49. package/dist/components/features/emailBuilder/panels/shared/LinkFieldMergeTags.vue.d.ts +31 -0
  50. package/dist/components/features/emailBuilder/panels/shared/OverrideBadge.vue.d.ts +9 -0
  51. package/dist/components/features/emailBuilder/panels/shared/PreviewBadge.vue.d.ts +11 -0
  52. package/dist/components/features/emailBuilder/panels/shared/TextFieldMergeTags.vue.d.ts +25 -0
  53. package/dist/components/features/emailBuilder/panels/ui/BoxStylingSection.vue.d.ts +7 -0
  54. package/dist/components/features/emailBuilder/panels/ui/PropertyAlignment.vue.d.ts +30 -0
  55. package/dist/components/features/emailBuilder/panels/ui/PropertyColor.vue.d.ts +75 -0
  56. package/dist/components/features/emailBuilder/panels/ui/PropertyGradientColor.vue.d.ts +27 -0
  57. package/dist/components/features/emailBuilder/panels/ui/PropertyNumberSlider.vue.d.ts +74 -0
  58. package/dist/components/features/emailBuilder/panels/ui/PropertySection.vue.d.ts +17 -0
  59. package/dist/components/features/emailBuilder/panels/ui/PropertySelect.vue.d.ts +74 -0
  60. package/dist/components/features/emailBuilder/panels/ui/PropertyTextStyle.vue.d.ts +52 -0
  61. package/dist/components/features/emailBuilder/panels/ui/PropertyTextStylePanel.vue.d.ts +72 -0
  62. package/dist/components/features/emailBuilder/panels/ui/PropertyToggle.vue.d.ts +45 -0
  63. package/dist/components/features/emailBuilder/panels/ui/PropertyVisibility.vue.d.ts +32 -0
  64. package/dist/components/features/emailBuilder/panels/ui/SpacingControl.vue.d.ts +19 -0
  65. package/dist/components/features/emailBuilder/panels/ui/color-picker/AlphaSlider.vue.d.ts +28 -0
  66. package/dist/components/features/emailBuilder/panels/ui/color-picker/ColorPickerPanel.vue.d.ts +31 -0
  67. package/dist/components/features/emailBuilder/panels/ui/color-picker/HueSlider.vue.d.ts +19 -0
  68. package/dist/components/features/emailBuilder/panels/ui/color-picker/RecentColors.vue.d.ts +20 -0
  69. package/dist/components/features/emailBuilder/panels/ui/color-picker/SVPanel.vue.d.ts +39 -0
  70. package/dist/components/features/emailBuilder/panels/ui/visibility-rule/Rule.vue.d.ts +28 -0
  71. package/dist/components/features/emailBuilder/preview/PreviewScreen.vue.d.ts +7 -0
  72. package/dist/components/features/emailBuilder/preview/ui/PreviewCanvas.vue.d.ts +10 -0
  73. package/dist/components/features/emailBuilder/preview/ui/PreviewCapabilityBadges.vue.d.ts +12 -0
  74. package/dist/components/features/emailBuilder/preview/ui/PreviewClientCard.vue.d.ts +20 -0
  75. package/dist/components/features/emailBuilder/preview/ui/PreviewClientList.vue.d.ts +21 -0
  76. package/dist/components/features/emailBuilder/preview/ui/PreviewClientPicker.vue.d.ts +16 -0
  77. package/dist/components/features/emailBuilder/preview/ui/PreviewComponent.vue.d.ts +10 -0
  78. package/dist/components/features/emailBuilder/preview/ui/PreviewDetailView.vue.d.ts +41 -0
  79. package/dist/components/features/emailBuilder/preview/ui/PreviewRendered.vue.d.ts +8 -0
  80. package/dist/components/features/emailBuilder/product/RowPreview.vue.d.ts +8 -0
  81. package/dist/components/features/emailBuilder/product/RowPreviewChildren.vue.d.ts +14 -0
  82. package/dist/components/features/emailBuilder/product/RowPreviewLegacyComponent.vue.d.ts +14 -0
  83. package/dist/components/features/emailBuilder/product/RowPreviewRow.vue.d.ts +9 -0
  84. package/dist/components/features/emailBuilder/product/SavedRowsPanel.vue.d.ts +3 -0
  85. package/dist/components/features/emailBuilder/product/SavedTemplatesPanel.vue.d.ts +13 -0
  86. package/dist/components/features/emailBuilder/product/VersionHistoryPanel.vue.d.ts +14 -0
  87. package/dist/components/features/emailBuilder/sidebar/SidebarBlockButton.vue.d.ts +35 -0
  88. package/dist/components/features/emailBuilder/tabs/GeneralTab.vue.d.ts +3 -0
  89. package/dist/components/features/emailBuilder/tabs/LayoutTab.vue.d.ts +3 -0
  90. package/dist/components/features/emailBuilder/tabs/content/ContentTab.vue.d.ts +3 -0
  91. package/dist/components/features/emailBuilder/tabs/content/LayersPanel.vue.d.ts +7 -0
  92. package/dist/components/features/emailBuilder/tabs/general/MergeTagsTab.vue.d.ts +3 -0
  93. package/dist/components/features/emailBuilder/tabs/general/StylesTab.vue.d.ts +3 -0
  94. package/dist/components/features/emailBuilder/tabs/general/VisibilityTab.vue.d.ts +3 -0
  95. package/dist/components/features/emailBuilder/tabs/general/VisibilityWrapESPTab.vue.d.ts +3 -0
  96. package/dist/components/features/emailBuilder/tabs/general/merge-tags/LinkTagTab.vue.d.ts +3 -0
  97. package/dist/components/features/emailBuilder/tabs/general/merge-tags/MergeTagTab.vue.d.ts +3 -0
  98. package/dist/components/features/emailBuilder/ui/LinkInputDialog.vue.d.ts +17 -0
  99. package/dist/components/features/emailBuilder/ui/canvas/CanvasRowDropZone.vue.d.ts +12 -0
  100. package/dist/components/features/emailBuilder/ui/canvas/DropZone.vue.d.ts +10 -0
  101. package/dist/components/features/emailBuilder/ui/canvas/Loader.vue.d.ts +19 -0
  102. package/dist/components/features/emailBuilder/ui/layers-panel/ComponentIcon.vue.d.ts +7 -0
  103. package/dist/components/features/emailBuilder/ui/layers-panel/LayerColumnChildren.vue.d.ts +42 -0
  104. package/dist/components/features/emailBuilder/ui/layers-panel/LayerDropLine.vue.d.ts +8 -0
  105. package/dist/components/features/emailBuilder/ui/renderers/AnchorRenderer.vue.d.ts +10 -0
  106. package/dist/components/features/emailBuilder/ui/renderers/DividerRenderer.vue.d.ts +10 -0
  107. package/dist/components/features/emailBuilder/ui/renderers/HeadingRenderer.vue.d.ts +10 -0
  108. package/dist/components/features/emailBuilder/ui/renderers/ImageRenderer.vue.d.ts +10 -0
  109. package/dist/components/features/emailBuilder/ui/renderers/ListRenderer.vue.d.ts +10 -0
  110. package/dist/components/features/emailBuilder/ui/renderers/MenuRenderer.vue.d.ts +10 -0
  111. package/dist/components/features/emailBuilder/ui/renderers/ParagraphRenderer.vue.d.ts +10 -0
  112. package/dist/components/features/emailBuilder/ui/renderers/SocialsRenderer.vue.d.ts +10 -0
  113. package/dist/components/features/emailBuilder/ui/renderers/SpacerRenderer.vue.d.ts +10 -0
  114. package/dist/components/features/emailBuilder/ui/renderers/VideoRenderer.vue.d.ts +10 -0
  115. package/dist/components/features/emailBuilder/ui/rich-text-editor/RichTextEditor.vue.d.ts +12 -0
  116. package/dist/components/features/emailBuilder/ui/rich-text-editor/pickers/MergeTagPicker.vue.d.ts +18 -0
  117. package/dist/components/features/emailBuilder/ui/rich-text-editor/pickers/RichTextColorPicker.vue.d.ts +15 -0
  118. package/dist/components/features/emailBuilder/ui/visibility/SupportBadge.vue.d.ts +10 -0
  119. package/dist/components/features/emailBuilder/ui/visibility/VisibilityPopover.vue.d.ts +45 -0
  120. package/dist/components/ui/ConfirmDialog.vue.d.ts +3 -0
  121. package/dist/components/ui/Icon.vue.d.ts +33 -0
  122. package/dist/components/ui/InfoDialog.vue.d.ts +12 -0
  123. package/dist/components/ui/Loading.vue.d.ts +6 -0
  124. package/dist/components/ui/ShadowSafeToast.vue.d.ts +3 -0
  125. package/dist/components/ui/primitives/Button.vue.d.ts +23 -0
  126. package/dist/components/ui/primitives/DatePicker.vue.d.ts +16 -0
  127. package/dist/components/ui/primitives/Dialog.vue.d.ts +34 -0
  128. package/dist/components/ui/primitives/InputText.vue.d.ts +29 -0
  129. package/dist/components/ui/primitives/Message.vue.d.ts +20 -0
  130. package/dist/components/ui/primitives/Select.vue.d.ts +22 -0
  131. package/dist/composables/emailBuilder/components/useSystemRows.d.ts +22 -0
  132. package/dist/composables/emailBuilder/core/ui/useLayerHoverScroll.d.ts +10 -10
  133. package/dist/composables/emailBuilder/core/useEmailBuilder.d.ts +18 -0
  134. package/dist/composables/emailBuilder/export/logic/espLogicWrapper.d.ts +4 -4
  135. package/dist/composables/emailBuilder/export/targets/templateSnapshot.d.ts +24 -0
  136. package/dist/composables/emailBuilder/persistence/useEmailBuilderPersistence.d.ts +1 -1
  137. package/dist/composables/system/useColorScheme.d.ts +16 -0
  138. package/dist/editor.css +2074 -1688
  139. package/dist/{element-CWjNN0lY.js → element-95RHug4F.js} +3275 -1986
  140. package/dist/element-scoped-styles.css +2074 -1688
  141. package/dist/element.d.ts +1 -1
  142. package/dist/element.js +1 -1
  143. package/dist/{html-DGrfikay.js → html-D6UnSE1C.js} +1 -1
  144. package/dist/index.d.ts +4 -2
  145. package/dist/index.js +3325 -1984
  146. package/dist/init.d.ts +95 -2
  147. package/dist/init.js +29 -3
  148. package/dist/theme.d.ts +68 -17
  149. package/dist/types/assistant.d.ts +56 -0
  150. package/dist/{vue.runtime.esm-bundler-CfYyFhW6.js → vue.runtime.esm-bundler-BaHqghYy.js} +3 -3
  151. package/package.json +6 -3
  152. package/dist/composables/emailBuilder/transform/pipeline/optimizeAI.d.ts +0 -125
package/dist/init.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PartialStorageAdapter } from './adapters/types';
2
+ import { AssistantMount } from './types/assistant';
2
3
  import { ThemeOptions } from './theme';
3
4
  /**
4
5
  * The ergonomic, no-Vue-knowledge entry point. element.ts already provides
@@ -22,6 +23,67 @@ export interface InitOptions {
22
23
  subject: string;
23
24
  html: string;
24
25
  }) => Promise<void> | void;
26
+ /**
27
+ * Name shown in the desktop-only notice's "Powered by" line. Omit for the
28
+ * package default; pass an empty string to drop the line entirely.
29
+ *
30
+ * Unlike storageAdapter/theme/onSendTestEmail this is a plain string, so
31
+ * the custom element accepts it as a `brand-name` attribute too —
32
+ * `<maildeno-editor brand-name="Acme">` works without any JavaScript.
33
+ * init() still sets it as a property below, for consistency with the
34
+ * other options rather than out of necessity.
35
+ */
36
+ brandName?: string;
37
+ /**
38
+ * Replaces the saved-templates panel and its header button with version
39
+ * history. Requires an adapter implementing the version methods — see
40
+ * EditorStorageAdapter; the built-in localStorage adapter implements all
41
+ * of them, so this works with no backend.
42
+ *
43
+ * A boolean, so the custom element accepts it as a `versions` attribute
44
+ * too — attribute presence is truthy, matching how HTML booleans work.
45
+ */
46
+ versions?: boolean;
47
+ /**
48
+ * Called after a successful save. Its presence is what reveals the Save
49
+ * button — omit it for a read-only or guest editor and the button, the
50
+ * save-status indicator and the autosave timer all disappear.
51
+ *
52
+ * The "save" event still fires alongside, so handle.on("save", …) keeps
53
+ * working; this option exists because a listener attached after mount
54
+ * can't retroactively decide whether the button should have rendered.
55
+ */
56
+ onSave?: (payload: {
57
+ templateId: string | null;
58
+ }) => void;
59
+ /**
60
+ * Fills the editor's assistant drawer with your own UI.
61
+ *
62
+ * The editor supplies the drawer, its trigger button, open/close state,
63
+ * escape handling and shadow-DOM-safe positioning; `mount` receives the
64
+ * drawer's body element plus a small canvas API (getJson/setJson/
65
+ * getSelection/setSelection/onChange) and renders whatever it likes into
66
+ * it — React root, plain DOM, anything.
67
+ *
68
+ * Called on first open rather than at startup, and `unmount` on close, so
69
+ * a drawer the user never opens costs nothing.
70
+ *
71
+ * ```ts
72
+ * init({
73
+ * container: "#editor",
74
+ * assistant: {
75
+ * mount(el, editor) {
76
+ * el.innerHTML = "<button>Rewrite</button>";
77
+ * el.querySelector("button").onclick = async () => {
78
+ * const next = await myApi.rewrite(editor.getJson());
79
+ * editor.setJson(next);
80
+ * };
81
+ * },
82
+ * },
83
+ * });
84
+ * ```
85
+ */
86
+ assistant?: AssistantMount;
25
87
  /**
26
88
  * Render inside a shadow root (default) or directly in the page.
27
89
  *
@@ -46,6 +108,14 @@ export interface EditorHandle {
46
108
  /** Vue's defineCustomElement dispatches emits as real DOM CustomEvents
47
109
  * on the host element, with the emit payload in event.detail — this is
48
110
  * just addEventListener with that unwrapping done for you. */
111
+ /**
112
+ * Additional listeners for the save event.
113
+ *
114
+ * Only ever fires when `onSave` was passed to init(): without it the editor
115
+ * has no Save button and never saves, so there is no event to hear. If you
116
+ * only want to observe saves, pass a no-op `onSave` to enable saving and do
117
+ * the work here.
118
+ */
49
119
  on(event: "save", handler: (payload: {
50
120
  templateId: string | null;
51
121
  }) => void): void;
@@ -69,14 +139,37 @@ export interface EditorHandle {
69
139
  getMjml(mode?: "prune" | "wrap"): string | null;
70
140
  getReactEmail(mode?: "prune" | "wrap"): string | null;
71
141
  getJson(): Record<string, unknown> | null;
142
+ /** The write side of getJson(). Accepts what getJson() returns, so
143
+ * setJson(getJson()) round-trips, plus the { canvas, content: { rows } }
144
+ * shape version APIs typically hand back.
145
+ *
146
+ * history defaults to "undoable" — one Ctrl+Z-able step, right for
147
+ * anything the user triggered. Pass "reset" when swapping which document
148
+ * is open, where undoing back into the previous document would be wrong. */
149
+ setJson(data: unknown, opts?: {
150
+ history?: "undoable" | "reset";
151
+ }): void;
152
+ /** The selected node, or null. `type` is the block type, so a host can
153
+ * branch on it without resolving the id against the tree itself. */
154
+ getSelection(): {
155
+ id: string;
156
+ type: string | null;
157
+ } | null;
158
+ /** Selects by id, or clears with null. Returns false if no node has that
159
+ * id. Does not touch history — selection is view state. */
160
+ setSelection(id: string | null): boolean;
161
+ /** Fires after each committed change. Returns an unsubscribe function.
162
+ * Keyed to history commits rather than raw mutations, so typing inside a
163
+ * text block produces one call, not one per keystroke. */
164
+ onChange(cb: () => void): () => void;
72
165
  /** Removes the element from the DOM. Vue's custom element wrapper
73
166
  * handles unmounting the internal app and cleaning up watchers/effects
74
167
  * as part of its own disconnectedCallback — not reimplemented here. */
75
168
  destroy(): void;
76
169
  }
77
170
  export declare function init(options: InitOptions): Promise<EditorHandle>;
78
- export { registerBlock, getBlock, getAllBlocks, } from './blocks/registry';
79
- export { registerESPSyntax, getRegisteredCustomESPs, } from './esp/registry';
171
+ export { registerBlock, getBlock, getAllBlocks } from './blocks/registry';
172
+ export { registerESPSyntax, getRegisteredCustomESPs } from './esp/registry';
80
173
  export { registerMergeTags, getRegisteredMergeTagIds, } from './merge-tags/registry';
81
174
  export { setEditorTheme, palette } from './theme';
82
175
  export { createLocalStorageAdapter } from './adapters/localStorageAdapter';
package/dist/init.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as h, at as ref, i as createApp, rt as reactive } from "./vue.runtime.esm-bundler-CfYyFhW6.js";
2
- import { a as setEditorTheme, c as createLocalStorageAdapter, d as getRegisteredMergeTagIds, f as registerMergeTags, h as registerBlock, i as palette, l as getRegisteredCustomESPs, m as getBlock, n as registerMaildenoEditorElement, p as getAllBlocks, r as EmailEditor_default, s as buildShadowStyles, u as registerESPSyntax } from "./element-CWjNN0lY.js";
1
+ import { O as h, at as reactive, i as createApp, st as ref } from "./vue.runtime.esm-bundler-BaHqghYy.js";
2
+ import { a as setEditorTheme, c as getRegisteredCustomESPs, d as registerMergeTags, f as getAllBlocks, h as createLocalStorageAdapter, i as palette, l as registerESPSyntax, m as registerBlock, n as registerMaildenoEditorElement, p as getBlock, r as EmailEditor_default, s as buildShadowStyles, u as getRegisteredMergeTagIds } from "./element-95RHug4F.js";
3
3
  //#region src/lightDom.ts
4
4
  var stylesInjected = false;
5
5
  /**
@@ -63,7 +63,11 @@ async function init(options) {
63
63
  storageAdapter: options.storageAdapter,
64
64
  theme: options.theme,
65
65
  capabilities: options.capabilities,
66
- onSendTestEmail: options.onSendTestEmail
66
+ onSendTestEmail: options.onSendTestEmail,
67
+ brandName: options.brandName,
68
+ versions: options.versions,
69
+ saveHandler: options.onSave,
70
+ assistant: options.assistant
67
71
  });
68
72
  await new Promise((resolve) => setTimeout(resolve, 0));
69
73
  const call = (name, ...args) => {
@@ -79,6 +83,12 @@ async function init(options) {
79
83
  getMjml: (mode = "prune") => call("getMjml", mode),
80
84
  getReactEmail: (mode = "prune") => call("getReactEmail", mode),
81
85
  getJson: () => call("getJson"),
86
+ setJson: (data, opts) => {
87
+ call("setJson", data, opts);
88
+ },
89
+ getSelection: () => call("getSelection"),
90
+ setSelection: (id) => call("setSelection", id) ?? false,
91
+ onChange: (cb) => call("onChange", cb) ?? (() => {}),
82
92
  destroy: () => mount.destroy()
83
93
  };
84
94
  }
@@ -89,6 +99,10 @@ async function init(options) {
89
99
  if (options.theme) el.theme = options.theme;
90
100
  if (options.capabilities) el.capabilities = options.capabilities;
91
101
  if (options.onSendTestEmail) el.onSendTestEmail = options.onSendTestEmail;
102
+ if (options.brandName !== void 0) el.brandName = options.brandName;
103
+ if (options.versions !== void 0) el.versions = options.versions;
104
+ if (options.assistant) el.assistant = options.assistant;
105
+ if (options.onSave) el.saveHandler = options.onSave;
92
106
  container.appendChild(el);
93
107
  await new Promise((resolve) => setTimeout(resolve, 0));
94
108
  const listenerWrappers = /* @__PURE__ */ new WeakMap();
@@ -121,6 +135,18 @@ async function init(options) {
121
135
  getJson() {
122
136
  return el.getJson ? el.getJson() : null;
123
137
  },
138
+ setJson(data, opts) {
139
+ el.setJson?.(data, opts);
140
+ },
141
+ getSelection() {
142
+ return el.getSelection ? el.getSelection() : null;
143
+ },
144
+ setSelection(id) {
145
+ return el.setSelection ? el.setSelection(id) : false;
146
+ },
147
+ onChange(cb) {
148
+ return el.onChange ? el.onChange(cb) : () => {};
149
+ },
124
150
  destroy() {
125
151
  el.remove();
126
152
  }
package/dist/theme.d.ts CHANGED
@@ -3,20 +3,41 @@
3
3
  *
4
4
  * Setting variables rather than regenerating a stylesheet is what makes this
5
5
  * work in the custom-element build: the bundled shadow-root CSS is static and
6
- * cannot be re-emitted at runtime, but a custom property set on the host
7
- * cascades into the shadow tree and updates every rule reading it, live.
6
+ * cannot be re-emitted at runtime, but a custom property set on the editor
7
+ * root cascades into the whole subtree and updates every rule reading it,
8
+ * live.
8
9
  */
9
10
  /**
10
11
  * Every themeable token.
11
12
  *
12
13
  * Two layers, deliberately. Core tokens (`primary`, `surface`, `text`, …)
13
14
  * re-theme the whole editor coherently. Semantic tokens (`headerBg`,
14
- * `inputBg`, `overlayBg`, …) default to the core ones and exist for hosts
15
+ * `overlayBg`, `toolbarBg`, …) default to the core ones and exist for hosts
15
16
  * that want to change one surface without redefining everything else.
16
17
  *
17
18
  * Anything left out keeps its default, so a partial theme is always coherent
18
19
  * rather than half-applied — setting only `primary` cannot produce unreadable
19
20
  * text, and setting only `headerBg` cannot leave the rest inconsistent.
21
+ *
22
+ * ── Every token here is read by something ───────────────────────────────────
23
+ * Twenty-one used to be listed that nothing in the package consumed:
24
+ * `ring`, the four `input*` tokens, `primarySoft*`, `primaryBorder`,
25
+ * `onPrimarySoft`, `onAccentSoft`, `inverseSurfaceHover`, `borderSubtle`,
26
+ * `surfaceSunken`, `shadowSm`, `shadowLg`, the four `code*` tokens and the two
27
+ * `skeleton*` tokens. They had CSS defaults, they type-checked, they appeared
28
+ * in the docs — and setting any of them did nothing, because no rule ever read
29
+ * the variable.
30
+ *
31
+ * The `input*` four are the ones worth knowing about: inputs are styled from
32
+ * `surface` / `border` / `text` / `textSubtle` directly, in the scoped CSS of
33
+ * InputText.vue, Select.vue and DatePicker.vue. The dark palette's "a field
34
+ * darker than its panel reads as an input" intent was never realised. Removing
35
+ * them changes nothing on screen — they were already inert — but it stops the
36
+ * type surface promising a control the editor does not offer. Wiring them up
37
+ * instead is three small scoped-CSS edits, if that look is wanted.
38
+ *
39
+ * `codeBg` and friends belong to the host dashboard's own CodeBlock component,
40
+ * never to the editor, which renders no code panels at all.
20
41
  */
21
42
  export interface ThemeTokens {
22
43
  /** Brand/accent colour. Drives the primary button, focus rings, selection. */
@@ -27,13 +48,16 @@ export interface ThemeTokens {
27
48
  onPrimary?: string;
28
49
  /** Page background behind the canvas. */
29
50
  background?: string;
30
- /** Panels, header, toolbars, popovers. */
51
+ /** Panels, header, toolbars, popovers — and, because inputs read it
52
+ * directly, field backgrounds. */
31
53
  surface?: string;
32
54
  /** Subtle fills — inactive tabs, secondary buttons. */
33
55
  surfaceMuted?: string;
56
+ /** Hover fill, and the background of a disabled input. */
34
57
  surfaceHover?: string;
35
58
  text?: string;
36
59
  textMuted?: string;
60
+ /** Also the input placeholder colour. */
37
61
  textSubtle?: string;
38
62
  border?: string;
39
63
  borderStrong?: string;
@@ -42,9 +66,7 @@ export interface ThemeTokens {
42
66
  success?: string;
43
67
  warning?: string;
44
68
  info?: string;
45
- /** Focus ring colour. Defaults to `primary`. */
46
- ring?: string;
47
- /** Box-shadow used by popovers and dialogs. */
69
+ /** Box-shadow used by popovers and dialogs. Feeds `overlayShadow`. */
48
70
  shadow?: string;
49
71
  /** Backdrop behind modal dialogs. */
50
72
  scrim?: string;
@@ -58,10 +80,6 @@ export interface ThemeTokens {
58
80
  accentBg?: string;
59
81
  accentText?: string;
60
82
  canvasBg?: string;
61
- inputBg?: string;
62
- inputText?: string;
63
- inputBorder?: string;
64
- inputPlaceholder?: string;
65
83
  /** Dialogs, toasts, dropdowns, date picker and floating toolbars. */
66
84
  overlayBg?: string;
67
85
  overlayText?: string;
@@ -83,7 +101,7 @@ export interface ThemeTokens {
83
101
  /** Same role as `selection`, one level up: row outlines, the row's
84
102
  * floating toolbar, and "this is a row" indicators in the Layout tab
85
103
  * and Layers panel. Separate token so components and rows can be told
86
- * apart at a glance */
104
+ * apart at a glance. */
87
105
  rowSelection?: string;
88
106
  rowSelectionBg?: string;
89
107
  rowSelectionFg?: string;
@@ -112,15 +130,34 @@ export interface ThemeTokens {
112
130
  dangerBg?: string;
113
131
  dangerFg?: string;
114
132
  dangerBorder?: string;
133
+ /** The dark pill — primary CTA, active tab. FLIPS to a light fill in dark
134
+ * mode. Use this, not `text`, for any dark-filled control: a text token
135
+ * cannot invert that way without making body copy invisible. */
136
+ inverseSurface?: string;
137
+ onInverse?: string;
138
+ onInverseMuted?: string;
139
+ /** Secondary signal, distinct from `primary`. Used for AI surfaces and the
140
+ * row-selection family. */
141
+ accent?: string;
142
+ accentHover?: string;
143
+ onAccent?: string;
144
+ accentSoft?: string;
145
+ accentBorder?: string;
115
146
  }
116
147
  export interface ThemeOptions extends ThemeTokens {
117
148
  /** Tokens applied only in light mode. */
118
149
  light?: ThemeTokens;
119
150
  /**
120
- * Tokens applied only when the editor has the `dark` class.
151
+ * Tokens applied only when the editor is in dark mode.
121
152
  *
122
153
  * Dark mode has its own complete set of defaults, so overriding a couple of
123
154
  * tokens here is enough — you do not have to restate a whole palette.
155
+ *
156
+ * "In dark mode" means the editor root carries the `dark` class, which
157
+ * useColorScheme.ts puts there by mirroring the host page's own `.dark` on
158
+ * <html> or <body>. A host with a working theme switcher needs no wiring;
159
+ * one whose switcher works some other way passes `colorMode` to
160
+ * <EmailEditor> instead.
124
161
  */
125
162
  dark?: ThemeTokens;
126
163
  /** @deprecated Use `primary`. */
@@ -139,10 +176,24 @@ export interface ThemeOptions extends ThemeTokens {
139
176
  * });
140
177
  * ```
141
178
  *
142
- * @param target For the plain Vue build, omit defaults to
143
- * `document.documentElement`. For the custom-element build, pass the
144
- * `<maildeno-editor>` element, so the properties cascade into its shadow
145
- * tree. `handle.setTheme()` does this for you.
179
+ * @param target Where the tokens are declared. **This must be the editor's own
180
+ * root element**, and <EmailEditor> passes it for you — the default below is
181
+ * only for callers driving the CSS variables by hand, with no editor
182
+ * mounted.
183
+ *
184
+ * Why it matters: the library build runs every injected stylesheet through
185
+ * scopeInjectedCss.ts, which rewrites `:root`/`:host` to `.md-editor-scope`
186
+ * so the editor's CSS cannot restyle the host page. That puts the package's
187
+ * default tokens *directly on the editor root div*. A custom property
188
+ * declared on an element beats any value inherited from an ancestor,
189
+ * whatever the specificity — so a theme written to <html> is shadowed by the
190
+ * defaults and never reaches the editor at all. Writing to the same element
191
+ * the defaults land on puts the two in the same cascade, where the runtime
192
+ * sheet wins on source order.
193
+ *
194
+ * This is also why theming appeared to work when running from source (the
195
+ * playground aliases straight to `src` and never runs the scoper, so `:root`
196
+ * stays `:root`) and silently did nothing in a consuming app.
146
197
  */
147
198
  export declare function setEditorTheme(options: ThemeOptions, target?: HTMLElement): void;
148
199
  /**
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The canvas API handed to a host-supplied assistant panel.
3
+ *
4
+ * Defined once here rather than inline in each place it appears, because it
5
+ * shows up in three: the #assistant slot's prop, assistant.mount()'s second
6
+ * argument, and EditorHandle. Three structural copies would drift the first
7
+ * time a method is added, and the drift would be silent — a slot typed with
8
+ * five methods and a callback typed with four both compile fine.
9
+ *
10
+ * A read/write subset of what EmailEditor exposes, not the whole surface.
11
+ * An assistant needs to see the canvas, change it, and know when it moved.
12
+ * It has no business calling destroy() or re-theming the editor, so those
13
+ * are absent rather than present-and-discouraged.
14
+ */
15
+ export interface EditorWriteApi {
16
+ /** Current template as a plain object, or null when the canvas is empty. */
17
+ getJson(): Record<string, unknown> | null;
18
+ /**
19
+ * Replaces the canvas. Accepts what getJson() returns.
20
+ *
21
+ * Defaults to an undoable step, which is almost always what an assistant
22
+ * wants: a user who dislikes a generated design presses Ctrl+Z and has
23
+ * their own work back. Passing "reset" throws that away, so it is for
24
+ * document swaps rather than edits.
25
+ */
26
+ setJson(data: unknown, opts?: {
27
+ history?: "undoable" | "reset";
28
+ }): void;
29
+ /** The selected block, or null. `type` is the block type ("paragraph",
30
+ * "image"), which is what a "rewrite this heading" flow branches on. */
31
+ getSelection(): {
32
+ id: string;
33
+ type: string | null;
34
+ } | null;
35
+ /** Selects by id, or clears with null. False if no block has that id. */
36
+ setSelection(id: string | null): boolean;
37
+ /** Runs after each committed change. Returns an unsubscribe function —
38
+ * call it when the panel tears down, or the callback outlives the panel
39
+ * and fires against a dead component. */
40
+ onChange(cb: () => void): () => void;
41
+ }
42
+ /**
43
+ * How an init()/custom-element host fills the assistant drawer.
44
+ *
45
+ * Imperative rather than a component, because that path has no framework in
46
+ * common with the editor — a React host renders with createRoot into the
47
+ * element, a vanilla host sets innerHTML, and neither should need to know
48
+ * Vue exists.
49
+ */
50
+ export interface AssistantMount {
51
+ /** Called on first open, with the drawer's body element. */
52
+ mount: (el: HTMLElement, editor: EditorWriteApi) => void;
53
+ /** Called on close and on editor teardown. Tear down listeners and any
54
+ * framework root here; the editor only empties the element after this. */
55
+ unmount?: (el: HTMLElement) => void;
56
+ }
@@ -5884,8 +5884,8 @@ function baseCreateRenderer(options, createHydrationFns) {
5884
5884
  const oldLength = c1.length;
5885
5885
  const newLength = c2.length;
5886
5886
  const commonLength = Math.min(oldLength, newLength);
5887
- let i;
5888
- for (i = 0; i < commonLength; i++) {
5887
+ let i = 0;
5888
+ for (; i < commonLength; i++) {
5889
5889
  const nextChild = c2[i] = optimized ? cloneIfMounted(c2[i]) : normalizeVNode(c2[i]);
5890
5890
  patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, namespace, slotScopeIds, optimized);
5891
5891
  }
@@ -9094,4 +9094,4 @@ var compile = () => {
9094
9094
  if (!!(process.env.NODE_ENV !== "production")) warn("Runtime compilation is not supported in this build of Vue. Configure your bundler to alias \"vue\" to \"vue/dist/vue.esm-bundler.js\".");
9095
9095
  };
9096
9096
  //#endregion
9097
- export { getCurrentScope as $, mergeProps as A, resolveComponent as B, defineAsyncComponent as C, h as D, guardReactiveProps as E, onUpdated as F, watchEffect as G, toHandlers as H, openBlock as I, withCtx as J, watchPostEffect as K, provide as L, onBeforeUnmount as M, onMounted as N, inject as O, onUnmounted as P, effectScope as Q, renderList as R, createVNode as S, getCurrentInstance as T, useId as U, resolveDynamicComponent as V, watch as W, withMemo as X, withDirectives as Y, customRef as Z, createBlock as _, toDisplayString as _t, defineCustomElement as a, ref as at, createStaticVNode as b, vShow as c, toRef as ct, Comment as d, triggerRef as dt, isRef as et, Fragment as f, unref as ft, createBaseVNode as g, normalizeStyle as gt, computed as h, normalizeProps as ht, createApp as i, readonly as it, nextTick as j, mergeDefaults as k, withKeys as l, toRefs as lt, cloneVNode as m, normalizeClass as mt, Transition as n, onScopeDispose as nt, vModelSelect as o, shallowReadonly as ot, Teleport as p, camelize as pt, watchSyncEffect as q, TransitionGroup as r, reactive as rt, vModelText as s, shallowRef as st, vue_runtime_esm_bundler_exports as t, markRaw as tt, withModifiers as u, toValue as ut, createCommentVNode as v, toHandlerKey as vt, defineComponent as w, createTextVNode as x, createElementBlock as y, __exportAll as yt, renderSlot as z };
9097
+ export { customRef as $, mergeDefaults as A, renderSlot as B, createVNode as C, guardReactiveProps as D, getCurrentInstance as E, onUnmounted as F, useSlots as G, resolveDynamicComponent as H, onUpdated as I, watchPostEffect as J, watch as K, openBlock as L, nextTick as M, onBeforeUnmount as N, h as O, onMounted as P, withMemo as Q, provide as R, createTextVNode as S, defineComponent as T, toHandlers as U, resolveComponent as V, useId as W, withCtx as X, watchSyncEffect as Y, withDirectives as Z, createBlock as _, normalizeProps as _t, defineCustomElement as a, reactive as at, createSlots as b, toHandlerKey as bt, vShow as c, shallowReadonly as ct, Comment as d, toRefs as dt, effectScope as et, Fragment as f, toValue as ft, createBaseVNode as g, normalizeClass as gt, computed as h, camelize as ht, createApp as i, onScopeDispose as it, mergeProps as j, inject as k, withKeys as l, shallowRef as lt, cloneVNode as m, unref as mt, Transition as n, isRef as nt, vModelSelect as o, readonly as ot, Teleport as p, triggerRef as pt, watchEffect as q, TransitionGroup as r, markRaw as rt, vModelText as s, ref as st, vue_runtime_esm_bundler_exports as t, getCurrentScope as tt, withModifiers as u, toRef as ut, createCommentVNode as v, normalizeStyle as vt, defineAsyncComponent as w, createStaticVNode as x, __exportAll as xt, createElementBlock as y, toDisplayString as yt, renderList as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maildeno/editor",
3
- "version": "0.1.4",
3
+ "version": "0.4.3",
4
4
  "description": "An open-source, framework-agnostic email template editor. Drag-and-drop block editing, HTML/MJML/React Email/JSON export, and a pluggable ESP-conditional-logic engine with zero required backend.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  "files": [
23
23
  "dist",
24
24
  "README.md",
25
+ "CHANGELOG.md",
25
26
  "LICENSE"
26
27
  ],
27
28
  "scripts": {
@@ -29,7 +30,9 @@
29
30
  "dev:element": "vite build --config vite.config.element.ts --watch",
30
31
  "build": "vite build && vite build --config vite.config.element.ts",
31
32
  "typecheck": "vue-tsc -p tsconfig.json --noEmit && tsc -p tsconfig.node.json --noEmit",
32
- "prepublishOnly": "npm run typecheck && npm run build"
33
+ "prepublishOnly": "npm run typecheck && npm run build",
34
+ "format": "prettier --write \"src/**/*.{ts,vue}\"",
35
+ "format:check": "prettier --check \"src/**/*.{ts,vue}\""
33
36
  },
34
37
  "sideEffects": [
35
38
  "**/*.css"
@@ -96,4 +99,4 @@
96
99
  "vite-plugin-dts": "^5.0.3",
97
100
  "vue-tsc": "^3.3.11"
98
101
  }
99
- }
102
+ }
@@ -1,125 +0,0 @@
1
- /**
2
- * optimizeAI.ts
3
- * AI-facing counterpart to optimize.ts. Strips default/noise values from
4
- * rows, columns, components, and canvas before building the snapshot sent
5
- * to the AI model — separate pipeline so it can strip more aggressively
6
- * than the JSON-export pipeline without the two compromising each other.
7
- *
8
- * optimize.ts / hydrate.ts are NOT modified by this file and are unaffected.
9
- *
10
- * Two different kinds of "default" are handled differently, on purpose:
11
- *
12
- * - STATELESS style props (margin, padding, border, letterSpacing, ...):
13
- * no "user chose to remove this" meaning attached — just set vs. unset.
14
- * Diffed against each component TYPE's real default via
15
- * useEmailBuilderDefaults(), so this never drifts out of sync the way a
16
- * hardcoded universal check (e.g. "is it all-zero") can for component
17
- * types whose real default isn't zero. The AI doesn't lose anything by
18
- * these being stripped: schemaBlock() in useEmailAIPrompts.ts already
19
- * tells it every prop + its default, independent of what's in the
20
- * snapshot. Snapshot = the diff; schema = the full menu.
21
- *
22
- * - SELECTION-style fields (socials platforms, mobile overrides, the icon
23
- * cluster): reflect a deliberate choice, not just set-vs-unset. Mirrored
24
- * EXACTLY from optimize.ts's existing logic, unchanged, so this pipeline
25
- * respects the same choices the export pipeline already does.
26
- *
27
- * Restoring what gets stripped here needs no new hydrate-side code: hydrate.ts's
28
- * hydrateComponent() already deep-merges against each type's real defaults
29
- * (via the same useEmailBuilderDefaults()), so it already restores anything
30
- * this file strips. See useEmailAISnapshot.ts's existing hydrateAIRows /
31
- * hydrateAIRow / hydrateAIComponent — those remain the AI hydration path,
32
- * unchanged.
33
- */
34
- interface VisibilityConfig {
35
- enabled: boolean;
36
- match: "all" | "any";
37
- rules: unknown[];
38
- }
39
- interface BorderConfig {
40
- width: number;
41
- style: string;
42
- color: string;
43
- radius?: number;
44
- }
45
- interface GradientConfig {
46
- useGradient: boolean;
47
- solid: string;
48
- gradient: {
49
- type: "linear" | "radial";
50
- direction: string;
51
- colors: Array<{
52
- color: string;
53
- position: number;
54
- }>;
55
- };
56
- }
57
- interface Component {
58
- id: string;
59
- type: string;
60
- componentType?: string;
61
- props: Record<string, unknown>;
62
- }
63
- type CanvasChild = Component | NestedRow | RowSpacer;
64
- interface Column {
65
- id: string;
66
- width: number;
67
- children?: CanvasChild[];
68
- components?: Component[];
69
- backgroundColor?: string;
70
- backgroundGradient?: GradientConfig;
71
- backgroundImage?: string;
72
- backgroundSize?: string;
73
- backgroundPosition?: string;
74
- backgroundRepeat?: string;
75
- padding?: Record<string, number>;
76
- border?: BorderConfig;
77
- verticalAlign?: string;
78
- [key: string]: unknown;
79
- }
80
- interface NestedRow {
81
- id: string;
82
- type: "row";
83
- name?: string;
84
- columns?: Column[];
85
- visibility?: VisibilityConfig;
86
- border?: BorderConfig;
87
- backgroundColor?: string;
88
- backgroundImage?: string;
89
- backgroundSize?: string;
90
- backgroundPosition?: string;
91
- backgroundRepeat?: string;
92
- padding?: Record<string, number>;
93
- backgroundGradient?: GradientConfig;
94
- minHeight?: number;
95
- gap?: number;
96
- [key: string]: unknown;
97
- }
98
- interface RowSpacer {
99
- id: string;
100
- type: "row-spacer";
101
- name?: string;
102
- height?: number;
103
- backgroundColor?: string;
104
- backgroundGradient?: GradientConfig;
105
- visibility?: VisibilityConfig;
106
- [key: string]: unknown;
107
- }
108
- type Row = NestedRow | RowSpacer;
109
- interface Canvas {
110
- language?: string;
111
- preheaderText?: string;
112
- bodyBackgroundColor?: string;
113
- bodyBackgroundImage?: string;
114
- bodyBackgroundSize?: string;
115
- bodyBackgroundPosition?: string;
116
- bodyBackgroundRepeat?: string;
117
- backgroundColor?: string;
118
- width?: number;
119
- padding?: Record<string, number>;
120
- mobileBreakpoint?: number;
121
- [key: string]: unknown;
122
- }
123
- export declare const optimizeCanvasForAI: (canvas: Canvas) => Partial<Canvas>;
124
- export declare const optimizeRowsForAI: (rows: Row[]) => Partial<Row>[];
125
- export {};