@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
package/dist/code.esm.js
CHANGED
|
@@ -203,27 +203,28 @@ class Z {
|
|
|
203
203
|
}
|
|
204
204
|
// Set cursor position
|
|
205
205
|
setCursorPosition(e) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
var t;
|
|
207
|
+
const s = this.getText().split(`
|
|
208
|
+
`), i = Math.min(e.line, s.length - 1), n = Math.min(e.column, ((t = s[i]) == null ? void 0 : t.length) || 0);
|
|
209
|
+
let r = 0;
|
|
210
|
+
for (let a = 0; a < i; a++)
|
|
211
|
+
r += s[a].length + 1;
|
|
212
|
+
r += n;
|
|
213
|
+
const o = document.createRange(), l = window.getSelection(), h = this.resolveOffsetToDomPoint(r);
|
|
214
|
+
if (h)
|
|
214
215
|
try {
|
|
215
|
-
|
|
216
|
-
} catch (
|
|
217
|
-
console.warn("Could not set cursor position:",
|
|
216
|
+
o.setStart(h.node, h.offset), o.setEnd(h.node, h.offset), l?.removeAllRanges(), l?.addRange(o), this.ensureCaretVisible();
|
|
217
|
+
} catch (a) {
|
|
218
|
+
console.warn("Could not set cursor position:", a);
|
|
218
219
|
}
|
|
219
220
|
else {
|
|
220
|
-
const
|
|
221
|
+
const a = this.contentElement.querySelector(
|
|
221
222
|
`[${this.trailingNewlineMarkerAttr}]`
|
|
222
223
|
);
|
|
223
224
|
try {
|
|
224
|
-
|
|
225
|
-
} catch (
|
|
226
|
-
console.warn("Could not set fallback cursor position:",
|
|
225
|
+
a && a.parentNode === this.contentElement ? o.setStartBefore(a) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), l?.removeAllRanges(), l?.addRange(o), this.ensureCaretVisible();
|
|
226
|
+
} catch (c) {
|
|
227
|
+
console.warn("Could not set fallback cursor position:", c);
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
230
|
}
|
|
@@ -254,16 +255,17 @@ class Z {
|
|
|
254
255
|
setSelectionRange(e) {
|
|
255
256
|
const t = this.getText().split(`
|
|
256
257
|
`), s = (c) => {
|
|
257
|
-
const
|
|
258
|
+
const d = Math.max(0, Math.min(c.line, t.length - 1)), f = Math.max(
|
|
258
259
|
0,
|
|
259
|
-
Math.min(c.column, t[
|
|
260
|
+
Math.min(c.column, t[d] ? t[d].length : 0)
|
|
260
261
|
);
|
|
261
|
-
let
|
|
262
|
-
for (let g = 0; g <
|
|
263
|
-
|
|
264
|
-
return
|
|
262
|
+
let u = 0;
|
|
263
|
+
for (let g = 0; g < d; g++)
|
|
264
|
+
u += t[g].length + 1;
|
|
265
|
+
return u + f;
|
|
265
266
|
}, i = s(e.start), n = s(e.end), [r, o] = i <= n ? [i, n] : [n, i], l = this.resolveOffsetToDomPoint(r), h = this.resolveOffsetToDomPoint(o);
|
|
266
|
-
if (!l || !h)
|
|
267
|
+
if (!l || !h)
|
|
268
|
+
return;
|
|
267
269
|
const a = document.createRange();
|
|
268
270
|
try {
|
|
269
271
|
a.setStart(l.node, l.offset), a.setEnd(h.node, h.offset);
|
|
@@ -309,7 +311,8 @@ class Z {
|
|
|
309
311
|
this.editorContainer.scrollTop = e;
|
|
310
312
|
}
|
|
311
313
|
syncTrailingNewlineMarker(e) {
|
|
312
|
-
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((s) => s.remove()), !e)
|
|
314
|
+
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((s) => s.remove()), !e)
|
|
315
|
+
return;
|
|
313
316
|
const t = document.createElement("span");
|
|
314
317
|
t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
|
|
315
318
|
display: inline-block;
|
|
@@ -321,45 +324,50 @@ class Z {
|
|
|
321
324
|
}
|
|
322
325
|
// Ensure caret is visible inside the editor scroll container
|
|
323
326
|
ensureCaretVisible() {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
327
|
+
var e;
|
|
328
|
+
const t = window.getSelection();
|
|
329
|
+
if (!t || t.rangeCount === 0)
|
|
330
|
+
return;
|
|
331
|
+
const s = t.getRangeAt(0).cloneRange();
|
|
332
|
+
s.collapse(!1);
|
|
333
|
+
let i = s.getClientRects()[0] || s.getBoundingClientRect();
|
|
334
|
+
if ((!i || i.width === 0 && i.height === 0) && t.focusNode instanceof Element ? i = t.focusNode.getBoundingClientRect() : (!i || i.width === 0 && i.height === 0) && (e = t.focusNode) != null && e.parentElement && (i = t.focusNode.parentElement.getBoundingClientRect()), !i)
|
|
335
|
+
return;
|
|
336
|
+
const n = this.editorContainer.getBoundingClientRect(), r = 12;
|
|
337
|
+
i.bottom > n.bottom - r ? this.editorContainer.scrollTop += i.bottom - (n.bottom - r) : i.top < n.top + r && (this.editorContainer.scrollTop -= n.top + r - i.top);
|
|
332
338
|
}
|
|
333
339
|
// Destroy the view
|
|
334
340
|
destroy() {
|
|
335
341
|
this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
|
|
336
342
|
}
|
|
337
343
|
resolveOffsetToDomPoint(e) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
344
|
+
var t;
|
|
345
|
+
const s = Math.max(0, e);
|
|
346
|
+
let i = 0;
|
|
347
|
+
const n = document.createTreeWalker(
|
|
341
348
|
this.contentElement,
|
|
342
349
|
NodeFilter.SHOW_TEXT,
|
|
343
350
|
null
|
|
344
351
|
);
|
|
345
|
-
let
|
|
346
|
-
for (;
|
|
347
|
-
|
|
352
|
+
let r = null, o;
|
|
353
|
+
for (; o = n.nextNode(); ) {
|
|
354
|
+
const l = o.parentElement;
|
|
355
|
+
if (l != null && l.hasAttribute(this.trailingNewlineMarkerAttr))
|
|
348
356
|
continue;
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
352
|
-
const
|
|
357
|
+
r = o;
|
|
358
|
+
const h = o.textContent || "", a = this.buildVisibleToDomMap(h), c = Math.max(0, a.length - 1);
|
|
359
|
+
if (i + c >= s) {
|
|
360
|
+
const d = Math.max(0, s - i), f = a[d] ?? h.length;
|
|
353
361
|
return {
|
|
354
|
-
node:
|
|
355
|
-
offset:
|
|
362
|
+
node: o,
|
|
363
|
+
offset: f
|
|
356
364
|
};
|
|
357
365
|
}
|
|
358
|
-
|
|
366
|
+
i += c;
|
|
359
367
|
}
|
|
360
|
-
if (
|
|
361
|
-
const
|
|
362
|
-
return { node:
|
|
368
|
+
if (r) {
|
|
369
|
+
const l = ((t = r.textContent) == null ? void 0 : t.length) || 0;
|
|
370
|
+
return { node: r, offset: l };
|
|
363
371
|
}
|
|
364
372
|
return null;
|
|
365
373
|
}
|
|
@@ -443,22 +451,22 @@ const F = class L {
|
|
|
443
451
|
const c = document.createTextNode(`
|
|
444
452
|
`);
|
|
445
453
|
a.insertNode(c), a.setStartAfter(c), a.collapse(!0), s.removeAllRanges(), s.addRange(a), this.view.ensureCaretVisible();
|
|
446
|
-
const
|
|
447
|
-
this.textModel.setText(
|
|
454
|
+
const d = this.view.getText();
|
|
455
|
+
this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
|
|
448
456
|
const f = Math.min(
|
|
449
457
|
h + 1,
|
|
450
458
|
this.textModel.getText().length
|
|
451
459
|
);
|
|
452
460
|
try {
|
|
453
|
-
const
|
|
454
|
-
this.setCursor(
|
|
461
|
+
const u = this.textModel.offsetToPosition(f);
|
|
462
|
+
this.setCursor(u), this.view.ensureCaretVisible();
|
|
455
463
|
} catch {
|
|
456
464
|
}
|
|
457
465
|
this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
458
466
|
this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
|
|
459
467
|
try {
|
|
460
|
-
const
|
|
461
|
-
this.setCursor(
|
|
468
|
+
const u = this.textModel.offsetToPosition(f);
|
|
469
|
+
this.setCursor(u), this.view.ensureCaretVisible();
|
|
462
470
|
} catch {
|
|
463
471
|
}
|
|
464
472
|
}), this.highlightTimeout = null;
|
|
@@ -583,7 +591,8 @@ const F = class L {
|
|
|
583
591
|
}
|
|
584
592
|
// Search & Navigation
|
|
585
593
|
search(e, t = {}) {
|
|
586
|
-
if (!e)
|
|
594
|
+
if (!e)
|
|
595
|
+
return [];
|
|
587
596
|
const s = {
|
|
588
597
|
query: e,
|
|
589
598
|
caseSensitive: !1,
|
|
@@ -600,16 +609,16 @@ const F = class L {
|
|
|
600
609
|
}
|
|
601
610
|
let c;
|
|
602
611
|
for (; (c = a.exec(r)) !== null; ) {
|
|
603
|
-
const
|
|
604
|
-
if (
|
|
612
|
+
const d = c[0] ?? "";
|
|
613
|
+
if (d.length === 0) {
|
|
605
614
|
a.lastIndex = c.index + 1;
|
|
606
615
|
continue;
|
|
607
616
|
}
|
|
608
|
-
const f = c.index,
|
|
609
|
-
s.wholeWord && !this.isWholeWordBoundary(r, f,
|
|
617
|
+
const f = c.index, u = c.index + d.length;
|
|
618
|
+
s.wholeWord && !this.isWholeWordBoundary(r, f, u) || this.pushSearchResultFromOffsets(
|
|
610
619
|
i,
|
|
611
620
|
f,
|
|
612
|
-
|
|
621
|
+
u,
|
|
613
622
|
r,
|
|
614
623
|
o
|
|
615
624
|
);
|
|
@@ -617,14 +626,14 @@ const F = class L {
|
|
|
617
626
|
} else {
|
|
618
627
|
let a = 0, c = l.indexOf(h, a);
|
|
619
628
|
for (; c !== -1; ) {
|
|
620
|
-
const
|
|
621
|
-
!s.wholeWord || this.isWholeWordBoundary(r, c,
|
|
629
|
+
const d = c + h.length;
|
|
630
|
+
!s.wholeWord || this.isWholeWordBoundary(r, c, d) ? (this.pushSearchResultFromOffsets(
|
|
622
631
|
i,
|
|
623
632
|
c,
|
|
624
|
-
|
|
633
|
+
d,
|
|
625
634
|
r,
|
|
626
635
|
o
|
|
627
|
-
), a =
|
|
636
|
+
), a = d) : a = c + 1, c = l.indexOf(h, a);
|
|
628
637
|
}
|
|
629
638
|
}
|
|
630
639
|
return i;
|
|
@@ -709,9 +718,9 @@ const F = class L {
|
|
|
709
718
|
let n, r, o, l;
|
|
710
719
|
if (t || i) {
|
|
711
720
|
n = this.getSelection();
|
|
712
|
-
const
|
|
713
|
-
if (
|
|
714
|
-
r =
|
|
721
|
+
const d = this.getCollapsedSelectionOffsetInEditor();
|
|
722
|
+
if (d !== void 0)
|
|
723
|
+
r = d;
|
|
715
724
|
else {
|
|
716
725
|
const f = this.getCursor().position;
|
|
717
726
|
r = this.textModel.positionToOffset(f);
|
|
@@ -726,11 +735,11 @@ const F = class L {
|
|
|
726
735
|
return;
|
|
727
736
|
}
|
|
728
737
|
if (n && (o !== void 0 || l !== void 0)) {
|
|
729
|
-
const
|
|
738
|
+
const d = o !== void 0 ? o : r, f = l !== void 0 ? l : r, u = Math.min(d, f), g = Math.max(d, f), p = this.textModel.offsetToPosition(u), y = this.textModel.offsetToPosition(g);
|
|
730
739
|
this.view.setSelectionRange({ start: p, end: y });
|
|
731
740
|
} else if (r !== void 0) {
|
|
732
|
-
const
|
|
733
|
-
this.view.setCursorPosition(
|
|
741
|
+
const d = this.textModel.offsetToPosition(r);
|
|
742
|
+
this.view.setCursorPosition(d);
|
|
734
743
|
}
|
|
735
744
|
} catch {
|
|
736
745
|
}
|
|
@@ -772,7 +781,8 @@ const F = class L {
|
|
|
772
781
|
const o = i.textContent ?? "", l = o.indexOf(L.CURSOR_SENTINEL);
|
|
773
782
|
l !== -1 && (n || (n = i, r = l), i.textContent = o.split(L.CURSOR_SENTINEL).join("")), i = s.nextNode();
|
|
774
783
|
}
|
|
775
|
-
if (!n || !t)
|
|
784
|
+
if (!n || !t)
|
|
785
|
+
return !1;
|
|
776
786
|
try {
|
|
777
787
|
const o = document.createRange();
|
|
778
788
|
return o.setStart(n, r), o.collapse(!0), t.removeAllRanges(), t.addRange(o), !0;
|
|
@@ -790,7 +800,8 @@ const F = class L {
|
|
|
790
800
|
}
|
|
791
801
|
// History: undo/redo
|
|
792
802
|
undo() {
|
|
793
|
-
if (this.undoStack.length === 0)
|
|
803
|
+
if (this.undoStack.length === 0)
|
|
804
|
+
return;
|
|
794
805
|
const e = this.undoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
|
|
795
806
|
this.redoStack.push(t);
|
|
796
807
|
try {
|
|
@@ -816,7 +827,8 @@ const F = class L {
|
|
|
816
827
|
}
|
|
817
828
|
}
|
|
818
829
|
redo() {
|
|
819
|
-
if (this.redoStack.length === 0)
|
|
830
|
+
if (this.redoStack.length === 0)
|
|
831
|
+
return;
|
|
820
832
|
const e = this.redoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
|
|
821
833
|
this.undoStack.push(t);
|
|
822
834
|
try {
|
|
@@ -843,7 +855,8 @@ const F = class L {
|
|
|
843
855
|
}
|
|
844
856
|
// Insert a tab character or spaces at current cursor
|
|
845
857
|
insertTab() {
|
|
846
|
-
if (this.config.readOnly)
|
|
858
|
+
if (this.config.readOnly)
|
|
859
|
+
return;
|
|
847
860
|
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = " ".repeat(this.config.tabSize || 2), i = this.textModel.insertText(e, s), n = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + s.length);
|
|
848
861
|
if (!this.suppressHistory) {
|
|
849
862
|
const r = this.getSelection();
|
|
@@ -856,7 +869,8 @@ const F = class L {
|
|
|
856
869
|
}
|
|
857
870
|
// Insert a newline at current cursor position
|
|
858
871
|
insertNewLine() {
|
|
859
|
-
if (this.config.readOnly)
|
|
872
|
+
if (this.config.readOnly)
|
|
873
|
+
return;
|
|
860
874
|
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = this.textModel.insertText(e, `
|
|
861
875
|
`), i = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
|
|
862
876
|
if (!this.suppressHistory) {
|
|
@@ -873,7 +887,8 @@ const F = class L {
|
|
|
873
887
|
this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
|
|
874
888
|
}
|
|
875
889
|
off(e, t) {
|
|
876
|
-
if (!this.eventListeners.has(e))
|
|
890
|
+
if (!this.eventListeners.has(e))
|
|
891
|
+
return;
|
|
877
892
|
const s = this.eventListeners.get(e);
|
|
878
893
|
if (t) {
|
|
879
894
|
const i = s.indexOf(t);
|
|
@@ -892,17 +907,19 @@ class J {
|
|
|
892
907
|
this.editor = e;
|
|
893
908
|
}
|
|
894
909
|
handleKeyDown(e) {
|
|
895
|
-
if (!this.editor)
|
|
910
|
+
if (!this.editor)
|
|
911
|
+
return;
|
|
896
912
|
const t = this.findMatchingBinding(e);
|
|
897
913
|
if (t)
|
|
898
914
|
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
|
|
899
915
|
}
|
|
900
916
|
findMatchingBinding(e) {
|
|
901
917
|
const { key: t, ctrlKey: s, altKey: i, shiftKey: n, metaKey: r } = e, o = String(t).toLowerCase(), l = this.keymap[o];
|
|
902
|
-
if (!l)
|
|
918
|
+
if (!l)
|
|
919
|
+
return null;
|
|
903
920
|
for (const h of l) {
|
|
904
|
-
const a = h.ctrlKey === void 0 || h.ctrlKey === s, c = h.altKey === void 0 || h.altKey === i,
|
|
905
|
-
if (a && c &&
|
|
921
|
+
const a = h.ctrlKey === void 0 || h.ctrlKey === s, c = h.altKey === void 0 || h.altKey === i, d = h.shiftKey === void 0 || h.shiftKey === n, f = h.metaKey === void 0 || h.metaKey === r;
|
|
922
|
+
if (a && c && d && f)
|
|
906
923
|
return h;
|
|
907
924
|
}
|
|
908
925
|
return null;
|
|
@@ -992,18 +1009,21 @@ class G {
|
|
|
992
1009
|
}), this.updateLineNumbers();
|
|
993
1010
|
}
|
|
994
1011
|
createLineNumbers() {
|
|
995
|
-
if (!this.editor)
|
|
1012
|
+
if (!this.editor)
|
|
1013
|
+
return;
|
|
996
1014
|
const e = this.editor.getView().getLineNumbersElement();
|
|
997
1015
|
e && (this.lineNumbersElement = e);
|
|
998
1016
|
}
|
|
999
1017
|
updateLineNumbers() {
|
|
1000
|
-
if (!this.lineNumbersElement || !this.editor || !this.isEnabled)
|
|
1018
|
+
if (!this.lineNumbersElement || !this.editor || !this.isEnabled)
|
|
1019
|
+
return;
|
|
1001
1020
|
const e = this.editor.getValue().split(`
|
|
1002
1021
|
`).length, t = Array.from({ length: Math.max(e, 20) }, (s, i) => i + 1);
|
|
1003
1022
|
this.lineNumbersElement.innerHTML = t.map((s) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("");
|
|
1004
1023
|
}
|
|
1005
1024
|
toggle() {
|
|
1006
|
-
if (!this.editor)
|
|
1025
|
+
if (!this.editor)
|
|
1026
|
+
return;
|
|
1007
1027
|
this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
|
|
1008
1028
|
const e = this.editor.getView().getContentElement();
|
|
1009
1029
|
e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
|
|
@@ -1101,11 +1121,13 @@ const W = class m {
|
|
|
1101
1121
|
this.isVisible = !1, this.searchUI && (this.searchUI.style.display = "none"), this.replaceInputEl && (this.replaceInputEl.style.display = "none", this.replaceInputEl.value = ""), this.updateModeHint(!1), this.clearHighlights(), this.restoreSelectionState();
|
|
1102
1122
|
}
|
|
1103
1123
|
createSearchUI() {
|
|
1104
|
-
if (!this.editor)
|
|
1124
|
+
if (!this.editor)
|
|
1125
|
+
return;
|
|
1105
1126
|
const e = this.editor.getView().getContentElement(), t = e.closest(
|
|
1106
1127
|
this.editorContainerSelector
|
|
1107
1128
|
), s = e.closest(".rte-source-editor-modal") || t || e.parentElement;
|
|
1108
|
-
if (!s)
|
|
1129
|
+
if (!s)
|
|
1130
|
+
return;
|
|
1109
1131
|
window.getComputedStyle(s).position === "static" && (s.style.position = "relative"), this.searchUI = document.createElement("div"), this.searchUI.className = m.css.root, this.searchUI.style.display = "none", this.searchUI.innerHTML = `
|
|
1110
1132
|
<div class="${m.css.row}">
|
|
1111
1133
|
<input type="text" class="${m.css.findInput} ${m.css.inputBase}" placeholder="Find..." />
|
|
@@ -1149,24 +1171,24 @@ const W = class m {
|
|
|
1149
1171
|
`.${m.css.mode}`
|
|
1150
1172
|
), c = this.searchUI.querySelector(
|
|
1151
1173
|
`.${m.css.caseSensitive}`
|
|
1152
|
-
),
|
|
1174
|
+
), d = this.searchUI.querySelector(
|
|
1153
1175
|
`.${m.css.wholeWord}`
|
|
1154
1176
|
), f = this.searchUI.querySelector(
|
|
1155
1177
|
`.${m.css.regex}`
|
|
1156
1178
|
);
|
|
1157
|
-
this.findInput = i, this.replaceInputEl = n, this.statusDiv = h, this.modeDiv = a, this.caseSensitiveInput = c, this.wholeWordInput =
|
|
1179
|
+
this.findInput = i, this.replaceInputEl = n, this.statusDiv = h, this.modeDiv = a, this.caseSensitiveInput = c, this.wholeWordInput = d, this.regexInput = f, c.checked = !!this.searchOptions.caseSensitive, d.checked = !!this.searchOptions.wholeWord, f.checked = !!this.searchOptions.regex, i.addEventListener("input", () => {
|
|
1158
1180
|
this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
|
|
1159
1181
|
const g = i.value;
|
|
1160
1182
|
this.searchDebounceTimer = setTimeout(() => {
|
|
1161
1183
|
this.performSearch(g, !1, !1);
|
|
1162
1184
|
}, 120);
|
|
1163
1185
|
});
|
|
1164
|
-
const
|
|
1165
|
-
this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord =
|
|
1186
|
+
const u = () => {
|
|
1187
|
+
this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = d.checked, this.searchOptions.regex = f.checked;
|
|
1166
1188
|
const g = i.value;
|
|
1167
1189
|
g.trim() ? this.performSearch(g, !1, !1) : this.performSearch("", !1, !1);
|
|
1168
1190
|
};
|
|
1169
|
-
c.addEventListener("change",
|
|
1191
|
+
c.addEventListener("change", u), d.addEventListener("change", u), f.addEventListener("change", u), i.addEventListener("keydown", (g) => {
|
|
1170
1192
|
g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.findPrev() : this.findNext()) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
|
|
1171
1193
|
}), n.addEventListener("keydown", (g) => {
|
|
1172
1194
|
g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.replaceAll(i.value, n.value) : this.replaceCurrent(i.value, n.value)) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
|
|
@@ -1207,9 +1229,11 @@ const W = class m {
|
|
|
1207
1229
|
this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights(!0);
|
|
1208
1230
|
}
|
|
1209
1231
|
replaceCurrent(e, t) {
|
|
1210
|
-
if (!this.editor || !e.trim() || ((this.currentQuery !== e || this.currentResults.length === 0) && this.performSearch(e, !1, !0), this.currentIndex < 0 || this.currentResults.length === 0))
|
|
1232
|
+
if (!this.editor || !e.trim() || ((this.currentQuery !== e || this.currentResults.length === 0) && this.performSearch(e, !1, !0), this.currentIndex < 0 || this.currentResults.length === 0))
|
|
1233
|
+
return;
|
|
1211
1234
|
const s = this.currentResults[this.currentIndex];
|
|
1212
|
-
if (!s)
|
|
1235
|
+
if (!s)
|
|
1236
|
+
return;
|
|
1213
1237
|
const i = this.computeReplacementRange(s.range.start, t);
|
|
1214
1238
|
if (this.editor.replace(s.range, t), this.config.replaceAndFindNext) {
|
|
1215
1239
|
this.currentQuery = e;
|
|
@@ -1224,7 +1248,8 @@ const W = class m {
|
|
|
1224
1248
|
this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
1225
1249
|
}
|
|
1226
1250
|
replaceAll(e, t) {
|
|
1227
|
-
if (!this.editor || !e.trim())
|
|
1251
|
+
if (!this.editor || !e.trim())
|
|
1252
|
+
return;
|
|
1228
1253
|
const s = this.editor.replaceAll(e, t, this.searchOptions);
|
|
1229
1254
|
this.performSearch(e, !1, !1), this.showTransientStatus(`Replaced ${s} occurrence${s === 1 ? "" : "s"}`), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
1230
1255
|
}
|
|
@@ -1238,7 +1263,8 @@ const W = class m {
|
|
|
1238
1263
|
));
|
|
1239
1264
|
}
|
|
1240
1265
|
navigateToResult(e, t) {
|
|
1241
|
-
if (!this.editor)
|
|
1266
|
+
if (!this.editor)
|
|
1267
|
+
return;
|
|
1242
1268
|
const s = document.activeElement, i = !!s && (s === this.findInput || s === this.replaceInputEl);
|
|
1243
1269
|
t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
|
|
1244
1270
|
const n = this.editor.getView();
|
|
@@ -1247,10 +1273,11 @@ const W = class m {
|
|
|
1247
1273
|
});
|
|
1248
1274
|
}
|
|
1249
1275
|
clearHighlights() {
|
|
1276
|
+
var e, t;
|
|
1250
1277
|
if (this.hasCustomHighlightSupport)
|
|
1251
1278
|
try {
|
|
1252
|
-
const
|
|
1253
|
-
e.highlights
|
|
1279
|
+
const s = CSS;
|
|
1280
|
+
(e = s.highlights) == null || e.delete(this.highlightMatchName), (t = s.highlights) == null || t.delete(this.highlightActiveName);
|
|
1254
1281
|
} catch {
|
|
1255
1282
|
}
|
|
1256
1283
|
}
|
|
@@ -1258,17 +1285,20 @@ const W = class m {
|
|
|
1258
1285
|
this.scrollLogicalRangeIntoView(e.range, !0);
|
|
1259
1286
|
}
|
|
1260
1287
|
scrollLogicalRangeIntoView(e, t) {
|
|
1261
|
-
if (!this.editor)
|
|
1288
|
+
if (!this.editor)
|
|
1289
|
+
return;
|
|
1262
1290
|
const s = this.editor.getView().getContentElement(), i = this.editor.getValue(), { lineStarts: n, lines: r } = this.buildLineStarts(i), o = this.buildTextNodeIndex(s);
|
|
1263
|
-
if (o.length === 0)
|
|
1291
|
+
if (o.length === 0)
|
|
1292
|
+
return;
|
|
1264
1293
|
const l = this.toDomRange(e, n, r, o);
|
|
1265
|
-
if (!l)
|
|
1294
|
+
if (!l)
|
|
1295
|
+
return;
|
|
1266
1296
|
const h = l.startContainer.nodeType === Node.TEXT_NODE ? l.startContainer.parentElement : l.startContainer, a = this.resolveScrollContainer(s);
|
|
1267
1297
|
if (a) {
|
|
1268
|
-
const c = l.getClientRects()[0] || l.getBoundingClientRect(),
|
|
1298
|
+
const c = l.getClientRects()[0] || l.getBoundingClientRect(), d = a.getBoundingClientRect(), f = a.scrollTop + (c.top - d.top) - d.height / 2 + c.height / 2, u = 18;
|
|
1269
1299
|
let g = t ? f : a.scrollTop, p = a.scrollLeft;
|
|
1270
|
-
const y = a.scrollLeft + (c.left -
|
|
1271
|
-
c.right >
|
|
1300
|
+
const y = a.scrollLeft + (c.left - d.left), k = y + c.width;
|
|
1301
|
+
c.right > d.right - u ? p = k - d.width + u : c.left < d.left + u && (p = Math.max(0, y - u));
|
|
1272
1302
|
const v = Math.max(0, a.scrollHeight - a.clientHeight), C = Math.max(0, a.scrollWidth - a.clientWidth);
|
|
1273
1303
|
if (g = Math.min(v, Math.max(0, g)), p = Math.min(C, Math.max(0, p)), v === 0 && C === 0) {
|
|
1274
1304
|
h?.scrollIntoView({
|
|
@@ -1303,13 +1333,17 @@ const W = class m {
|
|
|
1303
1333
|
});
|
|
1304
1334
|
}
|
|
1305
1335
|
centerCurrentSelectionInView() {
|
|
1306
|
-
if (!this.editor)
|
|
1336
|
+
if (!this.editor)
|
|
1337
|
+
return;
|
|
1307
1338
|
const e = this.editor.getView().getContentElement(), t = this.resolveScrollContainer(e);
|
|
1308
|
-
if (!t)
|
|
1339
|
+
if (!t)
|
|
1340
|
+
return;
|
|
1309
1341
|
const s = window.getSelection();
|
|
1310
|
-
if (!s || s.rangeCount === 0)
|
|
1342
|
+
if (!s || s.rangeCount === 0)
|
|
1343
|
+
return;
|
|
1311
1344
|
const i = s.getRangeAt(0).cloneRange(), n = i.getClientRects()[0] || i.getBoundingClientRect();
|
|
1312
|
-
if (!n)
|
|
1345
|
+
if (!n)
|
|
1346
|
+
return;
|
|
1313
1347
|
const r = t.getBoundingClientRect(), o = t.scrollTop + (n.top - r.top) - r.height / 2 + n.height / 2, l = Math.max(0, t.scrollHeight - t.clientHeight), h = Math.min(l, Math.max(0, o));
|
|
1314
1348
|
h !== t.scrollTop && t.scrollTo({
|
|
1315
1349
|
top: h,
|
|
@@ -1345,19 +1379,21 @@ const W = class m {
|
|
|
1345
1379
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
1346
1380
|
}
|
|
1347
1381
|
clampRangeToDocument(e) {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1382
|
+
var t, s;
|
|
1383
|
+
const i = this.editor;
|
|
1384
|
+
if (!i)
|
|
1385
|
+
return e;
|
|
1386
|
+
const n = i.getValue().split(`
|
|
1387
|
+
`), r = Math.max(0, n.length - 1), o = Math.max(0, Math.min(e.start.line, r)), l = Math.max(0, Math.min(e.end.line, r)), h = Math.max(
|
|
1352
1388
|
0,
|
|
1353
|
-
Math.min(e.start.column,
|
|
1354
|
-
),
|
|
1389
|
+
Math.min(e.start.column, ((t = n[o]) == null ? void 0 : t.length) || 0)
|
|
1390
|
+
), a = Math.max(
|
|
1355
1391
|
0,
|
|
1356
|
-
Math.min(e.end.column, s[
|
|
1392
|
+
Math.min(e.end.column, ((s = n[l]) == null ? void 0 : s.length) || 0)
|
|
1357
1393
|
);
|
|
1358
1394
|
return {
|
|
1359
|
-
start: { line:
|
|
1360
|
-
end: { line:
|
|
1395
|
+
start: { line: o, column: h },
|
|
1396
|
+
end: { line: l, column: a }
|
|
1361
1397
|
};
|
|
1362
1398
|
}
|
|
1363
1399
|
focusWithoutScrolling(e) {
|
|
@@ -1394,8 +1430,9 @@ const W = class m {
|
|
|
1394
1430
|
return null;
|
|
1395
1431
|
}
|
|
1396
1432
|
resolveScrollContainer(e) {
|
|
1397
|
-
|
|
1398
|
-
|
|
1433
|
+
var t, s;
|
|
1434
|
+
const i = (t = this.editor) == null ? void 0 : t.getView(), n = ((s = i?.getScrollElement) == null ? void 0 : s.call(i)) || null;
|
|
1435
|
+
return n && this.canScroll(n) ? n : this.findScrollContainer(e);
|
|
1399
1436
|
}
|
|
1400
1437
|
canScroll(e) {
|
|
1401
1438
|
return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
|
|
@@ -1410,25 +1447,27 @@ const W = class m {
|
|
|
1410
1447
|
if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
|
|
1411
1448
|
return;
|
|
1412
1449
|
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: s, lines: i } = this.buildLineStarts(t), n = this.buildTextNodeIndex(e);
|
|
1413
|
-
if (n.length === 0)
|
|
1450
|
+
if (n.length === 0)
|
|
1451
|
+
return;
|
|
1414
1452
|
const r = this.buildVisibleDocumentText(n), o = [];
|
|
1415
1453
|
let l = null;
|
|
1416
1454
|
const h = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
|
|
1417
1455
|
for (let a = 0; a < h; a++) {
|
|
1418
|
-
const c = this.currentResults[a],
|
|
1456
|
+
const c = this.currentResults[a], d = this.searchOptions.regex ? c.match || this.currentQuery : this.currentQuery || c.match, f = this.toDomRange(
|
|
1419
1457
|
c.range,
|
|
1420
1458
|
s,
|
|
1421
1459
|
i,
|
|
1422
1460
|
n,
|
|
1423
1461
|
r,
|
|
1424
|
-
|
|
1462
|
+
d
|
|
1425
1463
|
);
|
|
1426
1464
|
f && (o.push(f), a === this.currentIndex && (l = f));
|
|
1427
1465
|
}
|
|
1428
1466
|
if (o.length !== 0)
|
|
1429
1467
|
try {
|
|
1430
1468
|
const a = CSS, c = window.Highlight;
|
|
1431
|
-
if (!a.highlights || !c)
|
|
1469
|
+
if (!a.highlights || !c)
|
|
1470
|
+
return;
|
|
1432
1471
|
a.highlights.set(this.highlightMatchName, new c(...o)), l && a.highlights.set(this.highlightActiveName, new c(l));
|
|
1433
1472
|
} catch {
|
|
1434
1473
|
}
|
|
@@ -1442,63 +1481,66 @@ const W = class m {
|
|
|
1442
1481
|
return { lineStarts: s, lines: t };
|
|
1443
1482
|
}
|
|
1444
1483
|
positionToOffset(e, t, s) {
|
|
1445
|
-
|
|
1446
|
-
|
|
1484
|
+
var i;
|
|
1485
|
+
const n = Math.max(0, Math.min(e.line, s.length - 1)), r = Math.max(0, Math.min(e.column, ((i = s[n]) == null ? void 0 : i.length) || 0));
|
|
1486
|
+
return t[n] + r;
|
|
1447
1487
|
}
|
|
1448
1488
|
buildTextNodeIndex(e) {
|
|
1449
1489
|
const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), s = [];
|
|
1450
1490
|
let i = 0, n;
|
|
1451
1491
|
for (; n = t.nextNode(); ) {
|
|
1452
|
-
const r = n;
|
|
1453
|
-
if (
|
|
1492
|
+
const r = n, o = r.parentElement;
|
|
1493
|
+
if (o != null && o.hasAttribute(this.trailingMarkerAttr))
|
|
1454
1494
|
continue;
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1495
|
+
const l = r.textContent || "", h = this.buildVisibleToDomMap(l), a = Math.max(0, h.length - 1);
|
|
1496
|
+
a === 0 && l.length === 0 || (s.push({
|
|
1457
1497
|
node: r,
|
|
1458
1498
|
start: i,
|
|
1459
|
-
end: i +
|
|
1460
|
-
visibleToDom:
|
|
1461
|
-
}), i +=
|
|
1499
|
+
end: i + a,
|
|
1500
|
+
visibleToDom: h
|
|
1501
|
+
}), i += a);
|
|
1462
1502
|
}
|
|
1463
1503
|
return s;
|
|
1464
1504
|
}
|
|
1465
1505
|
resolveDomPoint(e, t) {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1506
|
+
var s, i;
|
|
1507
|
+
const n = Math.max(0, e);
|
|
1508
|
+
for (let o = 0; o < t.length; o++) {
|
|
1509
|
+
const l = t[o];
|
|
1510
|
+
if (n <= l.end) {
|
|
1511
|
+
const h = Math.max(0, n - l.start), a = l.visibleToDom[h] ?? ((s = l.node.textContent) == null ? void 0 : s.length) ?? 0;
|
|
1471
1512
|
return {
|
|
1472
|
-
node:
|
|
1473
|
-
offset:
|
|
1513
|
+
node: l.node,
|
|
1514
|
+
offset: a
|
|
1474
1515
|
};
|
|
1475
1516
|
}
|
|
1476
1517
|
}
|
|
1477
|
-
const
|
|
1478
|
-
return
|
|
1479
|
-
node:
|
|
1480
|
-
offset:
|
|
1518
|
+
const r = t[t.length - 1];
|
|
1519
|
+
return r ? {
|
|
1520
|
+
node: r.node,
|
|
1521
|
+
offset: r.visibleToDom[r.visibleToDom.length - 1] ?? ((i = r.node.textContent) == null ? void 0 : i.length) ?? 0
|
|
1481
1522
|
} : null;
|
|
1482
1523
|
}
|
|
1483
1524
|
toDomRange(e, t, s, i, n, r) {
|
|
1484
1525
|
const o = this.positionToOffset(e.start, t, s), l = this.positionToOffset(e.end, t, s);
|
|
1485
1526
|
let h = Math.min(o, l), a = Math.max(o, l);
|
|
1486
1527
|
if (n && r) {
|
|
1487
|
-
const
|
|
1488
|
-
if (g.length ===
|
|
1528
|
+
const u = r, g = n.slice(h, a);
|
|
1529
|
+
if (g.length === u.length && g.toLowerCase() !== u.toLowerCase()) {
|
|
1489
1530
|
const p = this.findNearestMatchOffset(
|
|
1490
1531
|
n,
|
|
1491
|
-
|
|
1532
|
+
u,
|
|
1492
1533
|
h
|
|
1493
1534
|
);
|
|
1494
|
-
p !== -1 && (h = p, a = p +
|
|
1535
|
+
p !== -1 && (h = p, a = p + u.length);
|
|
1495
1536
|
}
|
|
1496
1537
|
}
|
|
1497
|
-
const c = this.resolveDomPoint(h, i),
|
|
1498
|
-
if (!c || !
|
|
1538
|
+
const c = this.resolveDomPoint(h, i), d = this.resolveDomPoint(a, i);
|
|
1539
|
+
if (!c || !d)
|
|
1540
|
+
return null;
|
|
1499
1541
|
const f = document.createRange();
|
|
1500
1542
|
try {
|
|
1501
|
-
return f.setStart(c.node, c.offset), f.setEnd(
|
|
1543
|
+
return f.setStart(c.node, c.offset), f.setEnd(d.node, d.offset), f;
|
|
1502
1544
|
} catch {
|
|
1503
1545
|
return null;
|
|
1504
1546
|
}
|
|
@@ -1517,11 +1559,13 @@ const W = class m {
|
|
|
1517
1559
|
findNearestMatchOffset(e, t, s) {
|
|
1518
1560
|
const i = t.toLowerCase();
|
|
1519
1561
|
let n = e.toLowerCase().indexOf(i);
|
|
1520
|
-
if (n === -1)
|
|
1562
|
+
if (n === -1)
|
|
1563
|
+
return -1;
|
|
1521
1564
|
let r = n, o = Math.abs(n - s);
|
|
1522
1565
|
for (; n !== -1; ) {
|
|
1523
1566
|
const l = Math.abs(n - s);
|
|
1524
|
-
if (l < o && (o = l, r = n), l === 0)
|
|
1567
|
+
if (l < o && (o = l, r = n), l === 0)
|
|
1568
|
+
return n;
|
|
1525
1569
|
n = e.toLowerCase().indexOf(i, n + 1);
|
|
1526
1570
|
}
|
|
1527
1571
|
return r;
|
|
@@ -1591,7 +1635,8 @@ const W = class m {
|
|
|
1591
1635
|
return t;
|
|
1592
1636
|
}
|
|
1593
1637
|
ensureHighlightStyles() {
|
|
1594
|
-
if (document.getElementById(this.highlightStyleId))
|
|
1638
|
+
if (document.getElementById(this.highlightStyleId))
|
|
1639
|
+
return;
|
|
1595
1640
|
const e = document.createElement("style");
|
|
1596
1641
|
e.id = this.highlightStyleId, e.textContent = `
|
|
1597
1642
|
::highlight(${this.highlightMatchName}) {
|
|
@@ -1607,7 +1652,7 @@ const W = class m {
|
|
|
1607
1652
|
destroy() {
|
|
1608
1653
|
this.searchDebounceTimer && (clearTimeout(this.searchDebounceTimer), this.searchDebounceTimer = null), this.liveRefreshTimer && (clearTimeout(this.liveRefreshTimer), this.liveRefreshTimer = null), this.statusResetTimer && (clearTimeout(this.statusResetTimer), this.statusResetTimer = null), this.clearHighlights(), this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.editor && this.editorChangeHandler && this.editor.off("change", this.editorChangeHandler), this.editorChangeHandler = null, this.findInput = null, this.replaceInputEl = null, this.statusDiv = null, this.modeDiv = null, this.caseSensitiveInput = null, this.wholeWordInput = null, this.regexInput = null, this.searchUI = null;
|
|
1609
1654
|
const e = document.getElementById(this.highlightStyleId);
|
|
1610
|
-
e
|
|
1655
|
+
e != null && e.parentNode && e.parentNode.removeChild(e), this.editor = null;
|
|
1611
1656
|
}
|
|
1612
1657
|
};
|
|
1613
1658
|
W.css = {
|
|
@@ -1656,20 +1701,24 @@ class ie {
|
|
|
1656
1701
|
});
|
|
1657
1702
|
}
|
|
1658
1703
|
updateBracketMatching() {
|
|
1659
|
-
if (!this.editor)
|
|
1704
|
+
if (!this.editor)
|
|
1705
|
+
return;
|
|
1660
1706
|
const e = this.editor.getCursor(), t = this.editor.getValue();
|
|
1661
1707
|
this.clearBracketHighlighting();
|
|
1662
1708
|
const s = this.getBracketAtPosition(t, e.position);
|
|
1663
|
-
if (!s)
|
|
1709
|
+
if (!s)
|
|
1710
|
+
return;
|
|
1664
1711
|
const i = this.findMatchingBracket(t, s);
|
|
1665
1712
|
i && (this.currentMatch = i, this.highlightBrackets(i));
|
|
1666
1713
|
}
|
|
1667
1714
|
getBracketAtPosition(e, t) {
|
|
1668
1715
|
const s = e.split(`
|
|
1669
1716
|
`);
|
|
1670
|
-
if (t.line >= s.length)
|
|
1717
|
+
if (t.line >= s.length)
|
|
1718
|
+
return null;
|
|
1671
1719
|
const i = s[t.line];
|
|
1672
|
-
if (t.column >= i.length)
|
|
1720
|
+
if (t.column >= i.length)
|
|
1721
|
+
return null;
|
|
1673
1722
|
const n = i[t.column];
|
|
1674
1723
|
return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
|
|
1675
1724
|
}
|
|
@@ -1684,10 +1733,10 @@ class ie {
|
|
|
1684
1733
|
for (let l = s; l < t.length; l++) {
|
|
1685
1734
|
const h = t[l], a = l === s ? i : 0;
|
|
1686
1735
|
for (let c = a; c < h.length; c++) {
|
|
1687
|
-
const
|
|
1688
|
-
if (
|
|
1736
|
+
const d = h[c];
|
|
1737
|
+
if (d === n)
|
|
1689
1738
|
o++;
|
|
1690
|
-
else if (
|
|
1739
|
+
else if (d === r && (o--, o === 0))
|
|
1691
1740
|
return {
|
|
1692
1741
|
open: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
|
|
1693
1742
|
close: { start: { line: l, column: c }, end: { line: l, column: c + 1 } },
|
|
@@ -1703,10 +1752,10 @@ class ie {
|
|
|
1703
1752
|
for (let l = s; l >= 0; l--) {
|
|
1704
1753
|
const h = t[l], a = l === s ? i : h.length - 1;
|
|
1705
1754
|
for (let c = a; c >= 0; c--) {
|
|
1706
|
-
const
|
|
1707
|
-
if (
|
|
1755
|
+
const d = h[c];
|
|
1756
|
+
if (d === n)
|
|
1708
1757
|
o++;
|
|
1709
|
-
else if (
|
|
1758
|
+
else if (d === r && (o--, o === 0))
|
|
1710
1759
|
return {
|
|
1711
1760
|
open: { start: { line: l, column: c }, end: { line: l, column: c + 1 } },
|
|
1712
1761
|
close: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
|
|
@@ -1746,7 +1795,8 @@ class ne {
|
|
|
1746
1795
|
}, e.on("change", this.changeHandler), this.createFoldingUI(), this.scheduleFoldIndicatorUpdate();
|
|
1747
1796
|
}
|
|
1748
1797
|
createFoldingUI() {
|
|
1749
|
-
if (!this.editor)
|
|
1798
|
+
if (!this.editor)
|
|
1799
|
+
return;
|
|
1750
1800
|
const e = this.editor.getView().getContentElement(), t = e.closest(".rte-source-editor-modal") || e.parentElement;
|
|
1751
1801
|
t && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
|
|
1752
1802
|
position: absolute;
|
|
@@ -1764,9 +1814,11 @@ class ne {
|
|
|
1764
1814
|
}));
|
|
1765
1815
|
}
|
|
1766
1816
|
updateFoldIndicators() {
|
|
1767
|
-
if (!this.editor || !this.foldingUI)
|
|
1817
|
+
if (!this.editor || !this.foldingUI)
|
|
1818
|
+
return;
|
|
1768
1819
|
const e = this.editor.getValue();
|
|
1769
|
-
if (e === this.lastSnapshot)
|
|
1820
|
+
if (e === this.lastSnapshot)
|
|
1821
|
+
return;
|
|
1770
1822
|
this.lastSnapshot = e, this.foldingUI.innerHTML = "", this.foldIndicators = [];
|
|
1771
1823
|
const t = e.split(`
|
|
1772
1824
|
`), s = this.findFoldableLines(t), i = document.createDocumentFragment();
|
|
@@ -1895,7 +1947,8 @@ class re {
|
|
|
1895
1947
|
let t = e || "";
|
|
1896
1948
|
for (let s = 0; s < 5; s++) {
|
|
1897
1949
|
const i = t;
|
|
1898
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === i)
|
|
1950
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === i)
|
|
1951
|
+
break;
|
|
1899
1952
|
}
|
|
1900
1953
|
return t;
|
|
1901
1954
|
}
|
|
@@ -1904,9 +1957,9 @@ class re {
|
|
|
1904
1957
|
let n = i(e);
|
|
1905
1958
|
const r = (h) => {
|
|
1906
1959
|
let a = h.replace(/"/g, '"').replace(/'/g, "'");
|
|
1907
|
-
return a = a.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${s.comment};">$1</span>`), a = a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (c,
|
|
1908
|
-
const p = String(
|
|
1909
|
-
return `<span style="color: ${s.styleProp};">${
|
|
1960
|
+
return a = a.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${s.comment};">$1</span>`), a = a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (c, d, f, u, g) => {
|
|
1961
|
+
const p = String(u).trim(), y = i(p);
|
|
1962
|
+
return `<span style="color: ${s.styleProp};">${d}</span>${f}<span style="color: ${s.styleVal};">${y}</span>${g}`;
|
|
1910
1963
|
}), a;
|
|
1911
1964
|
}, o = [];
|
|
1912
1965
|
try {
|
|
@@ -1914,17 +1967,18 @@ class re {
|
|
|
1914
1967
|
} catch {
|
|
1915
1968
|
}
|
|
1916
1969
|
let l = 0;
|
|
1917
|
-
return n = n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (h, a, c,
|
|
1918
|
-
|
|
1919
|
-
(o[l
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1970
|
+
return n = n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (h, a, c, d, f) => {
|
|
1971
|
+
var u, g;
|
|
1972
|
+
const p = ((u = o[l++]) == null ? void 0 : u.inner) ?? this.unescapeEntitiesRepeated(d || "");
|
|
1973
|
+
(((g = o[l - 1]) == null ? void 0 : g.attrs) || c || "").toLowerCase();
|
|
1974
|
+
const y = this._highlightJS(p, s);
|
|
1975
|
+
return `${a}${y}${f}`;
|
|
1976
|
+
}), n = n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (h, a, c, d) => {
|
|
1923
1977
|
const f = r(c);
|
|
1924
|
-
return `${a}${f}${
|
|
1925
|
-
}), n = n.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${s.comment};">$1</span>`), n = n.replace(/(<!DOCTYPE[\s\S]*?>)/i, `<span style="color: ${s.doctype};">$1</span>`), n = n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g, (h, a, c,
|
|
1926
|
-
const
|
|
1927
|
-
let g =
|
|
1978
|
+
return `${a}${f}${d}`;
|
|
1979
|
+
}), n = n.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${s.comment};">$1</span>`), n = n.replace(/(<!DOCTYPE[\s\S]*?>)/i, `<span style="color: ${s.doctype};">$1</span>`), n = n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g, (h, a, c, d, f) => {
|
|
1980
|
+
const u = `<span style="color: ${s.tag};">${c}</span>`;
|
|
1981
|
+
let g = d;
|
|
1928
1982
|
return g = g.replace(
|
|
1929
1983
|
/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,
|
|
1930
1984
|
(p, y, k, v) => {
|
|
@@ -1939,76 +1993,76 @@ class re {
|
|
|
1939
1993
|
b && (T = `${b}${S}${b}`), T = `<span style="color: ${s.attrValue};">${T}</span>`;
|
|
1940
1994
|
return `${E}${k}${T}`;
|
|
1941
1995
|
}
|
|
1942
|
-
), `${a}${
|
|
1996
|
+
), `${a}${u}${g}${f}`;
|
|
1943
1997
|
}), n;
|
|
1944
1998
|
}
|
|
1945
1999
|
_highlightJS(e, t) {
|
|
1946
2000
|
const s = this.unescapeEntitiesRepeated(e);
|
|
1947
2001
|
this.escapeHTML(s);
|
|
1948
|
-
const i = [], n = (
|
|
1949
|
-
let f = "",
|
|
2002
|
+
const i = [], n = (d) => {
|
|
2003
|
+
let f = "", u = d;
|
|
1950
2004
|
do
|
|
1951
|
-
f = String.fromCharCode(97 +
|
|
1952
|
-
while (
|
|
2005
|
+
f = String.fromCharCode(97 + u % 26) + f, u = Math.floor(u / 26) - 1;
|
|
2006
|
+
while (u >= 0);
|
|
1953
2007
|
return f || "a";
|
|
1954
|
-
}, r = (
|
|
2008
|
+
}, r = (d) => `\0${n(d)}\0`, o = (d) => {
|
|
1955
2009
|
const f = i.length;
|
|
1956
|
-
return i.push(
|
|
2010
|
+
return i.push(d), r(f);
|
|
1957
2011
|
};
|
|
1958
2012
|
let l;
|
|
1959
2013
|
const h = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
1960
2014
|
let a = 0, c = "";
|
|
1961
2015
|
for (; l = h.exec(s); ) {
|
|
1962
|
-
const
|
|
1963
|
-
a <
|
|
2016
|
+
const d = l.index;
|
|
2017
|
+
a < d && (c += this.escapeHTML(s.slice(a, d)));
|
|
1964
2018
|
const f = l[0];
|
|
1965
2019
|
/^\/\*/.test(f) || /^\/\//.test(f) ? c += o(`<span style="color: ${t.comment};">${this.escapeHTML(f)}</span>`) : c += o(`<span style="color: ${t.string};">${this.escapeHTML(f)}</span>`), a = h.lastIndex;
|
|
1966
2020
|
}
|
|
1967
|
-
return a < s.length && (c += this.escapeHTML(s.slice(a))), c = c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (
|
|
1968
|
-
const g = c[
|
|
1969
|
-
return g === "&" || g === "#" || p === ";" || p === "#" ?
|
|
1970
|
-
}), c = c.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), c.replace(/\u0000([a-z]+)\u0000/g, (
|
|
1971
|
-
let
|
|
2021
|
+
return a < s.length && (c += this.escapeHTML(s.slice(a))), c = c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, f, u) => {
|
|
2022
|
+
const g = c[u - 1] || "", p = c[u + d.length] || "";
|
|
2023
|
+
return g === "&" || g === "#" || p === ";" || p === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
|
|
2024
|
+
}), c = c.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), c.replace(/\u0000([a-z]+)\u0000/g, (d, f) => {
|
|
2025
|
+
let u = 0;
|
|
1972
2026
|
for (let g = 0; g < f.length; g++)
|
|
1973
|
-
|
|
1974
|
-
return
|
|
2027
|
+
u = u * 26 + (f.charCodeAt(g) - 97 + 1);
|
|
2028
|
+
return u = u - 1, i[u] || "";
|
|
1975
2029
|
});
|
|
1976
2030
|
}
|
|
1977
2031
|
_highlightPHP(e, t) {
|
|
1978
2032
|
const s = this.unescapeEntitiesRepeated(e);
|
|
1979
2033
|
let i = this.escapeHTML(s);
|
|
1980
|
-
const n = [], r = (
|
|
1981
|
-
let g = "", p =
|
|
2034
|
+
const n = [], r = (u) => {
|
|
2035
|
+
let g = "", p = u;
|
|
1982
2036
|
do
|
|
1983
2037
|
g = String.fromCharCode(97 + p % 26) + g, p = Math.floor(p / 26) - 1;
|
|
1984
2038
|
while (p >= 0);
|
|
1985
2039
|
return g || "a";
|
|
1986
|
-
}, o = (
|
|
2040
|
+
}, o = (u) => {
|
|
1987
2041
|
const g = n.length;
|
|
1988
|
-
return n.push(
|
|
1989
|
-
}, l = (
|
|
1990
|
-
const p = i.indexOf(
|
|
1991
|
-
return p === -1 ? !1 : (i = i.slice(0, p) + g + i.slice(p +
|
|
2042
|
+
return n.push(u), `\0${r(g)}\0`;
|
|
2043
|
+
}, l = (u, g) => {
|
|
2044
|
+
const p = i.indexOf(u);
|
|
2045
|
+
return p === -1 ? !1 : (i = i.slice(0, p) + g + i.slice(p + u.length), !0);
|
|
1992
2046
|
};
|
|
1993
2047
|
let h;
|
|
1994
|
-
const a = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g,
|
|
2048
|
+
const a = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, f = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
1995
2049
|
for (; h = a.exec(s); ) {
|
|
1996
|
-
const
|
|
1997
|
-
l(this.escapeHTML(
|
|
2050
|
+
const u = h[0];
|
|
2051
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
1998
2052
|
}
|
|
1999
2053
|
for (; h = c.exec(s); ) {
|
|
2000
|
-
const
|
|
2001
|
-
l(this.escapeHTML(
|
|
2054
|
+
const u = h[0];
|
|
2055
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2002
2056
|
}
|
|
2003
|
-
for (; h =
|
|
2004
|
-
const
|
|
2005
|
-
l(this.escapeHTML(
|
|
2057
|
+
for (; h = d.exec(s); ) {
|
|
2058
|
+
const u = h[0];
|
|
2059
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2006
2060
|
}
|
|
2007
2061
|
for (; h = f.exec(s); ) {
|
|
2008
|
-
const
|
|
2009
|
-
l(this.escapeHTML(
|
|
2062
|
+
const u = h[0];
|
|
2063
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`));
|
|
2010
2064
|
}
|
|
2011
|
-
return i = i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), i = i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${t.keyword};">$1</span>`), i = i.replace(/\u0000([a-z]+)\u0000/g, (
|
|
2065
|
+
return i = i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), i = i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${t.keyword};">$1</span>`), i = i.replace(/\u0000([a-z]+)\u0000/g, (u, g) => {
|
|
2012
2066
|
let p = 0;
|
|
2013
2067
|
for (let y = 0; y < g.length; y++)
|
|
2014
2068
|
p = p * 26 + (g.charCodeAt(y) - 97 + 1);
|
|
@@ -2472,9 +2526,9 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2472
2526
|
};
|
|
2473
2527
|
return (() => {
|
|
2474
2528
|
const r = s(t);
|
|
2475
|
-
let o = null, l = "dark", h = !1, a = !1, c = !1,
|
|
2476
|
-
const f = !!e.closest(P) || document.body.matches(P) || document.documentElement.matches(P),
|
|
2477
|
-
|
|
2529
|
+
let o = null, l = "dark", h = !1, a = !1, c = !1, d = !1;
|
|
2530
|
+
const f = !!e.closest(P) || document.body.matches(P) || document.documentElement.matches(P), u = document.createElement("div");
|
|
2531
|
+
u.className = "rte-source-editor-overlay", f && u.classList.add("rte-theme-dark");
|
|
2478
2532
|
const g = document.createElement("div");
|
|
2479
2533
|
g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
|
|
2480
2534
|
const p = document.createElement("div");
|
|
@@ -2532,7 +2586,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2532
2586
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
2533
2587
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
2534
2588
|
</div>
|
|
2535
|
-
`, g.appendChild(p), g.appendChild(y), g.appendChild(E),
|
|
2589
|
+
`, g.appendChild(p), g.appendChild(y), g.appendChild(E), u.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
|
|
2536
2590
|
const x = document.createElement("style");
|
|
2537
2591
|
x.id = "rte-source-editor-styles", x.textContent = le, document.head.appendChild(x);
|
|
2538
2592
|
}
|
|
@@ -2557,10 +2611,10 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2557
2611
|
}, U = (x) => {
|
|
2558
2612
|
c !== x && (c = x, $ && ($.style.display = c ? "inline" : "none"));
|
|
2559
2613
|
}, H = () => {
|
|
2560
|
-
if (!
|
|
2561
|
-
for (
|
|
2614
|
+
if (!d) {
|
|
2615
|
+
for (d = !0; O.length; )
|
|
2562
2616
|
O.pop()?.();
|
|
2563
|
-
o && (o.destroy(), o = null),
|
|
2617
|
+
o && (o.destroy(), o = null), u.isConnected && u.remove();
|
|
2564
2618
|
}
|
|
2565
2619
|
}, K = () => {
|
|
2566
2620
|
l = l === "dark" ? "light" : "dark", o?.setTheme(l), S && (S.innerHTML = l === "light" ? `
|
|
@@ -2594,7 +2648,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2594
2648
|
</svg>
|
|
2595
2649
|
`);
|
|
2596
2650
|
}, q = () => {
|
|
2597
|
-
a = !a,
|
|
2651
|
+
a = !a, u.classList.toggle("fullscreen", a), C.style.height = a ? "calc(100vh - 200px)" : "400px", T && (T.innerHTML = a ? `
|
|
2598
2652
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2599
2653
|
<path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
|
|
2600
2654
|
</svg>
|
|
@@ -2631,13 +2685,13 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2631
2685
|
alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", x);
|
|
2632
2686
|
}
|
|
2633
2687
|
};
|
|
2634
|
-
S && R(S, "click", K), b && R(b, "click", z), T && R(T, "click", q), I && R(I, "click", H), B && R(B, "click", Q), N && R(N, "click", j), R(
|
|
2635
|
-
x.target ===
|
|
2688
|
+
S && R(S, "click", K), b && R(b, "click", z), T && R(T, "click", q), I && R(I, "click", H), B && R(B, "click", Q), N && R(N, "click", j), R(u, "click", (x) => {
|
|
2689
|
+
x.target === u && H();
|
|
2636
2690
|
}), R(document, "keydown", (x) => {
|
|
2637
2691
|
const M = x;
|
|
2638
2692
|
M.key === "Escape" && (M.preventDefault(), H());
|
|
2639
|
-
}), document.body.appendChild(
|
|
2640
|
-
if (!(
|
|
2693
|
+
}), document.body.appendChild(u), requestAnimationFrame(() => {
|
|
2694
|
+
if (!(d || !u.isConnected))
|
|
2641
2695
|
try {
|
|
2642
2696
|
o = oe(C, {
|
|
2643
2697
|
value: r,
|