@editora/plugins 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/approval-workflow.cjs.js +14 -14
- package/dist/approval-workflow.esm.js +265 -262
- package/dist/blockquote.cjs.js +1 -1
- package/dist/blockquote.esm.js +177 -15
- package/dist/blocks-library.cjs.js +6 -6
- package/dist/blocks-library.esm.js +95 -92
- package/dist/bold.cjs.js +1 -1
- package/dist/bold.esm.js +10 -6
- package/dist/capitalization.cjs.js +1 -1
- package/dist/capitalization.esm.js +124 -44
- package/dist/checklist.cjs.js +1 -1
- package/dist/checklist.esm.js +251 -191
- package/dist/citations.cjs.js +4 -4
- package/dist/citations.esm.js +131 -128
- package/dist/clear-formatting.cjs.js +1 -1
- package/dist/clear-formatting.esm.js +68 -36
- package/dist/code.cjs.js +27 -21
- package/dist/code.esm.js +72 -43
- package/dist/content-rules.cjs.js +5 -5
- package/dist/content-rules.esm.js +104 -101
- package/dist/data-binding.cjs.js +3 -3
- package/dist/data-binding.esm.js +51 -48
- package/dist/direction.cjs.js +1 -1
- package/dist/direction.esm.js +97 -74
- package/dist/doc-schema.cjs.js +4 -4
- package/dist/doc-schema.esm.js +104 -101
- package/dist/embed-iframe.cjs.js +21 -4
- package/dist/embed-iframe.esm.js +279 -116
- package/dist/heading.cjs.js +1 -1
- package/dist/heading.esm.js +239 -56
- package/dist/history.cjs.js +1 -1
- package/dist/history.esm.js +74 -89
- package/dist/inlineFormatting-DOYOJdnD.js +1 -0
- package/dist/inlineFormatting-DuVTGXYG.mjs +95 -0
- package/dist/italic.cjs.js +1 -1
- package/dist/italic.esm.js +12 -8
- package/dist/math.cjs.js +27 -21
- package/dist/math.esm.js +218 -146
- package/dist/merge-tag.cjs.js +8 -2
- package/dist/merge-tag.esm.js +130 -111
- package/dist/pii-redaction.cjs.js +6 -6
- package/dist/pii-redaction.esm.js +169 -166
- package/dist/smart-paste.cjs.js +5 -5
- package/dist/smart-paste.esm.js +120 -117
- package/dist/special-characters.cjs.js +6 -10
- package/dist/special-characters.esm.js +97 -75
- package/dist/strikethrough.cjs.js +1 -1
- package/dist/strikethrough.esm.js +11 -25
- package/dist/translation-workflow.cjs.js +7 -7
- package/dist/translation-workflow.esm.js +103 -100
- package/dist/underline.cjs.js +1 -1
- package/dist/underline.esm.js +7 -3
- package/package.json +3 -3
package/dist/math.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const O = {
|
|
2
2
|
latex: [
|
|
3
3
|
{ name: "Fraction", formula: "\\frac{a}{b}", description: "Simple fraction" },
|
|
4
4
|
{ name: "Square Root", formula: "\\sqrt{x}", description: "Square root" },
|
|
@@ -19,46 +19,117 @@ const F = {
|
|
|
19
19
|
{ name: "Parentheses", formula: '<mfenced open="(" close=")"><mi>a</mi><mo>+</mo><mi>b</mi></mfenced>', description: "Grouped expression" }
|
|
20
20
|
]
|
|
21
21
|
};
|
|
22
|
-
let
|
|
23
|
-
const
|
|
22
|
+
let T = null, B = null, H = !1, y = null, m = null;
|
|
23
|
+
const k = '[data-theme="dark"], .dark, .editora-theme-dark', K = () => new Promise((e, t) => {
|
|
24
24
|
if (window.katex) {
|
|
25
|
-
|
|
25
|
+
e(window.katex);
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
window.katex && (clearInterval(
|
|
28
|
+
if (H) {
|
|
29
|
+
const s = setInterval(() => {
|
|
30
|
+
window.katex && (clearInterval(s), e(window.katex));
|
|
31
31
|
}, 100);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
}),
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
return (
|
|
44
|
-
},
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
H = !0;
|
|
35
|
+
const r = document.createElement("link");
|
|
36
|
+
r.rel = "stylesheet", r.href = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css", document.head.appendChild(r);
|
|
37
|
+
const l = document.createElement("script");
|
|
38
|
+
l.src = "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js", l.onload = () => e(window.katex), l.onerror = t, document.head.appendChild(l);
|
|
39
|
+
}), N = () => {
|
|
40
|
+
const e = window.getSelection();
|
|
41
|
+
if (!e || e.rangeCount === 0) return null;
|
|
42
|
+
const t = e.getRangeAt(0).startContainer;
|
|
43
|
+
return (t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement)?.closest(".rte-content, .editora-content") || null;
|
|
44
|
+
}, U = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null, R = (e) => U(e)?.closest('.rte-content, .editora-content, [contenteditable="true"]') || null, W = (e, t, r) => {
|
|
45
|
+
if (t !== r) {
|
|
46
|
+
if (typeof window.execEditorCommand == "function") {
|
|
47
|
+
window.execEditorCommand("recordDomTransaction", e, t, r);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (typeof window.executeEditorCommand == "function")
|
|
51
|
+
try {
|
|
52
|
+
window.executeEditorCommand("recordDomTransaction", { editor: e, beforeHTML: t, afterHTML: r });
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, G = (e) => {
|
|
57
|
+
if (!(e instanceof Element)) return null;
|
|
58
|
+
const t = e.closest(".math-formula, .math-block");
|
|
59
|
+
return t instanceof HTMLElement ? t : null;
|
|
60
|
+
}, h = () => {
|
|
61
|
+
m && (m.classList.remove("math-object-selected"), m.removeAttribute("data-rte-selected-object"), m = null);
|
|
62
|
+
}, X = (e) => {
|
|
63
|
+
if (m === e) return;
|
|
64
|
+
h(), m = e, e.classList.add("math-object-selected"), e.setAttribute("data-rte-selected-object", "true");
|
|
65
|
+
const t = window.getSelection();
|
|
66
|
+
if (!t) return;
|
|
67
|
+
const r = document.createRange();
|
|
68
|
+
r.selectNode(e), t.removeAllRanges(), t.addRange(r);
|
|
69
|
+
}, Z = (e, t) => {
|
|
70
|
+
const r = window.getSelection();
|
|
71
|
+
if (!r) return;
|
|
72
|
+
const l = document.createRange();
|
|
73
|
+
t && t.parentNode === e ? l.setStartBefore(t) : (l.selectNodeContents(e), l.collapse(!1)), l.collapse(!0), r.removeAllRanges(), r.addRange(l);
|
|
74
|
+
}, Q = (e) => {
|
|
75
|
+
if (e.childNodes.length > 0) return;
|
|
76
|
+
const t = document.createElement("p");
|
|
77
|
+
t.appendChild(document.createElement("br")), e.appendChild(t);
|
|
78
|
+
}, J = () => {
|
|
79
|
+
if (!m || !m.isConnected)
|
|
80
|
+
return h(), !1;
|
|
81
|
+
const e = m, t = R(e);
|
|
82
|
+
if (!t)
|
|
83
|
+
return h(), !1;
|
|
84
|
+
const r = t.innerHTML, l = e.nextSibling;
|
|
85
|
+
e.remove(), Q(t), h(), Z(t, l);
|
|
86
|
+
const s = t.innerHTML;
|
|
87
|
+
return W(t, r, s), t.dispatchEvent(new window.Event("input", { bubbles: !0 })), r !== s;
|
|
88
|
+
}, V = () => {
|
|
89
|
+
if (document.getElementById("math-object-selection-styles")) return;
|
|
90
|
+
const e = document.createElement("style");
|
|
91
|
+
e.id = "math-object-selection-styles", e.textContent = `
|
|
92
|
+
.math-object-selected {
|
|
93
|
+
outline: 2px solid #2563eb !important;
|
|
94
|
+
outline-offset: 2px;
|
|
95
|
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
|
|
96
|
+
}
|
|
97
|
+
`, document.head.appendChild(e);
|
|
98
|
+
}, Y = () => {
|
|
99
|
+
typeof window > "u" || window.__mathPluginObjectSelectionInitialized || (window.__mathPluginObjectSelectionInitialized = !0, V(), document.addEventListener("pointerdown", (e) => {
|
|
100
|
+
const t = G(e.target);
|
|
101
|
+
if (!t) {
|
|
102
|
+
e.target?.closest?.(".math-dialog-overlay") || h();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
e.preventDefault(), R(t)?.focus(), X(t);
|
|
106
|
+
}, !0), document.addEventListener("keydown", (e) => {
|
|
107
|
+
if (m) {
|
|
108
|
+
if (e.key === "Escape") {
|
|
109
|
+
h();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
e.key !== "Backspace" && e.key !== "Delete" || (e.preventDefault(), e.stopPropagation(), J());
|
|
113
|
+
}
|
|
114
|
+
}, !0));
|
|
115
|
+
}, ee = (e) => {
|
|
116
|
+
if ((e || N())?.closest(k)) return !0;
|
|
117
|
+
const r = window.getSelection();
|
|
118
|
+
if (r && r.rangeCount > 0) {
|
|
119
|
+
const s = r.getRangeAt(0).startContainer;
|
|
120
|
+
if ((s.nodeType === Node.ELEMENT_NODE ? s : s.parentElement)?.closest(k)) return !0;
|
|
50
121
|
}
|
|
51
|
-
return document.activeElement?.closest(
|
|
52
|
-
},
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
|
|
122
|
+
return document.activeElement?.closest(k) ? !0 : document.body.matches(k) || document.documentElement.matches(k);
|
|
123
|
+
}, j = async (e, t) => {
|
|
124
|
+
const r = t || B?.closest(".rte-content, .editora-content") || N() || y;
|
|
125
|
+
y = r || null;
|
|
126
|
+
const l = window.getSelection();
|
|
127
|
+
if (l && l.rangeCount > 0) {
|
|
128
|
+
const n = l.getRangeAt(0);
|
|
129
|
+
T = r && r.contains(n.commonAncestorContainer) ? n.cloneRange() : null;
|
|
59
130
|
}
|
|
60
|
-
await
|
|
61
|
-
const
|
|
131
|
+
await K();
|
|
132
|
+
const s = ee(r), o = s ? {
|
|
62
133
|
overlay: "rgba(0, 0, 0, 0.62)",
|
|
63
134
|
dialogBg: "#1f2937",
|
|
64
135
|
border: "#3b4657",
|
|
@@ -100,172 +171,173 @@ const w = '[data-theme="dark"], .dark, .editora-theme-dark', N = () => new Promi
|
|
|
100
171
|
insertBg: "#007bff",
|
|
101
172
|
insertHover: "#0069d9",
|
|
102
173
|
invalid: "#cc0000"
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
let
|
|
108
|
-
|
|
109
|
-
<div style="display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid ${
|
|
110
|
-
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${
|
|
111
|
-
<button class="close-btn" style="background: none; border: none; font-size: 28px; cursor: pointer; color: ${
|
|
174
|
+
}, d = document.createElement("div");
|
|
175
|
+
d.className = "math-dialog-overlay", d.style.cssText = `position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: ${o.overlay}; display: flex; align-items: center; justify-content: center; z-index: 99999;`;
|
|
176
|
+
const c = document.createElement("div");
|
|
177
|
+
c.style.cssText = `background: ${o.dialogBg}; border: 1px solid ${o.border}; border-radius: 8px; width: 90%; max-width: 600px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); color: ${o.text};`;
|
|
178
|
+
let u = e?.format || "latex", S = e?.formula || "", _ = e?.inline !== !1, b = null, L = "";
|
|
179
|
+
c.innerHTML = `
|
|
180
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid ${o.border}; background: ${o.panelBg};">
|
|
181
|
+
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${o.text};">${e ? "Edit" : "Insert"} Math Formula</h2>
|
|
182
|
+
<button class="close-btn" style="background: none; border: none; font-size: 28px; cursor: pointer; color: ${o.muted}; padding: 0; width: 30px; height: 30px; line-height: 1;">×</button>
|
|
112
183
|
</div>
|
|
113
184
|
|
|
114
185
|
<div style="padding: 20px; overflow-y: auto; flex: 1;">
|
|
115
186
|
<div style="margin-bottom: 20px;">
|
|
116
|
-
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${
|
|
187
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${o.text};">Format:</label>
|
|
117
188
|
<div style="display: flex; gap: 16px;">
|
|
118
|
-
<label style="cursor: pointer; color: ${
|
|
119
|
-
<label style="cursor: pointer; color: ${
|
|
189
|
+
<label style="cursor: pointer; color: ${o.text};"><input type="radio" name="format" value="latex" ${u === "latex" ? "checked" : ""} style="margin-right: 6px;"> LaTeX</label>
|
|
190
|
+
<label style="cursor: pointer; color: ${o.text};"><input type="radio" name="format" value="mathml" ${u === "mathml" ? "checked" : ""} style="margin-right: 6px;"> MathML</label>
|
|
120
191
|
</div>
|
|
121
192
|
</div>
|
|
122
193
|
|
|
123
194
|
<div style="margin-bottom: 20px;">
|
|
124
|
-
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${
|
|
195
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${o.text};">Quick Templates:</label>
|
|
125
196
|
<div id="templates-grid" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-height: 200px; overflow-y: auto;"></div>
|
|
126
197
|
</div>
|
|
127
198
|
|
|
128
199
|
<div style="margin-bottom: 20px;">
|
|
129
|
-
<label style="cursor: pointer; color: ${
|
|
200
|
+
<label style="cursor: pointer; color: ${o.text};"><input type="checkbox" id="inline-cb" ${_ ? "checked" : ""} style="margin-right: 8px;"> Inline math</label>
|
|
130
201
|
</div>
|
|
131
202
|
|
|
132
203
|
<div style="margin-bottom: 20px;">
|
|
133
|
-
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${
|
|
134
|
-
<textarea id="formula-input" rows="4" style="width: 100%; min-height: 112px; padding: 10px 12px; border: 1px solid ${
|
|
204
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${o.text};">Formula:</label>
|
|
205
|
+
<textarea id="formula-input" rows="4" style="width: 100%; min-height: 112px; padding: 10px 12px; border: 1px solid ${o.fieldBorder}; border-radius: 6px; font-family: 'Courier New', monospace; font-size: 14px; line-height: 1.45; background: ${o.fieldBg}; color: ${o.text}; box-sizing: border-box; overflow-x: hidden; overflow-y: auto; resize: vertical;">${S}</textarea>
|
|
135
206
|
</div>
|
|
136
207
|
|
|
137
208
|
<div style="margin-bottom: 20px;">
|
|
138
|
-
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${
|
|
139
|
-
<div id="preview-area" style="min-height: 60px; padding: 15px; border: 1px solid ${
|
|
209
|
+
<label style="display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: ${o.text};">Preview:</label>
|
|
210
|
+
<div id="preview-area" style="min-height: 60px; padding: 15px; border: 1px solid ${o.fieldBorder}; border-radius: 4px; background: ${o.previewBg}; display: flex; align-items: center; justify-content: center; color: ${o.previewText};"></div>
|
|
140
211
|
</div>
|
|
141
212
|
</div>
|
|
142
213
|
|
|
143
|
-
<div style="display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid ${
|
|
144
|
-
<button class="cancel-btn" style="padding: 10px 20px; background: ${
|
|
145
|
-
<button id="insert-btn" style="padding: 10px 20px; background: ${
|
|
214
|
+
<div style="display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid ${o.border}; background: ${o.panelBg};">
|
|
215
|
+
<button class="cancel-btn" style="padding: 10px 20px; background: ${o.cancelBg}; color: ${o.cancelText}; border: 1px solid ${o.cancelBorder}; border-radius: 4px; cursor: pointer; font-size: 14px;">Cancel</button>
|
|
216
|
+
<button id="insert-btn" style="padding: 10px 20px; background: ${o.insertBg}; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;" disabled>${e ? "Update" : "Insert"}</button>
|
|
146
217
|
</div>
|
|
147
|
-
`,
|
|
148
|
-
const
|
|
218
|
+
`, d.appendChild(c), document.body.appendChild(d);
|
|
219
|
+
const p = c.querySelector("#formula-input"), v = c.querySelector("#preview-area"), $ = c.querySelector("#templates-grid"), z = c.querySelectorAll('input[name="format"]'), I = c.querySelector("#inline-cb"), f = c.querySelector("#insert-btn"), g = c.querySelector(".close-btn"), w = c.querySelector(".cancel-btn"), P = (n) => encodeURIComponent(n), q = (n) => {
|
|
149
220
|
try {
|
|
150
|
-
return decodeURIComponent(
|
|
221
|
+
return decodeURIComponent(n);
|
|
151
222
|
} catch {
|
|
152
|
-
return
|
|
223
|
+
return n;
|
|
153
224
|
}
|
|
154
|
-
},
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
<button type="button" data-formula="${P(
|
|
158
|
-
<div style="font-weight: 600; font-size: 12px; color: ${
|
|
159
|
-
<div style="font-size: 10px; color: ${
|
|
225
|
+
}, C = () => {
|
|
226
|
+
const n = O[u];
|
|
227
|
+
$.innerHTML = n.map((i) => `
|
|
228
|
+
<button type="button" data-formula="${P(i.formula)}" title="${i.description}" style="padding: 8px; border: 1px solid ${o.fieldBorder}; border-radius: 4px; background: ${o.templateBtnBg}; cursor: pointer; text-align: left; transition: background-color 0.16s ease;">
|
|
229
|
+
<div style="font-weight: 600; font-size: 12px; color: ${o.templateBtnText};">${i.name}</div>
|
|
230
|
+
<div style="font-size: 10px; color: ${o.templateSubText}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${i.formula.substring(0, 20)}...</div>
|
|
160
231
|
</button>
|
|
161
232
|
`).join("");
|
|
162
|
-
},
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
if (L =
|
|
166
|
-
|
|
233
|
+
}, F = () => {
|
|
234
|
+
const n = p.value.trim(), i = `${u}:${n}`;
|
|
235
|
+
if (i !== L) {
|
|
236
|
+
if (L = i, !n) {
|
|
237
|
+
v.innerHTML = `<span style="color: ${o.previewText};">Enter a formula to see preview</span>`, f.disabled = !0;
|
|
167
238
|
return;
|
|
168
239
|
}
|
|
169
|
-
|
|
240
|
+
f.disabled = !1;
|
|
170
241
|
try {
|
|
171
|
-
if (
|
|
172
|
-
const
|
|
173
|
-
|
|
242
|
+
if (u === "latex") {
|
|
243
|
+
const a = window.katex;
|
|
244
|
+
v.innerHTML = a.renderToString(n, { displayMode: !1, throwOnError: !1 });
|
|
174
245
|
} else
|
|
175
|
-
|
|
246
|
+
n.trim().startsWith("<math") ? v.innerHTML = n : v.innerHTML = `<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">${n}</math>`;
|
|
176
247
|
} catch {
|
|
177
|
-
|
|
248
|
+
v.innerHTML = `<span style="color: ${o.invalid};">Invalid formula</span>`;
|
|
178
249
|
}
|
|
179
250
|
}
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
|
|
251
|
+
}, M = () => {
|
|
252
|
+
b !== null && cancelAnimationFrame(b), b = requestAnimationFrame(() => {
|
|
253
|
+
b = null, F();
|
|
183
254
|
});
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
},
|
|
187
|
-
document.removeEventListener("keydown",
|
|
255
|
+
}, A = (n) => {
|
|
256
|
+
n.key === "Escape" && (n.preventDefault(), n.stopPropagation(), E());
|
|
257
|
+
}, E = () => {
|
|
258
|
+
document.removeEventListener("keydown", A, !0), b !== null && (cancelAnimationFrame(b), b = null), d.parentNode && d.parentNode.removeChild(d);
|
|
188
259
|
};
|
|
189
|
-
|
|
190
|
-
|
|
260
|
+
g.onmouseover = () => {
|
|
261
|
+
g.style.color = "#f8fafc", g.style.background = s ? "#334155" : "#e5e7eb", g.style.borderRadius = "4px";
|
|
262
|
+
}, g.onmouseout = () => {
|
|
263
|
+
g.style.color = o.muted, g.style.background = "none";
|
|
264
|
+
}, w.onmouseover = () => {
|
|
265
|
+
w.style.background = s ? "#475569" : "#f3f4f6";
|
|
266
|
+
}, w.onmouseout = () => {
|
|
267
|
+
w.style.background = o.cancelBg;
|
|
268
|
+
}, f.onmouseover = () => {
|
|
269
|
+
f.disabled || (f.style.background = o.insertHover);
|
|
191
270
|
}, f.onmouseout = () => {
|
|
192
|
-
f.style.
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const n = e.target.closest("button[data-formula]");
|
|
203
|
-
n && (n.style.background = t.templateBtnHover);
|
|
204
|
-
}), k.addEventListener("mouseout", (e) => {
|
|
205
|
-
const n = e.target.closest("button[data-formula]");
|
|
206
|
-
n && (n.style.background = t.templateBtnBg);
|
|
207
|
-
}), k.addEventListener("click", (e) => {
|
|
208
|
-
const n = e.target.closest("button[data-formula]");
|
|
209
|
-
n && (u.value = R(n.getAttribute("data-formula") || ""), T = u.value, E());
|
|
271
|
+
f.style.background = o.insertBg;
|
|
272
|
+
}, $.addEventListener("mouseover", (n) => {
|
|
273
|
+
const a = n.target.closest("button[data-formula]");
|
|
274
|
+
a && (a.style.background = o.templateBtnHover);
|
|
275
|
+
}), $.addEventListener("mouseout", (n) => {
|
|
276
|
+
const a = n.target.closest("button[data-formula]");
|
|
277
|
+
a && (a.style.background = o.templateBtnBg);
|
|
278
|
+
}), $.addEventListener("click", (n) => {
|
|
279
|
+
const a = n.target.closest("button[data-formula]");
|
|
280
|
+
a && (p.value = q(a.getAttribute("data-formula") || ""), S = p.value, M());
|
|
210
281
|
});
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
214
|
-
const
|
|
215
|
-
if (
|
|
216
|
-
const
|
|
282
|
+
const D = () => {
|
|
283
|
+
const n = p.value.trim();
|
|
284
|
+
if (!n) return;
|
|
285
|
+
const i = { formula: n, format: u, inline: I.checked }, a = i.inline ? document.createElement("span") : document.createElement("div");
|
|
286
|
+
if (a.className = i.inline ? "math-formula" : "math-block", a.setAttribute("data-math-formula", n), a.setAttribute("data-math-format", u), a.contentEditable = "false", a.style.cssText = i.inline ? "background: #f0f8ff; border: 1px solid #b8daff; border-radius: 4px; padding: 2px 6px; margin: 0 2px; color: #004085; display: inline-block; cursor: pointer;" : "background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; padding: 12px; margin: 8px 0; text-align: center; display: block; cursor: pointer;", u === "latex") {
|
|
287
|
+
const x = window.katex;
|
|
217
288
|
try {
|
|
218
|
-
|
|
219
|
-
displayMode: !
|
|
289
|
+
a.innerHTML = x.renderToString(n, {
|
|
290
|
+
displayMode: !i.inline,
|
|
220
291
|
throwOnError: !1
|
|
221
292
|
});
|
|
222
293
|
} catch {
|
|
223
|
-
|
|
294
|
+
a.textContent = i.inline ? `$${n}$` : `$$${n}$$`;
|
|
224
295
|
}
|
|
225
|
-
} else if (
|
|
226
|
-
|
|
296
|
+
} else if (n.trim().startsWith("<math"))
|
|
297
|
+
a.innerHTML = n;
|
|
227
298
|
else {
|
|
228
|
-
const
|
|
229
|
-
|
|
299
|
+
const x = `<math xmlns="http://www.w3.org/1998/Math/MathML" display="${i.inline ? "inline" : "block"}">${n}</math>`;
|
|
300
|
+
a.innerHTML = x;
|
|
230
301
|
}
|
|
231
302
|
if (B)
|
|
232
|
-
B.replaceWith(
|
|
233
|
-
else if (
|
|
234
|
-
|
|
235
|
-
else if (
|
|
236
|
-
const
|
|
237
|
-
|
|
303
|
+
B.replaceWith(a);
|
|
304
|
+
else if (T)
|
|
305
|
+
T.deleteContents(), T.insertNode(a);
|
|
306
|
+
else if (y && y.isConnected) {
|
|
307
|
+
const x = document.createRange();
|
|
308
|
+
x.selectNodeContents(y), x.collapse(!1), x.insertNode(a);
|
|
238
309
|
}
|
|
239
|
-
(
|
|
310
|
+
(a.closest(".rte-content, .editora-content") || y)?.dispatchEvent(new Event("input", { bubbles: !0 })), E();
|
|
240
311
|
};
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}), document.addEventListener("keydown",
|
|
244
|
-
|
|
245
|
-
|
|
312
|
+
g.addEventListener("click", E), w.addEventListener("click", E), f.addEventListener("click", D), d.addEventListener("click", (n) => {
|
|
313
|
+
n.target === d && E();
|
|
314
|
+
}), document.addEventListener("keydown", A, !0), z.forEach((n) => {
|
|
315
|
+
n.addEventListener("change", (i) => {
|
|
316
|
+
u = i.target.value, L = "", C(), M();
|
|
246
317
|
});
|
|
247
|
-
}),
|
|
248
|
-
|
|
249
|
-
}),
|
|
250
|
-
(
|
|
251
|
-
}),
|
|
318
|
+
}), p.addEventListener("input", () => {
|
|
319
|
+
S = p.value, M();
|
|
320
|
+
}), p.addEventListener("keydown", (n) => {
|
|
321
|
+
(n.ctrlKey || n.metaKey) && n.key === "Enter" && (n.preventDefault(), D());
|
|
322
|
+
}), C(), M(), p.focus();
|
|
252
323
|
};
|
|
253
324
|
if (typeof window < "u" && !window.__mathPluginDoubleClickInitialized) {
|
|
254
325
|
window.__mathPluginDoubleClickInitialized = !0;
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
326
|
+
const e = (r) => {
|
|
327
|
+
const s = r.target.closest(".math-formula, .math-block");
|
|
328
|
+
if (s) {
|
|
329
|
+
r.preventDefault(), r.stopPropagation(), r.stopImmediatePropagation(), h(), B = s;
|
|
330
|
+
const o = s.getAttribute("data-math-formula") || "", d = s.getAttribute("data-math-format") || "latex", c = s.classList.contains("math-formula");
|
|
331
|
+
j({ formula: o, format: d, inline: c });
|
|
261
332
|
}
|
|
262
|
-
},
|
|
263
|
-
document.addEventListener("dblclick",
|
|
333
|
+
}, t = () => {
|
|
334
|
+
document.addEventListener("dblclick", e, { capture: !0 });
|
|
264
335
|
};
|
|
265
|
-
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded",
|
|
336
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", t) : setTimeout(t, 100);
|
|
266
337
|
}
|
|
267
|
-
const
|
|
338
|
+
const ne = () => ({
|
|
268
339
|
name: "math",
|
|
340
|
+
init: Y,
|
|
269
341
|
toolbar: [
|
|
270
342
|
{
|
|
271
343
|
label: "Insert Math",
|
|
@@ -274,9 +346,9 @@ const K = () => ({
|
|
|
274
346
|
}
|
|
275
347
|
],
|
|
276
348
|
commands: {
|
|
277
|
-
insertMath: (
|
|
278
|
-
const
|
|
279
|
-
return
|
|
349
|
+
insertMath: (e, t) => {
|
|
350
|
+
const r = t?.contentElement instanceof HTMLElement ? t.contentElement : null;
|
|
351
|
+
return j(void 0, r), !0;
|
|
280
352
|
}
|
|
281
353
|
},
|
|
282
354
|
keymap: {
|
|
@@ -284,5 +356,5 @@ const K = () => ({
|
|
|
284
356
|
}
|
|
285
357
|
});
|
|
286
358
|
export {
|
|
287
|
-
|
|
359
|
+
ne as MathPlugin
|
|
288
360
|
};
|
package/dist/merge-tag.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=".rte-content, .editora-content",te='[data-theme="dark"], .dark, .editora-theme-dark',re={title:"Insert Merge Tag",searchPlaceholder:"Search merge tags...",emptyStateText:"No merge tags found",cancelText:"Cancel",insertText:"Insert",showPreview:!0};function ne(){return[{id:"USER",name:"User",tags:[{key:"first_name",label:"First Name",category:"User",preview:"John"},{key:"last_name",label:"Last Name",category:"User",preview:"Doe"},{key:"email",label:"Email",category:"User",preview:"john@example.com"},{key:"phone",label:"Phone",category:"User",preview:"+1-555-1234"},{key:"full_name",label:"Full Name",category:"User",preview:"John Doe"},{key:"username",label:"Username",category:"User",preview:"johndoe"}]},{id:"COMPANY",name:"Company",tags:[{key:"company_name",label:"Company Name",category:"Company",preview:"Acme Corp"},{key:"company_address",label:"Company Address",category:"Company",preview:"123 Main St"},{key:"company_phone",label:"Company Phone",category:"Company",preview:"+1-555-0000"},{key:"company_email",label:"Company Email",category:"Company",preview:"info@acme.com"}]},{id:"DATE",name:"Date",tags:[{key:"today",label:"Today",category:"Date",preview:new Date().toLocaleDateString()},{key:"tomorrow",label:"Tomorrow",category:"Date",preview:new Date(Date.now()+864e5).toLocaleDateString()},{key:"next_week",label:"Next Week",category:"Date",preview:new Date(Date.now()+6048e5).toLocaleDateString()}]},{id:"CUSTOM",name:"Custom",tags:[]}]}function R(t,r){return t.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_").replace(/^_+|_+$/g,"")||`CATEGORY_${r+1}`}function ae(t,r){return(t.key||t.value||t.label).trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||`tag_${r+1}`}function oe(t){const r=(()=>{if(Array.isArray(t?.categories)&&t.categories.length>0)return t.categories;if(Array.isArray(t?.tags)&&t.tags.length>0){const c=new Map;return t.tags.forEach(d=>{const g=(d.category||"Custom").trim()||"Custom",i=c.get(g);i?i.push(d):c.set(g,[d])}),Array.from(c.entries()).map(([d,g],i)=>({id:R(d,i),name:d,tags:g}))}return ne()})(),e={},n=[];if(r.forEach((c,d)=>{const g=R(c.id||c.name,d);n.push(g),e[g]={name:c.name,tags:(Array.isArray(c.tags)?c.tags:[]).map((i,b)=>{const u=ae(i,b),f=(i.category||c.name).trim()||c.name;return{...i,key:u,category:f,categoryKey:g,searchIndex:`${i.label} ${u} ${f} ${i.description??""} ${i.value??""}`.toLowerCase()}})}}),n.length===0){const c="CUSTOM";n.push(c),e[c]={name:"Custom",tags:[]}}const a=t?.defaultCategory?R(t.defaultCategory,0):null,l=a&&n.includes(a)?a:n[0];return{categoriesByKey:e,categoryKeys:n,defaultCategory:l}}function le(t){const r=t?.tokenTemplate;return typeof r=="function"?e=>{const n=r(e);return typeof n=="string"&&n.trim()?n:e.value?.trim()||`{{ ${e.label} }}`}:typeof r=="string"&&r.trim()?e=>r.replace(/\{key\}/gi,e.key).replace(/\{label\}/gi,e.label).replace(/\{category\}/gi,e.category).replace(/\{value\}/gi,e.value??""):e=>e.value?.trim()||`{{ ${e.label} }}`}function ce(t){return{catalog:oe(t),dialog:{...re,...t?.dialog||{}},formatToken:le(t)}}let j=!1,H=!1,L=null,S=null,w=null,q=!1,y=null;function X(t,r){if(r===t.innerHTML)return;const e=window.execEditorCommand||window.executeEditorCommand;if(typeof e=="function")try{e("recordDomTransaction",t,r,t.innerHTML)}catch{}}function _(){if(j||typeof document>"u")return;j=!0;const t=document.createElement("style");t.id="merge-tag-plugin-styles",t.textContent=`
|
|
2
2
|
.rte-merge-tag-overlay {
|
|
3
3
|
--rte-mt-overlay-bg: rgba(15, 23, 36, 0.56);
|
|
4
4
|
--rte-mt-dialog-bg: #ffffff;
|
|
@@ -117,9 +117,15 @@
|
|
|
117
117
|
line-height: 1.3;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
.rte-merge-tag.rte-merge-tag-selected {
|
|
121
|
+
outline: 2px solid #2563eb;
|
|
122
|
+
outline-offset: 2px;
|
|
123
|
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-merge-tag {
|
|
121
127
|
background: #223247;
|
|
122
128
|
border-color: #3f5f84;
|
|
123
129
|
color: #8dc4ff;
|
|
124
130
|
}
|
|
125
|
-
`,document.head.appendChild(t)}function j(){K||typeof document>"u"||(K=!0,document.addEventListener("focusin",t=>{const e=t.target?.closest(h);e&&(S=e)}),document.addEventListener("selectionchange",()=>{const t=Y();t&&(S=t)}))}function Y(){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0).startContainer;return(e.nodeType===Node.ELEMENT_NODE?e:e.parentElement)?.closest(h)||null}function X(){const t=Y();if(t)return t;const e=document.activeElement?.closest(h);return e||(S?.isConnected?S:document.querySelector(h))}function le(t){const r=t.parentNode;if(!r)return;const e=window.getSelection();if(!e)return;const n=document.createRange(),l=Array.from(r.childNodes).indexOf(t);l<0||(n.setStart(r,l),n.setEnd(r,l+1),e.removeAllRanges(),e.addRange(n))}function q(t,r){t instanceof Text&&t.data.length!==0&&(r?(t.data.startsWith(" ")||t.data.startsWith(" "))&&t.deleteData(0,1):(t.data.endsWith(" ")||t.data.endsWith(" "))&&t.deleteData(t.data.length-1,1),t.data.length===0&&t.parentNode?.removeChild(t))}function W(t,r){const e=window.getSelection();if(!e)return;const n=document.createRange(),a=Math.max(0,Math.min(r,t.childNodes.length));n.setStart(t,a),n.collapse(!0),e.removeAllRanges(),e.addRange(n)}function ce(t,r){const e=t.closest(h),n=e?.innerHTML??"",a=t.parentNode;if(!a)return!1;const c=Array.from(a.childNodes).indexOf(t);if(c<0)return!1;const d=t.previousSibling,g=t.nextSibling;return a.removeChild(t),r==="Backspace"?(q(g,!0),W(a,c)):(q(d,!1),W(a,c)),e&&(J(e,n),e.dispatchEvent(new Event("input",{bubbles:!0}))),!0}function ie(t){if(t.collapsed||!(t.startContainer instanceof HTMLElement||t.startContainer instanceof Text)||t.startContainer!==t.endContainer||t.endOffset!==t.startOffset+1)return null;const r=t.startContainer;if(!(r instanceof Element||r instanceof DocumentFragment))return null;const e=r.childNodes[t.startOffset];return e instanceof HTMLElement&&e.classList.contains("rte-merge-tag")?e:null}function se(t,r){if(!t.collapsed)return null;const{startContainer:e,startOffset:n}=t,a=l=>l instanceof HTMLElement&&l.classList.contains("rte-merge-tag")?l:null;if(e.nodeType===Node.ELEMENT_NODE){const l=e;return r==="Backspace"&&n>0?a(l.childNodes[n-1]||null):r==="Delete"?a(l.childNodes[n]||null):null}if(e.nodeType===Node.TEXT_NODE){const l=e;return r==="Backspace"?n===0?a(l.previousSibling):n===1&&(l.data[0]===" "||l.data[0]===" ")&&l.previousSibling instanceof HTMLElement&&l.previousSibling.classList.contains("rte-merge-tag")?l.previousSibling:null:n===l.data.length?a(l.nextSibling):null}return null}function V(){H||typeof document>"u"||(H=!0,document.addEventListener("click",t=>{const e=t.target?.closest(".rte-merge-tag");if(!e)return;const n=e.closest(h);n&&(t.preventDefault(),t.stopPropagation(),n.focus({preventScroll:!0}),le(e))}),document.addEventListener("keydown",t=>{if(t.key!=="Backspace"&&t.key!=="Delete")return;const r=window.getSelection();if(!r||r.rangeCount===0)return;const e=r.getRangeAt(0),n=X();if(!n||!n.contains(e.commonAncestorContainer))return;let a=ie(e);a||(a=se(e,t.key)),a&&(t.preventDefault(),t.stopPropagation(),ce(a,t.key))}))}function de(t){return t?!!t.closest(Q):!1}function ge(){E&&(E(),E=null),N=null}function G(t){const r=document.createRange();return r.selectNodeContents(t),r.collapse(!1),r}function me(t,r){const e=window.getSelection(),n=r?r.cloneRange():G(t),l=n.startContainer.isConnected&&n.endContainer.isConnected&&t.contains(n.commonAncestorContainer)?n:G(t);return e&&(e.removeAllRanges(),e.addRange(l)),l}function ue(t,r){const e=document.createElement("span");e.className="rte-merge-tag",e.setAttribute("contenteditable","false"),e.setAttribute("data-key",t.key),e.setAttribute("data-category",t.category),e.setAttribute("data-label",t.label),t.value&&e.setAttribute("data-value",t.value);const n=r(t);return e.setAttribute("data-token",n),e.setAttribute("aria-label",`Merge tag: ${t.label}`),e.textContent=n,e}function fe(t,r,e,n){const a=window.getSelection();if(!a)return!1;const l=t.innerHTML;t.focus({preventScroll:!0});const c=me(t,r),g=(c.startContainer.nodeType===Node.ELEMENT_NODE?c.startContainer:c.startContainer.parentElement)?.closest(".rte-merge-tag");g&&t.contains(g)&&(c.setStartAfter(g),c.setEndAfter(g));try{c.deleteContents();const i=ue(e,n),b=document.createTextNode(" "),u=document.createDocumentFragment();u.appendChild(i),u.appendChild(b),c.insertNode(u);const f=document.createRange();return f.setStartAfter(b),f.collapse(!0),a.removeAllRanges(),a.addRange(f),J(t,l),t.dispatchEvent(new Event("input",{bubbles:!0})),!0}catch(i){return console.error("Failed to insert merge tag:",i),!1}}function pe(t,r,e){const n=t.catalog.categoriesByKey[r]?.tags||[],a=e.trim().toLowerCase();return a?n.filter(l=>l.searchIndex.includes(a)):n}function be(t,r){ge(),R();const e={category:r.catalog.defaultCategory,searchTerm:"",filteredTags:r.catalog.categoriesByKey[r.catalog.defaultCategory]?.tags||[],selectedIndex:0,savedRange:(()=>{const o=window.getSelection();if(!o||o.rangeCount===0)return null;const s=o.getRangeAt(0);return t.contains(s.commonAncestorContainer)?s.cloneRange():null})(),searchRaf:null},n=document.createElement("div");n.className="rte-merge-tag-overlay",n.setAttribute("role","dialog"),n.setAttribute("aria-modal","true"),de(t)&&n.classList.add("rte-ui-theme-dark");const a=document.createElement("div");a.className="rte-merge-tag-dialog";const l=document.createElement("div");l.className="rte-merge-tag-header";const c=document.createElement("h2");c.style.margin="0",c.style.fontSize="18px",c.style.fontWeight="700",c.textContent=r.dialog.title;const d=document.createElement("button");d.className="rte-merge-tag-close",d.setAttribute("aria-label","Close"),d.style.background="none",d.style.border="none",d.style.color="inherit",d.style.cursor="pointer",d.style.fontSize="20px",d.textContent="✕",l.appendChild(c),l.appendChild(d);const g=document.createElement("div");g.className="rte-merge-tag-body";const i=document.createElement("input");i.type="text",i.className="rte-merge-tag-input",i.placeholder=r.dialog.searchPlaceholder,i.setAttribute("aria-label","Search merge tags");const b=document.createElement("div");b.className="rte-merge-tag-tabs",r.catalog.categoryKeys.forEach(o=>{const s=document.createElement("button");s.type="button",s.className="rte-merge-tag-tab",s.setAttribute("data-category",o),s.textContent=r.catalog.categoriesByKey[o]?.name||o,b.appendChild(s)});const u=document.createElement("div");u.className="rte-merge-tag-list";const f=document.createElement("div");f.className="rte-merge-tag-preview",g.appendChild(i),g.appendChild(b),g.appendChild(u),g.appendChild(f);const w=document.createElement("div");w.className="rte-merge-tag-footer";const x=document.createElement("button");x.type="button",x.className="rte-merge-tag-btn-secondary",x.textContent=r.dialog.cancelText;const y=document.createElement("button");y.type="button",y.className="rte-merge-tag-btn-primary",y.textContent=r.dialog.insertText,w.appendChild(x),w.appendChild(y),a.appendChild(l),a.appendChild(g),a.appendChild(w),n.appendChild(a),document.body.appendChild(n),N=n;const _=()=>{b.querySelectorAll(".rte-merge-tag-tab").forEach(s=>{const p=s.dataset.category===e.category;s.classList.toggle("active",p)})},L=()=>{if(e.filteredTags.length===0){e.selectedIndex=-1;return}e.selectedIndex<0&&(e.selectedIndex=0),e.selectedIndex>=e.filteredTags.length&&(e.selectedIndex=e.filteredTags.length-1)},O=()=>{if(!r.dialog.showPreview){f.style.display="none",y.disabled=e.filteredTags.length===0;return}L();const o=e.selectedIndex>=0?e.filteredTags[e.selectedIndex]:null;if(!o){f.style.display="none",y.disabled=!0;return}f.style.display="block",f.textContent=`Preview: ${r.formatToken(o)}`,y.disabled=!1},Z=()=>{if(e.selectedIndex<0)return;u.querySelector(`.rte-merge-tag-item[data-index="${e.selectedIndex}"]`)?.scrollIntoView({block:"nearest"})},k=()=>{u.querySelector(".rte-merge-tag-item.selected")?.classList.remove("selected"),e.selectedIndex>=0&&u.querySelector(`.rte-merge-tag-item[data-index="${e.selectedIndex}"]`)?.classList.add("selected"),O(),Z()},A=()=>{if(e.filteredTags=pe(r,e.category,e.searchTerm),e.filteredTags.length>0&&e.selectedIndex<0&&(e.selectedIndex=0),L(),u.innerHTML="",e.filteredTags.length===0){const s=document.createElement("div");s.className="rte-merge-tag-empty",s.textContent=r.dialog.emptyStateText,u.appendChild(s),O();return}const o=document.createDocumentFragment();e.filteredTags.forEach((s,p)=>{const m=document.createElement("div");m.className="rte-merge-tag-item",m.setAttribute("data-index",String(p)),m.classList.toggle("selected",p===e.selectedIndex);const D=document.createElement("div");if(D.className="rte-merge-tag-item-label",D.textContent=s.label,m.appendChild(D),s.preview){const M=document.createElement("div");M.className="rte-merge-tag-item-preview",M.textContent=s.preview,m.appendChild(M)}o.appendChild(m)}),u.appendChild(o),k()},z=()=>{e.searchRaf!==null&&cancelAnimationFrame(e.searchRaf),e.searchRaf=requestAnimationFrame(()=>{e.searchRaf=null,e.searchTerm=i.value,e.selectedIndex=0,A()})},v=()=>{e.searchRaf!==null&&(cancelAnimationFrame(e.searchRaf),e.searchRaf=null),n.remove(),N===n&&(N=null,E=null)},T=()=>{if(L(),e.selectedIndex<0)return;const o=e.filteredTags[e.selectedIndex];fe(t,e.savedRange,o,r.formatToken)&&v()},F=o=>{const p=o.target.closest(".rte-merge-tag-tab");if(!p)return;const m=p.dataset.category;!m||!r.catalog.categoriesByKey[m]||(e.category=m,e.searchTerm="",i.value="",e.selectedIndex=0,_(),A())},P=o=>{const p=o.target.closest(".rte-merge-tag-item");if(!p)return;const m=Number(p.dataset.index||"-1");Number.isNaN(m)||m<0||m>=e.filteredTags.length||(e.selectedIndex=m,k())},B=o=>{const p=o.target.closest(".rte-merge-tag-item");if(!p)return;const m=Number(p.dataset.index||"-1");Number.isNaN(m)||m<0||m>=e.filteredTags.length||(e.selectedIndex=m,T())},C=o=>{if(o.key==="Escape"){o.preventDefault(),v();return}if(o.key==="ArrowDown"){if(o.preventDefault(),e.filteredTags.length===0)return;e.selectedIndex=Math.min(e.filteredTags.length-1,e.selectedIndex+1),k();return}if(o.key==="ArrowUp"){if(o.preventDefault(),e.filteredTags.length===0)return;e.selectedIndex=Math.max(0,e.selectedIndex-1),k();return}o.key==="Enter"&&(o.preventDefault(),T())},U=o=>{o.target===n&&v()};b.addEventListener("click",F),u.addEventListener("click",P),u.addEventListener("dblclick",B),i.addEventListener("input",z),i.addEventListener("keydown",C),n.addEventListener("click",U),a.addEventListener("keydown",C),d?.addEventListener("click",v),x.addEventListener("click",v),y.addEventListener("click",T),E=()=>{b.removeEventListener("click",F),u.removeEventListener("click",P),u.removeEventListener("dblclick",B),i.removeEventListener("input",z),i.removeEventListener("keydown",C),n.removeEventListener("click",U),a.removeEventListener("keydown",C),d?.removeEventListener("click",v),x.removeEventListener("click",v),y.removeEventListener("click",T),e.searchRaf!==null&&(cancelAnimationFrame(e.searchRaf),e.searchRaf=null),n.remove()},_(),A(),setTimeout(()=>{i.focus()},0)}const ye=t=>({name:"mergeTag",config:t,init:()=>{R(),j(),V()},toolbar:[{label:"Merge Tag",command:"insertMergeTag",icon:"{{ }}"}],commands:{insertMergeTag:()=>{R(),j(),V();const r=X();return r?(be(r,oe(t)),!0):!1}}});exports.MergeTagPlugin=ye;
|
|
131
|
+
`,document.head.appendChild(t)}function W(){H||typeof document>"u"||(H=!0,document.addEventListener("focusin",t=>{const e=t.target?.closest(E);e&&(L=e)}),document.addEventListener("selectionchange",()=>{const t=Z();t&&(L=t)}))}function Z(){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0).startContainer;return(e.nodeType===Node.ELEMENT_NODE?e:e.parentElement)?.closest(E)||null}function Q(){const t=Z();if(t)return t;const e=document.activeElement?.closest(E);return e||(L?.isConnected?L:document.querySelector(E))}function O(){y&&(y.classList.remove("rte-merge-tag-selected"),y.removeAttribute("data-rte-selected-object"),y=null)}function ie(t){y!==t&&(O(),y=t,t.classList.add("rte-merge-tag-selected"),t.setAttribute("data-rte-selected-object","true")),se(t)}function se(t){const r=t.parentNode;if(!r)return;const e=window.getSelection();if(!e)return;const n=document.createRange(),l=Array.from(r.childNodes).indexOf(t);l<0||(n.setStart(r,l),n.setEnd(r,l+1),e.removeAllRanges(),e.addRange(n))}function V(t,r){t instanceof Text&&t.data.length!==0&&(r?(t.data.startsWith(" ")||t.data.startsWith(" "))&&t.deleteData(0,1):(t.data.endsWith(" ")||t.data.endsWith(" "))&&t.deleteData(t.data.length-1,1),t.data.length===0&&t.parentNode?.removeChild(t))}function G(t,r){const e=window.getSelection();if(!e)return;const n=document.createRange(),a=Math.max(0,Math.min(r,t.childNodes.length));n.setStart(t,a),n.collapse(!0),e.removeAllRanges(),e.addRange(n)}function de(t,r){const e=t.closest(E),n=e?.innerHTML??"",a=t.parentNode;if(!a)return!1;const c=Array.from(a.childNodes).indexOf(t);if(c<0)return!1;const d=t.previousSibling,g=t.nextSibling;return a.removeChild(t),y===t&&(y=null),r==="Backspace"?(V(g,!0),G(a,c)):(V(d,!1),G(a,c)),e&&(X(e,n),e.dispatchEvent(new Event("input",{bubbles:!0}))),!0}function ge(t){if(t.collapsed||!(t.startContainer instanceof HTMLElement||t.startContainer instanceof Text)||t.startContainer!==t.endContainer||t.endOffset!==t.startOffset+1)return null;const r=t.startContainer;if(!(r instanceof Element||r instanceof DocumentFragment))return null;const e=r.childNodes[t.startOffset];return e instanceof HTMLElement&&e.classList.contains("rte-merge-tag")?e:null}function me(t,r){if(!t.collapsed)return null;const{startContainer:e,startOffset:n}=t,a=l=>l instanceof HTMLElement&&l.classList.contains("rte-merge-tag")?l:null;if(e.nodeType===Node.ELEMENT_NODE){const l=e;return r==="Backspace"&&n>0?a(l.childNodes[n-1]||null):r==="Delete"?a(l.childNodes[n]||null):null}if(e.nodeType===Node.TEXT_NODE){const l=e;return r==="Backspace"?n===0?a(l.previousSibling):n===1&&(l.data[0]===" "||l.data[0]===" ")&&l.previousSibling instanceof HTMLElement&&l.previousSibling.classList.contains("rte-merge-tag")?l.previousSibling:null:n===l.data.length?a(l.nextSibling):null}return null}function J(){q||typeof document>"u"||(q=!0,document.addEventListener("pointerdown",t=>{const e=t.target?.closest(".rte-merge-tag");if(!e){t.target?.closest?.(".rte-merge-tag-overlay")||O();return}const n=e.closest(E);n&&(t.preventDefault(),t.stopPropagation(),n.focus({preventScroll:!0}),ie(e))},!0),document.addEventListener("keydown",t=>{if(t.key==="Escape"&&y){O();return}if(t.key!=="Backspace"&&t.key!=="Delete")return;const r=window.getSelection();if(!r||r.rangeCount===0)return;const e=r.getRangeAt(0),n=Q();if(!n||!n.contains(e.commonAncestorContainer))return;let a=y?.isConnected?y:null;a&&!n.contains(a)&&(a=null),a||(a=ge(e)),a||(a=me(e,t.key)),a&&(t.preventDefault(),t.stopPropagation(),de(a,t.key))}))}function ue(t){return t?!!t.closest(te):!1}function fe(){w&&(w(),w=null),S=null}function Y(t){const r=document.createRange();return r.selectNodeContents(t),r.collapse(!1),r}function pe(t,r){const e=window.getSelection(),n=r?r.cloneRange():Y(t),l=n.startContainer.isConnected&&n.endContainer.isConnected&&t.contains(n.commonAncestorContainer)?n:Y(t);return e&&(e.removeAllRanges(),e.addRange(l)),l}function be(t,r){const e=document.createElement("span");e.className="rte-merge-tag",e.setAttribute("contenteditable","false"),e.setAttribute("data-key",t.key),e.setAttribute("data-category",t.category),e.setAttribute("data-label",t.label),t.value&&e.setAttribute("data-value",t.value);const n=r(t);return e.setAttribute("data-token",n),e.setAttribute("aria-label",`Merge tag: ${t.label}`),e.textContent=n,e}function ye(t,r,e,n){const a=window.getSelection();if(!a)return!1;const l=t.innerHTML;t.focus({preventScroll:!0});const c=pe(t,r),g=(c.startContainer.nodeType===Node.ELEMENT_NODE?c.startContainer:c.startContainer.parentElement)?.closest(".rte-merge-tag");g&&t.contains(g)&&(c.setStartAfter(g),c.setEndAfter(g));try{c.deleteContents();const i=be(e,n),b=document.createTextNode(" "),u=document.createDocumentFragment();u.appendChild(i),u.appendChild(b),c.insertNode(u);const f=document.createRange();return f.setStartAfter(b),f.collapse(!0),a.removeAllRanges(),a.addRange(f),X(t,l),t.dispatchEvent(new Event("input",{bubbles:!0})),!0}catch(i){return console.error("Failed to insert merge tag:",i),!1}}function xe(t,r,e){const n=t.catalog.categoriesByKey[r]?.tags||[],a=e.trim().toLowerCase();return a?n.filter(l=>l.searchIndex.includes(a)):n}function ve(t,r){fe(),_();const e={category:r.catalog.defaultCategory,searchTerm:"",filteredTags:r.catalog.categoriesByKey[r.catalog.defaultCategory]?.tags||[],selectedIndex:0,savedRange:(()=>{const o=window.getSelection();if(!o||o.rangeCount===0)return null;const s=o.getRangeAt(0);return t.contains(s.commonAncestorContainer)?s.cloneRange():null})(),searchRaf:null},n=document.createElement("div");n.className="rte-merge-tag-overlay",n.setAttribute("role","dialog"),n.setAttribute("aria-modal","true"),ue(t)&&n.classList.add("rte-ui-theme-dark");const a=document.createElement("div");a.className="rte-merge-tag-dialog";const l=document.createElement("div");l.className="rte-merge-tag-header";const c=document.createElement("h2");c.style.margin="0",c.style.fontSize="18px",c.style.fontWeight="700",c.textContent=r.dialog.title;const d=document.createElement("button");d.className="rte-merge-tag-close",d.setAttribute("aria-label","Close"),d.style.background="none",d.style.border="none",d.style.color="inherit",d.style.cursor="pointer",d.style.fontSize="20px",d.textContent="✕",l.appendChild(c),l.appendChild(d);const g=document.createElement("div");g.className="rte-merge-tag-body";const i=document.createElement("input");i.type="text",i.className="rte-merge-tag-input",i.placeholder=r.dialog.searchPlaceholder,i.setAttribute("aria-label","Search merge tags");const b=document.createElement("div");b.className="rte-merge-tag-tabs",r.catalog.categoryKeys.forEach(o=>{const s=document.createElement("button");s.type="button",s.className="rte-merge-tag-tab",s.setAttribute("data-category",o),s.textContent=r.catalog.categoriesByKey[o]?.name||o,b.appendChild(s)});const u=document.createElement("div");u.className="rte-merge-tag-list";const f=document.createElement("div");f.className="rte-merge-tag-preview",g.appendChild(i),g.appendChild(b),g.appendChild(u),g.appendChild(f);const T=document.createElement("div");T.className="rte-merge-tag-footer";const h=document.createElement("button");h.type="button",h.className="rte-merge-tag-btn-secondary",h.textContent=r.dialog.cancelText;const x=document.createElement("button");x.type="button",x.className="rte-merge-tag-btn-primary",x.textContent=r.dialog.insertText,T.appendChild(h),T.appendChild(x),a.appendChild(l),a.appendChild(g),a.appendChild(T),n.appendChild(a),document.body.appendChild(n),S=n;const z=()=>{b.querySelectorAll(".rte-merge-tag-tab").forEach(s=>{const p=s.dataset.category===e.category;s.classList.toggle("active",p)})},A=()=>{if(e.filteredTags.length===0){e.selectedIndex=-1;return}e.selectedIndex<0&&(e.selectedIndex=0),e.selectedIndex>=e.filteredTags.length&&(e.selectedIndex=e.filteredTags.length-1)},F=()=>{if(!r.dialog.showPreview){f.style.display="none",x.disabled=e.filteredTags.length===0;return}A();const o=e.selectedIndex>=0?e.filteredTags[e.selectedIndex]:null;if(!o){f.style.display="none",x.disabled=!0;return}f.style.display="block",f.textContent=`Preview: ${r.formatToken(o)}`,x.disabled=!1},ee=()=>{if(e.selectedIndex<0)return;u.querySelector(`.rte-merge-tag-item[data-index="${e.selectedIndex}"]`)?.scrollIntoView({block:"nearest"})},k=()=>{u.querySelector(".rte-merge-tag-item.selected")?.classList.remove("selected"),e.selectedIndex>=0&&u.querySelector(`.rte-merge-tag-item[data-index="${e.selectedIndex}"]`)?.classList.add("selected"),F(),ee()},D=()=>{if(e.filteredTags=xe(r,e.category,e.searchTerm),e.filteredTags.length>0&&e.selectedIndex<0&&(e.selectedIndex=0),A(),u.innerHTML="",e.filteredTags.length===0){const s=document.createElement("div");s.className="rte-merge-tag-empty",s.textContent=r.dialog.emptyStateText,u.appendChild(s),F();return}const o=document.createDocumentFragment();e.filteredTags.forEach((s,p)=>{const m=document.createElement("div");m.className="rte-merge-tag-item",m.setAttribute("data-index",String(p)),m.classList.toggle("selected",p===e.selectedIndex);const M=document.createElement("div");if(M.className="rte-merge-tag-item-label",M.textContent=s.label,m.appendChild(M),s.preview){const I=document.createElement("div");I.className="rte-merge-tag-item-preview",I.textContent=s.preview,m.appendChild(I)}o.appendChild(m)}),u.appendChild(o),k()},P=()=>{e.searchRaf!==null&&cancelAnimationFrame(e.searchRaf),e.searchRaf=requestAnimationFrame(()=>{e.searchRaf=null,e.searchTerm=i.value,e.selectedIndex=0,D()})},v=()=>{e.searchRaf!==null&&(cancelAnimationFrame(e.searchRaf),e.searchRaf=null),n.remove(),S===n&&(S=null,w=null)},C=()=>{if(A(),e.selectedIndex<0)return;const o=e.filteredTags[e.selectedIndex];ye(t,e.savedRange,o,r.formatToken)&&v()},B=o=>{const p=o.target.closest(".rte-merge-tag-tab");if(!p)return;const m=p.dataset.category;!m||!r.catalog.categoriesByKey[m]||(e.category=m,e.searchTerm="",i.value="",e.selectedIndex=0,z(),D())},U=o=>{const p=o.target.closest(".rte-merge-tag-item");if(!p)return;const m=Number(p.dataset.index||"-1");Number.isNaN(m)||m<0||m>=e.filteredTags.length||(e.selectedIndex=m,k())},$=o=>{const p=o.target.closest(".rte-merge-tag-item");if(!p)return;const m=Number(p.dataset.index||"-1");Number.isNaN(m)||m<0||m>=e.filteredTags.length||(e.selectedIndex=m,C())},N=o=>{if(o.key==="Escape"){o.preventDefault(),v();return}if(o.key==="ArrowDown"){if(o.preventDefault(),e.filteredTags.length===0)return;e.selectedIndex=Math.min(e.filteredTags.length-1,e.selectedIndex+1),k();return}if(o.key==="ArrowUp"){if(o.preventDefault(),e.filteredTags.length===0)return;e.selectedIndex=Math.max(0,e.selectedIndex-1),k();return}o.key==="Enter"&&(o.preventDefault(),C())},K=o=>{o.target===n&&v()};b.addEventListener("click",B),u.addEventListener("click",U),u.addEventListener("dblclick",$),i.addEventListener("input",P),i.addEventListener("keydown",N),n.addEventListener("click",K),a.addEventListener("keydown",N),d?.addEventListener("click",v),h.addEventListener("click",v),x.addEventListener("click",C),w=()=>{b.removeEventListener("click",B),u.removeEventListener("click",U),u.removeEventListener("dblclick",$),i.removeEventListener("input",P),i.removeEventListener("keydown",N),n.removeEventListener("click",K),a.removeEventListener("keydown",N),d?.removeEventListener("click",v),h.removeEventListener("click",v),x.removeEventListener("click",C),e.searchRaf!==null&&(cancelAnimationFrame(e.searchRaf),e.searchRaf=null),n.remove()},z(),D(),setTimeout(()=>{i.focus()},0)}const he=t=>({name:"mergeTag",config:t,init:()=>{_(),W(),J()},toolbar:[{label:"Merge Tag",command:"insertMergeTag",icon:"{{ }}"}],commands:{insertMergeTag:()=>{_(),W(),J();const r=Q();return r?(ve(r,ce(t)),!0):!1}}});exports.MergeTagPlugin=he;
|