@editora/plugins 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/code.cjs.js +17 -17
- package/dist/code.esm.js +278 -224
- package/dist/media-manager.cjs.js +21 -21
- package/dist/media-manager.esm.js +117 -115
- package/dist/slash-commands.cjs.js +3 -3
- package/dist/slash-commands.esm.js +149 -149
- package/dist/template.cjs.js +21 -20
- package/dist/template.esm.js +713 -165
- package/package.json +13 -7
- package/LICENSE +0 -21
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
function O(e, t) {
|
|
2
|
-
const
|
|
2
|
+
const o = Array.from({ length: t }).map(() => "<th><p><br></p></th>").join(""), n = Array.from({ length: e }).map(
|
|
3
3
|
() => `<tr>${Array.from({ length: t }).map(() => "<td><p><br></p></td>").join("")}</tr>`
|
|
4
4
|
).join("");
|
|
5
|
-
return `<table class="rte-table"><thead><tr>${
|
|
5
|
+
return `<table class="rte-table"><thead><tr>${o}</tr></thead><tbody>${n}</tbody></table><p><br></p>`;
|
|
6
6
|
}
|
|
7
7
|
function q() {
|
|
8
8
|
return [
|
|
@@ -107,12 +107,12 @@ function q() {
|
|
|
107
107
|
];
|
|
108
108
|
}
|
|
109
109
|
function $(e) {
|
|
110
|
-
const t = [],
|
|
110
|
+
const t = [], o = /* @__PURE__ */ new Set();
|
|
111
111
|
return e.forEach((n) => {
|
|
112
|
-
const
|
|
113
|
-
!
|
|
112
|
+
const r = String(n.id || "").trim(), i = String(n.label || "").trim();
|
|
113
|
+
!r || !i || o.has(r) || (o.add(r), t.push({
|
|
114
114
|
...n,
|
|
115
|
-
id:
|
|
115
|
+
id: r,
|
|
116
116
|
label: i,
|
|
117
117
|
description: n.description ? String(n.description) : void 0,
|
|
118
118
|
keywords: Array.isArray(n.keywords) ? n.keywords.map((a) => String(a)).filter(Boolean) : void 0
|
|
@@ -120,16 +120,16 @@ function $(e) {
|
|
|
120
120
|
}), t;
|
|
121
121
|
}
|
|
122
122
|
function D(e) {
|
|
123
|
-
const t = (e.triggerChar || "/")[0] || "/",
|
|
123
|
+
const t = (e.triggerChar || "/")[0] || "/", o = e.includeDefaultItems !== !1, n = o ? [...e.items || [], ...q()] : e.items || [];
|
|
124
124
|
return {
|
|
125
125
|
triggerChar: t,
|
|
126
126
|
minChars: Math.max(0, e.minChars ?? 0),
|
|
127
127
|
maxQueryLength: Math.max(1, e.maxQueryLength ?? 48),
|
|
128
128
|
maxSuggestions: Math.max(1, e.maxSuggestions ?? 10),
|
|
129
129
|
requireBoundary: e.requireBoundary !== !1,
|
|
130
|
-
includeDefaultItems:
|
|
130
|
+
includeDefaultItems: o,
|
|
131
131
|
items: $(n),
|
|
132
|
-
itemRenderer: e.itemRenderer,
|
|
132
|
+
itemRenderer: e.itemRenderer || ((r) => r.label),
|
|
133
133
|
emptyStateText: e.emptyStateText || "No commands found",
|
|
134
134
|
panelLabel: e.panelLabel || "Slash commands"
|
|
135
135
|
};
|
|
@@ -241,18 +241,18 @@ function F(e) {
|
|
|
241
241
|
if (e?.editorElement instanceof HTMLElement) {
|
|
242
242
|
const n = e.editorElement;
|
|
243
243
|
if (n.matches(s)) return n;
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
244
|
+
const r = n.querySelector(s);
|
|
245
|
+
if (r instanceof HTMLElement) return r;
|
|
246
246
|
}
|
|
247
247
|
const t = window.getSelection();
|
|
248
248
|
if (t && t.rangeCount > 0) {
|
|
249
249
|
const n = t.getRangeAt(0).startContainer, i = (n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(s);
|
|
250
250
|
if (i) return i;
|
|
251
251
|
}
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
if (
|
|
255
|
-
const n =
|
|
252
|
+
const o = document.activeElement;
|
|
253
|
+
if (o) {
|
|
254
|
+
if (o.matches(s)) return o;
|
|
255
|
+
const n = o.closest(s);
|
|
256
256
|
if (n) return n;
|
|
257
257
|
}
|
|
258
258
|
return document.querySelector(s);
|
|
@@ -266,30 +266,30 @@ function _(e) {
|
|
|
266
266
|
function E(e) {
|
|
267
267
|
const t = window.getSelection();
|
|
268
268
|
if (!t || t.rangeCount === 0) return null;
|
|
269
|
-
const
|
|
270
|
-
return e.contains(
|
|
269
|
+
const o = t.getRangeAt(0);
|
|
270
|
+
return e.contains(o.commonAncestorContainer) ? o.cloneRange() : null;
|
|
271
271
|
}
|
|
272
272
|
function y(e, t) {
|
|
273
|
-
const
|
|
274
|
-
|
|
273
|
+
const o = window.getSelection();
|
|
274
|
+
o && (o.removeAllRanges(), o.addRange(t), e.focus({ preventScroll: !0 }));
|
|
275
275
|
}
|
|
276
276
|
function j(e) {
|
|
277
277
|
if (!e.collapsed) return null;
|
|
278
|
-
const t = e.startContainer,
|
|
278
|
+
const t = e.startContainer, o = e.startOffset;
|
|
279
279
|
if (t.nodeType === Node.TEXT_NODE) {
|
|
280
280
|
const n = t;
|
|
281
281
|
return {
|
|
282
282
|
node: n,
|
|
283
|
-
textBefore: n.data.slice(0,
|
|
284
|
-
caretOffset:
|
|
283
|
+
textBefore: n.data.slice(0, o),
|
|
284
|
+
caretOffset: o
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
if (t.nodeType === Node.ELEMENT_NODE) {
|
|
288
288
|
const n = t;
|
|
289
|
-
if (
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
const i =
|
|
289
|
+
if (o > 0) {
|
|
290
|
+
const r = n.childNodes[o - 1];
|
|
291
|
+
if (r && r.nodeType === Node.TEXT_NODE) {
|
|
292
|
+
const i = r;
|
|
293
293
|
return {
|
|
294
294
|
node: i,
|
|
295
295
|
textBefore: i.data,
|
|
@@ -300,52 +300,52 @@ function j(e) {
|
|
|
300
300
|
}
|
|
301
301
|
return null;
|
|
302
302
|
}
|
|
303
|
-
function K(e, t,
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
303
|
+
function K(e, t, o, n) {
|
|
304
|
+
const r = e.lastIndexOf(t);
|
|
305
|
+
if (r < 0 || n && !_(e[r - 1]))
|
|
306
306
|
return null;
|
|
307
|
-
const i = e.slice(
|
|
308
|
-
return /\s/.test(i) || i.length >
|
|
307
|
+
const i = e.slice(r + 1);
|
|
308
|
+
return /\s/.test(i) || i.length > o ? null : {
|
|
309
309
|
trigger: t,
|
|
310
310
|
query: i,
|
|
311
|
-
startOffset:
|
|
311
|
+
startOffset: r
|
|
312
312
|
};
|
|
313
313
|
}
|
|
314
314
|
function Q(e, t) {
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
const n =
|
|
315
|
+
const o = t.cloneRange();
|
|
316
|
+
o.collapse(!1);
|
|
317
|
+
const n = o.getClientRects();
|
|
318
318
|
if (n.length > 0)
|
|
319
319
|
return n[n.length - 1];
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
const i =
|
|
323
|
-
return
|
|
320
|
+
const r = document.createElement("span");
|
|
321
|
+
r.textContent = "", o.insertNode(r);
|
|
322
|
+
const i = r.getBoundingClientRect();
|
|
323
|
+
return r.remove(), e.normalize(), i;
|
|
324
324
|
}
|
|
325
325
|
function A(e, t) {
|
|
326
326
|
if (!e.panel) return;
|
|
327
|
-
const
|
|
327
|
+
const o = Q(e.editor, t), n = e.panel;
|
|
328
328
|
n.style.display = "block", n.classList.add("show"), n.style.left = "0px", n.style.top = "0px";
|
|
329
|
-
const
|
|
330
|
-
let l = Math.max(8, Math.min(
|
|
331
|
-
d +
|
|
329
|
+
const r = n.getBoundingClientRect(), i = window.innerWidth, a = window.innerHeight;
|
|
330
|
+
let l = Math.max(8, Math.min(o.left, i - r.width - 8)), d = o.bottom + 8;
|
|
331
|
+
d + r.height > a - 8 && (d = Math.max(8, o.top - r.height - 8)), n.style.position = "fixed", n.style.left = `${l}px`, n.style.top = `${d}px`;
|
|
332
332
|
}
|
|
333
333
|
function k(e, t) {
|
|
334
334
|
if (!t) return m(e);
|
|
335
|
-
const
|
|
336
|
-
if (
|
|
337
|
-
const i = m(e.slice(0,
|
|
335
|
+
const o = e.toLowerCase(), n = t.toLowerCase(), r = o.indexOf(n);
|
|
336
|
+
if (r < 0) return m(e);
|
|
337
|
+
const i = m(e.slice(0, r)), a = m(e.slice(r, r + t.length)), l = m(e.slice(r + t.length));
|
|
338
338
|
return `${i}<mark>${a}</mark>${l}`;
|
|
339
339
|
}
|
|
340
340
|
function U(e, t) {
|
|
341
341
|
if (e.panel && e.list) return;
|
|
342
|
-
const
|
|
343
|
-
|
|
342
|
+
const o = document.createElement("div");
|
|
343
|
+
o.className = "rte-slash-panel", o.style.display = "none", o.setAttribute("role", "dialog"), o.setAttribute("aria-modal", "false");
|
|
344
344
|
const n = document.createElement("div");
|
|
345
|
-
n.className = "rte-slash-list", n.setAttribute("role", "listbox"), n.setAttribute("aria-label", t.panelLabel),
|
|
346
|
-
|
|
347
|
-
}),
|
|
348
|
-
const i =
|
|
345
|
+
n.className = "rte-slash-list", n.setAttribute("role", "listbox"), n.setAttribute("aria-label", t.panelLabel), o.appendChild(n), document.body.appendChild(o), e.panel = o, e.list = n, o.addEventListener("mousedown", (r) => {
|
|
346
|
+
r.preventDefault();
|
|
347
|
+
}), o.addEventListener("click", (r) => {
|
|
348
|
+
const i = r.target;
|
|
349
349
|
if (!i) return;
|
|
350
350
|
const a = i.closest(".rte-slash-item");
|
|
351
351
|
if (!a) return;
|
|
@@ -356,8 +356,8 @@ function U(e, t) {
|
|
|
356
356
|
function c(e) {
|
|
357
357
|
e.panel && (e.panel.style.display = "none", e.panel.classList.remove("show"), e.isOpen = !1, e.filteredItems = [], e.activeIndex = 0, e.query = "", e.replaceRange = null, e.anchorRange = null);
|
|
358
358
|
}
|
|
359
|
-
function W(e, t,
|
|
360
|
-
if (!t) return e.slice(0,
|
|
359
|
+
function W(e, t, o) {
|
|
360
|
+
if (!t) return e.slice(0, o);
|
|
361
361
|
const n = t.toLowerCase();
|
|
362
362
|
return e.filter((i) => [
|
|
363
363
|
i.id,
|
|
@@ -365,30 +365,30 @@ function W(e, t, r) {
|
|
|
365
365
|
i.description || "",
|
|
366
366
|
i.command || "",
|
|
367
367
|
...i.keywords || []
|
|
368
|
-
].join(" ").toLowerCase().includes(n)).slice(0,
|
|
368
|
+
].join(" ").toLowerCase().includes(n)).slice(0, o);
|
|
369
369
|
}
|
|
370
370
|
function Z(e, t) {
|
|
371
371
|
if (!e.list) return;
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
372
|
+
const o = e.list;
|
|
373
|
+
if (o.innerHTML = "", e.filteredItems.length === 0) {
|
|
374
374
|
const n = document.createElement("div");
|
|
375
|
-
n.className = "rte-slash-empty", n.textContent = t.emptyStateText,
|
|
375
|
+
n.className = "rte-slash-empty", n.textContent = t.emptyStateText, o.appendChild(n), o.removeAttribute("aria-activedescendant");
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
|
-
e.filteredItems.forEach((n,
|
|
378
|
+
e.filteredItems.forEach((n, r) => {
|
|
379
379
|
const i = document.createElement("button");
|
|
380
|
-
i.type = "button", i.className = "rte-slash-item", i.setAttribute("role", "option"), i.setAttribute("data-index", String(
|
|
380
|
+
i.type = "button", i.className = "rte-slash-item", i.setAttribute("role", "option"), i.setAttribute("data-index", String(r)), i.setAttribute("id", `rte-slash-item-${e.instanceId}-${r}`), i.setAttribute("aria-selected", r === e.activeIndex ? "true" : "false"), i.setAttribute("aria-label", n.description ? `${n.label} - ${n.description}` : n.label), r === e.activeIndex && i.classList.add("active"), t.itemRenderer ? i.innerHTML = t.itemRenderer(n, e.query) : i.innerHTML = `
|
|
381
381
|
<span class="rte-slash-item-title">${k(n.label, e.query)}</span>
|
|
382
382
|
${n.description ? `<span class="rte-slash-item-description">${k(n.description, e.query)}</span>` : ""}
|
|
383
|
-
`,
|
|
384
|
-
}), e.filteredItems.length > 0 &&
|
|
383
|
+
`, o.appendChild(i);
|
|
384
|
+
}), e.filteredItems.length > 0 && o.setAttribute("aria-activedescendant", `rte-slash-item-${e.instanceId}-${e.activeIndex}`);
|
|
385
385
|
}
|
|
386
386
|
function G(e, t) {
|
|
387
387
|
if (t === e.innerHTML) return;
|
|
388
|
-
const
|
|
389
|
-
if (typeof
|
|
388
|
+
const o = window.execEditorCommand || window.executeEditorCommand;
|
|
389
|
+
if (typeof o == "function")
|
|
390
390
|
try {
|
|
391
|
-
|
|
391
|
+
o("recordDomTransaction", e, t, e.innerHTML);
|
|
392
392
|
} catch {
|
|
393
393
|
}
|
|
394
394
|
}
|
|
@@ -402,14 +402,14 @@ function L(e, t) {
|
|
|
402
402
|
return !0;
|
|
403
403
|
} catch {
|
|
404
404
|
}
|
|
405
|
-
const
|
|
406
|
-
if (!
|
|
407
|
-
const n =
|
|
405
|
+
const o = window.getSelection();
|
|
406
|
+
if (!o || o.rangeCount === 0) return !1;
|
|
407
|
+
const n = o.getRangeAt(0);
|
|
408
408
|
if (!e.contains(n.commonAncestorContainer)) return !1;
|
|
409
409
|
n.deleteContents();
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
const i =
|
|
410
|
+
const r = document.createElement("template");
|
|
411
|
+
r.innerHTML = t;
|
|
412
|
+
const i = r.content, a = i.lastChild;
|
|
413
413
|
if (n.insertNode(i), a) {
|
|
414
414
|
const l = document.createRange();
|
|
415
415
|
l.setStartAfter(a), l.collapse(!0), y(e, l);
|
|
@@ -423,15 +423,15 @@ function X(e, t) {
|
|
|
423
423
|
return !0;
|
|
424
424
|
} catch {
|
|
425
425
|
}
|
|
426
|
-
const
|
|
427
|
-
if (!
|
|
428
|
-
const n =
|
|
426
|
+
const o = window.getSelection();
|
|
427
|
+
if (!o || o.rangeCount === 0) return !1;
|
|
428
|
+
const n = o.getRangeAt(0);
|
|
429
429
|
if (!e.contains(n.commonAncestorContainer)) return !1;
|
|
430
430
|
n.deleteContents();
|
|
431
|
-
const
|
|
432
|
-
n.insertNode(
|
|
431
|
+
const r = document.createTextNode(t);
|
|
432
|
+
n.insertNode(r);
|
|
433
433
|
const i = document.createRange();
|
|
434
|
-
return i.setStart(
|
|
434
|
+
return i.setStart(r, r.length), i.collapse(!0), y(e, i), !0;
|
|
435
435
|
}
|
|
436
436
|
function J(e, t) {
|
|
437
437
|
switch (e.toLowerCase()) {
|
|
@@ -485,38 +485,38 @@ function J(e, t) {
|
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
|
-
function S(e, t,
|
|
488
|
+
function S(e, t, o) {
|
|
489
489
|
const n = I(e);
|
|
490
490
|
if (n && typeof n.execCommand == "function")
|
|
491
491
|
try {
|
|
492
|
-
if (n.execCommand(t,
|
|
492
|
+
if (n.execCommand(t, o) !== !1) return !0;
|
|
493
493
|
} catch {
|
|
494
494
|
}
|
|
495
|
-
const
|
|
496
|
-
if (typeof
|
|
495
|
+
const r = window.execEditorCommand || window.executeEditorCommand;
|
|
496
|
+
if (typeof r == "function")
|
|
497
497
|
try {
|
|
498
|
-
if (
|
|
498
|
+
if (r(t, o, {
|
|
499
499
|
editorElement: n,
|
|
500
500
|
contentElement: e
|
|
501
501
|
}) !== !1) return !0;
|
|
502
502
|
} catch {
|
|
503
503
|
}
|
|
504
|
-
return J(t,
|
|
504
|
+
return J(t, o);
|
|
505
505
|
}
|
|
506
506
|
async function Y(e, t) {
|
|
507
|
-
const
|
|
508
|
-
editor:
|
|
507
|
+
const o = e.editor, n = I(o), r = {
|
|
508
|
+
editor: o,
|
|
509
509
|
editorRoot: n,
|
|
510
510
|
query: e.query,
|
|
511
511
|
trigger: e.trigger,
|
|
512
|
-
executeCommand: (i, a) => S(
|
|
513
|
-
insertHTML: (i) => L(
|
|
512
|
+
executeCommand: (i, a) => S(o, i, a),
|
|
513
|
+
insertHTML: (i) => L(o, i)
|
|
514
514
|
};
|
|
515
|
-
return t.action ? await Promise.resolve(t.action(
|
|
515
|
+
return t.action ? await Promise.resolve(t.action(r)) !== !1 : t.insertHTML ? L(o, t.insertHTML) : t.command ? S(o, t.command, t.commandValue) : !1;
|
|
516
516
|
}
|
|
517
517
|
async function M(e, t) {
|
|
518
518
|
if (t < 0 || t >= e.filteredItems.length || !e.replaceRange) return;
|
|
519
|
-
const
|
|
519
|
+
const o = e.filteredItems[t], n = e.editor, r = n.innerHTML, i = `${e.trigger}${e.query}`;
|
|
520
520
|
if (!window.getSelection()) return;
|
|
521
521
|
const l = e.replaceRange.cloneRange();
|
|
522
522
|
if (!n.contains(l.commonAncestorContainer)) return;
|
|
@@ -525,23 +525,23 @@ async function M(e, t) {
|
|
|
525
525
|
d.collapse(!0), y(n, d);
|
|
526
526
|
let x = !1;
|
|
527
527
|
try {
|
|
528
|
-
x = await Y(e,
|
|
528
|
+
x = await Y(e, o);
|
|
529
529
|
} catch {
|
|
530
530
|
x = !1;
|
|
531
531
|
}
|
|
532
|
-
c(e), x ? (V(n), G(n,
|
|
532
|
+
c(e), x ? (V(n), G(n, r)) : i && X(n, i), n.focus({ preventScroll: !0 });
|
|
533
533
|
}
|
|
534
534
|
function R(e, t) {
|
|
535
535
|
if (e.filteredItems.length === 0) return;
|
|
536
|
-
const
|
|
537
|
-
if (e.activeIndex = ((e.activeIndex + t) %
|
|
536
|
+
const o = e.filteredItems.length;
|
|
537
|
+
if (e.activeIndex = ((e.activeIndex + t) % o + o) % o, !e.list) return;
|
|
538
538
|
const n = Array.from(e.list.querySelectorAll(".rte-slash-item"));
|
|
539
539
|
n.forEach((i, a) => {
|
|
540
540
|
const l = a === e.activeIndex;
|
|
541
541
|
i.classList.toggle("active", l), i.setAttribute("aria-selected", l ? "true" : "false");
|
|
542
542
|
});
|
|
543
|
-
const
|
|
544
|
-
|
|
543
|
+
const r = n[e.activeIndex];
|
|
544
|
+
r && (e.list.setAttribute("aria-activedescendant", r.id), r.scrollIntoView({ block: "nearest" }));
|
|
545
545
|
}
|
|
546
546
|
function T(e) {
|
|
547
547
|
if (!(!e.isOpen || !e.panel || !e.anchorRange)) {
|
|
@@ -552,27 +552,27 @@ function T(e) {
|
|
|
552
552
|
A(e, e.anchorRange);
|
|
553
553
|
}
|
|
554
554
|
}
|
|
555
|
-
function N(e, t,
|
|
556
|
-
U(e, t), e.query = n, e.trigger =
|
|
555
|
+
function N(e, t, o, n, r, i) {
|
|
556
|
+
U(e, t), e.query = n, e.trigger = r, e.replaceRange = i.cloneRange(), e.anchorRange = o.cloneRange(), e.filteredItems = W(e.items, n, t.maxSuggestions), e.activeIndex = 0, e.isOpen = !0, e.panel && (Z(e, t), A(e, o));
|
|
557
557
|
}
|
|
558
558
|
function ee(e, t) {
|
|
559
|
-
const
|
|
560
|
-
if (
|
|
559
|
+
const o = e.editor;
|
|
560
|
+
if (o.getAttribute("contenteditable") === "false") {
|
|
561
561
|
c(e);
|
|
562
562
|
return;
|
|
563
563
|
}
|
|
564
|
-
const n = E(
|
|
564
|
+
const n = E(o);
|
|
565
565
|
if (!n || !n.collapsed) {
|
|
566
566
|
c(e);
|
|
567
567
|
return;
|
|
568
568
|
}
|
|
569
|
-
const
|
|
570
|
-
if (!
|
|
569
|
+
const r = j(n);
|
|
570
|
+
if (!r) {
|
|
571
571
|
c(e);
|
|
572
572
|
return;
|
|
573
573
|
}
|
|
574
574
|
const i = K(
|
|
575
|
-
|
|
575
|
+
r.textBefore,
|
|
576
576
|
t.triggerChar,
|
|
577
577
|
t.maxQueryLength,
|
|
578
578
|
t.requireBoundary
|
|
@@ -586,16 +586,16 @@ function ee(e, t) {
|
|
|
586
586
|
return;
|
|
587
587
|
}
|
|
588
588
|
const a = n.cloneRange();
|
|
589
|
-
a.setStart(
|
|
589
|
+
a.setStart(r.node, i.startOffset), a.setEnd(r.node, r.caretOffset), N(e, t, n, i.query, i.trigger, a);
|
|
590
590
|
}
|
|
591
591
|
function H(e, t) {
|
|
592
|
-
const
|
|
593
|
-
if (
|
|
592
|
+
const o = e.editor;
|
|
593
|
+
if (o.getAttribute("contenteditable") === "false")
|
|
594
594
|
return !1;
|
|
595
|
-
let n = E(
|
|
596
|
-
n || (n = document.createRange(), n.selectNodeContents(
|
|
597
|
-
const
|
|
598
|
-
return
|
|
595
|
+
let n = E(o);
|
|
596
|
+
n || (n = document.createRange(), n.selectNodeContents(o), n.collapse(!1), y(o, n));
|
|
597
|
+
const r = n.cloneRange();
|
|
598
|
+
return r.collapse(!0), N(e, t, n, "", t.triggerChar, r), !0;
|
|
599
599
|
}
|
|
600
600
|
function te(e) {
|
|
601
601
|
return !(e.metaKey || e.ctrlKey) || e.altKey ? !1 : e.key === "/" || e.code === "Slash";
|
|
@@ -617,9 +617,9 @@ function ne(e, t) {
|
|
|
617
617
|
};
|
|
618
618
|
}
|
|
619
619
|
function w(e, t) {
|
|
620
|
-
const
|
|
621
|
-
if (
|
|
622
|
-
return
|
|
620
|
+
const o = g.get(e);
|
|
621
|
+
if (o)
|
|
622
|
+
return o.items = t.items, o;
|
|
623
623
|
const n = ne(e, t);
|
|
624
624
|
return g.set(e, n), n;
|
|
625
625
|
}
|
|
@@ -627,63 +627,63 @@ function re(e) {
|
|
|
627
627
|
const t = g.get(e);
|
|
628
628
|
t && (t.panel?.parentNode && t.panel.parentNode.removeChild(t.panel), g.delete(e));
|
|
629
629
|
}
|
|
630
|
-
function C(e, t,
|
|
630
|
+
function C(e, t, o) {
|
|
631
631
|
if (p.has(e)) return;
|
|
632
632
|
const n = {
|
|
633
633
|
input: () => {
|
|
634
|
-
ee(t,
|
|
634
|
+
ee(t, o);
|
|
635
635
|
},
|
|
636
|
-
keydown: (
|
|
636
|
+
keydown: (r) => {
|
|
637
637
|
if (t.editor.getAttribute("contenteditable") === "false") {
|
|
638
638
|
c(t);
|
|
639
639
|
return;
|
|
640
640
|
}
|
|
641
|
-
if (!t.isOpen && te(
|
|
642
|
-
|
|
641
|
+
if (!t.isOpen && te(r)) {
|
|
642
|
+
r.preventDefault(), H(t, o);
|
|
643
643
|
return;
|
|
644
644
|
}
|
|
645
645
|
if (t.isOpen) {
|
|
646
|
-
if (
|
|
647
|
-
|
|
646
|
+
if (r.key === "ArrowDown") {
|
|
647
|
+
r.preventDefault(), R(t, 1);
|
|
648
648
|
return;
|
|
649
649
|
}
|
|
650
|
-
if (
|
|
651
|
-
|
|
650
|
+
if (r.key === "ArrowUp") {
|
|
651
|
+
r.preventDefault(), R(t, -1);
|
|
652
652
|
return;
|
|
653
653
|
}
|
|
654
|
-
if (
|
|
654
|
+
if (r.key === "Enter" || r.key === "Tab") {
|
|
655
655
|
if (t.filteredItems.length === 0) {
|
|
656
|
-
|
|
656
|
+
r.key === "Tab" && r.preventDefault(), c(t);
|
|
657
657
|
return;
|
|
658
658
|
}
|
|
659
|
-
|
|
659
|
+
r.preventDefault(), M(t, t.activeIndex);
|
|
660
660
|
return;
|
|
661
661
|
}
|
|
662
|
-
if (
|
|
663
|
-
|
|
662
|
+
if (r.key === "Escape") {
|
|
663
|
+
r.preventDefault(), c(t);
|
|
664
664
|
return;
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
},
|
|
668
668
|
blur: () => {
|
|
669
669
|
window.setTimeout(() => {
|
|
670
|
-
const
|
|
671
|
-
t.panel &&
|
|
670
|
+
const r = document.activeElement;
|
|
671
|
+
t.panel && r && t.panel.contains(r) || c(t);
|
|
672
672
|
}, 0);
|
|
673
673
|
},
|
|
674
|
-
mousedown: (
|
|
674
|
+
mousedown: (r) => {
|
|
675
675
|
if (!t.isOpen || !t.panel) return;
|
|
676
|
-
const i =
|
|
676
|
+
const i = r.target;
|
|
677
677
|
i && !t.panel.contains(i) && !e.contains(i) && c(t);
|
|
678
678
|
},
|
|
679
679
|
selectionchange: () => {
|
|
680
680
|
if (!t.isOpen) return;
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
681
|
+
const r = E(e);
|
|
682
|
+
if (!r || !r.collapsed) {
|
|
683
683
|
c(t);
|
|
684
684
|
return;
|
|
685
685
|
}
|
|
686
|
-
t.anchorRange =
|
|
686
|
+
t.anchorRange = r.cloneRange(), T(t);
|
|
687
687
|
},
|
|
688
688
|
reposition: () => {
|
|
689
689
|
T(t);
|
|
@@ -697,12 +697,12 @@ function oe(e) {
|
|
|
697
697
|
}
|
|
698
698
|
function ie(e) {
|
|
699
699
|
b || (b = !0, f = (t) => {
|
|
700
|
-
const
|
|
701
|
-
if (!(
|
|
702
|
-
const
|
|
703
|
-
if (!
|
|
704
|
-
const i = w(
|
|
705
|
-
C(
|
|
700
|
+
const o = t.target;
|
|
701
|
+
if (!(o instanceof Node)) return;
|
|
702
|
+
const r = P(o)?.closest(s) || null;
|
|
703
|
+
if (!r) return;
|
|
704
|
+
const i = w(r, e);
|
|
705
|
+
C(r, i, e);
|
|
706
706
|
}, document.addEventListener("focusin", f, !0));
|
|
707
707
|
}
|
|
708
708
|
function ae() {
|
|
@@ -722,11 +722,11 @@ const le = (e = {}) => {
|
|
|
722
722
|
}
|
|
723
723
|
],
|
|
724
724
|
commands: {
|
|
725
|
-
openSlashCommands: (
|
|
726
|
-
const
|
|
727
|
-
if (!
|
|
728
|
-
const i = w(
|
|
729
|
-
return C(
|
|
725
|
+
openSlashCommands: (o, n) => {
|
|
726
|
+
const r = F(n);
|
|
727
|
+
if (!r) return !1;
|
|
728
|
+
const i = w(r, t);
|
|
729
|
+
return C(r, i, t), H(i, t);
|
|
730
730
|
}
|
|
731
731
|
},
|
|
732
732
|
keymap: {
|
|
@@ -735,14 +735,14 @@ const le = (e = {}) => {
|
|
|
735
735
|
},
|
|
736
736
|
init: () => {
|
|
737
737
|
h += 1, ie(t), Array.from(document.querySelectorAll(s)).forEach((n) => {
|
|
738
|
-
const
|
|
739
|
-
C(n,
|
|
738
|
+
const r = w(n, t);
|
|
739
|
+
C(n, r, t);
|
|
740
740
|
});
|
|
741
741
|
},
|
|
742
742
|
destroy: () => {
|
|
743
743
|
h = Math.max(0, h - 1), Array.from(document.querySelectorAll(s)).forEach((n) => {
|
|
744
|
-
const
|
|
745
|
-
|
|
744
|
+
const r = g.get(n);
|
|
745
|
+
r && (c(r), oe(n), re(n));
|
|
746
746
|
}), h === 0 && ae();
|
|
747
747
|
}
|
|
748
748
|
};
|