@savvycal/mjml-editor 0.6.0 → 0.7.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SourceEditor.d.ts","sourceRoot":"","sources":["../../../src/components/editor/SourceEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SourceEditor.d.ts","sourceRoot":"","sources":["../../../src/components/editor/SourceEditor.tsx"],"names":[],"mappings":"AA0DA,wBAAgB,YAAY,4CAkH3B"}
|
|
@@ -1,116 +1,111 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as f, useRef as g, useEffect as p, useCallback as
|
|
3
|
-
import { AlertTriangle as y } from "lucide-react";
|
|
1
|
+
import { jsxs as m, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { useState as f, useRef as g, useEffect as p, useCallback as v, useMemo as y } from "react";
|
|
4
3
|
import k from "@uiw/react-codemirror";
|
|
5
|
-
import { EditorState as
|
|
6
|
-
import { indentUnit as
|
|
7
|
-
import { lineNumbers as
|
|
8
|
-
import { history as
|
|
9
|
-
import { highlightSelectionMatches as
|
|
10
|
-
import { xml as
|
|
11
|
-
import { tags as
|
|
12
|
-
import { useEditor as
|
|
13
|
-
import { serializeMjml as
|
|
14
|
-
import { ResizableSplitPane as
|
|
4
|
+
import { EditorState as N } from "@codemirror/state";
|
|
5
|
+
import { indentUnit as M, bracketMatching as E, syntaxHighlighting as j, HighlightStyle as C } from "@codemirror/language";
|
|
6
|
+
import { lineNumbers as w, highlightActiveLineGutter as L, highlightActiveLine as D, EditorView as W, keymap as R } from "@codemirror/view";
|
|
7
|
+
import { history as z, indentWithTab as A, defaultKeymap as H, historyKeymap as K } from "@codemirror/commands";
|
|
8
|
+
import { highlightSelectionMatches as T, searchKeymap as U } from "@codemirror/search";
|
|
9
|
+
import { xml as _ } from "@codemirror/lang-xml";
|
|
10
|
+
import { tags as t } from "@lezer/highlight";
|
|
11
|
+
import { useEditor as B } from "../../context/EditorContext.js";
|
|
12
|
+
import { serializeMjml as b, parseMjml as I } from "../../lib/mjml/parser.js";
|
|
13
|
+
import { ResizableSplitPane as J } from "../ui/resizable-split-pane.js";
|
|
15
14
|
import { SourcePreview as O } from "./SourcePreview.js";
|
|
16
|
-
const P = 350,
|
|
15
|
+
const P = 350, V = C.define([
|
|
17
16
|
{
|
|
18
|
-
tag:
|
|
17
|
+
tag: t.tagName,
|
|
19
18
|
color: "var(--cm-tag, oklch(0.74 0.1 158))",
|
|
20
19
|
fontWeight: "600"
|
|
21
20
|
},
|
|
22
21
|
{
|
|
23
|
-
tag:
|
|
22
|
+
tag: t.attributeName,
|
|
24
23
|
color: "var(--cm-attribute-name, oklch(0.76 0.09 80))"
|
|
25
24
|
},
|
|
26
25
|
{
|
|
27
|
-
tag: [
|
|
26
|
+
tag: [t.attributeValue, t.string],
|
|
28
27
|
color: "var(--cm-attribute-value, oklch(0.77 0.1 255))"
|
|
29
28
|
},
|
|
30
29
|
{
|
|
31
|
-
tag: [
|
|
30
|
+
tag: [t.angleBracket, t.bracket],
|
|
32
31
|
color: "var(--cm-punctuation, oklch(0.7 0.02 250))"
|
|
33
32
|
},
|
|
34
|
-
{ tag:
|
|
33
|
+
{ tag: t.comment, color: "var(--cm-comment, oklch(0.63 0.01 250))" },
|
|
35
34
|
{
|
|
36
|
-
tag:
|
|
35
|
+
tag: t.invalid,
|
|
37
36
|
color: "var(--cm-invalid, oklch(0.7 0.16 25))",
|
|
38
37
|
textDecoration: "underline"
|
|
39
38
|
}
|
|
40
39
|
]);
|
|
41
|
-
function
|
|
42
|
-
const { state: s, setDocument: u } =
|
|
40
|
+
function ae() {
|
|
41
|
+
const { state: s, setDocument: u } = B(), [o, d] = f(""), [a, i] = f(null), c = g(!1), l = g("");
|
|
43
42
|
p(() => {
|
|
44
|
-
if (
|
|
45
|
-
|
|
43
|
+
if (c.current) {
|
|
44
|
+
c.current = !1;
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
48
|
-
const e =
|
|
49
|
-
|
|
47
|
+
const e = b(s.document);
|
|
48
|
+
l.current = e, d(e), i(null);
|
|
50
49
|
}, [s.document]);
|
|
51
|
-
const h =
|
|
50
|
+
const h = v(
|
|
52
51
|
(e) => {
|
|
53
52
|
try {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
53
|
+
const r = I(e);
|
|
54
|
+
if (r.tagName !== "mjml") {
|
|
56
55
|
i("Invalid MJML: Document must have an <mjml> root element");
|
|
57
56
|
return;
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
} catch (
|
|
61
|
-
i(
|
|
58
|
+
l.current = b(r), c.current = !0, u(r), i(null);
|
|
59
|
+
} catch (r) {
|
|
60
|
+
i(r instanceof Error ? r.message : "Failed to parse MJML");
|
|
62
61
|
}
|
|
63
62
|
},
|
|
64
63
|
[u]
|
|
65
|
-
),
|
|
64
|
+
), x = y(
|
|
66
65
|
() => [
|
|
66
|
+
w(),
|
|
67
67
|
L(),
|
|
68
68
|
D(),
|
|
69
|
-
|
|
69
|
+
z(),
|
|
70
|
+
N.tabSize.of(2),
|
|
71
|
+
M.of(" "),
|
|
72
|
+
E(),
|
|
70
73
|
T(),
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
w(Y),
|
|
76
|
-
R.lineWrapping,
|
|
77
|
-
A.of([
|
|
78
|
-
z,
|
|
74
|
+
j(V),
|
|
75
|
+
W.lineWrapping,
|
|
76
|
+
R.of([
|
|
77
|
+
A,
|
|
79
78
|
...H,
|
|
80
|
-
...
|
|
79
|
+
...K,
|
|
81
80
|
...U
|
|
82
81
|
]),
|
|
83
|
-
|
|
82
|
+
_()
|
|
84
83
|
],
|
|
85
84
|
[]
|
|
86
|
-
), S =
|
|
85
|
+
), S = v((e) => {
|
|
87
86
|
d(e), i(null);
|
|
88
87
|
}, []);
|
|
89
88
|
return p(() => {
|
|
90
|
-
if (
|
|
89
|
+
if (o === l.current)
|
|
91
90
|
return;
|
|
92
91
|
const e = window.setTimeout(() => {
|
|
93
|
-
h(
|
|
92
|
+
h(o);
|
|
94
93
|
}, P);
|
|
95
94
|
return () => window.clearTimeout(e);
|
|
96
|
-
}, [
|
|
97
|
-
|
|
95
|
+
}, [o, h]), /* @__PURE__ */ m(
|
|
96
|
+
J,
|
|
98
97
|
{
|
|
99
98
|
defaultLeftWidth: 50,
|
|
100
99
|
minLeftWidth: 30,
|
|
101
100
|
maxLeftWidth: 70,
|
|
102
101
|
children: [
|
|
103
|
-
/* @__PURE__ */
|
|
104
|
-
/* @__PURE__ */
|
|
105
|
-
/* @__PURE__ */ t(y, { className: "h-4 w-4 mt-0.5 flex-shrink-0" }),
|
|
106
|
-
/* @__PURE__ */ t("p", { className: "text-sm", children: "You are editing raw MJML source. Valid changes sync to the visual editor automatically." })
|
|
107
|
-
] }) }),
|
|
108
|
-
/* @__PURE__ */ t("div", { className: "flex-1 min-h-0 p-4", children: /* @__PURE__ */ t(
|
|
102
|
+
/* @__PURE__ */ m("div", { className: "flex flex-col h-full bg-background", children: [
|
|
103
|
+
/* @__PURE__ */ n("div", { className: "flex-1 min-h-0 p-4", children: /* @__PURE__ */ n(
|
|
109
104
|
k,
|
|
110
105
|
{
|
|
111
|
-
value:
|
|
106
|
+
value: o,
|
|
112
107
|
onChange: S,
|
|
113
|
-
extensions:
|
|
108
|
+
extensions: x,
|
|
114
109
|
basicSetup: !1,
|
|
115
110
|
theme: "none",
|
|
116
111
|
className: "source-editor h-full overflow-hidden rounded-md border border-border bg-muted text-foreground",
|
|
@@ -118,16 +113,16 @@ function le() {
|
|
|
118
113
|
spellCheck: !1
|
|
119
114
|
}
|
|
120
115
|
) }),
|
|
121
|
-
/* @__PURE__ */
|
|
122
|
-
!
|
|
123
|
-
|
|
116
|
+
/* @__PURE__ */ m("div", { className: "px-4 pb-4 flex items-center gap-3", children: [
|
|
117
|
+
!a && /* @__PURE__ */ n("span", { className: "text-sm text-foreground-muted", children: "Changes sync automatically" }),
|
|
118
|
+
a && /* @__PURE__ */ n("span", { className: "text-sm text-destructive", children: a })
|
|
124
119
|
] })
|
|
125
120
|
] }),
|
|
126
|
-
/* @__PURE__ */
|
|
121
|
+
/* @__PURE__ */ n(O, { mjmlSource: o, debounceMs: 300 })
|
|
127
122
|
]
|
|
128
123
|
}
|
|
129
124
|
);
|
|
130
125
|
}
|
|
131
126
|
export {
|
|
132
|
-
|
|
127
|
+
ae as SourceEditor
|
|
133
128
|
};
|