@editora/core 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/{A11yCheckerPlugin.native-BRdGYMju.mjs → A11yCheckerPlugin.native-58d12bed.mjs} +23 -12
- package/dist/{AnchorPlugin.native-BcYGEtd9.mjs → AnchorPlugin.native-289a112a.mjs} +112 -102
- package/dist/ApprovalWorkflowPlugin.native-449ce66c.mjs +1115 -0
- package/dist/{BackgroundColorPlugin.native-50iAT9xU.mjs → BackgroundColorPlugin.native-8aceb5cc.mjs} +16 -9
- package/dist/{BlockquotePlugin.native-JFmOLsxN.mjs → BlockquotePlugin.native-3541c714.mjs} +3 -2
- package/dist/BlocksLibraryPlugin.native-1cc51e63.mjs +1386 -0
- package/dist/{BoldPlugin.native-BAzzoqU5.mjs → BoldPlugin.native-f9d7f8e4.mjs} +1 -1
- package/dist/{CapitalizationPlugin.native-DOMsh5R7.mjs → CapitalizationPlugin.native-42c135dc.mjs} +3 -2
- package/dist/{ChecklistPlugin.native-nuSSEFNI.mjs → ChecklistPlugin.native-3b397ee9.mjs} +43 -22
- package/dist/CitationsPlugin.native-169fb1e8.mjs +1532 -0
- package/dist/{ClearFormattingPlugin.native-Bq_XcTh2.mjs → ClearFormattingPlugin.native-77baa514.mjs} +11 -6
- package/dist/{CodePlugin.native-DlpTPdkd.mjs → CodePlugin.native-989cf0aa.mjs} +629 -580
- package/dist/{CodeSamplePlugin.native-CgGoH-X4.mjs → CodeSamplePlugin.native-6cc0148e.mjs} +19 -10
- package/dist/{CommentsPlugin.native-DPSqTkiv.mjs → CommentsPlugin.native-03659874.mjs} +55 -28
- package/dist/ConditionalContentPlugin.native-4983143a.mjs +1424 -0
- package/dist/ContentRulesPlugin.native-63ed405b.mjs +1149 -0
- package/dist/DataBindingPlugin.native-427e9d75.mjs +956 -0
- package/dist/{DirectionPlugin.native-CDnbdNyl.mjs → DirectionPlugin.native-4e742f42.mjs} +19 -10
- package/dist/DocSchemaPlugin.native-8e41eda0.mjs +1382 -0
- package/dist/{DocumentManagerPlugin.native-C2cs_1w4.mjs → DocumentManagerPlugin.native-e69895ad.mjs} +4 -4
- package/dist/{EmbedIframePlugin.native-DKJx2OS7.mjs → EmbedIframePlugin.native-55209c87.mjs} +70 -70
- package/dist/{EmojisPlugin.native-CitxxlWX.mjs → EmojisPlugin.native-65c5ac47.mjs} +11 -6
- package/dist/{FontFamilyPlugin.native-j8hMTbg4.mjs → FontFamilyPlugin.native-f9bc255a.mjs} +7 -4
- package/dist/{FontSizePlugin.native-B_jCh7dY.mjs → FontSizePlugin.native-f5647872.mjs} +19 -10
- package/dist/{FootnotePlugin.native-D730OGRm.mjs → FootnotePlugin.native-494657b3.mjs} +77 -39
- package/dist/{FullscreenPlugin.native-ChXyxeNw.mjs → FullscreenPlugin.native-87ce92e9.mjs} +1 -1
- package/dist/{HeadingPlugin.native-DrLYwQnQ.mjs → HeadingPlugin.native-e38c4a16.mjs} +1 -1
- package/dist/{HistoryPlugin.native-TDnVMsEO.mjs → HistoryPlugin.native-92ed4be4.mjs} +43 -22
- package/dist/{IndentPlugin.native-BHixp8sP.mjs → IndentPlugin.native-e4ee902b.mjs} +23 -12
- package/dist/{ItalicPlugin.native-CQjjDyUL.mjs → ItalicPlugin.native-7c95cfbc.mjs} +1 -1
- package/dist/{LineHeightPlugin.native-CM7iXdQj.mjs → LineHeightPlugin.native-5668f78c.mjs} +19 -10
- package/dist/{LinkPlugin.native-DYCIcdTm.mjs → LinkPlugin.native-6df29111.mjs} +9 -5
- package/dist/{ListPlugin.native-V7EZC1lM.mjs → ListPlugin.native-fe2e115a.mjs} +9 -5
- package/dist/{MathPlugin.native-f_mDp8VL.mjs → MathPlugin.native-735bbac2.mjs} +9 -5
- package/dist/{MediaManagerPlugin.native-BiXiK8FC.mjs → MediaManagerPlugin.native-3cf48a00.mjs} +219 -207
- package/dist/MentionPlugin.native-3b1e8c05.mjs +778 -0
- package/dist/{MergeTagPlugin.native-C3eOfEgw.mjs → MergeTagPlugin.native-31cf7d48.mjs} +51 -26
- package/dist/PIIRedactionPlugin.native-7ab10b9f.mjs +1449 -0
- package/dist/{PageBreakPlugin.native-CXdX5fAv.mjs → PageBreakPlugin.native-1794c5fb.mjs} +67 -52
- package/dist/{PreviewPlugin.native-DBvfpmIv.mjs → PreviewPlugin.native-f7b67cc0.mjs} +38 -33
- package/dist/{PrintPlugin.native-7qt5v7L5.mjs → PrintPlugin.native-f6a168c2.mjs} +5 -3
- package/dist/SlashCommandsPlugin.native-8d45e511.mjs +790 -0
- package/dist/SmartPastePlugin.native-a6c5efec.mjs +1447 -0
- package/dist/{SpecialCharactersPlugin.native-CZDato89.mjs → SpecialCharactersPlugin.native-7f06d4ba.mjs} +17 -9
- package/dist/{SpellCheckPlugin.native-BZB9AewP.mjs → SpellCheckPlugin.native-04e20834.mjs} +41 -21
- package/dist/{StrikethroughPlugin.native-0Be7j49s.mjs → StrikethroughPlugin.native-905e9501.mjs} +9 -5
- package/dist/{TablePlugin.native-DrHX-efe.mjs → TablePlugin.native-7d5458c1.mjs} +58 -30
- package/dist/{TemplatePlugin.native-CrpfKRJ8.mjs → TemplatePlugin.native-580f0f63.mjs} +32 -17
- package/dist/{TextAlignmentPlugin.native-sM_1s00t.mjs → TextAlignmentPlugin.native-9357b3ed.mjs} +11 -6
- package/dist/{TextColorPlugin.native-Bwl_bSmc.mjs → TextColorPlugin.native-d53ed459.mjs} +26 -14
- package/dist/TrackChangesPlugin.native-e96da509.mjs +818 -0
- package/dist/TranslationWorkflowPlugin.native-4e711b1e.mjs +1797 -0
- package/dist/{UnderlinePlugin.native-QpIcK4L2.mjs → UnderlinePlugin.native-8080c998.mjs} +1 -1
- package/dist/VersionDiffPlugin.native-5bbeff85.mjs +801 -0
- package/dist/_commonjsHelpers-69d58be2.mjs +31 -0
- package/dist/{anchoredPopover-Bxds0VoB.mjs → anchoredPopover-5cca53ba.mjs} +1 -1
- package/dist/documentManager-8327fb6e.mjs +9166 -0
- package/dist/{editorContainerHelpers-C7kdWnS0.mjs → editorContainerHelpers-69585c07.mjs} +3 -2
- package/dist/editora.min.js +14 -13
- package/dist/editora.umd.js +14 -13
- package/dist/{html2canvas.esm-AYkPY5LS.mjs → html2canvas.esm-c51cb3b9.mjs} +978 -894
- package/dist/index-072ef022.js +11 -0
- package/dist/index-49d31221.mjs +16860 -0
- package/dist/{index-yzU4NdPT.mjs → index-7da30697.mjs} +490 -358
- package/dist/index.cjs.js +1 -1
- package/dist/index.es-b47a189f.mjs +5782 -0
- package/dist/index.esm.js +12 -7
- package/dist/{jspdf.es.min-BJGtOnRT.mjs → jspdf.es.min-780c82db.mjs} +4808 -3784
- package/dist/plugin-loader.js +77 -40
- package/dist/{purify.es-CKpwg8Tk.mjs → purify.es-3bdbcfc5.mjs} +20 -10
- package/dist/style.css +1 -0
- package/dist/webcomponent-core.js +546 -414
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +40 -39
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +484 -315
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +6035 -558
- package/package.json +11 -5
- package/dist/_commonjsHelpers-DOllISpa.mjs +0 -32
- package/dist/core.css +0 -1
- package/dist/documentManager-vQ1VkbUY.mjs +0 -8418
- package/dist/index-BpE6GFbz.js +0 -10
- package/dist/index-BslAFzmv.mjs +0 -16544
- package/dist/index.es-BYD2KEo6.mjs +0 -6666
|
@@ -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), l = t.split(`
|
|
46
46
|
`);
|
|
47
|
-
|
|
47
|
+
l[0] = r + l[0], l[l.length - 1] = l[l.length - 1] + o, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...l);
|
|
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,37 +192,37 @@ 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
|
-
var
|
|
207
|
-
const
|
|
208
|
-
`), s = Math.min(e.line,
|
|
209
|
-
let
|
|
210
|
-
for (let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
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 a = 0; a < s; a++)
|
|
211
|
+
r += i[a].length + 1;
|
|
212
|
+
r += n;
|
|
213
|
+
const o = document.createRange(), l = window.getSelection(), h = this.resolveOffsetToDomPoint(r);
|
|
214
|
+
if (h)
|
|
215
215
|
try {
|
|
216
|
-
|
|
217
|
-
} catch (
|
|
218
|
-
console.warn("Could not set cursor position:",
|
|
216
|
+
o.setStart(h.node, h.offset), o.setEnd(h.node, h.offset), l == null || l.removeAllRanges(), l == null || l.addRange(o), this.ensureCaretVisible();
|
|
217
|
+
} catch (a) {
|
|
218
|
+
console.warn("Could not set cursor position:", a);
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
|
-
const
|
|
221
|
+
const a = this.contentElement.querySelector(
|
|
222
222
|
`[${this.trailingNewlineMarkerAttr}]`
|
|
223
223
|
);
|
|
224
224
|
try {
|
|
225
|
-
|
|
225
|
+
a && a.parentNode === this.contentElement ? o.setStartBefore(a) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), l == null || l.removeAllRanges(), l == null || l.addRange(o), this.ensureCaretVisible();
|
|
226
226
|
} catch (c) {
|
|
227
227
|
console.warn("Could not set fallback cursor position:", c);
|
|
228
228
|
}
|
|
@@ -233,17 +233,17 @@ class Z {
|
|
|
233
233
|
const e = window.getSelection();
|
|
234
234
|
if (!e || e.rangeCount === 0 || e.isCollapsed)
|
|
235
235
|
return;
|
|
236
|
-
const t = e.getRangeAt(0),
|
|
237
|
-
|
|
238
|
-
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(`
|
|
239
239
|
`), n = t.cloneRange();
|
|
240
240
|
n.selectNodeContents(this.contentElement), n.setEnd(t.endContainer, t.endOffset);
|
|
241
241
|
const r = n.toString().replace(/\u200B/g, "").split(`
|
|
242
242
|
`);
|
|
243
243
|
return {
|
|
244
244
|
start: {
|
|
245
|
-
line:
|
|
246
|
-
column:
|
|
245
|
+
line: s.length - 1,
|
|
246
|
+
column: s[s.length - 1].length
|
|
247
247
|
},
|
|
248
248
|
end: {
|
|
249
249
|
line: r.length - 1,
|
|
@@ -254,22 +254,23 @@ class Z {
|
|
|
254
254
|
// Set selection range
|
|
255
255
|
setSelectionRange(e) {
|
|
256
256
|
const t = this.getText().split(`
|
|
257
|
-
`),
|
|
258
|
-
const d = Math.max(0, Math.min(c.line, t.length - 1)),
|
|
257
|
+
`), i = (c) => {
|
|
258
|
+
const d = Math.max(0, Math.min(c.line, t.length - 1)), p = Math.max(
|
|
259
259
|
0,
|
|
260
260
|
Math.min(c.column, t[d] ? t[d].length : 0)
|
|
261
261
|
);
|
|
262
262
|
let u = 0;
|
|
263
263
|
for (let g = 0; g < d; g++)
|
|
264
264
|
u += t[g].length + 1;
|
|
265
|
-
return u +
|
|
266
|
-
},
|
|
267
|
-
if (!
|
|
268
|
-
|
|
265
|
+
return u + p;
|
|
266
|
+
}, s = i(e.start), n = i(e.end), [r, o] = s <= n ? [s, n] : [n, s], l = this.resolveOffsetToDomPoint(r), h = this.resolveOffsetToDomPoint(o);
|
|
267
|
+
if (!l || !h)
|
|
268
|
+
return;
|
|
269
|
+
const a = document.createRange();
|
|
269
270
|
try {
|
|
270
|
-
|
|
271
|
+
a.setStart(l.node, l.offset), a.setEnd(h.node, h.offset);
|
|
271
272
|
const c = window.getSelection();
|
|
272
|
-
c == null || c.removeAllRanges(), c == null || c.addRange(
|
|
273
|
+
c == null || c.removeAllRanges(), c == null || c.addRange(a), this.ensureCaretVisible();
|
|
273
274
|
} catch (c) {
|
|
274
275
|
console.warn("Could not set selection range:", c);
|
|
275
276
|
}
|
|
@@ -288,8 +289,8 @@ class Z {
|
|
|
288
289
|
}
|
|
289
290
|
// Apply theme
|
|
290
291
|
applyTheme(e) {
|
|
291
|
-
Object.entries(e).forEach(([t,
|
|
292
|
-
this.container.style.setProperty(`--${t}`,
|
|
292
|
+
Object.entries(e).forEach(([t, i]) => {
|
|
293
|
+
this.container.style.setProperty(`--${t}`, i);
|
|
293
294
|
});
|
|
294
295
|
}
|
|
295
296
|
// Scroll to position
|
|
@@ -310,7 +311,8 @@ class Z {
|
|
|
310
311
|
this.editorContainer.scrollTop = e;
|
|
311
312
|
}
|
|
312
313
|
syncTrailingNewlineMarker(e) {
|
|
313
|
-
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((
|
|
314
|
+
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e)
|
|
315
|
+
return;
|
|
314
316
|
const t = document.createElement("span");
|
|
315
317
|
t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
|
|
316
318
|
display: inline-block;
|
|
@@ -322,56 +324,60 @@ class Z {
|
|
|
322
324
|
}
|
|
323
325
|
// Ensure caret is visible inside the editor scroll container
|
|
324
326
|
ensureCaretVisible() {
|
|
325
|
-
var
|
|
326
|
-
const
|
|
327
|
-
if (!
|
|
328
|
-
|
|
329
|
-
t.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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);
|
|
334
338
|
}
|
|
335
339
|
// Destroy the view
|
|
336
340
|
destroy() {
|
|
337
341
|
this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
|
|
338
342
|
}
|
|
339
343
|
resolveOffsetToDomPoint(e) {
|
|
340
|
-
var l
|
|
341
|
-
|
|
344
|
+
var l;
|
|
345
|
+
var t;
|
|
346
|
+
const i = Math.max(0, e);
|
|
342
347
|
let s = 0;
|
|
343
|
-
const
|
|
348
|
+
const n = document.createTreeWalker(
|
|
344
349
|
this.contentElement,
|
|
345
350
|
NodeFilter.SHOW_TEXT,
|
|
346
351
|
null
|
|
347
352
|
);
|
|
348
|
-
let
|
|
349
|
-
for (;
|
|
350
|
-
|
|
353
|
+
let r = null, o;
|
|
354
|
+
for (; o = n.nextNode(); ) {
|
|
355
|
+
const h = o.parentElement;
|
|
356
|
+
if (h != null && h.hasAttribute(this.trailingNewlineMarkerAttr))
|
|
351
357
|
continue;
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
if (s + d >=
|
|
355
|
-
const
|
|
358
|
+
r = o;
|
|
359
|
+
const a = o.textContent || "", c = this.buildVisibleToDomMap(a), d = Math.max(0, c.length - 1);
|
|
360
|
+
if (s + d >= i) {
|
|
361
|
+
const p = Math.max(0, i - s), u = (l = c[p]) != null ? l : a.length;
|
|
356
362
|
return {
|
|
357
|
-
node:
|
|
363
|
+
node: o,
|
|
358
364
|
offset: u
|
|
359
365
|
};
|
|
360
366
|
}
|
|
361
367
|
s += d;
|
|
362
368
|
}
|
|
363
|
-
if (
|
|
364
|
-
const
|
|
365
|
-
return { node:
|
|
369
|
+
if (r) {
|
|
370
|
+
const h = ((t = r.textContent) == null ? void 0 : t.length) || 0;
|
|
371
|
+
return { node: r, offset: h };
|
|
366
372
|
}
|
|
367
373
|
return null;
|
|
368
374
|
}
|
|
369
375
|
buildVisibleToDomMap(e) {
|
|
370
376
|
const t = [0];
|
|
371
|
-
let
|
|
372
|
-
for (let
|
|
373
|
-
const n = e[
|
|
374
|
-
this.virtualMarkerRegex.test(n) || (
|
|
377
|
+
let i = 0;
|
|
378
|
+
for (let s = 0; s < e.length; s++) {
|
|
379
|
+
const n = e[s];
|
|
380
|
+
this.virtualMarkerRegex.test(n) || (i += 1, t[i] = s + 1);
|
|
375
381
|
}
|
|
376
382
|
return t;
|
|
377
383
|
}
|
|
@@ -386,7 +392,7 @@ const F = class L {
|
|
|
386
392
|
lineWrapping: !1,
|
|
387
393
|
lineNumbers: !0,
|
|
388
394
|
...t
|
|
389
|
-
}, this.textModel = new D(this.config.value), this.view = new Z(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((
|
|
395
|
+
}, 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();
|
|
390
396
|
}
|
|
391
397
|
// Public accessors for extensions
|
|
392
398
|
getTextModel() {
|
|
@@ -412,21 +418,21 @@ const F = class L {
|
|
|
412
418
|
setupEventHandlers() {
|
|
413
419
|
const e = this.view.getContentElement();
|
|
414
420
|
e.addEventListener("input", () => {
|
|
415
|
-
const t = this.view.getText(),
|
|
416
|
-
if (t !==
|
|
421
|
+
const t = this.view.getText(), i = this.textModel.getText();
|
|
422
|
+
if (t !== i) {
|
|
417
423
|
if (!this.suppressHistory) {
|
|
418
|
-
const
|
|
419
|
-
let
|
|
420
|
-
r && (
|
|
424
|
+
const s = this.getCursor().position, n = this.textModel.positionToOffset(s), r = this.getSelection();
|
|
425
|
+
let o, l;
|
|
426
|
+
r && (o = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: i, cursorOffset: n, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
421
427
|
}
|
|
422
428
|
this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText:
|
|
429
|
+
const s = this.view.getText();
|
|
430
|
+
s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
|
|
431
|
+
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
|
|
426
432
|
}
|
|
427
433
|
}), e.addEventListener("selectionchange", () => {
|
|
428
|
-
const t = this.getCursor(),
|
|
429
|
-
this.emit("cursor", t),
|
|
434
|
+
const t = this.getCursor(), i = this.getSelection();
|
|
435
|
+
this.emit("cursor", t), i && this.emit("selection", i);
|
|
430
436
|
}), e.addEventListener("keydown", (t) => {
|
|
431
437
|
if (this.emit("keydown", t), t.key === "Tab") {
|
|
432
438
|
this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
|
|
@@ -434,33 +440,33 @@ const F = class L {
|
|
|
434
440
|
}
|
|
435
441
|
if (t.key === "Enter") {
|
|
436
442
|
if (!this.config.readOnly) {
|
|
437
|
-
const
|
|
438
|
-
if (
|
|
439
|
-
const
|
|
440
|
-
let
|
|
441
|
-
r && (
|
|
442
|
-
const h = r &&
|
|
443
|
-
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset:
|
|
444
|
-
const
|
|
445
|
-
|
|
443
|
+
const i = window.getSelection();
|
|
444
|
+
if (i && i.rangeCount > 0) {
|
|
445
|
+
const s = this.getCursor().position, n = this.textModel.positionToOffset(s), r = this.getSelection();
|
|
446
|
+
let o, l;
|
|
447
|
+
r && (o = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end));
|
|
448
|
+
const h = r && o !== void 0 && l !== void 0 ? Math.min(o, l) : n;
|
|
449
|
+
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
|
|
450
|
+
const a = i.getRangeAt(0);
|
|
451
|
+
a.deleteContents();
|
|
446
452
|
const c = document.createTextNode(`
|
|
447
453
|
`);
|
|
448
|
-
|
|
454
|
+
a.insertNode(c), a.setStartAfter(c), a.collapse(!0), i.removeAllRanges(), i.addRange(a), this.view.ensureCaretVisible();
|
|
449
455
|
const d = this.view.getText();
|
|
450
456
|
this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
|
|
451
|
-
const
|
|
457
|
+
const p = Math.min(
|
|
452
458
|
h + 1,
|
|
453
459
|
this.textModel.getText().length
|
|
454
460
|
);
|
|
455
461
|
try {
|
|
456
|
-
const u = this.textModel.offsetToPosition(
|
|
462
|
+
const u = this.textModel.offsetToPosition(p);
|
|
457
463
|
this.setCursor(u), this.view.ensureCaretVisible();
|
|
458
464
|
} catch (u) {
|
|
459
465
|
}
|
|
460
466
|
this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
461
467
|
this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
|
|
462
468
|
try {
|
|
463
|
-
const u = this.textModel.offsetToPosition(
|
|
469
|
+
const u = this.textModel.offsetToPosition(p);
|
|
464
470
|
this.setCursor(u), this.view.ensureCaretVisible();
|
|
465
471
|
} catch (u) {
|
|
466
472
|
}
|
|
@@ -471,15 +477,15 @@ const F = class L {
|
|
|
471
477
|
t.preventDefault(), t.stopPropagation();
|
|
472
478
|
return;
|
|
473
479
|
}
|
|
474
|
-
for (const
|
|
475
|
-
if (
|
|
480
|
+
for (const i of this.extensions.values())
|
|
481
|
+
if (i.onKeyDown && i.onKeyDown(t) === !1) {
|
|
476
482
|
t.preventDefault(), t.stopPropagation();
|
|
477
483
|
return;
|
|
478
484
|
}
|
|
479
485
|
}), e.addEventListener("mousedown", (t) => {
|
|
480
486
|
this.emit("mousedown", t);
|
|
481
|
-
for (const
|
|
482
|
-
if (
|
|
487
|
+
for (const i of this.extensions.values())
|
|
488
|
+
if (i.onMouseDown && i.onMouseDown(t) === !1) {
|
|
483
489
|
t.preventDefault(), t.stopPropagation();
|
|
484
490
|
return;
|
|
485
491
|
}
|
|
@@ -506,8 +512,8 @@ const F = class L {
|
|
|
506
512
|
}
|
|
507
513
|
// Emit events to listeners
|
|
508
514
|
emit(e, ...t) {
|
|
509
|
-
const
|
|
510
|
-
|
|
515
|
+
const i = this.eventListeners.get(e);
|
|
516
|
+
i && i.forEach((s) => s(...t));
|
|
511
517
|
}
|
|
512
518
|
// State management
|
|
513
519
|
getValue() {
|
|
@@ -555,12 +561,12 @@ const F = class L {
|
|
|
555
561
|
"editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
|
|
556
562
|
};
|
|
557
563
|
this.view.applyTheme(t);
|
|
558
|
-
const
|
|
559
|
-
if (
|
|
564
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
565
|
+
if (i && typeof i.setTheme == "function")
|
|
560
566
|
try {
|
|
561
|
-
|
|
562
|
-
} catch (
|
|
563
|
-
console.warn("Error applying theme to syntax-highlighting extension",
|
|
567
|
+
i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
|
|
568
|
+
} catch (s) {
|
|
569
|
+
console.warn("Error applying theme to syntax-highlighting extension", s);
|
|
564
570
|
}
|
|
565
571
|
}
|
|
566
572
|
setReadOnly(e) {
|
|
@@ -577,8 +583,8 @@ const F = class L {
|
|
|
577
583
|
t && t.destroy && t.destroy(), this.extensions.delete(e);
|
|
578
584
|
}
|
|
579
585
|
executeCommand(e, ...t) {
|
|
580
|
-
const
|
|
581
|
-
|
|
586
|
+
const i = this.commands.get(e);
|
|
587
|
+
i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
|
|
582
588
|
}
|
|
583
589
|
// Register a command
|
|
584
590
|
registerCommand(e, t) {
|
|
@@ -586,95 +592,96 @@ const F = class L {
|
|
|
586
592
|
}
|
|
587
593
|
// Search & Navigation
|
|
588
594
|
search(e, t = {}) {
|
|
589
|
-
var
|
|
590
|
-
if (!e)
|
|
591
|
-
|
|
595
|
+
var a;
|
|
596
|
+
if (!e)
|
|
597
|
+
return [];
|
|
598
|
+
const i = {
|
|
592
599
|
query: e,
|
|
593
600
|
caseSensitive: !1,
|
|
594
601
|
wholeWord: !1,
|
|
595
602
|
regex: !1,
|
|
596
603
|
...t
|
|
597
|
-
},
|
|
598
|
-
if (
|
|
604
|
+
}, s = [], n = this.textModel.getText(), { normalizedText: r, normalizedToRawOffsets: o } = this.buildSearchTextAndOffsetMap(n), l = i.caseSensitive ? r : r.toLowerCase(), h = i.caseSensitive ? e : e.toLowerCase();
|
|
605
|
+
if (i.regex) {
|
|
599
606
|
let c;
|
|
600
607
|
try {
|
|
601
|
-
c = new RegExp(e,
|
|
602
|
-
} catch (
|
|
608
|
+
c = new RegExp(e, i.caseSensitive ? "g" : "gi");
|
|
609
|
+
} catch (p) {
|
|
603
610
|
return [];
|
|
604
611
|
}
|
|
605
612
|
let d;
|
|
606
613
|
for (; (d = c.exec(r)) !== null; ) {
|
|
607
|
-
const
|
|
608
|
-
if (
|
|
614
|
+
const p = (a = d[0]) != null ? a : "";
|
|
615
|
+
if (p.length === 0) {
|
|
609
616
|
c.lastIndex = d.index + 1;
|
|
610
617
|
continue;
|
|
611
618
|
}
|
|
612
|
-
const u = d.index, g = d.index +
|
|
613
|
-
|
|
614
|
-
|
|
619
|
+
const u = d.index, g = d.index + p.length;
|
|
620
|
+
i.wholeWord && !this.isWholeWordBoundary(r, u, g) || this.pushSearchResultFromOffsets(
|
|
621
|
+
s,
|
|
615
622
|
u,
|
|
616
623
|
g,
|
|
617
624
|
r,
|
|
618
|
-
|
|
625
|
+
o
|
|
619
626
|
);
|
|
620
627
|
}
|
|
621
628
|
} else {
|
|
622
|
-
let c = 0, d =
|
|
629
|
+
let c = 0, d = l.indexOf(h, c);
|
|
623
630
|
for (; d !== -1; ) {
|
|
624
|
-
const
|
|
625
|
-
!
|
|
626
|
-
|
|
631
|
+
const p = d + h.length;
|
|
632
|
+
!i.wholeWord || this.isWholeWordBoundary(r, d, p) ? (this.pushSearchResultFromOffsets(
|
|
633
|
+
s,
|
|
627
634
|
d,
|
|
628
|
-
|
|
635
|
+
p,
|
|
629
636
|
r,
|
|
630
|
-
|
|
631
|
-
), c =
|
|
637
|
+
o
|
|
638
|
+
), c = p) : c = d + 1, d = l.indexOf(h, c);
|
|
632
639
|
}
|
|
633
640
|
}
|
|
634
|
-
return
|
|
641
|
+
return s;
|
|
635
642
|
}
|
|
636
|
-
pushSearchResultFromOffsets(e, t,
|
|
637
|
-
var
|
|
638
|
-
const r = (
|
|
643
|
+
pushSearchResultFromOffsets(e, t, i, s, n) {
|
|
644
|
+
var a, c;
|
|
645
|
+
const r = (a = n[t]) != null ? a : t, o = (c = n[i]) != null ? c : r, l = this.textModel.offsetToPosition(r), h = this.textModel.offsetToPosition(o);
|
|
639
646
|
e.push({
|
|
640
|
-
range: { start:
|
|
641
|
-
match:
|
|
647
|
+
range: { start: l, end: h },
|
|
648
|
+
match: s.substring(t, i)
|
|
642
649
|
});
|
|
643
650
|
}
|
|
644
|
-
isWholeWordBoundary(e, t,
|
|
645
|
-
const
|
|
646
|
-
return !this.isWordChar(
|
|
651
|
+
isWholeWordBoundary(e, t, i) {
|
|
652
|
+
const s = t > 0 ? e[t - 1] : "", n = i < e.length ? e[i] : "";
|
|
653
|
+
return !this.isWordChar(s) && !this.isWordChar(n);
|
|
647
654
|
}
|
|
648
655
|
isWordChar(e) {
|
|
649
656
|
return /^[A-Za-z0-9_]$/.test(e);
|
|
650
657
|
}
|
|
651
658
|
buildSearchTextAndOffsetMap(e) {
|
|
652
|
-
const t = [],
|
|
653
|
-
let
|
|
659
|
+
const t = [], i = [0];
|
|
660
|
+
let s = 0;
|
|
654
661
|
for (let n = 0; n < e.length; n++) {
|
|
655
662
|
const r = e[n];
|
|
656
|
-
r === "" || r === L.CURSOR_SENTINEL || (t.push(r),
|
|
663
|
+
r === "" || r === L.CURSOR_SENTINEL || (t.push(r), s += 1, i[s] = n + 1);
|
|
657
664
|
}
|
|
658
|
-
return s
|
|
665
|
+
return i[s] = e.length, {
|
|
659
666
|
normalizedText: t.join(""),
|
|
660
|
-
normalizedToRawOffsets:
|
|
667
|
+
normalizedToRawOffsets: i
|
|
661
668
|
};
|
|
662
669
|
}
|
|
663
670
|
replace(e, t) {
|
|
664
|
-
const
|
|
671
|
+
const i = this.getValue();
|
|
665
672
|
if (!this.suppressHistory) {
|
|
666
|
-
const n = this.getCursor().position, r = this.textModel.positionToOffset(n),
|
|
667
|
-
let
|
|
668
|
-
|
|
673
|
+
const n = this.getCursor().position, r = this.textModel.positionToOffset(n), o = this.getSelection();
|
|
674
|
+
let l, h;
|
|
675
|
+
o && (l = this.textModel.positionToOffset(o.start), h = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: l, focusOffset: h }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
669
676
|
}
|
|
670
|
-
const
|
|
671
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [
|
|
677
|
+
const s = this.textModel.replaceRange(e, t);
|
|
678
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [s]);
|
|
672
679
|
}
|
|
673
|
-
replaceAll(e, t,
|
|
674
|
-
const
|
|
680
|
+
replaceAll(e, t, i = {}) {
|
|
681
|
+
const s = this.search(e, i);
|
|
675
682
|
let n = 0;
|
|
676
|
-
for (let r =
|
|
677
|
-
this.replace(
|
|
683
|
+
for (let r = s.length - 1; r >= 0; r--)
|
|
684
|
+
this.replace(s[r].range, t), n++;
|
|
678
685
|
return n;
|
|
679
686
|
}
|
|
680
687
|
// Folding (basic implementation)
|
|
@@ -707,32 +714,32 @@ const F = class L {
|
|
|
707
714
|
// and restores it after updating the DOM. Callers that will explicitly set the caret
|
|
708
715
|
// should pass `false` to avoid stomping programmatic cursor changes.
|
|
709
716
|
renderTextWithHighlight(e, t = !0) {
|
|
710
|
-
const
|
|
711
|
-
if (
|
|
717
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
718
|
+
if (i && typeof i.highlightHTML == "function")
|
|
712
719
|
try {
|
|
713
|
-
const
|
|
714
|
-
let n, r,
|
|
715
|
-
if (t ||
|
|
720
|
+
const s = !t && !this.expectingProgrammaticCursor;
|
|
721
|
+
let n, r, o, l;
|
|
722
|
+
if (t || s) {
|
|
716
723
|
n = this.getSelection();
|
|
717
724
|
const d = this.getCollapsedSelectionOffsetInEditor();
|
|
718
725
|
if (d !== void 0)
|
|
719
726
|
r = d;
|
|
720
727
|
else {
|
|
721
|
-
const
|
|
722
|
-
r = this.textModel.positionToOffset(
|
|
728
|
+
const p = this.getCursor().position;
|
|
729
|
+
r = this.textModel.positionToOffset(p);
|
|
723
730
|
}
|
|
724
|
-
n && (
|
|
731
|
+
n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end));
|
|
725
732
|
}
|
|
726
|
-
const h = (t ||
|
|
727
|
-
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(c) : this.view.setHTML(c), this.view.syncTrailingNewlineMarkerForText(e), (t ||
|
|
733
|
+
const h = (t || s) && !n && r !== void 0 && this.hasCollapsedSelectionInEditor(), a = h ? this.insertSentinelAtOffset(e, r) : e, c = i.highlightHTML(a);
|
|
734
|
+
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(c) : this.view.setHTML(c), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
|
|
728
735
|
try {
|
|
729
736
|
if (h && this.restoreCursorFromSentinel()) {
|
|
730
737
|
this.view.ensureCaretVisible();
|
|
731
738
|
return;
|
|
732
739
|
}
|
|
733
|
-
if (n && (
|
|
734
|
-
const d =
|
|
735
|
-
this.view.setSelectionRange({ start:
|
|
740
|
+
if (n && (o !== void 0 || l !== void 0)) {
|
|
741
|
+
const d = o !== void 0 ? o : r, p = l !== void 0 ? l : r, u = Math.min(d, p), g = Math.max(d, p), f = this.textModel.offsetToPosition(u), y = this.textModel.offsetToPosition(g);
|
|
742
|
+
this.view.setSelectionRange({ start: f, end: y });
|
|
736
743
|
} else if (r !== void 0) {
|
|
737
744
|
const d = this.textModel.offsetToPosition(r);
|
|
738
745
|
this.view.setCursorPosition(d);
|
|
@@ -741,8 +748,8 @@ const F = class L {
|
|
|
741
748
|
}
|
|
742
749
|
});
|
|
743
750
|
return;
|
|
744
|
-
} catch (
|
|
745
|
-
console.warn("Syntax highlighting failed, falling back to plain text",
|
|
751
|
+
} catch (s) {
|
|
752
|
+
console.warn("Syntax highlighting failed, falling back to plain text", s);
|
|
746
753
|
}
|
|
747
754
|
this.view.setText(e);
|
|
748
755
|
}
|
|
@@ -757,32 +764,33 @@ const F = class L {
|
|
|
757
764
|
const e = window.getSelection();
|
|
758
765
|
if (!e || e.rangeCount === 0 || !e.isCollapsed)
|
|
759
766
|
return;
|
|
760
|
-
const t = e.getRangeAt(0),
|
|
761
|
-
if (!
|
|
767
|
+
const t = e.getRangeAt(0), i = this.view.getContentElement();
|
|
768
|
+
if (!i.contains(t.commonAncestorContainer))
|
|
762
769
|
return;
|
|
763
|
-
const
|
|
764
|
-
return
|
|
770
|
+
const s = t.cloneRange();
|
|
771
|
+
return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
|
|
765
772
|
}
|
|
766
773
|
stripVirtualMarkers(e) {
|
|
767
774
|
return e.replace(/\u200B/g, "").split(L.CURSOR_SENTINEL).join("");
|
|
768
775
|
}
|
|
769
776
|
insertSentinelAtOffset(e, t) {
|
|
770
|
-
const
|
|
771
|
-
return e.slice(0,
|
|
777
|
+
const i = Math.max(0, Math.min(t, e.length));
|
|
778
|
+
return e.slice(0, i) + L.CURSOR_SENTINEL + e.slice(i);
|
|
772
779
|
}
|
|
773
780
|
restoreCursorFromSentinel() {
|
|
774
|
-
var
|
|
775
|
-
const e = this.view.getContentElement(), t = window.getSelection(),
|
|
776
|
-
let
|
|
777
|
-
for (;
|
|
778
|
-
const
|
|
779
|
-
h !== -1 && (n || (n =
|
|
781
|
+
var o;
|
|
782
|
+
const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
|
|
783
|
+
let s = i.nextNode(), n = null, r = 0;
|
|
784
|
+
for (; s; ) {
|
|
785
|
+
const l = (o = s.textContent) != null ? o : "", h = l.indexOf(L.CURSOR_SENTINEL);
|
|
786
|
+
h !== -1 && (n || (n = s, r = h), s.textContent = l.split(L.CURSOR_SENTINEL).join("")), s = i.nextNode();
|
|
780
787
|
}
|
|
781
|
-
if (!n || !t)
|
|
788
|
+
if (!n || !t)
|
|
789
|
+
return !1;
|
|
782
790
|
try {
|
|
783
|
-
const
|
|
784
|
-
return
|
|
785
|
-
} catch (
|
|
791
|
+
const l = document.createRange();
|
|
792
|
+
return l.setStart(n, r), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
|
|
793
|
+
} catch (l) {
|
|
786
794
|
return !1;
|
|
787
795
|
}
|
|
788
796
|
}
|
|
@@ -796,20 +804,21 @@ const F = class L {
|
|
|
796
804
|
}
|
|
797
805
|
// History: undo/redo
|
|
798
806
|
undo() {
|
|
799
|
-
if (this.undoStack.length === 0)
|
|
807
|
+
if (this.undoStack.length === 0)
|
|
808
|
+
return;
|
|
800
809
|
const e = this.undoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
|
|
801
810
|
this.redoStack.push(t);
|
|
802
811
|
try {
|
|
803
812
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
804
|
-
let
|
|
805
|
-
typeof e == "string" ?
|
|
813
|
+
let i, s;
|
|
814
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
806
815
|
try {
|
|
807
|
-
if (
|
|
816
|
+
if (s != null)
|
|
808
817
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
809
|
-
const n = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
810
|
-
this.setSelection({ start: h, end:
|
|
818
|
+
const n = e.anchorOffset !== void 0 ? e.anchorOffset : s, r = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(n, r), l = Math.max(n, r), h = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
|
|
819
|
+
this.setSelection({ start: h, end: a });
|
|
811
820
|
} else {
|
|
812
|
-
const n = this.textModel.offsetToPosition(
|
|
821
|
+
const n = this.textModel.offsetToPosition(s);
|
|
813
822
|
this.setCursor(n);
|
|
814
823
|
}
|
|
815
824
|
} catch (n) {
|
|
@@ -822,20 +831,21 @@ const F = class L {
|
|
|
822
831
|
}
|
|
823
832
|
}
|
|
824
833
|
redo() {
|
|
825
|
-
if (this.redoStack.length === 0)
|
|
834
|
+
if (this.redoStack.length === 0)
|
|
835
|
+
return;
|
|
826
836
|
const e = this.redoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
|
|
827
837
|
this.undoStack.push(t);
|
|
828
838
|
try {
|
|
829
839
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
830
|
-
let
|
|
831
|
-
typeof e == "string" ?
|
|
840
|
+
let i, s;
|
|
841
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
832
842
|
try {
|
|
833
|
-
if (
|
|
843
|
+
if (s != null)
|
|
834
844
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
835
|
-
const n = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
836
|
-
this.setSelection({ start: h, end:
|
|
845
|
+
const n = e.anchorOffset !== void 0 ? e.anchorOffset : s, r = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(n, r), l = Math.max(n, r), h = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
|
|
846
|
+
this.setSelection({ start: h, end: a });
|
|
837
847
|
} else {
|
|
838
|
-
const n = this.textModel.offsetToPosition(
|
|
848
|
+
const n = this.textModel.offsetToPosition(s);
|
|
839
849
|
this.setCursor(n);
|
|
840
850
|
}
|
|
841
851
|
} catch (n) {
|
|
@@ -849,43 +859,46 @@ const F = class L {
|
|
|
849
859
|
}
|
|
850
860
|
// Insert a tab character or spaces at current cursor
|
|
851
861
|
insertTab() {
|
|
852
|
-
if (this.config.readOnly)
|
|
853
|
-
|
|
862
|
+
if (this.config.readOnly)
|
|
863
|
+
return;
|
|
864
|
+
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);
|
|
854
865
|
if (!this.suppressHistory) {
|
|
855
866
|
const r = this.getSelection();
|
|
856
|
-
let
|
|
857
|
-
r && (
|
|
867
|
+
let o, l;
|
|
868
|
+
r && (o = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: l }), this.redoStack.length = 0;
|
|
858
869
|
}
|
|
859
870
|
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(n), setTimeout(() => {
|
|
860
871
|
this.expectingProgrammaticCursor = !1;
|
|
861
|
-
}, 20), this.emit("change", [
|
|
872
|
+
}, 20), this.emit("change", [s]);
|
|
862
873
|
}
|
|
863
874
|
// Insert a newline at current cursor position
|
|
864
875
|
insertNewLine() {
|
|
865
|
-
if (this.config.readOnly)
|
|
866
|
-
|
|
867
|
-
|
|
876
|
+
if (this.config.readOnly)
|
|
877
|
+
return;
|
|
878
|
+
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
|
|
879
|
+
`), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
|
|
868
880
|
if (!this.suppressHistory) {
|
|
869
881
|
const n = this.getSelection();
|
|
870
|
-
let r,
|
|
871
|
-
n && (r = this.textModel.positionToOffset(n.start),
|
|
882
|
+
let r, o;
|
|
883
|
+
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;
|
|
872
884
|
}
|
|
873
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(
|
|
885
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
|
|
874
886
|
this.expectingProgrammaticCursor = !1;
|
|
875
|
-
}, 20), this.emit("change", [
|
|
887
|
+
}, 20), this.emit("change", [i]);
|
|
876
888
|
}
|
|
877
889
|
// Events
|
|
878
890
|
on(e, t) {
|
|
879
891
|
this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
|
|
880
892
|
}
|
|
881
893
|
off(e, t) {
|
|
882
|
-
if (!this.eventListeners.has(e))
|
|
883
|
-
|
|
894
|
+
if (!this.eventListeners.has(e))
|
|
895
|
+
return;
|
|
896
|
+
const i = this.eventListeners.get(e);
|
|
884
897
|
if (t) {
|
|
885
|
-
const
|
|
886
|
-
|
|
898
|
+
const s = i.indexOf(t);
|
|
899
|
+
s !== -1 && i.splice(s, 1);
|
|
887
900
|
} else
|
|
888
|
-
|
|
901
|
+
i.length = 0;
|
|
889
902
|
}
|
|
890
903
|
};
|
|
891
904
|
F.CURSOR_SENTINEL = "";
|
|
@@ -898,17 +911,19 @@ class J {
|
|
|
898
911
|
this.editor = e;
|
|
899
912
|
}
|
|
900
913
|
handleKeyDown(e) {
|
|
901
|
-
if (!this.editor)
|
|
914
|
+
if (!this.editor)
|
|
915
|
+
return;
|
|
902
916
|
const t = this.findMatchingBinding(e);
|
|
903
917
|
if (t)
|
|
904
918
|
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
|
|
905
919
|
}
|
|
906
920
|
findMatchingBinding(e) {
|
|
907
|
-
const { key: t, ctrlKey:
|
|
908
|
-
if (!
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
921
|
+
const { key: t, ctrlKey: i, altKey: s, shiftKey: n, metaKey: r } = e, o = String(t).toLowerCase(), l = this.keymap[o];
|
|
922
|
+
if (!l)
|
|
923
|
+
return null;
|
|
924
|
+
for (const h of l) {
|
|
925
|
+
const a = 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;
|
|
926
|
+
if (a && c && d && p)
|
|
912
927
|
return h;
|
|
913
928
|
}
|
|
914
929
|
return null;
|
|
@@ -921,12 +936,12 @@ class J {
|
|
|
921
936
|
const e = {};
|
|
922
937
|
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;
|
|
923
938
|
}
|
|
924
|
-
addBinding(e, t,
|
|
939
|
+
addBinding(e, t, i, s) {
|
|
925
940
|
const n = t.toLowerCase();
|
|
926
941
|
e[n] || (e[n] = []), e[n].push({
|
|
927
942
|
key: n,
|
|
928
|
-
command:
|
|
929
|
-
...
|
|
943
|
+
command: s,
|
|
944
|
+
...i
|
|
930
945
|
});
|
|
931
946
|
}
|
|
932
947
|
// Public API for customizing keymap
|
|
@@ -935,23 +950,23 @@ class J {
|
|
|
935
950
|
}
|
|
936
951
|
addKeyBinding(e) {
|
|
937
952
|
const t = e.key.toLowerCase();
|
|
938
|
-
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((
|
|
953
|
+
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
|
|
939
954
|
...e,
|
|
940
955
|
key: t
|
|
941
956
|
});
|
|
942
957
|
}
|
|
943
958
|
removeKeyBinding(e, t) {
|
|
944
|
-
const
|
|
945
|
-
t ? this.keymap[
|
|
959
|
+
const i = e.toLowerCase();
|
|
960
|
+
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];
|
|
946
961
|
}
|
|
947
962
|
getKeymap() {
|
|
948
963
|
return { ...this.keymap };
|
|
949
964
|
}
|
|
950
965
|
getBindingsForCommand(e) {
|
|
951
966
|
const t = [];
|
|
952
|
-
for (const
|
|
953
|
-
for (const
|
|
954
|
-
|
|
967
|
+
for (const i in this.keymap)
|
|
968
|
+
for (const s of this.keymap[i])
|
|
969
|
+
s.command === e && t.push({ ...s });
|
|
955
970
|
return t;
|
|
956
971
|
}
|
|
957
972
|
getPlatformInfo() {
|
|
@@ -970,13 +985,13 @@ class Y {
|
|
|
970
985
|
}
|
|
971
986
|
setup(e) {
|
|
972
987
|
e.on("change", (t) => {
|
|
973
|
-
const
|
|
988
|
+
const i = {
|
|
974
989
|
changes: t,
|
|
975
990
|
selection: e.getSelection(),
|
|
976
991
|
effects: [],
|
|
977
992
|
annotations: []
|
|
978
993
|
};
|
|
979
|
-
this.transactions.push(
|
|
994
|
+
this.transactions.push(i);
|
|
980
995
|
});
|
|
981
996
|
}
|
|
982
997
|
getTransactions() {
|
|
@@ -998,18 +1013,21 @@ class G {
|
|
|
998
1013
|
}), this.updateLineNumbers();
|
|
999
1014
|
}
|
|
1000
1015
|
createLineNumbers() {
|
|
1001
|
-
if (!this.editor)
|
|
1016
|
+
if (!this.editor)
|
|
1017
|
+
return;
|
|
1002
1018
|
const e = this.editor.getView().getLineNumbersElement();
|
|
1003
1019
|
e && (this.lineNumbersElement = e);
|
|
1004
1020
|
}
|
|
1005
1021
|
updateLineNumbers() {
|
|
1006
|
-
if (!this.lineNumbersElement || !this.editor || !this.isEnabled)
|
|
1022
|
+
if (!this.lineNumbersElement || !this.editor || !this.isEnabled)
|
|
1023
|
+
return;
|
|
1007
1024
|
const e = this.editor.getValue().split(`
|
|
1008
|
-
`).length, t = Array.from({ length: Math.max(e, 20) }, (
|
|
1009
|
-
this.lineNumbersElement.innerHTML = t.map((
|
|
1025
|
+
`).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
|
|
1026
|
+
this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("");
|
|
1010
1027
|
}
|
|
1011
1028
|
toggle() {
|
|
1012
|
-
if (!this.editor)
|
|
1029
|
+
if (!this.editor)
|
|
1030
|
+
return;
|
|
1013
1031
|
this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
|
|
1014
1032
|
const e = this.editor.getView().getContentElement();
|
|
1015
1033
|
e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
|
|
@@ -1091,8 +1109,8 @@ const W = class m {
|
|
|
1091
1109
|
this.findPrev();
|
|
1092
1110
|
}), e.registerCommand("replace", () => {
|
|
1093
1111
|
this.showReplace();
|
|
1094
|
-
}), e.registerCommand("replaceAll", (t,
|
|
1095
|
-
this.replaceAll(t,
|
|
1112
|
+
}), e.registerCommand("replaceAll", (t, i) => {
|
|
1113
|
+
this.replaceAll(t, i);
|
|
1096
1114
|
}), this.editorChangeHandler = () => {
|
|
1097
1115
|
!this.isVisible || !this.currentQuery || this.scheduleLiveRefresh(!0);
|
|
1098
1116
|
}, e.on("change", this.editorChangeHandler);
|
|
@@ -1107,12 +1125,14 @@ const W = class m {
|
|
|
1107
1125
|
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();
|
|
1108
1126
|
}
|
|
1109
1127
|
createSearchUI() {
|
|
1110
|
-
if (!this.editor)
|
|
1128
|
+
if (!this.editor)
|
|
1129
|
+
return;
|
|
1111
1130
|
const e = this.editor.getView().getContentElement(), t = e.closest(
|
|
1112
1131
|
this.editorContainerSelector
|
|
1113
|
-
),
|
|
1114
|
-
if (!
|
|
1115
|
-
|
|
1132
|
+
), i = e.closest(".rte-source-editor-modal") || t || e.parentElement;
|
|
1133
|
+
if (!i)
|
|
1134
|
+
return;
|
|
1135
|
+
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 = `
|
|
1116
1136
|
<div class="${m.css.row}">
|
|
1117
1137
|
<input type="text" class="${m.css.findInput} ${m.css.inputBase}" placeholder="Find..." />
|
|
1118
1138
|
<button class="${m.css.prevButton} ${m.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
|
|
@@ -1139,49 +1159,49 @@ const W = class m {
|
|
|
1139
1159
|
</div>
|
|
1140
1160
|
<input type="text" class="${m.css.replaceInput} ${m.css.inputBase} ${m.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
1141
1161
|
`;
|
|
1142
|
-
const
|
|
1162
|
+
const s = this.searchUI.querySelector(
|
|
1143
1163
|
`.${m.css.findInput}`
|
|
1144
1164
|
), n = this.searchUI.querySelector(
|
|
1145
1165
|
`.${m.css.replaceInput}`
|
|
1146
1166
|
), r = this.searchUI.querySelector(
|
|
1147
1167
|
`.${m.css.prevButton}`
|
|
1148
|
-
),
|
|
1168
|
+
), o = this.searchUI.querySelector(
|
|
1149
1169
|
`.${m.css.nextButton}`
|
|
1150
|
-
),
|
|
1170
|
+
), l = this.searchUI.querySelector(
|
|
1151
1171
|
`.${m.css.closeButton}`
|
|
1152
1172
|
), h = this.searchUI.querySelector(
|
|
1153
1173
|
`.${m.css.status}`
|
|
1154
|
-
),
|
|
1174
|
+
), a = this.searchUI.querySelector(
|
|
1155
1175
|
`.${m.css.mode}`
|
|
1156
1176
|
), c = this.searchUI.querySelector(
|
|
1157
1177
|
`.${m.css.caseSensitive}`
|
|
1158
1178
|
), d = this.searchUI.querySelector(
|
|
1159
1179
|
`.${m.css.wholeWord}`
|
|
1160
|
-
),
|
|
1180
|
+
), p = this.searchUI.querySelector(
|
|
1161
1181
|
`.${m.css.regex}`
|
|
1162
1182
|
);
|
|
1163
|
-
this.findInput =
|
|
1183
|
+
this.findInput = s, this.replaceInputEl = n, this.statusDiv = h, this.modeDiv = a, 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", () => {
|
|
1164
1184
|
this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
|
|
1165
|
-
const g =
|
|
1185
|
+
const g = s.value;
|
|
1166
1186
|
this.searchDebounceTimer = setTimeout(() => {
|
|
1167
1187
|
this.performSearch(g, !1, !1);
|
|
1168
1188
|
}, 120);
|
|
1169
1189
|
});
|
|
1170
1190
|
const u = () => {
|
|
1171
|
-
this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = d.checked, this.searchOptions.regex =
|
|
1172
|
-
const g =
|
|
1191
|
+
this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = d.checked, this.searchOptions.regex = p.checked;
|
|
1192
|
+
const g = s.value;
|
|
1173
1193
|
g.trim() ? this.performSearch(g, !1, !1) : this.performSearch("", !1, !1);
|
|
1174
1194
|
};
|
|
1175
|
-
c.addEventListener("change", u), d.addEventListener("change", u),
|
|
1195
|
+
c.addEventListener("change", u), d.addEventListener("change", u), p.addEventListener("change", u), s.addEventListener("keydown", (g) => {
|
|
1176
1196
|
g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.findPrev() : this.findNext()) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
|
|
1177
1197
|
}), n.addEventListener("keydown", (g) => {
|
|
1178
|
-
g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.replaceAll(
|
|
1179
|
-
}), r.addEventListener("click", () => this.findPrev()),
|
|
1198
|
+
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());
|
|
1199
|
+
}), r.addEventListener("click", () => this.findPrev()), o.addEventListener("click", () => this.findNext()), l.addEventListener("click", () => this.hideSearch()), i.appendChild(this.searchUI);
|
|
1180
1200
|
}
|
|
1181
1201
|
updateModeHint(e) {
|
|
1182
1202
|
this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
|
|
1183
1203
|
}
|
|
1184
|
-
performSearch(e, t,
|
|
1204
|
+
performSearch(e, t, i) {
|
|
1185
1205
|
if (!this.editor || !e.trim()) {
|
|
1186
1206
|
this.currentQuery = "", this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("");
|
|
1187
1207
|
return;
|
|
@@ -1191,12 +1211,12 @@ const W = class m {
|
|
|
1191
1211
|
return;
|
|
1192
1212
|
}
|
|
1193
1213
|
this.currentQuery = e;
|
|
1194
|
-
const
|
|
1214
|
+
const s = this.currentIndex, n = this.editor.search(e, this.searchOptions);
|
|
1195
1215
|
if (this.currentResults = n, n.length === 0) {
|
|
1196
1216
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
|
|
1197
1217
|
return;
|
|
1198
1218
|
}
|
|
1199
|
-
t &&
|
|
1219
|
+
t && s >= 0 ? this.currentIndex = Math.min(s, n.length - 1) : this.currentIndex = 0, this.updateHighlights(i);
|
|
1200
1220
|
}
|
|
1201
1221
|
findNext() {
|
|
1202
1222
|
if (this.currentResults.length === 0) {
|
|
@@ -1213,26 +1233,29 @@ const W = class m {
|
|
|
1213
1233
|
this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights(!0);
|
|
1214
1234
|
}
|
|
1215
1235
|
replaceCurrent(e, t) {
|
|
1216
|
-
if (!this.editor || !e.trim() || ((this.currentQuery !== e || this.currentResults.length === 0) && this.performSearch(e, !1, !0), this.currentIndex < 0 || this.currentResults.length === 0))
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1236
|
+
if (!this.editor || !e.trim() || ((this.currentQuery !== e || this.currentResults.length === 0) && this.performSearch(e, !1, !0), this.currentIndex < 0 || this.currentResults.length === 0))
|
|
1237
|
+
return;
|
|
1238
|
+
const i = this.currentResults[this.currentIndex];
|
|
1239
|
+
if (!i)
|
|
1240
|
+
return;
|
|
1241
|
+
const s = this.computeReplacementRange(i.range.start, t);
|
|
1242
|
+
if (this.editor.replace(i.range, t), this.config.replaceAndFindNext) {
|
|
1221
1243
|
this.currentQuery = e;
|
|
1222
1244
|
const n = this.editor.search(e, this.searchOptions);
|
|
1223
1245
|
if (this.currentResults = n, n.length === 0) {
|
|
1224
1246
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
|
|
1225
1247
|
return;
|
|
1226
1248
|
}
|
|
1227
|
-
this.currentIndex = this.findNextResultIndexAfter(
|
|
1249
|
+
this.currentIndex = this.findNextResultIndexAfter(s.end, n), this.updateHighlights(!0);
|
|
1228
1250
|
} else
|
|
1229
|
-
this.scrollLogicalRangeIntoView(
|
|
1251
|
+
this.scrollLogicalRangeIntoView(s, !0), this.performSearch(e, !0, !1);
|
|
1230
1252
|
this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
1231
1253
|
}
|
|
1232
1254
|
replaceAll(e, t) {
|
|
1233
|
-
if (!this.editor || !e.trim())
|
|
1234
|
-
|
|
1235
|
-
|
|
1255
|
+
if (!this.editor || !e.trim())
|
|
1256
|
+
return;
|
|
1257
|
+
const i = this.editor.replaceAll(e, t, this.searchOptions);
|
|
1258
|
+
this.performSearch(e, !1, !1), this.showTransientStatus(`Replaced ${i} occurrence${i === 1 ? "" : "s"}`), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
1236
1259
|
}
|
|
1237
1260
|
updateHighlights(e) {
|
|
1238
1261
|
if (this.clearHighlights(), this.currentResults.length === 0 || this.currentIndex === -1 || !this.editor)
|
|
@@ -1244,40 +1267,44 @@ const W = class m {
|
|
|
1244
1267
|
));
|
|
1245
1268
|
}
|
|
1246
1269
|
navigateToResult(e, t) {
|
|
1247
|
-
if (!this.editor)
|
|
1248
|
-
|
|
1270
|
+
if (!this.editor)
|
|
1271
|
+
return;
|
|
1272
|
+
const i = document.activeElement, s = !!i && (i === this.findInput || i === this.replaceInputEl);
|
|
1249
1273
|
t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
|
|
1250
1274
|
const n = this.editor.getView();
|
|
1251
|
-
t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t &&
|
|
1252
|
-
this.focusWithoutScrolling(
|
|
1275
|
+
t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t && s && i && requestAnimationFrame(() => {
|
|
1276
|
+
this.focusWithoutScrolling(i);
|
|
1253
1277
|
});
|
|
1254
1278
|
}
|
|
1255
1279
|
clearHighlights() {
|
|
1256
1280
|
var e, t;
|
|
1257
1281
|
if (this.hasCustomHighlightSupport)
|
|
1258
1282
|
try {
|
|
1259
|
-
const
|
|
1260
|
-
(e =
|
|
1261
|
-
} catch (
|
|
1283
|
+
const i = CSS;
|
|
1284
|
+
(e = i.highlights) == null || e.delete(this.highlightMatchName), (t = i.highlights) == null || t.delete(this.highlightActiveName);
|
|
1285
|
+
} catch (i) {
|
|
1262
1286
|
}
|
|
1263
1287
|
}
|
|
1264
1288
|
scrollResultIntoView(e) {
|
|
1265
1289
|
this.scrollLogicalRangeIntoView(e.range, !0);
|
|
1266
1290
|
}
|
|
1267
1291
|
scrollLogicalRangeIntoView(e, t) {
|
|
1268
|
-
if (!this.editor)
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
const
|
|
1274
|
-
if (
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
c.
|
|
1279
|
-
|
|
1280
|
-
|
|
1292
|
+
if (!this.editor)
|
|
1293
|
+
return;
|
|
1294
|
+
const i = this.editor.getView().getContentElement(), s = this.editor.getValue(), { lineStarts: n, lines: r } = this.buildLineStarts(s), o = this.buildTextNodeIndex(i);
|
|
1295
|
+
if (o.length === 0)
|
|
1296
|
+
return;
|
|
1297
|
+
const l = this.toDomRange(e, n, r, o);
|
|
1298
|
+
if (!l)
|
|
1299
|
+
return;
|
|
1300
|
+
const h = l.startContainer.nodeType === Node.TEXT_NODE ? l.startContainer.parentElement : l.startContainer, a = this.resolveScrollContainer(i);
|
|
1301
|
+
if (a) {
|
|
1302
|
+
const c = l.getClientRects()[0] || l.getBoundingClientRect(), d = a.getBoundingClientRect(), p = a.scrollTop + (c.top - d.top) - d.height / 2 + c.height / 2, u = 18;
|
|
1303
|
+
let g = t ? p : a.scrollTop, f = a.scrollLeft;
|
|
1304
|
+
const y = a.scrollLeft + (c.left - d.left), C = y + c.width;
|
|
1305
|
+
c.right > d.right - u ? f = C - d.width + u : c.left < d.left + u && (f = Math.max(0, y - u));
|
|
1306
|
+
const v = Math.max(0, a.scrollHeight - a.clientHeight), S = Math.max(0, a.scrollWidth - a.clientWidth);
|
|
1307
|
+
if (g = Math.min(v, Math.max(0, g)), f = Math.min(S, Math.max(0, f)), v === 0 && S === 0) {
|
|
1281
1308
|
h == null || h.scrollIntoView({
|
|
1282
1309
|
block: t ? "center" : "nearest",
|
|
1283
1310
|
inline: "nearest",
|
|
@@ -1285,9 +1312,9 @@ const W = class m {
|
|
|
1285
1312
|
});
|
|
1286
1313
|
return;
|
|
1287
1314
|
}
|
|
1288
|
-
(g !==
|
|
1315
|
+
(g !== a.scrollTop || f !== a.scrollLeft) && a.scrollTo({
|
|
1289
1316
|
top: g,
|
|
1290
|
-
left:
|
|
1317
|
+
left: f,
|
|
1291
1318
|
behavior: "smooth"
|
|
1292
1319
|
});
|
|
1293
1320
|
return;
|
|
@@ -1305,67 +1332,72 @@ const W = class m {
|
|
|
1305
1332
|
const t = e.value.length;
|
|
1306
1333
|
try {
|
|
1307
1334
|
e.setSelectionRange(t, t);
|
|
1308
|
-
} catch (
|
|
1335
|
+
} catch (i) {
|
|
1309
1336
|
}
|
|
1310
1337
|
});
|
|
1311
1338
|
}
|
|
1312
1339
|
centerCurrentSelectionInView() {
|
|
1313
|
-
if (!this.editor)
|
|
1340
|
+
if (!this.editor)
|
|
1341
|
+
return;
|
|
1314
1342
|
const e = this.editor.getView().getContentElement(), t = this.resolveScrollContainer(e);
|
|
1315
|
-
if (!t)
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
const
|
|
1343
|
+
if (!t)
|
|
1344
|
+
return;
|
|
1345
|
+
const i = window.getSelection();
|
|
1346
|
+
if (!i || i.rangeCount === 0)
|
|
1347
|
+
return;
|
|
1348
|
+
const s = i.getRangeAt(0).cloneRange(), n = s.getClientRects()[0] || s.getBoundingClientRect();
|
|
1349
|
+
if (!n)
|
|
1350
|
+
return;
|
|
1351
|
+
const r = t.getBoundingClientRect(), o = t.scrollTop + (n.top - r.top) - r.height / 2 + n.height / 2, l = Math.max(0, t.scrollHeight - t.clientHeight), h = Math.min(l, Math.max(0, o));
|
|
1321
1352
|
h !== t.scrollTop && t.scrollTo({
|
|
1322
1353
|
top: h,
|
|
1323
1354
|
behavior: "smooth"
|
|
1324
1355
|
});
|
|
1325
1356
|
}
|
|
1326
1357
|
computeReplacementRange(e, t) {
|
|
1327
|
-
const
|
|
1328
|
-
`),
|
|
1358
|
+
const i = t.replace(/\r\n?/g, `
|
|
1359
|
+
`), s = i.split(`
|
|
1329
1360
|
`);
|
|
1330
1361
|
let n;
|
|
1331
|
-
return
|
|
1362
|
+
return s.length <= 1 ? (n = {
|
|
1332
1363
|
start: e,
|
|
1333
1364
|
end: {
|
|
1334
1365
|
line: e.line,
|
|
1335
|
-
column: e.column +
|
|
1366
|
+
column: e.column + i.length
|
|
1336
1367
|
}
|
|
1337
1368
|
}, this.clampRangeToDocument(n)) : (n = {
|
|
1338
1369
|
start: e,
|
|
1339
1370
|
end: {
|
|
1340
|
-
line: e.line +
|
|
1341
|
-
column:
|
|
1371
|
+
line: e.line + s.length - 1,
|
|
1372
|
+
column: s[s.length - 1].length
|
|
1342
1373
|
}
|
|
1343
1374
|
}, this.clampRangeToDocument(n));
|
|
1344
1375
|
}
|
|
1345
1376
|
findNextResultIndexAfter(e, t) {
|
|
1346
|
-
for (let
|
|
1347
|
-
if (this.comparePositions(t[
|
|
1348
|
-
return
|
|
1377
|
+
for (let i = 0; i < t.length; i++)
|
|
1378
|
+
if (this.comparePositions(t[i].range.start, e) >= 0)
|
|
1379
|
+
return i;
|
|
1349
1380
|
return 0;
|
|
1350
1381
|
}
|
|
1351
1382
|
comparePositions(e, t) {
|
|
1352
1383
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
1353
1384
|
}
|
|
1354
1385
|
clampRangeToDocument(e) {
|
|
1355
|
-
var
|
|
1356
|
-
const
|
|
1357
|
-
if (!
|
|
1358
|
-
|
|
1359
|
-
|
|
1386
|
+
var t, i;
|
|
1387
|
+
const s = this.editor;
|
|
1388
|
+
if (!s)
|
|
1389
|
+
return e;
|
|
1390
|
+
const n = s.getValue().split(`
|
|
1391
|
+
`), r = Math.max(0, n.length - 1), o = Math.max(0, Math.min(e.start.line, r)), l = Math.max(0, Math.min(e.end.line, r)), h = Math.max(
|
|
1360
1392
|
0,
|
|
1361
|
-
Math.min(e.start.column, ((
|
|
1393
|
+
Math.min(e.start.column, ((t = n[o]) == null ? void 0 : t.length) || 0)
|
|
1362
1394
|
), a = Math.max(
|
|
1363
1395
|
0,
|
|
1364
|
-
Math.min(e.end.column, ((
|
|
1396
|
+
Math.min(e.end.column, ((i = n[l]) == null ? void 0 : i.length) || 0)
|
|
1365
1397
|
);
|
|
1366
1398
|
return {
|
|
1367
|
-
start: { line:
|
|
1368
|
-
end: { line:
|
|
1399
|
+
start: { line: o, column: h },
|
|
1400
|
+
end: { line: l, column: a }
|
|
1369
1401
|
};
|
|
1370
1402
|
}
|
|
1371
1403
|
focusWithoutScrolling(e) {
|
|
@@ -1374,19 +1406,19 @@ const W = class m {
|
|
|
1374
1406
|
preventScroll: !0
|
|
1375
1407
|
});
|
|
1376
1408
|
} catch (t) {
|
|
1377
|
-
const
|
|
1378
|
-
let
|
|
1379
|
-
for (;
|
|
1380
|
-
this.canScroll(
|
|
1381
|
-
el:
|
|
1382
|
-
top:
|
|
1383
|
-
left:
|
|
1384
|
-
}),
|
|
1409
|
+
const i = [];
|
|
1410
|
+
let s = e.parentElement;
|
|
1411
|
+
for (; s; )
|
|
1412
|
+
this.canScroll(s) && i.push({
|
|
1413
|
+
el: s,
|
|
1414
|
+
top: s.scrollTop,
|
|
1415
|
+
left: s.scrollLeft
|
|
1416
|
+
}), s = s.parentElement;
|
|
1385
1417
|
const n = window.scrollX, r = window.scrollY;
|
|
1386
1418
|
e.focus();
|
|
1387
|
-
for (let
|
|
1388
|
-
const
|
|
1389
|
-
|
|
1419
|
+
for (let o = 0; o < i.length; o++) {
|
|
1420
|
+
const l = i[o];
|
|
1421
|
+
l.el.scrollTop = l.top, l.el.scrollLeft = l.left;
|
|
1390
1422
|
}
|
|
1391
1423
|
window.scrollTo(n, r);
|
|
1392
1424
|
}
|
|
@@ -1394,17 +1426,17 @@ const W = class m {
|
|
|
1394
1426
|
findScrollContainer(e) {
|
|
1395
1427
|
let t = e;
|
|
1396
1428
|
for (; t; ) {
|
|
1397
|
-
const
|
|
1398
|
-
if ((
|
|
1429
|
+
const i = window.getComputedStyle(t).overflowY;
|
|
1430
|
+
if ((i === "auto" || i === "scroll") && t.scrollHeight > t.clientHeight)
|
|
1399
1431
|
return t;
|
|
1400
1432
|
t = t.parentElement;
|
|
1401
1433
|
}
|
|
1402
1434
|
return null;
|
|
1403
1435
|
}
|
|
1404
1436
|
resolveScrollContainer(e) {
|
|
1405
|
-
var
|
|
1406
|
-
const
|
|
1407
|
-
return
|
|
1437
|
+
var t, i;
|
|
1438
|
+
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;
|
|
1439
|
+
return n && this.canScroll(n) ? n : this.findScrollContainer(e);
|
|
1408
1440
|
}
|
|
1409
1441
|
canScroll(e) {
|
|
1410
1442
|
return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
|
|
@@ -1418,123 +1450,128 @@ const W = class m {
|
|
|
1418
1450
|
applyCustomHighlights() {
|
|
1419
1451
|
if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
|
|
1420
1452
|
return;
|
|
1421
|
-
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts:
|
|
1422
|
-
if (n.length === 0)
|
|
1423
|
-
|
|
1424
|
-
|
|
1453
|
+
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines: s } = this.buildLineStarts(t), n = this.buildTextNodeIndex(e);
|
|
1454
|
+
if (n.length === 0)
|
|
1455
|
+
return;
|
|
1456
|
+
const r = this.buildVisibleDocumentText(n), o = [];
|
|
1457
|
+
let l = null;
|
|
1425
1458
|
const h = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
|
|
1426
|
-
for (let
|
|
1427
|
-
const c = this.currentResults[
|
|
1459
|
+
for (let a = 0; a < h; a++) {
|
|
1460
|
+
const c = this.currentResults[a], d = this.searchOptions.regex ? c.match || this.currentQuery : this.currentQuery || c.match, p = this.toDomRange(
|
|
1428
1461
|
c.range,
|
|
1429
|
-
s,
|
|
1430
1462
|
i,
|
|
1463
|
+
s,
|
|
1431
1464
|
n,
|
|
1432
1465
|
r,
|
|
1433
1466
|
d
|
|
1434
1467
|
);
|
|
1435
|
-
|
|
1468
|
+
p && (o.push(p), a === this.currentIndex && (l = p));
|
|
1436
1469
|
}
|
|
1437
|
-
if (
|
|
1470
|
+
if (o.length !== 0)
|
|
1438
1471
|
try {
|
|
1439
|
-
const
|
|
1440
|
-
if (!
|
|
1441
|
-
|
|
1442
|
-
|
|
1472
|
+
const a = CSS, c = window.Highlight;
|
|
1473
|
+
if (!a.highlights || !c)
|
|
1474
|
+
return;
|
|
1475
|
+
a.highlights.set(this.highlightMatchName, new c(...o)), l && a.highlights.set(this.highlightActiveName, new c(l));
|
|
1476
|
+
} catch (a) {
|
|
1443
1477
|
}
|
|
1444
1478
|
}
|
|
1445
1479
|
buildLineStarts(e) {
|
|
1446
1480
|
const t = e.split(`
|
|
1447
|
-
`),
|
|
1448
|
-
let
|
|
1481
|
+
`), i = new Array(t.length);
|
|
1482
|
+
let s = 0;
|
|
1449
1483
|
for (let n = 0; n < t.length; n++)
|
|
1450
|
-
|
|
1451
|
-
return { lineStarts:
|
|
1484
|
+
i[n] = s, s += t[n].length + 1;
|
|
1485
|
+
return { lineStarts: i, lines: t };
|
|
1452
1486
|
}
|
|
1453
|
-
positionToOffset(e, t,
|
|
1454
|
-
var
|
|
1455
|
-
const
|
|
1456
|
-
return t[
|
|
1487
|
+
positionToOffset(e, t, i) {
|
|
1488
|
+
var s;
|
|
1489
|
+
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));
|
|
1490
|
+
return t[n] + r;
|
|
1457
1491
|
}
|
|
1458
1492
|
buildTextNodeIndex(e) {
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
let i = 0, n;
|
|
1493
|
+
const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), i = [];
|
|
1494
|
+
let s = 0, n;
|
|
1462
1495
|
for (; n = t.nextNode(); ) {
|
|
1463
|
-
const
|
|
1464
|
-
if (
|
|
1496
|
+
const r = n, o = r.parentElement;
|
|
1497
|
+
if (o != null && o.hasAttribute(this.trailingMarkerAttr))
|
|
1465
1498
|
continue;
|
|
1466
|
-
const
|
|
1467
|
-
|
|
1468
|
-
node:
|
|
1469
|
-
start:
|
|
1470
|
-
end:
|
|
1499
|
+
const l = r.textContent || "", h = this.buildVisibleToDomMap(l), a = Math.max(0, h.length - 1);
|
|
1500
|
+
a === 0 && l.length === 0 || (i.push({
|
|
1501
|
+
node: r,
|
|
1502
|
+
start: s,
|
|
1503
|
+
end: s + a,
|
|
1471
1504
|
visibleToDom: h
|
|
1472
|
-
}),
|
|
1505
|
+
}), s += a);
|
|
1473
1506
|
}
|
|
1474
|
-
return
|
|
1507
|
+
return i;
|
|
1475
1508
|
}
|
|
1476
1509
|
resolveDomPoint(e, t) {
|
|
1477
|
-
var
|
|
1478
|
-
|
|
1510
|
+
var o, l, h, a;
|
|
1511
|
+
var i, s;
|
|
1512
|
+
const n = Math.max(0, e);
|
|
1479
1513
|
for (let c = 0; c < t.length; c++) {
|
|
1480
1514
|
const d = t[c];
|
|
1481
|
-
if (
|
|
1482
|
-
const
|
|
1515
|
+
if (n <= d.end) {
|
|
1516
|
+
const p = Math.max(0, n - d.start), u = (l = (o = d.visibleToDom[p]) != null ? o : (i = d.node.textContent) == null ? void 0 : i.length) != null ? l : 0;
|
|
1483
1517
|
return {
|
|
1484
1518
|
node: d.node,
|
|
1485
1519
|
offset: u
|
|
1486
1520
|
};
|
|
1487
1521
|
}
|
|
1488
1522
|
}
|
|
1489
|
-
const
|
|
1490
|
-
return
|
|
1491
|
-
node:
|
|
1492
|
-
offset: (
|
|
1523
|
+
const r = t[t.length - 1];
|
|
1524
|
+
return r ? {
|
|
1525
|
+
node: r.node,
|
|
1526
|
+
offset: (a = (h = r.visibleToDom[r.visibleToDom.length - 1]) != null ? h : (s = r.node.textContent) == null ? void 0 : s.length) != null ? a : 0
|
|
1493
1527
|
} : null;
|
|
1494
1528
|
}
|
|
1495
|
-
toDomRange(e, t,
|
|
1496
|
-
const
|
|
1497
|
-
let h = Math.min(
|
|
1529
|
+
toDomRange(e, t, i, s, n, r) {
|
|
1530
|
+
const o = this.positionToOffset(e.start, t, i), l = this.positionToOffset(e.end, t, i);
|
|
1531
|
+
let h = Math.min(o, l), a = Math.max(o, l);
|
|
1498
1532
|
if (n && r) {
|
|
1499
|
-
const u = r, g = n.slice(h,
|
|
1533
|
+
const u = r, g = n.slice(h, a);
|
|
1500
1534
|
if (g.length === u.length && g.toLowerCase() !== u.toLowerCase()) {
|
|
1501
|
-
const
|
|
1535
|
+
const f = this.findNearestMatchOffset(
|
|
1502
1536
|
n,
|
|
1503
1537
|
u,
|
|
1504
1538
|
h
|
|
1505
1539
|
);
|
|
1506
|
-
|
|
1540
|
+
f !== -1 && (h = f, a = f + u.length);
|
|
1507
1541
|
}
|
|
1508
1542
|
}
|
|
1509
|
-
const c = this.resolveDomPoint(h,
|
|
1510
|
-
if (!c || !d)
|
|
1511
|
-
|
|
1543
|
+
const c = this.resolveDomPoint(h, s), d = this.resolveDomPoint(a, s);
|
|
1544
|
+
if (!c || !d)
|
|
1545
|
+
return null;
|
|
1546
|
+
const p = document.createRange();
|
|
1512
1547
|
try {
|
|
1513
|
-
return
|
|
1548
|
+
return p.setStart(c.node, c.offset), p.setEnd(d.node, d.offset), p;
|
|
1514
1549
|
} catch (u) {
|
|
1515
1550
|
return null;
|
|
1516
1551
|
}
|
|
1517
1552
|
}
|
|
1518
1553
|
buildVisibleDocumentText(e) {
|
|
1519
1554
|
let t = "";
|
|
1520
|
-
for (let
|
|
1521
|
-
const
|
|
1522
|
-
for (let n = 0; n <
|
|
1523
|
-
const r =
|
|
1555
|
+
for (let i = 0; i < e.length; i++) {
|
|
1556
|
+
const s = e[i].node.textContent || "";
|
|
1557
|
+
for (let n = 0; n < s.length; n++) {
|
|
1558
|
+
const r = s[n];
|
|
1524
1559
|
this.virtualMarkerRegex.test(r) || (t += r);
|
|
1525
1560
|
}
|
|
1526
1561
|
}
|
|
1527
1562
|
return t;
|
|
1528
1563
|
}
|
|
1529
|
-
findNearestMatchOffset(e, t,
|
|
1530
|
-
const
|
|
1531
|
-
let n = e.toLowerCase().indexOf(
|
|
1532
|
-
if (n === -1)
|
|
1533
|
-
|
|
1564
|
+
findNearestMatchOffset(e, t, i) {
|
|
1565
|
+
const s = t.toLowerCase();
|
|
1566
|
+
let n = e.toLowerCase().indexOf(s);
|
|
1567
|
+
if (n === -1)
|
|
1568
|
+
return -1;
|
|
1569
|
+
let r = n, o = Math.abs(n - i);
|
|
1534
1570
|
for (; n !== -1; ) {
|
|
1535
|
-
const
|
|
1536
|
-
if (
|
|
1537
|
-
|
|
1571
|
+
const l = Math.abs(n - i);
|
|
1572
|
+
if (l < o && (o = l, r = n), l === 0)
|
|
1573
|
+
return n;
|
|
1574
|
+
n = e.toLowerCase().indexOf(s, n + 1);
|
|
1538
1575
|
}
|
|
1539
1576
|
return r;
|
|
1540
1577
|
}
|
|
@@ -1595,15 +1632,16 @@ const W = class m {
|
|
|
1595
1632
|
}
|
|
1596
1633
|
buildVisibleToDomMap(e) {
|
|
1597
1634
|
const t = [0];
|
|
1598
|
-
let
|
|
1599
|
-
for (let
|
|
1600
|
-
const n = e[
|
|
1601
|
-
this.virtualMarkerRegex.test(n) || (
|
|
1635
|
+
let i = 0;
|
|
1636
|
+
for (let s = 0; s < e.length; s++) {
|
|
1637
|
+
const n = e[s];
|
|
1638
|
+
this.virtualMarkerRegex.test(n) || (i += 1, t[i] = s + 1);
|
|
1602
1639
|
}
|
|
1603
1640
|
return t;
|
|
1604
1641
|
}
|
|
1605
1642
|
ensureHighlightStyles() {
|
|
1606
|
-
if (document.getElementById(this.highlightStyleId))
|
|
1643
|
+
if (document.getElementById(this.highlightStyleId))
|
|
1644
|
+
return;
|
|
1607
1645
|
const e = document.createElement("style");
|
|
1608
1646
|
e.id = this.highlightStyleId, e.textContent = `
|
|
1609
1647
|
::highlight(${this.highlightMatchName}) {
|
|
@@ -1645,8 +1683,8 @@ W.css = {
|
|
|
1645
1683
|
mode: "search-mode",
|
|
1646
1684
|
modeLayout: "lce-search-mode"
|
|
1647
1685
|
};
|
|
1648
|
-
let
|
|
1649
|
-
class
|
|
1686
|
+
let ie = W;
|
|
1687
|
+
class se {
|
|
1650
1688
|
constructor() {
|
|
1651
1689
|
this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
|
|
1652
1690
|
"(": ")",
|
|
@@ -1668,60 +1706,64 @@ class ie {
|
|
|
1668
1706
|
});
|
|
1669
1707
|
}
|
|
1670
1708
|
updateBracketMatching() {
|
|
1671
|
-
if (!this.editor)
|
|
1709
|
+
if (!this.editor)
|
|
1710
|
+
return;
|
|
1672
1711
|
const e = this.editor.getCursor(), t = this.editor.getValue();
|
|
1673
1712
|
this.clearBracketHighlighting();
|
|
1674
|
-
const
|
|
1675
|
-
if (!
|
|
1676
|
-
|
|
1677
|
-
|
|
1713
|
+
const i = this.getBracketAtPosition(t, e.position);
|
|
1714
|
+
if (!i)
|
|
1715
|
+
return;
|
|
1716
|
+
const s = this.findMatchingBracket(t, i);
|
|
1717
|
+
s && (this.currentMatch = s, this.highlightBrackets(s));
|
|
1678
1718
|
}
|
|
1679
1719
|
getBracketAtPosition(e, t) {
|
|
1680
|
-
const
|
|
1720
|
+
const i = e.split(`
|
|
1681
1721
|
`);
|
|
1682
|
-
if (t.line >=
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1722
|
+
if (t.line >= i.length)
|
|
1723
|
+
return null;
|
|
1724
|
+
const s = i[t.line];
|
|
1725
|
+
if (t.column >= s.length)
|
|
1726
|
+
return null;
|
|
1727
|
+
const n = s[t.column];
|
|
1686
1728
|
return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
|
|
1687
1729
|
}
|
|
1688
1730
|
findMatchingBracket(e, t) {
|
|
1689
|
-
const
|
|
1690
|
-
`),
|
|
1691
|
-
return this.bracketPairs[r] ? this.findClosingBracket(e,
|
|
1731
|
+
const i = e.split(`
|
|
1732
|
+
`), s = t.position.line, n = t.position.column, r = t.char;
|
|
1733
|
+
return this.bracketPairs[r] ? this.findClosingBracket(e, i, s, n, r) : this.reverseBracketPairs[r] ? this.findOpeningBracket(e, i, s, n, r) : null;
|
|
1692
1734
|
}
|
|
1693
|
-
findClosingBracket(e, t,
|
|
1735
|
+
findClosingBracket(e, t, i, s, n) {
|
|
1694
1736
|
const r = this.bracketPairs[n];
|
|
1695
|
-
let
|
|
1696
|
-
for (let
|
|
1697
|
-
const h = t[
|
|
1698
|
-
for (let c =
|
|
1737
|
+
let o = 0;
|
|
1738
|
+
for (let l = i; l < t.length; l++) {
|
|
1739
|
+
const h = t[l], a = l === i ? s : 0;
|
|
1740
|
+
for (let c = a; c < h.length; c++) {
|
|
1699
1741
|
const d = h[c];
|
|
1700
1742
|
if (d === n)
|
|
1701
|
-
|
|
1702
|
-
else if (d === r && (
|
|
1743
|
+
o++;
|
|
1744
|
+
else if (d === r && (o--, o === 0))
|
|
1703
1745
|
return {
|
|
1704
|
-
open: { start: { line:
|
|
1705
|
-
close: { start: { line:
|
|
1746
|
+
open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1747
|
+
close: { start: { line: l, column: c }, end: { line: l, column: c + 1 } },
|
|
1706
1748
|
type: n
|
|
1707
1749
|
};
|
|
1708
1750
|
}
|
|
1709
1751
|
}
|
|
1710
1752
|
return null;
|
|
1711
1753
|
}
|
|
1712
|
-
findOpeningBracket(e, t,
|
|
1754
|
+
findOpeningBracket(e, t, i, s, n) {
|
|
1713
1755
|
const r = this.reverseBracketPairs[n];
|
|
1714
|
-
let
|
|
1715
|
-
for (let
|
|
1716
|
-
const h = t[
|
|
1717
|
-
for (let c =
|
|
1756
|
+
let o = 0;
|
|
1757
|
+
for (let l = i; l >= 0; l--) {
|
|
1758
|
+
const h = t[l], a = l === i ? s : h.length - 1;
|
|
1759
|
+
for (let c = a; c >= 0; c--) {
|
|
1718
1760
|
const d = h[c];
|
|
1719
1761
|
if (d === n)
|
|
1720
|
-
|
|
1721
|
-
else if (d === r && (
|
|
1762
|
+
o++;
|
|
1763
|
+
else if (d === r && (o--, o === 0))
|
|
1722
1764
|
return {
|
|
1723
|
-
open: { start: { line:
|
|
1724
|
-
close: { start: { line:
|
|
1765
|
+
open: { start: { line: l, column: c }, end: { line: l, column: c + 1 } },
|
|
1766
|
+
close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1725
1767
|
type: r
|
|
1726
1768
|
};
|
|
1727
1769
|
}
|
|
@@ -1758,7 +1800,8 @@ class ne {
|
|
|
1758
1800
|
}, e.on("change", this.changeHandler), this.createFoldingUI(), this.scheduleFoldIndicatorUpdate();
|
|
1759
1801
|
}
|
|
1760
1802
|
createFoldingUI() {
|
|
1761
|
-
if (!this.editor)
|
|
1803
|
+
if (!this.editor)
|
|
1804
|
+
return;
|
|
1762
1805
|
const e = this.editor.getView().getContentElement(), t = e.closest(".rte-source-editor-modal") || e.parentElement;
|
|
1763
1806
|
t && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
|
|
1764
1807
|
position: absolute;
|
|
@@ -1776,22 +1819,24 @@ class ne {
|
|
|
1776
1819
|
}));
|
|
1777
1820
|
}
|
|
1778
1821
|
updateFoldIndicators() {
|
|
1779
|
-
if (!this.editor || !this.foldingUI)
|
|
1822
|
+
if (!this.editor || !this.foldingUI)
|
|
1823
|
+
return;
|
|
1780
1824
|
const e = this.editor.getValue();
|
|
1781
|
-
if (e === this.lastSnapshot)
|
|
1825
|
+
if (e === this.lastSnapshot)
|
|
1826
|
+
return;
|
|
1782
1827
|
this.lastSnapshot = e, this.foldingUI.innerHTML = "", this.foldIndicators = [];
|
|
1783
1828
|
const t = e.split(`
|
|
1784
|
-
`),
|
|
1785
|
-
|
|
1829
|
+
`), i = this.findFoldableLines(t), s = document.createDocumentFragment();
|
|
1830
|
+
i.forEach((n) => {
|
|
1786
1831
|
const r = this.createFoldIndicator(n);
|
|
1787
|
-
|
|
1788
|
-
}), this.foldingUI.appendChild(
|
|
1832
|
+
s.appendChild(r), this.foldIndicators.push(r);
|
|
1833
|
+
}), this.foldingUI.appendChild(s);
|
|
1789
1834
|
}
|
|
1790
1835
|
findFoldableLines(e) {
|
|
1791
1836
|
const t = [];
|
|
1792
|
-
for (let
|
|
1793
|
-
const
|
|
1794
|
-
(
|
|
1837
|
+
for (let i = 0; i < e.length; i++) {
|
|
1838
|
+
const s = e[i].trim();
|
|
1839
|
+
(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);
|
|
1795
1840
|
}
|
|
1796
1841
|
return t;
|
|
1797
1842
|
}
|
|
@@ -1831,7 +1876,7 @@ class re {
|
|
|
1831
1876
|
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
|
|
1832
1877
|
}
|
|
1833
1878
|
setup(e) {
|
|
1834
|
-
this.editor = e, this.registerMode("html", { name: "html", highlight: (t,
|
|
1879
|
+
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) });
|
|
1835
1880
|
}
|
|
1836
1881
|
// Extension provides methods that can be called by the editor
|
|
1837
1882
|
setTheme(e) {
|
|
@@ -1891,8 +1936,8 @@ class re {
|
|
|
1891
1936
|
}
|
|
1892
1937
|
// Public API: highlight a source string using the chosen mode (or detect html)
|
|
1893
1938
|
highlight(e, t) {
|
|
1894
|
-
const
|
|
1895
|
-
return (this.modes.get(
|
|
1939
|
+
const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
|
|
1940
|
+
return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
|
|
1896
1941
|
}
|
|
1897
1942
|
// Backwards-compatible method
|
|
1898
1943
|
highlightHTML(e) {
|
|
@@ -1905,128 +1950,130 @@ class re {
|
|
|
1905
1950
|
// Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;...
|
|
1906
1951
|
unescapeEntitiesRepeated(e) {
|
|
1907
1952
|
let t = e || "";
|
|
1908
|
-
for (let
|
|
1909
|
-
const
|
|
1910
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t ===
|
|
1953
|
+
for (let i = 0; i < 5; i++) {
|
|
1954
|
+
const s = t;
|
|
1955
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === s)
|
|
1956
|
+
break;
|
|
1911
1957
|
}
|
|
1912
1958
|
return t;
|
|
1913
1959
|
}
|
|
1914
1960
|
_highlightHTML(e, t) {
|
|
1915
|
-
const
|
|
1916
|
-
let n =
|
|
1961
|
+
const i = t, s = (h) => this.escapeHTML(h);
|
|
1962
|
+
let n = s(e);
|
|
1917
1963
|
const r = (h) => {
|
|
1918
|
-
let
|
|
1919
|
-
return
|
|
1920
|
-
const
|
|
1921
|
-
return `<span style="color: ${
|
|
1922
|
-
}),
|
|
1923
|
-
},
|
|
1964
|
+
let a = h.replace(/"/g, '"').replace(/'/g, "'");
|
|
1965
|
+
return a = a.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), a = a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (c, d, p, u, g) => {
|
|
1966
|
+
const f = String(u).trim(), y = s(f);
|
|
1967
|
+
return `<span style="color: ${i.styleProp};">${d}</span>${p}<span style="color: ${i.styleVal};">${y}</span>${g}`;
|
|
1968
|
+
}), a;
|
|
1969
|
+
}, o = [];
|
|
1924
1970
|
try {
|
|
1925
|
-
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (h,
|
|
1971
|
+
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (h, a, c) => (o.push({ attrs: String(a || ""), inner: String(c || "") }), h));
|
|
1926
1972
|
} catch (h) {
|
|
1927
1973
|
}
|
|
1928
|
-
let
|
|
1929
|
-
return n = n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (h,
|
|
1930
|
-
var
|
|
1931
|
-
|
|
1932
|
-
(
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1974
|
+
let l = 0;
|
|
1975
|
+
return n = n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (h, a, c, d, p) => {
|
|
1976
|
+
var C;
|
|
1977
|
+
var u, g;
|
|
1978
|
+
const f = (C = (u = o[l++]) == null ? void 0 : u.inner) != null ? C : this.unescapeEntitiesRepeated(d || "");
|
|
1979
|
+
(((g = o[l - 1]) == null ? void 0 : g.attrs) || c || "").toLowerCase();
|
|
1980
|
+
const y = this._highlightJS(f, i);
|
|
1981
|
+
return `${a}${y}${p}`;
|
|
1982
|
+
}), n = n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (h, a, c, d) => {
|
|
1983
|
+
const p = r(c);
|
|
1984
|
+
return `${a}${p}${d}`;
|
|
1985
|
+
}), 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, a, c, d, p) => {
|
|
1986
|
+
const u = `<span style="color: ${i.tag};">${c}</span>`;
|
|
1940
1987
|
let g = d;
|
|
1941
1988
|
return g = g.replace(
|
|
1942
1989
|
/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,
|
|
1943
|
-
(
|
|
1944
|
-
const S = String(y).toLowerCase(), E = `<span style="color: ${
|
|
1990
|
+
(f, y, C, v) => {
|
|
1991
|
+
const S = String(y).toLowerCase(), E = `<span style="color: ${i.attrName};">${y}</span>`;
|
|
1945
1992
|
let M = v, b = "";
|
|
1946
1993
|
v.startsWith(""") && v.endsWith(""") ? (M = v.slice(6, -6), b = """) : v.startsWith("'") && v.endsWith("'") && (M = v.slice(5, -5), b = "'");
|
|
1947
1994
|
let T = v;
|
|
1948
1995
|
if (S === "style") {
|
|
1949
|
-
const I = M.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (B, $, A, O) => `<span style="color: ${
|
|
1950
|
-
b ? T = `${b}${I}${b}` : T = I, T = `<span style="color: ${
|
|
1996
|
+
const I = M.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (B, $, A, O) => `<span style="color: ${i.styleProp};">${$}</span>:<span style="color: ${i.styleVal};">${A.trim()}</span>${O}`);
|
|
1997
|
+
b ? T = `${b}${I}${b}` : T = I, T = `<span style="color: ${i.attrValue};">${T}</span>`;
|
|
1951
1998
|
} else
|
|
1952
|
-
b && (T = `${b}${M}${b}`), T = `<span style="color: ${
|
|
1999
|
+
b && (T = `${b}${M}${b}`), T = `<span style="color: ${i.attrValue};">${T}</span>`;
|
|
1953
2000
|
return `${E}${C}${T}`;
|
|
1954
2001
|
}
|
|
1955
|
-
), `${
|
|
2002
|
+
), `${a}${u}${g}${p}`;
|
|
1956
2003
|
}), n;
|
|
1957
2004
|
}
|
|
1958
2005
|
_highlightJS(e, t) {
|
|
1959
|
-
const
|
|
1960
|
-
this.escapeHTML(
|
|
1961
|
-
const
|
|
1962
|
-
let
|
|
2006
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
2007
|
+
this.escapeHTML(i);
|
|
2008
|
+
const s = [], n = (d) => {
|
|
2009
|
+
let p = "", u = d;
|
|
1963
2010
|
do
|
|
1964
|
-
|
|
2011
|
+
p = String.fromCharCode(97 + u % 26) + p, u = Math.floor(u / 26) - 1;
|
|
1965
2012
|
while (u >= 0);
|
|
1966
|
-
return
|
|
1967
|
-
}, r = (d) => `\0${n(d)}\0`,
|
|
1968
|
-
const
|
|
1969
|
-
return
|
|
2013
|
+
return p || "a";
|
|
2014
|
+
}, r = (d) => `\0${n(d)}\0`, o = (d) => {
|
|
2015
|
+
const p = s.length;
|
|
2016
|
+
return s.push(d), r(p);
|
|
1970
2017
|
};
|
|
1971
|
-
let
|
|
2018
|
+
let l;
|
|
1972
2019
|
const h = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
1973
|
-
let
|
|
1974
|
-
for (;
|
|
1975
|
-
const d =
|
|
1976
|
-
|
|
1977
|
-
const
|
|
1978
|
-
/^\/\*/.test(
|
|
2020
|
+
let a = 0, c = "";
|
|
2021
|
+
for (; l = h.exec(i); ) {
|
|
2022
|
+
const d = l.index;
|
|
2023
|
+
a < d && (c += this.escapeHTML(i.slice(a, d)));
|
|
2024
|
+
const p = l[0];
|
|
2025
|
+
/^\/\*/.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>`), a = h.lastIndex;
|
|
1979
2026
|
}
|
|
1980
|
-
return
|
|
1981
|
-
const g = c[u - 1] || "",
|
|
1982
|
-
return g === "&" || g === "#" ||
|
|
1983
|
-
}), 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,
|
|
2027
|
+
return a < i.length && (c += this.escapeHTML(i.slice(a))), c = c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, p, u) => {
|
|
2028
|
+
const g = c[u - 1] || "", f = c[u + d.length] || "";
|
|
2029
|
+
return g === "&" || g === "#" || f === ";" || f === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
|
|
2030
|
+
}), 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) => {
|
|
1984
2031
|
let u = 0;
|
|
1985
|
-
for (let g = 0; g <
|
|
1986
|
-
u = u * 26 + (
|
|
1987
|
-
return u = u - 1,
|
|
2032
|
+
for (let g = 0; g < p.length; g++)
|
|
2033
|
+
u = u * 26 + (p.charCodeAt(g) - 97 + 1);
|
|
2034
|
+
return u = u - 1, s[u] || "";
|
|
1988
2035
|
});
|
|
1989
2036
|
}
|
|
1990
2037
|
_highlightPHP(e, t) {
|
|
1991
|
-
const
|
|
1992
|
-
let
|
|
2038
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
2039
|
+
let s = this.escapeHTML(i);
|
|
1993
2040
|
const n = [], r = (u) => {
|
|
1994
|
-
let g = "",
|
|
2041
|
+
let g = "", f = u;
|
|
1995
2042
|
do
|
|
1996
|
-
g = String.fromCharCode(97 +
|
|
1997
|
-
while (
|
|
2043
|
+
g = String.fromCharCode(97 + f % 26) + g, f = Math.floor(f / 26) - 1;
|
|
2044
|
+
while (f >= 0);
|
|
1998
2045
|
return g || "a";
|
|
1999
|
-
},
|
|
2046
|
+
}, o = (u) => {
|
|
2000
2047
|
const g = n.length;
|
|
2001
2048
|
return n.push(u), `\0${r(g)}\0`;
|
|
2002
|
-
},
|
|
2003
|
-
const
|
|
2004
|
-
return
|
|
2049
|
+
}, l = (u, g) => {
|
|
2050
|
+
const f = s.indexOf(u);
|
|
2051
|
+
return f === -1 ? !1 : (s = s.slice(0, f) + g + s.slice(f + u.length), !0);
|
|
2005
2052
|
};
|
|
2006
2053
|
let h;
|
|
2007
|
-
const
|
|
2008
|
-
for (; h =
|
|
2054
|
+
const a = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, p = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
2055
|
+
for (; h = a.exec(i); ) {
|
|
2009
2056
|
const u = h[0];
|
|
2010
|
-
|
|
2057
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2011
2058
|
}
|
|
2012
|
-
for (; h = c.exec(
|
|
2059
|
+
for (; h = c.exec(i); ) {
|
|
2013
2060
|
const u = h[0];
|
|
2014
|
-
|
|
2061
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2015
2062
|
}
|
|
2016
|
-
for (; h = d.exec(
|
|
2063
|
+
for (; h = d.exec(i); ) {
|
|
2017
2064
|
const u = h[0];
|
|
2018
|
-
|
|
2065
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
2019
2066
|
}
|
|
2020
|
-
for (; h =
|
|
2067
|
+
for (; h = p.exec(i); ) {
|
|
2021
2068
|
const u = h[0];
|
|
2022
|
-
|
|
2069
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`));
|
|
2023
2070
|
}
|
|
2024
|
-
return
|
|
2025
|
-
let
|
|
2071
|
+
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) => {
|
|
2072
|
+
let f = 0;
|
|
2026
2073
|
for (let y = 0; y < g.length; y++)
|
|
2027
|
-
|
|
2028
|
-
return
|
|
2029
|
-
}),
|
|
2074
|
+
f = f * 26 + (g.charCodeAt(y) - 97 + 1);
|
|
2075
|
+
return f = f - 1, n[f] || "";
|
|
2076
|
+
}), s;
|
|
2030
2077
|
}
|
|
2031
2078
|
// Method to check if content contains syntax that should be highlighted
|
|
2032
2079
|
shouldHighlight(e) {
|
|
@@ -2038,7 +2085,7 @@ class re {
|
|
|
2038
2085
|
}
|
|
2039
2086
|
function oe(w, e) {
|
|
2040
2087
|
const t = { ...e };
|
|
2041
|
-
return t.extensions || (t.extensions = []), t.extensions.some((
|
|
2088
|
+
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);
|
|
2042
2089
|
}
|
|
2043
2090
|
const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Editor Dialog Styles */
|
|
2044
2091
|
.rte-source-editor-overlay {
|
|
@@ -2437,36 +2484,38 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2437
2484
|
*/
|
|
2438
2485
|
toggleSourceView: () => {
|
|
2439
2486
|
const e = (() => {
|
|
2440
|
-
var
|
|
2487
|
+
var o, l, h;
|
|
2441
2488
|
const n = window.getSelection();
|
|
2442
2489
|
if (n && n.anchorNode) {
|
|
2443
|
-
let
|
|
2444
|
-
for (;
|
|
2445
|
-
if ((
|
|
2446
|
-
return
|
|
2447
|
-
|
|
2490
|
+
let a = n.anchorNode instanceof HTMLElement ? n.anchorNode : n.anchorNode.parentElement;
|
|
2491
|
+
for (; a; ) {
|
|
2492
|
+
if ((o = a.classList) != null && o.contains("rte-content"))
|
|
2493
|
+
return a;
|
|
2494
|
+
a = a.parentElement;
|
|
2448
2495
|
}
|
|
2449
2496
|
}
|
|
2450
2497
|
if (document.activeElement) {
|
|
2451
|
-
let
|
|
2452
|
-
if ((
|
|
2453
|
-
return
|
|
2454
|
-
for (;
|
|
2455
|
-
if ((h =
|
|
2456
|
-
return
|
|
2457
|
-
const c =
|
|
2498
|
+
let a = document.activeElement;
|
|
2499
|
+
if ((l = a.classList) != null && l.contains("rte-content"))
|
|
2500
|
+
return a;
|
|
2501
|
+
for (; a && a !== document.body; ) {
|
|
2502
|
+
if ((h = a.classList) != null && h.contains("rte-content"))
|
|
2503
|
+
return a;
|
|
2504
|
+
const c = a.querySelector(
|
|
2458
2505
|
".rte-content"
|
|
2459
2506
|
);
|
|
2460
|
-
if (c)
|
|
2461
|
-
|
|
2507
|
+
if (c)
|
|
2508
|
+
return c;
|
|
2509
|
+
a = a.parentElement;
|
|
2462
2510
|
}
|
|
2463
2511
|
}
|
|
2464
2512
|
const r = document.querySelector("[data-editora-editor]");
|
|
2465
2513
|
if (r) {
|
|
2466
|
-
const
|
|
2514
|
+
const a = r.querySelector(
|
|
2467
2515
|
".rte-content"
|
|
2468
2516
|
);
|
|
2469
|
-
if (
|
|
2517
|
+
if (a)
|
|
2518
|
+
return a;
|
|
2470
2519
|
}
|
|
2471
2520
|
return document.querySelector(".rte-content");
|
|
2472
2521
|
})();
|
|
@@ -2474,25 +2523,25 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2474
2523
|
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
2475
2524
|
"Editor content area not found. Please click inside the editor first."
|
|
2476
2525
|
), !1;
|
|
2477
|
-
const t = e.innerHTML,
|
|
2478
|
-
let r = "",
|
|
2479
|
-
const
|
|
2480
|
-
for (const
|
|
2481
|
-
|
|
2482
|
-
` + " ".repeat(
|
|
2483
|
-
` + " ".repeat(
|
|
2484
|
-
` + " ".repeat(
|
|
2526
|
+
const t = e.innerHTML, i = (n) => {
|
|
2527
|
+
let r = "", o = 0;
|
|
2528
|
+
const l = 2, h = n.split(/(<\/?[a-zA-Z][^>]*>)/);
|
|
2529
|
+
for (const a of h)
|
|
2530
|
+
a.trim() && (a.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), r += `
|
|
2531
|
+
` + " ".repeat(o * l) + a) : a.match(/^<[a-zA-Z]/) && !a.match(/\/>$/) ? (r += `
|
|
2532
|
+
` + " ".repeat(o * l) + a, o++) : a.match(/^<[a-zA-Z].*\/>$/) ? r += `
|
|
2533
|
+
` + " ".repeat(o * l) + a : r += a.trim());
|
|
2485
2534
|
return r.trim();
|
|
2486
2535
|
};
|
|
2487
2536
|
return (() => {
|
|
2488
|
-
const r =
|
|
2489
|
-
let
|
|
2490
|
-
const
|
|
2491
|
-
u.className = "rte-source-editor-overlay",
|
|
2537
|
+
const r = i(t);
|
|
2538
|
+
let o = null, l = "dark", h = !1, a = !1, c = !1, d = !1;
|
|
2539
|
+
const p = !!e.closest(P) || document.body.matches(P) || document.documentElement.matches(P), u = document.createElement("div");
|
|
2540
|
+
u.className = "rte-source-editor-overlay", p && u.classList.add("rte-theme-dark");
|
|
2492
2541
|
const g = document.createElement("div");
|
|
2493
2542
|
g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
|
|
2494
|
-
const
|
|
2495
|
-
|
|
2543
|
+
const f = document.createElement("div");
|
|
2544
|
+
f.className = "rte-source-editor-header", f.innerHTML = `
|
|
2496
2545
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
2497
2546
|
<div class="rte-source-editor-header-toolbar">
|
|
2498
2547
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -2546,17 +2595,17 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2546
2595
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
2547
2596
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
2548
2597
|
</div>
|
|
2549
|
-
`, g.appendChild(
|
|
2598
|
+
`, g.appendChild(f), g.appendChild(y), g.appendChild(E), u.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
|
|
2550
2599
|
const x = document.createElement("style");
|
|
2551
2600
|
x.id = "rte-source-editor-styles", x.textContent = le, document.head.appendChild(x);
|
|
2552
2601
|
}
|
|
2553
|
-
const M =
|
|
2602
|
+
const M = f.querySelector(
|
|
2554
2603
|
".theme-toggle-btn"
|
|
2555
|
-
), b =
|
|
2604
|
+
), b = f.querySelector(
|
|
2556
2605
|
".readonly-toggle-btn"
|
|
2557
|
-
), T =
|
|
2606
|
+
), T = f.querySelector(
|
|
2558
2607
|
".rte-source-editor-fullscreen-btn"
|
|
2559
|
-
), I =
|
|
2608
|
+
), I = f.querySelector(
|
|
2560
2609
|
".rte-source-editor-close-btn"
|
|
2561
2610
|
), B = E.querySelector(
|
|
2562
2611
|
".rte-source-editor-btn-cancel"
|
|
@@ -2576,10 +2625,10 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2576
2625
|
const x = O.pop();
|
|
2577
2626
|
x == null || x();
|
|
2578
2627
|
}
|
|
2579
|
-
|
|
2628
|
+
o && (o.destroy(), o = null), u.isConnected && u.remove();
|
|
2580
2629
|
}
|
|
2581
2630
|
}, K = () => {
|
|
2582
|
-
|
|
2631
|
+
l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l), M && (M.innerHTML = l === "light" ? `
|
|
2583
2632
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2584
2633
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
2585
2634
|
</svg>
|
|
@@ -2597,7 +2646,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2597
2646
|
</svg>
|
|
2598
2647
|
`);
|
|
2599
2648
|
}, z = () => {
|
|
2600
|
-
h = !h,
|
|
2649
|
+
h = !h, o == null || o.setReadOnly(h), b && (b.classList.toggle("active", h), b.innerHTML = h ? `
|
|
2601
2650
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2602
2651
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
2603
2652
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -2610,7 +2659,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2610
2659
|
</svg>
|
|
2611
2660
|
`);
|
|
2612
2661
|
}, q = () => {
|
|
2613
|
-
|
|
2662
|
+
a = !a, u.classList.toggle("fullscreen", a), S.style.height = a ? "calc(100vh - 200px)" : "400px", T && (T.innerHTML = a ? `
|
|
2614
2663
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
2615
2664
|
<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"/>
|
|
2616
2665
|
</svg>
|
|
@@ -2623,7 +2672,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2623
2672
|
c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || H();
|
|
2624
2673
|
}, j = () => {
|
|
2625
2674
|
try {
|
|
2626
|
-
const x = (
|
|
2675
|
+
const x = (o == null ? void 0 : o.getValue()) || "", k = document.createElement("div");
|
|
2627
2676
|
k.innerHTML = x, k.querySelectorAll(
|
|
2628
2677
|
'script, iframe[src^="javascript:"], object, embed'
|
|
2629
2678
|
).forEach((N) => N.remove()), e.innerHTML = k.innerHTML;
|
|
@@ -2655,7 +2704,7 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2655
2704
|
}), document.body.appendChild(u), requestAnimationFrame(() => {
|
|
2656
2705
|
if (!(d || !u.isConnected))
|
|
2657
2706
|
try {
|
|
2658
|
-
|
|
2707
|
+
o = oe(S, {
|
|
2659
2708
|
value: r,
|
|
2660
2709
|
theme: "dark",
|
|
2661
2710
|
readOnly: !1,
|
|
@@ -2663,15 +2712,15 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2663
2712
|
new G(),
|
|
2664
2713
|
new _(),
|
|
2665
2714
|
new ee(),
|
|
2666
|
-
new ie(),
|
|
2667
2715
|
new se(),
|
|
2716
|
+
new ie(),
|
|
2668
2717
|
new ne(),
|
|
2669
2718
|
new re()
|
|
2670
2719
|
]
|
|
2671
|
-
}),
|
|
2672
|
-
const x = (
|
|
2720
|
+
}), o.on("change", () => {
|
|
2721
|
+
const x = (o == null ? void 0 : o.getValue()) || "";
|
|
2673
2722
|
U(x !== r);
|
|
2674
|
-
}), requestAnimationFrame(() =>
|
|
2723
|
+
}), requestAnimationFrame(() => o == null ? void 0 : o.focus());
|
|
2675
2724
|
} catch (x) {
|
|
2676
2725
|
console.error("Failed to initialize code editor:", x);
|
|
2677
2726
|
}
|
|
@@ -2688,4 +2737,4 @@ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Edi
|
|
|
2688
2737
|
export {
|
|
2689
2738
|
ae as CodePlugin
|
|
2690
2739
|
};
|
|
2691
|
-
//# sourceMappingURL=CodePlugin.native-
|
|
2740
|
+
//# sourceMappingURL=CodePlugin.native-989cf0aa.mjs.map
|