@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
|
import "./shared-config.esm.js";
|
|
2
|
-
let A = null,
|
|
2
|
+
let A = null, p = null, s = null, R = [], D = !1, I = null, V = 0, j = 0, $ = 0, C = 0, N = 1, T = null;
|
|
3
3
|
const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
4
|
-
const r = (
|
|
5
|
-
|
|
4
|
+
const r = (a) => {
|
|
5
|
+
a.key !== "Escape" || !e.isConnected || (a.preventDefault(), a.stopPropagation(), t());
|
|
6
6
|
};
|
|
7
7
|
return document.addEventListener("keydown", r, !0), () => {
|
|
8
8
|
document.removeEventListener("keydown", r, !0);
|
|
@@ -462,10 +462,10 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
462
462
|
}, F = (e, t) => {
|
|
463
463
|
const r = window.getSelection();
|
|
464
464
|
r && r.rangeCount > 0 && (A = r.getRangeAt(0).cloneRange());
|
|
465
|
-
const
|
|
466
|
-
let o = "upload", d = "",
|
|
465
|
+
const a = _(t), i = H();
|
|
466
|
+
let o = "upload", d = "", l = "", c = "", g = "";
|
|
467
467
|
const v = () => {
|
|
468
|
-
|
|
468
|
+
i.innerHTML = `
|
|
469
469
|
<div class="rte-media-header">
|
|
470
470
|
<h2 class="rte-media-title">Insert ${e === "image" ? "Image" : "Video"}</h2>
|
|
471
471
|
<button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
|
|
@@ -508,11 +508,11 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
508
508
|
<div class="rte-media-grid">
|
|
509
509
|
<div class="rte-media-field">
|
|
510
510
|
<label class="rte-media-label">Width (px)</label>
|
|
511
|
-
<input type="number" id="width-input" class="rte-media-input" placeholder="Auto" value="${
|
|
511
|
+
<input type="number" id="width-input" class="rte-media-input" placeholder="Auto" value="${l}">
|
|
512
512
|
</div>
|
|
513
513
|
<div class="rte-media-field">
|
|
514
514
|
<label class="rte-media-label">Height (px)</label>
|
|
515
|
-
<input type="number" id="height-input" class="rte-media-input" placeholder="Auto" value="${
|
|
515
|
+
<input type="number" id="height-input" class="rte-media-input" placeholder="Auto" value="${c}">
|
|
516
516
|
</div>
|
|
517
517
|
</div>
|
|
518
518
|
${d ? `
|
|
@@ -533,19 +533,19 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
533
533
|
</div>
|
|
534
534
|
`;
|
|
535
535
|
};
|
|
536
|
-
v(),
|
|
536
|
+
v(), a.appendChild(i), document.body.appendChild(a);
|
|
537
537
|
let k = () => {
|
|
538
538
|
};
|
|
539
539
|
const h = () => {
|
|
540
|
-
k(),
|
|
540
|
+
k(), a.parentNode && a.parentNode.removeChild(a);
|
|
541
541
|
};
|
|
542
|
-
k = B(
|
|
542
|
+
k = B(a, h);
|
|
543
543
|
const L = () => {
|
|
544
544
|
if (!d) return;
|
|
545
545
|
const n = e === "image" ? document.createElement("img") : document.createElement("video");
|
|
546
|
-
n.src = d, n.setAttribute("data-media-type", e), e === "image" && g && (n.alt = g),
|
|
546
|
+
n.src = d, n.setAttribute("data-media-type", e), e === "image" && g && (n.alt = g), l && (n.style.width = `${l}px`, n.setAttribute("width", l)), c && (n.style.height = `${c}px`, n.setAttribute("height", c)), e === "video" && (n.controls = !0), !l && !c ? n.style.cssText = "max-width: 100%; height: auto; display: block; margin: 1em 0; cursor: pointer;" : n.style.cssText = `display: block; margin: 1em 0; cursor: pointer; ${l ? `width: ${l}px;` : "max-width: 100%;"} ${c ? `height: ${c}px;` : "height: auto;"}`, A && (A.deleteContents(), A.insertNode(n)), h();
|
|
547
547
|
}, x = async (n) => {
|
|
548
|
-
const b =
|
|
548
|
+
const b = i.querySelector("#upload-progress"), u = i.querySelector("#progress-bar"), y = i.querySelector("#progress-text");
|
|
549
549
|
if (b && u && y) {
|
|
550
550
|
b.style.display = "block";
|
|
551
551
|
let M = 0;
|
|
@@ -564,13 +564,13 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
}, m = () => {
|
|
567
|
-
const n =
|
|
567
|
+
const n = i.querySelector(".close-btn"), b = i.querySelector(".cancel-btn"), u = i.querySelector("#insert-btn"), y = i.querySelector(".tab-upload"), M = i.querySelector(".tab-url");
|
|
568
568
|
if (n?.addEventListener("click", h), b?.addEventListener("click", h), u?.addEventListener("click", L), y?.addEventListener("click", () => {
|
|
569
569
|
o = "upload", v(), m();
|
|
570
570
|
}), M?.addEventListener("click", () => {
|
|
571
571
|
o = "url", v(), m();
|
|
572
572
|
}), o === "upload") {
|
|
573
|
-
const f =
|
|
573
|
+
const f = i.querySelector(".dropzone"), w = i.querySelector("#file-input");
|
|
574
574
|
f?.addEventListener("click", () => w?.click()), f?.addEventListener("dragover", (S) => {
|
|
575
575
|
S.preventDefault(), f.classList.add("is-dragover");
|
|
576
576
|
}), f?.addEventListener("dragleave", () => {
|
|
@@ -585,20 +585,20 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
585
585
|
});
|
|
586
586
|
}
|
|
587
587
|
if (o === "url") {
|
|
588
|
-
const f =
|
|
588
|
+
const f = i.querySelector("#url-input"), w = i.querySelector("#alt-input"), S = i.querySelector("#width-input"), z = i.querySelector("#height-input");
|
|
589
589
|
f?.addEventListener("input", () => {
|
|
590
590
|
d = f.value, v(), m();
|
|
591
591
|
}), w?.addEventListener("input", () => {
|
|
592
592
|
g = w.value;
|
|
593
593
|
}), S?.addEventListener("input", () => {
|
|
594
|
-
|
|
594
|
+
l = S.value;
|
|
595
595
|
}), z?.addEventListener("input", () => {
|
|
596
|
-
|
|
596
|
+
c = z.value;
|
|
597
597
|
});
|
|
598
598
|
}
|
|
599
599
|
};
|
|
600
|
-
m(),
|
|
601
|
-
n.target ===
|
|
600
|
+
m(), a.addEventListener("click", (n) => {
|
|
601
|
+
n.target === a && h();
|
|
602
602
|
});
|
|
603
603
|
}, K = () => {
|
|
604
604
|
["nw", "ne", "sw", "se"].forEach((t) => {
|
|
@@ -617,19 +617,19 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
617
617
|
`, r.setAttribute("data-position", t), document.body.appendChild(r), R.push(r);
|
|
618
618
|
});
|
|
619
619
|
}, q = () => {
|
|
620
|
-
if (!
|
|
620
|
+
if (!p) {
|
|
621
621
|
R.forEach((r) => r.style.display = "none");
|
|
622
622
|
return;
|
|
623
623
|
}
|
|
624
|
-
const e =
|
|
624
|
+
const e = p.getBoundingClientRect(), t = {
|
|
625
625
|
nw: { x: e.left - 5, y: e.top - 5 },
|
|
626
626
|
ne: { x: e.right - 5, y: e.top - 5 },
|
|
627
627
|
sw: { x: e.left - 5, y: e.bottom - 5 },
|
|
628
628
|
se: { x: e.right - 5, y: e.bottom - 5 }
|
|
629
629
|
};
|
|
630
630
|
R.forEach((r) => {
|
|
631
|
-
const
|
|
632
|
-
r.style.left = `${
|
|
631
|
+
const a = r.getAttribute("data-position"), i = t[a];
|
|
632
|
+
r.style.left = `${i.x}px`, r.style.top = `${i.y}px`, r.style.display = "block";
|
|
633
633
|
});
|
|
634
634
|
}, J = (e) => {
|
|
635
635
|
const t = _(e), r = H(!0);
|
|
@@ -648,19 +648,19 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
648
648
|
<button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
|
|
649
649
|
</div>
|
|
650
650
|
`, t.appendChild(r), document.body.appendChild(t);
|
|
651
|
-
const
|
|
652
|
-
let
|
|
651
|
+
const a = r.querySelector("#alt-text-input"), i = r.querySelector(".close-btn"), o = r.querySelector(".cancel-btn"), d = r.querySelector(".save-btn");
|
|
652
|
+
let l = () => {
|
|
653
653
|
};
|
|
654
|
-
const
|
|
655
|
-
|
|
654
|
+
const c = () => {
|
|
655
|
+
l(), t.parentNode && t.parentNode.removeChild(t);
|
|
656
656
|
};
|
|
657
|
-
|
|
658
|
-
g.target === t &&
|
|
657
|
+
l = B(t, c), i.addEventListener("click", c), o.addEventListener("click", c), t.addEventListener("click", (g) => {
|
|
658
|
+
g.target === t && c();
|
|
659
659
|
}), d.addEventListener("click", () => {
|
|
660
|
-
e.alt =
|
|
661
|
-
}),
|
|
660
|
+
e.alt = a.value, c();
|
|
661
|
+
}), a.focus(), a.select();
|
|
662
662
|
}, Q = (e) => {
|
|
663
|
-
const t = e.closest("a"), r = t?.getAttribute("href") || "",
|
|
663
|
+
const t = e.closest("a"), r = t?.getAttribute("href") || "", a = t?.getAttribute("target") || "_self", i = t?.getAttribute("title") || "", o = _(e), d = H(!0);
|
|
664
664
|
d.innerHTML = `
|
|
665
665
|
<div class="rte-media-header">
|
|
666
666
|
<h2 class="rte-media-title">${t ? "Edit Link" : "Add Link"}</h2>
|
|
@@ -673,10 +673,10 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
673
673
|
</div>
|
|
674
674
|
<div class="rte-media-field">
|
|
675
675
|
<label class="rte-media-label">Title (tooltip)</label>
|
|
676
|
-
<input id="link-title" type="text" class="rte-media-input" value="${
|
|
676
|
+
<input id="link-title" type="text" class="rte-media-input" value="${i}" placeholder="Optional tooltip text" />
|
|
677
677
|
</div>
|
|
678
678
|
<label class="rte-media-checkbox-label">
|
|
679
|
-
<input id="link-target" type="checkbox" ${
|
|
679
|
+
<input id="link-target" type="checkbox" ${a === "_blank" ? "checked" : ""} />
|
|
680
680
|
Open in new window/tab
|
|
681
681
|
</label>
|
|
682
682
|
</div>
|
|
@@ -688,7 +688,7 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
688
688
|
</div>
|
|
689
689
|
</div>
|
|
690
690
|
`, o.appendChild(d), document.body.appendChild(o);
|
|
691
|
-
const
|
|
691
|
+
const l = d.querySelector("#link-url"), c = d.querySelector("#link-title"), g = d.querySelector("#link-target"), v = d.querySelector(".close-btn"), k = d.querySelector(".cancel-btn"), h = d.querySelector(".save-btn"), L = d.querySelector(".remove-link-btn");
|
|
692
692
|
let x = () => {
|
|
693
693
|
};
|
|
694
694
|
const m = () => {
|
|
@@ -697,23 +697,23 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
697
697
|
x = B(o, m), v.addEventListener("click", m), k.addEventListener("click", m), o.addEventListener("click", (n) => {
|
|
698
698
|
n.target === o && m();
|
|
699
699
|
}), h.addEventListener("click", () => {
|
|
700
|
-
const n =
|
|
700
|
+
const n = l.value.trim();
|
|
701
701
|
if (n) {
|
|
702
702
|
const b = n.startsWith("http") ? n : `https://${n}`;
|
|
703
703
|
if (t)
|
|
704
|
-
t.setAttribute("href", b), t.setAttribute("target", g.checked ? "_blank" : "_self"), g.checked ? t.setAttribute("rel", "noopener noreferrer") : t.removeAttribute("rel"),
|
|
704
|
+
t.setAttribute("href", b), t.setAttribute("target", g.checked ? "_blank" : "_self"), g.checked ? t.setAttribute("rel", "noopener noreferrer") : t.removeAttribute("rel"), c.value.trim() ? t.setAttribute("title", c.value.trim()) : t.removeAttribute("title");
|
|
705
705
|
else {
|
|
706
706
|
const u = document.createElement("a");
|
|
707
|
-
u.href = b, u.target = g.checked ? "_blank" : "_self", g.checked && (u.rel = "noopener noreferrer"),
|
|
707
|
+
u.href = b, u.target = g.checked ? "_blank" : "_self", g.checked && (u.rel = "noopener noreferrer"), c.value.trim() && (u.title = c.value.trim()), e.replaceWith(u), u.appendChild(e);
|
|
708
708
|
}
|
|
709
|
-
m(),
|
|
709
|
+
m(), s && p && U(p);
|
|
710
710
|
}
|
|
711
711
|
}), L?.addEventListener("click", () => {
|
|
712
|
-
t && confirm("Remove link from this media?") && (t.replaceWith(e), m(),
|
|
713
|
-
}),
|
|
712
|
+
t && confirm("Remove link from this media?") && (t.replaceWith(e), m(), s && p && U(p));
|
|
713
|
+
}), l.focus();
|
|
714
714
|
}, ee = (e) => {
|
|
715
715
|
const t = _(e), r = H();
|
|
716
|
-
let
|
|
716
|
+
let a = "url", i = e.src;
|
|
717
717
|
const o = () => {
|
|
718
718
|
r.innerHTML = `
|
|
719
719
|
<div class="rte-media-header">
|
|
@@ -722,12 +722,12 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
722
722
|
</div>
|
|
723
723
|
|
|
724
724
|
<div class="rte-media-tabs">
|
|
725
|
-
<button class="tab-upload rte-media-tab ${
|
|
726
|
-
<button class="tab-url rte-media-tab ${
|
|
725
|
+
<button class="tab-upload rte-media-tab ${a === "upload" ? "active" : ""}" type="button">Upload</button>
|
|
726
|
+
<button class="tab-url rte-media-tab ${a === "url" ? "active" : ""}" type="button">URL</button>
|
|
727
727
|
</div>
|
|
728
728
|
|
|
729
729
|
<div class="rte-media-body">
|
|
730
|
-
${
|
|
730
|
+
${a === "upload" ? `
|
|
731
731
|
<div id="upload-section">
|
|
732
732
|
<div class="dropzone rte-media-dropzone">
|
|
733
733
|
<div class="rte-media-dropzone-icon">📁</div>
|
|
@@ -746,13 +746,13 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
746
746
|
<div id="url-section">
|
|
747
747
|
<div class="rte-media-field">
|
|
748
748
|
<label class="rte-media-label">Image URL</label>
|
|
749
|
-
<input type="text" id="url-input" class="rte-media-input" placeholder="https://example.com/image.jpg" value="${
|
|
749
|
+
<input type="text" id="url-input" class="rte-media-input" placeholder="https://example.com/image.jpg" value="${i}">
|
|
750
750
|
</div>
|
|
751
|
-
${
|
|
751
|
+
${i ? `
|
|
752
752
|
<div class="rte-media-field">
|
|
753
753
|
<label class="rte-media-label">Preview</label>
|
|
754
754
|
<div class="rte-media-preview">
|
|
755
|
-
<img src="${
|
|
755
|
+
<img src="${i}" alt="Preview" onerror="this.parentElement.innerHTML='<p class="rte-media-muted">Failed to load image</p>'">
|
|
756
756
|
</div>
|
|
757
757
|
</div>
|
|
758
758
|
` : ""}
|
|
@@ -762,19 +762,19 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
762
762
|
|
|
763
763
|
<div class="rte-media-footer">
|
|
764
764
|
<button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
|
|
765
|
-
<button id="replace-btn" class="rte-media-btn rte-media-btn-primary" type="button" ${!
|
|
765
|
+
<button id="replace-btn" class="rte-media-btn rte-media-btn-primary" type="button" ${!i && a === "url" ? "disabled" : ""}>Replace</button>
|
|
766
766
|
</div>
|
|
767
767
|
`;
|
|
768
768
|
};
|
|
769
769
|
o(), t.appendChild(r), document.body.appendChild(t);
|
|
770
770
|
let d = () => {
|
|
771
771
|
};
|
|
772
|
-
const
|
|
772
|
+
const l = () => {
|
|
773
773
|
d(), t.parentNode && t.parentNode.removeChild(t);
|
|
774
774
|
};
|
|
775
|
-
d = B(t,
|
|
776
|
-
const
|
|
777
|
-
|
|
775
|
+
d = B(t, l);
|
|
776
|
+
const c = () => {
|
|
777
|
+
i && (e.src = i, l());
|
|
778
778
|
}, g = async (k) => {
|
|
779
779
|
const h = r.querySelector("#upload-progress"), L = r.querySelector("#progress-bar"), x = r.querySelector("#progress-text");
|
|
780
780
|
if (h && L && x) {
|
|
@@ -787,7 +787,7 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
787
787
|
const b = new FileReader();
|
|
788
788
|
b.onload = () => {
|
|
789
789
|
clearInterval(n), L.style.width = "100%", x.textContent = "Upload complete", setTimeout(() => {
|
|
790
|
-
|
|
790
|
+
i = b.result, a = "url", o(), v();
|
|
791
791
|
}, 500);
|
|
792
792
|
}, b.readAsDataURL(k);
|
|
793
793
|
} catch {
|
|
@@ -796,11 +796,11 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
796
796
|
}
|
|
797
797
|
}, v = () => {
|
|
798
798
|
const k = r.querySelector(".close-btn"), h = r.querySelector(".cancel-btn"), L = r.querySelector("#replace-btn"), x = r.querySelector(".tab-upload"), m = r.querySelector(".tab-url");
|
|
799
|
-
if (k?.addEventListener("click",
|
|
800
|
-
|
|
799
|
+
if (k?.addEventListener("click", l), h?.addEventListener("click", l), L?.addEventListener("click", c), x?.addEventListener("click", () => {
|
|
800
|
+
a = "upload", o(), v();
|
|
801
801
|
}), m?.addEventListener("click", () => {
|
|
802
|
-
|
|
803
|
-
}),
|
|
802
|
+
a = "url", o(), v();
|
|
803
|
+
}), a === "upload") {
|
|
804
804
|
const n = r.querySelector(".dropzone"), b = r.querySelector("#file-input");
|
|
805
805
|
n?.addEventListener("click", () => b?.click()), n?.addEventListener("dragover", (u) => {
|
|
806
806
|
u.preventDefault(), n.classList.add("is-dragover");
|
|
@@ -815,31 +815,33 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
815
815
|
y && g(y);
|
|
816
816
|
});
|
|
817
817
|
}
|
|
818
|
-
if (
|
|
818
|
+
if (a === "url") {
|
|
819
819
|
const n = r.querySelector("#url-input");
|
|
820
820
|
n?.addEventListener("input", () => {
|
|
821
|
-
|
|
821
|
+
i = n.value, o(), v();
|
|
822
822
|
});
|
|
823
823
|
}
|
|
824
824
|
};
|
|
825
825
|
v(), t.addEventListener("click", (k) => {
|
|
826
|
-
k.target === t &&
|
|
826
|
+
k.target === t && l();
|
|
827
827
|
});
|
|
828
828
|
}, E = () => {
|
|
829
|
-
if (!
|
|
830
|
-
const e =
|
|
831
|
-
|
|
832
|
-
|
|
829
|
+
if (!s || !p) return;
|
|
830
|
+
const e = s.offsetHeight || 40, t = p.offsetTop, r = p.offsetLeft, a = p.offsetWidth, i = t - e - 8, o = r + a / 2 - (s.offsetWidth || 120) / 2;
|
|
831
|
+
s.style.top = `${i}px`, s.style.left = `${o}px`, setTimeout(() => {
|
|
832
|
+
s && (s.style.display = "flex");
|
|
833
833
|
}, 100);
|
|
834
834
|
}, U = (e) => {
|
|
835
|
-
|
|
835
|
+
s && (s._cleanup && s._cleanup(), s.remove());
|
|
836
836
|
const t = e.parentElement;
|
|
837
837
|
if (t) {
|
|
838
|
-
const
|
|
839
|
-
(!
|
|
838
|
+
const l = t.style.position;
|
|
839
|
+
(!l || l === "static") && (t.style.position = "relative", t._originalPosition = l), s = document.createElement("div"), s.className = "media-floating-toolbar", G(e) && s.classList.add("rte-ui-theme-dark"), t.insertBefore(s, t.firstChild), E();
|
|
840
840
|
}
|
|
841
|
-
const r =
|
|
842
|
-
|
|
841
|
+
const r = s;
|
|
842
|
+
if (!r) return;
|
|
843
|
+
const a = e.tagName === "IMG", i = e.closest("a");
|
|
844
|
+
r.innerHTML = `
|
|
843
845
|
<button class="media-floating-toolbar-btn btn-align-left" title="Align Left" type="button">
|
|
844
846
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="17" y1="10" x2="3" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="17" y1="18" x2="3" y2="18"></line></svg>
|
|
845
847
|
</button>
|
|
@@ -850,14 +852,14 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
850
852
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="21" y1="10" x2="7" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="21" y1="18" x2="7" y2="18"></line></svg>
|
|
851
853
|
</button>
|
|
852
854
|
<div class="media-floating-toolbar-separator" aria-hidden="true"></div>
|
|
853
|
-
${
|
|
855
|
+
${a ? `
|
|
854
856
|
<button class="media-floating-toolbar-btn btn-alt" title="Edit Alt Text" type="button">
|
|
855
857
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path></svg>
|
|
856
858
|
</button>` : ""}
|
|
857
859
|
<button class="media-floating-toolbar-btn btn-link" title="${i ? "Edit/Remove Link" : "Add Link"}" type="button">
|
|
858
860
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
|
859
861
|
</button>
|
|
860
|
-
${
|
|
862
|
+
${a ? `
|
|
861
863
|
<button class="media-floating-toolbar-btn btn-replace" title="Replace Image" type="button">
|
|
862
864
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>
|
|
863
865
|
</button>` : ""}
|
|
@@ -868,82 +870,82 @@ const W = '[data-theme="dark"], .dark, .editora-theme-dark', B = (e, t) => {
|
|
|
868
870
|
`, setTimeout(() => {
|
|
869
871
|
E();
|
|
870
872
|
}, 0);
|
|
871
|
-
const
|
|
872
|
-
let
|
|
873
|
-
for (;
|
|
874
|
-
|
|
875
|
-
window.addEventListener("scroll",
|
|
876
|
-
let
|
|
877
|
-
for (;
|
|
878
|
-
|
|
879
|
-
window.removeEventListener("scroll",
|
|
880
|
-
},
|
|
873
|
+
const o = () => E();
|
|
874
|
+
let d = e.parentElement;
|
|
875
|
+
for (; d; )
|
|
876
|
+
d.addEventListener("scroll", o), d = d.parentElement;
|
|
877
|
+
window.addEventListener("scroll", o), window.addEventListener("resize", o), r._cleanup = () => {
|
|
878
|
+
let l = e.parentElement;
|
|
879
|
+
for (; l; )
|
|
880
|
+
l.removeEventListener("scroll", o), l = l.parentElement;
|
|
881
|
+
window.removeEventListener("scroll", o), window.removeEventListener("resize", o);
|
|
882
|
+
}, r.querySelector(".btn-align-left")?.addEventListener("click", () => {
|
|
881
883
|
e.style.display = "block", e.style.marginLeft = "0", e.style.marginRight = "auto", E();
|
|
882
|
-
}),
|
|
884
|
+
}), r.querySelector(".btn-align-center")?.addEventListener("click", () => {
|
|
883
885
|
e.style.display = "block", e.style.marginLeft = "auto", e.style.marginRight = "auto", E();
|
|
884
|
-
}),
|
|
886
|
+
}), r.querySelector(".btn-align-right")?.addEventListener("click", () => {
|
|
885
887
|
e.style.display = "block", e.style.marginLeft = "auto", e.style.marginRight = "0", E();
|
|
886
|
-
}),
|
|
888
|
+
}), r.querySelector(".btn-alt")?.addEventListener("click", () => {
|
|
887
889
|
e.tagName === "IMG" && J(e);
|
|
888
|
-
}),
|
|
890
|
+
}), r.querySelector(".btn-link")?.addEventListener("click", () => {
|
|
889
891
|
Q(e);
|
|
890
|
-
}),
|
|
892
|
+
}), r.querySelector(".btn-replace")?.addEventListener("click", () => {
|
|
891
893
|
e.tagName === "IMG" && ee(e);
|
|
892
|
-
}),
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
const c = parseInt(
|
|
894
|
+
}), r.querySelector(".btn-resize")?.addEventListener("click", () => {
|
|
895
|
+
const l = prompt("Enter width in pixels:", String(e.width || e.offsetWidth));
|
|
896
|
+
if (l && !isNaN(parseInt(l))) {
|
|
897
|
+
const c = parseInt(l);
|
|
896
898
|
e.style.width = `${c}px`, e.setAttribute("width", String(c)), q(), E();
|
|
897
899
|
}
|
|
898
|
-
}),
|
|
899
|
-
confirm("Remove this media?") && (e.remove(),
|
|
900
|
-
}),
|
|
900
|
+
}), r.querySelector(".btn-remove")?.addEventListener("click", () => {
|
|
901
|
+
confirm("Remove this media?") && (e.remove(), s && (s._cleanup && s._cleanup(), s.remove(), s = null), p = null, q());
|
|
902
|
+
}), r._cleanup = () => {
|
|
901
903
|
window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
|
|
902
904
|
};
|
|
903
905
|
}, O = (e) => {
|
|
904
906
|
T = e || null, K(), document.addEventListener("click", (t) => {
|
|
905
907
|
const r = t.target;
|
|
906
908
|
if (r.tagName === "IMG" || r.tagName === "VIDEO") {
|
|
907
|
-
const
|
|
908
|
-
let
|
|
909
|
-
if (T ?
|
|
910
|
-
t.preventDefault(), t.stopPropagation(),
|
|
909
|
+
const a = r;
|
|
910
|
+
let i = !1;
|
|
911
|
+
if (T ? i = T.contains(a) : i = !!a.closest('[contenteditable="true"]'), i) {
|
|
912
|
+
t.preventDefault(), t.stopPropagation(), p = a, p.style.display = "block", U(a), q();
|
|
911
913
|
return;
|
|
912
914
|
}
|
|
913
915
|
}
|
|
914
|
-
if (!r.closest(".btn-link, .btn-resize, .btn-remove") &&
|
|
915
|
-
if (
|
|
916
|
-
const
|
|
917
|
-
|
|
916
|
+
if (!r.closest(".btn-link, .btn-resize, .btn-remove") && s && !r.closest("button")) {
|
|
917
|
+
if (s._cleanup && s._cleanup(), s.remove(), s = null, p && p.parentElement) {
|
|
918
|
+
const a = p.parentElement;
|
|
919
|
+
a._originalPosition !== void 0 && (a.style.position = a._originalPosition, delete a._originalPosition);
|
|
918
920
|
}
|
|
919
|
-
|
|
921
|
+
p = null, q();
|
|
920
922
|
}
|
|
921
923
|
}), R.forEach((t) => {
|
|
922
924
|
t.addEventListener("mousedown", (r) => {
|
|
923
|
-
if (!
|
|
925
|
+
if (!p) return;
|
|
924
926
|
r.preventDefault(), r.stopPropagation(), D = !0, I = t.getAttribute("data-position"), V = r.clientX, j = r.clientY;
|
|
925
|
-
const
|
|
926
|
-
$ =
|
|
927
|
+
const a = p.getBoundingClientRect();
|
|
928
|
+
$ = a.width, C = a.height, N = $ / C, document.body.style.userSelect = "none", document.body.style.cursor = `${I}-resize`;
|
|
927
929
|
});
|
|
928
930
|
}), document.addEventListener("mousemove", (t) => {
|
|
929
|
-
if (!D || !
|
|
930
|
-
const r = t.clientX - V,
|
|
931
|
-
let
|
|
931
|
+
if (!D || !p || !I) return;
|
|
932
|
+
const r = t.clientX - V, a = t.clientY - j;
|
|
933
|
+
let i = $, o = C;
|
|
932
934
|
switch (I) {
|
|
933
935
|
case "se":
|
|
934
|
-
|
|
936
|
+
i = $ + r, o = C + a;
|
|
935
937
|
break;
|
|
936
938
|
case "sw":
|
|
937
|
-
|
|
939
|
+
i = $ - r, o = C + a;
|
|
938
940
|
break;
|
|
939
941
|
case "ne":
|
|
940
|
-
|
|
942
|
+
i = $ + r, o = C - a;
|
|
941
943
|
break;
|
|
942
944
|
case "nw":
|
|
943
|
-
|
|
945
|
+
i = $ - r, o = C - a;
|
|
944
946
|
break;
|
|
945
947
|
}
|
|
946
|
-
Math.abs(r) > Math.abs(
|
|
948
|
+
Math.abs(r) > Math.abs(a) ? o = i / N : i = o * N, i = Math.max(50, i), o = Math.max(50, o), p.style.width = `${i}px`, p.style.height = `${o}px`, p.setAttribute("width", String(Math.round(i))), p.setAttribute("height", String(Math.round(o))), q(), E();
|
|
947
949
|
}), document.addEventListener("mouseup", () => {
|
|
948
950
|
D && (D = !1, I = null, document.body.style.userSelect = "", document.body.style.cursor = "");
|
|
949
951
|
}), window.addEventListener("scroll", q), window.addEventListener("resize", q);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function H(e,t){const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function H(e,t){const o=Array.from({length:t}).map(()=>"<th><p><br></p></th>").join(""),n=Array.from({length:e}).map(()=>`<tr>${Array.from({length:t}).map(()=>"<td><p><br></p></td>").join("")}</tr>`).join("");return`<table class="rte-table"><thead><tr>${o}</tr></thead><tbody>${n}</tbody></table><p><br></p>`}function q(){return[{id:"paragraph",label:"Paragraph",description:"Switch to paragraph text",command:"paragraph",keywords:["text","normal","p"]},{id:"h1",label:"Heading 1",description:"Large section heading",command:"heading1",keywords:["title","header","h1"]},{id:"h2",label:"Heading 2",description:"Medium section heading",command:"heading2",keywords:["subtitle","header","h2"]},{id:"h3",label:"Heading 3",description:"Small section heading",command:"heading3",keywords:["header","h3"]},{id:"bulleted-list",label:"Bulleted List",description:"Create a bullet list",command:"toggleBulletList",keywords:["list","ul","bullet"]},{id:"numbered-list",label:"Numbered List",description:"Create a numbered list",command:"toggleOrderedList",keywords:["list","ol","numbered"]},{id:"blockquote",label:"Blockquote",description:"Insert a quote block",command:"toggleBlockquote",keywords:["quote","citation"]},{id:"table-3x3",label:"Table 3x3",description:"Insert a 3 x 3 table",action:({insertHTML:e})=>e(H(3,3)),keywords:["table","grid","rows","columns"]},{id:"horizontal-rule",label:"Divider",description:"Insert a horizontal rule",command:"insertHorizontalRule",keywords:["hr","separator","line"]},{id:"bold",label:"Bold",description:"Toggle bold formatting",command:"toggleBold",keywords:["strong","b"]},{id:"italic",label:"Italic",description:"Toggle italic formatting",command:"toggleItalic",keywords:["emphasis","i"]},{id:"underline",label:"Underline",description:"Toggle underline formatting",command:"toggleUnderline",keywords:["u"]},{id:"strikethrough",label:"Strikethrough",description:"Toggle strikethrough formatting",command:"toggleStrikethrough",keywords:["strike","s"]},{id:"clear-formatting",label:"Clear Formatting",description:"Remove text formatting",command:"clearFormatting",keywords:["reset","plain"]}]}function $(e){const t=[],o=new Set;return e.forEach(n=>{const r=String(n.id||"").trim(),i=String(n.label||"").trim();!r||!i||o.has(r)||(o.add(r),t.push({...n,id:r,label:i,description:n.description?String(n.description):void 0,keywords:Array.isArray(n.keywords)?n.keywords.map(a=>String(a)).filter(Boolean):void 0}))}),t}function D(e){const t=(e.triggerChar||"/")[0]||"/",o=e.includeDefaultItems!==!1,n=o?[...e.items||[],...q()]:e.items||[];return{triggerChar:t,minChars:Math.max(0,e.minChars??0),maxQueryLength:Math.max(1,e.maxQueryLength??48),maxSuggestions:Math.max(1,e.maxSuggestions??10),requireBoundary:e.requireBoundary!==!1,includeDefaultItems:o,items:$(n),itemRenderer:e.itemRenderer||(r=>r.label),emptyStateText:e.emptyStateText||"No commands found",panelLabel:e.panelLabel||"Slash commands"}}const u='[data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark';let E=!1;function B(){if(E||typeof document>"u")return;E=!0;const e=document.createElement("style");e.id="rte-slash-commands-styles",e.textContent=`
|
|
2
2
|
.rte-slash-panel {
|
|
3
3
|
width: min(225px, calc(100vw - 16px));
|
|
4
4
|
max-height: min(360px, calc(100vh - 24px));
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
${u} .rte-slash-empty {
|
|
85
85
|
color: #9ca3af;
|
|
86
86
|
}
|
|
87
|
-
`,document.head.appendChild(e)}const s=".rte-content, .editora-content",g=new WeakMap,p=new WeakMap;let b=!1,f=null,h=0,z=0;function P(e){return e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null}function I(e){return e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||e}function _(e){if(e?.contentElement instanceof HTMLElement)return e.contentElement;if(e?.editorElement instanceof HTMLElement){const n=e.editorElement;if(n.matches(s))return n;const
|
|
87
|
+
`,document.head.appendChild(e)}const s=".rte-content, .editora-content",g=new WeakMap,p=new WeakMap;let b=!1,f=null,h=0,z=0;function P(e){return e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null}function I(e){return e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||e}function _(e){if(e?.contentElement instanceof HTMLElement)return e.contentElement;if(e?.editorElement instanceof HTMLElement){const n=e.editorElement;if(n.matches(s))return n;const r=n.querySelector(s);if(r instanceof HTMLElement)return r}const t=window.getSelection();if(t&&t.rangeCount>0){const n=t.getRangeAt(0).startContainer,i=(n.nodeType===Node.ELEMENT_NODE?n:n.parentElement)?.closest(s);if(i)return i}const o=document.activeElement;if(o){if(o.matches(s))return o;const n=o.closest(s);if(n)return n}return document.querySelector(s)}function m(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function F(e){return e?/\s|[([{"'`]/.test(e):!0}function v(e){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const o=t.getRangeAt(0);return e.contains(o.commonAncestorContainer)?o.cloneRange():null}function y(e,t){const o=window.getSelection();o&&(o.removeAllRanges(),o.addRange(t),e.focus({preventScroll:!0}))}function j(e){if(!e.collapsed)return null;const t=e.startContainer,o=e.startOffset;if(t.nodeType===Node.TEXT_NODE){const n=t;return{node:n,textBefore:n.data.slice(0,o),caretOffset:o}}if(t.nodeType===Node.ELEMENT_NODE){const n=t;if(o>0){const r=n.childNodes[o-1];if(r&&r.nodeType===Node.TEXT_NODE){const i=r;return{node:i,textBefore:i.data,caretOffset:i.length}}}}return null}function K(e,t,o,n){const r=e.lastIndexOf(t);if(r<0||n&&!F(e[r-1]))return null;const i=e.slice(r+1);return/\s/.test(i)||i.length>o?null:{trigger:t,query:i,startOffset:r}}function Q(e,t){const o=t.cloneRange();o.collapse(!1);const n=o.getClientRects();if(n.length>0)return n[n.length-1];const r=document.createElement("span");r.textContent="",o.insertNode(r);const i=r.getBoundingClientRect();return r.remove(),e.normalize(),i}function A(e,t){if(!e.panel)return;const o=Q(e.editor,t),n=e.panel;n.style.display="block",n.classList.add("show"),n.style.left="0px",n.style.top="0px";const r=n.getBoundingClientRect(),i=window.innerWidth,a=window.innerHeight;let l=Math.max(8,Math.min(o.left,i-r.width-8)),d=o.bottom+8;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`}function k(e,t){if(!t)return m(e);const o=e.toLowerCase(),n=t.toLowerCase(),r=o.indexOf(n);if(r<0)return m(e);const i=m(e.slice(0,r)),a=m(e.slice(r,r+t.length)),l=m(e.slice(r+t.length));return`${i}<mark>${a}</mark>${l}`}function U(e,t){if(e.panel&&e.list)return;const o=document.createElement("div");o.className="rte-slash-panel",o.style.display="none",o.setAttribute("role","dialog"),o.setAttribute("aria-modal","false");const n=document.createElement("div");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=>{r.preventDefault()}),o.addEventListener("click",r=>{const i=r.target;if(!i)return;const a=i.closest(".rte-slash-item");if(!a)return;const l=Number(a.getAttribute("data-index"));Number.isFinite(l)&&M(e,l)})}function c(e){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)}function W(e,t,o){if(!t)return e.slice(0,o);const n=t.toLowerCase();return e.filter(i=>[i.id,i.label,i.description||"",i.command||"",...i.keywords||[]].join(" ").toLowerCase().includes(n)).slice(0,o)}function Z(e,t){if(!e.list)return;const o=e.list;if(o.innerHTML="",e.filteredItems.length===0){const n=document.createElement("div");n.className="rte-slash-empty",n.textContent=t.emptyStateText,o.appendChild(n),o.removeAttribute("aria-activedescendant");return}e.filteredItems.forEach((n,r)=>{const i=document.createElement("button");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=`
|
|
88
88
|
<span class="rte-slash-item-title">${k(n.label,e.query)}</span>
|
|
89
89
|
${n.description?`<span class="rte-slash-item-description">${k(n.description,e.query)}</span>`:""}
|
|
90
|
-
`,
|
|
90
|
+
`,o.appendChild(i)}),e.filteredItems.length>0&&o.setAttribute("aria-activedescendant",`rte-slash-item-${e.instanceId}-${e.activeIndex}`)}function G(e,t){if(t===e.innerHTML)return;const o=window.execEditorCommand||window.executeEditorCommand;if(typeof o=="function")try{o("recordDomTransaction",e,t,e.innerHTML)}catch{}}function V(e){e.dispatchEvent(new Event("input",{bubbles:!0}))}function L(e,t){e.focus({preventScroll:!0});try{if(document.execCommand("insertHTML",!1,t))return!0}catch{}const o=window.getSelection();if(!o||o.rangeCount===0)return!1;const n=o.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return!1;n.deleteContents();const r=document.createElement("template");r.innerHTML=t;const i=r.content,a=i.lastChild;if(n.insertNode(i),a){const l=document.createRange();l.setStartAfter(a),l.collapse(!0),y(e,l)}return!0}function X(e,t){e.focus({preventScroll:!0});try{if(document.execCommand("insertText",!1,t))return!0}catch{}const o=window.getSelection();if(!o||o.rangeCount===0)return!1;const n=o.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return!1;n.deleteContents();const r=document.createTextNode(t);n.insertNode(r);const i=document.createRange();return i.setStart(r,r.length),i.collapse(!0),y(e,i),!0}function J(e,t){switch(e.toLowerCase()){case"paragraph":case"p":return document.execCommand("formatBlock",!1,"<p>");case"heading1":case"h1":return document.execCommand("formatBlock",!1,"<h1>");case"heading2":case"h2":return document.execCommand("formatBlock",!1,"<h2>");case"heading3":case"h3":return document.execCommand("formatBlock",!1,"<h3>");case"blockquote":case"toggleblockquote":return document.execCommand("formatBlock",!1,"<blockquote>");case"bulletlist":case"togglebulletlist":case"insertunorderedlist":return document.execCommand("insertUnorderedList");case"numberedlist":case"toggleorderedlist":case"insertorderedlist":return document.execCommand("insertOrderedList");case"horizontalrule":case"divider":case"inserthorizontalrule":return document.execCommand("insertHorizontalRule");case"bold":case"togglebold":return document.execCommand("bold");case"italic":case"toggleitalic":return document.execCommand("italic");case"underline":case"toggleunderline":return document.execCommand("underline");case"strikethrough":case"togglestrikethrough":return document.execCommand("strikeThrough");case"clearformatting":case"removeformat":return document.execCommand("removeFormat");default:try{return document.execCommand(e,!1,t)}catch{return!1}}}function S(e,t,o){const n=I(e);if(n&&typeof n.execCommand=="function")try{if(n.execCommand(t,o)!==!1)return!0}catch{}const r=window.execEditorCommand||window.executeEditorCommand;if(typeof r=="function")try{if(r(t,o,{editorElement:n,contentElement:e})!==!1)return!0}catch{}return J(t,o)}async function Y(e,t){const o=e.editor,n=I(o),r={editor:o,editorRoot:n,query:e.query,trigger:e.trigger,executeCommand:(i,a)=>S(o,i,a),insertHTML:i=>L(o,i)};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}async function M(e,t){if(t<0||t>=e.filteredItems.length||!e.replaceRange)return;const o=e.filteredItems[t],n=e.editor,r=n.innerHTML,i=`${e.trigger}${e.query}`;if(!window.getSelection())return;const l=e.replaceRange.cloneRange();if(!n.contains(l.commonAncestorContainer))return;l.deleteContents();const d=l.cloneRange();d.collapse(!0),y(n,d);let x=!1;try{x=await Y(e,o)}catch{x=!1}c(e),x?(V(n),G(n,r)):i&&X(n,i),n.focus({preventScroll:!0})}function R(e,t){if(e.filteredItems.length===0)return;const o=e.filteredItems.length;if(e.activeIndex=((e.activeIndex+t)%o+o)%o,!e.list)return;const n=Array.from(e.list.querySelectorAll(".rte-slash-item"));n.forEach((i,a)=>{const l=a===e.activeIndex;i.classList.toggle("active",l),i.setAttribute("aria-selected",l?"true":"false")});const r=n[e.activeIndex];r&&(e.list.setAttribute("aria-activedescendant",r.id),r.scrollIntoView({block:"nearest"}))}function T(e){if(!(!e.isOpen||!e.panel||!e.anchorRange)){if(!e.editor.isConnected){c(e);return}A(e,e.anchorRange)}}function N(e,t,o,n,r,i){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))}function ee(e,t){const o=e.editor;if(o.getAttribute("contenteditable")==="false"){c(e);return}const n=v(o);if(!n||!n.collapsed){c(e);return}const r=j(n);if(!r){c(e);return}const i=K(r.textBefore,t.triggerChar,t.maxQueryLength,t.requireBoundary);if(!i){c(e);return}if(i.query.length<t.minChars){c(e);return}const a=n.cloneRange();a.setStart(r.node,i.startOffset),a.setEnd(r.node,r.caretOffset),N(e,t,n,i.query,i.trigger,a)}function O(e,t){const o=e.editor;if(o.getAttribute("contenteditable")==="false")return!1;let n=v(o);n||(n=document.createRange(),n.selectNodeContents(o),n.collapse(!1),y(o,n));const r=n.cloneRange();return r.collapse(!0),N(e,t,n,"",t.triggerChar,r),!0}function te(e){return!(e.metaKey||e.ctrlKey)||e.altKey?!1:e.key==="/"||e.code==="Slash"}function ne(e,t){return{editor:e,panel:null,list:null,replaceRange:null,items:t.items,filteredItems:[],activeIndex:0,query:"",trigger:t.triggerChar,isOpen:!1,instanceId:++z,anchorRange:null}}function w(e,t){const o=g.get(e);if(o)return o.items=t.items,o;const n=ne(e,t);return g.set(e,n),n}function re(e){const t=g.get(e);t&&(t.panel?.parentNode&&t.panel.parentNode.removeChild(t.panel),g.delete(e))}function C(e,t,o){if(p.has(e))return;const n={input:()=>{ee(t,o)},keydown:r=>{if(t.editor.getAttribute("contenteditable")==="false"){c(t);return}if(!t.isOpen&&te(r)){r.preventDefault(),O(t,o);return}if(t.isOpen){if(r.key==="ArrowDown"){r.preventDefault(),R(t,1);return}if(r.key==="ArrowUp"){r.preventDefault(),R(t,-1);return}if(r.key==="Enter"||r.key==="Tab"){if(t.filteredItems.length===0){r.key==="Tab"&&r.preventDefault(),c(t);return}r.preventDefault(),M(t,t.activeIndex);return}if(r.key==="Escape"){r.preventDefault(),c(t);return}}},blur:()=>{window.setTimeout(()=>{const r=document.activeElement;t.panel&&r&&t.panel.contains(r)||c(t)},0)},mousedown:r=>{if(!t.isOpen||!t.panel)return;const i=r.target;i&&!t.panel.contains(i)&&!e.contains(i)&&c(t)},selectionchange:()=>{if(!t.isOpen)return;const r=v(e);if(!r||!r.collapsed){c(t);return}t.anchorRange=r.cloneRange(),T(t)},reposition:()=>{T(t)}};e.addEventListener("input",n.input),e.addEventListener("keydown",n.keydown),e.addEventListener("blur",n.blur),document.addEventListener("mousedown",n.mousedown,!0),document.addEventListener("selectionchange",n.selectionchange),window.addEventListener("resize",n.reposition,{passive:!0}),window.addEventListener("scroll",n.reposition,!0),p.set(e,n)}function oe(e){const t=p.get(e);t&&(e.removeEventListener("input",t.input),e.removeEventListener("keydown",t.keydown),e.removeEventListener("blur",t.blur),document.removeEventListener("mousedown",t.mousedown,!0),document.removeEventListener("selectionchange",t.selectionchange),window.removeEventListener("resize",t.reposition),window.removeEventListener("scroll",t.reposition,!0),p.delete(e))}function ie(e){b||(b=!0,f=t=>{const o=t.target;if(!(o instanceof Node))return;const r=P(o)?.closest(s)||null;if(!r)return;const i=w(r,e);C(r,i,e)},document.addEventListener("focusin",f,!0))}function ae(){!b||!f||(document.removeEventListener("focusin",f,!0),b=!1,f=null)}const le=(e={})=>{B();const t=D(e);return{name:"slashCommands",toolbar:[{id:"slashCommands",label:"Slash Commands",command:"openSlashCommands",icon:'<svg width="24" height="24" focusable="false" aria-hidden="true"><path d="M8.7 20a1 1 0 0 1-.7-.3c-.4-.4-.4-1 0-1.4L15.6 5a1 1 0 0 1 1.4 1.4L9.4 19.7a1 1 0 0 1-.7.3Zm7.8 0c-.3 0-.5 0-.7-.3l-1.8-1.8a1 1 0 1 1 1.4-1.4l1.8 1.8a1 1 0 0 1-.7 1.7Zm-9-12a1 1 0 0 1-.7-1.7L8.6 4.5A1 1 0 1 1 10 6L8.2 7.8a1 1 0 0 1-.7.3Z"></path></svg>'}],commands:{openSlashCommands:(o,n)=>{const r=_(n);if(!r)return!1;const i=w(r,t);return C(r,i,t),O(i,t)}},keymap:{"Mod-/":"openSlashCommands","Mod-Shift-7":"openSlashCommands"},init:()=>{h+=1,ie(t),Array.from(document.querySelectorAll(s)).forEach(n=>{const r=w(n,t);C(n,r,t)})},destroy:()=>{h=Math.max(0,h-1),Array.from(document.querySelectorAll(s)).forEach(n=>{const r=g.get(n);r&&(c(r),oe(n),re(n))}),h===0&&ae()}}};exports.SlashCommandsPlugin=le;
|