monto-email-builder 1.4.0 → 1.4.2

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,350 +1,422 @@
1
- import { jsxs as m, jsx as r, Fragment as wt } from "react/jsx-runtime";
2
- import { forwardRef as St, useState as y, useRef as oe, useEffect as J, useCallback as w, useMemo as Q, useImperativeHandle as Ht } from "react";
3
- import Lt from "@uiw/react-codemirror";
4
- import { html as Dt } from "@codemirror/lang-html";
5
- import { xcodeDark as Mt, tomorrowNightBlue as It, dracula as Je, basicDark as kt, abcdef as At, bbedit as zt, noctisLilac as Ot, gruvboxLight as Rt, tokyoNightDay as Bt, vscodeLight as Ft, xcodeLight as Nt } from "@uiw/codemirror-themes-all";
6
- import F from "@mui/material/ToggleButton";
7
- import _e from "@mui/material/ToggleButtonGroup";
8
- import { useTheme as $t, Box as d, Tooltip as O, FormControl as _t, InputLabel as Pt, Select as Wt, ListSubheader as Pe, MenuItem as We, Button as ie, Tabs as jt, Tab as je, Typography as S, Accordion as Gt, AccordionSummary as Kt, AccordionDetails as Ut, TextField as le, Divider as Yt } from "@mui/material";
9
- import { alpha as Ge } from "@mui/material/styles";
10
- import * as qt from "@mui/icons-material/AddOutlined";
11
- import * as Xt from "@mui/icons-material/Code";
12
- import * as Jt from "@mui/icons-material/DataObjectOutlined";
13
- import * as Qt from "@mui/icons-material/ExpandMoreOutlined";
14
- import * as Zt from "@mui/icons-material/HelpOutlined";
15
- import * as er from "@mui/icons-material/Visibility";
16
- import * as tr from "@mui/icons-material/ViewColumn";
17
- import * as rr from "@mui/icons-material/MonitorOutlined";
18
- import * as or from "@mui/icons-material/PhoneIphoneOutlined";
19
- import { B as ir, V as H, r as V, t as lr } from "./chunks/chunk-CF4KXMbF.js";
20
- const ae = ir, Ke = "unsubscribe_link", ne = /\{\{\s*([^{}]+?)\s*\}\}/g, Ue = /\{%\s*([^{}%]+?)\s*%\}/g;
21
- function se(o, a, s, l, c) {
22
- return o[a - 1] !== l && o[s] !== c;
1
+ import { jsx as o, jsxs as f, Fragment as Nt } from "react/jsx-runtime";
2
+ import { forwardRef as dt, useState as E, useRef as $, useEffect as X, useCallback as D, useMemo as J, useImperativeHandle as zt } from "react";
3
+ import Ot from "@uiw/react-codemirror";
4
+ import { html as Pt } from "@codemirror/lang-html";
5
+ import { xcodeDark as _t, tomorrowNightBlue as Wt, dracula as ut, basicDark as jt, abcdef as Gt, bbedit as Ut, noctisLilac as qt, gruvboxLight as Yt, tokyoNightDay as Kt, vscodeLight as Xt, xcodeLight as Jt } from "@uiw/codemirror-themes-all";
6
+ import Q from "@mui/material/ToggleButton";
7
+ import et from "@mui/material/ToggleButtonGroup";
8
+ import { ThemeProvider as Qt, ScopedCssBaseline as Zt, useTheme as er, Box as m, Tooltip as G, FormControl as tr, InputLabel as rr, Select as or, ListSubheader as tt, MenuItem as rt, Button as ve, Tabs as ar, Tab as ot, Typography as B, Accordion as nr, AccordionSummary as ir, AccordionDetails as lr, TextField as ye, Divider as sr } from "@mui/material";
9
+ import { alpha as ce } from "@mui/material/styles";
10
+ import * as cr from "@mui/icons-material/AddOutlined";
11
+ import * as dr from "@mui/icons-material/Code";
12
+ import * as ur from "@mui/icons-material/DataObjectOutlined";
13
+ import * as mr from "@mui/icons-material/ExpandMoreOutlined";
14
+ import * as hr from "@mui/icons-material/HelpOutlined";
15
+ import * as br from "@mui/icons-material/Visibility";
16
+ import * as pr from "@mui/icons-material/ViewColumn";
17
+ import * as fr from "@mui/icons-material/MonitorOutlined";
18
+ import * as xr from "@mui/icons-material/PhoneIphoneOutlined";
19
+ import { B as gr, V as A, r as L, T as vr, t as yr } from "./chunks/chunk-ZMWDxWGX.js";
20
+ const Ee = gr, at = "unsubscribe_link", Ve = /\{\{\s*([^{}]+?)\s*\}\}/g, nt = /\{%\s*([^{}%]+?)\s*%\}/g;
21
+ function Te(a, n, s, d, c) {
22
+ return a[n - 1] !== d && a[s] !== c;
23
23
  }
24
- function Qe(o, a = "user") {
25
- return a === "builtin" || a === "system" ? `{%${o}%}` : `{{${o}}}`;
24
+ function mt(a, n = "user") {
25
+ return n === "builtin" || n === "system" ? `{%${a}%}` : `{{${a}}}`;
26
26
  }
27
- function ar(o) {
28
- const a = typeof o == "string" ? o.trim() : "";
29
- if (a.startsWith("{{") && a.endsWith("}}")) {
30
- const s = a.slice(2, -2).trim();
31
- if (H.test(s)) return { attribute: s, type: "user" };
27
+ function Ir(a) {
28
+ const n = typeof a == "string" ? a.trim() : "";
29
+ if (n.startsWith("{{") && n.endsWith("}}")) {
30
+ const s = n.slice(2, -2).trim();
31
+ if (A.test(s)) return { attribute: s, type: "user" };
32
32
  }
33
- if (a.startsWith("{%") && a.endsWith("%}")) {
34
- const s = a.slice(2, -2).trim();
35
- if (H.test(s)) return { attribute: s, type: "system" };
33
+ if (n.startsWith("{%") && n.endsWith("%}")) {
34
+ const s = n.slice(2, -2).trim();
35
+ if (A.test(s)) return { attribute: s, type: "system" };
36
36
  }
37
37
  return null;
38
38
  }
39
- function nr(o, a) {
40
- const s = o.variable ?? o.Variable ?? o.key ?? "", l = ar(s), g = (o.type ?? o.Type ?? (l == null ? void 0 : l.type) ?? "user") === "system" ? "system" : "user", h = o.attribute ?? o.Attribute ?? (l == null ? void 0 : l.attribute) ?? "", p = String(h).trim();
41
- return !p || !H.test(p) ? null : {
42
- id: Number(o.id) || a + 1,
43
- variable: g === "system" ? `{%${p}%}` : `{{${p}}}`,
44
- type: g,
45
- attribute: p,
46
- default: String(o.default ?? o.Default ?? o.value ?? "")
39
+ function Er(a, n) {
40
+ const s = a.variable ?? a.Variable ?? a.key ?? "", d = Ir(s), x = (a.type ?? a.Type ?? (d == null ? void 0 : d.type) ?? "user") === "system" ? "system" : "user", i = a.attribute ?? a.Attribute ?? (d == null ? void 0 : d.attribute) ?? "", u = String(i).trim();
41
+ return !u || !A.test(u) ? null : {
42
+ id: Number(a.id) || n + 1,
43
+ variableInstanceId: a.variableInstanceId ?? a.VariableInstanceId,
44
+ variable: x === "system" ? `{%${u}%}` : `{{${u}}}`,
45
+ type: x,
46
+ attribute: u,
47
+ default: String(a.default ?? a.Default ?? a.value ?? "")
47
48
  };
48
49
  }
49
- function Ye(o) {
50
- if (!Array.isArray(o)) return [];
51
- const a = /* @__PURE__ */ new Map();
52
- return o.forEach((s, l) => {
53
- const c = nr(s, l);
54
- c && a.set(`${c.type}:${c.attribute}`, c);
55
- }), Array.from(a.values()).map((s, l) => ({
56
- ...s,
57
- id: l + 1
58
- }));
50
+ function it(a) {
51
+ return Array.isArray(a) ? a.map((n, s) => Er(n, s)).filter((n) => !!n).map((n, s) => ({
52
+ ...n,
53
+ id: s + 1,
54
+ variableInstanceId: n.variableInstanceId || we(n.type, n.attribute, s)
55
+ })) : [];
59
56
  }
60
- function sr(o) {
61
- const a = o || "", s = /* @__PURE__ */ new Map(), l = (h, p) => {
62
- const f = `${p}:${h}`;
63
- s.has(f) || s.set(f, {
64
- id: s.size + 1,
65
- variable: p === "system" ? `{%${h}%}` : `{{${h}}}`,
66
- type: p,
67
- attribute: h,
68
- default: ""
69
- });
57
+ function de(a) {
58
+ const n = a || "", s = [], d = (i, u, p) => {
59
+ s.push({ attribute: i, type: u, start: p });
70
60
  };
71
61
  let c;
72
- for (ne.lastIndex = 0; c = ne.exec(a); ) {
73
- const h = c.index, p = h + c[0].length;
74
- if (!se(a, h, p, "{", "}")) continue;
75
- const f = c[1].trim();
76
- !f || !H.test(f) || l(f, "user");
62
+ for (Ve.lastIndex = 0; c = Ve.exec(n); ) {
63
+ const i = c.index, u = i + c[0].length;
64
+ if (!Te(n, i, u, "{", "}")) continue;
65
+ const p = c[1].trim();
66
+ !p || !A.test(p) || d(p, "user", i);
77
67
  }
78
- let g;
79
- for (Ue.lastIndex = 0; g = Ue.exec(a); ) {
80
- const h = g.index, p = h + g[0].length;
81
- if (!se(a, h, p, "{", "}")) continue;
82
- const f = g[1].trim();
83
- !f || !H.test(f) || l(f, "system");
68
+ let x;
69
+ for (nt.lastIndex = 0; x = nt.exec(n); ) {
70
+ const i = x.index, u = i + x[0].length;
71
+ if (!Te(n, i, u, "{", "}")) continue;
72
+ const p = x[1].trim();
73
+ !p || !A.test(p) || d(p, "system", i);
84
74
  }
85
- return Array.from(s.values());
86
- }
87
- function dr(o, a) {
88
- const s = /* @__PURE__ */ new Map();
89
- return a.forEach((l) => {
90
- s.set(`${l.type}:${l.attribute}`, l.default ?? "");
91
- }), o.map((l, c) => ({
92
- ...l,
93
- id: c + 1,
94
- default: s.get(`${l.type}:${l.attribute}`) ?? l.default ?? ""
75
+ return s.sort((i, u) => i.start - u.start), s.map((i, u) => ({
76
+ id: u + 1,
77
+ variableInstanceId: wr(i.type, i.attribute, i.start),
78
+ variable: i.type === "system" ? `{%${i.attribute}%}` : `{{${i.attribute}}}`,
79
+ type: i.type,
80
+ attribute: i.attribute,
81
+ default: ""
95
82
  }));
96
83
  }
97
- function cr(o) {
98
- return o.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
84
+ function Ie(a, n) {
85
+ const s = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
86
+ return n.forEach((c) => {
87
+ const x = { item: c, consumed: !1 };
88
+ if (c.variableInstanceId) {
89
+ const p = s.get(c.variableInstanceId) ?? [];
90
+ p.push(x), s.set(c.variableInstanceId, p);
91
+ }
92
+ const i = `${c.type}:${c.attribute}`, u = d.get(i) ?? [];
93
+ u.push(x), d.set(i, u);
94
+ }), a.map((c, x) => {
95
+ var N;
96
+ const i = `${c.type}:${c.attribute}`, u = c.variableInstanceId ? (N = s.get(c.variableInstanceId)) == null ? void 0 : N.find((g) => !g.consumed) : void 0, p = (d.get(i) ?? []).find((g) => !g.consumed), w = u ?? p;
97
+ return w && (w.consumed = !0), {
98
+ ...c,
99
+ id: x + 1,
100
+ variableInstanceId: c.variableInstanceId || we(c.type, c.attribute, x),
101
+ default: c.type === "system" ? "" : (w == null ? void 0 : w.item.default) ?? c.default ?? ""
102
+ };
103
+ });
104
+ }
105
+ function Vr(a) {
106
+ return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
99
107
  }
100
- function ur(o, a) {
101
- const s = /* @__PURE__ */ new Map();
102
- return a.forEach((l) => {
103
- l.type === "user" && s.set(l.attribute, l.default ?? "");
104
- }), (o || "").replace(ne, (l, c, g, h) => {
105
- const p = g + l.length;
106
- if (!se(h, g, p, "{", "}")) return l;
107
- const f = String(c).trim();
108
- if (!f || !H.test(f)) return l;
109
- const R = s.get(f);
110
- return R === void 0 || R === "" ? l : cr(R);
108
+ function lt(a, n) {
109
+ const s = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
110
+ n.forEach((i) => {
111
+ i.type === "user" && (i.variableInstanceId && s.set(i.variableInstanceId, i.default ?? ""), d.has(i.attribute) || d.set(i.attribute, i.default ?? ""));
112
+ });
113
+ const c = de(a), x = /* @__PURE__ */ new Map();
114
+ return c.forEach((i) => {
115
+ const u = Number(String(i.variableInstanceId ?? "").split("-at-")[1]);
116
+ Number.isFinite(u) && x.set(u, i);
117
+ }), (a || "").replace(Ve, (i, u, p, w) => {
118
+ var Z;
119
+ const N = p + i.length;
120
+ if (!Te(w, p, N, "{", "}")) return i;
121
+ const g = String(u).trim();
122
+ if (!g || !A.test(g)) return i;
123
+ const F = (Z = x.get(p)) == null ? void 0 : Z.variableInstanceId, z = (F ? s.get(F) : void 0) ?? (n.filter((l) => l.type === "user" && l.attribute === g).length === 1 ? d.get(g) : void 0);
124
+ return z === void 0 || z === "" ? i : Vr(z);
111
125
  });
112
126
  }
113
- function qe(o, a, s = "") {
114
- const l = o.trim();
115
- if (!l || !H.test(l)) return null;
116
- const c = a === "builtin" ? "system" : "user";
127
+ function st(a, n, s = "") {
128
+ const d = a.trim();
129
+ if (!d || !A.test(d)) return null;
130
+ const c = n === "builtin" ? "system" : "user";
117
131
  return {
118
132
  id: 1,
119
- variable: Qe(l, a),
133
+ variableInstanceId: we(c, d, 0),
134
+ variable: mt(d, n),
120
135
  type: c,
121
- attribute: l,
136
+ attribute: d,
122
137
  default: c === "system" ? "" : s
123
138
  };
124
139
  }
125
- function mr(o) {
126
- const a = o.trim();
127
- return a ? ae.some((s) => s.items.some((l) => l.name === a)) : !1;
140
+ function Tr(a) {
141
+ const n = a.trim();
142
+ return n ? Ee.some((s) => s.items.some((d) => d.name === n)) : !1;
128
143
  }
129
- function hr(o, a) {
130
- const s = o.trim();
131
- return a === "user" && s === Ke ? `<a href="{{${Ke}}">Unsubscribe Link</a>` : Qe(s, a);
144
+ function Cr(a, n) {
145
+ const s = a.trim();
146
+ return n === "user" && s === at ? `<a href="{{${at}}}">Unsubscribe Link</a>` : mt(s, n);
132
147
  }
133
- const br = V(qt), pr = V(Xt), fr = V(Jt), xr = V(Qt), gr = V(Zt), yr = V(er), vr = V(tr), Er = V(rr), Tr = V(or), de = {
148
+ function we(a, n, s) {
149
+ return `html-${a}-${n}-${s + 1}`;
150
+ }
151
+ function wr(a, n, s) {
152
+ return `html-${a}-${n}-at-${s}`;
153
+ }
154
+ const Hr = L(cr), Sr = L(dr), Mr = L(ur), Dr = L(mr), Lr = L(hr), kr = L(br), Br = L(pr), Ar = L(fr), Fr = L(xr), Ce = {
134
155
  // 浅色主题
135
- xcodeLight: Nt,
136
- vscodeLight: Ft,
137
- tokyoNightDay: Bt,
138
- gruvboxLight: Rt,
139
- noctisLilac: Ot,
140
- bbedit: zt,
156
+ xcodeLight: Jt,
157
+ vscodeLight: Xt,
158
+ tokyoNightDay: Kt,
159
+ gruvboxLight: Yt,
160
+ noctisLilac: qt,
161
+ bbedit: Ut,
141
162
  // 深色主题
142
- abcdef: At,
143
- basicDark: kt,
144
- dracula: Je,
145
- tomorrowNightBlue: It,
146
- xcodeDark: Mt
147
- }, Vr = {
163
+ abcdef: Gt,
164
+ basicDark: jt,
165
+ dracula: ut,
166
+ tomorrowNightBlue: Wt,
167
+ xcodeDark: _t
168
+ }, Rr = {
148
169
  xcodeLight: "Xcode Light (Light)",
149
170
  vscodeLight: "VSCode Light (Light)",
150
171
  tokyoNightDay: "Tokyo Night Day (Light)",
151
172
  gruvboxLight: "Gruvbox Light (Light)",
152
173
  noctisLilac: "Noctis Lilac (Light)",
153
174
  bbedit: "BBEdit (Light)"
154
- }, Cr = {
175
+ }, $r = {
155
176
  abcdef: "ABCDEF (Dark)",
156
177
  basicDark: "Basic Dark (Dark)",
157
178
  dracula: "Dracula (Dark)",
158
179
  tomorrowNightBlue: "Tomorrow Night Blue (Dark)",
159
180
  xcodeDark: "Xcode Dark (Dark)"
160
- }, Ze = "html-editor-theme", Xe = "dracula";
161
- function wr(o = Xe) {
162
- const a = o && de[o] ? o : Xe;
163
- if (typeof window > "u") return a;
181
+ }, ht = "html-editor-theme", ct = "dracula";
182
+ function Nr(a = ct) {
183
+ const n = a && Ce[a] ? a : ct;
184
+ if (typeof window > "u") return n;
164
185
  try {
165
- const s = localStorage.getItem(Ze);
166
- if (s && de[s]) return s;
186
+ const s = localStorage.getItem(ht);
187
+ if (s && Ce[s]) return s;
167
188
  } catch {
168
189
  console.error("Failed to get HTML Editor stored theme");
169
190
  }
170
- return a;
191
+ return n;
171
192
  }
172
- function Sr(o) {
193
+ function zr(a) {
173
194
  try {
174
- localStorage.setItem(Ze, o);
195
+ localStorage.setItem(ht, a);
175
196
  } catch {
176
- console.error("Failed to set HTML Editor stored theme", o);
197
+ console.error("Failed to set HTML Editor stored theme", a);
177
198
  }
178
199
  }
179
- function Hr({
180
- value: o,
181
- onChange: a,
200
+ function Or({
201
+ value: a,
202
+ onChange: n,
182
203
  language: s = "zh",
183
- initialMode: l = "split",
204
+ initialMode: d = "split",
184
205
  initialDevice: c = "desktop",
185
- codeEditorHeight: g = "100%",
186
- previewHeight: h = "100%",
187
- sx: p,
188
- showToolbar: f = !0,
189
- initialTheme: R,
190
- initialRightTab: et = "preview",
191
- variables: N,
192
- onVariablesChange: $,
193
- requireVariableDefaults: ce = !0
194
- }, tt) {
195
- var ve, Ee, Te, Ve, Ce, we, Se, He, Le, De, Me, Ie, ke, Ae, ze, Oe, Re, Be;
196
- const n = (e, t) => lr(e, t, s), [v, rt] = y(l), [D, ot] = y(c), [ue, it] = y(() => wr(R)), [x, me] = y(o), [he, M] = y(et), [u, be] = y(() => Ye(N)), [lt, at] = y(!1), [nt, st] = y("custom"), [I, pe] = y(""), [k, fe] = y(""), [Z, _] = y(!1), [ee, P] = y(!1), B = oe(null), xe = oe(null), W = oe(null);
197
- J(() => {
198
- o !== x && me(o);
199
- }, [o]), J(() => {
200
- N !== void 0 && be(Ye(N));
201
- }, [N]);
202
- const C = w(
206
+ codeEditorHeight: x = "100%",
207
+ previewHeight: i = "100%",
208
+ sx: u,
209
+ showToolbar: p = !0,
210
+ initialTheme: w,
211
+ initialRightTab: N = "preview",
212
+ variables: g,
213
+ onVariablesChange: F,
214
+ requireVariableDefaults: z = !0
215
+ }, Z) {
216
+ var Re, $e, Ne, ze, Oe, Pe, _e, We, je, Ge, Ue, qe, Ye, Ke, Xe, Je, Qe, Ze;
217
+ const l = (e, t) => yr(e, t, s), [H, pt] = E(d), [O, ft] = E(c), [He, xt] = E(() => Nr(w)), [T, ue] = E(a), [ee, P] = E(N), [C, Se] = E(() => it(g)), [gt, vt] = E(!1), [yt, It] = E(null), [_, Me] = E(""), [W, De] = E(""), [me, te] = E(!1), [he, re] = E(!1), U = $(null), be = $(null), R = $(C), Le = $(null), ke = $(null), pe = $(!1), oe = $(null);
218
+ X(() => {
219
+ a !== T && ue(a);
220
+ }, [a]), X(() => {
221
+ if (g === void 0) return;
222
+ const e = it(g);
223
+ R.current = e, Se(e);
224
+ }, [g]);
225
+ const k = D(
203
226
  (e) => {
204
- const t = e.map((i, b) => ({
205
- ...i,
206
- id: b + 1,
207
- default: i.type === "system" ? "" : i.default ?? ""
227
+ const t = e.map((r, h) => ({
228
+ ...r,
229
+ id: h + 1,
230
+ default: r.type === "system" ? "" : r.default ?? ""
208
231
  }));
209
- return be(t), $ == null || $(t), t;
232
+ return R.current = t, Se(t), F == null || F(t), t;
210
233
  },
211
- [$]
212
- ), te = (e) => {
213
- me(e), B.current && clearTimeout(B.current), B.current = setTimeout(() => {
214
- a == null || a(e);
234
+ [F]
235
+ ), S = D(() => {
236
+ var t, r;
237
+ const e = (r = (t = be.current) == null ? void 0 : t.state) == null ? void 0 : r.doc;
238
+ return e && typeof e.toString == "function" ? e.toString() : T;
239
+ }, [T]), fe = (e) => {
240
+ ue(e), U.current && clearTimeout(U.current), U.current = setTimeout(() => {
241
+ n == null || n(e);
215
242
  }, 300);
216
- }, j = w(
217
- (e = x) => {
218
- const t = sr(e), i = dr(t, u);
219
- return C(i);
243
+ }, q = D(
244
+ (e) => {
245
+ const t = de(e ?? S()), r = Ie(t, R.current);
246
+ return k(r);
220
247
  },
221
- [u, x, C]
222
- ), G = w(() => {
223
- const e = j(x), t = ce ? e.filter((i) => i.type === "user" && i.default.trim() === "") : [];
224
- return at(t.length > 0), t.length > 0 && M("variables"), {
225
- valid: t.length === 0,
226
- variables: e,
227
- missing: t
248
+ [S, k]
249
+ ), ae = D(() => {
250
+ const e = S();
251
+ e !== T && ue(e);
252
+ const t = q(e), r = z ? t.filter((h) => h.type === "user" && h.default.trim() === "") : [];
253
+ return vt(r.length > 0), r.length > 0 && P("variables"), {
254
+ valid: r.length === 0,
255
+ variables: t,
256
+ missing: r
228
257
  };
229
- }, [x, ce, j]), dt = w(() => {
230
- G(), M("variables");
231
- }, [G]);
232
- J(() => () => {
233
- B.current && clearTimeout(B.current);
258
+ }, [S, T, z, q]), Et = D(() => {
259
+ pe.current = !0, ae(), P("variables");
260
+ }, [ae]);
261
+ X(() => {
262
+ if (ee !== "variables" || !pe.current) return;
263
+ const e = window.requestAnimationFrame(() => {
264
+ const t = Le.current, r = ke.current;
265
+ t && r && t.scrollTo({
266
+ top: Math.max(r.offsetTop - 8, 0),
267
+ behavior: "auto"
268
+ }), pe.current = !1;
269
+ });
270
+ return () => window.cancelAnimationFrame(e);
271
+ }, [ee, C.length]), X(() => () => {
272
+ U.current && clearTimeout(U.current);
234
273
  }, []);
235
- const ct = (e) => {
236
- var X, Fe, Ne;
274
+ const Vt = (e) => {
275
+ var y, I, Y;
237
276
  const t = e || "";
238
- let i = t;
277
+ let r = t;
239
278
  if (!t.trim())
240
- i = "<!DOCTYPE html><html><head></head><body></body></html>";
279
+ r = "<!DOCTYPE html><html><head></head><body></body></html>";
241
280
  else {
242
- const T = new DOMParser().parseFromString(t, "text/html"), re = ((X = T.documentElement) == null ? void 0 : X.tagName.toLowerCase()) === "html", Tt = ((Fe = T.head) == null ? void 0 : Fe.tagName.toLowerCase()) === "head", Vt = ((Ne = T.body) == null ? void 0 : Ne.tagName.toLowerCase()) === "body";
243
- if (!re || !Tt || !Vt) {
244
- const Ct = T.body ? T.body.innerHTML : t;
245
- i = `<!DOCTYPE html><html><head>${T.head ? T.head.innerHTML : ""}</head><body>${Ct}</body></html>`;
281
+ const M = new DOMParser().parseFromString(t, "text/html"), ge = ((y = M.documentElement) == null ? void 0 : y.tagName.toLowerCase()) === "html", Ft = ((I = M.head) == null ? void 0 : I.tagName.toLowerCase()) === "head", Rt = ((Y = M.body) == null ? void 0 : Y.tagName.toLowerCase()) === "body";
282
+ if (!ge || !Ft || !Rt) {
283
+ const $t = M.body ? M.body.innerHTML : t;
284
+ r = `<!DOCTYPE html><html><head>${M.head ? M.head.innerHTML : ""}</head><body>${$t}</body></html>`;
246
285
  } else
247
- i = `<!DOCTYPE html>${T.documentElement.outerHTML}`;
286
+ r = `<!DOCTYPE html>${M.documentElement.outerHTML}`;
248
287
  }
249
- const b = ["script", "iframe", "object", "embed", "canvas"], z = new DOMParser().parseFromString(i, "text/html");
250
- return b.forEach(($e) => {
251
- z.querySelectorAll($e).forEach((re) => re.remove());
252
- }), i = `<!DOCTYPE html>${z.documentElement.outerHTML}`, i;
253
- }, K = Q(
254
- () => ur(x, u),
255
- [u, x]
256
- ), U = Q(() => ct(K), [K]);
257
- Ht(
258
- tt,
288
+ const h = ["script", "iframe", "object", "embed", "canvas"], b = new DOMParser().parseFromString(r, "text/html");
289
+ return h.forEach((K) => {
290
+ b.querySelectorAll(K).forEach((ge) => ge.remove());
291
+ }), r = `<!DOCTYPE html>${b.documentElement.outerHTML}`, r;
292
+ }, Be = J(
293
+ () => lt(T, C),
294
+ [C, T]
295
+ ), ne = J(() => Vt(Be), [Be]);
296
+ zt(
297
+ Z,
259
298
  () => ({
260
- getValue: () => x,
261
- getPreviewHtml: () => K,
262
- scanVariables: () => j(x),
263
- getVariables: (e) => (e == null || e(u), u),
264
- validateVariables: G,
265
- showVariables: () => M("variables")
299
+ getValue: () => S(),
300
+ getPreviewHtml: () => lt(S(), R.current),
301
+ scanVariables: () => q(S()),
302
+ getVariables: (e) => {
303
+ const t = q(S());
304
+ return e == null || e(t), t;
305
+ },
306
+ validateVariables: ae,
307
+ showVariables: () => P("variables")
266
308
  }),
267
- [u, x, K, j, G]
268
- ), J(() => {
269
- W.current && W.current.srcdoc !== U && (W.current.srcdoc = U);
270
- }, [U]);
271
- const ut = (e, t) => {
272
- t !== null && rt(t);
273
- }, mt = (e, t) => {
274
- (t === "desktop" || t === "mobile") && ot(t);
275
- }, Y = w(
309
+ [S, q, ae]
310
+ ), X(() => {
311
+ oe.current && oe.current.srcdoc !== ne && (oe.current.srcdoc = ne);
312
+ }, [ne]);
313
+ const Tt = (e, t) => {
314
+ t !== null && pt(t);
315
+ }, Ct = (e, t) => {
316
+ (t === "desktop" || t === "mobile") && ft(t);
317
+ }, ie = D(
276
318
  (e) => {
277
- var i, b;
278
- const t = xe.current;
319
+ var h, v;
320
+ const t = be.current;
279
321
  if (t != null && t.state && (t != null && t.dispatch)) {
280
- const L = (i = t.state.selection) == null ? void 0 : i.main, z = (L == null ? void 0 : L.from) ?? t.state.doc.length, X = (L == null ? void 0 : L.to) ?? z;
281
- t.dispatch({
282
- changes: { from: z, to: X, insert: e },
283
- selection: { anchor: z + e.length }
284
- }), (b = t.focus) == null || b.call(t), te(t.state.doc.toString());
285
- return;
322
+ const b = (h = t.state.selection) == null ? void 0 : h.main, y = t.state.doc.toString(), I = (b == null ? void 0 : b.from) ?? t.state.doc.length, Y = (b == null ? void 0 : b.to) ?? I, K = `${y.slice(0, I)}${e}${y.slice(Y)}`;
323
+ return t.dispatch({
324
+ changes: { from: I, to: Y, insert: e },
325
+ selection: { anchor: I + e.length }
326
+ }), (v = t.focus) == null || v.call(t), fe(K), K;
286
327
  }
287
- te(`${x}${e}`);
328
+ const r = `${T}${e}`;
329
+ return fe(r), r;
288
330
  },
289
- [x]
290
- ), ht = w(
291
- (e, t, i) => {
292
- C(
293
- u.map(
294
- (b) => b.attribute === e && b.type === t ? { ...b, default: i } : b
331
+ [T]
332
+ ), wt = D(
333
+ (e, t) => {
334
+ const r = R.current;
335
+ k(
336
+ r.map(
337
+ (h) => h.variableInstanceId === e ? { ...h, default: t } : h
295
338
  )
296
339
  );
297
340
  },
298
- [u, C]
299
- ), bt = w(
341
+ [k]
342
+ ), Ht = D(
300
343
  (e, t) => {
301
- const i = qe(e, t);
302
- i && (Y(hr(e, t)), u.some((b) => b.attribute === i.attribute && b.type === i.type) || C([...u, i]), M("variables"));
344
+ if (!st(e, t)) return;
345
+ const h = ie(Cr(e, t)), v = de(h), b = Ie(v, R.current);
346
+ k(b), P("variables");
303
347
  },
304
- [u, Y, C]
305
- ), q = Q(() => {
306
- const e = I.trim();
307
- return e ? H.test(e) ? mr(e) || u.some((t) => t.type === "user" && t.attribute === e) ? n("text.variables.customVariableNameDuplicate") : "" : n("text.variables.customVariableNameInvalid") : n("text.variables.customVariableNameRequired");
308
- }, [I, u]), pt = w(() => {
309
- const e = k.trim();
310
- if (_(!0), P(!0), q || e === "") return;
311
- const t = qe(I.trim(), "user", e);
312
- t && (Y(t.variable), C([...u, t]), pe(""), fe(""), _(!1), P(!1), M("variables"));
313
- }, [k, I, q, u, Y, C]), ft = Q(() => [{ id: "custom", items: u.filter((t) => t.type === "user").filter((t) => !ae.some((i) => i.items.some((b) => b.name === t.attribute))).map((t) => ({
314
- name: t.attribute,
315
- labelKey: t.attribute,
316
- kind: "user"
317
- })) }, ...ae], [u]), xt = (e) => e === "custom" ? "text.variables.groupCustom" : e === "contacts" ? "text.variables.groupContacts" : e === "email" ? "text.variables.groupEmail" : e === "organization" ? "text.variables.groupOrganization" : e === "date" ? "text.variables.groupDate" : "text.variables.groupLinks", E = $t(), gt = D === "desktop" || D === "mobile" ? D : "desktop", yt = v === "split" || v === "code" || v === "preview" ? v : "split";
318
- (Ee = (ve = E.palette) == null ? void 0 : ve.action) == null || Ee.selected, (Ve = (Te = E.palette) == null ? void 0 : Te.primary) == null || Ve.main, (we = (Ce = E.palette) == null ? void 0 : Ce.action) == null || we.selected, (He = (Se = E.palette) == null ? void 0 : Se.background) == null || He.paper, (De = (Le = E.palette) == null ? void 0 : Le.text) == null || De.primary, (Ie = (Me = E.palette) == null ? void 0 : Me.action) == null || Ie.hover;
319
- const A = {
348
+ [ie, k]
349
+ ), le = J(() => {
350
+ const e = _.trim();
351
+ return e ? A.test(e) ? Tr(e) || C.some((t) => t.type === "user" && t.attribute === e) ? l("text.variables.customVariableNameDuplicate") : "" : l("text.variables.customVariableNameInvalid") : l("text.variables.customVariableNameRequired");
352
+ }, [_, C]), St = D(() => {
353
+ const e = W.trim();
354
+ if (te(!0), re(!0), le || e === "") return;
355
+ const t = st(_.trim(), "user", e);
356
+ if (!t) return;
357
+ const r = ie(t.variable), h = de(r), v = Ie(h, R.current);
358
+ let b = -1;
359
+ for (let y = v.length - 1; y >= 0; y -= 1) {
360
+ const I = v[y];
361
+ if (I.type === t.type && I.attribute === t.attribute && I.default === "") {
362
+ b = y;
363
+ break;
364
+ }
365
+ }
366
+ k(
367
+ v.map(
368
+ (y, I) => I === b ? { ...y, default: t.default } : y
369
+ )
370
+ ), Me(""), De(""), te(!1), re(!1), P("variables");
371
+ }, [W, _, le, ie, k]), Mt = J(() => {
372
+ const e = /* @__PURE__ */ new Set();
373
+ return [{ id: "custom", items: C.filter((r) => r.type === "user").filter((r) => !Ee.some((h) => h.items.some((v) => v.name === r.attribute))).filter((r) => e.has(r.attribute) ? !1 : (e.add(r.attribute), !0)).map((r) => ({
374
+ name: r.attribute,
375
+ labelKey: r.attribute,
376
+ kind: "user"
377
+ })) }, ...Ee];
378
+ }, [C]), se = J(
379
+ () => C.filter((e) => e.type !== "system"),
380
+ [C]
381
+ ), Dt = (e) => e === "custom" ? "text.variables.groupCustom" : e === "contacts" ? "text.variables.groupContacts" : e === "email" ? "text.variables.groupEmail" : e === "organization" ? "text.variables.groupOrganization" : e === "date" ? "text.variables.groupDate" : "text.variables.groupLinks", V = er(), Lt = O === "desktop" || O === "mobile" ? O : "desktop", kt = H === "split" || H === "code" || H === "preview" ? H : "split";
382
+ ($e = (Re = V.palette) == null ? void 0 : Re.action) == null || $e.selected, (ze = (Ne = V.palette) == null ? void 0 : Ne.primary) == null || ze.main, (Pe = (Oe = V.palette) == null ? void 0 : Oe.action) == null || Pe.selected, (We = (_e = V.palette) == null ? void 0 : _e.background) == null || We.paper, (Ge = (je = V.palette) == null ? void 0 : je.text) == null || Ge.primary, (qe = (Ue = V.palette) == null ? void 0 : Ue.action) == null || qe.hover;
383
+ const j = {
320
384
  tooltip: {
321
385
  sx: {
322
386
  fontSize: "13px",
323
387
  fontWeight: 400,
324
388
  lineHeight: 1.45,
325
389
  maxWidth: 360,
326
- backgroundColor: Ge(((Ae = (ke = E.palette) == null ? void 0 : ke.text) == null ? void 0 : Ae.primary) ?? "#1F1F21", 0.9),
327
- color: ((Oe = (ze = E.palette) == null ? void 0 : ze.common) == null ? void 0 : Oe.white) ?? "#fff"
390
+ backgroundColor: ce(((Ke = (Ye = V.palette) == null ? void 0 : Ye.text) == null ? void 0 : Ke.primary) ?? "#1F1F21", 0.9),
391
+ color: ((Je = (Xe = V.palette) == null ? void 0 : Xe.common) == null ? void 0 : Je.white) ?? "#fff"
328
392
  }
329
393
  },
330
394
  arrow: {
331
- sx: { color: Ge(((Be = (Re = E.palette) == null ? void 0 : Re.text) == null ? void 0 : Be.primary) ?? "#1F1F21", 0.9) }
395
+ sx: { color: ce(((Ze = (Qe = V.palette) == null ? void 0 : Qe.text) == null ? void 0 : Ze.primary) ?? "#1F1F21", 0.9) }
396
+ }
397
+ }, xe = {
398
+ component: "div",
399
+ sx: {
400
+ mt: 0.5,
401
+ mx: 0,
402
+ minHeight: 18,
403
+ lineHeight: 1.5
332
404
  }
333
- }, ge = () => /* @__PURE__ */ m(
334
- d,
405
+ }, Ae = () => /* @__PURE__ */ f(
406
+ m,
335
407
  {
336
408
  sx: {
337
- height: g,
409
+ height: x,
338
410
  minHeight: 0,
339
411
  display: "flex",
340
412
  flexDirection: "column",
341
413
  position: "relative",
342
- borderRight: v === "split" ? "1px solid" : "none",
414
+ borderRight: H === "split" ? "1px solid" : "none",
343
415
  borderColor: "divider"
344
416
  },
345
417
  children: [
346
- /* @__PURE__ */ r(
347
- d,
418
+ /* @__PURE__ */ o(
419
+ m,
348
420
  {
349
421
  sx: {
350
422
  flex: 1,
@@ -374,16 +446,16 @@ function Hr({
374
446
  opacity: 1
375
447
  }
376
448
  },
377
- children: /* @__PURE__ */ r(
378
- Lt,
449
+ children: /* @__PURE__ */ o(
450
+ Ot,
379
451
  {
380
- value: x,
452
+ value: T,
381
453
  height: "100%",
382
- extensions: [Dt()],
383
- theme: de[ue] || Je,
384
- onChange: te,
454
+ extensions: [Pt()],
455
+ theme: Ce[He] || ut,
456
+ onChange: fe,
385
457
  onCreateEditor: (e) => {
386
- xe.current = e;
458
+ be.current = e;
387
459
  },
388
460
  basicSetup: {
389
461
  lineNumbers: !0,
@@ -395,13 +467,13 @@ function Hr({
395
467
  )
396
468
  }
397
469
  ),
398
- /* @__PURE__ */ r(
399
- ie,
470
+ /* @__PURE__ */ o(
471
+ ve,
400
472
  {
401
473
  size: "small",
402
474
  variant: "contained",
403
- startIcon: /* @__PURE__ */ r(fr, { fontSize: "small" }),
404
- onClick: dt,
475
+ startIcon: /* @__PURE__ */ o(Mr, { fontSize: "small" }),
476
+ onClick: Et,
405
477
  sx: {
406
478
  position: "absolute",
407
479
  right: 16,
@@ -410,33 +482,33 @@ function Hr({
410
482
  textTransform: "none",
411
483
  boxShadow: 3
412
484
  },
413
- children: n("common.save")
485
+ children: l("common.save")
414
486
  }
415
487
  )
416
488
  ]
417
489
  }
418
- ), vt = () => /* @__PURE__ */ r(d, { sx: {
419
- height: h,
490
+ ), Bt = () => /* @__PURE__ */ o(m, { sx: {
491
+ height: i,
420
492
  overflow: "auto",
421
493
  backgroundColor: "#F5F5F5",
422
- padding: D === "mobile" ? "32px 16px" : "16px",
494
+ padding: O === "mobile" ? "32px 16px" : "16px",
423
495
  display: "flex",
424
496
  justifyContent: "center"
425
- }, children: /* @__PURE__ */ r(
426
- d,
497
+ }, children: /* @__PURE__ */ o(
498
+ m,
427
499
  {
428
500
  sx: {
429
501
  width: "100%",
430
- maxWidth: D === "mobile" ? "370px" : "100%",
431
- height: D === "mobile" ? "800px" : "100%",
502
+ maxWidth: O === "mobile" ? "370px" : "100%",
503
+ height: O === "mobile" ? "800px" : "100%",
432
504
  border: "none",
433
505
  overflow: "hidden"
434
506
  },
435
- children: /* @__PURE__ */ r(
507
+ children: /* @__PURE__ */ o(
436
508
  "iframe",
437
509
  {
438
- ref: W,
439
- srcDoc: U,
510
+ ref: oe,
511
+ srcDoc: ne,
440
512
  style: {
441
513
  width: "100%",
442
514
  height: "100%",
@@ -448,33 +520,38 @@ function Hr({
448
520
  }
449
521
  )
450
522
  }
451
- ) }), Et = () => /* @__PURE__ */ m(
452
- d,
523
+ ) }), At = () => /* @__PURE__ */ f(
524
+ m,
453
525
  {
526
+ ref: Le,
454
527
  sx: {
455
- height: h,
528
+ flex: 1,
529
+ height: "100%",
530
+ minHeight: 0,
456
531
  overflow: "auto",
457
532
  backgroundColor: "background.paper",
458
- p: 2
533
+ px: 2,
534
+ pt: 2,
535
+ pb: 6
459
536
  },
460
537
  children: [
461
- /* @__PURE__ */ r(d, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 1, mb: 1.5 }, children: /* @__PURE__ */ m(d, { sx: { minWidth: 0 }, children: [
462
- /* @__PURE__ */ m(d, { sx: { display: "flex", alignItems: "center", gap: 0.75 }, children: [
463
- /* @__PURE__ */ r(S, { variant: "subtitle1", sx: { fontWeight: 700 }, children: n("htmlEditor.variables.title") }),
464
- /* @__PURE__ */ r(O, { title: n("htmlEditor.variables.help"), arrow: !0, slotProps: A, children: /* @__PURE__ */ r(d, { component: "span", sx: { display: "inline-flex", color: "text.secondary", cursor: "help" }, children: /* @__PURE__ */ r(gr, { fontSize: "small" }) }) })
538
+ /* @__PURE__ */ o(m, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 1, mb: 1.5 }, children: /* @__PURE__ */ f(m, { sx: { minWidth: 0 }, children: [
539
+ /* @__PURE__ */ f(m, { sx: { display: "flex", alignItems: "center", gap: 0.75 }, children: [
540
+ /* @__PURE__ */ o(B, { variant: "subtitle1", sx: { fontWeight: 700 }, children: l("htmlEditor.variables.title") }),
541
+ /* @__PURE__ */ o(G, { title: l("htmlEditor.variables.help"), arrow: !0, slotProps: j, children: /* @__PURE__ */ o(m, { component: "span", sx: { display: "inline-flex", color: "text.secondary", cursor: "help" }, children: /* @__PURE__ */ o(Lr, { fontSize: "small" }) }) })
465
542
  ] }),
466
- /* @__PURE__ */ r(S, { variant: "body2", color: "text.secondary", children: n("htmlEditor.variables.scanHint") })
543
+ /* @__PURE__ */ o(B, { component: "div", variant: "body2", color: "text.secondary", children: l("htmlEditor.variables.scanHint") })
467
544
  ] }) }),
468
- /* @__PURE__ */ r(d, { sx: { mb: 2 }, children: ft.map((e) => {
469
- const t = nt === e.id;
470
- return /* @__PURE__ */ m(
471
- Gt,
545
+ /* @__PURE__ */ o(m, { sx: { mb: 2 }, children: Mt.map((e) => {
546
+ const t = yt === e.id;
547
+ return /* @__PURE__ */ f(
548
+ nr,
472
549
  {
473
550
  disableGutters: !0,
474
551
  square: !0,
475
552
  elevation: 0,
476
553
  expanded: t,
477
- onChange: (i, b) => st(b ? e.id : null),
554
+ onChange: (r, h) => It(h ? e.id : null),
478
555
  sx: {
479
556
  "&:before": { display: "none" },
480
557
  border: 1,
@@ -484,64 +561,66 @@ function Hr({
484
561
  mb: 1
485
562
  },
486
563
  children: [
487
- /* @__PURE__ */ r(
488
- Kt,
564
+ /* @__PURE__ */ o(
565
+ ir,
489
566
  {
490
- expandIcon: /* @__PURE__ */ r(xr, { fontSize: "small" }),
567
+ expandIcon: /* @__PURE__ */ o(Dr, { fontSize: "small" }),
491
568
  sx: {
492
569
  minHeight: 44,
493
570
  "& .MuiAccordionSummary-content": { my: 1 }
494
571
  },
495
- children: /* @__PURE__ */ r(S, { variant: "body2", color: "text.primary", children: n(xt(e.id)) })
572
+ children: /* @__PURE__ */ o(B, { component: "div", variant: "body2", color: "text.primary", children: l(Dt(e.id)) })
496
573
  }
497
574
  ),
498
- /* @__PURE__ */ m(Ut, { sx: { pt: 0, pb: 1.25 }, children: [
499
- e.id === "custom" && /* @__PURE__ */ m(d, { sx: { mb: 1 }, children: [
500
- /* @__PURE__ */ r(
501
- le,
575
+ /* @__PURE__ */ f(lr, { sx: { pt: 0, pb: 1.25 }, children: [
576
+ e.id === "custom" && /* @__PURE__ */ f(m, { sx: { mb: 1 }, children: [
577
+ /* @__PURE__ */ o(
578
+ ye,
502
579
  {
503
580
  size: "small",
504
581
  fullWidth: !0,
505
- label: n("text.variables.customVariableName"),
506
- value: I,
582
+ label: l("text.variables.customVariableName"),
583
+ value: _,
507
584
  placeholder: "e.g. order_id",
508
- onChange: (i) => {
509
- pe(i.target.value), !Z && i.target.value.trim() !== "" && _(!0);
585
+ onChange: (r) => {
586
+ Me(r.target.value), !me && r.target.value.trim() !== "" && te(!0);
510
587
  },
511
588
  onBlur: () => {
512
- I.trim() !== "" && _(!0);
589
+ _.trim() !== "" && te(!0);
513
590
  },
514
- error: Z && !!q,
515
- helperText: Z && q || " ",
591
+ error: me && !!le,
592
+ helperText: me && le || " ",
593
+ FormHelperTextProps: xe,
516
594
  sx: { mb: 1 }
517
595
  }
518
596
  ),
519
- /* @__PURE__ */ r(
520
- le,
597
+ /* @__PURE__ */ o(
598
+ ye,
521
599
  {
522
600
  size: "small",
523
601
  fullWidth: !0,
524
- label: n("text.variables.defaultValueLabel"),
525
- value: k,
526
- placeholder: n("text.variables.defaultPlaceholder"),
527
- onChange: (i) => {
528
- fe(i.target.value), !ee && i.target.value.trim() !== "" && P(!0);
602
+ label: l("text.variables.defaultValueLabel"),
603
+ value: W,
604
+ placeholder: l("text.variables.defaultPlaceholder"),
605
+ onChange: (r) => {
606
+ De(r.target.value), !he && r.target.value.trim() !== "" && re(!0);
529
607
  },
530
608
  onBlur: () => {
531
- k.trim() !== "" && P(!0);
609
+ W.trim() !== "" && re(!0);
532
610
  },
533
- error: ee && k.trim() === "",
534
- helperText: ee && k.trim() === "" ? n("text.variables.defaultRequired") : " "
611
+ error: he && W.trim() === "",
612
+ helperText: he && W.trim() === "" ? l("text.variables.defaultRequired") : " ",
613
+ FormHelperTextProps: xe
535
614
  }
536
615
  ),
537
- /* @__PURE__ */ r(
538
- ie,
616
+ /* @__PURE__ */ o(
617
+ ve,
539
618
  {
540
619
  fullWidth: !0,
541
620
  size: "small",
542
621
  variant: "outlined",
543
- startIcon: /* @__PURE__ */ r(br, { fontSize: "small" }),
544
- onClick: pt,
622
+ startIcon: /* @__PURE__ */ o(Hr, { fontSize: "small" }),
623
+ onClick: St,
545
624
  sx: {
546
625
  justifyContent: "center",
547
626
  borderColor: "divider",
@@ -549,28 +628,37 @@ function Hr({
549
628
  color: "text.secondary",
550
629
  textTransform: "none"
551
630
  },
552
- children: n("text.variables.addCustomVariable")
631
+ children: l("text.variables.addCustomVariable")
553
632
  }
554
633
  )
555
634
  ] }),
556
- e.items.length > 0 && /* @__PURE__ */ r(d, { sx: { display: "grid", gap: 0.75 }, children: e.items.map((i) => /* @__PURE__ */ r(
557
- ie,
635
+ e.items.length > 0 && /* @__PURE__ */ o(m, { sx: { display: "grid", gap: 0.75 }, children: e.items.map((r) => /* @__PURE__ */ o(
636
+ ve,
558
637
  {
559
638
  size: "small",
560
639
  variant: "outlined",
561
- onClick: () => bt(i.name, i.kind),
640
+ onClick: () => Ht(r.name, r.kind),
562
641
  sx: {
563
642
  justifyContent: "flex-start",
564
643
  borderColor: "divider",
565
644
  color: "text.secondary",
566
645
  textTransform: "none"
567
646
  },
568
- children: /* @__PURE__ */ m(d, { sx: { textAlign: "left", minWidth: 0 }, children: [
569
- /* @__PURE__ */ r(S, { variant: "body2", color: "text.primary", children: e.id === "custom" ? i.name : n(i.labelKey) }),
570
- /* @__PURE__ */ r(S, { variant: "caption", color: "text.secondary", sx: { fontFamily: "monospace" }, children: i.kind === "builtin" ? `{%${i.name}%}` : `{{${i.name}}}` })
647
+ children: /* @__PURE__ */ f(m, { sx: { textAlign: "left", minWidth: 0 }, children: [
648
+ /* @__PURE__ */ o(B, { component: "div", variant: "body2", color: "text.primary", children: e.id === "custom" ? r.name : l(r.labelKey) }),
649
+ /* @__PURE__ */ o(
650
+ B,
651
+ {
652
+ component: "div",
653
+ variant: "caption",
654
+ color: "text.secondary",
655
+ sx: { fontFamily: "monospace" },
656
+ children: r.kind === "builtin" ? `{%${r.name}%}` : `{{${r.name}}}`
657
+ }
658
+ )
571
659
  ] })
572
660
  },
573
- `${e.id}:${i.name}`
661
+ `${e.id}:${r.name}`
574
662
  )) })
575
663
  ] })
576
664
  ]
@@ -578,11 +666,11 @@ function Hr({
578
666
  e.id
579
667
  );
580
668
  }) }),
581
- /* @__PURE__ */ r(Yt, { sx: { my: 2 } }),
582
- /* @__PURE__ */ r(S, { variant: "subtitle2", sx: { mb: 1 }, children: n("htmlEditor.variables.detected") }),
583
- /* @__PURE__ */ r(S, { variant: "body2", color: "text.secondary", sx: { mb: 1.25 }, children: n("htmlEditor.variables.defaultHelp") }),
584
- u.length === 0 ? /* @__PURE__ */ r(
585
- d,
669
+ /* @__PURE__ */ o(sr, { sx: { my: 2 } }),
670
+ /* @__PURE__ */ o(B, { component: "div", ref: ke, variant: "subtitle2", sx: { mb: 0.5 }, children: l("htmlEditor.variables.detected") }),
671
+ /* @__PURE__ */ o(B, { component: "div", variant: "caption", color: "text.secondary", sx: { display: "block", mb: 1 }, children: l("htmlEditor.variables.defaultHelp") }),
672
+ se.length === 0 ? /* @__PURE__ */ o(
673
+ m,
586
674
  {
587
675
  sx: {
588
676
  border: "1px dashed",
@@ -593,50 +681,81 @@ function Hr({
593
681
  fontSize: 14,
594
682
  textAlign: "center"
595
683
  },
596
- children: n("htmlEditor.variables.empty")
684
+ children: l("htmlEditor.variables.empty")
597
685
  }
598
- ) : /* @__PURE__ */ r(d, { sx: { display: "grid", gap: 1.5 }, children: u.map((e) => {
599
- const t = lt && e.type === "user" && e.default.trim() === "";
600
- return /* @__PURE__ */ m(
601
- d,
686
+ ) : /* @__PURE__ */ o(m, { sx: { display: "grid", gap: 0.25 }, children: se.map((e, t) => {
687
+ const r = gt && e.type === "user" && e.default.trim() === "", h = se.filter((b) => b.type === e.type && b.attribute === e.attribute).length, v = se.slice(0, t + 1).filter((b) => b.type === e.type && b.attribute === e.attribute).length;
688
+ return /* @__PURE__ */ f(
689
+ m,
602
690
  {
603
691
  sx: {
604
692
  display: "grid",
605
- gap: 0.75,
606
- p: 1.25,
693
+ gridTemplateColumns: { xs: "1fr", sm: "minmax(150px, 42%) 1fr" },
694
+ alignItems: r ? "flex-start" : "center",
695
+ gap: 1,
696
+ px: 1,
697
+ py: 0.75,
607
698
  border: "1px solid",
608
- borderColor: t ? "error.main" : "divider",
609
- borderRadius: 1
699
+ borderColor: r ? "error.main" : "transparent",
700
+ borderRadius: 1,
701
+ borderBottomColor: r ? "error.main" : "divider",
702
+ backgroundColor: r ? ce(V.palette.error.main, 0.04) : "transparent",
703
+ transition: "background-color 120ms ease, border-color 120ms ease",
704
+ "&:hover": {
705
+ backgroundColor: r ? ce(V.palette.error.main, 0.04) : "action.hover",
706
+ borderColor: r ? "error.main" : "divider"
707
+ }
610
708
  },
611
709
  children: [
612
- /* @__PURE__ */ r(S, { variant: "body2", sx: { fontFamily: "monospace", wordBreak: "break-all" }, children: e.variable }),
613
- /* @__PURE__ */ r(
614
- le,
710
+ /* @__PURE__ */ o(
711
+ B,
712
+ {
713
+ component: "div",
714
+ variant: "body2",
715
+ sx: {
716
+ fontFamily: "monospace",
717
+ fontSize: 13,
718
+ lineHeight: 1.35,
719
+ wordBreak: "break-all",
720
+ color: r ? "error.main" : "text.primary"
721
+ },
722
+ children: h > 1 ? `${e.variable} (${v})` : e.variable
723
+ }
724
+ ),
725
+ /* @__PURE__ */ o(
726
+ ye,
615
727
  {
616
728
  size: "small",
617
729
  fullWidth: !0,
618
730
  disabled: e.type === "system",
619
731
  value: e.default,
620
- label: n("text.variables.defaultValueLabel"),
621
- placeholder: e.type === "system" ? n("htmlEditor.variables.systemDefault") : n("text.variables.defaultPlaceholder"),
622
- error: t,
623
- helperText: t ? n("text.variables.defaultRequired") : " ",
624
- onChange: (i) => ht(e.attribute, e.type, i.target.value)
732
+ label: r ? l("text.variables.defaultValueLabel") : void 0,
733
+ placeholder: e.type === "system" ? l("htmlEditor.variables.systemDefault") : l("text.variables.defaultPlaceholder"),
734
+ error: r,
735
+ helperText: r ? l("text.variables.defaultRequired") : void 0,
736
+ FormHelperTextProps: xe,
737
+ onChange: (b) => wt(e.variableInstanceId, b.target.value),
738
+ sx: {
739
+ "& .MuiInputBase-input": {
740
+ py: 0.75,
741
+ fontSize: 13
742
+ }
743
+ }
625
744
  }
626
745
  )
627
746
  ]
628
747
  },
629
- `${e.type}:${e.attribute}`
748
+ e.variableInstanceId || `${e.type}:${e.attribute}:${e.id}`
630
749
  );
631
750
  }) })
632
751
  ]
633
752
  }
634
- ), ye = () => /* @__PURE__ */ m(d, { sx: { height: h, minHeight: 0, display: "flex", flexDirection: "column" }, children: [
635
- /* @__PURE__ */ m(
636
- jt,
753
+ ), Fe = () => /* @__PURE__ */ f(m, { sx: { height: i, minHeight: 0, display: "flex", flexDirection: "column" }, children: [
754
+ /* @__PURE__ */ f(
755
+ ar,
637
756
  {
638
- value: he,
639
- onChange: (e, t) => M(t),
757
+ value: ee,
758
+ onChange: (e, t) => P(t),
640
759
  sx: {
641
760
  minHeight: 40,
642
761
  borderBottom: "1px solid",
@@ -648,15 +767,15 @@ function Hr({
648
767
  }
649
768
  },
650
769
  children: [
651
- /* @__PURE__ */ r(je, { value: "preview", label: n("htmlEditor.tabs.preview") }),
652
- /* @__PURE__ */ r(je, { value: "variables", label: n("htmlEditor.tabs.variables") })
770
+ /* @__PURE__ */ o(ot, { value: "preview", label: l("htmlEditor.tabs.preview") }),
771
+ /* @__PURE__ */ o(ot, { value: "variables", label: l("htmlEditor.tabs.variables") })
653
772
  ]
654
773
  }
655
774
  ),
656
- /* @__PURE__ */ r(d, { sx: { flex: 1, minHeight: 0, overflow: "hidden" }, children: he === "preview" ? vt() : Et() })
775
+ /* @__PURE__ */ o(m, { sx: { flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }, children: ee === "preview" ? Bt() : At() })
657
776
  ] });
658
- return /* @__PURE__ */ m(
659
- d,
777
+ return /* @__PURE__ */ f(
778
+ m,
660
779
  {
661
780
  sx: {
662
781
  display: "flex",
@@ -665,11 +784,11 @@ function Hr({
665
784
  width: "100%",
666
785
  minHeight: 0,
667
786
  minWidth: 0,
668
- ...p
787
+ ...u
669
788
  },
670
789
  children: [
671
- f && /* @__PURE__ */ m(
672
- d,
790
+ p && /* @__PURE__ */ f(
791
+ m,
673
792
  {
674
793
  sx: {
675
794
  display: "flex",
@@ -681,55 +800,55 @@ function Hr({
681
800
  backgroundColor: "background.paper"
682
801
  },
683
802
  children: [
684
- /* @__PURE__ */ m(d, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
685
- /* @__PURE__ */ m(
686
- _e,
803
+ /* @__PURE__ */ f(m, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
804
+ /* @__PURE__ */ f(
805
+ et,
687
806
  {
688
- value: yt,
807
+ value: kt,
689
808
  exclusive: !0,
690
- onChange: ut,
809
+ onChange: Tt,
691
810
  size: "small",
692
- "aria-label": n("htmlEditor.mode.split"),
811
+ "aria-label": l("htmlEditor.mode.split"),
693
812
  children: [
694
- /* @__PURE__ */ r(O, { title: n("htmlEditor.tooltips.splitView"), arrow: !0, slotProps: A, children: /* @__PURE__ */ r(
695
- F,
813
+ /* @__PURE__ */ o(G, { title: l("htmlEditor.tooltips.splitView"), arrow: !0, slotProps: j, children: /* @__PURE__ */ o(
814
+ Q,
696
815
  {
697
816
  value: "split",
698
- "aria-label": n("htmlEditor.mode.split"),
699
- children: /* @__PURE__ */ r(vr, { fontSize: "small" })
817
+ "aria-label": l("htmlEditor.mode.split"),
818
+ children: /* @__PURE__ */ o(Br, { fontSize: "small" })
700
819
  }
701
820
  ) }),
702
- /* @__PURE__ */ r(O, { title: n("htmlEditor.tooltips.codeOnly"), arrow: !0, slotProps: A, children: /* @__PURE__ */ r(
703
- F,
821
+ /* @__PURE__ */ o(G, { title: l("htmlEditor.tooltips.codeOnly"), arrow: !0, slotProps: j, children: /* @__PURE__ */ o(
822
+ Q,
704
823
  {
705
824
  value: "code",
706
- "aria-label": n("htmlEditor.mode.code"),
707
- children: /* @__PURE__ */ r(pr, { fontSize: "small" })
825
+ "aria-label": l("htmlEditor.mode.code"),
826
+ children: /* @__PURE__ */ o(Sr, { fontSize: "small" })
708
827
  }
709
828
  ) }),
710
- /* @__PURE__ */ r(O, { title: n("htmlEditor.tooltips.previewOnly"), arrow: !0, slotProps: A, children: /* @__PURE__ */ r(
711
- F,
829
+ /* @__PURE__ */ o(G, { title: l("htmlEditor.tooltips.previewOnly"), arrow: !0, slotProps: j, children: /* @__PURE__ */ o(
830
+ Q,
712
831
  {
713
832
  value: "preview",
714
- "aria-label": n("htmlEditor.mode.preview"),
715
- children: /* @__PURE__ */ r(yr, { fontSize: "small" })
833
+ "aria-label": l("htmlEditor.mode.preview"),
834
+ children: /* @__PURE__ */ o(kr, { fontSize: "small" })
716
835
  }
717
836
  ) })
718
837
  ]
719
838
  }
720
839
  ),
721
- /* @__PURE__ */ m(_t, { size: "small", sx: { minWidth: 140 }, children: [
722
- /* @__PURE__ */ r(Pt, { id: "theme-select-label", children: n("htmlEditor.theme") }),
723
- /* @__PURE__ */ m(
724
- Wt,
840
+ /* @__PURE__ */ f(tr, { size: "small", sx: { minWidth: 140 }, children: [
841
+ /* @__PURE__ */ o(rr, { id: "theme-select-label", children: l("htmlEditor.theme") }),
842
+ /* @__PURE__ */ f(
843
+ or,
725
844
  {
726
845
  labelId: "theme-select-label",
727
846
  id: "theme-select",
728
- value: ue,
729
- label: n("htmlEditor.theme"),
847
+ value: He,
848
+ label: l("htmlEditor.theme"),
730
849
  onChange: (e) => {
731
850
  const t = e.target.value;
732
- it(t), console.log("theme changed to", t), Sr(t);
851
+ xt(t), zr(t);
733
852
  },
734
853
  sx: {
735
854
  // fontSize: '0.875rem',
@@ -738,38 +857,38 @@ function Hr({
738
857
  }
739
858
  },
740
859
  children: [
741
- /* @__PURE__ */ r(Pe, { children: n("htmlEditor.lightThemes") }),
742
- Object.entries(Vr).map(([e, t]) => /* @__PURE__ */ r(We, { value: e, children: t }, e)),
743
- /* @__PURE__ */ r(Pe, { children: n("htmlEditor.darkThemes") }),
744
- Object.entries(Cr).map(([e, t]) => /* @__PURE__ */ r(We, { value: e, children: t }, e))
860
+ /* @__PURE__ */ o(tt, { children: l("htmlEditor.lightThemes") }),
861
+ Object.entries(Rr).map(([e, t]) => /* @__PURE__ */ o(rt, { value: e, children: t }, e)),
862
+ /* @__PURE__ */ o(tt, { children: l("htmlEditor.darkThemes") }),
863
+ Object.entries($r).map(([e, t]) => /* @__PURE__ */ o(rt, { value: e, children: t }, e))
745
864
  ]
746
865
  }
747
866
  )
748
867
  ] })
749
868
  ] }),
750
- /* @__PURE__ */ r(d, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: v !== "code" && /* @__PURE__ */ m(
751
- _e,
869
+ /* @__PURE__ */ o(m, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: H !== "code" && /* @__PURE__ */ f(
870
+ et,
752
871
  {
753
- value: gt,
872
+ value: Lt,
754
873
  exclusive: !0,
755
- onChange: mt,
874
+ onChange: Ct,
756
875
  size: "small",
757
- "aria-label": n("htmlEditor.device.desktop"),
876
+ "aria-label": l("htmlEditor.device.desktop"),
758
877
  children: [
759
- /* @__PURE__ */ r(O, { title: n("htmlEditor.tooltips.desktopView"), arrow: !0, slotProps: A, children: /* @__PURE__ */ r(
760
- F,
878
+ /* @__PURE__ */ o(G, { title: l("htmlEditor.tooltips.desktopView"), arrow: !0, slotProps: j, children: /* @__PURE__ */ o(
879
+ Q,
761
880
  {
762
881
  value: "desktop",
763
- "aria-label": n("htmlEditor.device.desktop"),
764
- children: /* @__PURE__ */ r(Er, { fontSize: "small" })
882
+ "aria-label": l("htmlEditor.device.desktop"),
883
+ children: /* @__PURE__ */ o(Ar, { fontSize: "small" })
765
884
  }
766
885
  ) }),
767
- /* @__PURE__ */ r(O, { title: n("htmlEditor.tooltips.mobileView"), arrow: !0, slotProps: A, children: /* @__PURE__ */ r(
768
- F,
886
+ /* @__PURE__ */ o(G, { title: l("htmlEditor.tooltips.mobileView"), arrow: !0, slotProps: j, children: /* @__PURE__ */ o(
887
+ Q,
769
888
  {
770
889
  value: "mobile",
771
- "aria-label": n("htmlEditor.device.mobile"),
772
- children: /* @__PURE__ */ r(Tr, { fontSize: "small" })
890
+ "aria-label": l("htmlEditor.device.mobile"),
891
+ children: /* @__PURE__ */ o(Fr, { fontSize: "small" })
773
892
  }
774
893
  ) })
775
894
  ]
@@ -778,8 +897,8 @@ function Hr({
778
897
  ]
779
898
  }
780
899
  ),
781
- /* @__PURE__ */ m(
782
- d,
900
+ /* @__PURE__ */ f(
901
+ m,
783
902
  {
784
903
  sx: {
785
904
  flex: 1,
@@ -789,12 +908,12 @@ function Hr({
789
908
  overflow: "hidden"
790
909
  },
791
910
  children: [
792
- v === "split" && /* @__PURE__ */ m(wt, { children: [
793
- /* @__PURE__ */ r(d, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: ge() }),
794
- /* @__PURE__ */ r(d, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: ye() })
911
+ H === "split" && /* @__PURE__ */ f(Nt, { children: [
912
+ /* @__PURE__ */ o(m, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: Ae() }),
913
+ /* @__PURE__ */ o(m, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: Fe() })
795
914
  ] }),
796
- v === "code" && /* @__PURE__ */ r(d, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: ge() }),
797
- v === "preview" && /* @__PURE__ */ r(d, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: ye() })
915
+ H === "code" && /* @__PURE__ */ o(m, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: Ae() }),
916
+ H === "preview" && /* @__PURE__ */ o(m, { sx: { flex: 1, minHeight: 0, minWidth: 0, overflow: "hidden" }, children: Fe() })
798
917
  ]
799
918
  }
800
919
  )
@@ -802,9 +921,24 @@ function Hr({
802
921
  }
803
922
  );
804
923
  }
805
- const Lr = St(Hr);
806
- Lr.displayName = "HtmlEditor";
924
+ const bt = dt(Or);
925
+ bt.displayName = "HtmlEditorContent";
926
+ const Pr = dt((a, n) => /* @__PURE__ */ o(Qt, { theme: vr, children: /* @__PURE__ */ o(
927
+ Zt,
928
+ {
929
+ sx: {
930
+ height: "100%",
931
+ width: "100%",
932
+ minHeight: 0,
933
+ minWidth: 0,
934
+ display: "flex",
935
+ flexDirection: "column"
936
+ },
937
+ children: /* @__PURE__ */ o(bt, { ref: n, ...a })
938
+ }
939
+ ) }));
940
+ Pr.displayName = "HtmlEditor";
807
941
  export {
808
- Lr as HtmlEditor,
809
- Lr as default
942
+ Pr as HtmlEditor,
943
+ Pr as default
810
944
  };