@savvycal/mjml-editor 0.0.1 → 0.0.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.
- package/README.md +191 -0
- package/dist/components/editor/BlockIcon.d.ts +7 -0
- package/dist/components/editor/BlockIcon.d.ts.map +1 -0
- package/dist/components/editor/BlockInspector.d.ts +6 -0
- package/dist/components/editor/BlockInspector.d.ts.map +1 -0
- package/dist/components/editor/BlockInspector.js +380 -0
- package/dist/components/editor/EditorCanvas.d.ts +11 -0
- package/dist/components/editor/EditorCanvas.d.ts.map +1 -0
- package/dist/components/editor/EditorCanvas.js +116 -0
- package/dist/components/editor/FontEditor.d.ts +2 -0
- package/dist/components/editor/FontEditor.d.ts.map +1 -0
- package/dist/components/editor/FontEditor.js +227 -0
- package/dist/components/editor/GlobalStylesPanel.d.ts +7 -0
- package/dist/components/editor/GlobalStylesPanel.d.ts.map +1 -0
- package/dist/components/editor/GlobalStylesPanel.js +310 -0
- package/dist/components/editor/InteractivePreview.d.ts +8 -0
- package/dist/components/editor/InteractivePreview.d.ts.map +1 -0
- package/dist/components/editor/InteractivePreview.js +130 -0
- package/dist/components/editor/LiquidAutocomplete.d.ts +10 -0
- package/dist/components/editor/LiquidAutocomplete.d.ts.map +1 -0
- package/dist/components/editor/LiquidAutocomplete.js +70 -0
- package/dist/components/editor/LiquidInput.d.ts +12 -0
- package/dist/components/editor/LiquidInput.d.ts.map +1 -0
- package/dist/components/editor/LiquidInput.js +185 -0
- package/dist/components/editor/MjmlEditor.d.ts +22 -0
- package/dist/components/editor/MjmlEditor.d.ts.map +1 -0
- package/dist/components/editor/MjmlEditor.js +137 -0
- package/dist/components/editor/OutlineTree.d.ts +7 -0
- package/dist/components/editor/OutlineTree.d.ts.map +1 -0
- package/dist/components/editor/OutlineTree.js +282 -0
- package/dist/components/editor/SourceEditor.d.ts +2 -0
- package/dist/components/editor/SourceEditor.d.ts.map +1 -0
- package/dist/components/editor/SourceEditor.js +70 -0
- package/dist/components/editor/SourcePreview.d.ts +7 -0
- package/dist/components/editor/SourcePreview.d.ts.map +1 -0
- package/dist/components/editor/SourcePreview.js +69 -0
- package/dist/components/editor/TiptapEditor.d.ts +12 -0
- package/dist/components/editor/TiptapEditor.d.ts.map +1 -0
- package/dist/components/editor/TiptapEditor.js +330 -0
- package/dist/components/editor/VisualEditor.d.ts +7 -0
- package/dist/components/editor/VisualEditor.d.ts.map +1 -0
- package/dist/components/editor/VisualEditor.js +51 -0
- package/dist/components/editor/visual-blocks/VisualBlock.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualBlock.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualBlock.js +34 -0
- package/dist/components/editor/visual-blocks/VisualButton.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualButton.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualButton.js +111 -0
- package/dist/components/editor/visual-blocks/VisualColumn.d.ts +8 -0
- package/dist/components/editor/visual-blocks/VisualColumn.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualColumn.js +44 -0
- package/dist/components/editor/visual-blocks/VisualDivider.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualDivider.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualDivider.js +41 -0
- package/dist/components/editor/visual-blocks/VisualImage.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualImage.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualImage.js +48 -0
- package/dist/components/editor/visual-blocks/VisualRaw.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualRaw.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualRaw.js +32 -0
- package/dist/components/editor/visual-blocks/VisualSection.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualSection.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualSection.js +131 -0
- package/dist/components/editor/visual-blocks/VisualSocial.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualSocial.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualSocial.js +62 -0
- package/dist/components/editor/visual-blocks/VisualSpacer.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualSpacer.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualSpacer.js +30 -0
- package/dist/components/editor/visual-blocks/VisualText.d.ts +7 -0
- package/dist/components/editor/visual-blocks/VisualText.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/VisualText.js +103 -0
- package/dist/components/editor/visual-blocks/helpers.d.ts +13 -0
- package/dist/components/editor/visual-blocks/helpers.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/helpers.js +44 -0
- package/dist/components/editor/visual-blocks/useResolvedAttributes.d.ts +7 -0
- package/dist/components/editor/visual-blocks/useResolvedAttributes.d.ts.map +1 -0
- package/dist/components/editor/visual-blocks/useResolvedAttributes.js +12 -0
- package/dist/components/ui/badge.d.ts +10 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/badge.js +26 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +54 -0
- package/dist/components/ui/card.d.ts +10 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/collapsible.js +7 -0
- package/dist/components/ui/floating-panel.d.ts +12 -0
- package/dist/components/ui/floating-panel.d.ts.map +1 -0
- package/dist/components/ui/floating-panel.js +54 -0
- package/dist/components/ui/input.d.ts +4 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +26 -0
- package/dist/components/ui/label.d.ts +5 -0
- package/dist/components/ui/label.d.ts.map +1 -0
- package/dist/components/ui/label.js +23 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/popover.js +39 -0
- package/dist/components/ui/resizable-split-pane.d.ts +10 -0
- package/dist/components/ui/resizable-split-pane.d.ts.map +1 -0
- package/dist/components/ui/resizable-split-pane.js +65 -0
- package/dist/components/ui/scroll-area.d.ts +10 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.js +69 -0
- package/dist/components/ui/select.d.ts +16 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +145 -0
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/tabs.d.ts +8 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/tabs.js +68 -0
- package/dist/components/ui/theme-toggle.d.ts +2 -0
- package/dist/components/ui/theme-toggle.d.ts.map +1 -0
- package/dist/components/ui/theme-toggle.js +58 -0
- package/dist/components.css +365 -0
- package/dist/context/EditorContext.d.ts +40 -0
- package/dist/context/EditorContext.d.ts.map +1 -0
- package/dist/context/EditorContext.js +576 -0
- package/dist/context/LiquidSchemaContext.d.ts +10 -0
- package/dist/context/LiquidSchemaContext.d.ts.map +1 -0
- package/dist/context/LiquidSchemaContext.js +16 -0
- package/dist/context/ThemeContext.d.ts +29 -0
- package/dist/context/ThemeContext.d.ts.map +1 -0
- package/dist/context/ThemeContext.js +55 -0
- package/dist/extensions/LiquidHighlight.d.ts +3 -0
- package/dist/extensions/LiquidHighlight.d.ts.map +1 -0
- package/dist/extensions/LiquidHighlight.js +58 -0
- package/dist/extensions/LiquidSuggestion.d.ts +18 -0
- package/dist/extensions/LiquidSuggestion.d.ts.map +1 -0
- package/dist/extensions/LiquidSuggestion.js +119 -0
- package/dist/hooks/useFontLoader.d.ts +6 -0
- package/dist/hooks/useFontLoader.d.ts.map +1 -0
- package/dist/hooks/useFontLoader.js +21 -0
- package/dist/hooks/useStyleLoader.d.ts +11 -0
- package/dist/hooks/useStyleLoader.d.ts.map +1 -0
- package/dist/hooks/useStyleLoader.js +26 -0
- package/dist/index.d.ts +6 -150
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -57452
- package/dist/lib/html-utils.d.ts +23 -0
- package/dist/lib/html-utils.d.ts.map +1 -0
- package/dist/lib/html-utils.js +25 -0
- package/dist/lib/mjml/attributes.d.ts +100 -0
- package/dist/lib/mjml/attributes.d.ts.map +1 -0
- package/dist/lib/mjml/attributes.js +105 -0
- package/dist/lib/mjml/parser.d.ts +67 -0
- package/dist/lib/mjml/parser.d.ts.map +1 -0
- package/dist/lib/mjml/parser.js +184 -0
- package/dist/lib/mjml/parser.test.d.ts +2 -0
- package/dist/lib/mjml/parser.test.d.ts.map +1 -0
- package/dist/lib/mjml/renderer.d.ts +23 -0
- package/dist/lib/mjml/renderer.d.ts.map +1 -0
- package/dist/lib/mjml/renderer.js +75 -0
- package/dist/lib/mjml/schema.d.ts +21 -0
- package/dist/lib/mjml/schema.d.ts.map +1 -0
- package/dist/lib/mjml/schema.js +1307 -0
- package/dist/lib/mjml/scopeCSS.d.ts +21 -0
- package/dist/lib/mjml/scopeCSS.d.ts.map +1 -0
- package/dist/lib/mjml/scopeCSS.js +67 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +8 -0
- package/dist/preset.css +150 -0
- package/dist/types/liquid.d.ts +28 -0
- package/dist/types/liquid.d.ts.map +1 -0
- package/dist/types/mjml.d.ts +101 -0
- package/dist/types/mjml.d.ts.map +1 -0
- package/package.json +14 -10
- package/dist/styles.css +0 -1
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { jsx as J } from "react/jsx-runtime";
|
|
2
|
+
import { useReducer as W, useCallback as h, useMemo as D, createContext as $, useContext as q } from "react";
|
|
3
|
+
import { v4 as N } from "uuid";
|
|
4
|
+
import { cloneNode as m, addIds as j, findNodeById as U, moveNode as z, deleteNode as G, insertNode as Q, updateNode as F } from "../lib/mjml/parser.js";
|
|
5
|
+
import { getDefaultBlock as X, getSchemaForTag as Y } from "../lib/mjml/schema.js";
|
|
6
|
+
import { extractMjmlAttributes as Z, getDefinedClasses as ee, resolveNodeAttributes as te, getInheritedValue as ne, extractFonts as oe } from "../lib/mjml/attributes.js";
|
|
7
|
+
function de(e) {
|
|
8
|
+
let d = e.children?.find((o) => o.tagName === "mj-head"), t = !1;
|
|
9
|
+
d || (d = {
|
|
10
|
+
tagName: "mj-head",
|
|
11
|
+
attributes: {},
|
|
12
|
+
children: [],
|
|
13
|
+
_id: N()
|
|
14
|
+
}, t = !0);
|
|
15
|
+
let n = d.children?.find((o) => o.tagName === "mj-attributes");
|
|
16
|
+
if (n || (n = {
|
|
17
|
+
tagName: "mj-attributes",
|
|
18
|
+
attributes: {},
|
|
19
|
+
children: [],
|
|
20
|
+
_id: N()
|
|
21
|
+
}, d = {
|
|
22
|
+
...d,
|
|
23
|
+
children: [...d.children || [], n]
|
|
24
|
+
}, t = !0), !t)
|
|
25
|
+
return e;
|
|
26
|
+
const r = e.children?.filter((o) => o.tagName !== "mj-head") || [];
|
|
27
|
+
return {
|
|
28
|
+
...e,
|
|
29
|
+
children: [d, ...r]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function v(e, d, t, n) {
|
|
33
|
+
const r = de(e), o = r.children?.find((s) => s.tagName === "mj-head");
|
|
34
|
+
if (!o) return e;
|
|
35
|
+
const l = o.children?.find(
|
|
36
|
+
(s) => s.tagName === "mj-attributes"
|
|
37
|
+
);
|
|
38
|
+
if (!l) return e;
|
|
39
|
+
const i = [...l.children || []];
|
|
40
|
+
if (d === "all") {
|
|
41
|
+
const s = i.findIndex((I) => I.tagName === "mj-all"), f = {
|
|
42
|
+
tagName: "mj-all",
|
|
43
|
+
attributes: s >= 0 ? { ...i[s].attributes, ...n } : n,
|
|
44
|
+
_id: s >= 0 ? i[s]._id : N()
|
|
45
|
+
};
|
|
46
|
+
s >= 0 ? i[s] = f : i.unshift(f);
|
|
47
|
+
} else if (d === "element" && t) {
|
|
48
|
+
const s = i.findIndex((I) => I.tagName === t), f = {
|
|
49
|
+
tagName: t,
|
|
50
|
+
attributes: s >= 0 ? { ...i[s].attributes, ...n } : n,
|
|
51
|
+
_id: s >= 0 ? i[s]._id : N()
|
|
52
|
+
};
|
|
53
|
+
s >= 0 ? i[s] = f : i.push(f);
|
|
54
|
+
} else if (d === "class" && t) {
|
|
55
|
+
const s = i.findIndex(
|
|
56
|
+
(I) => I.tagName === "mj-class" && I.attributes.name === t
|
|
57
|
+
), f = {
|
|
58
|
+
tagName: "mj-class",
|
|
59
|
+
attributes: s >= 0 ? {
|
|
60
|
+
...i[s].attributes,
|
|
61
|
+
name: t,
|
|
62
|
+
...n
|
|
63
|
+
} : { name: t, ...n },
|
|
64
|
+
_id: s >= 0 ? i[s]._id : N()
|
|
65
|
+
};
|
|
66
|
+
s >= 0 ? i[s] = f : i.push(f);
|
|
67
|
+
}
|
|
68
|
+
const a = {
|
|
69
|
+
...l,
|
|
70
|
+
children: i
|
|
71
|
+
}, y = {
|
|
72
|
+
...o,
|
|
73
|
+
children: o.children?.map(
|
|
74
|
+
(s) => s.tagName === "mj-attributes" ? a : s
|
|
75
|
+
)
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
...r,
|
|
79
|
+
children: r.children?.map(
|
|
80
|
+
(s) => s.tagName === "mj-head" ? y : s
|
|
81
|
+
)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function re(e, d) {
|
|
85
|
+
return v(e, "class", d, {});
|
|
86
|
+
}
|
|
87
|
+
function ie(e, d) {
|
|
88
|
+
const t = e.children?.find((i) => i.tagName === "mj-head");
|
|
89
|
+
if (!t) return e;
|
|
90
|
+
const n = t.children?.find(
|
|
91
|
+
(i) => i.tagName === "mj-attributes"
|
|
92
|
+
);
|
|
93
|
+
if (!n) return e;
|
|
94
|
+
const r = n.children?.filter(
|
|
95
|
+
(i) => !(i.tagName === "mj-class" && i.attributes.name === d)
|
|
96
|
+
) || [], o = {
|
|
97
|
+
...n,
|
|
98
|
+
children: r
|
|
99
|
+
}, l = {
|
|
100
|
+
...t,
|
|
101
|
+
children: t.children?.map(
|
|
102
|
+
(i) => i.tagName === "mj-attributes" ? o : i
|
|
103
|
+
)
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
...e,
|
|
107
|
+
children: e.children?.map(
|
|
108
|
+
(i) => i.tagName === "mj-head" ? l : i
|
|
109
|
+
)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function ce(e, d, t) {
|
|
113
|
+
const n = e.children?.find((a) => a.tagName === "mj-head");
|
|
114
|
+
if (!n) return e;
|
|
115
|
+
const r = n.children?.find(
|
|
116
|
+
(a) => a.tagName === "mj-attributes"
|
|
117
|
+
);
|
|
118
|
+
if (!r) return e;
|
|
119
|
+
const o = r.children?.map((a) => a.tagName === "mj-class" && a.attributes.name === d ? {
|
|
120
|
+
...a,
|
|
121
|
+
attributes: { ...a.attributes, name: t }
|
|
122
|
+
} : a) || [], l = {
|
|
123
|
+
...r,
|
|
124
|
+
children: o
|
|
125
|
+
}, i = {
|
|
126
|
+
...n,
|
|
127
|
+
children: n.children?.map(
|
|
128
|
+
(a) => a.tagName === "mj-attributes" ? l : a
|
|
129
|
+
)
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
...e,
|
|
133
|
+
children: e.children?.map(
|
|
134
|
+
(a) => a.tagName === "mj-head" ? i : a
|
|
135
|
+
)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function se(e) {
|
|
139
|
+
let d = e.children?.find((t) => t.tagName === "mj-head");
|
|
140
|
+
if (!d) {
|
|
141
|
+
d = {
|
|
142
|
+
tagName: "mj-head",
|
|
143
|
+
attributes: {},
|
|
144
|
+
children: [],
|
|
145
|
+
_id: N()
|
|
146
|
+
};
|
|
147
|
+
const t = e.children?.filter((n) => n.tagName !== "mj-head") || [];
|
|
148
|
+
return {
|
|
149
|
+
...e,
|
|
150
|
+
children: [d, ...t]
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return e;
|
|
154
|
+
}
|
|
155
|
+
function R(e, d, t) {
|
|
156
|
+
const n = se(e), r = n.children?.find((y) => y.tagName === "mj-head");
|
|
157
|
+
if (!r) return e;
|
|
158
|
+
const o = r.children?.findIndex(
|
|
159
|
+
(y) => y.tagName === "mj-font" && y.attributes.name === d
|
|
160
|
+
) ?? -1, l = {
|
|
161
|
+
tagName: "mj-font",
|
|
162
|
+
attributes: { name: d, href: t },
|
|
163
|
+
_id: o >= 0 ? r.children[o]._id : N()
|
|
164
|
+
};
|
|
165
|
+
let i;
|
|
166
|
+
o >= 0 ? (i = [...r.children], i[o] = l) : i = [l, ...r.children || []];
|
|
167
|
+
const a = { ...r, children: i };
|
|
168
|
+
return {
|
|
169
|
+
...n,
|
|
170
|
+
children: n.children?.map(
|
|
171
|
+
(y) => y.tagName === "mj-head" ? a : y
|
|
172
|
+
)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function le(e, d) {
|
|
176
|
+
const t = e.children?.find((o) => o.tagName === "mj-head");
|
|
177
|
+
if (!t?.children) return e;
|
|
178
|
+
const n = t.children.filter(
|
|
179
|
+
(o) => !(o.tagName === "mj-font" && o.attributes.name === d)
|
|
180
|
+
), r = { ...t, children: n };
|
|
181
|
+
return {
|
|
182
|
+
...e,
|
|
183
|
+
children: e.children?.map(
|
|
184
|
+
(o) => o.tagName === "mj-head" ? r : o
|
|
185
|
+
)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function ae(e, d) {
|
|
189
|
+
switch (d.type) {
|
|
190
|
+
case "SELECT_BLOCK":
|
|
191
|
+
return { ...e, selectedBlockId: d.payload };
|
|
192
|
+
case "UPDATE_ATTRIBUTES": {
|
|
193
|
+
const { id: t, attributes: n } = d.payload, r = F(e.document, t, (l) => ({
|
|
194
|
+
...l,
|
|
195
|
+
attributes: { ...l.attributes, ...n }
|
|
196
|
+
})), o = [
|
|
197
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
198
|
+
m(r)
|
|
199
|
+
].slice(-50);
|
|
200
|
+
return {
|
|
201
|
+
...e,
|
|
202
|
+
document: r,
|
|
203
|
+
history: o,
|
|
204
|
+
historyIndex: o.length - 1
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
case "UPDATE_CONTENT": {
|
|
208
|
+
const { id: t, content: n } = d.payload, r = F(e.document, t, (l) => ({
|
|
209
|
+
...l,
|
|
210
|
+
content: n
|
|
211
|
+
})), o = [
|
|
212
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
213
|
+
m(r)
|
|
214
|
+
].slice(-50);
|
|
215
|
+
return {
|
|
216
|
+
...e,
|
|
217
|
+
document: r,
|
|
218
|
+
history: o,
|
|
219
|
+
historyIndex: o.length - 1
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
case "ADD_BLOCK": {
|
|
223
|
+
const { parentId: t, index: n, block: r } = d.payload, o = Q(e.document, t, n, r), l = [
|
|
224
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
225
|
+
m(o)
|
|
226
|
+
].slice(-50);
|
|
227
|
+
return {
|
|
228
|
+
...e,
|
|
229
|
+
document: o,
|
|
230
|
+
selectedBlockId: r._id || null,
|
|
231
|
+
history: l,
|
|
232
|
+
historyIndex: l.length - 1
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
case "DELETE_BLOCK": {
|
|
236
|
+
const t = G(e.document, d.payload), n = [
|
|
237
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
238
|
+
m(t)
|
|
239
|
+
].slice(-50);
|
|
240
|
+
return {
|
|
241
|
+
...e,
|
|
242
|
+
document: t,
|
|
243
|
+
selectedBlockId: e.selectedBlockId === d.payload ? null : e.selectedBlockId,
|
|
244
|
+
history: n,
|
|
245
|
+
historyIndex: n.length - 1
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
case "MOVE_BLOCK": {
|
|
249
|
+
const { id: t, newParentId: n, newIndex: r } = d.payload, o = z(e.document, t, n, r), l = [
|
|
250
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
251
|
+
m(o)
|
|
252
|
+
].slice(-50);
|
|
253
|
+
return {
|
|
254
|
+
...e,
|
|
255
|
+
document: o,
|
|
256
|
+
history: l,
|
|
257
|
+
historyIndex: l.length - 1
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
case "SET_DOCUMENT": {
|
|
261
|
+
const t = j(d.payload);
|
|
262
|
+
return {
|
|
263
|
+
...e,
|
|
264
|
+
document: t,
|
|
265
|
+
selectedBlockId: null,
|
|
266
|
+
history: [m(t)],
|
|
267
|
+
historyIndex: 0
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
case "UNDO": {
|
|
271
|
+
if (e.historyIndex <= 0) return e;
|
|
272
|
+
const t = e.historyIndex - 1;
|
|
273
|
+
return {
|
|
274
|
+
...e,
|
|
275
|
+
document: m(e.history[t]),
|
|
276
|
+
historyIndex: t
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
case "REDO": {
|
|
280
|
+
if (e.historyIndex >= e.history.length - 1) return e;
|
|
281
|
+
const t = e.historyIndex + 1;
|
|
282
|
+
return {
|
|
283
|
+
...e,
|
|
284
|
+
document: m(e.history[t]),
|
|
285
|
+
historyIndex: t
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
case "UPDATE_MJML_ATTRIBUTE": {
|
|
289
|
+
const { attributeType: t, target: n, attributes: r } = d.payload, o = v(
|
|
290
|
+
e.document,
|
|
291
|
+
t,
|
|
292
|
+
n,
|
|
293
|
+
r
|
|
294
|
+
), l = [
|
|
295
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
296
|
+
m(o)
|
|
297
|
+
].slice(-50);
|
|
298
|
+
return {
|
|
299
|
+
...e,
|
|
300
|
+
document: o,
|
|
301
|
+
history: l,
|
|
302
|
+
historyIndex: l.length - 1
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
case "ADD_CLASS": {
|
|
306
|
+
const t = re(e.document, d.payload), n = [
|
|
307
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
308
|
+
m(t)
|
|
309
|
+
].slice(-50);
|
|
310
|
+
return {
|
|
311
|
+
...e,
|
|
312
|
+
document: t,
|
|
313
|
+
history: n,
|
|
314
|
+
historyIndex: n.length - 1
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
case "REMOVE_CLASS": {
|
|
318
|
+
const t = ie(
|
|
319
|
+
e.document,
|
|
320
|
+
d.payload
|
|
321
|
+
), n = [
|
|
322
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
323
|
+
m(t)
|
|
324
|
+
].slice(-50);
|
|
325
|
+
return {
|
|
326
|
+
...e,
|
|
327
|
+
document: t,
|
|
328
|
+
history: n,
|
|
329
|
+
historyIndex: n.length - 1
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
case "RENAME_CLASS": {
|
|
333
|
+
const { oldName: t, newName: n } = d.payload, r = ce(
|
|
334
|
+
e.document,
|
|
335
|
+
t,
|
|
336
|
+
n
|
|
337
|
+
), o = [
|
|
338
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
339
|
+
m(r)
|
|
340
|
+
].slice(-50);
|
|
341
|
+
return {
|
|
342
|
+
...e,
|
|
343
|
+
document: r,
|
|
344
|
+
history: o,
|
|
345
|
+
historyIndex: o.length - 1
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
case "ADD_FONT": {
|
|
349
|
+
const { name: t, href: n } = d.payload, r = R(e.document, t, n), o = [
|
|
350
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
351
|
+
m(r)
|
|
352
|
+
].slice(-50);
|
|
353
|
+
return {
|
|
354
|
+
...e,
|
|
355
|
+
document: r,
|
|
356
|
+
history: o,
|
|
357
|
+
historyIndex: o.length - 1
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
case "REMOVE_FONT": {
|
|
361
|
+
const t = le(
|
|
362
|
+
e.document,
|
|
363
|
+
d.payload
|
|
364
|
+
), n = [
|
|
365
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
366
|
+
m(t)
|
|
367
|
+
].slice(-50);
|
|
368
|
+
return {
|
|
369
|
+
...e,
|
|
370
|
+
document: t,
|
|
371
|
+
history: n,
|
|
372
|
+
historyIndex: n.length - 1
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
case "UPDATE_FONT": {
|
|
376
|
+
const { name: t, href: n } = d.payload, r = R(e.document, t, n), o = [
|
|
377
|
+
...e.history.slice(0, e.historyIndex + 1),
|
|
378
|
+
m(r)
|
|
379
|
+
].slice(-50);
|
|
380
|
+
return {
|
|
381
|
+
...e,
|
|
382
|
+
document: r,
|
|
383
|
+
history: o,
|
|
384
|
+
historyIndex: o.length - 1
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
default:
|
|
388
|
+
return e;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const P = $(null);
|
|
392
|
+
function Ne({
|
|
393
|
+
children: e,
|
|
394
|
+
initialDocument: d
|
|
395
|
+
}) {
|
|
396
|
+
const [t, n] = W(ae, {
|
|
397
|
+
document: j(d),
|
|
398
|
+
selectedBlockId: null,
|
|
399
|
+
history: [m(j(d))],
|
|
400
|
+
historyIndex: 0
|
|
401
|
+
}), r = h((c) => {
|
|
402
|
+
n({ type: "SELECT_BLOCK", payload: c });
|
|
403
|
+
}, []), o = h(
|
|
404
|
+
(c, u) => {
|
|
405
|
+
n({ type: "UPDATE_ATTRIBUTES", payload: { id: c, attributes: u } });
|
|
406
|
+
},
|
|
407
|
+
[]
|
|
408
|
+
), l = h((c, u) => {
|
|
409
|
+
n({ type: "UPDATE_CONTENT", payload: { id: c, content: u } });
|
|
410
|
+
}, []), i = h(
|
|
411
|
+
(c, u, p) => {
|
|
412
|
+
const x = X(p), V = {
|
|
413
|
+
tagName: p,
|
|
414
|
+
attributes: x.attributes,
|
|
415
|
+
content: x.content,
|
|
416
|
+
_id: N()
|
|
417
|
+
};
|
|
418
|
+
n({ type: "ADD_BLOCK", payload: { parentId: c, index: u, block: V } });
|
|
419
|
+
},
|
|
420
|
+
[]
|
|
421
|
+
), a = h(() => {
|
|
422
|
+
const c = t.document.children?.find((x) => x.tagName === "mj-body");
|
|
423
|
+
if (!c?._id) return;
|
|
424
|
+
const u = {
|
|
425
|
+
tagName: "mj-section",
|
|
426
|
+
attributes: {},
|
|
427
|
+
_id: N(),
|
|
428
|
+
children: [
|
|
429
|
+
{
|
|
430
|
+
tagName: "mj-column",
|
|
431
|
+
attributes: {},
|
|
432
|
+
_id: N(),
|
|
433
|
+
children: []
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
}, p = c.children?.length || 0;
|
|
437
|
+
n({
|
|
438
|
+
type: "ADD_BLOCK",
|
|
439
|
+
payload: { parentId: c._id, index: p, block: u }
|
|
440
|
+
});
|
|
441
|
+
}, [t.document]), y = h(
|
|
442
|
+
(c) => {
|
|
443
|
+
const u = U(t.document, c);
|
|
444
|
+
if (!u) return;
|
|
445
|
+
const p = {
|
|
446
|
+
tagName: "mj-column",
|
|
447
|
+
attributes: {},
|
|
448
|
+
_id: N(),
|
|
449
|
+
children: []
|
|
450
|
+
}, x = u.children?.length || 0;
|
|
451
|
+
n({
|
|
452
|
+
type: "ADD_BLOCK",
|
|
453
|
+
payload: { parentId: c, index: x, block: p }
|
|
454
|
+
});
|
|
455
|
+
},
|
|
456
|
+
[t.document]
|
|
457
|
+
), s = h((c) => {
|
|
458
|
+
n({ type: "DELETE_BLOCK", payload: c });
|
|
459
|
+
}, []), f = h(
|
|
460
|
+
(c, u, p) => {
|
|
461
|
+
n({ type: "MOVE_BLOCK", payload: { id: c, newParentId: u, newIndex: p } });
|
|
462
|
+
},
|
|
463
|
+
[]
|
|
464
|
+
), I = h((c) => {
|
|
465
|
+
n({ type: "SET_DOCUMENT", payload: c });
|
|
466
|
+
}, []), b = h(() => {
|
|
467
|
+
n({ type: "UNDO" });
|
|
468
|
+
}, []), E = h(() => {
|
|
469
|
+
n({ type: "REDO" });
|
|
470
|
+
}, []), _ = D(() => t.selectedBlockId ? U(t.document, t.selectedBlockId) : null, [t.document, t.selectedBlockId]), g = D(
|
|
471
|
+
() => Z(t.document),
|
|
472
|
+
[t.document]
|
|
473
|
+
), A = D(
|
|
474
|
+
() => ee(t.document),
|
|
475
|
+
[t.document]
|
|
476
|
+
), C = h(
|
|
477
|
+
(c) => te(c, g),
|
|
478
|
+
[g]
|
|
479
|
+
), T = h(
|
|
480
|
+
(c, u) => {
|
|
481
|
+
const p = Y(c.tagName);
|
|
482
|
+
return ne(c, u, g, p);
|
|
483
|
+
},
|
|
484
|
+
[g]
|
|
485
|
+
), w = h(
|
|
486
|
+
(c, u, p) => {
|
|
487
|
+
n({
|
|
488
|
+
type: "UPDATE_MJML_ATTRIBUTE",
|
|
489
|
+
payload: { attributeType: c, target: u, attributes: p }
|
|
490
|
+
});
|
|
491
|
+
},
|
|
492
|
+
[]
|
|
493
|
+
), B = h((c) => {
|
|
494
|
+
n({ type: "ADD_CLASS", payload: c });
|
|
495
|
+
}, []), O = h((c) => {
|
|
496
|
+
n({ type: "REMOVE_CLASS", payload: c });
|
|
497
|
+
}, []), M = h((c, u) => {
|
|
498
|
+
n({ type: "RENAME_CLASS", payload: { oldName: c, newName: u } });
|
|
499
|
+
}, []), k = D(() => oe(t.document), [t.document]), L = h((c, u) => {
|
|
500
|
+
n({ type: "ADD_FONT", payload: { name: c, href: u } });
|
|
501
|
+
}, []), S = h((c) => {
|
|
502
|
+
n({ type: "REMOVE_FONT", payload: c });
|
|
503
|
+
}, []), H = h((c, u) => {
|
|
504
|
+
n({ type: "UPDATE_FONT", payload: { name: c, href: u } });
|
|
505
|
+
}, []), K = D(
|
|
506
|
+
() => ({
|
|
507
|
+
state: t,
|
|
508
|
+
selectBlock: r,
|
|
509
|
+
updateAttributes: o,
|
|
510
|
+
updateContent: l,
|
|
511
|
+
addBlock: i,
|
|
512
|
+
addSection: a,
|
|
513
|
+
addColumn: y,
|
|
514
|
+
deleteBlock: s,
|
|
515
|
+
moveBlock: f,
|
|
516
|
+
setDocument: I,
|
|
517
|
+
undo: b,
|
|
518
|
+
redo: E,
|
|
519
|
+
canUndo: t.historyIndex > 0,
|
|
520
|
+
canRedo: t.historyIndex < t.history.length - 1,
|
|
521
|
+
selectedBlock: _,
|
|
522
|
+
// mj-attributes support
|
|
523
|
+
mjmlAttributes: g,
|
|
524
|
+
definedClasses: A,
|
|
525
|
+
getResolvedAttributes: C,
|
|
526
|
+
getInheritedValue: T,
|
|
527
|
+
updateMjmlAttribute: w,
|
|
528
|
+
addClass: B,
|
|
529
|
+
removeClass: O,
|
|
530
|
+
renameClass: M,
|
|
531
|
+
// mj-font support
|
|
532
|
+
fonts: k,
|
|
533
|
+
addFont: L,
|
|
534
|
+
removeFont: S,
|
|
535
|
+
updateFont: H
|
|
536
|
+
}),
|
|
537
|
+
[
|
|
538
|
+
t,
|
|
539
|
+
r,
|
|
540
|
+
o,
|
|
541
|
+
l,
|
|
542
|
+
i,
|
|
543
|
+
a,
|
|
544
|
+
y,
|
|
545
|
+
s,
|
|
546
|
+
f,
|
|
547
|
+
I,
|
|
548
|
+
b,
|
|
549
|
+
E,
|
|
550
|
+
_,
|
|
551
|
+
g,
|
|
552
|
+
A,
|
|
553
|
+
C,
|
|
554
|
+
T,
|
|
555
|
+
w,
|
|
556
|
+
B,
|
|
557
|
+
O,
|
|
558
|
+
M,
|
|
559
|
+
k,
|
|
560
|
+
L,
|
|
561
|
+
S,
|
|
562
|
+
H
|
|
563
|
+
]
|
|
564
|
+
);
|
|
565
|
+
return /* @__PURE__ */ J(P.Provider, { value: K, children: e });
|
|
566
|
+
}
|
|
567
|
+
function Ie() {
|
|
568
|
+
const e = q(P);
|
|
569
|
+
if (!e)
|
|
570
|
+
throw new Error("useEditor must be used within an EditorProvider");
|
|
571
|
+
return e;
|
|
572
|
+
}
|
|
573
|
+
export {
|
|
574
|
+
Ne as EditorProvider,
|
|
575
|
+
Ie as useEditor
|
|
576
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { LiquidSchema } from '../types/liquid';
|
|
3
|
+
interface LiquidSchemaProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
schema?: LiquidSchema;
|
|
6
|
+
}
|
|
7
|
+
export declare function LiquidSchemaProvider({ children, schema, }: LiquidSchemaProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function useLiquidSchema(): LiquidSchema | undefined;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=LiquidSchemaContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiquidSchemaContext.d.ts","sourceRoot":"","sources":["../../src/context/LiquidSchemaContext.tsx"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,UAAU,yBAAyB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,MAAM,GACP,EAAE,yBAAyB,2CAM3B;AAED,wBAAgB,eAAe,6BAE9B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as i, useContext as n } from "react";
|
|
3
|
+
const e = i(void 0);
|
|
4
|
+
function m({
|
|
5
|
+
children: t,
|
|
6
|
+
schema: o
|
|
7
|
+
}) {
|
|
8
|
+
return /* @__PURE__ */ r(e.Provider, { value: o, children: t });
|
|
9
|
+
}
|
|
10
|
+
function d() {
|
|
11
|
+
return n(e);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
m as LiquidSchemaProvider,
|
|
15
|
+
d as useLiquidSchema
|
|
16
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type Theme = 'light' | 'dark' | 'system';
|
|
3
|
+
type ResolvedTheme = 'light' | 'dark';
|
|
4
|
+
interface ThemeContextValue {
|
|
5
|
+
theme: Theme;
|
|
6
|
+
resolvedTheme: ResolvedTheme;
|
|
7
|
+
setTheme: (theme: Theme) => void;
|
|
8
|
+
toggleTheme: () => void;
|
|
9
|
+
}
|
|
10
|
+
interface ThemeProviderProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
defaultTheme?: Theme;
|
|
13
|
+
storageKey?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to apply the theme class to document.documentElement.
|
|
16
|
+
* This is needed for Radix UI portals (popovers, menus, etc.) which
|
|
17
|
+
* render outside the .mjml-editor container.
|
|
18
|
+
*
|
|
19
|
+
* Set to false if the host app manages document-level theme classes
|
|
20
|
+
* and you want to prevent conflicts.
|
|
21
|
+
*
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
applyToDocument?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function ThemeProvider({ children, defaultTheme, storageKey, applyToDocument, }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare function useTheme(): ThemeContextValue;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=ThemeContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/context/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AACzC,KAAK,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;AAEtC,UAAU,iBAAiB;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAsBD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,YAAY,EACZ,UAAwB,EACxB,eAAsB,GACvB,EAAE,kBAAkB,2CAgDpB;AAGD,wBAAgB,QAAQ,sBAMvB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { useState as d, useEffect as h, useCallback as a, useMemo as S, createContext as E, useContext as x } from "react";
|
|
3
|
+
const u = E(null), l = "mjml-editor-theme";
|
|
4
|
+
function p() {
|
|
5
|
+
return typeof window > "u" ? "light" : window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
6
|
+
}
|
|
7
|
+
function C() {
|
|
8
|
+
if (typeof window > "u") return "system";
|
|
9
|
+
const e = localStorage.getItem(l);
|
|
10
|
+
return e === "light" || e === "dark" || e === "system" ? e : "system";
|
|
11
|
+
}
|
|
12
|
+
function P({
|
|
13
|
+
children: e,
|
|
14
|
+
defaultTheme: f,
|
|
15
|
+
storageKey: s = l,
|
|
16
|
+
applyToDocument: m = !0
|
|
17
|
+
}) {
|
|
18
|
+
const [n, g] = d(
|
|
19
|
+
() => f ?? C()
|
|
20
|
+
), [T, w] = d(p);
|
|
21
|
+
h(() => {
|
|
22
|
+
const t = window.matchMedia("(prefers-color-scheme: dark)"), c = (k) => {
|
|
23
|
+
w(k.matches ? "dark" : "light");
|
|
24
|
+
};
|
|
25
|
+
return t.addEventListener("change", c), () => t.removeEventListener("change", c);
|
|
26
|
+
}, []);
|
|
27
|
+
const r = n === "system" ? T : n;
|
|
28
|
+
h(() => {
|
|
29
|
+
if (!m) return;
|
|
30
|
+
const t = document.documentElement;
|
|
31
|
+
t.classList.remove("light", "dark"), t.classList.add(r);
|
|
32
|
+
}, [r, m]);
|
|
33
|
+
const o = a(
|
|
34
|
+
(t) => {
|
|
35
|
+
g(t), localStorage.setItem(s, t);
|
|
36
|
+
},
|
|
37
|
+
[s]
|
|
38
|
+
), i = a(() => {
|
|
39
|
+
o(r === "light" ? "dark" : "light");
|
|
40
|
+
}, [r, o]), v = S(
|
|
41
|
+
() => ({ theme: n, resolvedTheme: r, setTheme: o, toggleTheme: i }),
|
|
42
|
+
[n, r, o, i]
|
|
43
|
+
);
|
|
44
|
+
return /* @__PURE__ */ y(u.Provider, { value: v, children: e });
|
|
45
|
+
}
|
|
46
|
+
function b() {
|
|
47
|
+
const e = x(u);
|
|
48
|
+
if (!e)
|
|
49
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
50
|
+
return e;
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
P as ThemeProvider,
|
|
54
|
+
b as useTheme
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiquidHighlight.d.ts","sourceRoot":"","sources":["../../src/extensions/LiquidHighlight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAyDzC,eAAO,MAAM,eAAe,qBA8B1B,CAAC"}
|