@maildeno/editor 0.4.3 → 0.4.4

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/dist/init.js CHANGED
@@ -1,156 +1,148 @@
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
- //#region src/lightDom.ts
4
- var stylesInjected = false;
5
- /**
6
- * The shadow path hands these strings to defineCustomElement, which turns
7
- * them into <style> tags inside the shadow root. Here they go to
8
- * document.head instead — same content, different destination. Guarded so
9
- * multiple editors on one page inject once.
10
- */
11
- function injectStylesIntoHead() {
12
- if (stylesInjected || typeof document === "undefined") return;
13
- stylesInjected = true;
14
- for (const css of buildShadowStyles()) {
15
- if (!css) continue;
16
- const style = document.createElement("style");
17
- style.setAttribute("data-maildeno-light-dom", "");
18
- style.textContent = css;
19
- document.head.appendChild(style);
20
- }
1
+ import { r as g, c as u, b as f, h as v, _ as S, a as h, d as E } from "./element-DyFj9kgl.js";
2
+ import { e as A, g as C, f as J, i as M, j, p as I, k as R, l as x, m as N, s as P } from "./element-DyFj9kgl.js";
3
+ let c = !1;
4
+ function p() {
5
+ if (!(c || typeof document > "u")) {
6
+ c = !0;
7
+ for (const e of f()) {
8
+ if (!e) continue;
9
+ const l = document.createElement("style");
10
+ l.setAttribute("data-maildeno-light-dom", ""), l.textContent = e, document.head.appendChild(l);
11
+ }
12
+ }
21
13
  }
22
- function mountLightDom(container, initialProps) {
23
- injectStylesIntoHead();
24
- const props = reactive({ ...initialProps });
25
- const saveHandlers = /* @__PURE__ */ new Set();
26
- const editorRef = ref(null);
27
- const mountEl = document.createElement("div");
28
- mountEl.style.height = "100%";
29
- container.appendChild(mountEl);
30
- const app = createApp({ setup() {
31
- return () => h(EmailEditor_default, {
32
- ...props,
33
- ref: editorRef,
34
- onSave: (payload) => saveHandlers.forEach((fn) => fn(payload))
35
- });
36
- } });
37
- app.mount(mountEl);
38
- return {
39
- element: mountEl,
40
- exposed: () => editorRef.value ?? null,
41
- setProp: (key, value) => {
42
- props[key] = value;
43
- },
44
- addSaveHandler: (fn) => saveHandlers.add(fn),
45
- removeSaveHandler: (fn) => saveHandlers.delete(fn),
46
- destroy: () => {
47
- app.unmount();
48
- mountEl.remove();
49
- }
50
- };
14
+ function y(e, l) {
15
+ p();
16
+ const a = g({ ...l }), i = /* @__PURE__ */ new Set(), d = h(null), n = document.createElement("div");
17
+ n.style.height = "100%", e.appendChild(n);
18
+ const r = u({
19
+ setup() {
20
+ return () => v(S, {
21
+ ...a,
22
+ ref: d,
23
+ onSave: (t) => i.forEach((s) => s(t))
24
+ });
25
+ }
26
+ });
27
+ return r.mount(n), {
28
+ element: n,
29
+ exposed: () => d.value ?? null,
30
+ setProp: (t, s) => {
31
+ a[t] = s;
32
+ },
33
+ addSaveHandler: (t) => i.add(t),
34
+ removeSaveHandler: (t) => i.delete(t),
35
+ destroy: () => {
36
+ r.unmount(), n.remove();
37
+ }
38
+ };
51
39
  }
52
- //#endregion
53
- //#region src/init.ts
54
- function toDomEventName(event) {
55
- return event;
40
+ async function H(e) {
41
+ const l = typeof e.container == "string" ? document.querySelector(e.container) : e.container;
42
+ if (!l)
43
+ throw new Error(
44
+ `[maildeno-editor] init() couldn't find a container${typeof e.container == "string" ? ` matching "${e.container}"` : ""}.`
45
+ );
46
+ if (e.shadowDom === !1) {
47
+ const n = y(l, {
48
+ templateId: e.templateId,
49
+ storageAdapter: e.storageAdapter,
50
+ theme: e.theme,
51
+ capabilities: e.capabilities,
52
+ onSendTestEmail: e.onSendTestEmail,
53
+ brandName: e.brandName,
54
+ versions: e.versions,
55
+ saveHandler: e.onSave,
56
+ assistant: e.assistant
57
+ });
58
+ await new Promise((t) => setTimeout(t, 0));
59
+ const r = (t, ...s) => {
60
+ var m;
61
+ const o = (m = n.exposed()) == null ? void 0 : m[t];
62
+ return typeof o == "function" ? o(...s) : null;
63
+ };
64
+ return {
65
+ element: n.element,
66
+ on: (t, s) => n.addSaveHandler(s),
67
+ off: (t, s) => n.removeSaveHandler(s),
68
+ setTheme: (t) => n.setProp("theme", t),
69
+ getHtml: (t = "prune") => r("getHtml", t),
70
+ getMjml: (t = "prune") => r("getMjml", t),
71
+ getReactEmail: (t = "prune") => r("getReactEmail", t),
72
+ getJson: () => r("getJson"),
73
+ setJson: (t, s) => {
74
+ r("setJson", t, s);
75
+ },
76
+ getSelection: () => r("getSelection"),
77
+ setSelection: (t) => r("setSelection", t) ?? !1,
78
+ // Falls back to a no-op unsubscribe rather than null so callers can
79
+ // always call the result — a host storing it and invoking it during
80
+ // teardown shouldn't have to null-check a cleanup function.
81
+ onChange: (t) => r("onChange", t) ?? (() => {
82
+ }),
83
+ destroy: () => n.destroy()
84
+ };
85
+ }
86
+ E();
87
+ const a = document.createElement("maildeno-editor");
88
+ e.templateId !== void 0 && (a.templateId = e.templateId), e.storageAdapter && (a.storageAdapter = e.storageAdapter), e.theme && (a.theme = e.theme), e.capabilities && (a.capabilities = e.capabilities), e.onSendTestEmail && (a.onSendTestEmail = e.onSendTestEmail), e.brandName !== void 0 && (a.brandName = e.brandName), e.versions !== void 0 && (a.versions = e.versions), e.assistant && (a.assistant = e.assistant), e.onSave && (a.saveHandler = e.onSave), l.appendChild(a), await new Promise((n) => setTimeout(n, 0));
89
+ const i = /* @__PURE__ */ new WeakMap();
90
+ return {
91
+ element: a,
92
+ on(n, r) {
93
+ const t = ((s) => r(
94
+ Array.isArray(s.detail) ? s.detail[0] : s.detail
95
+ ));
96
+ i.set(r, t), a.addEventListener(n, t);
97
+ },
98
+ off(n, r) {
99
+ const t = i.get(r);
100
+ t && (a.removeEventListener(n, t), i.delete(r));
101
+ },
102
+ setTheme(n) {
103
+ a.theme = n;
104
+ },
105
+ getHtml(n = "prune") {
106
+ return a.getHtml ? a.getHtml(n) : null;
107
+ },
108
+ getMjml(n = "prune") {
109
+ return a.getMjml ? a.getMjml(n) : null;
110
+ },
111
+ getReactEmail(n = "prune") {
112
+ return a.getReactEmail ? a.getReactEmail(n) : null;
113
+ },
114
+ getJson() {
115
+ return a.getJson ? a.getJson() : null;
116
+ },
117
+ setJson(n, r) {
118
+ var t;
119
+ (t = a.setJson) == null || t.call(a, n, r);
120
+ },
121
+ getSelection() {
122
+ return a.getSelection ? a.getSelection() : null;
123
+ },
124
+ setSelection(n) {
125
+ return a.setSelection ? a.setSelection(n) : !1;
126
+ },
127
+ onChange(n) {
128
+ return a.onChange ? a.onChange(n) : () => {
129
+ };
130
+ },
131
+ destroy() {
132
+ a.remove();
133
+ }
134
+ };
56
135
  }
57
- async function init(options) {
58
- const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
59
- if (!container) throw new Error(`[maildeno-editor] init() couldn't find a container${typeof options.container === "string" ? ` matching "${options.container}"` : ""}.`);
60
- if (options.shadowDom === false) {
61
- const mount = mountLightDom(container, {
62
- templateId: options.templateId,
63
- storageAdapter: options.storageAdapter,
64
- theme: options.theme,
65
- capabilities: options.capabilities,
66
- onSendTestEmail: options.onSendTestEmail,
67
- brandName: options.brandName,
68
- versions: options.versions,
69
- saveHandler: options.onSave,
70
- assistant: options.assistant
71
- });
72
- await new Promise((resolve) => setTimeout(resolve, 0));
73
- const call = (name, ...args) => {
74
- const fn = mount.exposed()?.[name];
75
- return typeof fn === "function" ? fn(...args) : null;
76
- };
77
- return {
78
- element: mount.element,
79
- on: (_event, handler) => mount.addSaveHandler(handler),
80
- off: (_event, handler) => mount.removeSaveHandler(handler),
81
- setTheme: (theme) => mount.setProp("theme", theme),
82
- getHtml: (mode = "prune") => call("getHtml", mode),
83
- getMjml: (mode = "prune") => call("getMjml", mode),
84
- getReactEmail: (mode = "prune") => call("getReactEmail", mode),
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) ?? (() => {}),
92
- destroy: () => mount.destroy()
93
- };
94
- }
95
- registerMaildenoEditorElement();
96
- const el = document.createElement("maildeno-editor");
97
- if (options.templateId !== void 0) el.templateId = options.templateId;
98
- if (options.storageAdapter) el.storageAdapter = options.storageAdapter;
99
- if (options.theme) el.theme = options.theme;
100
- if (options.capabilities) el.capabilities = options.capabilities;
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;
106
- container.appendChild(el);
107
- await new Promise((resolve) => setTimeout(resolve, 0));
108
- const listenerWrappers = /* @__PURE__ */ new WeakMap();
109
- return {
110
- element: el,
111
- on(event, handler) {
112
- const wrapped = ((e) => handler(Array.isArray(e.detail) ? e.detail[0] : e.detail));
113
- listenerWrappers.set(handler, wrapped);
114
- el.addEventListener(toDomEventName(event), wrapped);
115
- },
116
- off(event, handler) {
117
- const wrapped = listenerWrappers.get(handler);
118
- if (wrapped) {
119
- el.removeEventListener(toDomEventName(event), wrapped);
120
- listenerWrappers.delete(handler);
121
- }
122
- },
123
- setTheme(theme) {
124
- el.theme = theme;
125
- },
126
- getHtml(mode = "prune") {
127
- return el.getHtml ? el.getHtml(mode) : null;
128
- },
129
- getMjml(mode = "prune") {
130
- return el.getMjml ? el.getMjml(mode) : null;
131
- },
132
- getReactEmail(mode = "prune") {
133
- return el.getReactEmail ? el.getReactEmail(mode) : null;
134
- },
135
- getJson() {
136
- return el.getJson ? el.getJson() : null;
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
- },
150
- destroy() {
151
- el.remove();
152
- }
153
- };
154
- }
155
- //#endregion
156
- export { createLocalStorageAdapter, getAllBlocks, getBlock, getRegisteredCustomESPs, getRegisteredMergeTagIds, init, palette, registerBlock, registerESPSyntax, registerMergeTags, setEditorTheme };
136
+ export {
137
+ A as createLocalStorageAdapter,
138
+ C as getAllBlocks,
139
+ J as getBlock,
140
+ M as getRegisteredCustomESPs,
141
+ j as getRegisteredMergeTagIds,
142
+ H as init,
143
+ I as palette,
144
+ R as registerBlock,
145
+ x as registerESPSyntax,
146
+ N as registerMergeTags,
147
+ P as setEditorTheme
148
+ };