@editora/core 1.0.3 → 1.0.5
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 +34 -0
- package/dist/{A11yCheckerPlugin.native-CZKpi3uF.mjs → A11yCheckerPlugin.native-BRdGYMju.mjs} +225 -173
- package/dist/AnchorPlugin.native-C1Rw5m04.mjs +404 -0
- package/dist/BackgroundColorPlugin.native-BE-p9DRd.mjs +489 -0
- package/dist/ChecklistPlugin.native-nuSSEFNI.mjs +309 -0
- package/dist/ClearFormattingPlugin.native-Bq_XcTh2.mjs +140 -0
- package/dist/{CodePlugin.native-CK9d8rmt.mjs → CodePlugin.native-B263UI8O.mjs} +624 -473
- package/dist/CodeSamplePlugin.native-CgGoH-X4.mjs +384 -0
- package/dist/CommentsPlugin.native-tMnWn8a2.mjs +723 -0
- package/dist/DirectionPlugin.native-CDnbdNyl.mjs +130 -0
- package/dist/{EmbedIframePlugin.native-ifr9KLdN.mjs → EmbedIframePlugin.native-CSWIB1jm.mjs} +154 -50
- package/dist/{EmojisPlugin.native-D6mJSnSR.mjs → EmojisPlugin.native-DxTm_DL-.mjs} +156 -103
- package/dist/FontFamilyPlugin.native-j8hMTbg4.mjs +158 -0
- package/dist/FontSizePlugin.native-B_jCh7dY.mjs +286 -0
- package/dist/FootnotePlugin.native-D730OGRm.mjs +425 -0
- package/dist/HistoryPlugin.native-TDnVMsEO.mjs +257 -0
- package/dist/IndentPlugin.native-BHixp8sP.mjs +150 -0
- package/dist/LineHeightPlugin.native-CM7iXdQj.mjs +151 -0
- package/dist/{LinkPlugin.native-BdAOV-iu.mjs → LinkPlugin.native-CS2g-G18.mjs} +128 -53
- package/dist/{ListPlugin.native-CLFU5AUQ.mjs → ListPlugin.native-V7EZC1lM.mjs} +59 -12
- package/dist/MathPlugin.native-KUxz0o8C.mjs +251 -0
- package/dist/MediaManagerPlugin.native-CgP5iInD.mjs +970 -0
- package/dist/MergeTagPlugin.native-DIGWhdnF.mjs +419 -0
- package/dist/PageBreakPlugin.native-CGiQxXqR.mjs +297 -0
- package/dist/{PrintPlugin.native-BUpm52VJ.mjs → PrintPlugin.native-7qt5v7L5.mjs} +10 -10
- package/dist/{SpecialCharactersPlugin.native-x7a2SWXc.mjs → SpecialCharactersPlugin.native-DANrbExJ.mjs} +143 -97
- package/dist/SpellCheckPlugin.native-C8bPvRHy.mjs +1019 -0
- package/dist/StrikethroughPlugin.native-0Be7j49s.mjs +73 -0
- package/dist/{TablePlugin.native-EEWXn1-s.mjs → TablePlugin.native-DrHX-efe.mjs} +149 -145
- package/dist/TemplatePlugin.native-4lKEm-WY.mjs +578 -0
- package/dist/TextAlignmentPlugin.native-sM_1s00t.mjs +108 -0
- package/dist/{TextColorPlugin.native-D6SmTglm.mjs → TextColorPlugin.native-Clgtb50j.mjs} +173 -92
- package/dist/colorSelectionApply-CK1My9N2.mjs +67 -0
- package/dist/core.css +1 -1
- package/dist/editora.min.js +31 -29
- package/dist/editora.umd.js +31 -29
- package/dist/index-CqWQFb3D.js +10 -0
- package/dist/index-OwnkG39N.mjs +2227 -0
- package/dist/index.cjs.js +14 -18
- package/dist/index.esm.js +204 -521
- package/dist/plugin-loader.js +26 -26
- package/dist/webcomponent-core.js +1286 -295
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +111 -78
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +1252 -261
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +3552 -2037
- package/index.d.ts +355 -0
- package/package.json +21 -18
- package/dist/A11yCheckerPlugin.native-CZKpi3uF.mjs.map +0 -1
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs +0 -340
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs.map +0 -1
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs +0 -449
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs.map +0 -1
- package/dist/BlockquotePlugin.native-JFmOLsxN.mjs.map +0 -1
- package/dist/BoldPlugin.native-BAzzoqU5.mjs.map +0 -1
- package/dist/CapitalizationPlugin.native-DOMsh5R7.mjs.map +0 -1
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs +0 -153
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs.map +0 -1
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs +0 -27
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs.map +0 -1
- package/dist/CodePlugin.native-CK9d8rmt.mjs.map +0 -1
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs +0 -326
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs.map +0 -1
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs +0 -473
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs.map +0 -1
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs +0 -59
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs.map +0 -1
- package/dist/DocumentManagerPlugin.native-BvZL5CSG.mjs.map +0 -1
- package/dist/EmbedIframePlugin.native-ifr9KLdN.mjs.map +0 -1
- package/dist/EmojisPlugin.native-D6mJSnSR.mjs.map +0 -1
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs +0 -106
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs.map +0 -1
- package/dist/FontSizePlugin.native-DkLMLPue.mjs +0 -186
- package/dist/FontSizePlugin.native-DkLMLPue.mjs.map +0 -1
- package/dist/FootnotePlugin.native-BciVc9W6.mjs +0 -128
- package/dist/FootnotePlugin.native-BciVc9W6.mjs.map +0 -1
- package/dist/FullscreenPlugin.native-ChXyxeNw.mjs.map +0 -1
- package/dist/HeadingPlugin.native-DrLYwQnQ.mjs.map +0 -1
- package/dist/HistoryPlugin.native-DoDRifCf.mjs +0 -89
- package/dist/HistoryPlugin.native-DoDRifCf.mjs.map +0 -1
- package/dist/IndentPlugin.native-CbFugPoi.mjs +0 -133
- package/dist/IndentPlugin.native-CbFugPoi.mjs.map +0 -1
- package/dist/ItalicPlugin.native-CQjjDyUL.mjs.map +0 -1
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs +0 -73
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs.map +0 -1
- package/dist/LinkPlugin.native-BdAOV-iu.mjs.map +0 -1
- package/dist/ListPlugin.native-CLFU5AUQ.mjs.map +0 -1
- package/dist/MathPlugin.native-DE_ii-LA.mjs +0 -182
- package/dist/MathPlugin.native-DE_ii-LA.mjs.map +0 -1
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs +0 -533
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs.map +0 -1
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs +0 -178
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs.map +0 -1
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs +0 -172
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs.map +0 -1
- package/dist/PreviewPlugin.native-DBvfpmIv.mjs.map +0 -1
- package/dist/PrintPlugin.native-BUpm52VJ.mjs.map +0 -1
- package/dist/SpecialCharactersPlugin.native-x7a2SWXc.mjs.map +0 -1
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs +0 -465
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs.map +0 -1
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs +0 -43
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs.map +0 -1
- package/dist/TablePlugin.native-EEWXn1-s.mjs.map +0 -1
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs +0 -564
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs.map +0 -1
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs +0 -97
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs.map +0 -1
- package/dist/TextColorPlugin.native-D6SmTglm.mjs.map +0 -1
- package/dist/UnderlinePlugin.native-QpIcK4L2.mjs.map +0 -1
- package/dist/documentManager-irzj9n3V.mjs.map +0 -1
- package/dist/editorContainerHelpers-C7kdWnS0.mjs.map +0 -1
- package/dist/editora.min.js.map +0 -1
- package/dist/editora.umd.js.map +0 -1
- package/dist/index-BF5RBhL9.js +0 -4
- package/dist/index-BF5RBhL9.js.map +0 -1
- package/dist/index-BPsf460l.mjs +0 -1243
- package/dist/index-BPsf460l.mjs.map +0 -1
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es-CuicffkQ.mjs.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/plugin-loader.js.map +0 -1
- package/dist/purify.es-CKpwg8Tk.mjs.map +0 -1
- package/dist/webcomponent-core.js.map +0 -1
- package/dist/webcomponent-core.min.js.map +0 -1
- package/dist/webcomponent.cjs.js.map +0 -1
- package/dist/webcomponent.esm.js.map +0 -1
- package/dist/webcomponent.js.map +0 -1
- package/dist/webcomponent.min.js.map +0 -1
|
@@ -30,28 +30,28 @@ class P {
|
|
|
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), r = s.substring(0, e.start.column) + t + s.substring(e.end.column);
|
|
43
43
|
this._lines[e.start.line] = r;
|
|
44
44
|
} else {
|
|
45
|
-
const
|
|
45
|
+
const s = this.getLine(e.start.line), r = this.getLine(e.end.line), n = s.substring(0, e.start.column) + t, o = r.substring(e.end.column), l = t.split(`
|
|
46
46
|
`);
|
|
47
|
-
|
|
47
|
+
l[0] = n + 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 P {
|
|
|
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,
|
|
@@ -96,9 +96,9 @@ class P {
|
|
|
96
96
|
return e._lines = [...this._lines], e._version = this._version, e;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
class
|
|
99
|
+
class U {
|
|
100
100
|
constructor(e) {
|
|
101
|
-
this.gutterWidth = 50, this.lineHeight = 21, this.container = e, this.createDOM();
|
|
101
|
+
this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.container = e, this.createDOM();
|
|
102
102
|
}
|
|
103
103
|
createDOM() {
|
|
104
104
|
this.container.innerHTML = "";
|
|
@@ -149,8 +149,8 @@ class B {
|
|
|
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, r) => r + 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() {
|
|
@@ -162,85 +162,103 @@ class B {
|
|
|
162
162
|
}
|
|
163
163
|
// Get text content
|
|
164
164
|
getText() {
|
|
165
|
-
|
|
165
|
+
const e = this.contentElement.textContent || "";
|
|
166
|
+
return this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`) && e.endsWith("") ? e.slice(0, -1) : e;
|
|
166
167
|
}
|
|
167
168
|
// Set text content
|
|
168
169
|
setText(e) {
|
|
169
|
-
this.contentElement.textContent = e
|
|
170
|
+
this.contentElement.textContent = e, this.syncTrailingNewlineMarker(e.endsWith(`
|
|
171
|
+
`));
|
|
170
172
|
const t = e.split(`
|
|
171
173
|
`).length;
|
|
172
174
|
this.updateLineNumbers(t);
|
|
173
175
|
}
|
|
174
176
|
// Set inner HTML (used for syntax highlighted content)
|
|
175
177
|
setHTML(e) {
|
|
176
|
-
const t = /<|>/.test(e), s = /<span\b/i.test(e),
|
|
177
|
-
|
|
178
|
-
const
|
|
178
|
+
const t = /\n$/.test(e), i = /<|>/.test(e), s = /<span\b/i.test(e), r = /<[^>]+>/.test(e);
|
|
179
|
+
i && s ? this.contentElement.innerHTML = e : r && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
|
|
180
|
+
const n = (this.contentElement.textContent || "").split(`
|
|
179
181
|
`).length;
|
|
180
|
-
this.updateLineNumbers(
|
|
182
|
+
this.updateLineNumbers(n);
|
|
183
|
+
}
|
|
184
|
+
// Keep trailing-newline caret marker in sync for live contenteditable edits
|
|
185
|
+
// (without forcing a full setText/setHTML render).
|
|
186
|
+
syncTrailingNewlineMarkerForText(e) {
|
|
187
|
+
this.syncTrailingNewlineMarker(e.endsWith(`
|
|
188
|
+
`));
|
|
181
189
|
}
|
|
182
190
|
// Get cursor position from DOM selection
|
|
183
191
|
getCursorPosition() {
|
|
184
192
|
const e = window.getSelection();
|
|
185
193
|
if (!e || e.rangeCount === 0)
|
|
186
194
|
return { line: 0, column: 0 };
|
|
187
|
-
const t = e.getRangeAt(0),
|
|
188
|
-
|
|
189
|
-
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(`
|
|
190
198
|
`);
|
|
191
199
|
return {
|
|
192
|
-
line:
|
|
193
|
-
column:
|
|
200
|
+
line: s.length - 1,
|
|
201
|
+
column: s[s.length - 1].length
|
|
194
202
|
};
|
|
195
203
|
}
|
|
196
204
|
// Set cursor position
|
|
197
205
|
setCursorPosition(e) {
|
|
198
|
-
var g,
|
|
206
|
+
var g, h;
|
|
199
207
|
const t = this.getText().split(`
|
|
200
|
-
`),
|
|
208
|
+
`), i = Math.min(e.line, t.length - 1), s = Math.min(e.column, ((g = t[i]) == null ? void 0 : g.length) || 0);
|
|
201
209
|
let r = 0;
|
|
202
|
-
for (let f = 0; f <
|
|
210
|
+
for (let f = 0; f < i; f++)
|
|
203
211
|
r += t[f].length + 1;
|
|
204
|
-
r +=
|
|
212
|
+
r += s;
|
|
205
213
|
const n = document.createRange(), o = window.getSelection();
|
|
206
|
-
let
|
|
207
|
-
const
|
|
214
|
+
let l = 0, c = null, a = 0;
|
|
215
|
+
const u = document.createTreeWalker(
|
|
208
216
|
this.contentElement,
|
|
209
217
|
NodeFilter.SHOW_TEXT,
|
|
210
218
|
null
|
|
211
219
|
);
|
|
212
|
-
let
|
|
213
|
-
for (;
|
|
214
|
-
const f = ((
|
|
215
|
-
if (
|
|
216
|
-
c =
|
|
220
|
+
let d;
|
|
221
|
+
for (; d = u.nextNode(); ) {
|
|
222
|
+
const f = ((h = d.textContent) == null ? void 0 : h.length) || 0;
|
|
223
|
+
if (l + f >= r) {
|
|
224
|
+
c = d, a = r - l;
|
|
217
225
|
break;
|
|
218
226
|
}
|
|
219
|
-
|
|
227
|
+
l += f;
|
|
220
228
|
}
|
|
221
229
|
if (c)
|
|
222
230
|
try {
|
|
223
|
-
n.setStart(c,
|
|
231
|
+
n.setStart(c, a), n.setEnd(c, a), o == null || o.removeAllRanges(), o == null || o.addRange(n), this.ensureCaretVisible();
|
|
224
232
|
} catch (f) {
|
|
225
233
|
console.warn("Could not set cursor position:", f);
|
|
226
234
|
}
|
|
235
|
+
else {
|
|
236
|
+
const f = this.contentElement.querySelector(
|
|
237
|
+
`[${this.trailingNewlineMarkerAttr}]`
|
|
238
|
+
);
|
|
239
|
+
try {
|
|
240
|
+
f && f.parentNode === this.contentElement ? n.setStartBefore(f) : (n.selectNodeContents(this.contentElement), n.collapse(!1)), n.collapse(!0), o == null || o.removeAllRanges(), o == null || o.addRange(n), this.ensureCaretVisible();
|
|
241
|
+
} catch (p) {
|
|
242
|
+
console.warn("Could not set fallback cursor position:", p);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
227
245
|
}
|
|
228
246
|
// Get selection range
|
|
229
247
|
getSelectionRange() {
|
|
230
248
|
const e = window.getSelection();
|
|
231
249
|
if (!e || e.rangeCount === 0 || e.isCollapsed)
|
|
232
250
|
return;
|
|
233
|
-
const t = e.getRangeAt(0),
|
|
234
|
-
|
|
235
|
-
const
|
|
251
|
+
const t = e.getRangeAt(0), i = t.cloneRange();
|
|
252
|
+
i.selectNodeContents(this.contentElement), i.setEnd(t.startContainer, t.startOffset);
|
|
253
|
+
const s = i.toString().replace(/\u200B/g, "").split(`
|
|
236
254
|
`), r = t.cloneRange();
|
|
237
255
|
r.selectNodeContents(this.contentElement), r.setEnd(t.endContainer, t.endOffset);
|
|
238
|
-
const n = r.toString().split(`
|
|
256
|
+
const n = r.toString().replace(/\u200B/g, "").split(`
|
|
239
257
|
`);
|
|
240
258
|
return {
|
|
241
259
|
start: {
|
|
242
|
-
line:
|
|
243
|
-
column:
|
|
260
|
+
line: s.length - 1,
|
|
261
|
+
column: s[s.length - 1].length
|
|
244
262
|
},
|
|
245
263
|
end: {
|
|
246
264
|
line: n.length - 1,
|
|
@@ -254,7 +272,7 @@ class B {
|
|
|
254
272
|
}
|
|
255
273
|
// Focus the editor
|
|
256
274
|
focus() {
|
|
257
|
-
this.contentElement.focus();
|
|
275
|
+
this.contentElement.focus(), this.ensureCaretVisible();
|
|
258
276
|
}
|
|
259
277
|
// Blur the editor
|
|
260
278
|
blur() {
|
|
@@ -266,8 +284,8 @@ class B {
|
|
|
266
284
|
}
|
|
267
285
|
// Apply theme
|
|
268
286
|
applyTheme(e) {
|
|
269
|
-
Object.entries(e).forEach(([t,
|
|
270
|
-
this.container.style.setProperty(`--${t}`,
|
|
287
|
+
Object.entries(e).forEach(([t, i]) => {
|
|
288
|
+
this.container.style.setProperty(`--${t}`, i);
|
|
271
289
|
});
|
|
272
290
|
}
|
|
273
291
|
// Scroll to position
|
|
@@ -283,14 +301,37 @@ class B {
|
|
|
283
301
|
setScrollTop(e) {
|
|
284
302
|
this.editorContainer.scrollTop = e;
|
|
285
303
|
}
|
|
304
|
+
syncTrailingNewlineMarker(e) {
|
|
305
|
+
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e) return;
|
|
306
|
+
const t = document.createElement("span");
|
|
307
|
+
t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
|
|
308
|
+
display: inline-block;
|
|
309
|
+
width: 0;
|
|
310
|
+
overflow: hidden;
|
|
311
|
+
pointer-events: none;
|
|
312
|
+
user-select: none;
|
|
313
|
+
`, t.appendChild(document.createTextNode("")), this.contentElement.appendChild(t);
|
|
314
|
+
}
|
|
315
|
+
// Ensure caret is visible inside the editor scroll container
|
|
316
|
+
ensureCaretVisible() {
|
|
317
|
+
var n;
|
|
318
|
+
const e = window.getSelection();
|
|
319
|
+
if (!e || e.rangeCount === 0) return;
|
|
320
|
+
const t = e.getRangeAt(0).cloneRange();
|
|
321
|
+
t.collapse(!1);
|
|
322
|
+
let i = t.getClientRects()[0] || t.getBoundingClientRect();
|
|
323
|
+
if ((!i || i.width === 0 && i.height === 0) && e.focusNode instanceof Element ? i = e.focusNode.getBoundingClientRect() : (!i || i.width === 0 && i.height === 0) && ((n = e.focusNode) != null && n.parentElement) && (i = e.focusNode.parentElement.getBoundingClientRect()), !i) return;
|
|
324
|
+
const s = this.editorContainer.getBoundingClientRect(), r = 12;
|
|
325
|
+
i.bottom > s.bottom - r ? this.editorContainer.scrollTop += i.bottom - (s.bottom - r) : i.top < s.top + r && (this.editorContainer.scrollTop -= s.top + r - i.top);
|
|
326
|
+
}
|
|
286
327
|
// Destroy the view
|
|
287
328
|
destroy() {
|
|
288
329
|
this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
|
|
289
330
|
}
|
|
290
331
|
}
|
|
291
|
-
|
|
332
|
+
const K = class M {
|
|
292
333
|
constructor(e, t = {}) {
|
|
293
|
-
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.expectingProgrammaticCursor = !1, this.config = {
|
|
334
|
+
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.config = {
|
|
294
335
|
value: "",
|
|
295
336
|
theme: "default",
|
|
296
337
|
readOnly: !1,
|
|
@@ -298,7 +339,7 @@ class K {
|
|
|
298
339
|
lineWrapping: !1,
|
|
299
340
|
lineNumbers: !0,
|
|
300
341
|
...t
|
|
301
|
-
}, this.textModel = new P(this.config.value), this.view = new
|
|
342
|
+
}, this.textModel = new P(this.config.value), this.view = new U(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();
|
|
302
343
|
}
|
|
303
344
|
// Public accessors for extensions
|
|
304
345
|
getTextModel() {
|
|
@@ -324,20 +365,21 @@ class K {
|
|
|
324
365
|
setupEventHandlers() {
|
|
325
366
|
const e = this.view.getContentElement();
|
|
326
367
|
e.addEventListener("input", () => {
|
|
327
|
-
const t = this.view.getText(),
|
|
328
|
-
if (t !==
|
|
368
|
+
const t = this.view.getText(), i = this.textModel.getText();
|
|
369
|
+
if (t !== i) {
|
|
329
370
|
if (!this.suppressHistory) {
|
|
330
|
-
const
|
|
331
|
-
let o,
|
|
332
|
-
n && (o = this.textModel.positionToOffset(n.start),
|
|
371
|
+
const s = this.getCursor().position, r = this.textModel.positionToOffset(s), n = this.getSelection();
|
|
372
|
+
let o, l;
|
|
373
|
+
n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
333
374
|
}
|
|
334
|
-
this.textModel.setText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
335
|
-
this.
|
|
336
|
-
|
|
375
|
+
this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
376
|
+
const s = this.view.getText();
|
|
377
|
+
s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
|
|
378
|
+
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
|
|
337
379
|
}
|
|
338
380
|
}), e.addEventListener("selectionchange", () => {
|
|
339
|
-
const t = this.getCursor(),
|
|
340
|
-
this.emit("cursor", t),
|
|
381
|
+
const t = this.getCursor(), i = this.getSelection();
|
|
382
|
+
this.emit("cursor", t), i && this.emit("selection", i);
|
|
341
383
|
}), e.addEventListener("keydown", (t) => {
|
|
342
384
|
if (this.emit("keydown", t), t.key === "Tab") {
|
|
343
385
|
this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
|
|
@@ -345,31 +387,35 @@ class K {
|
|
|
345
387
|
}
|
|
346
388
|
if (t.key === "Enter") {
|
|
347
389
|
if (!this.config.readOnly) {
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
const
|
|
351
|
-
let o,
|
|
352
|
-
n && (o = this.textModel.positionToOffset(n.start),
|
|
353
|
-
const c =
|
|
354
|
-
|
|
355
|
-
const
|
|
390
|
+
const i = window.getSelection();
|
|
391
|
+
if (i && i.rangeCount > 0) {
|
|
392
|
+
const s = this.getCursor().position, r = this.textModel.positionToOffset(s), n = this.getSelection();
|
|
393
|
+
let o, l;
|
|
394
|
+
n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end));
|
|
395
|
+
const c = n && o !== void 0 && l !== void 0 ? Math.min(o, l) : r;
|
|
396
|
+
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: r, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
|
|
397
|
+
const a = i.getRangeAt(0);
|
|
398
|
+
a.deleteContents();
|
|
399
|
+
const u = document.createTextNode(`
|
|
356
400
|
`);
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
401
|
+
a.insertNode(u), a.setStartAfter(u), a.collapse(!0), i.removeAllRanges(), i.addRange(a), this.view.ensureCaretVisible();
|
|
402
|
+
const d = this.view.getText();
|
|
403
|
+
this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
|
|
404
|
+
const g = Math.min(
|
|
405
|
+
c + 1,
|
|
406
|
+
this.textModel.getText().length
|
|
407
|
+
);
|
|
408
|
+
try {
|
|
409
|
+
const h = this.textModel.offsetToPosition(g);
|
|
410
|
+
this.setCursor(h), this.view.ensureCaretVisible();
|
|
411
|
+
} catch (h) {
|
|
412
|
+
}
|
|
413
|
+
this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
363
414
|
this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
|
|
364
415
|
try {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
} else {
|
|
369
|
-
const x = this.textModel.offsetToPosition(u);
|
|
370
|
-
this.setCursor(x);
|
|
371
|
-
}
|
|
372
|
-
} catch (x) {
|
|
416
|
+
const h = this.textModel.offsetToPosition(g);
|
|
417
|
+
this.setCursor(h), this.view.ensureCaretVisible();
|
|
418
|
+
} catch (h) {
|
|
373
419
|
}
|
|
374
420
|
}), this.highlightTimeout = null;
|
|
375
421
|
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: this.getValue(), oldText: "" }]);
|
|
@@ -378,15 +424,15 @@ class K {
|
|
|
378
424
|
t.preventDefault(), t.stopPropagation();
|
|
379
425
|
return;
|
|
380
426
|
}
|
|
381
|
-
for (const
|
|
382
|
-
if (
|
|
427
|
+
for (const i of this.extensions.values())
|
|
428
|
+
if (i.onKeyDown && i.onKeyDown(t) === !1) {
|
|
383
429
|
t.preventDefault(), t.stopPropagation();
|
|
384
430
|
return;
|
|
385
431
|
}
|
|
386
432
|
}), e.addEventListener("mousedown", (t) => {
|
|
387
433
|
this.emit("mousedown", t);
|
|
388
|
-
for (const
|
|
389
|
-
if (
|
|
434
|
+
for (const i of this.extensions.values())
|
|
435
|
+
if (i.onMouseDown && i.onMouseDown(t) === !1) {
|
|
390
436
|
t.preventDefault(), t.stopPropagation();
|
|
391
437
|
return;
|
|
392
438
|
}
|
|
@@ -413,8 +459,8 @@ class K {
|
|
|
413
459
|
}
|
|
414
460
|
// Emit events to listeners
|
|
415
461
|
emit(e, ...t) {
|
|
416
|
-
const
|
|
417
|
-
|
|
462
|
+
const i = this.eventListeners.get(e);
|
|
463
|
+
i && i.forEach((s) => s(...t));
|
|
418
464
|
}
|
|
419
465
|
// State management
|
|
420
466
|
getValue() {
|
|
@@ -462,12 +508,12 @@ class K {
|
|
|
462
508
|
"editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
|
|
463
509
|
};
|
|
464
510
|
this.view.applyTheme(t);
|
|
465
|
-
const
|
|
466
|
-
if (
|
|
511
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
512
|
+
if (i && typeof i.setTheme == "function")
|
|
467
513
|
try {
|
|
468
|
-
|
|
469
|
-
} catch (
|
|
470
|
-
console.warn("Error applying theme to syntax-highlighting extension",
|
|
514
|
+
i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
|
|
515
|
+
} catch (s) {
|
|
516
|
+
console.warn("Error applying theme to syntax-highlighting extension", s);
|
|
471
517
|
}
|
|
472
518
|
}
|
|
473
519
|
setReadOnly(e) {
|
|
@@ -484,8 +530,8 @@ class K {
|
|
|
484
530
|
t && t.destroy && t.destroy(), this.extensions.delete(e);
|
|
485
531
|
}
|
|
486
532
|
executeCommand(e, ...t) {
|
|
487
|
-
const
|
|
488
|
-
|
|
533
|
+
const i = this.commands.get(e);
|
|
534
|
+
i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
|
|
489
535
|
}
|
|
490
536
|
// Register a command
|
|
491
537
|
registerCommand(e, t) {
|
|
@@ -493,51 +539,51 @@ class K {
|
|
|
493
539
|
}
|
|
494
540
|
// Search & Navigation
|
|
495
541
|
search(e, t = {}) {
|
|
496
|
-
const
|
|
542
|
+
const i = {
|
|
497
543
|
caseSensitive: !1,
|
|
498
544
|
regex: !1,
|
|
499
545
|
...t
|
|
500
|
-
},
|
|
546
|
+
}, s = [], r = this.getValue();
|
|
501
547
|
r.split(`
|
|
502
548
|
`);
|
|
503
|
-
let n =
|
|
504
|
-
if (
|
|
505
|
-
const
|
|
549
|
+
let n = i.caseSensitive ? r : r.toLowerCase(), o = i.caseSensitive ? e : e.toLowerCase();
|
|
550
|
+
if (i.regex) {
|
|
551
|
+
const l = new RegExp(o, i.caseSensitive ? "g" : "gi");
|
|
506
552
|
let c;
|
|
507
|
-
for (; (c =
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
range: { start:
|
|
553
|
+
for (; (c = l.exec(n)) !== null; ) {
|
|
554
|
+
const a = this.textModel.offsetToPosition(c.index), u = this.textModel.offsetToPosition(c.index + c[0].length);
|
|
555
|
+
s.push({
|
|
556
|
+
range: { start: a, end: u },
|
|
511
557
|
match: c[0]
|
|
512
558
|
});
|
|
513
559
|
}
|
|
514
560
|
} else {
|
|
515
|
-
let
|
|
561
|
+
let l = 0, c = n.indexOf(o, l);
|
|
516
562
|
for (; c !== -1; ) {
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
range: { start:
|
|
520
|
-
match: r.substring(c,
|
|
521
|
-
}),
|
|
563
|
+
const a = c + e.length, u = this.textModel.offsetToPosition(c), d = this.textModel.offsetToPosition(a);
|
|
564
|
+
s.push({
|
|
565
|
+
range: { start: u, end: d },
|
|
566
|
+
match: r.substring(c, a)
|
|
567
|
+
}), l = a, c = n.indexOf(o, l);
|
|
522
568
|
}
|
|
523
569
|
}
|
|
524
|
-
return
|
|
570
|
+
return s;
|
|
525
571
|
}
|
|
526
572
|
replace(e, t) {
|
|
527
|
-
const
|
|
573
|
+
const i = this.getValue();
|
|
528
574
|
if (!this.suppressHistory) {
|
|
529
575
|
const r = this.getCursor().position, n = this.textModel.positionToOffset(r), o = this.getSelection();
|
|
530
|
-
let
|
|
531
|
-
o && (
|
|
576
|
+
let l, c;
|
|
577
|
+
o && (l = this.textModel.positionToOffset(o.start), c = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: n, anchorOffset: l, focusOffset: c }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
532
578
|
}
|
|
533
|
-
const
|
|
534
|
-
this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [
|
|
579
|
+
const s = this.textModel.replaceRange(e, t);
|
|
580
|
+
this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [s]);
|
|
535
581
|
}
|
|
536
|
-
replaceAll(e, t,
|
|
537
|
-
const
|
|
582
|
+
replaceAll(e, t, i = {}) {
|
|
583
|
+
const s = this.search(e, i);
|
|
538
584
|
let r = 0;
|
|
539
|
-
for (let n =
|
|
540
|
-
this.replace(
|
|
585
|
+
for (let n = s.length - 1; n >= 0; n--)
|
|
586
|
+
this.replace(s[n].range, t), r++;
|
|
541
587
|
return r;
|
|
542
588
|
}
|
|
543
589
|
// Folding (basic implementation)
|
|
@@ -570,35 +616,85 @@ class K {
|
|
|
570
616
|
// and restores it after updating the DOM. Callers that will explicitly set the caret
|
|
571
617
|
// should pass `false` to avoid stomping programmatic cursor changes.
|
|
572
618
|
renderTextWithHighlight(e, t = !0) {
|
|
573
|
-
const
|
|
574
|
-
if (
|
|
619
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
620
|
+
if (i && typeof i.highlightHTML == "function")
|
|
575
621
|
try {
|
|
576
|
-
const
|
|
577
|
-
let r, n, o,
|
|
578
|
-
if (t ||
|
|
622
|
+
const s = !t && !this.expectingProgrammaticCursor;
|
|
623
|
+
let r, n, o, l;
|
|
624
|
+
if (t || s) {
|
|
579
625
|
r = this.getSelection();
|
|
580
|
-
const
|
|
581
|
-
|
|
626
|
+
const d = this.getCollapsedSelectionOffsetInEditor();
|
|
627
|
+
if (d !== void 0)
|
|
628
|
+
n = d;
|
|
629
|
+
else {
|
|
630
|
+
const g = this.getCursor().position;
|
|
631
|
+
n = this.textModel.positionToOffset(g);
|
|
632
|
+
}
|
|
633
|
+
r && (o = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end));
|
|
582
634
|
}
|
|
583
|
-
const c = s.
|
|
584
|
-
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(
|
|
635
|
+
const c = (t || s) && !r && n !== void 0 && this.hasCollapsedSelectionInEditor(), a = c ? this.insertSentinelAtOffset(e, n) : e, u = i.highlightHTML(a);
|
|
636
|
+
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(u) : this.view.setHTML(u), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
|
|
585
637
|
try {
|
|
586
|
-
if (
|
|
587
|
-
|
|
588
|
-
|
|
638
|
+
if (c && this.restoreCursorFromSentinel()) {
|
|
639
|
+
this.view.ensureCaretVisible();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (r && (o !== void 0 || l !== void 0)) {
|
|
643
|
+
const d = o !== void 0 ? o : n, g = l !== void 0 ? l : n, h = Math.min(d, g), f = Math.max(d, g), p = this.textModel.offsetToPosition(h), x = this.textModel.offsetToPosition(f);
|
|
644
|
+
this.view.setSelectionRange({ start: p, end: x });
|
|
589
645
|
} else if (n !== void 0) {
|
|
590
|
-
const
|
|
591
|
-
this.view.setCursorPosition(
|
|
646
|
+
const d = this.textModel.offsetToPosition(n);
|
|
647
|
+
this.view.setCursorPosition(d);
|
|
592
648
|
}
|
|
593
|
-
} catch (
|
|
649
|
+
} catch (d) {
|
|
594
650
|
}
|
|
595
651
|
});
|
|
596
652
|
return;
|
|
597
|
-
} catch (
|
|
598
|
-
console.warn("Syntax highlighting failed, falling back to plain text",
|
|
653
|
+
} catch (s) {
|
|
654
|
+
console.warn("Syntax highlighting failed, falling back to plain text", s);
|
|
599
655
|
}
|
|
600
656
|
this.view.setText(e);
|
|
601
657
|
}
|
|
658
|
+
hasCollapsedSelectionInEditor() {
|
|
659
|
+
const e = window.getSelection();
|
|
660
|
+
if (!e || e.rangeCount === 0 || !e.isCollapsed)
|
|
661
|
+
return !1;
|
|
662
|
+
const t = e.getRangeAt(0);
|
|
663
|
+
return this.view.getContentElement().contains(t.commonAncestorContainer);
|
|
664
|
+
}
|
|
665
|
+
getCollapsedSelectionOffsetInEditor() {
|
|
666
|
+
const e = window.getSelection();
|
|
667
|
+
if (!e || e.rangeCount === 0 || !e.isCollapsed)
|
|
668
|
+
return;
|
|
669
|
+
const t = e.getRangeAt(0), i = this.view.getContentElement();
|
|
670
|
+
if (!i.contains(t.commonAncestorContainer))
|
|
671
|
+
return;
|
|
672
|
+
const s = t.cloneRange();
|
|
673
|
+
return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
|
|
674
|
+
}
|
|
675
|
+
stripVirtualMarkers(e) {
|
|
676
|
+
return e.replace(/\u200B/g, "").split(M.CURSOR_SENTINEL).join("");
|
|
677
|
+
}
|
|
678
|
+
insertSentinelAtOffset(e, t) {
|
|
679
|
+
const i = Math.max(0, Math.min(t, e.length));
|
|
680
|
+
return e.slice(0, i) + M.CURSOR_SENTINEL + e.slice(i);
|
|
681
|
+
}
|
|
682
|
+
restoreCursorFromSentinel() {
|
|
683
|
+
var o;
|
|
684
|
+
const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
|
|
685
|
+
let s = i.nextNode(), r = null, n = 0;
|
|
686
|
+
for (; s; ) {
|
|
687
|
+
const l = (o = s.textContent) != null ? o : "", c = l.indexOf(M.CURSOR_SENTINEL);
|
|
688
|
+
c !== -1 && (r || (r = s, n = c), s.textContent = l.split(M.CURSOR_SENTINEL).join("")), s = i.nextNode();
|
|
689
|
+
}
|
|
690
|
+
if (!r || !t) return !1;
|
|
691
|
+
try {
|
|
692
|
+
const l = document.createRange();
|
|
693
|
+
return l.setStart(r, n), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
|
|
694
|
+
} catch (l) {
|
|
695
|
+
return !1;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
602
698
|
destroy() {
|
|
603
699
|
if (!this.isDestroyed) {
|
|
604
700
|
this.isDestroyed = !0;
|
|
@@ -614,15 +710,15 @@ class K {
|
|
|
614
710
|
this.redoStack.push(t);
|
|
615
711
|
try {
|
|
616
712
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
617
|
-
let
|
|
618
|
-
typeof e == "string" ?
|
|
713
|
+
let i, s;
|
|
714
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
619
715
|
try {
|
|
620
|
-
if (
|
|
716
|
+
if (s != null)
|
|
621
717
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
622
|
-
const r = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
623
|
-
this.setSelection({ start: c, end:
|
|
718
|
+
const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, n = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(r, n), l = Math.max(r, n), c = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
|
|
719
|
+
this.setSelection({ start: c, end: a });
|
|
624
720
|
} else {
|
|
625
|
-
const r = this.textModel.offsetToPosition(
|
|
721
|
+
const r = this.textModel.offsetToPosition(s);
|
|
626
722
|
this.setCursor(r);
|
|
627
723
|
}
|
|
628
724
|
} catch (r) {
|
|
@@ -640,15 +736,15 @@ class K {
|
|
|
640
736
|
this.undoStack.push(t);
|
|
641
737
|
try {
|
|
642
738
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
643
|
-
let
|
|
644
|
-
typeof e == "string" ?
|
|
739
|
+
let i, s;
|
|
740
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
645
741
|
try {
|
|
646
|
-
if (
|
|
742
|
+
if (s != null)
|
|
647
743
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
648
|
-
const r = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
649
|
-
this.setSelection({ start: c, end:
|
|
744
|
+
const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, n = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(r, n), l = Math.max(r, n), c = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
|
|
745
|
+
this.setSelection({ start: c, end: a });
|
|
650
746
|
} else {
|
|
651
|
-
const r = this.textModel.offsetToPosition(
|
|
747
|
+
const r = this.textModel.offsetToPosition(s);
|
|
652
748
|
this.setCursor(r);
|
|
653
749
|
}
|
|
654
750
|
} catch (r) {
|
|
@@ -663,29 +759,29 @@ class K {
|
|
|
663
759
|
// Insert a tab character or spaces at current cursor
|
|
664
760
|
insertTab() {
|
|
665
761
|
if (this.config.readOnly) return;
|
|
666
|
-
const e = this.getCursor().position, t = this.textModel.positionToOffset(e),
|
|
762
|
+
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = " ".repeat(this.config.tabSize || 2), s = this.textModel.insertText(e, i), r = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + i.length);
|
|
667
763
|
if (!this.suppressHistory) {
|
|
668
764
|
const n = this.getSelection();
|
|
669
|
-
let o,
|
|
670
|
-
n && (o = this.textModel.positionToOffset(n.start),
|
|
765
|
+
let o, l;
|
|
766
|
+
n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: l }), this.redoStack.length = 0;
|
|
671
767
|
}
|
|
672
768
|
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(r), setTimeout(() => {
|
|
673
769
|
this.expectingProgrammaticCursor = !1;
|
|
674
|
-
}, 20), this.emit("change", [
|
|
770
|
+
}, 20), this.emit("change", [s]);
|
|
675
771
|
}
|
|
676
772
|
// Insert a newline at current cursor position
|
|
677
773
|
insertNewLine() {
|
|
678
774
|
if (this.config.readOnly) return;
|
|
679
|
-
const e = this.getCursor().position, t = this.textModel.positionToOffset(e),
|
|
680
|
-
`),
|
|
775
|
+
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
|
|
776
|
+
`), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
|
|
681
777
|
if (!this.suppressHistory) {
|
|
682
778
|
const r = this.getSelection();
|
|
683
779
|
let n, o;
|
|
684
780
|
r && (n = this.textModel.positionToOffset(r.start), o = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: n, focusOffset: o }), this.redoStack.length = 0;
|
|
685
781
|
}
|
|
686
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(
|
|
782
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
|
|
687
783
|
this.expectingProgrammaticCursor = !1;
|
|
688
|
-
}, 20), this.emit("change", [
|
|
784
|
+
}, 20), this.emit("change", [i]);
|
|
689
785
|
}
|
|
690
786
|
// Events
|
|
691
787
|
on(e, t) {
|
|
@@ -693,15 +789,17 @@ class K {
|
|
|
693
789
|
}
|
|
694
790
|
off(e, t) {
|
|
695
791
|
if (!this.eventListeners.has(e)) return;
|
|
696
|
-
const
|
|
792
|
+
const i = this.eventListeners.get(e);
|
|
697
793
|
if (t) {
|
|
698
|
-
const
|
|
699
|
-
|
|
794
|
+
const s = i.indexOf(t);
|
|
795
|
+
s !== -1 && i.splice(s, 1);
|
|
700
796
|
} else
|
|
701
|
-
|
|
797
|
+
i.length = 0;
|
|
702
798
|
}
|
|
703
|
-
}
|
|
704
|
-
|
|
799
|
+
};
|
|
800
|
+
K.CURSOR_SENTINEL = "";
|
|
801
|
+
let z = K;
|
|
802
|
+
class q {
|
|
705
803
|
constructor(e) {
|
|
706
804
|
this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
|
|
707
805
|
}
|
|
@@ -715,11 +813,11 @@ class V {
|
|
|
715
813
|
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
|
|
716
814
|
}
|
|
717
815
|
findMatchingBinding(e) {
|
|
718
|
-
const { key: t, ctrlKey:
|
|
719
|
-
if (!
|
|
720
|
-
for (const c of
|
|
721
|
-
const
|
|
722
|
-
if (
|
|
816
|
+
const { key: t, ctrlKey: i, altKey: s, shiftKey: r, metaKey: n } = e, o = String(t).toLowerCase(), l = this.keymap[o];
|
|
817
|
+
if (!l) return null;
|
|
818
|
+
for (const c of l) {
|
|
819
|
+
const a = c.ctrlKey === void 0 || c.ctrlKey === i, u = c.altKey === void 0 || c.altKey === s, d = c.shiftKey === void 0 || c.shiftKey === r, g = c.metaKey === void 0 || c.metaKey === n;
|
|
820
|
+
if (a && u && d && g)
|
|
723
821
|
return c;
|
|
724
822
|
}
|
|
725
823
|
return null;
|
|
@@ -732,12 +830,12 @@ class V {
|
|
|
732
830
|
const e = {};
|
|
733
831
|
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;
|
|
734
832
|
}
|
|
735
|
-
addBinding(e, t,
|
|
833
|
+
addBinding(e, t, i, s) {
|
|
736
834
|
const r = t.toLowerCase();
|
|
737
835
|
e[r] || (e[r] = []), e[r].push({
|
|
738
836
|
key: r,
|
|
739
|
-
command:
|
|
740
|
-
...
|
|
837
|
+
command: s,
|
|
838
|
+
...i
|
|
741
839
|
});
|
|
742
840
|
}
|
|
743
841
|
// Public API for customizing keymap
|
|
@@ -746,23 +844,23 @@ class V {
|
|
|
746
844
|
}
|
|
747
845
|
addKeyBinding(e) {
|
|
748
846
|
const t = e.key.toLowerCase();
|
|
749
|
-
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((
|
|
847
|
+
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
|
|
750
848
|
...e,
|
|
751
849
|
key: t
|
|
752
850
|
});
|
|
753
851
|
}
|
|
754
852
|
removeKeyBinding(e, t) {
|
|
755
|
-
const
|
|
756
|
-
t ? this.keymap[
|
|
853
|
+
const i = e.toLowerCase();
|
|
854
|
+
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];
|
|
757
855
|
}
|
|
758
856
|
getKeymap() {
|
|
759
857
|
return { ...this.keymap };
|
|
760
858
|
}
|
|
761
859
|
getBindingsForCommand(e) {
|
|
762
860
|
const t = [];
|
|
763
|
-
for (const
|
|
764
|
-
for (const
|
|
765
|
-
|
|
861
|
+
for (const i in this.keymap)
|
|
862
|
+
for (const s of this.keymap[i])
|
|
863
|
+
s.command === e && t.push({ ...s });
|
|
766
864
|
return t;
|
|
767
865
|
}
|
|
768
866
|
getPlatformInfo() {
|
|
@@ -775,19 +873,19 @@ class V {
|
|
|
775
873
|
this.keymap = {}, this.editor = null;
|
|
776
874
|
}
|
|
777
875
|
}
|
|
778
|
-
class
|
|
876
|
+
class F {
|
|
779
877
|
constructor() {
|
|
780
878
|
this.name = "transaction", this.transactions = [];
|
|
781
879
|
}
|
|
782
880
|
setup(e) {
|
|
783
881
|
e.on("change", (t) => {
|
|
784
|
-
const
|
|
785
|
-
changes:
|
|
882
|
+
const i = {
|
|
883
|
+
changes: t,
|
|
786
884
|
selection: e.getSelection(),
|
|
787
885
|
effects: [],
|
|
788
886
|
annotations: []
|
|
789
887
|
};
|
|
790
|
-
this.transactions.push(
|
|
888
|
+
this.transactions.push(i);
|
|
791
889
|
});
|
|
792
890
|
}
|
|
793
891
|
getTransactions() {
|
|
@@ -797,7 +895,7 @@ class A {
|
|
|
797
895
|
this.transactions = [];
|
|
798
896
|
}
|
|
799
897
|
}
|
|
800
|
-
class
|
|
898
|
+
class _ {
|
|
801
899
|
constructor() {
|
|
802
900
|
this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
|
|
803
901
|
}
|
|
@@ -816,10 +914,11 @@ class U {
|
|
|
816
914
|
updateLineNumbers() {
|
|
817
915
|
if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
|
|
818
916
|
const e = this.editor.getValue().split(`
|
|
819
|
-
`).length, t = Array.from({ length: Math.max(e, 20) }, (
|
|
820
|
-
this.lineNumbersElement.innerHTML = t.map((
|
|
917
|
+
`).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
|
|
918
|
+
this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("");
|
|
821
919
|
}
|
|
822
920
|
toggle() {
|
|
921
|
+
if (!this.editor) return;
|
|
823
922
|
this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
|
|
824
923
|
const e = this.editor.getView().getContentElement();
|
|
825
924
|
e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
|
|
@@ -828,7 +927,7 @@ class U {
|
|
|
828
927
|
this.lineNumbersElement = null, this.editor = null;
|
|
829
928
|
}
|
|
830
929
|
}
|
|
831
|
-
class
|
|
930
|
+
class W {
|
|
832
931
|
constructor() {
|
|
833
932
|
this.name = "theme", this.editor = null, this.currentTheme = "dark";
|
|
834
933
|
}
|
|
@@ -853,7 +952,7 @@ class z {
|
|
|
853
952
|
this.editor = null;
|
|
854
953
|
}
|
|
855
954
|
}
|
|
856
|
-
class
|
|
955
|
+
class D {
|
|
857
956
|
constructor() {
|
|
858
957
|
this.name = "read-only", this.editor = null, this.isReadOnly = !1;
|
|
859
958
|
}
|
|
@@ -880,7 +979,7 @@ class q {
|
|
|
880
979
|
this.editor = null;
|
|
881
980
|
}
|
|
882
981
|
}
|
|
883
|
-
class
|
|
982
|
+
class j {
|
|
884
983
|
constructor() {
|
|
885
984
|
this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1;
|
|
886
985
|
}
|
|
@@ -893,8 +992,8 @@ class F {
|
|
|
893
992
|
this.findPrev();
|
|
894
993
|
}), e.registerCommand("replace", () => {
|
|
895
994
|
this.showReplace();
|
|
896
|
-
}), e.registerCommand("replaceAll", (t,
|
|
897
|
-
this.replaceAll(t,
|
|
995
|
+
}), e.registerCommand("replaceAll", (t, i) => {
|
|
996
|
+
this.replaceAll(t, i);
|
|
898
997
|
});
|
|
899
998
|
}
|
|
900
999
|
showSearch() {
|
|
@@ -905,11 +1004,11 @@ class F {
|
|
|
905
1004
|
}
|
|
906
1005
|
}
|
|
907
1006
|
showReplace() {
|
|
908
|
-
var
|
|
1007
|
+
var i, s;
|
|
909
1008
|
this.showSearch();
|
|
910
|
-
const e = (
|
|
1009
|
+
const e = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-replace-input");
|
|
911
1010
|
e && (e.style.display = "block", e.focus());
|
|
912
|
-
const t = (
|
|
1011
|
+
const t = (s = this.searchUI) == null ? void 0 : s.querySelector(".search-status");
|
|
913
1012
|
t && (t.textContent = "Replace mode - Enter to replace, Shift+Enter to replace all");
|
|
914
1013
|
}
|
|
915
1014
|
hideSearch() {
|
|
@@ -989,35 +1088,35 @@ class F {
|
|
|
989
1088
|
margin-top: 4px;
|
|
990
1089
|
" />
|
|
991
1090
|
`;
|
|
992
|
-
const t = this.searchUI.querySelector("input"),
|
|
1091
|
+
const t = this.searchUI.querySelector("input"), i = this.searchUI.querySelector(".search-replace-input"), s = this.searchUI.querySelector(".search-prev"), r = this.searchUI.querySelector(".search-next"), n = this.searchUI.querySelector(".search-close");
|
|
993
1092
|
t.addEventListener("input", () => {
|
|
994
1093
|
this.performSearch(t.value);
|
|
995
1094
|
}), t.addEventListener("keydown", (o) => {
|
|
996
1095
|
o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.findPrev() : this.findNext());
|
|
997
|
-
}),
|
|
998
|
-
o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.replaceAll(t.value,
|
|
999
|
-
}),
|
|
1096
|
+
}), i.addEventListener("keydown", (o) => {
|
|
1097
|
+
o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.replaceAll(t.value, i.value) : this.replaceCurrent(t.value, i.value));
|
|
1098
|
+
}), s.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), n.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
|
|
1000
1099
|
}
|
|
1001
1100
|
performSearch(e) {
|
|
1002
1101
|
if (!this.editor || !e.trim()) {
|
|
1003
1102
|
this.clearHighlights(), this.updateStatus("");
|
|
1004
1103
|
return;
|
|
1005
1104
|
}
|
|
1006
|
-
const t = this.editor.getValue(),
|
|
1007
|
-
let
|
|
1008
|
-
for (;
|
|
1009
|
-
const r = this.getPositionFromOffset(t,
|
|
1010
|
-
|
|
1105
|
+
const t = this.editor.getValue(), i = [];
|
|
1106
|
+
let s = t.toLowerCase().indexOf(e.toLowerCase());
|
|
1107
|
+
for (; s !== -1; ) {
|
|
1108
|
+
const r = this.getPositionFromOffset(t, s), n = this.getPositionFromOffset(t, s + e.length);
|
|
1109
|
+
i.push({
|
|
1011
1110
|
range: { start: r, end: n },
|
|
1012
|
-
match: t.substring(
|
|
1013
|
-
}),
|
|
1111
|
+
match: t.substring(s, s + e.length)
|
|
1112
|
+
}), s = t.toLowerCase().indexOf(e.toLowerCase(), s + 1);
|
|
1014
1113
|
}
|
|
1015
|
-
this.currentResults =
|
|
1114
|
+
this.currentResults = i, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
|
|
1016
1115
|
}
|
|
1017
1116
|
getPositionFromOffset(e, t) {
|
|
1018
|
-
const
|
|
1019
|
-
`),
|
|
1020
|
-
return { line:
|
|
1117
|
+
const i = e.substring(0, t).split(`
|
|
1118
|
+
`), s = i.length - 1, r = i[i.length - 1].length;
|
|
1119
|
+
return { line: s, column: r };
|
|
1021
1120
|
}
|
|
1022
1121
|
findNext() {
|
|
1023
1122
|
this.currentResults.length !== 0 && (this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights());
|
|
@@ -1027,25 +1126,25 @@ class F {
|
|
|
1027
1126
|
}
|
|
1028
1127
|
replaceCurrent(e, t) {
|
|
1029
1128
|
if (!this.editor || !e.trim() || this.currentIndex === -1) return;
|
|
1030
|
-
const
|
|
1031
|
-
if (!
|
|
1032
|
-
const
|
|
1033
|
-
this.editor.setValue(
|
|
1129
|
+
const i = this.currentResults[this.currentIndex];
|
|
1130
|
+
if (!i) return;
|
|
1131
|
+
const s = this.editor.getValue(), r = this.getOffsetFromPosition(s, i.range.start), n = s.substring(0, r), o = s.substring(r + e.length), l = n + t + o;
|
|
1132
|
+
this.editor.setValue(l), this.performSearch(e), this.updateStatus("Replaced current occurrence");
|
|
1034
1133
|
}
|
|
1035
1134
|
replaceAll(e, t) {
|
|
1036
1135
|
if (!this.editor || !e.trim()) return;
|
|
1037
|
-
let
|
|
1136
|
+
let i = this.editor.getValue(), s = 0, r = i.toLowerCase().indexOf(e.toLowerCase());
|
|
1038
1137
|
for (; r !== -1; )
|
|
1039
|
-
|
|
1040
|
-
|
|
1138
|
+
i = i.substring(0, r) + t + i.substring(r + e.length), s++, r = i.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
|
|
1139
|
+
s > 0 && (this.editor.setValue(i), this.updateStatus(`Replaced ${s} occurrences`));
|
|
1041
1140
|
}
|
|
1042
1141
|
getOffsetFromPosition(e, t) {
|
|
1043
|
-
const
|
|
1142
|
+
const i = e.split(`
|
|
1044
1143
|
`);
|
|
1045
|
-
let
|
|
1144
|
+
let s = 0;
|
|
1046
1145
|
for (let r = 0; r < t.line; r++)
|
|
1047
|
-
|
|
1048
|
-
return
|
|
1146
|
+
s += i[r].length + 1;
|
|
1147
|
+
return s += t.column, s;
|
|
1049
1148
|
}
|
|
1050
1149
|
updateHighlights() {
|
|
1051
1150
|
this.clearHighlights(), !(this.currentResults.length === 0 || this.currentIndex === -1) && (this.currentResults[this.currentIndex], this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`));
|
|
@@ -1053,15 +1152,15 @@ class F {
|
|
|
1053
1152
|
clearHighlights() {
|
|
1054
1153
|
}
|
|
1055
1154
|
updateStatus(e) {
|
|
1056
|
-
var
|
|
1057
|
-
const t = (
|
|
1155
|
+
var i;
|
|
1156
|
+
const t = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-status");
|
|
1058
1157
|
t && (t.textContent = e);
|
|
1059
1158
|
}
|
|
1060
1159
|
destroy() {
|
|
1061
1160
|
this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.searchUI = null, this.editor = null;
|
|
1062
1161
|
}
|
|
1063
1162
|
}
|
|
1064
|
-
class
|
|
1163
|
+
class Z {
|
|
1065
1164
|
constructor() {
|
|
1066
1165
|
this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
|
|
1067
1166
|
"(": ")",
|
|
@@ -1086,57 +1185,57 @@ class _ {
|
|
|
1086
1185
|
if (!this.editor) return;
|
|
1087
1186
|
const e = this.editor.getCursor(), t = this.editor.getValue();
|
|
1088
1187
|
this.clearBracketHighlighting();
|
|
1089
|
-
const
|
|
1090
|
-
if (!
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1188
|
+
const i = this.getBracketAtPosition(t, e.position);
|
|
1189
|
+
if (!i) return;
|
|
1190
|
+
const s = this.findMatchingBracket(t, i);
|
|
1191
|
+
s && (this.currentMatch = s, this.highlightBrackets(s));
|
|
1093
1192
|
}
|
|
1094
1193
|
getBracketAtPosition(e, t) {
|
|
1095
|
-
const
|
|
1194
|
+
const i = e.split(`
|
|
1096
1195
|
`);
|
|
1097
|
-
if (t.line >=
|
|
1098
|
-
const
|
|
1099
|
-
if (t.column >=
|
|
1100
|
-
const r =
|
|
1196
|
+
if (t.line >= i.length) return null;
|
|
1197
|
+
const s = i[t.line];
|
|
1198
|
+
if (t.column >= s.length) return null;
|
|
1199
|
+
const r = s[t.column];
|
|
1101
1200
|
return this.bracketPairs[r] || this.reverseBracketPairs[r] ? { char: r, position: t } : null;
|
|
1102
1201
|
}
|
|
1103
1202
|
findMatchingBracket(e, t) {
|
|
1104
|
-
const
|
|
1105
|
-
`),
|
|
1106
|
-
return this.bracketPairs[n] ? this.findClosingBracket(e,
|
|
1203
|
+
const i = e.split(`
|
|
1204
|
+
`), s = t.position.line, r = t.position.column, n = t.char;
|
|
1205
|
+
return this.bracketPairs[n] ? this.findClosingBracket(e, i, s, r, n) : this.reverseBracketPairs[n] ? this.findOpeningBracket(e, i, s, r, n) : null;
|
|
1107
1206
|
}
|
|
1108
|
-
findClosingBracket(e, t,
|
|
1207
|
+
findClosingBracket(e, t, i, s, r) {
|
|
1109
1208
|
const n = this.bracketPairs[r];
|
|
1110
1209
|
let o = 0;
|
|
1111
|
-
for (let
|
|
1112
|
-
const c = t[
|
|
1113
|
-
for (let
|
|
1114
|
-
const
|
|
1115
|
-
if (
|
|
1210
|
+
for (let l = i; l < t.length; l++) {
|
|
1211
|
+
const c = t[l], a = l === i ? s : 0;
|
|
1212
|
+
for (let u = a; u < c.length; u++) {
|
|
1213
|
+
const d = c[u];
|
|
1214
|
+
if (d === r)
|
|
1116
1215
|
o++;
|
|
1117
|
-
else if (
|
|
1216
|
+
else if (d === n && (o--, o === 0))
|
|
1118
1217
|
return {
|
|
1119
|
-
open: { start: { line:
|
|
1120
|
-
close: { start: { line:
|
|
1218
|
+
open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1219
|
+
close: { start: { line: l, column: u }, end: { line: l, column: u + 1 } },
|
|
1121
1220
|
type: r
|
|
1122
1221
|
};
|
|
1123
1222
|
}
|
|
1124
1223
|
}
|
|
1125
1224
|
return null;
|
|
1126
1225
|
}
|
|
1127
|
-
findOpeningBracket(e, t,
|
|
1226
|
+
findOpeningBracket(e, t, i, s, r) {
|
|
1128
1227
|
const n = this.reverseBracketPairs[r];
|
|
1129
1228
|
let o = 0;
|
|
1130
|
-
for (let
|
|
1131
|
-
const c = t[
|
|
1132
|
-
for (let
|
|
1133
|
-
const
|
|
1134
|
-
if (
|
|
1229
|
+
for (let l = i; l >= 0; l--) {
|
|
1230
|
+
const c = t[l], a = l === i ? s : c.length - 1;
|
|
1231
|
+
for (let u = a; u >= 0; u--) {
|
|
1232
|
+
const d = c[u];
|
|
1233
|
+
if (d === r)
|
|
1135
1234
|
o++;
|
|
1136
|
-
else if (
|
|
1235
|
+
else if (d === n && (o--, o === 0))
|
|
1137
1236
|
return {
|
|
1138
|
-
open: { start: { line:
|
|
1139
|
-
close: { start: { line:
|
|
1237
|
+
open: { start: { line: l, column: u }, end: { line: l, column: u + 1 } },
|
|
1238
|
+
close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1140
1239
|
type: n
|
|
1141
1240
|
};
|
|
1142
1241
|
}
|
|
@@ -1155,7 +1254,7 @@ class _ {
|
|
|
1155
1254
|
this.clearBracketHighlighting(), this.editor = null;
|
|
1156
1255
|
}
|
|
1157
1256
|
}
|
|
1158
|
-
class
|
|
1257
|
+
class J {
|
|
1159
1258
|
constructor() {
|
|
1160
1259
|
this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;
|
|
1161
1260
|
}
|
|
@@ -1196,9 +1295,9 @@ class D {
|
|
|
1196
1295
|
}
|
|
1197
1296
|
findFoldableLines(e) {
|
|
1198
1297
|
const t = [];
|
|
1199
|
-
for (let
|
|
1200
|
-
const
|
|
1201
|
-
(
|
|
1298
|
+
for (let i = 0; i < e.length; i++) {
|
|
1299
|
+
const s = e[i].trim();
|
|
1300
|
+
(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);
|
|
1202
1301
|
}
|
|
1203
1302
|
return t;
|
|
1204
1303
|
}
|
|
@@ -1234,12 +1333,12 @@ class D {
|
|
|
1234
1333
|
this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.foldingUI = null, this.foldIndicators = [], this.editor = null;
|
|
1235
1334
|
}
|
|
1236
1335
|
}
|
|
1237
|
-
class
|
|
1336
|
+
class X {
|
|
1238
1337
|
constructor() {
|
|
1239
1338
|
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
|
|
1240
1339
|
}
|
|
1241
1340
|
setup(e) {
|
|
1242
|
-
this.editor = e, this.registerMode("html", { name: "html", highlight: (t,
|
|
1341
|
+
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) });
|
|
1243
1342
|
}
|
|
1244
1343
|
// Extension provides methods that can be called by the editor
|
|
1245
1344
|
setTheme(e) {
|
|
@@ -1299,8 +1398,8 @@ class W {
|
|
|
1299
1398
|
}
|
|
1300
1399
|
// Public API: highlight a source string using the chosen mode (or detect html)
|
|
1301
1400
|
highlight(e, t) {
|
|
1302
|
-
const
|
|
1303
|
-
return (this.modes.get(
|
|
1401
|
+
const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
|
|
1402
|
+
return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
|
|
1304
1403
|
}
|
|
1305
1404
|
// Backwards-compatible method
|
|
1306
1405
|
highlightHTML(e) {
|
|
@@ -1313,125 +1412,128 @@ class W {
|
|
|
1313
1412
|
// Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;...
|
|
1314
1413
|
unescapeEntitiesRepeated(e) {
|
|
1315
1414
|
let t = e || "";
|
|
1316
|
-
for (let
|
|
1317
|
-
const
|
|
1318
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t ===
|
|
1415
|
+
for (let i = 0; i < 5; i++) {
|
|
1416
|
+
const s = t;
|
|
1417
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === s) break;
|
|
1319
1418
|
}
|
|
1320
1419
|
return t;
|
|
1321
1420
|
}
|
|
1322
1421
|
_highlightHTML(e, t) {
|
|
1323
|
-
const
|
|
1324
|
-
let r =
|
|
1422
|
+
const i = t, s = (c) => this.escapeHTML(c);
|
|
1423
|
+
let r = s(e);
|
|
1325
1424
|
const n = (c) => {
|
|
1326
|
-
let
|
|
1327
|
-
return
|
|
1328
|
-
const p = String(
|
|
1329
|
-
return `<span style="color: ${
|
|
1330
|
-
}),
|
|
1425
|
+
let a = c.replace(/"/g, '"').replace(/'/g, "'");
|
|
1426
|
+
return a = a.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), a = a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (u, d, g, h, f) => {
|
|
1427
|
+
const p = String(h).trim(), x = s(p);
|
|
1428
|
+
return `<span style="color: ${i.styleProp};">${d}</span>${g}<span style="color: ${i.styleVal};">${x}</span>${f}`;
|
|
1429
|
+
}), a;
|
|
1331
1430
|
}, o = [];
|
|
1332
1431
|
try {
|
|
1333
|
-
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (c,
|
|
1432
|
+
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (c, a, u) => (o.push({ attrs: String(a || ""), inner: String(u || "") }), c));
|
|
1334
1433
|
} catch (c) {
|
|
1335
1434
|
}
|
|
1336
|
-
let
|
|
1337
|
-
return r = r.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (c,
|
|
1338
|
-
var p, x,
|
|
1339
|
-
const
|
|
1340
|
-
(((
|
|
1341
|
-
const f = this._highlightJS(
|
|
1342
|
-
return `${
|
|
1343
|
-
}), r = r.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (c,
|
|
1344
|
-
const g = n(
|
|
1345
|
-
return `${
|
|
1346
|
-
}), r = r.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${
|
|
1347
|
-
const
|
|
1348
|
-
let f =
|
|
1349
|
-
return f = f.replace(
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1435
|
+
let l = 0;
|
|
1436
|
+
return r = r.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (c, a, u, d, g) => {
|
|
1437
|
+
var p, x, k;
|
|
1438
|
+
const h = (x = (p = o[l++]) == null ? void 0 : p.inner) != null ? x : this.unescapeEntitiesRepeated(d || "");
|
|
1439
|
+
(((k = o[l - 1]) == null ? void 0 : k.attrs) || u || "").toLowerCase();
|
|
1440
|
+
const f = this._highlightJS(h, i);
|
|
1441
|
+
return `${a}${f}${g}`;
|
|
1442
|
+
}), r = r.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (c, a, u, d) => {
|
|
1443
|
+
const g = n(u);
|
|
1444
|
+
return `${a}${g}${d}`;
|
|
1445
|
+
}), r = r.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${i.comment};">$1</span>`), r = r.replace(/(<!DOCTYPE[\s\S]*?>)/i, `<span style="color: ${i.doctype};">$1</span>`), r = r.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g, (c, a, u, d, g) => {
|
|
1446
|
+
const h = `<span style="color: ${i.tag};">${u}</span>`;
|
|
1447
|
+
let f = d;
|
|
1448
|
+
return f = f.replace(
|
|
1449
|
+
/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,
|
|
1450
|
+
(p, x, k, y) => {
|
|
1451
|
+
const R = String(x).toLowerCase(), H = `<span style="color: ${i.attrName};">${x}</span>`;
|
|
1452
|
+
let T = y, b = "";
|
|
1453
|
+
y.startsWith(""") && y.endsWith(""") ? (T = y.slice(6, -6), b = """) : y.startsWith("'") && y.endsWith("'") && (T = y.slice(5, -5), b = "'");
|
|
1454
|
+
let w = y;
|
|
1455
|
+
if (R === "style") {
|
|
1456
|
+
const S = T.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (N, E, L, O) => `<span style="color: ${i.styleProp};">${E}</span>:<span style="color: ${i.styleVal};">${L.trim()}</span>${O}`);
|
|
1457
|
+
b ? w = `${b}${S}${b}` : w = S, w = `<span style="color: ${i.attrValue};">${w}</span>`;
|
|
1458
|
+
} else
|
|
1459
|
+
b && (w = `${b}${T}${b}`), w = `<span style="color: ${i.attrValue};">${w}</span>`;
|
|
1460
|
+
return `${H}${k}${w}`;
|
|
1461
|
+
}
|
|
1462
|
+
), `${a}${h}${f}${g}`;
|
|
1361
1463
|
}), r;
|
|
1362
1464
|
}
|
|
1363
1465
|
_highlightJS(e, t) {
|
|
1364
|
-
const
|
|
1365
|
-
this.escapeHTML(
|
|
1366
|
-
const
|
|
1367
|
-
let g = "",
|
|
1466
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
1467
|
+
this.escapeHTML(i);
|
|
1468
|
+
const s = [], r = (d) => {
|
|
1469
|
+
let g = "", h = d;
|
|
1368
1470
|
do
|
|
1369
|
-
g = String.fromCharCode(97 +
|
|
1370
|
-
while (
|
|
1471
|
+
g = String.fromCharCode(97 + h % 26) + g, h = Math.floor(h / 26) - 1;
|
|
1472
|
+
while (h >= 0);
|
|
1371
1473
|
return g || "a";
|
|
1372
|
-
}, n = (
|
|
1373
|
-
const g =
|
|
1374
|
-
return
|
|
1474
|
+
}, n = (d) => `\0${r(d)}\0`, o = (d) => {
|
|
1475
|
+
const g = s.length;
|
|
1476
|
+
return s.push(d), n(g);
|
|
1375
1477
|
};
|
|
1376
|
-
let
|
|
1478
|
+
let l;
|
|
1377
1479
|
const c = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
1378
|
-
let
|
|
1379
|
-
for (;
|
|
1380
|
-
const
|
|
1381
|
-
|
|
1382
|
-
const g =
|
|
1383
|
-
/^\/\*/.test(g) || /^\/\//.test(g) ?
|
|
1480
|
+
let a = 0, u = "";
|
|
1481
|
+
for (; l = c.exec(i); ) {
|
|
1482
|
+
const d = l.index;
|
|
1483
|
+
a < d && (u += this.escapeHTML(i.slice(a, d)));
|
|
1484
|
+
const g = l[0];
|
|
1485
|
+
/^\/\*/.test(g) || /^\/\//.test(g) ? u += o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`) : u += o(`<span style="color: ${t.string};">${this.escapeHTML(g)}</span>`), a = c.lastIndex;
|
|
1384
1486
|
}
|
|
1385
|
-
return
|
|
1386
|
-
const f = h
|
|
1387
|
-
return f === "&" || f === "#" || p === ";" || p === "#" ?
|
|
1388
|
-
}),
|
|
1389
|
-
let
|
|
1487
|
+
return a < i.length && (u += this.escapeHTML(i.slice(a))), u = u.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, g, h) => {
|
|
1488
|
+
const f = u[h - 1] || "", p = u[h + d.length] || "";
|
|
1489
|
+
return f === "&" || f === "#" || p === ";" || p === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
|
|
1490
|
+
}), u = u.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>`), u.replace(/\u0000([a-z]+)\u0000/g, (d, g) => {
|
|
1491
|
+
let h = 0;
|
|
1390
1492
|
for (let f = 0; f < g.length; f++)
|
|
1391
|
-
|
|
1392
|
-
return
|
|
1493
|
+
h = h * 26 + (g.charCodeAt(f) - 97 + 1);
|
|
1494
|
+
return h = h - 1, s[h] || "";
|
|
1393
1495
|
});
|
|
1394
1496
|
}
|
|
1395
1497
|
_highlightPHP(e, t) {
|
|
1396
|
-
const
|
|
1397
|
-
let
|
|
1398
|
-
const r = [], n = (
|
|
1399
|
-
let f = "", p =
|
|
1498
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
1499
|
+
let s = this.escapeHTML(i);
|
|
1500
|
+
const r = [], n = (h) => {
|
|
1501
|
+
let f = "", p = h;
|
|
1400
1502
|
do
|
|
1401
1503
|
f = String.fromCharCode(97 + p % 26) + f, p = Math.floor(p / 26) - 1;
|
|
1402
1504
|
while (p >= 0);
|
|
1403
1505
|
return f || "a";
|
|
1404
|
-
}, o = (
|
|
1506
|
+
}, o = (h) => {
|
|
1405
1507
|
const f = r.length;
|
|
1406
|
-
return r.push(
|
|
1407
|
-
},
|
|
1408
|
-
const p =
|
|
1409
|
-
return p === -1 ? !1 : (
|
|
1508
|
+
return r.push(h), `\0${n(f)}\0`;
|
|
1509
|
+
}, l = (h, f) => {
|
|
1510
|
+
const p = s.indexOf(h);
|
|
1511
|
+
return p === -1 ? !1 : (s = s.slice(0, p) + f + s.slice(p + h.length), !0);
|
|
1410
1512
|
};
|
|
1411
1513
|
let c;
|
|
1412
|
-
const
|
|
1413
|
-
for (; c =
|
|
1414
|
-
const
|
|
1415
|
-
|
|
1514
|
+
const a = /\/\*[\s\S]*?\*\//g, u = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, g = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
1515
|
+
for (; c = a.exec(i); ) {
|
|
1516
|
+
const h = c[0];
|
|
1517
|
+
l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
|
|
1416
1518
|
}
|
|
1417
|
-
for (; c =
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1519
|
+
for (; c = u.exec(i); ) {
|
|
1520
|
+
const h = c[0];
|
|
1521
|
+
l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
|
|
1420
1522
|
}
|
|
1421
|
-
for (; c =
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1523
|
+
for (; c = d.exec(i); ) {
|
|
1524
|
+
const h = c[0];
|
|
1525
|
+
l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
|
|
1424
1526
|
}
|
|
1425
|
-
for (; c = g.exec(
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1527
|
+
for (; c = g.exec(i); ) {
|
|
1528
|
+
const h = c[0];
|
|
1529
|
+
l(this.escapeHTML(h), o(`<span style="color: ${t.string};">${this.escapeHTML(h)}</span>`));
|
|
1428
1530
|
}
|
|
1429
|
-
return
|
|
1531
|
+
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, (h, f) => {
|
|
1430
1532
|
let p = 0;
|
|
1431
1533
|
for (let x = 0; x < f.length; x++)
|
|
1432
1534
|
p = p * 26 + (f.charCodeAt(x) - 97 + 1);
|
|
1433
1535
|
return p = p - 1, r[p] || "";
|
|
1434
|
-
}),
|
|
1536
|
+
}), s;
|
|
1435
1537
|
}
|
|
1436
1538
|
// Method to check if content contains syntax that should be highlighted
|
|
1437
1539
|
shouldHighlight(e) {
|
|
@@ -1441,11 +1543,11 @@ class W {
|
|
|
1441
1543
|
this.editor = null, this.modes.clear();
|
|
1442
1544
|
}
|
|
1443
1545
|
}
|
|
1444
|
-
function
|
|
1546
|
+
function Y(v, e) {
|
|
1445
1547
|
const t = { ...e };
|
|
1446
|
-
return t.extensions || (t.extensions = []), t.extensions.some((
|
|
1548
|
+
return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new q(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new F()), new z(v, t);
|
|
1447
1549
|
}
|
|
1448
|
-
const
|
|
1550
|
+
const $ = '[data-theme="dark"], .dark, .editora-theme-dark', G = `/* Source Editor Dialog Styles */
|
|
1449
1551
|
.rte-source-editor-overlay {
|
|
1450
1552
|
position: fixed !important;
|
|
1451
1553
|
top: 0 !important;
|
|
@@ -1714,64 +1816,83 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1714
1816
|
background: #0056b3;
|
|
1715
1817
|
}
|
|
1716
1818
|
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
}
|
|
1819
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
|
|
1820
|
+
background: #1e1e1e;
|
|
1821
|
+
color: #f8f9fa;
|
|
1822
|
+
border: 1px solid #434d5f;
|
|
1823
|
+
}
|
|
1723
1824
|
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1825
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
|
|
1826
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
|
|
1827
|
+
background: #2a3442;
|
|
1828
|
+
border-color: #434d5f;
|
|
1829
|
+
}
|
|
1728
1830
|
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1831
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
|
|
1832
|
+
color: #f8f9fa;
|
|
1833
|
+
}
|
|
1732
1834
|
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1835
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
|
|
1836
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
|
|
1837
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
|
|
1838
|
+
color: #c1cede;
|
|
1839
|
+
}
|
|
1737
1840
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1841
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
|
|
1842
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
|
|
1843
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
|
|
1844
|
+
background: #404a5a;
|
|
1845
|
+
color: #f8fafc;
|
|
1846
|
+
}
|
|
1743
1847
|
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
}
|
|
1848
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
|
|
1849
|
+
background: #3b82f6;
|
|
1850
|
+
color: #ffffff;
|
|
1851
|
+
}
|
|
1749
1852
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
border-color: #d97706;
|
|
1754
|
-
}
|
|
1853
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
|
|
1854
|
+
background: #2563eb;
|
|
1855
|
+
}
|
|
1755
1856
|
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1857
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
|
|
1858
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
|
|
1859
|
+
color: #cbd5e1;
|
|
1860
|
+
}
|
|
1760
1861
|
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1862
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
|
|
1863
|
+
border-color: #3f4b60;
|
|
1864
|
+
border-top-color: #58a6ff;
|
|
1865
|
+
}
|
|
1764
1866
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1867
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
|
|
1868
|
+
background: #3f2124;
|
|
1869
|
+
color: #fecaca;
|
|
1870
|
+
border-color: #ef4444;
|
|
1871
|
+
}
|
|
1770
1872
|
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1873
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
|
|
1874
|
+
background: #3b3220;
|
|
1875
|
+
color: #fde68a;
|
|
1876
|
+
border-color: #f59e0b;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
|
|
1880
|
+
background: #334155;
|
|
1881
|
+
border-color: #475569;
|
|
1882
|
+
color: #f1f5f9;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
|
|
1886
|
+
background: #475569;
|
|
1887
|
+
border-color: #64748b;
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
|
|
1891
|
+
background: #3b82f6;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
.rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
|
|
1895
|
+
background: #2563eb;
|
|
1775
1896
|
}
|
|
1776
1897
|
|
|
1777
1898
|
/* Responsive design */
|
|
@@ -1803,15 +1924,15 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1803
1924
|
flex: 1;
|
|
1804
1925
|
text-align: center;
|
|
1805
1926
|
}
|
|
1806
|
-
}`,
|
|
1927
|
+
}`, ee = () => ({
|
|
1807
1928
|
name: "code",
|
|
1808
1929
|
// Toolbar button configuration
|
|
1809
1930
|
toolbar: [
|
|
1810
1931
|
{
|
|
1811
1932
|
label: "Source",
|
|
1812
1933
|
command: "toggleSourceView",
|
|
1813
|
-
type: "button",
|
|
1814
|
-
icon: "
|
|
1934
|
+
// type: "button",
|
|
1935
|
+
icon: '<svg width="24" height="24" focusable="false"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7ZM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7Z"></path></g></svg>',
|
|
1815
1936
|
shortcut: "Mod-Shift-S"
|
|
1816
1937
|
}
|
|
1817
1938
|
],
|
|
@@ -1823,56 +1944,62 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1823
1944
|
*/
|
|
1824
1945
|
toggleSourceView: () => {
|
|
1825
1946
|
const e = (() => {
|
|
1826
|
-
var o,
|
|
1947
|
+
var o, l, c;
|
|
1827
1948
|
const r = window.getSelection();
|
|
1828
1949
|
if (r && r.anchorNode) {
|
|
1829
|
-
let
|
|
1830
|
-
for (;
|
|
1831
|
-
if ((o =
|
|
1832
|
-
return
|
|
1833
|
-
|
|
1950
|
+
let a = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
|
|
1951
|
+
for (; a; ) {
|
|
1952
|
+
if ((o = a.classList) != null && o.contains("rte-content"))
|
|
1953
|
+
return a;
|
|
1954
|
+
a = a.parentElement;
|
|
1834
1955
|
}
|
|
1835
1956
|
}
|
|
1836
1957
|
if (document.activeElement) {
|
|
1837
|
-
let
|
|
1838
|
-
if ((
|
|
1839
|
-
return
|
|
1840
|
-
for (;
|
|
1841
|
-
if ((c =
|
|
1842
|
-
return
|
|
1843
|
-
const
|
|
1844
|
-
|
|
1845
|
-
|
|
1958
|
+
let a = document.activeElement;
|
|
1959
|
+
if ((l = a.classList) != null && l.contains("rte-content"))
|
|
1960
|
+
return a;
|
|
1961
|
+
for (; a && a !== document.body; ) {
|
|
1962
|
+
if ((c = a.classList) != null && c.contains("rte-content"))
|
|
1963
|
+
return a;
|
|
1964
|
+
const u = a.querySelector(
|
|
1965
|
+
".rte-content"
|
|
1966
|
+
);
|
|
1967
|
+
if (u) return u;
|
|
1968
|
+
a = a.parentElement;
|
|
1846
1969
|
}
|
|
1847
1970
|
}
|
|
1848
1971
|
const n = document.querySelector("[data-editora-editor]");
|
|
1849
1972
|
if (n) {
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1973
|
+
const a = n.querySelector(
|
|
1974
|
+
".rte-content"
|
|
1975
|
+
);
|
|
1976
|
+
if (a) return a;
|
|
1852
1977
|
}
|
|
1853
1978
|
return document.querySelector(".rte-content");
|
|
1854
1979
|
})();
|
|
1855
1980
|
if (!e)
|
|
1856
|
-
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
1857
|
-
|
|
1981
|
+
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
1982
|
+
"Editor content area not found. Please click inside the editor first."
|
|
1983
|
+
), !1;
|
|
1984
|
+
const t = e.innerHTML, i = (r) => {
|
|
1858
1985
|
let n = "", o = 0;
|
|
1859
|
-
const
|
|
1860
|
-
for (const
|
|
1861
|
-
|
|
1862
|
-
` + " ".repeat(o *
|
|
1863
|
-
` + " ".repeat(o *
|
|
1864
|
-
` + " ".repeat(o *
|
|
1986
|
+
const l = 2, c = r.split(/(<\/?[a-zA-Z][^>]*>)/);
|
|
1987
|
+
for (const a of c)
|
|
1988
|
+
a.trim() && (a.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), n += `
|
|
1989
|
+
` + " ".repeat(o * l) + a) : a.match(/^<[a-zA-Z]/) && !a.match(/\/>$/) ? (n += `
|
|
1990
|
+
` + " ".repeat(o * l) + a, o++) : a.match(/^<[a-zA-Z].*\/>$/) ? n += `
|
|
1991
|
+
` + " ".repeat(o * l) + a : n += a.trim());
|
|
1865
1992
|
return n.trim();
|
|
1866
1993
|
};
|
|
1867
1994
|
return (() => {
|
|
1868
|
-
var
|
|
1869
|
-
let r = null, n = "dark", o = !1,
|
|
1870
|
-
const
|
|
1871
|
-
|
|
1872
|
-
const u = document.createElement("div");
|
|
1873
|
-
u.className = "rte-source-editor-modal", u.setAttribute("role", "dialog"), u.setAttribute("aria-modal", "true"), u.setAttribute("aria-labelledby", "source-editor-title");
|
|
1995
|
+
var E, L, O, I, A, B;
|
|
1996
|
+
let r = null, n = "dark", o = !1, l = !1, c = !1;
|
|
1997
|
+
const a = t, u = !!e.closest($) || document.body.matches($) || document.documentElement.matches($), d = document.createElement("div");
|
|
1998
|
+
d.className = "rte-source-editor-overlay", u && d.classList.add("rte-theme-dark");
|
|
1874
1999
|
const g = document.createElement("div");
|
|
1875
|
-
g.className = "rte-source-editor-
|
|
2000
|
+
g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
|
|
2001
|
+
const h = document.createElement("div");
|
|
2002
|
+
h.className = "rte-source-editor-header", h.innerHTML = `
|
|
1876
2003
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
1877
2004
|
<div class="rte-source-editor-header-toolbar">
|
|
1878
2005
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -1909,14 +2036,14 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1909
2036
|
</button>
|
|
1910
2037
|
</div>
|
|
1911
2038
|
`;
|
|
1912
|
-
const d = document.createElement("div");
|
|
1913
|
-
d.className = "rte-source-editor-body";
|
|
1914
2039
|
const f = document.createElement("div");
|
|
1915
|
-
f.className = "rte-source-editor-
|
|
2040
|
+
f.className = "rte-source-editor-body";
|
|
1916
2041
|
const p = document.createElement("div");
|
|
1917
|
-
p.className = "rte-source-editor-
|
|
2042
|
+
p.className = "rte-source-editor-content";
|
|
1918
2043
|
const x = document.createElement("div");
|
|
1919
|
-
x.className = "rte-source-editor-
|
|
2044
|
+
x.className = "rte-source-editor-warning", x.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
|
|
2045
|
+
const k = document.createElement("div");
|
|
2046
|
+
k.className = "rte-source-editor-light-editor", k.style.height = "400px", p.appendChild(x), p.appendChild(k), f.appendChild(p);
|
|
1920
2047
|
const y = document.createElement("div");
|
|
1921
2048
|
if (y.className = "rte-source-editor-footer", y.innerHTML = `
|
|
1922
2049
|
<div class="rte-source-editor-footer-info">
|
|
@@ -1926,44 +2053,46 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1926
2053
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
1927
2054
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
1928
2055
|
</div>
|
|
1929
|
-
`,
|
|
2056
|
+
`, g.appendChild(h), g.appendChild(f), g.appendChild(y), d.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
|
|
1930
2057
|
const m = document.createElement("style");
|
|
1931
|
-
m.id = "rte-source-editor-styles", m.textContent =
|
|
2058
|
+
m.id = "rte-source-editor-styles", m.textContent = G, document.head.appendChild(m);
|
|
1932
2059
|
}
|
|
1933
|
-
document.body.appendChild(
|
|
2060
|
+
document.body.appendChild(d);
|
|
1934
2061
|
try {
|
|
1935
|
-
r =
|
|
1936
|
-
value:
|
|
2062
|
+
r = Y(k, {
|
|
2063
|
+
value: i(t),
|
|
1937
2064
|
theme: "dark",
|
|
1938
2065
|
readOnly: !1,
|
|
1939
2066
|
extensions: [
|
|
1940
|
-
new U(),
|
|
1941
|
-
new z(),
|
|
1942
|
-
new q(),
|
|
1943
2067
|
new _(),
|
|
1944
|
-
new
|
|
2068
|
+
new W(),
|
|
1945
2069
|
new D(),
|
|
1946
|
-
new
|
|
2070
|
+
new Z(),
|
|
2071
|
+
new j(),
|
|
2072
|
+
new J(),
|
|
2073
|
+
new X()
|
|
1947
2074
|
]
|
|
1948
2075
|
}), r.on("change", () => {
|
|
1949
|
-
c = ((r == null ? void 0 : r.getValue()) || "") !==
|
|
1950
|
-
const
|
|
1951
|
-
|
|
2076
|
+
c = ((r == null ? void 0 : r.getValue()) || "") !== i(a);
|
|
2077
|
+
const C = y.querySelector(
|
|
2078
|
+
".unsaved-changes"
|
|
2079
|
+
);
|
|
2080
|
+
C && (C.style.display = c ? "inline" : "none");
|
|
1952
2081
|
}), setTimeout(() => r == null ? void 0 : r.focus(), 100);
|
|
1953
2082
|
} catch (m) {
|
|
1954
2083
|
console.error("Failed to initialize code editor:", m);
|
|
1955
2084
|
}
|
|
1956
|
-
const
|
|
2085
|
+
const R = () => {
|
|
1957
2086
|
n = n === "dark" ? "light" : "dark", r == null || r.setTheme(n);
|
|
1958
|
-
const m =
|
|
2087
|
+
const m = h.querySelector(".theme-toggle-btn");
|
|
1959
2088
|
m && n === "light" && (m.innerHTML = `
|
|
1960
2089
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1961
2090
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
1962
2091
|
</svg>
|
|
1963
2092
|
`);
|
|
1964
|
-
},
|
|
2093
|
+
}, H = () => {
|
|
1965
2094
|
o = !o, r == null || r.setReadOnly(o);
|
|
1966
|
-
const m =
|
|
2095
|
+
const m = h.querySelector(".readonly-toggle-btn");
|
|
1967
2096
|
m && (o ? (m.classList.add("active"), m.innerHTML = `
|
|
1968
2097
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1969
2098
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
@@ -1976,10 +2105,12 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1976
2105
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
1977
2106
|
</svg>
|
|
1978
2107
|
`));
|
|
1979
|
-
},
|
|
1980
|
-
|
|
1981
|
-
const m =
|
|
1982
|
-
|
|
2108
|
+
}, T = () => {
|
|
2109
|
+
l = !l, l ? (d.classList.add("fullscreen"), k.style.height = "calc(100vh - 200px)") : (d.classList.remove("fullscreen"), k.style.height = "400px");
|
|
2110
|
+
const m = h.querySelector(
|
|
2111
|
+
".rte-source-editor-fullscreen-btn"
|
|
2112
|
+
);
|
|
2113
|
+
m && (m.innerHTML = l ? `
|
|
1983
2114
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1984
2115
|
<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"/>
|
|
1985
2116
|
</svg>
|
|
@@ -1988,25 +2119,45 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
1988
2119
|
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
1989
2120
|
</svg>
|
|
1990
2121
|
`);
|
|
1991
|
-
},
|
|
1992
|
-
r && (r.destroy(), r = null), document.body.removeChild(
|
|
1993
|
-
}, k = () => {
|
|
1994
|
-
c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || T();
|
|
2122
|
+
}, b = () => {
|
|
2123
|
+
r && (r.destroy(), r = null), document.body.removeChild(d);
|
|
1995
2124
|
}, w = () => {
|
|
2125
|
+
c && !confirm(
|
|
2126
|
+
"You have unsaved changes. Are you sure you want to cancel?"
|
|
2127
|
+
) || b();
|
|
2128
|
+
}, S = () => {
|
|
1996
2129
|
try {
|
|
1997
|
-
const m = (r == null ? void 0 : r.getValue()) || "",
|
|
1998
|
-
|
|
2130
|
+
const m = (r == null ? void 0 : r.getValue()) || "", C = document.createElement("div");
|
|
2131
|
+
C.innerHTML = m, C.querySelectorAll(
|
|
2132
|
+
'script, iframe[src^="javascript:"], object, embed'
|
|
2133
|
+
).forEach((V) => V.remove()), e.innerHTML = C.innerHTML;
|
|
2134
|
+
try {
|
|
2135
|
+
e.dispatchEvent(
|
|
2136
|
+
new InputEvent("input", {
|
|
2137
|
+
bubbles: !0,
|
|
2138
|
+
cancelable: !1,
|
|
2139
|
+
inputType: "insertReplacementText"
|
|
2140
|
+
})
|
|
2141
|
+
);
|
|
2142
|
+
} catch (V) {
|
|
2143
|
+
e.dispatchEvent(
|
|
2144
|
+
new Event("input", { bubbles: !0 })
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
e.dispatchEvent(
|
|
2148
|
+
new Event("change", { bubbles: !0 })
|
|
2149
|
+
), c = !1, b();
|
|
1999
2150
|
} catch (m) {
|
|
2000
2151
|
alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", m);
|
|
2001
2152
|
}
|
|
2002
2153
|
};
|
|
2003
|
-
(
|
|
2004
|
-
m.target ===
|
|
2154
|
+
(E = h.querySelector(".theme-toggle-btn")) == null || E.addEventListener("click", R), (L = h.querySelector(".readonly-toggle-btn")) == null || L.addEventListener("click", H), (O = h.querySelector(".rte-source-editor-fullscreen-btn")) == null || O.addEventListener("click", T), (I = h.querySelector(".rte-source-editor-close-btn")) == null || I.addEventListener("click", b), (A = y.querySelector(".rte-source-editor-btn-cancel")) == null || A.addEventListener("click", w), (B = y.querySelector(".rte-source-editor-btn-save")) == null || B.addEventListener("click", S), d.addEventListener("click", (m) => {
|
|
2155
|
+
m.target === d && b();
|
|
2005
2156
|
});
|
|
2006
|
-
const
|
|
2007
|
-
m.key === "Escape" && (
|
|
2157
|
+
const N = (m) => {
|
|
2158
|
+
m.key === "Escape" && (b(), document.removeEventListener("keydown", N));
|
|
2008
2159
|
};
|
|
2009
|
-
document.addEventListener("keydown",
|
|
2160
|
+
document.addEventListener("keydown", N);
|
|
2010
2161
|
})(), !0;
|
|
2011
2162
|
}
|
|
2012
2163
|
},
|
|
@@ -2017,6 +2168,6 @@ const Z = `/* Source Editor Dialog Styles */
|
|
|
2017
2168
|
}
|
|
2018
2169
|
});
|
|
2019
2170
|
export {
|
|
2020
|
-
|
|
2171
|
+
ee as CodePlugin
|
|
2021
2172
|
};
|
|
2022
|
-
//# sourceMappingURL=CodePlugin.native-
|
|
2173
|
+
//# sourceMappingURL=CodePlugin.native-B263UI8O.mjs.map
|