markdown-text-editor 1.9.3 → 1.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markdown-text-editor.es.js +22 -16
- package/dist/markdown-text-editor.es.js.map +1 -1
- package/dist/markdown-text-editor.min.js +3 -4
- package/dist/markdown-text-editor.min.js.map +1 -1
- package/dist/markdown-text-editor.umd.js +3 -4
- package/dist/markdown-text-editor.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -3650,7 +3650,7 @@ var Or = class {
|
|
|
3650
3650
|
}
|
|
3651
3651
|
}, kr = class {
|
|
3652
3652
|
constructor(e) {
|
|
3653
|
-
this.editor = e, this._matches = [], this._currentIndex = -1, this._caseSensitive = !1, this._panel = null, this._findInput = null, this._replaceInput = null, this._countEl = null, this._replaceRow = null, this._caseSensitiveBtn = null, this._highlightEl = null, this._scrollHandler = null, this._taHandler = this._onTextareaKeyDown.bind(this), e.usertextarea.addEventListener("keydown", this._taHandler);
|
|
3653
|
+
this.editor = e, this._matches = [], this._currentIndex = -1, this._caseSensitive = !1, this._panel = null, this._findInput = null, this._replaceInput = null, this._countEl = null, this._replaceRow = null, this._caseSensitiveBtn = null, this._highlightEl = null, this._matchTop = null, this._matchHeight = 0, this._scrollHandler = null, this._taHandler = this._onTextareaKeyDown.bind(this), e.usertextarea.addEventListener("keydown", this._taHandler);
|
|
3654
3654
|
}
|
|
3655
3655
|
_onTextareaKeyDown(e) {
|
|
3656
3656
|
let t = e.ctrlKey || e.metaKey;
|
|
@@ -3733,12 +3733,13 @@ var Or = class {
|
|
|
3733
3733
|
this._clearMatchHighlight();
|
|
3734
3734
|
return;
|
|
3735
3735
|
}
|
|
3736
|
-
|
|
3737
|
-
this._scrollToMatch(this.editor.usertextarea, e), this._showMatchHighlight();
|
|
3736
|
+
this._showMatchHighlight(), this._scrollMatchIntoView();
|
|
3738
3737
|
}
|
|
3739
|
-
|
|
3740
|
-
let
|
|
3741
|
-
|
|
3738
|
+
_scrollMatchIntoView() {
|
|
3739
|
+
let e = this.editor.usertextarea;
|
|
3740
|
+
if (this._matchTop === null || this._matchHeight <= 0) return;
|
|
3741
|
+
let t = e.clientHeight, n = e.scrollTop, r = this._matchHeight, i = n;
|
|
3742
|
+
this._matchTop - r < n ? i = this._matchTop - r : this._matchTop + this._matchHeight + r > n + t && (i = this._matchTop + this._matchHeight + r - t), i !== n && (e.scrollTop = Math.max(0, i), this._highlightEl && (this._highlightEl.style.top = this._matchTop - e.scrollTop + "px"));
|
|
3742
3743
|
}
|
|
3743
3744
|
_showMatchHighlight() {
|
|
3744
3745
|
if (this._clearMatchHighlight(), this._currentIndex === -1 || !this._matches.length) return;
|
|
@@ -3749,7 +3750,7 @@ var Or = class {
|
|
|
3749
3750
|
pointerEvents: "none",
|
|
3750
3751
|
top: "0",
|
|
3751
3752
|
left: "0",
|
|
3752
|
-
|
|
3753
|
+
width: n.clientWidth + "px",
|
|
3753
3754
|
whiteSpace: "pre-wrap",
|
|
3754
3755
|
wordBreak: "break-word",
|
|
3755
3756
|
overflowWrap: "break-word",
|
|
@@ -3764,7 +3765,9 @@ var Or = class {
|
|
|
3764
3765
|
let o = document.createElement("span");
|
|
3765
3766
|
o.textContent = n.value.substring(e, t) || "", a.appendChild(document.createTextNode(n.value.substring(0, e))), a.appendChild(o), a.appendChild(document.createTextNode(n.value.substring(t))), i.appendChild(a);
|
|
3766
3767
|
try {
|
|
3767
|
-
let e = i.getBoundingClientRect(), t = o.getBoundingClientRect()
|
|
3768
|
+
let e = i.getBoundingClientRect(), t = o.getBoundingClientRect();
|
|
3769
|
+
this._matchTop = t.top - e.top, this._matchHeight = t.height;
|
|
3770
|
+
let r = document.createElement("div");
|
|
3768
3771
|
Object.assign(r.style, {
|
|
3769
3772
|
position: "absolute",
|
|
3770
3773
|
top: t.top - e.top - n.scrollTop + "px",
|
|
@@ -3781,7 +3784,7 @@ var Or = class {
|
|
|
3781
3784
|
}
|
|
3782
3785
|
}
|
|
3783
3786
|
_clearMatchHighlight() {
|
|
3784
|
-
this._highlightEl?.remove(), this._highlightEl = null;
|
|
3787
|
+
this._highlightEl?.remove(), this._highlightEl = null, this._matchTop = null;
|
|
3785
3788
|
}
|
|
3786
3789
|
_updateCount() {
|
|
3787
3790
|
this._countEl && (this._matches.length === 0 ? this._countEl.textContent = this._findInput?.value ? "No results" : "" : this._countEl.textContent = `${this._currentIndex + 1} of ${this._matches.length}`);
|
|
@@ -3918,20 +3921,23 @@ var Or = class {
|
|
|
3918
3921
|
this._autoGrow(), this.renderHybrid(), this.debouncedPreview(), this.notifyChange();
|
|
3919
3922
|
}, this._scrollHandler = () => {
|
|
3920
3923
|
this._scrollRaf ||= requestAnimationFrame(() => {
|
|
3921
|
-
|
|
3922
|
-
let e = this.usertextarea, t = e.scrollTop / (e.scrollHeight - e.clientHeight);
|
|
3923
|
-
this.previewContent.scrollTop = t * (this.previewContent.scrollHeight - this.previewContent.clientHeight);
|
|
3924
|
-
}
|
|
3924
|
+
this._scrollRaf = null, this.mode === "hybrid" && (this.displayLayer.scrollTop = this.usertextarea.scrollTop, this.displayLayer.scrollLeft = this.usertextarea.scrollLeft), this.preview && this.previewContent && this._syncPreviewScroll();
|
|
3925
3925
|
});
|
|
3926
3926
|
}, this.usertextarea.addEventListener("input", this._inputHandler), this.usertextarea.addEventListener("scroll", this._scrollHandler);
|
|
3927
3927
|
}
|
|
3928
3928
|
debouncedPreview() {
|
|
3929
3929
|
this.preview && (clearTimeout(this.previewTimer), this.previewTimer = setTimeout(() => {
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
this.previewContent.scrollTop = t * (this.previewContent.scrollHeight - this.previewContent.clientHeight);
|
|
3930
|
+
let e = this.previewContent.scrollTop;
|
|
3931
|
+
this.previewContent.innerHTML = this._renderMarkdown(this.usertextarea.value), this.wirePreviewCheckboxes(), this._syncPreviewScroll() || (this.previewContent.scrollTop = e);
|
|
3933
3932
|
}, 150));
|
|
3934
3933
|
}
|
|
3934
|
+
_syncPreviewScroll() {
|
|
3935
|
+
if (!this.preview || !this.previewContent) return !1;
|
|
3936
|
+
let e = this.usertextarea, t = e.scrollHeight - e.clientHeight;
|
|
3937
|
+
if (t <= 0) return !1;
|
|
3938
|
+
let n = e.scrollTop / t, r = this.previewContent.scrollHeight - this.previewContent.clientHeight;
|
|
3939
|
+
return this.previewContent.scrollTop = n * r, !0;
|
|
3940
|
+
}
|
|
3935
3941
|
renderMarkdown(e) {
|
|
3936
3942
|
return this._renderMarkdown(e);
|
|
3937
3943
|
}
|