@editora/plugins 1.0.8 → 1.0.10
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 +27 -0
- package/dist/_commonjsHelpers-6763f629.js +1 -0
- package/dist/_commonjsHelpers-c5d32002.mjs +30 -0
- package/dist/a11y-checker.cjs.js +12 -12
- package/dist/a11y-checker.esm.js +98 -80
- package/dist/anchor.cjs.js +12 -12
- package/dist/anchor.esm.js +128 -115
- package/dist/anchoredPopover-33f1358d.mjs +109 -0
- package/dist/anchoredPopover-8151d535.js +1 -0
- package/dist/approval-workflow.cjs.js +447 -0
- package/dist/approval-workflow.esm.js +1111 -0
- package/dist/background-color.cjs.js +2 -2
- package/dist/background-color.esm.js +68 -55
- package/dist/blockquote.esm.js +2 -1
- package/dist/blocks-library.cjs.js +442 -0
- package/dist/blocks-library.esm.js +1384 -0
- package/dist/capitalization.esm.js +2 -1
- package/dist/checklist.cjs.js +1 -1
- package/dist/checklist.esm.js +82 -58
- package/dist/citations.cjs.js +548 -0
- package/dist/citations.esm.js +1530 -0
- package/dist/clear-formatting.cjs.js +1 -1
- package/dist/clear-formatting.esm.js +33 -27
- package/dist/code-sample.cjs.js +14 -14
- package/dist/code-sample.esm.js +93 -82
- package/dist/code.cjs.js +32 -32
- package/dist/code.esm.js +653 -594
- package/dist/comments.cjs.js +6 -6
- package/dist/comments.esm.js +158 -116
- package/dist/conditional-content.cjs.js +626 -0
- package/dist/conditional-content.esm.js +1421 -0
- package/dist/content-rules.cjs.js +408 -0
- package/dist/content-rules.esm.js +1147 -0
- package/dist/data-binding.cjs.js +321 -0
- package/dist/data-binding.esm.js +953 -0
- package/dist/direction.esm.js +18 -9
- package/dist/doc-schema.cjs.js +398 -0
- package/dist/doc-schema.esm.js +1378 -0
- package/dist/document-manager.cjs.js +1 -1
- package/dist/document-manager.esm.js +5 -4
- package/dist/documentManager-25b6203c.mjs +9122 -0
- package/dist/documentManager-b69e7054.js +17 -0
- package/dist/{editorContainerHelpers-C7kdWnS0.mjs → editorContainerHelpers-69585c07.mjs} +2 -1
- package/dist/embed-iframe.cjs.js +4 -4
- package/dist/embed-iframe.esm.js +81 -73
- package/dist/emojis.cjs.js +8 -8
- package/dist/emojis.esm.js +77 -65
- package/dist/enterprise.cjs.js +1 -0
- package/dist/enterprise.esm.js +58 -0
- package/dist/font-family.cjs.js +1 -1
- package/dist/font-family.esm.js +47 -39
- package/dist/font-size.cjs.js +1 -1
- package/dist/font-size.esm.js +53 -37
- package/dist/footnote.cjs.js +2 -2
- package/dist/footnote.esm.js +117 -76
- package/dist/history.cjs.js +1 -1
- package/dist/history.esm.js +92 -70
- package/dist/html2canvas.esm-09133e29.js +22 -0
- package/dist/{html2canvas.esm-BWVIUcAF.mjs → html2canvas.esm-1a1724a1.mjs} +225 -141
- package/dist/indent.cjs.js +1 -1
- package/dist/indent.esm.js +24 -12
- package/dist/index-656d224b.js +231 -0
- package/dist/index-6a8c48bb.js +1 -0
- package/dist/index-d027b7e2.mjs +16859 -0
- package/dist/{index-BFsKNTTj.mjs → index-f04538f2.mjs} +71 -70
- package/dist/index.cjs.js +1 -1
- package/dist/index.es-730f2d98.mjs +5775 -0
- package/dist/index.es-dd40173b.js +18 -0
- package/dist/index.esm.js +124 -93
- package/dist/italic.cjs.js +1 -1
- package/dist/italic.esm.js +9 -8
- package/dist/jspdf.es.min-90db2c97.js +243 -0
- package/dist/{jspdf.es.min-DQCoX5yh.mjs → jspdf.es.min-c36a4fd8.mjs} +4682 -3658
- package/dist/line-height.cjs.js +1 -1
- package/dist/line-height.esm.js +24 -11
- package/dist/link.cjs.js +5 -5
- package/dist/link.esm.js +30 -24
- package/dist/list.cjs.js +1 -1
- package/dist/list.esm.js +25 -20
- package/dist/lite.cjs.js +1 -1
- package/dist/lite.esm.js +61 -59
- package/dist/math.cjs.js +21 -21
- package/dist/math.esm.js +146 -139
- package/dist/media-manager.cjs.js +38 -38
- package/dist/media-manager.esm.js +325 -308
- package/dist/mentions.cjs.js +105 -0
- package/dist/mentions.esm.js +774 -0
- package/dist/merge-tag.cjs.js +2 -2
- package/dist/merge-tag.esm.js +216 -177
- package/dist/page-break.cjs.js +2 -2
- package/dist/page-break.esm.js +67 -51
- package/dist/pii-redaction.cjs.js +436 -0
- package/dist/pii-redaction.esm.js +1447 -0
- package/dist/preview.cjs.js +3 -3
- package/dist/preview.esm.js +37 -32
- package/dist/print.cjs.js +4 -4
- package/dist/print.esm.js +20 -17
- package/dist/{purify.es-DHhaBdbu.mjs → purify.es-35a15df8.mjs} +19 -9
- package/dist/{purify.es-T2a3nLiC.js → purify.es-a8d731c6.js} +1 -1
- package/dist/slash-commands.cjs.js +90 -0
- package/dist/slash-commands.esm.js +788 -0
- package/dist/smart-paste.cjs.js +398 -0
- package/dist/smart-paste.esm.js +1444 -0
- package/dist/special-characters.cjs.js +7 -7
- package/dist/special-characters.esm.js +69 -61
- package/dist/spell-check.cjs.js +5 -5
- package/dist/spell-check.esm.js +123 -97
- package/dist/strikethrough.cjs.js +1 -1
- package/dist/strikethrough.esm.js +19 -14
- package/dist/style.css +1 -0
- package/dist/table.cjs.js +4 -4
- package/dist/table.esm.js +225 -191
- package/dist/template.cjs.js +11 -11
- package/dist/template.esm.js +153 -124
- package/dist/text-alignment.cjs.js +1 -1
- package/dist/text-alignment.esm.js +27 -21
- package/dist/text-color.cjs.js +3 -3
- package/dist/text-color.esm.js +87 -70
- package/dist/track-changes.cjs.js +77 -0
- package/dist/track-changes.esm.js +817 -0
- package/dist/translation-workflow.cjs.js +626 -0
- package/dist/translation-workflow.esm.js +1794 -0
- package/dist/version-diff.cjs.js +362 -0
- package/dist/version-diff.esm.js +797 -0
- package/index.d.ts +798 -0
- package/package.json +114 -9
- package/dist/_commonjsHelpers-BH3jXuIh.js +0 -1
- package/dist/_commonjsHelpers-ByX85dGu.mjs +0 -33
- package/dist/anchoredPopover-BzqGPOAE.js +0 -1
- package/dist/anchoredPopover-Dts0IrgU.mjs +0 -106
- package/dist/documentManager-CTqRftU8.mjs +0 -8369
- package/dist/documentManager-Jf0RbSks.js +0 -17
- package/dist/html2canvas.esm-B5qzocYs.js +0 -5
- package/dist/index-CvJk4DKa.js +0 -221
- package/dist/index-D3CycEFU.mjs +0 -16543
- package/dist/index-tqLTHcO6.js +0 -1
- package/dist/index.es-CE_A4QSm.js +0 -5
- package/dist/index.es-DQ78mYYo.mjs +0 -6665
- package/dist/jspdf.es.min-BoS80556.js +0 -77
- package/dist/plugins.css +0 -1
- /package/dist/{editorContainerHelpers-CFbfiOJI.js → editorContainerHelpers-36b8ddf3.js} +0 -0
package/dist/code.esm.js
CHANGED
|
@@ -30,28 +30,28 @@ class D {
|
|
|
30
30
|
return this.getLine(e.start.line).substring(e.start.column, e.end.column);
|
|
31
31
|
const t = [];
|
|
32
32
|
t.push(this.getLine(e.start.line).substring(e.start.column));
|
|
33
|
-
for (let
|
|
34
|
-
t.push(this.getLine(
|
|
33
|
+
for (let i = e.start.line + 1; i < e.end.line; i++)
|
|
34
|
+
t.push(this.getLine(i));
|
|
35
35
|
return e.end.line < this.getLineCount() && t.push(this.getLine(e.end.line).substring(0, e.end.column)), t.join(`
|
|
36
36
|
`);
|
|
37
37
|
}
|
|
38
38
|
// Replace text in range
|
|
39
39
|
replaceRange(e, t) {
|
|
40
|
-
const
|
|
40
|
+
const i = this.getTextInRange(e);
|
|
41
41
|
if (e.start.line === e.end.line) {
|
|
42
|
-
const
|
|
42
|
+
const s = this.getLine(e.start.line), n = s.substring(0, e.start.column) + t + s.substring(e.end.column);
|
|
43
43
|
this._lines[e.start.line] = n;
|
|
44
44
|
} else {
|
|
45
|
-
const
|
|
45
|
+
const s = this.getLine(e.start.line), n = this.getLine(e.end.line), r = s.substring(0, e.start.column) + t, o = n.substring(e.end.column), a = t.split(`
|
|
46
46
|
`);
|
|
47
|
-
|
|
47
|
+
a[0] = r + a[0], a[a.length - 1] = a[a.length - 1] + o, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...a);
|
|
48
48
|
}
|
|
49
|
-
return this._version++, { range: e, text: t, oldText:
|
|
49
|
+
return this._version++, { range: e, text: t, oldText: i };
|
|
50
50
|
}
|
|
51
51
|
// Insert text at position
|
|
52
52
|
insertText(e, t) {
|
|
53
|
-
const
|
|
54
|
-
return this.replaceRange(
|
|
53
|
+
const i = { start: e, end: e };
|
|
54
|
+
return this.replaceRange(i, t);
|
|
55
55
|
}
|
|
56
56
|
// Delete text in range
|
|
57
57
|
deleteRange(e) {
|
|
@@ -60,18 +60,18 @@ class D {
|
|
|
60
60
|
// Convert position to offset
|
|
61
61
|
positionToOffset(e) {
|
|
62
62
|
let t = 0;
|
|
63
|
-
for (let
|
|
64
|
-
t += this.getLine(
|
|
63
|
+
for (let i = 0; i < e.line; i++)
|
|
64
|
+
t += this.getLine(i).length + 1;
|
|
65
65
|
return t += e.column, t;
|
|
66
66
|
}
|
|
67
67
|
// Convert offset to position
|
|
68
68
|
offsetToPosition(e) {
|
|
69
69
|
let t = e;
|
|
70
|
-
for (let
|
|
71
|
-
const
|
|
72
|
-
if (t <=
|
|
73
|
-
return { line:
|
|
74
|
-
t -=
|
|
70
|
+
for (let i = 0; i < this.getLineCount(); i++) {
|
|
71
|
+
const s = this.getLine(i).length;
|
|
72
|
+
if (t <= s)
|
|
73
|
+
return { line: i, column: t };
|
|
74
|
+
t -= s + 1;
|
|
75
75
|
}
|
|
76
76
|
return {
|
|
77
77
|
line: this.getLineCount() - 1,
|
|
@@ -149,8 +149,8 @@ class Z {
|
|
|
149
149
|
}
|
|
150
150
|
// Update line numbers
|
|
151
151
|
updateLineNumbers(e) {
|
|
152
|
-
const t = Math.max(e, 20),
|
|
153
|
-
this.lineNumbersElement.innerHTML =
|
|
152
|
+
const t = Math.max(e, 20), i = Array.from({ length: t }, (s, n) => n + 1);
|
|
153
|
+
this.lineNumbersElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("");
|
|
154
154
|
}
|
|
155
155
|
// Get content element
|
|
156
156
|
getContentElement() {
|
|
@@ -175,8 +175,8 @@ class Z {
|
|
|
175
175
|
}
|
|
176
176
|
// Set inner HTML (used for syntax highlighted content)
|
|
177
177
|
setHTML(e) {
|
|
178
|
-
const t = /\n$/.test(e),
|
|
179
|
-
|
|
178
|
+
const t = /\n$/.test(e), i = /<|>/.test(e), s = /<span\b/i.test(e), n = /<[^>]+>/.test(e);
|
|
179
|
+
i && s ? this.contentElement.innerHTML = e : n && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
|
|
180
180
|
const r = (this.contentElement.textContent || "").split(`
|
|
181
181
|
`).length;
|
|
182
182
|
this.updateLineNumbers(r);
|
|
@@ -192,38 +192,39 @@ class Z {
|
|
|
192
192
|
const e = window.getSelection();
|
|
193
193
|
if (!e || e.rangeCount === 0)
|
|
194
194
|
return { line: 0, column: 0 };
|
|
195
|
-
const t = e.getRangeAt(0),
|
|
196
|
-
|
|
197
|
-
const
|
|
195
|
+
const t = e.getRangeAt(0), i = t.cloneRange();
|
|
196
|
+
i.selectNodeContents(this.contentElement), i.setEnd(t.endContainer, t.endOffset);
|
|
197
|
+
const s = i.toString().replace(/\u200B/g, "").split(`
|
|
198
198
|
`);
|
|
199
199
|
return {
|
|
200
|
-
line:
|
|
201
|
-
column:
|
|
200
|
+
line: s.length - 1,
|
|
201
|
+
column: s[s.length - 1].length
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
// Set cursor position
|
|
205
205
|
setCursorPosition(e) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
var t;
|
|
207
|
+
const i = this.getText().split(`
|
|
208
|
+
`), s = Math.min(e.line, i.length - 1), n = Math.min(e.column, ((t = i[s]) == null ? void 0 : t.length) || 0);
|
|
209
|
+
let r = 0;
|
|
210
|
+
for (let l = 0; l < s; l++)
|
|
211
|
+
r += i[l].length + 1;
|
|
212
|
+
r += n;
|
|
213
|
+
const o = document.createRange(), a = 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), a == null || a.removeAllRanges(), a == null || a.addRange(o), this.ensureCaretVisible();
|
|
217
|
+
} catch (l) {
|
|
218
|
+
console.warn("Could not set cursor position:", l);
|
|
218
219
|
}
|
|
219
220
|
else {
|
|
220
|
-
const
|
|
221
|
+
const l = 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
|
+
l && l.parentNode === this.contentElement ? o.setStartBefore(l) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), a == null || a.removeAllRanges(), a == null || a.addRange(o), this.ensureCaretVisible();
|
|
226
|
+
} catch (c) {
|
|
227
|
+
console.warn("Could not set fallback cursor position:", c);
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
230
|
}
|
|
@@ -232,17 +233,17 @@ class Z {
|
|
|
232
233
|
const e = window.getSelection();
|
|
233
234
|
if (!e || e.rangeCount === 0 || e.isCollapsed)
|
|
234
235
|
return;
|
|
235
|
-
const t = e.getRangeAt(0),
|
|
236
|
-
|
|
237
|
-
const
|
|
236
|
+
const t = e.getRangeAt(0), i = t.cloneRange();
|
|
237
|
+
i.selectNodeContents(this.contentElement), i.setEnd(t.startContainer, t.startOffset);
|
|
238
|
+
const s = i.toString().replace(/\u200B/g, "").split(`
|
|
238
239
|
`), n = t.cloneRange();
|
|
239
240
|
n.selectNodeContents(this.contentElement), n.setEnd(t.endContainer, t.endOffset);
|
|
240
241
|
const r = n.toString().replace(/\u200B/g, "").split(`
|
|
241
242
|
`);
|
|
242
243
|
return {
|
|
243
244
|
start: {
|
|
244
|
-
line:
|
|
245
|
-
column:
|
|
245
|
+
line: s.length - 1,
|
|
246
|
+
column: s[s.length - 1].length
|
|
246
247
|
},
|
|
247
248
|
end: {
|
|
248
249
|
line: r.length - 1,
|
|
@@ -253,22 +254,23 @@ class Z {
|
|
|
253
254
|
// Set selection range
|
|
254
255
|
setSelectionRange(e) {
|
|
255
256
|
const t = this.getText().split(`
|
|
256
|
-
`),
|
|
257
|
-
const
|
|
257
|
+
`), i = (c) => {
|
|
258
|
+
const d = Math.max(0, Math.min(c.line, t.length - 1)), p = 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
|
|
265
|
-
},
|
|
266
|
-
if (!
|
|
267
|
-
|
|
262
|
+
let u = 0;
|
|
263
|
+
for (let g = 0; g < d; g++)
|
|
264
|
+
u += t[g].length + 1;
|
|
265
|
+
return u + p;
|
|
266
|
+
}, s = i(e.start), n = i(e.end), [r, o] = s <= n ? [s, n] : [n, s], a = this.resolveOffsetToDomPoint(r), h = this.resolveOffsetToDomPoint(o);
|
|
267
|
+
if (!a || !h)
|
|
268
|
+
return;
|
|
269
|
+
const l = document.createRange();
|
|
268
270
|
try {
|
|
269
|
-
|
|
271
|
+
l.setStart(a.node, a.offset), l.setEnd(h.node, h.offset);
|
|
270
272
|
const c = window.getSelection();
|
|
271
|
-
c
|
|
273
|
+
c == null || c.removeAllRanges(), c == null || c.addRange(l), this.ensureCaretVisible();
|
|
272
274
|
} catch (c) {
|
|
273
275
|
console.warn("Could not set selection range:", c);
|
|
274
276
|
}
|
|
@@ -287,8 +289,8 @@ class Z {
|
|
|
287
289
|
}
|
|
288
290
|
// Apply theme
|
|
289
291
|
applyTheme(e) {
|
|
290
|
-
Object.entries(e).forEach(([t,
|
|
291
|
-
this.container.style.setProperty(`--${t}`,
|
|
292
|
+
Object.entries(e).forEach(([t, i]) => {
|
|
293
|
+
this.container.style.setProperty(`--${t}`, i);
|
|
292
294
|
});
|
|
293
295
|
}
|
|
294
296
|
// Scroll to position
|
|
@@ -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((
|
|
314
|
+
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.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,54 +324,59 @@ 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
|
-
s.
|
|
327
|
+
var e;
|
|
328
|
+
const t = window.getSelection();
|
|
329
|
+
if (!t || t.rangeCount === 0)
|
|
330
|
+
return;
|
|
331
|
+
const i = t.getRangeAt(0).cloneRange();
|
|
332
|
+
i.collapse(!1);
|
|
333
|
+
let s = i.getClientRects()[0] || i.getBoundingClientRect();
|
|
334
|
+
if ((!s || s.width === 0 && s.height === 0) && t.focusNode instanceof Element ? s = t.focusNode.getBoundingClientRect() : (!s || s.width === 0 && s.height === 0) && (e = t.focusNode) != null && e.parentElement && (s = t.focusNode.parentElement.getBoundingClientRect()), !s)
|
|
335
|
+
return;
|
|
336
|
+
const n = this.editorContainer.getBoundingClientRect(), r = 12;
|
|
337
|
+
s.bottom > n.bottom - r ? this.editorContainer.scrollTop += s.bottom - (n.bottom - r) : s.top < n.top + r && (this.editorContainer.scrollTop -= n.top + r - s.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
|
-
|
|
344
|
+
var t;
|
|
345
|
+
const i = Math.max(0, e);
|
|
339
346
|
let s = 0;
|
|
340
|
-
const
|
|
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 a = o.parentElement;
|
|
355
|
+
if (a != null && a.hasAttribute(this.trailingNewlineMarkerAttr))
|
|
348
356
|
continue;
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
if (s +
|
|
352
|
-
const
|
|
357
|
+
r = o;
|
|
358
|
+
const h = o.textContent || "", l = this.buildVisibleToDomMap(h), c = Math.max(0, l.length - 1);
|
|
359
|
+
if (s + c >= i) {
|
|
360
|
+
const d = Math.max(0, i - s), p = l[d] ?? h.length;
|
|
353
361
|
return {
|
|
354
|
-
node:
|
|
355
|
-
offset:
|
|
362
|
+
node: o,
|
|
363
|
+
offset: p
|
|
356
364
|
};
|
|
357
365
|
}
|
|
358
|
-
s +=
|
|
366
|
+
s += c;
|
|
359
367
|
}
|
|
360
|
-
if (
|
|
361
|
-
const
|
|
362
|
-
return { node:
|
|
368
|
+
if (r) {
|
|
369
|
+
const a = ((t = r.textContent) == null ? void 0 : t.length) || 0;
|
|
370
|
+
return { node: r, offset: a };
|
|
363
371
|
}
|
|
364
372
|
return null;
|
|
365
373
|
}
|
|
366
374
|
buildVisibleToDomMap(e) {
|
|
367
375
|
const t = [0];
|
|
368
|
-
let
|
|
369
|
-
for (let
|
|
370
|
-
const n = e[
|
|
371
|
-
this.virtualMarkerRegex.test(n) || (
|
|
376
|
+
let i = 0;
|
|
377
|
+
for (let s = 0; s < e.length; s++) {
|
|
378
|
+
const n = e[s];
|
|
379
|
+
this.virtualMarkerRegex.test(n) || (i += 1, t[i] = s + 1);
|
|
372
380
|
}
|
|
373
381
|
return t;
|
|
374
382
|
}
|
|
@@ -383,7 +391,7 @@ const F = class L {
|
|
|
383
391
|
lineWrapping: !1,
|
|
384
392
|
lineNumbers: !0,
|
|
385
393
|
...t
|
|
386
|
-
}, this.textModel = new D(this.config.value), this.view = new Z(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((
|
|
394
|
+
}, this.textModel = new D(this.config.value), this.view = new Z(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
|
|
387
395
|
}
|
|
388
396
|
// Public accessors for extensions
|
|
389
397
|
getTextModel() {
|
|
@@ -409,21 +417,21 @@ const F = class L {
|
|
|
409
417
|
setupEventHandlers() {
|
|
410
418
|
const e = this.view.getContentElement();
|
|
411
419
|
e.addEventListener("input", () => {
|
|
412
|
-
const t = this.view.getText(),
|
|
413
|
-
if (t !==
|
|
420
|
+
const t = this.view.getText(), i = this.textModel.getText();
|
|
421
|
+
if (t !== i) {
|
|
414
422
|
if (!this.suppressHistory) {
|
|
415
|
-
const
|
|
416
|
-
let o,
|
|
417
|
-
r && (o = this.textModel.positionToOffset(r.start),
|
|
423
|
+
const s = this.getCursor().position, n = this.textModel.positionToOffset(s), r = this.getSelection();
|
|
424
|
+
let o, a;
|
|
425
|
+
r && (o = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: i, cursorOffset: n, anchorOffset: o, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
418
426
|
}
|
|
419
427
|
this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText:
|
|
428
|
+
const s = this.view.getText();
|
|
429
|
+
s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
|
|
430
|
+
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
|
|
423
431
|
}
|
|
424
432
|
}), e.addEventListener("selectionchange", () => {
|
|
425
|
-
const t = this.getCursor(),
|
|
426
|
-
this.emit("cursor", t),
|
|
433
|
+
const t = this.getCursor(), i = this.getSelection();
|
|
434
|
+
this.emit("cursor", t), i && this.emit("selection", i);
|
|
427
435
|
}), e.addEventListener("keydown", (t) => {
|
|
428
436
|
if (this.emit("keydown", t), t.key === "Tab") {
|
|
429
437
|
this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
|
|
@@ -431,34 +439,34 @@ const F = class L {
|
|
|
431
439
|
}
|
|
432
440
|
if (t.key === "Enter") {
|
|
433
441
|
if (!this.config.readOnly) {
|
|
434
|
-
const
|
|
435
|
-
if (
|
|
436
|
-
const
|
|
437
|
-
let o,
|
|
438
|
-
r && (o = this.textModel.positionToOffset(r.start),
|
|
439
|
-
const h = r && o !== void 0 &&
|
|
440
|
-
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset: o, focusOffset:
|
|
441
|
-
const
|
|
442
|
-
|
|
442
|
+
const i = window.getSelection();
|
|
443
|
+
if (i && i.rangeCount > 0) {
|
|
444
|
+
const s = this.getCursor().position, n = this.textModel.positionToOffset(s), r = this.getSelection();
|
|
445
|
+
let o, a;
|
|
446
|
+
r && (o = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end));
|
|
447
|
+
const h = r && o !== void 0 && a !== void 0 ? Math.min(o, a) : n;
|
|
448
|
+
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset: o, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
|
|
449
|
+
const l = i.getRangeAt(0);
|
|
450
|
+
l.deleteContents();
|
|
443
451
|
const c = document.createTextNode(`
|
|
444
452
|
`);
|
|
445
|
-
|
|
446
|
-
const
|
|
447
|
-
this.textModel.setText(
|
|
448
|
-
const
|
|
453
|
+
l.insertNode(c), l.setStartAfter(c), l.collapse(!0), i.removeAllRanges(), i.addRange(l), this.view.ensureCaretVisible();
|
|
454
|
+
const d = this.view.getText();
|
|
455
|
+
this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
|
|
456
|
+
const p = 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(p);
|
|
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(p);
|
|
469
|
+
this.setCursor(u), this.view.ensureCaretVisible();
|
|
462
470
|
} catch {
|
|
463
471
|
}
|
|
464
472
|
}), this.highlightTimeout = null;
|
|
@@ -468,15 +476,15 @@ const F = class L {
|
|
|
468
476
|
t.preventDefault(), t.stopPropagation();
|
|
469
477
|
return;
|
|
470
478
|
}
|
|
471
|
-
for (const
|
|
472
|
-
if (
|
|
479
|
+
for (const i of this.extensions.values())
|
|
480
|
+
if (i.onKeyDown && i.onKeyDown(t) === !1) {
|
|
473
481
|
t.preventDefault(), t.stopPropagation();
|
|
474
482
|
return;
|
|
475
483
|
}
|
|
476
484
|
}), e.addEventListener("mousedown", (t) => {
|
|
477
485
|
this.emit("mousedown", t);
|
|
478
|
-
for (const
|
|
479
|
-
if (
|
|
486
|
+
for (const i of this.extensions.values())
|
|
487
|
+
if (i.onMouseDown && i.onMouseDown(t) === !1) {
|
|
480
488
|
t.preventDefault(), t.stopPropagation();
|
|
481
489
|
return;
|
|
482
490
|
}
|
|
@@ -503,8 +511,8 @@ const F = class L {
|
|
|
503
511
|
}
|
|
504
512
|
// Emit events to listeners
|
|
505
513
|
emit(e, ...t) {
|
|
506
|
-
const
|
|
507
|
-
|
|
514
|
+
const i = this.eventListeners.get(e);
|
|
515
|
+
i && i.forEach((s) => s(...t));
|
|
508
516
|
}
|
|
509
517
|
// State management
|
|
510
518
|
getValue() {
|
|
@@ -552,12 +560,12 @@ const F = class L {
|
|
|
552
560
|
"editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
|
|
553
561
|
};
|
|
554
562
|
this.view.applyTheme(t);
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
563
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
564
|
+
if (i && typeof i.setTheme == "function")
|
|
557
565
|
try {
|
|
558
|
-
|
|
559
|
-
} catch (
|
|
560
|
-
console.warn("Error applying theme to syntax-highlighting extension",
|
|
566
|
+
i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
|
|
567
|
+
} catch (s) {
|
|
568
|
+
console.warn("Error applying theme to syntax-highlighting extension", s);
|
|
561
569
|
}
|
|
562
570
|
}
|
|
563
571
|
setReadOnly(e) {
|
|
@@ -574,8 +582,8 @@ const F = class L {
|
|
|
574
582
|
t && t.destroy && t.destroy(), this.extensions.delete(e);
|
|
575
583
|
}
|
|
576
584
|
executeCommand(e, ...t) {
|
|
577
|
-
const
|
|
578
|
-
|
|
585
|
+
const i = this.commands.get(e);
|
|
586
|
+
i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
|
|
579
587
|
}
|
|
580
588
|
// Register a command
|
|
581
589
|
registerCommand(e, t) {
|
|
@@ -583,93 +591,94 @@ const F = class L {
|
|
|
583
591
|
}
|
|
584
592
|
// Search & Navigation
|
|
585
593
|
search(e, t = {}) {
|
|
586
|
-
if (!e)
|
|
587
|
-
|
|
594
|
+
if (!e)
|
|
595
|
+
return [];
|
|
596
|
+
const i = {
|
|
588
597
|
query: e,
|
|
589
598
|
caseSensitive: !1,
|
|
590
599
|
wholeWord: !1,
|
|
591
600
|
regex: !1,
|
|
592
601
|
...t
|
|
593
|
-
},
|
|
594
|
-
if (
|
|
595
|
-
let
|
|
602
|
+
}, s = [], n = this.textModel.getText(), { normalizedText: r, normalizedToRawOffsets: o } = this.buildSearchTextAndOffsetMap(n), a = i.caseSensitive ? r : r.toLowerCase(), h = i.caseSensitive ? e : e.toLowerCase();
|
|
603
|
+
if (i.regex) {
|
|
604
|
+
let l;
|
|
596
605
|
try {
|
|
597
|
-
|
|
606
|
+
l = new RegExp(e, i.caseSensitive ? "g" : "gi");
|
|
598
607
|
} catch {
|
|
599
608
|
return [];
|
|
600
609
|
}
|
|
601
610
|
let c;
|
|
602
|
-
for (; (c =
|
|
603
|
-
const
|
|
604
|
-
if (
|
|
605
|
-
|
|
611
|
+
for (; (c = l.exec(r)) !== null; ) {
|
|
612
|
+
const d = c[0] ?? "";
|
|
613
|
+
if (d.length === 0) {
|
|
614
|
+
l.lastIndex = c.index + 1;
|
|
606
615
|
continue;
|
|
607
616
|
}
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
617
|
+
const p = c.index, u = c.index + d.length;
|
|
618
|
+
i.wholeWord && !this.isWholeWordBoundary(r, p, u) || this.pushSearchResultFromOffsets(
|
|
619
|
+
s,
|
|
620
|
+
p,
|
|
621
|
+
u,
|
|
613
622
|
r,
|
|
614
623
|
o
|
|
615
624
|
);
|
|
616
625
|
}
|
|
617
626
|
} else {
|
|
618
|
-
let
|
|
627
|
+
let l = 0, c = a.indexOf(h, l);
|
|
619
628
|
for (; c !== -1; ) {
|
|
620
|
-
const
|
|
621
|
-
!
|
|
622
|
-
|
|
629
|
+
const d = c + h.length;
|
|
630
|
+
!i.wholeWord || this.isWholeWordBoundary(r, c, d) ? (this.pushSearchResultFromOffsets(
|
|
631
|
+
s,
|
|
623
632
|
c,
|
|
624
|
-
|
|
633
|
+
d,
|
|
625
634
|
r,
|
|
626
635
|
o
|
|
627
|
-
),
|
|
636
|
+
), l = d) : l = c + 1, c = a.indexOf(h, l);
|
|
628
637
|
}
|
|
629
638
|
}
|
|
630
|
-
return
|
|
639
|
+
return s;
|
|
631
640
|
}
|
|
632
|
-
pushSearchResultFromOffsets(e, t,
|
|
633
|
-
const r = n[t] ?? t, o = n[
|
|
641
|
+
pushSearchResultFromOffsets(e, t, i, s, n) {
|
|
642
|
+
const r = n[t] ?? t, o = n[i] ?? r, a = this.textModel.offsetToPosition(r), h = this.textModel.offsetToPosition(o);
|
|
634
643
|
e.push({
|
|
635
|
-
range: { start:
|
|
636
|
-
match:
|
|
644
|
+
range: { start: a, end: h },
|
|
645
|
+
match: s.substring(t, i)
|
|
637
646
|
});
|
|
638
647
|
}
|
|
639
|
-
isWholeWordBoundary(e, t,
|
|
640
|
-
const
|
|
641
|
-
return !this.isWordChar(
|
|
648
|
+
isWholeWordBoundary(e, t, i) {
|
|
649
|
+
const s = t > 0 ? e[t - 1] : "", n = i < e.length ? e[i] : "";
|
|
650
|
+
return !this.isWordChar(s) && !this.isWordChar(n);
|
|
642
651
|
}
|
|
643
652
|
isWordChar(e) {
|
|
644
653
|
return /^[A-Za-z0-9_]$/.test(e);
|
|
645
654
|
}
|
|
646
655
|
buildSearchTextAndOffsetMap(e) {
|
|
647
|
-
const t = [],
|
|
648
|
-
let
|
|
656
|
+
const t = [], i = [0];
|
|
657
|
+
let s = 0;
|
|
649
658
|
for (let n = 0; n < e.length; n++) {
|
|
650
659
|
const r = e[n];
|
|
651
|
-
r === "" || r === L.CURSOR_SENTINEL || (t.push(r),
|
|
660
|
+
r === "" || r === L.CURSOR_SENTINEL || (t.push(r), s += 1, i[s] = n + 1);
|
|
652
661
|
}
|
|
653
|
-
return s
|
|
662
|
+
return i[s] = e.length, {
|
|
654
663
|
normalizedText: t.join(""),
|
|
655
|
-
normalizedToRawOffsets:
|
|
664
|
+
normalizedToRawOffsets: i
|
|
656
665
|
};
|
|
657
666
|
}
|
|
658
667
|
replace(e, t) {
|
|
659
|
-
const
|
|
668
|
+
const i = this.getValue();
|
|
660
669
|
if (!this.suppressHistory) {
|
|
661
670
|
const n = this.getCursor().position, r = this.textModel.positionToOffset(n), o = this.getSelection();
|
|
662
|
-
let
|
|
663
|
-
o && (
|
|
671
|
+
let a, h;
|
|
672
|
+
o && (a = this.textModel.positionToOffset(o.start), h = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: a, focusOffset: h }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
664
673
|
}
|
|
665
|
-
const
|
|
666
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [
|
|
674
|
+
const s = this.textModel.replaceRange(e, t);
|
|
675
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [s]);
|
|
667
676
|
}
|
|
668
|
-
replaceAll(e, t,
|
|
669
|
-
const
|
|
677
|
+
replaceAll(e, t, i = {}) {
|
|
678
|
+
const s = this.search(e, i);
|
|
670
679
|
let n = 0;
|
|
671
|
-
for (let r =
|
|
672
|
-
this.replace(
|
|
680
|
+
for (let r = s.length - 1; r >= 0; r--)
|
|
681
|
+
this.replace(s[r].range, t), n++;
|
|
673
682
|
return n;
|
|
674
683
|
}
|
|
675
684
|
// Folding (basic implementation)
|
|
@@ -702,42 +711,42 @@ const F = class L {
|
|
|
702
711
|
// and restores it after updating the DOM. Callers that will explicitly set the caret
|
|
703
712
|
// should pass `false` to avoid stomping programmatic cursor changes.
|
|
704
713
|
renderTextWithHighlight(e, t = !0) {
|
|
705
|
-
const
|
|
706
|
-
if (
|
|
714
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
715
|
+
if (i && typeof i.highlightHTML == "function")
|
|
707
716
|
try {
|
|
708
|
-
const
|
|
709
|
-
let n, r, o,
|
|
710
|
-
if (t ||
|
|
717
|
+
const s = !t && !this.expectingProgrammaticCursor;
|
|
718
|
+
let n, r, o, a;
|
|
719
|
+
if (t || s) {
|
|
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
|
-
const
|
|
717
|
-
r = this.textModel.positionToOffset(
|
|
725
|
+
const p = this.getCursor().position;
|
|
726
|
+
r = this.textModel.positionToOffset(p);
|
|
718
727
|
}
|
|
719
|
-
n && (o = this.textModel.positionToOffset(n.start),
|
|
728
|
+
n && (o = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end));
|
|
720
729
|
}
|
|
721
|
-
const h = (t ||
|
|
722
|
-
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(c) : this.view.setHTML(c), this.view.syncTrailingNewlineMarkerForText(e), (t ||
|
|
730
|
+
const h = (t || s) && !n && r !== void 0 && this.hasCollapsedSelectionInEditor(), l = h ? this.insertSentinelAtOffset(e, r) : e, c = i.highlightHTML(l);
|
|
731
|
+
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(c) : this.view.setHTML(c), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
|
|
723
732
|
try {
|
|
724
733
|
if (h && this.restoreCursorFromSentinel()) {
|
|
725
734
|
this.view.ensureCaretVisible();
|
|
726
735
|
return;
|
|
727
736
|
}
|
|
728
|
-
if (n && (o !== void 0 ||
|
|
729
|
-
const
|
|
730
|
-
this.view.setSelectionRange({ start:
|
|
737
|
+
if (n && (o !== void 0 || a !== void 0)) {
|
|
738
|
+
const d = o !== void 0 ? o : r, p = a !== void 0 ? a : r, u = Math.min(d, p), g = Math.max(d, p), f = this.textModel.offsetToPosition(u), y = this.textModel.offsetToPosition(g);
|
|
739
|
+
this.view.setSelectionRange({ start: f, 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
|
}
|
|
737
746
|
});
|
|
738
747
|
return;
|
|
739
|
-
} catch (
|
|
740
|
-
console.warn("Syntax highlighting failed, falling back to plain text",
|
|
748
|
+
} catch (s) {
|
|
749
|
+
console.warn("Syntax highlighting failed, falling back to plain text", s);
|
|
741
750
|
}
|
|
742
751
|
this.view.setText(e);
|
|
743
752
|
}
|
|
@@ -752,27 +761,28 @@ const F = class L {
|
|
|
752
761
|
const e = window.getSelection();
|
|
753
762
|
if (!e || e.rangeCount === 0 || !e.isCollapsed)
|
|
754
763
|
return;
|
|
755
|
-
const t = e.getRangeAt(0),
|
|
756
|
-
if (!
|
|
764
|
+
const t = e.getRangeAt(0), i = this.view.getContentElement();
|
|
765
|
+
if (!i.contains(t.commonAncestorContainer))
|
|
757
766
|
return;
|
|
758
|
-
const
|
|
759
|
-
return
|
|
767
|
+
const s = t.cloneRange();
|
|
768
|
+
return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
|
|
760
769
|
}
|
|
761
770
|
stripVirtualMarkers(e) {
|
|
762
771
|
return e.replace(/\u200B/g, "").split(L.CURSOR_SENTINEL).join("");
|
|
763
772
|
}
|
|
764
773
|
insertSentinelAtOffset(e, t) {
|
|
765
|
-
const
|
|
766
|
-
return e.slice(0,
|
|
774
|
+
const i = Math.max(0, Math.min(t, e.length));
|
|
775
|
+
return e.slice(0, i) + L.CURSOR_SENTINEL + e.slice(i);
|
|
767
776
|
}
|
|
768
777
|
restoreCursorFromSentinel() {
|
|
769
|
-
const e = this.view.getContentElement(), t = window.getSelection(),
|
|
770
|
-
let
|
|
771
|
-
for (;
|
|
772
|
-
const o =
|
|
773
|
-
|
|
778
|
+
const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
|
|
779
|
+
let s = i.nextNode(), n = null, r = 0;
|
|
780
|
+
for (; s; ) {
|
|
781
|
+
const o = s.textContent ?? "", a = o.indexOf(L.CURSOR_SENTINEL);
|
|
782
|
+
a !== -1 && (n || (n = s, r = a), s.textContent = o.split(L.CURSOR_SENTINEL).join("")), s = i.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,20 +800,21 @@ 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 {
|
|
797
808
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
798
|
-
let
|
|
799
|
-
typeof e == "string" ?
|
|
809
|
+
let i, s;
|
|
810
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
800
811
|
try {
|
|
801
|
-
if (
|
|
812
|
+
if (s != null)
|
|
802
813
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
803
|
-
const n = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
804
|
-
this.setSelection({ start: h, end:
|
|
814
|
+
const n = e.anchorOffset !== void 0 ? e.anchorOffset : s, r = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(n, r), a = Math.max(n, r), h = this.textModel.offsetToPosition(o), l = this.textModel.offsetToPosition(a);
|
|
815
|
+
this.setSelection({ start: h, end: l });
|
|
805
816
|
} else {
|
|
806
|
-
const n = this.textModel.offsetToPosition(
|
|
817
|
+
const n = this.textModel.offsetToPosition(s);
|
|
807
818
|
this.setCursor(n);
|
|
808
819
|
}
|
|
809
820
|
} catch {
|
|
@@ -816,20 +827,21 @@ 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 {
|
|
823
835
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
824
|
-
let
|
|
825
|
-
typeof e == "string" ?
|
|
836
|
+
let i, s;
|
|
837
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
826
838
|
try {
|
|
827
|
-
if (
|
|
839
|
+
if (s != null)
|
|
828
840
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
829
|
-
const n = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
830
|
-
this.setSelection({ start: h, end:
|
|
841
|
+
const n = e.anchorOffset !== void 0 ? e.anchorOffset : s, r = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(n, r), a = Math.max(n, r), h = this.textModel.offsetToPosition(o), l = this.textModel.offsetToPosition(a);
|
|
842
|
+
this.setSelection({ start: h, end: l });
|
|
831
843
|
} else {
|
|
832
|
-
const n = this.textModel.offsetToPosition(
|
|
844
|
+
const n = this.textModel.offsetToPosition(s);
|
|
833
845
|
this.setCursor(n);
|
|
834
846
|
}
|
|
835
847
|
} catch {
|
|
@@ -843,43 +855,46 @@ 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)
|
|
847
|
-
|
|
858
|
+
if (this.config.readOnly)
|
|
859
|
+
return;
|
|
860
|
+
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = " ".repeat(this.config.tabSize || 2), s = this.textModel.insertText(e, i), n = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + i.length);
|
|
848
861
|
if (!this.suppressHistory) {
|
|
849
862
|
const r = this.getSelection();
|
|
850
|
-
let o,
|
|
851
|
-
r && (o = this.textModel.positionToOffset(r.start),
|
|
863
|
+
let o, a;
|
|
864
|
+
r && (o = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: a }), this.redoStack.length = 0;
|
|
852
865
|
}
|
|
853
866
|
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(n), setTimeout(() => {
|
|
854
867
|
this.expectingProgrammaticCursor = !1;
|
|
855
|
-
}, 20), this.emit("change", [
|
|
868
|
+
}, 20), this.emit("change", [s]);
|
|
856
869
|
}
|
|
857
870
|
// Insert a newline at current cursor position
|
|
858
871
|
insertNewLine() {
|
|
859
|
-
if (this.config.readOnly)
|
|
860
|
-
|
|
861
|
-
|
|
872
|
+
if (this.config.readOnly)
|
|
873
|
+
return;
|
|
874
|
+
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
|
|
875
|
+
`), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
|
|
862
876
|
if (!this.suppressHistory) {
|
|
863
877
|
const n = this.getSelection();
|
|
864
878
|
let r, o;
|
|
865
879
|
n && (r = this.textModel.positionToOffset(n.start), o = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: r, focusOffset: o }), this.redoStack.length = 0;
|
|
866
880
|
}
|
|
867
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(
|
|
881
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
|
|
868
882
|
this.expectingProgrammaticCursor = !1;
|
|
869
|
-
}, 20), this.emit("change", [
|
|
883
|
+
}, 20), this.emit("change", [i]);
|
|
870
884
|
}
|
|
871
885
|
// Events
|
|
872
886
|
on(e, t) {
|
|
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))
|
|
877
|
-
|
|
890
|
+
if (!this.eventListeners.has(e))
|
|
891
|
+
return;
|
|
892
|
+
const i = this.eventListeners.get(e);
|
|
878
893
|
if (t) {
|
|
879
|
-
const
|
|
880
|
-
|
|
894
|
+
const s = i.indexOf(t);
|
|
895
|
+
s !== -1 && i.splice(s, 1);
|
|
881
896
|
} else
|
|
882
|
-
|
|
897
|
+
i.length = 0;
|
|
883
898
|
}
|
|
884
899
|
};
|
|
885
900
|
F.CURSOR_SENTINEL = "";
|
|
@@ -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
|
-
const { key: t, ctrlKey:
|
|
902
|
-
if (!
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
917
|
+
const { key: t, ctrlKey: i, altKey: s, shiftKey: n, metaKey: r } = e, o = String(t).toLowerCase(), a = this.keymap[o];
|
|
918
|
+
if (!a)
|
|
919
|
+
return null;
|
|
920
|
+
for (const h of a) {
|
|
921
|
+
const l = h.ctrlKey === void 0 || h.ctrlKey === i, c = h.altKey === void 0 || h.altKey === s, d = h.shiftKey === void 0 || h.shiftKey === n, p = h.metaKey === void 0 || h.metaKey === r;
|
|
922
|
+
if (l && c && d && p)
|
|
906
923
|
return h;
|
|
907
924
|
}
|
|
908
925
|
return null;
|
|
@@ -915,12 +932,12 @@ class J {
|
|
|
915
932
|
const e = {};
|
|
916
933
|
return this.addBinding(e, "f", { ctrlKey: !this.isMac, metaKey: this.isMac }, "find"), this.addBinding(e, "h", { ctrlKey: !this.isMac, metaKey: this.isMac }, "replace"), this.addBinding(e, "f3", {}, "findNext"), this.addBinding(e, "f3", { shiftKey: !0 }, "findPrev"), this.addBinding(e, "g", { ctrlKey: !this.isMac, metaKey: this.isMac }, "findNext"), this.addBinding(e, "[", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "fold"), this.addBinding(e, "]", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "unfold"), this.addBinding(e, "s", { ctrlKey: !0 }, "save"), this.addBinding(e, "s", { metaKey: !0 }, "save"), this.addBinding(e, "z", { ctrlKey: !0 }, "undo"), this.addBinding(e, "z", { metaKey: !0 }, "undo"), this.addBinding(e, "y", { ctrlKey: !0 }, "redo"), this.addBinding(e, "y", { metaKey: !0 }, "redo"), this.addBinding(e, "z", { ctrlKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "z", { metaKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "tab", {}, "insertTab"), this.addBinding(e, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), e;
|
|
917
934
|
}
|
|
918
|
-
addBinding(e, t,
|
|
935
|
+
addBinding(e, t, i, s) {
|
|
919
936
|
const n = t.toLowerCase();
|
|
920
937
|
e[n] || (e[n] = []), e[n].push({
|
|
921
938
|
key: n,
|
|
922
|
-
command:
|
|
923
|
-
...
|
|
939
|
+
command: s,
|
|
940
|
+
...i
|
|
924
941
|
});
|
|
925
942
|
}
|
|
926
943
|
// Public API for customizing keymap
|
|
@@ -929,23 +946,23 @@ class J {
|
|
|
929
946
|
}
|
|
930
947
|
addKeyBinding(e) {
|
|
931
948
|
const t = e.key.toLowerCase();
|
|
932
|
-
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((
|
|
949
|
+
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
|
|
933
950
|
...e,
|
|
934
951
|
key: t
|
|
935
952
|
});
|
|
936
953
|
}
|
|
937
954
|
removeKeyBinding(e, t) {
|
|
938
|
-
const
|
|
939
|
-
t ? this.keymap[
|
|
955
|
+
const i = e.toLowerCase();
|
|
956
|
+
t ? this.keymap[i] && (this.keymap[i] = this.keymap[i].filter((s) => s.command !== t), this.keymap[i].length === 0 && delete this.keymap[i]) : delete this.keymap[i];
|
|
940
957
|
}
|
|
941
958
|
getKeymap() {
|
|
942
959
|
return { ...this.keymap };
|
|
943
960
|
}
|
|
944
961
|
getBindingsForCommand(e) {
|
|
945
962
|
const t = [];
|
|
946
|
-
for (const
|
|
947
|
-
for (const
|
|
948
|
-
|
|
963
|
+
for (const i in this.keymap)
|
|
964
|
+
for (const s of this.keymap[i])
|
|
965
|
+
s.command === e && t.push({ ...s });
|
|
949
966
|
return t;
|
|
950
967
|
}
|
|
951
968
|
getPlatformInfo() {
|
|
@@ -964,13 +981,13 @@ class Y {
|
|
|
964
981
|
}
|
|
965
982
|
setup(e) {
|
|
966
983
|
e.on("change", (t) => {
|
|
967
|
-
const
|
|
984
|
+
const i = {
|
|
968
985
|
changes: t,
|
|
969
986
|
selection: e.getSelection(),
|
|
970
987
|
effects: [],
|
|
971
988
|
annotations: []
|
|
972
989
|
};
|
|
973
|
-
this.transactions.push(
|
|
990
|
+
this.transactions.push(i);
|
|
974
991
|
});
|
|
975
992
|
}
|
|
976
993
|
getTransactions() {
|
|
@@ -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
|
-
`).length, t = Array.from({ length: Math.max(e, 20) }, (
|
|
1003
|
-
this.lineNumbersElement.innerHTML = t.map((
|
|
1021
|
+
`).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
|
|
1022
|
+
this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</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();
|
|
@@ -1085,8 +1105,8 @@ const W = class m {
|
|
|
1085
1105
|
this.findPrev();
|
|
1086
1106
|
}), e.registerCommand("replace", () => {
|
|
1087
1107
|
this.showReplace();
|
|
1088
|
-
}), e.registerCommand("replaceAll", (t,
|
|
1089
|
-
this.replaceAll(t,
|
|
1108
|
+
}), e.registerCommand("replaceAll", (t, i) => {
|
|
1109
|
+
this.replaceAll(t, i);
|
|
1090
1110
|
}), this.editorChangeHandler = () => {
|
|
1091
1111
|
!this.isVisible || !this.currentQuery || this.scheduleLiveRefresh(!0);
|
|
1092
1112
|
}, e.on("change", this.editorChangeHandler);
|
|
@@ -1101,12 +1121,14 @@ 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
|
-
),
|
|
1108
|
-
if (!
|
|
1109
|
-
|
|
1128
|
+
), i = e.closest(".rte-source-editor-modal") || t || e.parentElement;
|
|
1129
|
+
if (!i)
|
|
1130
|
+
return;
|
|
1131
|
+
window.getComputedStyle(i).position === "static" && (i.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..." />
|
|
1112
1134
|
<button class="${m.css.prevButton} ${m.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
|
|
@@ -1133,7 +1155,7 @@ const W = class m {
|
|
|
1133
1155
|
</div>
|
|
1134
1156
|
<input type="text" class="${m.css.replaceInput} ${m.css.inputBase} ${m.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
1135
1157
|
`;
|
|
1136
|
-
const
|
|
1158
|
+
const s = this.searchUI.querySelector(
|
|
1137
1159
|
`.${m.css.findInput}`
|
|
1138
1160
|
), n = this.searchUI.querySelector(
|
|
1139
1161
|
`.${m.css.replaceInput}`
|
|
@@ -1141,41 +1163,41 @@ const W = class m {
|
|
|
1141
1163
|
`.${m.css.prevButton}`
|
|
1142
1164
|
), o = this.searchUI.querySelector(
|
|
1143
1165
|
`.${m.css.nextButton}`
|
|
1144
|
-
),
|
|
1166
|
+
), a = this.searchUI.querySelector(
|
|
1145
1167
|
`.${m.css.closeButton}`
|
|
1146
1168
|
), h = this.searchUI.querySelector(
|
|
1147
1169
|
`.${m.css.status}`
|
|
1148
|
-
),
|
|
1170
|
+
), l = this.searchUI.querySelector(
|
|
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
|
+
), p = this.searchUI.querySelector(
|
|
1155
1177
|
`.${m.css.regex}`
|
|
1156
1178
|
);
|
|
1157
|
-
this.findInput =
|
|
1179
|
+
this.findInput = s, this.replaceInputEl = n, this.statusDiv = h, this.modeDiv = l, this.caseSensitiveInput = c, this.wholeWordInput = d, this.regexInput = p, c.checked = !!this.searchOptions.caseSensitive, d.checked = !!this.searchOptions.wholeWord, p.checked = !!this.searchOptions.regex, s.addEventListener("input", () => {
|
|
1158
1180
|
this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
|
|
1159
|
-
const g =
|
|
1181
|
+
const g = s.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 =
|
|
1166
|
-
const g =
|
|
1186
|
+
const u = () => {
|
|
1187
|
+
this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = d.checked, this.searchOptions.regex = p.checked;
|
|
1188
|
+
const g = s.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), p.addEventListener("change", u), s.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
|
-
g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.replaceAll(
|
|
1173
|
-
}), r.addEventListener("click", () => this.findPrev()), o.addEventListener("click", () => this.findNext()),
|
|
1194
|
+
g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.replaceAll(s.value, n.value) : this.replaceCurrent(s.value, n.value)) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
|
|
1195
|
+
}), r.addEventListener("click", () => this.findPrev()), o.addEventListener("click", () => this.findNext()), a.addEventListener("click", () => this.hideSearch()), i.appendChild(this.searchUI);
|
|
1174
1196
|
}
|
|
1175
1197
|
updateModeHint(e) {
|
|
1176
1198
|
this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
|
|
1177
1199
|
}
|
|
1178
|
-
performSearch(e, t,
|
|
1200
|
+
performSearch(e, t, i) {
|
|
1179
1201
|
if (!this.editor || !e.trim()) {
|
|
1180
1202
|
this.currentQuery = "", this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("");
|
|
1181
1203
|
return;
|
|
@@ -1185,12 +1207,12 @@ const W = class m {
|
|
|
1185
1207
|
return;
|
|
1186
1208
|
}
|
|
1187
1209
|
this.currentQuery = e;
|
|
1188
|
-
const
|
|
1210
|
+
const s = this.currentIndex, n = this.editor.search(e, this.searchOptions);
|
|
1189
1211
|
if (this.currentResults = n, n.length === 0) {
|
|
1190
1212
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
|
|
1191
1213
|
return;
|
|
1192
1214
|
}
|
|
1193
|
-
t &&
|
|
1215
|
+
t && s >= 0 ? this.currentIndex = Math.min(s, n.length - 1) : this.currentIndex = 0, this.updateHighlights(i);
|
|
1194
1216
|
}
|
|
1195
1217
|
findNext() {
|
|
1196
1218
|
if (this.currentResults.length === 0) {
|
|
@@ -1207,26 +1229,29 @@ 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))
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
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;
|
|
1234
|
+
const i = this.currentResults[this.currentIndex];
|
|
1235
|
+
if (!i)
|
|
1236
|
+
return;
|
|
1237
|
+
const s = this.computeReplacementRange(i.range.start, t);
|
|
1238
|
+
if (this.editor.replace(i.range, t), this.config.replaceAndFindNext) {
|
|
1215
1239
|
this.currentQuery = e;
|
|
1216
1240
|
const n = this.editor.search(e, this.searchOptions);
|
|
1217
1241
|
if (this.currentResults = n, n.length === 0) {
|
|
1218
1242
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
|
|
1219
1243
|
return;
|
|
1220
1244
|
}
|
|
1221
|
-
this.currentIndex = this.findNextResultIndexAfter(
|
|
1245
|
+
this.currentIndex = this.findNextResultIndexAfter(s.end, n), this.updateHighlights(!0);
|
|
1222
1246
|
} else
|
|
1223
|
-
this.scrollLogicalRangeIntoView(
|
|
1247
|
+
this.scrollLogicalRangeIntoView(s, !0), this.performSearch(e, !0, !1);
|
|
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())
|
|
1228
|
-
|
|
1229
|
-
|
|
1251
|
+
if (!this.editor || !e.trim())
|
|
1252
|
+
return;
|
|
1253
|
+
const i = this.editor.replaceAll(e, t, this.searchOptions);
|
|
1254
|
+
this.performSearch(e, !1, !1), this.showTransientStatus(`Replaced ${i} occurrence${i === 1 ? "" : "s"}`), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
1230
1255
|
}
|
|
1231
1256
|
updateHighlights(e) {
|
|
1232
1257
|
if (this.clearHighlights(), this.currentResults.length === 0 || this.currentIndex === -1 || !this.editor)
|
|
@@ -1238,19 +1263,21 @@ const W = class m {
|
|
|
1238
1263
|
));
|
|
1239
1264
|
}
|
|
1240
1265
|
navigateToResult(e, t) {
|
|
1241
|
-
if (!this.editor)
|
|
1242
|
-
|
|
1266
|
+
if (!this.editor)
|
|
1267
|
+
return;
|
|
1268
|
+
const i = document.activeElement, s = !!i && (i === this.findInput || i === this.replaceInputEl);
|
|
1243
1269
|
t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
|
|
1244
1270
|
const n = this.editor.getView();
|
|
1245
|
-
t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t &&
|
|
1246
|
-
this.focusWithoutScrolling(
|
|
1271
|
+
t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t && s && i && requestAnimationFrame(() => {
|
|
1272
|
+
this.focusWithoutScrolling(i);
|
|
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 i = CSS;
|
|
1280
|
+
(e = i.highlights) == null || e.delete(this.highlightMatchName), (t = i.highlights) == null || t.delete(this.highlightActiveName);
|
|
1254
1281
|
} catch {
|
|
1255
1282
|
}
|
|
1256
1283
|
}
|
|
@@ -1258,34 +1285,37 @@ const W = class m {
|
|
|
1258
1285
|
this.scrollLogicalRangeIntoView(e.range, !0);
|
|
1259
1286
|
}
|
|
1260
1287
|
scrollLogicalRangeIntoView(e, t) {
|
|
1261
|
-
if (!this.editor)
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1267
|
-
if (a)
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
c.
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1288
|
+
if (!this.editor)
|
|
1289
|
+
return;
|
|
1290
|
+
const i = this.editor.getView().getContentElement(), s = this.editor.getValue(), { lineStarts: n, lines: r } = this.buildLineStarts(s), o = this.buildTextNodeIndex(i);
|
|
1291
|
+
if (o.length === 0)
|
|
1292
|
+
return;
|
|
1293
|
+
const a = this.toDomRange(e, n, r, o);
|
|
1294
|
+
if (!a)
|
|
1295
|
+
return;
|
|
1296
|
+
const h = a.startContainer.nodeType === Node.TEXT_NODE ? a.startContainer.parentElement : a.startContainer, l = this.resolveScrollContainer(i);
|
|
1297
|
+
if (l) {
|
|
1298
|
+
const c = a.getClientRects()[0] || a.getBoundingClientRect(), d = l.getBoundingClientRect(), p = l.scrollTop + (c.top - d.top) - d.height / 2 + c.height / 2, u = 18;
|
|
1299
|
+
let g = t ? p : l.scrollTop, f = l.scrollLeft;
|
|
1300
|
+
const y = l.scrollLeft + (c.left - d.left), k = y + c.width;
|
|
1301
|
+
c.right > d.right - u ? f = k - d.width + u : c.left < d.left + u && (f = Math.max(0, y - u));
|
|
1302
|
+
const v = Math.max(0, l.scrollHeight - l.clientHeight), C = Math.max(0, l.scrollWidth - l.clientWidth);
|
|
1303
|
+
if (g = Math.min(v, Math.max(0, g)), f = Math.min(C, Math.max(0, f)), v === 0 && C === 0) {
|
|
1304
|
+
h == null || h.scrollIntoView({
|
|
1275
1305
|
block: t ? "center" : "nearest",
|
|
1276
1306
|
inline: "nearest",
|
|
1277
1307
|
behavior: "smooth"
|
|
1278
1308
|
});
|
|
1279
1309
|
return;
|
|
1280
1310
|
}
|
|
1281
|
-
(g !==
|
|
1311
|
+
(g !== l.scrollTop || f !== l.scrollLeft) && l.scrollTo({
|
|
1282
1312
|
top: g,
|
|
1283
|
-
left:
|
|
1313
|
+
left: f,
|
|
1284
1314
|
behavior: "smooth"
|
|
1285
1315
|
});
|
|
1286
1316
|
return;
|
|
1287
1317
|
}
|
|
1288
|
-
h
|
|
1318
|
+
h == null || h.scrollIntoView({
|
|
1289
1319
|
block: t ? "center" : "nearest",
|
|
1290
1320
|
inline: "nearest",
|
|
1291
1321
|
behavior: "smooth"
|
|
@@ -1303,61 +1333,67 @@ 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)
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
const
|
|
1339
|
+
if (!t)
|
|
1340
|
+
return;
|
|
1341
|
+
const i = window.getSelection();
|
|
1342
|
+
if (!i || i.rangeCount === 0)
|
|
1343
|
+
return;
|
|
1344
|
+
const s = i.getRangeAt(0).cloneRange(), n = s.getClientRects()[0] || s.getBoundingClientRect();
|
|
1345
|
+
if (!n)
|
|
1346
|
+
return;
|
|
1347
|
+
const r = t.getBoundingClientRect(), o = t.scrollTop + (n.top - r.top) - r.height / 2 + n.height / 2, a = Math.max(0, t.scrollHeight - t.clientHeight), h = Math.min(a, Math.max(0, o));
|
|
1314
1348
|
h !== t.scrollTop && t.scrollTo({
|
|
1315
1349
|
top: h,
|
|
1316
1350
|
behavior: "smooth"
|
|
1317
1351
|
});
|
|
1318
1352
|
}
|
|
1319
1353
|
computeReplacementRange(e, t) {
|
|
1320
|
-
const
|
|
1321
|
-
`),
|
|
1354
|
+
const i = t.replace(/\r\n?/g, `
|
|
1355
|
+
`), s = i.split(`
|
|
1322
1356
|
`);
|
|
1323
1357
|
let n;
|
|
1324
|
-
return
|
|
1358
|
+
return s.length <= 1 ? (n = {
|
|
1325
1359
|
start: e,
|
|
1326
1360
|
end: {
|
|
1327
1361
|
line: e.line,
|
|
1328
|
-
column: e.column +
|
|
1362
|
+
column: e.column + i.length
|
|
1329
1363
|
}
|
|
1330
1364
|
}, this.clampRangeToDocument(n)) : (n = {
|
|
1331
1365
|
start: e,
|
|
1332
1366
|
end: {
|
|
1333
|
-
line: e.line +
|
|
1334
|
-
column:
|
|
1367
|
+
line: e.line + s.length - 1,
|
|
1368
|
+
column: s[s.length - 1].length
|
|
1335
1369
|
}
|
|
1336
1370
|
}, this.clampRangeToDocument(n));
|
|
1337
1371
|
}
|
|
1338
1372
|
findNextResultIndexAfter(e, t) {
|
|
1339
|
-
for (let
|
|
1340
|
-
if (this.comparePositions(t[
|
|
1341
|
-
return
|
|
1373
|
+
for (let i = 0; i < t.length; i++)
|
|
1374
|
+
if (this.comparePositions(t[i].range.start, e) >= 0)
|
|
1375
|
+
return i;
|
|
1342
1376
|
return 0;
|
|
1343
1377
|
}
|
|
1344
1378
|
comparePositions(e, t) {
|
|
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, i;
|
|
1383
|
+
const s = this.editor;
|
|
1384
|
+
if (!s)
|
|
1385
|
+
return e;
|
|
1386
|
+
const n = s.getValue().split(`
|
|
1387
|
+
`), r = Math.max(0, n.length - 1), o = Math.max(0, Math.min(e.start.line, r)), a = Math.max(0, Math.min(e.end.line, r)), h = Math.max(
|
|
1352
1388
|
0,
|
|
1353
|
-
Math.min(e.start.column,
|
|
1389
|
+
Math.min(e.start.column, ((t = n[o]) == null ? void 0 : t.length) || 0)
|
|
1354
1390
|
), l = Math.max(
|
|
1355
1391
|
0,
|
|
1356
|
-
Math.min(e.end.column,
|
|
1392
|
+
Math.min(e.end.column, ((i = n[a]) == null ? void 0 : i.length) || 0)
|
|
1357
1393
|
);
|
|
1358
1394
|
return {
|
|
1359
|
-
start: { line:
|
|
1360
|
-
end: { line:
|
|
1395
|
+
start: { line: o, column: h },
|
|
1396
|
+
end: { line: a, column: l }
|
|
1361
1397
|
};
|
|
1362
1398
|
}
|
|
1363
1399
|
focusWithoutScrolling(e) {
|
|
@@ -1367,35 +1403,36 @@ const W = class m {
|
|
|
1367
1403
|
});
|
|
1368
1404
|
} catch {
|
|
1369
1405
|
const t = [];
|
|
1370
|
-
let
|
|
1371
|
-
for (;
|
|
1372
|
-
this.canScroll(
|
|
1373
|
-
el:
|
|
1374
|
-
top:
|
|
1375
|
-
left:
|
|
1376
|
-
}),
|
|
1377
|
-
const
|
|
1406
|
+
let i = e.parentElement;
|
|
1407
|
+
for (; i; )
|
|
1408
|
+
this.canScroll(i) && t.push({
|
|
1409
|
+
el: i,
|
|
1410
|
+
top: i.scrollTop,
|
|
1411
|
+
left: i.scrollLeft
|
|
1412
|
+
}), i = i.parentElement;
|
|
1413
|
+
const s = window.scrollX, n = window.scrollY;
|
|
1378
1414
|
e.focus();
|
|
1379
1415
|
for (let r = 0; r < t.length; r++) {
|
|
1380
1416
|
const o = t[r];
|
|
1381
1417
|
o.el.scrollTop = o.top, o.el.scrollLeft = o.left;
|
|
1382
1418
|
}
|
|
1383
|
-
window.scrollTo(
|
|
1419
|
+
window.scrollTo(s, n);
|
|
1384
1420
|
}
|
|
1385
1421
|
}
|
|
1386
1422
|
findScrollContainer(e) {
|
|
1387
1423
|
let t = e;
|
|
1388
1424
|
for (; t; ) {
|
|
1389
|
-
const
|
|
1390
|
-
if ((
|
|
1425
|
+
const i = window.getComputedStyle(t).overflowY;
|
|
1426
|
+
if ((i === "auto" || i === "scroll") && t.scrollHeight > t.clientHeight)
|
|
1391
1427
|
return t;
|
|
1392
1428
|
t = t.parentElement;
|
|
1393
1429
|
}
|
|
1394
1430
|
return null;
|
|
1395
1431
|
}
|
|
1396
1432
|
resolveScrollContainer(e) {
|
|
1397
|
-
|
|
1398
|
-
|
|
1433
|
+
var t, i;
|
|
1434
|
+
const s = (t = this.editor) == null ? void 0 : t.getView(), n = ((i = s == null ? void 0 : s.getScrollElement) == null ? void 0 : i.call(s)) || 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;
|
|
@@ -1409,120 +1446,127 @@ const W = class m {
|
|
|
1409
1446
|
applyCustomHighlights() {
|
|
1410
1447
|
if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
|
|
1411
1448
|
return;
|
|
1412
|
-
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts:
|
|
1413
|
-
if (n.length === 0)
|
|
1449
|
+
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines: s } = this.buildLineStarts(t), n = this.buildTextNodeIndex(e);
|
|
1450
|
+
if (n.length === 0)
|
|
1451
|
+
return;
|
|
1414
1452
|
const r = this.buildVisibleDocumentText(n), o = [];
|
|
1415
|
-
let
|
|
1453
|
+
let a = null;
|
|
1416
1454
|
const h = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
|
|
1417
|
-
for (let
|
|
1418
|
-
const c = this.currentResults[
|
|
1455
|
+
for (let l = 0; l < h; l++) {
|
|
1456
|
+
const c = this.currentResults[l], d = this.searchOptions.regex ? c.match || this.currentQuery : this.currentQuery || c.match, p = this.toDomRange(
|
|
1419
1457
|
c.range,
|
|
1420
|
-
s,
|
|
1421
1458
|
i,
|
|
1459
|
+
s,
|
|
1422
1460
|
n,
|
|
1423
1461
|
r,
|
|
1424
|
-
|
|
1462
|
+
d
|
|
1425
1463
|
);
|
|
1426
|
-
|
|
1464
|
+
p && (o.push(p), l === this.currentIndex && (a = p));
|
|
1427
1465
|
}
|
|
1428
1466
|
if (o.length !== 0)
|
|
1429
1467
|
try {
|
|
1430
|
-
const
|
|
1431
|
-
if (!
|
|
1432
|
-
|
|
1468
|
+
const l = CSS, c = window.Highlight;
|
|
1469
|
+
if (!l.highlights || !c)
|
|
1470
|
+
return;
|
|
1471
|
+
l.highlights.set(this.highlightMatchName, new c(...o)), a && l.highlights.set(this.highlightActiveName, new c(a));
|
|
1433
1472
|
} catch {
|
|
1434
1473
|
}
|
|
1435
1474
|
}
|
|
1436
1475
|
buildLineStarts(e) {
|
|
1437
1476
|
const t = e.split(`
|
|
1438
|
-
`),
|
|
1439
|
-
let
|
|
1477
|
+
`), i = new Array(t.length);
|
|
1478
|
+
let s = 0;
|
|
1440
1479
|
for (let n = 0; n < t.length; n++)
|
|
1441
|
-
|
|
1442
|
-
return { lineStarts:
|
|
1480
|
+
i[n] = s, s += t[n].length + 1;
|
|
1481
|
+
return { lineStarts: i, lines: t };
|
|
1443
1482
|
}
|
|
1444
|
-
positionToOffset(e, t,
|
|
1445
|
-
|
|
1446
|
-
|
|
1483
|
+
positionToOffset(e, t, i) {
|
|
1484
|
+
var s;
|
|
1485
|
+
const n = Math.max(0, Math.min(e.line, i.length - 1)), r = Math.max(0, Math.min(e.column, ((s = i[n]) == null ? void 0 : s.length) || 0));
|
|
1486
|
+
return t[n] + r;
|
|
1447
1487
|
}
|
|
1448
1488
|
buildTextNodeIndex(e) {
|
|
1449
|
-
const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null),
|
|
1450
|
-
let
|
|
1489
|
+
const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), i = [];
|
|
1490
|
+
let s = 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 a = r.textContent || "", h = this.buildVisibleToDomMap(a), l = Math.max(0, h.length - 1);
|
|
1496
|
+
l === 0 && a.length === 0 || (i.push({
|
|
1457
1497
|
node: r,
|
|
1458
|
-
start:
|
|
1459
|
-
end:
|
|
1460
|
-
visibleToDom:
|
|
1461
|
-
}),
|
|
1498
|
+
start: s,
|
|
1499
|
+
end: s + l,
|
|
1500
|
+
visibleToDom: h
|
|
1501
|
+
}), s += l);
|
|
1462
1502
|
}
|
|
1463
|
-
return
|
|
1503
|
+
return i;
|
|
1464
1504
|
}
|
|
1465
1505
|
resolveDomPoint(e, t) {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1506
|
+
var i, s;
|
|
1507
|
+
const n = Math.max(0, e);
|
|
1508
|
+
for (let o = 0; o < t.length; o++) {
|
|
1509
|
+
const a = t[o];
|
|
1510
|
+
if (n <= a.end) {
|
|
1511
|
+
const h = Math.max(0, n - a.start), l = a.visibleToDom[h] ?? ((i = a.node.textContent) == null ? void 0 : i.length) ?? 0;
|
|
1471
1512
|
return {
|
|
1472
|
-
node:
|
|
1513
|
+
node: a.node,
|
|
1473
1514
|
offset: l
|
|
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] ?? ((s = r.node.textContent) == null ? void 0 : s.length) ?? 0
|
|
1481
1522
|
} : null;
|
|
1482
1523
|
}
|
|
1483
|
-
toDomRange(e, t,
|
|
1484
|
-
const o = this.positionToOffset(e.start, t,
|
|
1485
|
-
let h = Math.min(o,
|
|
1524
|
+
toDomRange(e, t, i, s, n, r) {
|
|
1525
|
+
const o = this.positionToOffset(e.start, t, i), a = this.positionToOffset(e.end, t, i);
|
|
1526
|
+
let h = Math.min(o, a), l = Math.max(o, a);
|
|
1486
1527
|
if (n && r) {
|
|
1487
|
-
const
|
|
1488
|
-
if (g.length ===
|
|
1489
|
-
const
|
|
1528
|
+
const u = r, g = n.slice(h, l);
|
|
1529
|
+
if (g.length === u.length && g.toLowerCase() !== u.toLowerCase()) {
|
|
1530
|
+
const f = this.findNearestMatchOffset(
|
|
1490
1531
|
n,
|
|
1491
|
-
|
|
1532
|
+
u,
|
|
1492
1533
|
h
|
|
1493
1534
|
);
|
|
1494
|
-
|
|
1535
|
+
f !== -1 && (h = f, l = f + u.length);
|
|
1495
1536
|
}
|
|
1496
1537
|
}
|
|
1497
|
-
const c = this.resolveDomPoint(h,
|
|
1498
|
-
if (!c || !
|
|
1499
|
-
|
|
1538
|
+
const c = this.resolveDomPoint(h, s), d = this.resolveDomPoint(l, s);
|
|
1539
|
+
if (!c || !d)
|
|
1540
|
+
return null;
|
|
1541
|
+
const p = document.createRange();
|
|
1500
1542
|
try {
|
|
1501
|
-
return
|
|
1543
|
+
return p.setStart(c.node, c.offset), p.setEnd(d.node, d.offset), p;
|
|
1502
1544
|
} catch {
|
|
1503
1545
|
return null;
|
|
1504
1546
|
}
|
|
1505
1547
|
}
|
|
1506
1548
|
buildVisibleDocumentText(e) {
|
|
1507
1549
|
let t = "";
|
|
1508
|
-
for (let
|
|
1509
|
-
const
|
|
1510
|
-
for (let n = 0; n <
|
|
1511
|
-
const r =
|
|
1550
|
+
for (let i = 0; i < e.length; i++) {
|
|
1551
|
+
const s = e[i].node.textContent || "";
|
|
1552
|
+
for (let n = 0; n < s.length; n++) {
|
|
1553
|
+
const r = s[n];
|
|
1512
1554
|
this.virtualMarkerRegex.test(r) || (t += r);
|
|
1513
1555
|
}
|
|
1514
1556
|
}
|
|
1515
1557
|
return t;
|
|
1516
1558
|
}
|
|
1517
|
-
findNearestMatchOffset(e, t,
|
|
1518
|
-
const
|
|
1519
|
-
let n = e.toLowerCase().indexOf(
|
|
1520
|
-
if (n === -1)
|
|
1521
|
-
|
|
1559
|
+
findNearestMatchOffset(e, t, i) {
|
|
1560
|
+
const s = t.toLowerCase();
|
|
1561
|
+
let n = e.toLowerCase().indexOf(s);
|
|
1562
|
+
if (n === -1)
|
|
1563
|
+
return -1;
|
|
1564
|
+
let r = n, o = Math.abs(n - i);
|
|
1522
1565
|
for (; n !== -1; ) {
|
|
1523
|
-
const
|
|
1524
|
-
if (
|
|
1525
|
-
|
|
1566
|
+
const a = Math.abs(n - i);
|
|
1567
|
+
if (a < o && (o = a, r = n), a === 0)
|
|
1568
|
+
return n;
|
|
1569
|
+
n = e.toLowerCase().indexOf(s, n + 1);
|
|
1526
1570
|
}
|
|
1527
1571
|
return r;
|
|
1528
1572
|
}
|
|
@@ -1583,15 +1627,16 @@ const W = class m {
|
|
|
1583
1627
|
}
|
|
1584
1628
|
buildVisibleToDomMap(e) {
|
|
1585
1629
|
const t = [0];
|
|
1586
|
-
let
|
|
1587
|
-
for (let
|
|
1588
|
-
const n = e[
|
|
1589
|
-
this.virtualMarkerRegex.test(n) || (
|
|
1630
|
+
let i = 0;
|
|
1631
|
+
for (let s = 0; s < e.length; s++) {
|
|
1632
|
+
const n = e[s];
|
|
1633
|
+
this.virtualMarkerRegex.test(n) || (i += 1, t[i] = s + 1);
|
|
1590
1634
|
}
|
|
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 = {
|
|
@@ -1633,8 +1678,8 @@ W.css = {
|
|
|
1633
1678
|
mode: "search-mode",
|
|
1634
1679
|
modeLayout: "lce-search-mode"
|
|
1635
1680
|
};
|
|
1636
|
-
let
|
|
1637
|
-
class
|
|
1681
|
+
let ie = W;
|
|
1682
|
+
class se {
|
|
1638
1683
|
constructor() {
|
|
1639
1684
|
this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
|
|
1640
1685
|
"(": ")",
|
|
@@ -1656,60 +1701,64 @@ 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
|
-
const
|
|
1663
|
-
if (!
|
|
1664
|
-
|
|
1665
|
-
|
|
1708
|
+
const i = this.getBracketAtPosition(t, e.position);
|
|
1709
|
+
if (!i)
|
|
1710
|
+
return;
|
|
1711
|
+
const s = this.findMatchingBracket(t, i);
|
|
1712
|
+
s && (this.currentMatch = s, this.highlightBrackets(s));
|
|
1666
1713
|
}
|
|
1667
1714
|
getBracketAtPosition(e, t) {
|
|
1668
|
-
const
|
|
1715
|
+
const i = e.split(`
|
|
1669
1716
|
`);
|
|
1670
|
-
if (t.line >=
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1717
|
+
if (t.line >= i.length)
|
|
1718
|
+
return null;
|
|
1719
|
+
const s = i[t.line];
|
|
1720
|
+
if (t.column >= s.length)
|
|
1721
|
+
return null;
|
|
1722
|
+
const n = s[t.column];
|
|
1674
1723
|
return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
|
|
1675
1724
|
}
|
|
1676
1725
|
findMatchingBracket(e, t) {
|
|
1677
|
-
const
|
|
1678
|
-
`),
|
|
1679
|
-
return this.bracketPairs[r] ? this.findClosingBracket(e,
|
|
1726
|
+
const i = e.split(`
|
|
1727
|
+
`), s = t.position.line, n = t.position.column, r = t.char;
|
|
1728
|
+
return this.bracketPairs[r] ? this.findClosingBracket(e, i, s, n, r) : this.reverseBracketPairs[r] ? this.findOpeningBracket(e, i, s, n, r) : null;
|
|
1680
1729
|
}
|
|
1681
|
-
findClosingBracket(e, t,
|
|
1730
|
+
findClosingBracket(e, t, i, s, n) {
|
|
1682
1731
|
const r = this.bracketPairs[n];
|
|
1683
1732
|
let o = 0;
|
|
1684
|
-
for (let
|
|
1685
|
-
const h = t[
|
|
1686
|
-
for (let c =
|
|
1687
|
-
const
|
|
1688
|
-
if (
|
|
1733
|
+
for (let a = i; a < t.length; a++) {
|
|
1734
|
+
const h = t[a], l = a === i ? s : 0;
|
|
1735
|
+
for (let c = l; c < h.length; c++) {
|
|
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
|
-
open: { start: { line:
|
|
1693
|
-
close: { start: { line:
|
|
1741
|
+
open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1742
|
+
close: { start: { line: a, column: c }, end: { line: a, column: c + 1 } },
|
|
1694
1743
|
type: n
|
|
1695
1744
|
};
|
|
1696
1745
|
}
|
|
1697
1746
|
}
|
|
1698
1747
|
return null;
|
|
1699
1748
|
}
|
|
1700
|
-
findOpeningBracket(e, t,
|
|
1749
|
+
findOpeningBracket(e, t, i, s, n) {
|
|
1701
1750
|
const r = this.reverseBracketPairs[n];
|
|
1702
1751
|
let o = 0;
|
|
1703
|
-
for (let
|
|
1704
|
-
const h = t[
|
|
1705
|
-
for (let c =
|
|
1706
|
-
const
|
|
1707
|
-
if (
|
|
1752
|
+
for (let a = i; a >= 0; a--) {
|
|
1753
|
+
const h = t[a], l = a === i ? s : h.length - 1;
|
|
1754
|
+
for (let c = l; c >= 0; c--) {
|
|
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
|
-
open: { start: { line:
|
|
1712
|
-
close: { start: { line:
|
|
1760
|
+
open: { start: { line: a, column: c }, end: { line: a, column: c + 1 } },
|
|
1761
|
+
close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1713
1762
|
type: r
|
|
1714
1763
|
};
|
|
1715
1764
|
}
|
|
@@ -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,22 +1814,24 @@ 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
|
-
`),
|
|
1773
|
-
|
|
1824
|
+
`), i = this.findFoldableLines(t), s = document.createDocumentFragment();
|
|
1825
|
+
i.forEach((n) => {
|
|
1774
1826
|
const r = this.createFoldIndicator(n);
|
|
1775
|
-
|
|
1776
|
-
}), this.foldingUI.appendChild(
|
|
1827
|
+
s.appendChild(r), this.foldIndicators.push(r);
|
|
1828
|
+
}), this.foldingUI.appendChild(s);
|
|
1777
1829
|
}
|
|
1778
1830
|
findFoldableLines(e) {
|
|
1779
1831
|
const t = [];
|
|
1780
|
-
for (let
|
|
1781
|
-
const
|
|
1782
|
-
(
|
|
1832
|
+
for (let i = 0; i < e.length; i++) {
|
|
1833
|
+
const s = e[i].trim();
|
|
1834
|
+
(s.startsWith("{") || s.startsWith("function") || s.startsWith("class") || s.startsWith("if") || s.includes("=>") || s.startsWith("for") || s.startsWith("while") || s.startsWith("try")) && t.push(i);
|
|
1783
1835
|
}
|
|
1784
1836
|
return t;
|
|
1785
1837
|
}
|
|
@@ -1819,7 +1871,7 @@ class re {
|
|
|
1819
1871
|
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
|
|
1820
1872
|
}
|
|
1821
1873
|
setup(e) {
|
|
1822
|
-
this.editor = e, this.registerMode("html", { name: "html", highlight: (t,
|
|
1874
|
+
this.editor = e, this.registerMode("html", { name: "html", highlight: (t, i) => this._highlightHTML(t, i) }), this.registerMode("javascript", { name: "javascript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("typescript", { name: "typescript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("php", { name: "php", highlight: (t, i) => this._highlightPHP(t, i) });
|
|
1823
1875
|
}
|
|
1824
1876
|
// Extension provides methods that can be called by the editor
|
|
1825
1877
|
setTheme(e) {
|
|
@@ -1879,8 +1931,8 @@ class re {
|
|
|
1879
1931
|
}
|
|
1880
1932
|
// Public API: highlight a source string using the chosen mode (or detect html)
|
|
1881
1933
|
highlight(e, t) {
|
|
1882
|
-
const
|
|
1883
|
-
return (this.modes.get(
|
|
1934
|
+
const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
|
|
1935
|
+
return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
|
|
1884
1936
|
}
|
|
1885
1937
|
// Backwards-compatible method
|
|
1886
1938
|
highlightHTML(e) {
|
|
@@ -1893,127 +1945,129 @@ class re {
|
|
|
1893
1945
|
// Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;...
|
|
1894
1946
|
unescapeEntitiesRepeated(e) {
|
|
1895
1947
|
let t = e || "";
|
|
1896
|
-
for (let
|
|
1897
|
-
const
|
|
1898
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t ===
|
|
1948
|
+
for (let i = 0; i < 5; i++) {
|
|
1949
|
+
const s = t;
|
|
1950
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === s)
|
|
1951
|
+
break;
|
|
1899
1952
|
}
|
|
1900
1953
|
return t;
|
|
1901
1954
|
}
|
|
1902
1955
|
_highlightHTML(e, t) {
|
|
1903
|
-
const
|
|
1904
|
-
let n =
|
|
1956
|
+
const i = t, s = (h) => this.escapeHTML(h);
|
|
1957
|
+
let n = s(e);
|
|
1905
1958
|
const r = (h) => {
|
|
1906
|
-
let
|
|
1907
|
-
return
|
|
1908
|
-
const
|
|
1909
|
-
return `<span style="color: ${
|
|
1910
|
-
}),
|
|
1959
|
+
let l = h.replace(/"/g, '"').replace(/'/g, "'");
|
|
1960
|
+
return l = l.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), l = l.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (c, d, p, u, g) => {
|
|
1961
|
+
const f = String(u).trim(), y = s(f);
|
|
1962
|
+
return `<span style="color: ${i.styleProp};">${d}</span>${p}<span style="color: ${i.styleVal};">${y}</span>${g}`;
|
|
1963
|
+
}), l;
|
|
1911
1964
|
}, o = [];
|
|
1912
1965
|
try {
|
|
1913
|
-
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (h,
|
|
1966
|
+
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (h, l, c) => (o.push({ attrs: String(l || ""), inner: String(c || "") }), h));
|
|
1914
1967
|
} catch {
|
|
1915
1968
|
}
|
|
1916
|
-
let
|
|
1917
|
-
return n = n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (h,
|
|
1918
|
-
|
|
1919
|
-
(o[
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1969
|
+
let a = 0;
|
|
1970
|
+
return n = n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (h, l, c, d, p) => {
|
|
1971
|
+
var u, g;
|
|
1972
|
+
const f = ((u = o[a++]) == null ? void 0 : u.inner) ?? this.unescapeEntitiesRepeated(d || "");
|
|
1973
|
+
(((g = o[a - 1]) == null ? void 0 : g.attrs) || c || "").toLowerCase();
|
|
1974
|
+
const y = this._highlightJS(f, i);
|
|
1975
|
+
return `${l}${y}${p}`;
|
|
1976
|
+
}), n = n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (h, l, c, d) => {
|
|
1977
|
+
const p = r(c);
|
|
1978
|
+
return `${l}${p}${d}`;
|
|
1979
|
+
}), n = n.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${i.comment};">$1</span>`), n = n.replace(/(<!DOCTYPE[\s\S]*?>)/i, `<span style="color: ${i.doctype};">$1</span>`), n = n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g, (h, l, c, d, p) => {
|
|
1980
|
+
const u = `<span style="color: ${i.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
|
-
(
|
|
1931
|
-
const C = String(y).toLowerCase(), E = `<span style="color: ${
|
|
1984
|
+
(f, y, k, v) => {
|
|
1985
|
+
const C = String(y).toLowerCase(), E = `<span style="color: ${i.attrName};">${y}</span>`;
|
|
1932
1986
|
let S = v, b = "";
|
|
1933
1987
|
v.startsWith(""") && v.endsWith(""") ? (S = v.slice(6, -6), b = """) : v.startsWith("'") && v.endsWith("'") && (S = v.slice(5, -5), b = "'");
|
|
1934
1988
|
let T = v;
|
|
1935
1989
|
if (C === "style") {
|
|
1936
|
-
const I = S.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (B, N, $, O) => `<span style="color: ${
|
|
1937
|
-
b ? T = `${b}${I}${b}` : T = I, T = `<span style="color: ${
|
|
1990
|
+
const I = S.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (B, N, $, O) => `<span style="color: ${i.styleProp};">${N}</span>:<span style="color: ${i.styleVal};">${$.trim()}</span>${O}`);
|
|
1991
|
+
b ? T = `${b}${I}${b}` : T = I, T = `<span style="color: ${i.attrValue};">${T}</span>`;
|
|
1938
1992
|
} else
|
|
1939
|
-
b && (T = `${b}${S}${b}`), T = `<span style="color: ${
|
|
1993
|
+
b && (T = `${b}${S}${b}`), T = `<span style="color: ${i.attrValue};">${T}</span>`;
|
|
1940
1994
|
return `${E}${k}${T}`;
|
|
1941
1995
|
}
|
|
1942
|
-
), `${
|
|
1996
|
+
), `${l}${u}${g}${p}`;
|
|
1943
1997
|
}), n;
|
|
1944
1998
|
}
|
|
1945
1999
|
_highlightJS(e, t) {
|
|
1946
|
-
const
|
|
1947
|
-
this.escapeHTML(
|
|
1948
|
-
const
|
|
1949
|
-
let
|
|
2000
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
2001
|
+
this.escapeHTML(i);
|
|
2002
|
+
const s = [], n = (d) => {
|
|
2003
|
+
let p = "", u = d;
|
|
1950
2004
|
do
|
|
1951
|
-
|
|
1952
|
-
while (
|
|
1953
|
-
return
|
|
1954
|
-
}, r = (
|
|
1955
|
-
const
|
|
1956
|
-
return
|
|
2005
|
+
p = String.fromCharCode(97 + u % 26) + p, u = Math.floor(u / 26) - 1;
|
|
2006
|
+
while (u >= 0);
|
|
2007
|
+
return p || "a";
|
|
2008
|
+
}, r = (d) => `\0${n(d)}\0`, o = (d) => {
|
|
2009
|
+
const p = s.length;
|
|
2010
|
+
return s.push(d), r(p);
|
|
1957
2011
|
};
|
|
1958
|
-
let
|
|
2012
|
+
let a;
|
|
1959
2013
|
const h = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
1960
|
-
let
|
|
1961
|
-
for (;
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
const
|
|
1965
|
-
/^\/\*/.test(
|
|
2014
|
+
let l = 0, c = "";
|
|
2015
|
+
for (; a = h.exec(i); ) {
|
|
2016
|
+
const d = a.index;
|
|
2017
|
+
l < d && (c += this.escapeHTML(i.slice(l, d)));
|
|
2018
|
+
const p = a[0];
|
|
2019
|
+
/^\/\*/.test(p) || /^\/\//.test(p) ? c += o(`<span style="color: ${t.comment};">${this.escapeHTML(p)}</span>`) : c += o(`<span style="color: ${t.string};">${this.escapeHTML(p)}</span>`), l = h.lastIndex;
|
|
1966
2020
|
}
|
|
1967
|
-
return
|
|
1968
|
-
const g = c[
|
|
1969
|
-
return g === "&" || g === "#" ||
|
|
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
|
|
1972
|
-
for (let g = 0; g <
|
|
1973
|
-
|
|
1974
|
-
return
|
|
2021
|
+
return l < i.length && (c += this.escapeHTML(i.slice(l))), c = c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, p, u) => {
|
|
2022
|
+
const g = c[u - 1] || "", f = c[u + d.length] || "";
|
|
2023
|
+
return g === "&" || g === "#" || f === ";" || f === "#" ? 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, p) => {
|
|
2025
|
+
let u = 0;
|
|
2026
|
+
for (let g = 0; g < p.length; g++)
|
|
2027
|
+
u = u * 26 + (p.charCodeAt(g) - 97 + 1);
|
|
2028
|
+
return u = u - 1, s[u] || "";
|
|
1975
2029
|
});
|
|
1976
2030
|
}
|
|
1977
2031
|
_highlightPHP(e, t) {
|
|
1978
|
-
const
|
|
1979
|
-
let
|
|
1980
|
-
const n = [], r = (
|
|
1981
|
-
let g = "",
|
|
2032
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
2033
|
+
let s = this.escapeHTML(i);
|
|
2034
|
+
const n = [], r = (u) => {
|
|
2035
|
+
let g = "", f = u;
|
|
1982
2036
|
do
|
|
1983
|
-
g = String.fromCharCode(97 +
|
|
1984
|
-
while (
|
|
2037
|
+
g = String.fromCharCode(97 + f % 26) + g, f = Math.floor(f / 26) - 1;
|
|
2038
|
+
while (f >= 0);
|
|
1985
2039
|
return g || "a";
|
|
1986
|
-
}, o = (
|
|
2040
|
+
}, o = (u) => {
|
|
1987
2041
|
const g = n.length;
|
|
1988
|
-
return n.push(
|
|
1989
|
-
},
|
|
1990
|
-
const
|
|
1991
|
-
return
|
|
2042
|
+
return n.push(u), `\0${r(g)}\0`;
|
|
2043
|
+
}, a = (u, g) => {
|
|
2044
|
+
const f = s.indexOf(u);
|
|
2045
|
+
return f === -1 ? !1 : (s = s.slice(0, f) + g + s.slice(f + u.length), !0);
|
|
1992
2046
|
};
|
|
1993
2047
|
let h;
|
|
1994
|
-
const
|
|
1995
|
-
for (; h =
|
|
1996
|
-
const
|
|
1997
|
-
|
|
2048
|
+
const l = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, p = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
2049
|
+
for (; h = l.exec(i); ) {
|
|
2050
|
+
const u = h[0];
|
|
2051
|
+
a(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
1998
2052
|
}
|
|
1999
|
-
for (; h = c.exec(
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2053
|
+
for (; h = c.exec(i); ) {
|
|
2054
|
+
const u = h[0];
|
|
2055
|
+
a(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2002
2056
|
}
|
|
2003
|
-
for (; h =
|
|
2004
|
-
const
|
|
2005
|
-
|
|
2057
|
+
for (; h = d.exec(i); ) {
|
|
2058
|
+
const u = h[0];
|
|
2059
|
+
a(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2006
2060
|
}
|
|
2007
|
-
for (; h =
|
|
2008
|
-
const
|
|
2009
|
-
|
|
2061
|
+
for (; h = p.exec(i); ) {
|
|
2062
|
+
const u = h[0];
|
|
2063
|
+
a(this.escapeHTML(u), o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`));
|
|
2010
2064
|
}
|
|
2011
|
-
return
|
|
2012
|
-
let
|
|
2065
|
+
return s = s.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), s = s.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>`), s = s.replace(/\u0000([a-z]+)\u0000/g, (u, g) => {
|
|
2066
|
+
let f = 0;
|
|
2013
2067
|
for (let y = 0; y < g.length; y++)
|
|
2014
|
-
|
|
2015
|
-
return
|
|
2016
|
-
}),
|
|
2068
|
+
f = f * 26 + (g.charCodeAt(y) - 97 + 1);
|
|
2069
|
+
return f = f - 1, n[f] || "";
|
|
2070
|
+
}), s;
|
|
2017
2071
|
}
|
|
2018
2072
|
// Method to check if content contains syntax that should be highlighted
|
|
2019
2073
|
shouldHighlight(e) {
|
|
@@ -2025,7 +2079,7 @@ class re {
|
|
|
2025
2079
|
}
|
|
2026
2080
|
function oe(w, e) {
|
|
2027
2081
|
const t = { ...e };
|
|
2028
|
-
return t.extensions || (t.extensions = []), t.extensions.some((
|
|
2082
|
+
return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new J(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new Y()), new X(w, t);
|
|
2029
2083
|
}
|
|
2030
2084
|
const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Editor Dialog Styles */
|
|
2031
2085
|
.rte-source-editor-overlay {
|
|
@@ -2424,35 +2478,38 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2424
2478
|
*/
|
|
2425
2479
|
toggleSourceView: () => {
|
|
2426
2480
|
const e = (() => {
|
|
2481
|
+
var o, a, h;
|
|
2427
2482
|
const n = window.getSelection();
|
|
2428
2483
|
if (n && n.anchorNode) {
|
|
2429
|
-
let
|
|
2430
|
-
for (;
|
|
2431
|
-
if (o.classList
|
|
2432
|
-
return
|
|
2433
|
-
|
|
2484
|
+
let l = n.anchorNode instanceof HTMLElement ? n.anchorNode : n.anchorNode.parentElement;
|
|
2485
|
+
for (; l; ) {
|
|
2486
|
+
if ((o = l.classList) != null && o.contains("rte-content"))
|
|
2487
|
+
return l;
|
|
2488
|
+
l = l.parentElement;
|
|
2434
2489
|
}
|
|
2435
2490
|
}
|
|
2436
2491
|
if (document.activeElement) {
|
|
2437
|
-
let
|
|
2438
|
-
if (
|
|
2439
|
-
return
|
|
2440
|
-
for (;
|
|
2441
|
-
if (
|
|
2442
|
-
return
|
|
2443
|
-
const
|
|
2492
|
+
let l = document.activeElement;
|
|
2493
|
+
if ((a = l.classList) != null && a.contains("rte-content"))
|
|
2494
|
+
return l;
|
|
2495
|
+
for (; l && l !== document.body; ) {
|
|
2496
|
+
if ((h = l.classList) != null && h.contains("rte-content"))
|
|
2497
|
+
return l;
|
|
2498
|
+
const c = l.querySelector(
|
|
2444
2499
|
".rte-content"
|
|
2445
2500
|
);
|
|
2446
|
-
if (
|
|
2447
|
-
|
|
2501
|
+
if (c)
|
|
2502
|
+
return c;
|
|
2503
|
+
l = l.parentElement;
|
|
2448
2504
|
}
|
|
2449
2505
|
}
|
|
2450
2506
|
const r = document.querySelector("[data-editora-editor]");
|
|
2451
2507
|
if (r) {
|
|
2452
|
-
const
|
|
2508
|
+
const l = r.querySelector(
|
|
2453
2509
|
".rte-content"
|
|
2454
2510
|
);
|
|
2455
|
-
if (
|
|
2511
|
+
if (l)
|
|
2512
|
+
return l;
|
|
2456
2513
|
}
|
|
2457
2514
|
return document.querySelector(".rte-content");
|
|
2458
2515
|
})();
|
|
@@ -2460,25 +2517,25 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2460
2517
|
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
2461
2518
|
"Editor content area not found. Please click inside the editor first."
|
|
2462
2519
|
), !1;
|
|
2463
|
-
const t = e.innerHTML,
|
|
2520
|
+
const t = e.innerHTML, i = (n) => {
|
|
2464
2521
|
let r = "", o = 0;
|
|
2465
|
-
const
|
|
2466
|
-
for (const
|
|
2467
|
-
|
|
2468
|
-
` + " ".repeat(o *
|
|
2469
|
-
` + " ".repeat(o *
|
|
2470
|
-
` + " ".repeat(o *
|
|
2522
|
+
const a = 2, h = n.split(/(<\/?[a-zA-Z][^>]*>)/);
|
|
2523
|
+
for (const l of h)
|
|
2524
|
+
l.trim() && (l.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), r += `
|
|
2525
|
+
` + " ".repeat(o * a) + l) : l.match(/^<[a-zA-Z]/) && !l.match(/\/>$/) ? (r += `
|
|
2526
|
+
` + " ".repeat(o * a) + l, o++) : l.match(/^<[a-zA-Z].*\/>$/) ? r += `
|
|
2527
|
+
` + " ".repeat(o * a) + l : r += l.trim());
|
|
2471
2528
|
return r.trim();
|
|
2472
2529
|
};
|
|
2473
2530
|
return (() => {
|
|
2474
|
-
const r =
|
|
2475
|
-
let o = null,
|
|
2476
|
-
const
|
|
2477
|
-
|
|
2531
|
+
const r = i(t);
|
|
2532
|
+
let o = null, a = "dark", h = !1, l = !1, c = !1, d = !1;
|
|
2533
|
+
const p = !!e.closest(P) || document.body.matches(P) || document.documentElement.matches(P), u = document.createElement("div");
|
|
2534
|
+
u.className = "rte-source-editor-overlay", p && u.classList.add("rte-theme-dark");
|
|
2478
2535
|
const g = document.createElement("div");
|
|
2479
2536
|
g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
|
|
2480
|
-
const
|
|
2481
|
-
|
|
2537
|
+
const f = document.createElement("div");
|
|
2538
|
+
f.className = "rte-source-editor-header", f.innerHTML = `
|
|
2482
2539
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
2483
2540
|
<div class="rte-source-editor-header-toolbar">
|
|
2484
2541
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -2532,17 +2589,17 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2532
2589
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
2533
2590
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
2534
2591
|
</div>
|
|
2535
|
-
`, g.appendChild(
|
|
2592
|
+
`, g.appendChild(f), g.appendChild(y), g.appendChild(E), u.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
|
|
2536
2593
|
const x = document.createElement("style");
|
|
2537
2594
|
x.id = "rte-source-editor-styles", x.textContent = le, document.head.appendChild(x);
|
|
2538
2595
|
}
|
|
2539
|
-
const S =
|
|
2596
|
+
const S = f.querySelector(
|
|
2540
2597
|
".theme-toggle-btn"
|
|
2541
|
-
), b =
|
|
2598
|
+
), b = f.querySelector(
|
|
2542
2599
|
".readonly-toggle-btn"
|
|
2543
|
-
), T =
|
|
2600
|
+
), T = f.querySelector(
|
|
2544
2601
|
".rte-source-editor-fullscreen-btn"
|
|
2545
|
-
), I =
|
|
2602
|
+
), I = f.querySelector(
|
|
2546
2603
|
".rte-source-editor-close-btn"
|
|
2547
2604
|
), B = E.querySelector(
|
|
2548
2605
|
".rte-source-editor-btn-cancel"
|
|
@@ -2557,13 +2614,15 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2557
2614
|
}, U = (x) => {
|
|
2558
2615
|
c !== x && (c = x, $ && ($.style.display = c ? "inline" : "none"));
|
|
2559
2616
|
}, H = () => {
|
|
2560
|
-
if (!
|
|
2561
|
-
for (
|
|
2562
|
-
O.pop()
|
|
2563
|
-
|
|
2617
|
+
if (!d) {
|
|
2618
|
+
for (d = !0; O.length; ) {
|
|
2619
|
+
const x = O.pop();
|
|
2620
|
+
x == null || x();
|
|
2621
|
+
}
|
|
2622
|
+
o && (o.destroy(), o = null), u.isConnected && u.remove();
|
|
2564
2623
|
}
|
|
2565
2624
|
}, K = () => {
|
|
2566
|
-
|
|
2625
|
+
a = a === "dark" ? "light" : "dark", o == null || o.setTheme(a), S && (S.innerHTML = a === "light" ? `
|
|
2567
2626
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2568
2627
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
2569
2628
|
</svg>
|
|
@@ -2581,7 +2640,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2581
2640
|
</svg>
|
|
2582
2641
|
`);
|
|
2583
2642
|
}, z = () => {
|
|
2584
|
-
h = !h, o
|
|
2643
|
+
h = !h, o == null || o.setReadOnly(h), b && (b.classList.toggle("active", h), b.innerHTML = h ? `
|
|
2585
2644
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2586
2645
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
2587
2646
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -2594,7 +2653,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2594
2653
|
</svg>
|
|
2595
2654
|
`);
|
|
2596
2655
|
}, q = () => {
|
|
2597
|
-
|
|
2656
|
+
l = !l, u.classList.toggle("fullscreen", l), C.style.height = l ? "calc(100vh - 200px)" : "400px", T && (T.innerHTML = l ? `
|
|
2598
2657
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2599
2658
|
<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
2659
|
</svg>
|
|
@@ -2607,7 +2666,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2607
2666
|
c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || H();
|
|
2608
2667
|
}, j = () => {
|
|
2609
2668
|
try {
|
|
2610
|
-
const x = o
|
|
2669
|
+
const x = (o == null ? void 0 : o.getValue()) || "", M = document.createElement("div");
|
|
2611
2670
|
M.innerHTML = x, M.querySelectorAll(
|
|
2612
2671
|
'script, iframe[src^="javascript:"], object, embed'
|
|
2613
2672
|
).forEach((A) => A.remove()), e.innerHTML = M.innerHTML;
|
|
@@ -2631,13 +2690,13 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2631
2690
|
alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", x);
|
|
2632
2691
|
}
|
|
2633
2692
|
};
|
|
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 ===
|
|
2693
|
+
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) => {
|
|
2694
|
+
x.target === u && H();
|
|
2636
2695
|
}), R(document, "keydown", (x) => {
|
|
2637
2696
|
const M = x;
|
|
2638
2697
|
M.key === "Escape" && (M.preventDefault(), H());
|
|
2639
|
-
}), document.body.appendChild(
|
|
2640
|
-
if (!(
|
|
2698
|
+
}), document.body.appendChild(u), requestAnimationFrame(() => {
|
|
2699
|
+
if (!(d || !u.isConnected))
|
|
2641
2700
|
try {
|
|
2642
2701
|
o = oe(C, {
|
|
2643
2702
|
value: r,
|
|
@@ -2647,15 +2706,15 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2647
2706
|
new G(),
|
|
2648
2707
|
new _(),
|
|
2649
2708
|
new ee(),
|
|
2650
|
-
new ie(),
|
|
2651
2709
|
new se(),
|
|
2710
|
+
new ie(),
|
|
2652
2711
|
new ne(),
|
|
2653
2712
|
new re()
|
|
2654
2713
|
]
|
|
2655
2714
|
}), o.on("change", () => {
|
|
2656
|
-
const x = o
|
|
2715
|
+
const x = (o == null ? void 0 : o.getValue()) || "";
|
|
2657
2716
|
U(x !== r);
|
|
2658
|
-
}), requestAnimationFrame(() => o
|
|
2717
|
+
}), requestAnimationFrame(() => o == null ? void 0 : o.focus());
|
|
2659
2718
|
} catch (x) {
|
|
2660
2719
|
console.error("Failed to initialize code editor:", x);
|
|
2661
2720
|
}
|