@maildeno/editor 0.4.3 → 0.4.5

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,136 @@
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 { O as o, at as c, i as u, st as g } from "./vue.runtime.esm-bundler-CsdyQceJ.js";
2
+ import { a as H, c as b, d as w, f as T, h as A, i as C, l as J, m as M, n as f, p as I, r as v, s as S, u as R } from "./element-Dq6bmt2l.js";
3
+ var m = !1;
4
+ function h() {
5
+ if (!(m || typeof document > "u")) {
6
+ m = !0;
7
+ for (const e of S()) {
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 E(e, l) {
15
+ h();
16
+ const t = c({ ...l }), i = /* @__PURE__ */ new Set(), a = g(null), r = document.createElement("div");
17
+ r.style.height = "100%", e.appendChild(r);
18
+ const n = u({ setup() {
19
+ return () => o(v, {
20
+ ...t,
21
+ ref: a,
22
+ onSave: (s) => i.forEach((d) => d(s))
23
+ });
24
+ } });
25
+ return n.mount(r), {
26
+ element: r,
27
+ exposed: () => a.value ?? null,
28
+ setProp: (s, d) => {
29
+ t[s] = d;
30
+ },
31
+ addSaveHandler: (s) => i.add(s),
32
+ removeSaveHandler: (s) => i.delete(s),
33
+ destroy: () => {
34
+ n.unmount(), r.remove();
35
+ }
36
+ };
51
37
  }
52
- //#endregion
53
- //#region src/init.ts
54
- function toDomEventName(event) {
55
- return event;
38
+ async function j(e) {
39
+ const l = typeof e.container == "string" ? document.querySelector(e.container) : e.container;
40
+ if (!l) throw new Error(`[maildeno-editor] init() couldn't find a container${typeof e.container == "string" ? ` matching "${e.container}"` : ""}.`);
41
+ if (e.shadowDom === !1) {
42
+ const a = E(l, {
43
+ templateId: e.templateId,
44
+ storageAdapter: e.storageAdapter,
45
+ theme: e.theme,
46
+ capabilities: e.capabilities,
47
+ onSendTestEmail: e.onSendTestEmail,
48
+ brandName: e.brandName,
49
+ versions: e.versions,
50
+ saveHandler: e.onSave,
51
+ assistant: e.assistant
52
+ });
53
+ await new Promise((n) => setTimeout(n, 0));
54
+ const r = (n, ...s) => {
55
+ const d = a.exposed()?.[n];
56
+ return typeof d == "function" ? d(...s) : null;
57
+ };
58
+ return {
59
+ element: a.element,
60
+ on: (n, s) => a.addSaveHandler(s),
61
+ off: (n, s) => a.removeSaveHandler(s),
62
+ setTheme: (n) => a.setProp("theme", n),
63
+ getHtml: (n = "prune") => r("getHtml", n),
64
+ getMjml: (n = "prune") => r("getMjml", n),
65
+ getReactEmail: (n = "prune") => r("getReactEmail", n),
66
+ getJson: () => r("getJson"),
67
+ setJson: (n, s) => {
68
+ r("setJson", n, s);
69
+ },
70
+ getSelection: () => r("getSelection"),
71
+ setSelection: (n) => r("setSelection", n) ?? !1,
72
+ onChange: (n) => r("onChange", n) ?? (() => {
73
+ }),
74
+ destroy: () => a.destroy()
75
+ };
76
+ }
77
+ f();
78
+ const t = document.createElement("maildeno-editor");
79
+ e.templateId !== void 0 && (t.templateId = e.templateId), e.storageAdapter && (t.storageAdapter = e.storageAdapter), e.theme && (t.theme = e.theme), e.capabilities && (t.capabilities = e.capabilities), e.onSendTestEmail && (t.onSendTestEmail = e.onSendTestEmail), e.brandName !== void 0 && (t.brandName = e.brandName), e.versions !== void 0 && (t.versions = e.versions), e.assistant && (t.assistant = e.assistant), e.onSave && (t.saveHandler = e.onSave), l.appendChild(t), await new Promise((a) => setTimeout(a, 0));
80
+ const i = /* @__PURE__ */ new WeakMap();
81
+ return {
82
+ element: t,
83
+ on(a, r) {
84
+ const n = ((s) => r(Array.isArray(s.detail) ? s.detail[0] : s.detail));
85
+ i.set(r, n), t.addEventListener(a, n);
86
+ },
87
+ off(a, r) {
88
+ const n = i.get(r);
89
+ n && (t.removeEventListener(a, n), i.delete(r));
90
+ },
91
+ setTheme(a) {
92
+ t.theme = a;
93
+ },
94
+ getHtml(a = "prune") {
95
+ return t.getHtml ? t.getHtml(a) : null;
96
+ },
97
+ getMjml(a = "prune") {
98
+ return t.getMjml ? t.getMjml(a) : null;
99
+ },
100
+ getReactEmail(a = "prune") {
101
+ return t.getReactEmail ? t.getReactEmail(a) : null;
102
+ },
103
+ getJson() {
104
+ return t.getJson ? t.getJson() : null;
105
+ },
106
+ setJson(a, r) {
107
+ t.setJson?.(a, r);
108
+ },
109
+ getSelection() {
110
+ return t.getSelection ? t.getSelection() : null;
111
+ },
112
+ setSelection(a) {
113
+ return t.setSelection ? t.setSelection(a) : !1;
114
+ },
115
+ onChange(a) {
116
+ return t.onChange ? t.onChange(a) : () => {
117
+ };
118
+ },
119
+ destroy() {
120
+ t.remove();
121
+ }
122
+ };
56
123
  }
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 };
124
+ export {
125
+ A as createLocalStorageAdapter,
126
+ T as getAllBlocks,
127
+ I as getBlock,
128
+ b as getRegisteredCustomESPs,
129
+ R as getRegisteredMergeTagIds,
130
+ j as init,
131
+ C as palette,
132
+ M as registerBlock,
133
+ J as registerESPSyntax,
134
+ w as registerMergeTags,
135
+ H as setEditorTheme
136
+ };