@editora/plugins 1.0.8 → 1.0.9
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/LICENSE +21 -0
- package/README.md +22 -0
- package/dist/approval-workflow.cjs.js +447 -0
- package/dist/approval-workflow.esm.js +1070 -0
- package/dist/blocks-library.cjs.js +442 -0
- package/dist/blocks-library.esm.js +1317 -0
- package/dist/citations.cjs.js +548 -0
- package/dist/citations.esm.js +1457 -0
- package/dist/conditional-content.cjs.js +626 -0
- package/dist/conditional-content.esm.js +1360 -0
- package/dist/content-rules.cjs.js +408 -0
- package/dist/content-rules.esm.js +1093 -0
- package/dist/data-binding.cjs.js +321 -0
- package/dist/data-binding.esm.js +913 -0
- package/dist/doc-schema.cjs.js +398 -0
- package/dist/doc-schema.esm.js +1310 -0
- package/dist/enterprise.cjs.js +1 -0
- package/dist/enterprise.esm.js +56 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +109 -81
- package/dist/mentions.cjs.js +105 -0
- package/dist/mentions.esm.js +726 -0
- package/dist/page-break.cjs.js +2 -2
- package/dist/page-break.esm.js +32 -32
- package/dist/pii-redaction.cjs.js +436 -0
- package/dist/pii-redaction.esm.js +1377 -0
- package/dist/preview.cjs.js +3 -3
- package/dist/preview.esm.js +29 -29
- package/dist/slash-commands.cjs.js +90 -0
- package/dist/slash-commands.esm.js +752 -0
- package/dist/smart-paste.cjs.js +398 -0
- package/dist/smart-paste.esm.js +1388 -0
- package/dist/track-changes.cjs.js +77 -0
- package/dist/track-changes.esm.js +755 -0
- package/dist/translation-workflow.cjs.js +626 -0
- package/dist/translation-workflow.esm.js +1718 -0
- package/dist/version-diff.cjs.js +362 -0
- package/dist/version-diff.esm.js +768 -0
- package/index.d.ts +798 -0
- package/package.json +104 -5
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
const g = ".rte-content, .editora-content", Y = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", w = '.rte-mention[data-mention="true"]', b = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', M = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
let P = !1, N = !1, T = null, v = 0;
|
|
3
|
+
function Q(e, n) {
|
|
4
|
+
if (n === e.innerHTML) return;
|
|
5
|
+
const o = window.execEditorCommand || window.executeEditorCommand;
|
|
6
|
+
if (typeof o == "function")
|
|
7
|
+
try {
|
|
8
|
+
o("recordDomTransaction", e, n, e.innerHTML);
|
|
9
|
+
} catch {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function U(e) {
|
|
13
|
+
e.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
14
|
+
}
|
|
15
|
+
function h(e, n) {
|
|
16
|
+
const o = window.getSelection();
|
|
17
|
+
o && (o.removeAllRanges(), o.addRange(n), e.focus({ preventScroll: !0 }));
|
|
18
|
+
}
|
|
19
|
+
function S(e, n) {
|
|
20
|
+
return e.startContainer === n.startContainer && e.startOffset === n.startOffset && e.endContainer === n.endContainer && e.endOffset === n.endOffset;
|
|
21
|
+
}
|
|
22
|
+
function E(e) {
|
|
23
|
+
const n = window.getSelection();
|
|
24
|
+
if (!n || n.rangeCount === 0) return null;
|
|
25
|
+
const o = n.getRangeAt(0);
|
|
26
|
+
return e.contains(o.commonAncestorContainer) ? o.cloneRange() : null;
|
|
27
|
+
}
|
|
28
|
+
function C(e) {
|
|
29
|
+
Array.from(e.querySelectorAll(w)).forEach((o) => {
|
|
30
|
+
o.setAttribute("data-mention", "true"), o.setAttribute("contenteditable", "false"), o.setAttribute("spellcheck", "false"), o.setAttribute("draggable", "false"), o.classList.add("rte-mention");
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function _(e) {
|
|
34
|
+
return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
|
|
35
|
+
}
|
|
36
|
+
function ee(e) {
|
|
37
|
+
return e.closest(Y) || e;
|
|
38
|
+
}
|
|
39
|
+
function k(e) {
|
|
40
|
+
return e ? (e.getAttribute("data-theme") || e.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : e.classList.contains("dark") || e.classList.contains("editora-theme-dark") || e.classList.contains("rte-theme-dark") : !1;
|
|
41
|
+
}
|
|
42
|
+
function ne(e) {
|
|
43
|
+
const n = ee(e);
|
|
44
|
+
if (k(n)) return !0;
|
|
45
|
+
const o = n.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
|
|
46
|
+
return k(o) ? !0 : k(document.documentElement) || k(document.body);
|
|
47
|
+
}
|
|
48
|
+
function W(e, n) {
|
|
49
|
+
e.classList.remove("rte-mention-theme-dark"), ne(n) && e.classList.add("rte-mention-theme-dark");
|
|
50
|
+
}
|
|
51
|
+
function te(e) {
|
|
52
|
+
if (e?.contentElement instanceof HTMLElement) return e.contentElement;
|
|
53
|
+
if (e?.editorElement instanceof HTMLElement) {
|
|
54
|
+
const t = e.editorElement;
|
|
55
|
+
if (t.matches(g)) return t;
|
|
56
|
+
const r = t.querySelector(g);
|
|
57
|
+
if (r instanceof HTMLElement) return r;
|
|
58
|
+
}
|
|
59
|
+
const n = window.getSelection();
|
|
60
|
+
if (n && n.rangeCount > 0) {
|
|
61
|
+
const t = n.getRangeAt(0).startContainer, i = (t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement)?.closest(g);
|
|
62
|
+
if (i) return i;
|
|
63
|
+
}
|
|
64
|
+
const o = document.activeElement;
|
|
65
|
+
if (o) {
|
|
66
|
+
if (o.matches(g)) return o;
|
|
67
|
+
const t = o.closest(g);
|
|
68
|
+
if (t) return t;
|
|
69
|
+
}
|
|
70
|
+
return document.querySelector(g);
|
|
71
|
+
}
|
|
72
|
+
function x(e) {
|
|
73
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
74
|
+
}
|
|
75
|
+
function D(e) {
|
|
76
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
77
|
+
}
|
|
78
|
+
function re(e, n) {
|
|
79
|
+
return n ? n.split(".").filter(Boolean).reduce((o, t) => {
|
|
80
|
+
if (!(!D(o) && !Array.isArray(o)))
|
|
81
|
+
return o[t];
|
|
82
|
+
}, e) : e;
|
|
83
|
+
}
|
|
84
|
+
function oe(e) {
|
|
85
|
+
return e ? /\s|[([{"'`]/.test(e) : !0;
|
|
86
|
+
}
|
|
87
|
+
function ie(e) {
|
|
88
|
+
if (!e.collapsed) return null;
|
|
89
|
+
const n = e.startContainer, o = e.startOffset;
|
|
90
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
91
|
+
const t = n;
|
|
92
|
+
return {
|
|
93
|
+
node: t,
|
|
94
|
+
textBefore: t.data.slice(0, o),
|
|
95
|
+
caretOffset: o
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
99
|
+
const t = n;
|
|
100
|
+
if (o > 0) {
|
|
101
|
+
const r = t.childNodes[o - 1];
|
|
102
|
+
if (r && r.nodeType === Node.TEXT_NODE) {
|
|
103
|
+
const i = r;
|
|
104
|
+
return {
|
|
105
|
+
node: i,
|
|
106
|
+
textBefore: i.data,
|
|
107
|
+
caretOffset: i.length
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
function ae(e, n, o) {
|
|
115
|
+
let t = -1, r = "";
|
|
116
|
+
if (n.forEach((a) => {
|
|
117
|
+
const l = e.lastIndexOf(a);
|
|
118
|
+
l > t && (t = l, r = a);
|
|
119
|
+
}), t < 0 || !oe(e[t - 1])) return null;
|
|
120
|
+
const i = e.slice(t + 1);
|
|
121
|
+
return /\s/.test(i) || i.length > o ? null : {
|
|
122
|
+
trigger: r,
|
|
123
|
+
query: i,
|
|
124
|
+
startOffset: t
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function le(e, n) {
|
|
128
|
+
const o = n.cloneRange();
|
|
129
|
+
o.collapse(!1);
|
|
130
|
+
const t = o.getClientRects();
|
|
131
|
+
if (t.length > 0)
|
|
132
|
+
return t[t.length - 1];
|
|
133
|
+
const r = document.createElement("span");
|
|
134
|
+
r.textContent = "", r.style.position = "relative", o.insertNode(r);
|
|
135
|
+
const i = r.getBoundingClientRect();
|
|
136
|
+
return r.remove(), e.normalize(), i;
|
|
137
|
+
}
|
|
138
|
+
function se(e, n) {
|
|
139
|
+
if (e.panel && e.list) return;
|
|
140
|
+
const o = document.createElement("div");
|
|
141
|
+
o.className = "rte-mention-panel", o.style.display = "none";
|
|
142
|
+
const t = document.createElement("div");
|
|
143
|
+
t.className = "rte-mention-list", o.appendChild(t), document.body.appendChild(o), W(o, e.editor), e.panel = o, e.list = t, o.addEventListener("mousedown", (r) => {
|
|
144
|
+
r.preventDefault();
|
|
145
|
+
}), o.addEventListener("click", (r) => {
|
|
146
|
+
const i = r.target;
|
|
147
|
+
if (!i) return;
|
|
148
|
+
const a = i.closest(".rte-mention-item");
|
|
149
|
+
if (!a) return;
|
|
150
|
+
const l = Number(a.getAttribute("data-index"));
|
|
151
|
+
Number.isFinite(l) && K(e, n, l);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function m(e) {
|
|
155
|
+
e.panel && (e.debounceHandle !== null && (window.clearTimeout(e.debounceHandle), e.debounceHandle = null), e.abortController && (e.abortController.abort(), e.abortController = null), e.panel.style.display = "none", e.panel.classList.remove("show"), e.isOpen = !1, e.loading = !1, e.items = [], e.activeIndex = 0, e.query = "", e.replaceRange = null);
|
|
156
|
+
}
|
|
157
|
+
function $(e, n) {
|
|
158
|
+
if (!e.panel) return;
|
|
159
|
+
W(e.panel, e.editor);
|
|
160
|
+
const o = le(e.editor, n), t = e.panel;
|
|
161
|
+
t.style.display = "block", t.classList.add("show"), t.style.left = "0px", t.style.top = "0px";
|
|
162
|
+
const r = t.getBoundingClientRect(), i = window.innerWidth, a = window.innerHeight;
|
|
163
|
+
let l = Math.max(8, Math.min(o.left, i - r.width - 8)), s = o.bottom + 8;
|
|
164
|
+
s + r.height > a - 8 && (s = Math.max(8, o.top - r.height - 8)), t.style.position = "fixed", t.style.left = `${l}px`, t.style.top = `${s}px`;
|
|
165
|
+
}
|
|
166
|
+
function ce(e, n) {
|
|
167
|
+
if (!n) return x(e);
|
|
168
|
+
const o = e.toLowerCase(), t = n.toLowerCase(), r = o.indexOf(t);
|
|
169
|
+
if (r < 0) return x(e);
|
|
170
|
+
const i = x(e.slice(0, r)), a = x(e.slice(r, r + n.length)), l = x(e.slice(r + n.length));
|
|
171
|
+
return `${i}<mark>${a}</mark>${l}`;
|
|
172
|
+
}
|
|
173
|
+
function B(e, n) {
|
|
174
|
+
if (!e.list) return;
|
|
175
|
+
const o = e.list;
|
|
176
|
+
if (o.innerHTML = "", e.loading) {
|
|
177
|
+
const t = document.createElement("div");
|
|
178
|
+
t.className = "rte-mention-empty", t.textContent = n.loadingText, o.appendChild(t);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (e.items.length === 0) {
|
|
182
|
+
const t = document.createElement("div");
|
|
183
|
+
t.className = "rte-mention-empty", t.textContent = e.query.length > 0 ? n.noResultsText : n.emptyStateText, o.appendChild(t);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
e.items.forEach((t, r) => {
|
|
187
|
+
const i = document.createElement("button");
|
|
188
|
+
i.type = "button", i.className = "rte-mention-item", r === e.activeIndex && i.classList.add("active"), i.setAttribute("data-index", String(r));
|
|
189
|
+
const a = n.itemRenderer ? n.itemRenderer(t, e.query) : `<span class="rte-mention-item-label">${ce(t.label, e.query)}</span>${t.meta ? `<span class="rte-mention-item-meta">${x(t.meta)}</span>` : ""}`;
|
|
190
|
+
i.innerHTML = a, o.appendChild(i);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function G(e, n) {
|
|
194
|
+
const o = /* @__PURE__ */ new Set(), t = [];
|
|
195
|
+
return e.forEach((r) => {
|
|
196
|
+
const i = (r.id || "").trim();
|
|
197
|
+
!i || o.has(i) || (o.add(i), t.push({
|
|
198
|
+
id: i,
|
|
199
|
+
label: r.label || i,
|
|
200
|
+
value: r.value,
|
|
201
|
+
meta: r.meta
|
|
202
|
+
}));
|
|
203
|
+
}), t.slice(0, n);
|
|
204
|
+
}
|
|
205
|
+
function ue(e, n) {
|
|
206
|
+
if (e.buildRequest) {
|
|
207
|
+
const c = e.buildRequest(n);
|
|
208
|
+
return {
|
|
209
|
+
url: c.url,
|
|
210
|
+
init: c.init || {}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const o = (e.method || "GET").toUpperCase(), t = typeof e.headers == "function" ? e.headers(n) : e.headers || {}, r = e.queryParam || "q", i = e.triggerParam || "trigger", a = e.limitParam || "limit", l = e.staticParams || {}, s = {
|
|
214
|
+
method: o,
|
|
215
|
+
headers: { ...t },
|
|
216
|
+
credentials: e.credentials,
|
|
217
|
+
mode: e.mode,
|
|
218
|
+
cache: e.cache,
|
|
219
|
+
signal: n.signal
|
|
220
|
+
}, f = new URL(e.url, window.location.origin);
|
|
221
|
+
if (o === "GET" || o === "HEAD") {
|
|
222
|
+
const c = new URLSearchParams(f.search);
|
|
223
|
+
Object.entries(l).forEach(([d, p]) => c.set(d, String(p))), c.set(r, n.query), c.set(i, n.trigger), c.set(a, String(n.limit)), f.search = c.toString();
|
|
224
|
+
} else {
|
|
225
|
+
const c = typeof e.body == "function" ? e.body(n) : e.body, d = {
|
|
226
|
+
[r]: n.query,
|
|
227
|
+
[i]: n.trigger,
|
|
228
|
+
[a]: n.limit,
|
|
229
|
+
...l
|
|
230
|
+
}, p = c ?? d;
|
|
231
|
+
if (D(p)) {
|
|
232
|
+
s.body = JSON.stringify(p);
|
|
233
|
+
const y = s.headers;
|
|
234
|
+
!y["Content-Type"] && !y["content-type"] && (y["Content-Type"] = "application/json");
|
|
235
|
+
} else
|
|
236
|
+
s.body = p;
|
|
237
|
+
}
|
|
238
|
+
return { url: f.toString(), init: s };
|
|
239
|
+
}
|
|
240
|
+
async function de(e, n, o, t) {
|
|
241
|
+
const r = n.api;
|
|
242
|
+
if (!r) return [];
|
|
243
|
+
e.abortController && e.abortController.abort();
|
|
244
|
+
const i = new AbortController();
|
|
245
|
+
e.abortController = i;
|
|
246
|
+
const a = {
|
|
247
|
+
query: o,
|
|
248
|
+
trigger: t,
|
|
249
|
+
limit: n.maxSuggestions,
|
|
250
|
+
signal: i.signal
|
|
251
|
+
}, l = Math.max(0, r.timeoutMs ?? 1e4);
|
|
252
|
+
let s = null;
|
|
253
|
+
l > 0 && (s = window.setTimeout(() => i.abort(), l));
|
|
254
|
+
try {
|
|
255
|
+
const { url: f, init: c } = ue(r, a), d = await fetch(f, {
|
|
256
|
+
...c,
|
|
257
|
+
signal: i.signal
|
|
258
|
+
});
|
|
259
|
+
if (!d.ok)
|
|
260
|
+
throw new Error(`Mention API request failed: ${d.status}`);
|
|
261
|
+
const y = (r.responseType || "json") === "text" ? await d.text() : await d.json();
|
|
262
|
+
let O = [];
|
|
263
|
+
if (r.transformResponse)
|
|
264
|
+
O = r.transformResponse(y, a) || [];
|
|
265
|
+
else {
|
|
266
|
+
const q = re(y, r.responsePath);
|
|
267
|
+
O = (Array.isArray(q) ? q : Array.isArray(y) ? y : []).map((u, J) => {
|
|
268
|
+
if (r.mapItem)
|
|
269
|
+
return r.mapItem(u, J);
|
|
270
|
+
if (!D(u)) return null;
|
|
271
|
+
const I = String(u.id ?? u.value ?? u.key ?? "").trim();
|
|
272
|
+
if (!I) return null;
|
|
273
|
+
const Z = String(u.label ?? u.name ?? I).trim();
|
|
274
|
+
return {
|
|
275
|
+
id: I,
|
|
276
|
+
label: Z,
|
|
277
|
+
value: u.value ? String(u.value) : void 0,
|
|
278
|
+
meta: u.meta ? String(u.meta) : void 0
|
|
279
|
+
};
|
|
280
|
+
}).filter((u) => !!u);
|
|
281
|
+
}
|
|
282
|
+
return G(O, n.maxSuggestions);
|
|
283
|
+
} catch (f) {
|
|
284
|
+
return f?.name !== "AbortError" && r.onError?.(f, a), [];
|
|
285
|
+
} finally {
|
|
286
|
+
s !== null && window.clearTimeout(s), e.abortController === i && (e.abortController = null);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function fe(e, n, o, t) {
|
|
290
|
+
const r = ++e.requestId;
|
|
291
|
+
let i = [];
|
|
292
|
+
if (n.search) {
|
|
293
|
+
const a = await n.search(o, t);
|
|
294
|
+
i = Array.isArray(a) ? a : [];
|
|
295
|
+
} else if (n.api)
|
|
296
|
+
i = await de(e, n, o, t);
|
|
297
|
+
else {
|
|
298
|
+
const a = o.toLowerCase();
|
|
299
|
+
i = n.items.filter((l) => a ? l.label.toLowerCase().includes(a) || l.id.toLowerCase().includes(a) : !0);
|
|
300
|
+
}
|
|
301
|
+
return r !== e.requestId ? [] : G(i, n.maxSuggestions);
|
|
302
|
+
}
|
|
303
|
+
function me(e, n, o) {
|
|
304
|
+
const t = e.editor;
|
|
305
|
+
if (C(t), !window.getSelection()) return !1;
|
|
306
|
+
const i = t.innerHTML;
|
|
307
|
+
let a = e.replaceRange ? e.replaceRange.cloneRange() : E(t);
|
|
308
|
+
if (!a || !t.contains(a.commonAncestorContainer) && (a = E(t), !a))
|
|
309
|
+
return !1;
|
|
310
|
+
const l = A(t, a.cloneRange(), "after");
|
|
311
|
+
S(l, a) || (h(t, l), a = l), a.deleteContents();
|
|
312
|
+
const s = document.createElement("span");
|
|
313
|
+
s.className = "rte-mention", s.setAttribute("data-mention", "true"), s.setAttribute("data-mention-id", o.id), s.setAttribute("contenteditable", "false"), s.textContent = o.value || `${e.trigger}${o.label}`, a.insertNode(s);
|
|
314
|
+
let f = s, c = 1;
|
|
315
|
+
if (n.insertSpaceAfterMention) {
|
|
316
|
+
const p = document.createTextNode(" ");
|
|
317
|
+
s.after(p), f = p, c = 1;
|
|
318
|
+
}
|
|
319
|
+
const d = document.createRange();
|
|
320
|
+
return d.setStart(f, c), d.collapse(!0), h(t, d), m(e), C(t), U(t), Q(t, i), !0;
|
|
321
|
+
}
|
|
322
|
+
function K(e, n, o) {
|
|
323
|
+
if (o < 0 || o >= e.items.length) return;
|
|
324
|
+
const t = e.items[o];
|
|
325
|
+
me(e, n, t);
|
|
326
|
+
}
|
|
327
|
+
function pe(e) {
|
|
328
|
+
return e.startContainer !== e.endContainer || e.startContainer.nodeType !== Node.ELEMENT_NODE || e.endOffset - e.startOffset !== 1 ? null : e.startContainer.childNodes[e.startOffset] || null;
|
|
329
|
+
}
|
|
330
|
+
function ge(e, n) {
|
|
331
|
+
const o = pe(e);
|
|
332
|
+
return !(o instanceof HTMLElement) || !o.matches(w) || !n.contains(o) ? null : o;
|
|
333
|
+
}
|
|
334
|
+
function V(e, n) {
|
|
335
|
+
const o = ge(e, n);
|
|
336
|
+
if (o) return o;
|
|
337
|
+
const r = _(e.startContainer)?.closest(w);
|
|
338
|
+
if (r && n.contains(r)) return r;
|
|
339
|
+
const a = _(e.endContainer)?.closest(w);
|
|
340
|
+
return a && n.contains(a) ? a : null;
|
|
341
|
+
}
|
|
342
|
+
function A(e, n, o = "after") {
|
|
343
|
+
const t = V(n, e);
|
|
344
|
+
if (!t) return n;
|
|
345
|
+
const r = document.createRange();
|
|
346
|
+
return o === "before" ? r.setStartBefore(t) : r.setStartAfter(t), r.collapse(!0), r;
|
|
347
|
+
}
|
|
348
|
+
function j(e, n, o = "after") {
|
|
349
|
+
const t = document.createRange();
|
|
350
|
+
o === "before" ? t.setStartBefore(n) : t.setStartAfter(n), t.collapse(!0), h(e, t);
|
|
351
|
+
}
|
|
352
|
+
function he(e, n, o) {
|
|
353
|
+
if (!e.collapsed) return null;
|
|
354
|
+
const t = e.startContainer, r = e.startOffset;
|
|
355
|
+
let i = null;
|
|
356
|
+
if (t.nodeType === Node.TEXT_NODE) {
|
|
357
|
+
const a = t;
|
|
358
|
+
n === "backward" && r === 0 ? i = a.previousSibling : n === "forward" && r === a.length && (i = a.nextSibling);
|
|
359
|
+
} else if (t.nodeType === Node.ELEMENT_NODE) {
|
|
360
|
+
const a = t;
|
|
361
|
+
n === "backward" && r > 0 ? i = a.childNodes[r - 1] || null : n === "forward" && r < a.childNodes.length && (i = a.childNodes[r] || null);
|
|
362
|
+
}
|
|
363
|
+
return !(i instanceof HTMLElement) || !i.matches(w) || !o.contains(i) ? null : i;
|
|
364
|
+
}
|
|
365
|
+
function z(e, n) {
|
|
366
|
+
const o = E(e);
|
|
367
|
+
if (!o) return !1;
|
|
368
|
+
const t = he(o, n, e);
|
|
369
|
+
if (!t) return !1;
|
|
370
|
+
const r = t.parentNode;
|
|
371
|
+
if (!r) return !1;
|
|
372
|
+
const i = e.innerHTML, a = Array.prototype.indexOf.call(r.childNodes, t);
|
|
373
|
+
t.remove();
|
|
374
|
+
const l = document.createRange();
|
|
375
|
+
return l.setStart(r, Math.max(0, a)), l.collapse(!0), h(e, l), U(e), Q(e, i), !0;
|
|
376
|
+
}
|
|
377
|
+
function X(e, n, o, t, r, i) {
|
|
378
|
+
if (se(e, n), e.query = t, e.trigger = r, e.replaceRange = i.cloneRange(), e.loading = !!(n.api && !n.search), e.debounceHandle !== null && (window.clearTimeout(e.debounceHandle), e.debounceHandle = null), !e.panel) return;
|
|
379
|
+
e.isOpen || (e.panel.style.display = "block", e.panel.classList.add("show"), e.isOpen = !0), B(e, n), $(e, o);
|
|
380
|
+
const a = () => {
|
|
381
|
+
e.debounceHandle = null, fe(e, n, t, r).then((s) => {
|
|
382
|
+
e.loading = !1, e.items = s, e.activeIndex = 0, e.panel && (B(e, n), $(e, o));
|
|
383
|
+
});
|
|
384
|
+
}, l = n.api && !n.search ? Math.max(0, n.api.debounceMs ?? 180) : 0;
|
|
385
|
+
l > 0 ? e.debounceHandle = window.setTimeout(a, l) : a();
|
|
386
|
+
}
|
|
387
|
+
function ye(e, n) {
|
|
388
|
+
const o = e.editor;
|
|
389
|
+
C(o);
|
|
390
|
+
let t = E(o);
|
|
391
|
+
if (!t || !t.collapsed) {
|
|
392
|
+
m(e);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const r = A(o, t.cloneRange(), "after");
|
|
396
|
+
if (!S(r, t)) {
|
|
397
|
+
h(o, r), t = r, m(e);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const i = ie(t);
|
|
401
|
+
if (!i) {
|
|
402
|
+
m(e);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const a = ae(i.textBefore, n.triggerChars, n.maxQueryLength);
|
|
406
|
+
if (!a) {
|
|
407
|
+
m(e);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if (a.query.length < n.minChars) {
|
|
411
|
+
m(e);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const l = t.cloneRange();
|
|
415
|
+
l.setStart(i.node, a.startOffset), l.setEnd(i.node, i.caretOffset), X(e, n, t, a.query, a.trigger, l);
|
|
416
|
+
}
|
|
417
|
+
function F(e, n) {
|
|
418
|
+
if (e.items.length === 0) return;
|
|
419
|
+
const o = e.items.length;
|
|
420
|
+
if (e.activeIndex = ((e.activeIndex + n) % o + o) % o, !e.list) return;
|
|
421
|
+
const t = Array.from(e.list.querySelectorAll(".rte-mention-item"));
|
|
422
|
+
t.forEach((i, a) => i.classList.toggle("active", a === e.activeIndex)), t[e.activeIndex]?.scrollIntoView({ block: "nearest" });
|
|
423
|
+
}
|
|
424
|
+
function be(e) {
|
|
425
|
+
return {
|
|
426
|
+
editor: e,
|
|
427
|
+
panel: null,
|
|
428
|
+
list: null,
|
|
429
|
+
replaceRange: null,
|
|
430
|
+
items: [],
|
|
431
|
+
activeIndex: 0,
|
|
432
|
+
query: "",
|
|
433
|
+
trigger: "@",
|
|
434
|
+
loading: !1,
|
|
435
|
+
isOpen: !1,
|
|
436
|
+
requestId: 0,
|
|
437
|
+
debounceHandle: null,
|
|
438
|
+
abortController: null
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function Ee(e) {
|
|
442
|
+
const n = M.get(e);
|
|
443
|
+
n && (n.panel?.parentNode && n.panel.parentNode.removeChild(n.panel), M.delete(e));
|
|
444
|
+
}
|
|
445
|
+
function H(e, n, o) {
|
|
446
|
+
if (R.has(e)) return;
|
|
447
|
+
C(e);
|
|
448
|
+
const t = {
|
|
449
|
+
beforeInput: (r) => {
|
|
450
|
+
C(e);
|
|
451
|
+
const i = E(e);
|
|
452
|
+
if (!i) return;
|
|
453
|
+
const a = V(i, e);
|
|
454
|
+
if (!a) return;
|
|
455
|
+
const l = r.inputType || "";
|
|
456
|
+
if (l.startsWith("insert")) {
|
|
457
|
+
if (r.preventDefault(), j(e, a, "after"), l === "insertParagraph" || l === "insertLineBreak") {
|
|
458
|
+
const s = l === "insertLineBreak" ? "insertLineBreak" : "insertParagraph";
|
|
459
|
+
document.execCommand(s, !1);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (l === "insertText" || l === "insertCompositionText") {
|
|
463
|
+
const s = r.data || "";
|
|
464
|
+
if (!s) return;
|
|
465
|
+
document.execCommand("insertText", !1, s);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
input: () => {
|
|
470
|
+
ye(n, o);
|
|
471
|
+
},
|
|
472
|
+
keydown: (r) => {
|
|
473
|
+
if (n.isOpen) {
|
|
474
|
+
if (r.key === "ArrowDown") {
|
|
475
|
+
r.preventDefault(), F(n, 1);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (r.key === "ArrowUp") {
|
|
479
|
+
r.preventDefault(), F(n, -1);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (r.key === "Enter" || r.key === "Tab") {
|
|
483
|
+
r.preventDefault(), K(n, o, n.activeIndex);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (r.key === "Escape") {
|
|
487
|
+
r.preventDefault(), m(n);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const i = E(e);
|
|
492
|
+
if (i) {
|
|
493
|
+
const a = A(e, i.cloneRange(), "after");
|
|
494
|
+
if (!S(a, i)) {
|
|
495
|
+
if (r.key === "Enter") {
|
|
496
|
+
r.preventDefault(), h(e, a), document.execCommand("insertParagraph", !1);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
r.key.length === 1 && !r.metaKey && !r.ctrlKey && !r.altKey && h(e, a);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (r.key === "Backspace" && z(e, "backward")) {
|
|
503
|
+
r.preventDefault();
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (r.key === "Delete" && z(e, "forward")) {
|
|
507
|
+
r.preventDefault();
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
click: (r) => {
|
|
512
|
+
const i = r.target;
|
|
513
|
+
if (!i) return;
|
|
514
|
+
const l = (i.nodeType === Node.ELEMENT_NODE ? i : i.parentElement)?.closest(w);
|
|
515
|
+
!l || !e.contains(l) || (r.preventDefault(), r.stopPropagation(), j(e, l, "after"), m(n));
|
|
516
|
+
},
|
|
517
|
+
blur: () => {
|
|
518
|
+
window.setTimeout(() => {
|
|
519
|
+
const r = document.activeElement;
|
|
520
|
+
n.panel && r && n.panel.contains(r) || m(n);
|
|
521
|
+
}, 0);
|
|
522
|
+
},
|
|
523
|
+
mousedown: (r) => {
|
|
524
|
+
if (!n.isOpen || !n.panel) return;
|
|
525
|
+
const i = r.target;
|
|
526
|
+
i && !n.panel.contains(i) && !e.contains(i) && m(n);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
e.addEventListener("beforeinput", t.beforeInput), e.addEventListener("input", t.input), e.addEventListener("keydown", t.keydown), e.addEventListener("click", t.click), e.addEventListener("blur", t.blur), document.addEventListener("mousedown", t.mousedown, !0), R.set(e, t);
|
|
530
|
+
}
|
|
531
|
+
function xe(e) {
|
|
532
|
+
const n = R.get(e);
|
|
533
|
+
n && (e.removeEventListener("beforeinput", n.beforeInput), e.removeEventListener("input", n.input), e.removeEventListener("keydown", n.keydown), e.removeEventListener("click", n.click), e.removeEventListener("blur", n.blur), document.removeEventListener("mousedown", n.mousedown, !0), R.delete(e));
|
|
534
|
+
}
|
|
535
|
+
function we() {
|
|
536
|
+
if (P || typeof document > "u") return;
|
|
537
|
+
P = !0;
|
|
538
|
+
const e = document.createElement("style");
|
|
539
|
+
e.id = "rte-mention-plugin-styles", e.textContent = `
|
|
540
|
+
.rte-mention {
|
|
541
|
+
display: inline-block;
|
|
542
|
+
padding: 0 6px;
|
|
543
|
+
margin: 0 1px;
|
|
544
|
+
border-radius: 10px;
|
|
545
|
+
background: #e8f0ff;
|
|
546
|
+
color: #1d4ed8;
|
|
547
|
+
font-weight: 600;
|
|
548
|
+
line-height: 1.6;
|
|
549
|
+
white-space: nowrap;
|
|
550
|
+
cursor: pointer;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
.rte-mention-panel {
|
|
554
|
+
width: min(320px, calc(100vw - 16px));
|
|
555
|
+
max-height: min(320px, calc(100vh - 32px));
|
|
556
|
+
overflow: hidden;
|
|
557
|
+
border: 1px solid #d9dfeb;
|
|
558
|
+
border-radius: 3px;
|
|
559
|
+
background: #ffffff;
|
|
560
|
+
box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
|
|
561
|
+
z-index: 2147483646;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.rte-mention-list {
|
|
565
|
+
max-height: min(300px, calc(100vh - 56px));
|
|
566
|
+
overflow: auto;
|
|
567
|
+
padding: 0px;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
.rte-mention-item {
|
|
571
|
+
width: 100%;
|
|
572
|
+
display: flex;
|
|
573
|
+
align-items: center;
|
|
574
|
+
justify-content: space-between;
|
|
575
|
+
gap: 12px;
|
|
576
|
+
border: none;
|
|
577
|
+
background: transparent;
|
|
578
|
+
padding: 10px 12px;
|
|
579
|
+
border-radius: 0px;
|
|
580
|
+
color: #0f172a;
|
|
581
|
+
text-align: left;
|
|
582
|
+
cursor: pointer;
|
|
583
|
+
font: inherit;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.rte-mention-item:hover,
|
|
587
|
+
.rte-mention-item.active {
|
|
588
|
+
background: #eff6ff;
|
|
589
|
+
color: #1d4ed8;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
.rte-mention-item-label mark {
|
|
593
|
+
background: rgba(59, 130, 246, 0.16);
|
|
594
|
+
color: inherit;
|
|
595
|
+
padding: 0 2px;
|
|
596
|
+
border-radius: 3px;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
.rte-mention-item-meta {
|
|
600
|
+
font-size: 12px;
|
|
601
|
+
color: #64748b;
|
|
602
|
+
white-space: nowrap;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
.rte-mention-empty {
|
|
606
|
+
padding: 12px;
|
|
607
|
+
color: #64748b;
|
|
608
|
+
font-size: 13px;
|
|
609
|
+
text-align: center;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
${b} .rte-mention {
|
|
613
|
+
background: rgba(37, 99, 235, 0.25);
|
|
614
|
+
color: #bfdbfe;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
${b} .rte-mention-panel,
|
|
618
|
+
.rte-mention-panel.rte-mention-theme-dark {
|
|
619
|
+
border-color: #364152;
|
|
620
|
+
background: #1f2937;
|
|
621
|
+
box-shadow: 0 22px 44px rgba(0, 0, 0, 0.48);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
${b} .rte-mention-item,
|
|
625
|
+
.rte-mention-panel.rte-mention-theme-dark .rte-mention-item {
|
|
626
|
+
color: #e5e7eb;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
${b} .rte-mention-item:hover,
|
|
630
|
+
${b} .rte-mention-item.active,
|
|
631
|
+
.rte-mention-panel.rte-mention-theme-dark .rte-mention-item:hover,
|
|
632
|
+
.rte-mention-panel.rte-mention-theme-dark .rte-mention-item.active {
|
|
633
|
+
background: #334155;
|
|
634
|
+
color: #bfdbfe;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
${b} .rte-mention-item-meta,
|
|
638
|
+
${b} .rte-mention-empty,
|
|
639
|
+
.rte-mention-panel.rte-mention-theme-dark .rte-mention-item-meta,
|
|
640
|
+
.rte-mention-panel.rte-mention-theme-dark .rte-mention-empty {
|
|
641
|
+
color: #9ca3af;
|
|
642
|
+
}
|
|
643
|
+
`, document.head.appendChild(e);
|
|
644
|
+
}
|
|
645
|
+
function Te(e) {
|
|
646
|
+
const n = (e.triggerChars || ["@"]).filter((o) => typeof o == "string" && o.length > 0).map((o) => o[0]);
|
|
647
|
+
return {
|
|
648
|
+
triggerChars: n.length > 0 ? n : ["@"],
|
|
649
|
+
minChars: Math.max(0, e.minChars ?? 1),
|
|
650
|
+
maxQueryLength: Math.max(1, e.maxQueryLength ?? 32),
|
|
651
|
+
maxSuggestions: Math.max(1, e.maxSuggestions ?? 8),
|
|
652
|
+
items: e.items || [
|
|
653
|
+
{ id: "john.doe", label: "John Doe", meta: "john@acme.com" },
|
|
654
|
+
{ id: "sarah.lee", label: "Sarah Lee", meta: "sarah@acme.com" },
|
|
655
|
+
{ id: "alex.chen", label: "Alex Chen", meta: "alex@acme.com" }
|
|
656
|
+
],
|
|
657
|
+
api: e.api,
|
|
658
|
+
search: e.search,
|
|
659
|
+
itemRenderer: e.itemRenderer,
|
|
660
|
+
emptyStateText: e.emptyStateText || "Type to search mentions",
|
|
661
|
+
noResultsText: e.noResultsText || "No matching mentions",
|
|
662
|
+
loadingText: e.loadingText || "Loading...",
|
|
663
|
+
insertSpaceAfterMention: e.insertSpaceAfterMention !== !1
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function L(e) {
|
|
667
|
+
const n = M.get(e);
|
|
668
|
+
if (n) return n;
|
|
669
|
+
const o = be(e);
|
|
670
|
+
return M.set(e, o), o;
|
|
671
|
+
}
|
|
672
|
+
function Ce(e) {
|
|
673
|
+
N || (N = !0, T = (n) => {
|
|
674
|
+
const o = n.target;
|
|
675
|
+
if (!(o instanceof Node)) return;
|
|
676
|
+
const r = (o.nodeType === Node.ELEMENT_NODE ? o : o.parentElement)?.closest(g) || null;
|
|
677
|
+
if (!r) return;
|
|
678
|
+
const i = L(r);
|
|
679
|
+
H(r, i, e);
|
|
680
|
+
}, document.addEventListener("focusin", T, !0));
|
|
681
|
+
}
|
|
682
|
+
function ve() {
|
|
683
|
+
!N || !T || (document.removeEventListener("focusin", T, !0), N = !1, T = null);
|
|
684
|
+
}
|
|
685
|
+
const Le = (e = {}) => {
|
|
686
|
+
we();
|
|
687
|
+
const n = Te(e);
|
|
688
|
+
return {
|
|
689
|
+
name: "mentions",
|
|
690
|
+
toolbar: [
|
|
691
|
+
{
|
|
692
|
+
label: "Mention",
|
|
693
|
+
command: "insertMention",
|
|
694
|
+
icon: '<svg width="24" height="24" focusable="false"><path d="M12.1 4a7.9 7.9 0 0 0-8 8c0 4.4 3.6 8 8 8 1.6 0 3-.4 4.4-1.3.4-.3.5-.9.2-1.3a1 1 0 0 0-1.3-.3 6 6 0 0 1-3.3.9 6 6 0 1 1 6-6v1.6c0 .8-.5 1.4-1.2 1.4-.8 0-1.2-.6-1.2-1.4V12c0-2-1.6-3.5-3.7-3.5s-3.8 1.6-3.8 3.6c0 2 1.7 3.6 3.8 3.6 1 0 1.9-.4 2.6-1 .5 1 1.4 1.6 2.5 1.6 1.8 0 3.2-1.5 3.2-3.4V12A7.9 7.9 0 0 0 12 4Zm0 9.7c-1 0-1.8-.8-1.8-1.7s.8-1.7 1.8-1.7c1 0 1.7.8 1.7 1.7s-.8 1.7-1.7 1.7Z"></path></svg>'
|
|
695
|
+
}
|
|
696
|
+
],
|
|
697
|
+
commands: {
|
|
698
|
+
insertMention: (o, t) => {
|
|
699
|
+
const r = te(t);
|
|
700
|
+
if (!r) return !1;
|
|
701
|
+
const i = L(r);
|
|
702
|
+
H(r, i, n);
|
|
703
|
+
let a = E(r);
|
|
704
|
+
a || (a = document.createRange(), a.selectNodeContents(r), a.collapse(!1), h(r, a));
|
|
705
|
+
const l = A(r, a.cloneRange(), "after");
|
|
706
|
+
S(l, a) || (h(r, l), a = l), i.query = "";
|
|
707
|
+
const s = a.cloneRange();
|
|
708
|
+
return i.trigger = n.triggerChars[0], X(i, n, a, "", i.trigger, s), !0;
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
init: () => {
|
|
712
|
+
v += 1, Ce(n), Array.from(document.querySelectorAll(g)).forEach((t) => {
|
|
713
|
+
const r = L(t);
|
|
714
|
+
H(t, r, n);
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
destroy: () => {
|
|
718
|
+
v = Math.max(0, v - 1), Array.from(document.querySelectorAll(g)).forEach((t) => {
|
|
719
|
+
m(L(t)), xe(t), Ee(t);
|
|
720
|
+
}), v === 0 && ve();
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
export {
|
|
725
|
+
Le as MentionPlugin
|
|
726
|
+
};
|