@editora/core 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/dist/{A11yCheckerPlugin.native-58d12bed.mjs → A11yCheckerPlugin.native-BRdGYMju.mjs} +12 -23
  3. package/dist/{AnchorPlugin.native-289a112a.mjs → AnchorPlugin.native-BcYGEtd9.mjs} +102 -112
  4. package/dist/{ApprovalWorkflowPlugin.native-449ce66c.mjs → ApprovalWorkflowPlugin.native-BZ6jO-Wj.mjs} +173 -209
  5. package/dist/{BackgroundColorPlugin.native-8aceb5cc.mjs → BackgroundColorPlugin.native-50iAT9xU.mjs} +9 -16
  6. package/dist/BlockquotePlugin.native-57_Xcjl1.mjs +212 -0
  7. package/dist/{BlocksLibraryPlugin.native-1cc51e63.mjs → BlocksLibraryPlugin.native-5sdsXsiE.mjs} +149 -205
  8. package/dist/{BoldPlugin.native-f9d7f8e4.mjs → BoldPlugin.native-CSh_LiIJ.mjs} +11 -7
  9. package/dist/CapitalizationPlugin.native-DLV4oPmB.mjs +159 -0
  10. package/dist/ChecklistPlugin.native-BS-kMz9O.mjs +371 -0
  11. package/dist/{CitationsPlugin.native-169fb1e8.mjs → CitationsPlugin.native-DQgoCd1B.mjs} +196 -261
  12. package/dist/ClearFormattingPlugin.native-DIS6AN2t.mjs +172 -0
  13. package/dist/CodePlugin.native-veDC_kx5.mjs +4600 -0
  14. package/dist/{CodeSamplePlugin.native-6cc0148e.mjs → CodeSamplePlugin.native-CgGoH-X4.mjs} +10 -19
  15. package/dist/{CommentsPlugin.native-03659874.mjs → CommentsPlugin.native-DPSqTkiv.mjs} +28 -55
  16. package/dist/{ConditionalContentPlugin.native-4983143a.mjs → ConditionalContentPlugin.native-CfhY46rU.mjs} +51 -108
  17. package/dist/{ContentRulesPlugin.native-63ed405b.mjs → ContentRulesPlugin.native-vPx5nC73.mjs} +153 -200
  18. package/dist/{DataBindingPlugin.native-427e9d75.mjs → DataBindingPlugin.native-BoXwghTz.mjs} +88 -124
  19. package/dist/DirectionPlugin.native-Bl-QLFzO.mjs +153 -0
  20. package/dist/{DocSchemaPlugin.native-8e41eda0.mjs → DocSchemaPlugin.native-DUSVRHqT.mjs} +112 -166
  21. package/dist/{DocumentManagerPlugin.native-e69895ad.mjs → DocumentManagerPlugin.native-C2cs_1w4.mjs} +4 -4
  22. package/dist/EmbedIframePlugin.native-BF_-LjTq.mjs +740 -0
  23. package/dist/{EmojisPlugin.native-65c5ac47.mjs → EmojisPlugin.native-CitxxlWX.mjs} +6 -11
  24. package/dist/{FontFamilyPlugin.native-f9bc255a.mjs → FontFamilyPlugin.native-j8hMTbg4.mjs} +4 -7
  25. package/dist/{FontSizePlugin.native-f5647872.mjs → FontSizePlugin.native-B_jCh7dY.mjs} +10 -19
  26. package/dist/{FootnotePlugin.native-494657b3.mjs → FootnotePlugin.native-D730OGRm.mjs} +39 -77
  27. package/dist/{FullscreenPlugin.native-87ce92e9.mjs → FullscreenPlugin.native-ChXyxeNw.mjs} +1 -1
  28. package/dist/HeadingPlugin.native-DZdvubrQ.mjs +249 -0
  29. package/dist/{HistoryPlugin.native-92ed4be4.mjs → HistoryPlugin.native-D2wl32jV.mjs} +107 -143
  30. package/dist/{IndentPlugin.native-e4ee902b.mjs → IndentPlugin.native-BHixp8sP.mjs} +12 -23
  31. package/dist/{ItalicPlugin.native-7c95cfbc.mjs → ItalicPlugin.native-CmnlwFHB.mjs} +15 -11
  32. package/dist/{LineHeightPlugin.native-5668f78c.mjs → LineHeightPlugin.native-CM7iXdQj.mjs} +10 -19
  33. package/dist/{LinkPlugin.native-6df29111.mjs → LinkPlugin.native-DYCIcdTm.mjs} +5 -9
  34. package/dist/{ListPlugin.native-fe2e115a.mjs → ListPlugin.native-V7EZC1lM.mjs} +5 -9
  35. package/dist/MathPlugin.native-NwWPHVmj.mjs +369 -0
  36. package/dist/{MediaManagerPlugin.native-3cf48a00.mjs → MediaManagerPlugin.native-eOsTJFpw.mjs} +11 -21
  37. package/dist/{MentionPlugin.native-3b1e8c05.mjs → MentionPlugin.native-BMDlOqur.mjs} +45 -89
  38. package/dist/MergeTagPlugin.native-BzRVoD9-.mjs +580 -0
  39. package/dist/{PIIRedactionPlugin.native-7ab10b9f.mjs → PIIRedactionPlugin.native-g7j4jOmm.mjs} +210 -260
  40. package/dist/{PageBreakPlugin.native-1794c5fb.mjs → PageBreakPlugin.native-DijGuHJZ.mjs} +16 -31
  41. package/dist/{PreviewPlugin.native-f7b67cc0.mjs → PreviewPlugin.native-WuIwOAOR.mjs} +6 -11
  42. package/dist/{PrintPlugin.native-f6a168c2.mjs → PrintPlugin.native-7qt5v7L5.mjs} +3 -5
  43. package/dist/{SlashCommandsPlugin.native-8d45e511.mjs → SlashCommandsPlugin.native-BiN6ODw5.mjs} +36 -71
  44. package/dist/{SmartPastePlugin.native-a6c5efec.mjs → SmartPastePlugin.native-CZAEHkyt.mjs} +173 -219
  45. package/dist/{SpecialCharactersPlugin.native-7f06d4ba.mjs → SpecialCharactersPlugin.native-DaG4b19I.mjs} +101 -85
  46. package/dist/{SpellCheckPlugin.native-04e20834.mjs → SpellCheckPlugin.native-BZB9AewP.mjs} +21 -41
  47. package/dist/{StrikethroughPlugin.native-905e9501.mjs → StrikethroughPlugin.native-V0TL4F48.mjs} +12 -30
  48. package/dist/{TablePlugin.native-7d5458c1.mjs → TablePlugin.native-DrHX-efe.mjs} +30 -58
  49. package/dist/TemplatePlugin.native-DLjFUaPW.mjs +1150 -0
  50. package/dist/{TextAlignmentPlugin.native-9357b3ed.mjs → TextAlignmentPlugin.native-sM_1s00t.mjs} +6 -11
  51. package/dist/{TextColorPlugin.native-d53ed459.mjs → TextColorPlugin.native-Bwl_bSmc.mjs} +14 -26
  52. package/dist/{TrackChangesPlugin.native-e96da509.mjs → TrackChangesPlugin.native-Bghu2q4a.mjs} +58 -115
  53. package/dist/{TranslationWorkflowPlugin.native-4e711b1e.mjs → TranslationWorkflowPlugin.native-DdF16tgT.mjs} +191 -257
  54. package/dist/{UnderlinePlugin.native-8080c998.mjs → UnderlinePlugin.native-DZzg23rv.mjs} +8 -4
  55. package/dist/{VersionDiffPlugin.native-5bbeff85.mjs → VersionDiffPlugin.native-Bvxgy--t.mjs} +26 -51
  56. package/dist/_commonjsHelpers-DOllISpa.mjs +32 -0
  57. package/dist/{anchoredPopover-5cca53ba.mjs → anchoredPopover-Bxds0VoB.mjs} +1 -1
  58. package/dist/core.css +1 -0
  59. package/dist/documentManager-vQ1VkbUY.mjs +8418 -0
  60. package/dist/{editorContainerHelpers-69585c07.mjs → editorContainerHelpers-C7kdWnS0.mjs} +2 -3
  61. package/dist/editora.min.js +13 -14
  62. package/dist/editora.umd.js +13 -14
  63. package/dist/{html2canvas.esm-c51cb3b9.mjs → html2canvas.esm-AYkPY5LS.mjs} +894 -978
  64. package/dist/index-BslAFzmv.mjs +16544 -0
  65. package/dist/index-CPMGUZfB.js +10 -0
  66. package/dist/{index-7da30697.mjs → index-DBoj6QfW.mjs} +127 -164
  67. package/dist/index.cjs.js +1 -1
  68. package/dist/index.es-BYD2KEo6.mjs +6666 -0
  69. package/dist/index.esm.js +7 -12
  70. package/dist/inlineFormatting-DJ0-NZtx.mjs +97 -0
  71. package/dist/{jspdf.es.min-780c82db.mjs → jspdf.es.min-BJGtOnRT.mjs} +3784 -4808
  72. package/dist/plugin-loader.js +67 -67
  73. package/dist/{purify.es-3bdbcfc5.mjs → purify.es-CKpwg8Tk.mjs} +10 -20
  74. package/dist/webcomponent-core.js +131 -168
  75. package/dist/webcomponent-core.min.css +1 -1
  76. package/dist/webcomponent-core.min.js +147 -65
  77. package/dist/webcomponent.cjs.js +1 -1
  78. package/dist/webcomponent.esm.js +1 -1
  79. package/dist/webcomponent.js +191 -228
  80. package/dist/webcomponent.min.css +1 -1
  81. package/dist/webcomponent.min.js +1248 -1346
  82. package/package.json +1 -1
  83. package/dist/BlockquotePlugin.native-3541c714.mjs +0 -49
  84. package/dist/CapitalizationPlugin.native-42c135dc.mjs +0 -80
  85. package/dist/ChecklistPlugin.native-3b397ee9.mjs +0 -330
  86. package/dist/ClearFormattingPlugin.native-77baa514.mjs +0 -145
  87. package/dist/CodePlugin.native-989cf0aa.mjs +0 -2740
  88. package/dist/DirectionPlugin.native-4e742f42.mjs +0 -139
  89. package/dist/EmbedIframePlugin.native-55209c87.mjs +0 -568
  90. package/dist/HeadingPlugin.native-e38c4a16.mjs +0 -64
  91. package/dist/MathPlugin.native-735bbac2.mjs +0 -296
  92. package/dist/MergeTagPlugin.native-31cf7d48.mjs +0 -584
  93. package/dist/TemplatePlugin.native-580f0f63.mjs +0 -617
  94. package/dist/_commonjsHelpers-69d58be2.mjs +0 -31
  95. package/dist/documentManager-8327fb6e.mjs +0 -9166
  96. package/dist/index-072ef022.js +0 -11
  97. package/dist/index-49d31221.mjs +0 -16860
  98. package/dist/index.es-b47a189f.mjs +0 -5782
  99. package/dist/style.css +0 -1
@@ -1,2740 +0,0 @@
1
- class D {
2
- constructor(e = "") {
3
- this._lines = [], this._version = 0, this.setText(e);
4
- }
5
- // Get line at index
6
- getLine(e) {
7
- return this._lines[e] || "";
8
- }
9
- // Get all lines
10
- getLines() {
11
- return [...this._lines];
12
- }
13
- // Get total number of lines
14
- getLineCount() {
15
- return this._lines.length;
16
- }
17
- // Get total text content
18
- getText() {
19
- return this._lines.join(`
20
- `);
21
- }
22
- // Set entire text content
23
- setText(e) {
24
- this._lines = e.split(`
25
- `), this._version++;
26
- }
27
- // Get text in a range
28
- getTextInRange(e) {
29
- if (e.start.line === e.end.line)
30
- return this.getLine(e.start.line).substring(e.start.column, e.end.column);
31
- const t = [];
32
- t.push(this.getLine(e.start.line).substring(e.start.column));
33
- for (let i = e.start.line + 1; i < e.end.line; i++)
34
- t.push(this.getLine(i));
35
- return e.end.line < this.getLineCount() && t.push(this.getLine(e.end.line).substring(0, e.end.column)), t.join(`
36
- `);
37
- }
38
- // Replace text in range
39
- replaceRange(e, t) {
40
- const i = this.getTextInRange(e);
41
- if (e.start.line === e.end.line) {
42
- const s = this.getLine(e.start.line), n = s.substring(0, e.start.column) + t + s.substring(e.end.column);
43
- this._lines[e.start.line] = n;
44
- } else {
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
- `);
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
- }
49
- return this._version++, { range: e, text: t, oldText: i };
50
- }
51
- // Insert text at position
52
- insertText(e, t) {
53
- const i = { start: e, end: e };
54
- return this.replaceRange(i, t);
55
- }
56
- // Delete text in range
57
- deleteRange(e) {
58
- return this.replaceRange(e, "");
59
- }
60
- // Convert position to offset
61
- positionToOffset(e) {
62
- let t = 0;
63
- for (let i = 0; i < e.line; i++)
64
- t += this.getLine(i).length + 1;
65
- return t += e.column, t;
66
- }
67
- // Convert offset to position
68
- offsetToPosition(e) {
69
- let t = e;
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
- }
76
- return {
77
- line: this.getLineCount() - 1,
78
- column: this.getLine(this.getLineCount() - 1).length
79
- };
80
- }
81
- // Validate position
82
- isValidPosition(e) {
83
- return !(e.line < 0 || e.line >= this.getLineCount() || e.column < 0 || e.column > this.getLine(e.line).length);
84
- }
85
- // Validate range
86
- isValidRange(e) {
87
- return this.isValidPosition(e.start) && this.isValidPosition(e.end);
88
- }
89
- // Get version for change tracking
90
- getVersion() {
91
- return this._version;
92
- }
93
- // Clone the model
94
- clone() {
95
- const e = new D();
96
- return e._lines = [...this._lines], e._version = this._version, e;
97
- }
98
- }
99
- class Z {
100
- constructor(e) {
101
- this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.virtualMarkerRegex = /[\u200B\uE000]/, this.container = e, this.createDOM();
102
- }
103
- createDOM() {
104
- this.container.innerHTML = "";
105
- const e = document.createElement("div");
106
- this.editorContainer = e, e.setAttribute("data-lce-editor-container", "true"), e.style.cssText = `
107
- position: relative;
108
- display: flex;
109
- width: 100%;
110
- height: 100%;
111
- background: var(--editor-background, #1e1e1e);
112
- color: var(--editor-foreground, #f8f9fa);
113
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
114
- font-size: 14px;
115
- line-height: ${this.lineHeight}px;
116
- /* make the outer container the single scrollable element so gutter and content scroll together */
117
- overflow: auto;
118
- `, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.setAttribute("data-editor-gutter", "true"), this.lineNumbersElement.style.cssText = `
119
- display: table-cell;
120
- vertical-align: top;
121
- width: ${this.gutterWidth}px;
122
- background: var(--editor-gutter-background, #252526);
123
- color: var(--editor-gutter-foreground, #858585);
124
- padding: 0 8px 0 0;
125
- text-align: right;
126
- border-right: 1px solid var(--editor-gutter-border, #3e3e42);
127
- user-select: none;
128
- z-index: 1;
129
- `, this.contentElement = document.createElement("div"), this.contentElement.style.cssText = `
130
- display: table-cell;
131
- vertical-align: top;
132
- padding: 0 12px;
133
- background: transparent;
134
- border: none;
135
- outline: none;
136
- white-space: pre;
137
- overflow-x: auto;
138
- overflow-y: visible;
139
- min-height: 400px;
140
- font-family: inherit;
141
- font-size: inherit;
142
- line-height: inherit;
143
- color: inherit;
144
- tab-size: 2;
145
- -moz-tab-size: 2;
146
- `, this.contentElement.contentEditable = "true", this.contentElement.spellcheck = !1;
147
- const t = document.createElement("div");
148
- t.setAttribute("data-editora-editor", "true"), t.style.cssText = "display: table; table-layout: fixed; width: 100%; height: 100%;", t.appendChild(this.lineNumbersElement), t.appendChild(this.contentElement), e.appendChild(t), this.container.appendChild(e), this.updateLineNumbers(1);
149
- }
150
- // Update line numbers
151
- updateLineNumbers(e) {
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
- }
155
- // Get content element
156
- getContentElement() {
157
- return this.contentElement;
158
- }
159
- // Get line numbers element
160
- getLineNumbersElement() {
161
- return this.lineNumbersElement;
162
- }
163
- // Get text content
164
- getText() {
165
- const e = this.contentElement.textContent || "";
166
- return this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`) && e.endsWith("​") ? e.slice(0, -1) : e;
167
- }
168
- // Set text content
169
- setText(e) {
170
- this.contentElement.textContent = e, this.syncTrailingNewlineMarker(e.endsWith(`
171
- `));
172
- const t = e.split(`
173
- `).length;
174
- this.updateLineNumbers(t);
175
- }
176
- // Set inner HTML (used for syntax highlighted content)
177
- setHTML(e) {
178
- const t = /\n$/.test(e), i = /&lt;|&gt;/.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
- const r = (this.contentElement.textContent || "").split(`
181
- `).length;
182
- this.updateLineNumbers(r);
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
- `));
189
- }
190
- // Get cursor position from DOM selection
191
- getCursorPosition() {
192
- const e = window.getSelection();
193
- if (!e || e.rangeCount === 0)
194
- return { line: 0, column: 0 };
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
- `);
199
- return {
200
- line: s.length - 1,
201
- column: s[s.length - 1].length
202
- };
203
- }
204
- // Set cursor position
205
- setCursorPosition(e) {
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
- try {
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
- }
220
- else {
221
- const a = this.contentElement.querySelector(
222
- `[${this.trailingNewlineMarkerAttr}]`
223
- );
224
- try {
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
- } catch (c) {
227
- console.warn("Could not set fallback cursor position:", c);
228
- }
229
- }
230
- }
231
- // Get selection range
232
- getSelectionRange() {
233
- const e = window.getSelection();
234
- if (!e || e.rangeCount === 0 || e.isCollapsed)
235
- return;
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
- `), n = t.cloneRange();
240
- n.selectNodeContents(this.contentElement), n.setEnd(t.endContainer, t.endOffset);
241
- const r = n.toString().replace(/\u200B/g, "").split(`
242
- `);
243
- return {
244
- start: {
245
- line: s.length - 1,
246
- column: s[s.length - 1].length
247
- },
248
- end: {
249
- line: r.length - 1,
250
- column: r[r.length - 1].length
251
- }
252
- };
253
- }
254
- // Set selection range
255
- setSelectionRange(e) {
256
- const t = this.getText().split(`
257
- `), i = (c) => {
258
- const d = Math.max(0, Math.min(c.line, t.length - 1)), p = Math.max(
259
- 0,
260
- Math.min(c.column, t[d] ? t[d].length : 0)
261
- );
262
- let u = 0;
263
- for (let g = 0; g < d; g++)
264
- u += t[g].length + 1;
265
- return u + p;
266
- }, s = i(e.start), n = i(e.end), [r, o] = s <= n ? [s, n] : [n, s], l = this.resolveOffsetToDomPoint(r), h = this.resolveOffsetToDomPoint(o);
267
- if (!l || !h)
268
- return;
269
- const a = document.createRange();
270
- try {
271
- a.setStart(l.node, l.offset), a.setEnd(h.node, h.offset);
272
- const c = window.getSelection();
273
- c == null || c.removeAllRanges(), c == null || c.addRange(a), this.ensureCaretVisible();
274
- } catch (c) {
275
- console.warn("Could not set selection range:", c);
276
- }
277
- }
278
- // Focus the editor
279
- focus() {
280
- this.contentElement.focus(), this.ensureCaretVisible();
281
- }
282
- // Blur the editor
283
- blur() {
284
- this.contentElement.blur();
285
- }
286
- // Set read-only mode
287
- setReadOnly(e) {
288
- this.contentElement.contentEditable = e ? "false" : "true";
289
- }
290
- // Apply theme
291
- applyTheme(e) {
292
- Object.entries(e).forEach(([t, i]) => {
293
- this.container.style.setProperty(`--${t}`, i);
294
- });
295
- }
296
- // Scroll to position
297
- scrollToPosition(e) {
298
- const t = this.lineNumbersElement.children[e.line];
299
- t && t.scrollIntoView({ block: "center", behavior: "smooth" });
300
- }
301
- // Get scroll position
302
- getScrollTop() {
303
- return this.editorContainer.scrollTop;
304
- }
305
- // Get primary scroll element
306
- getScrollElement() {
307
- return this.editorContainer;
308
- }
309
- // Set scroll position
310
- setScrollTop(e) {
311
- this.editorContainer.scrollTop = e;
312
- }
313
- syncTrailingNewlineMarker(e) {
314
- if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e)
315
- return;
316
- const t = document.createElement("span");
317
- t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
318
- display: inline-block;
319
- width: 0;
320
- overflow: hidden;
321
- pointer-events: none;
322
- user-select: none;
323
- `, t.appendChild(document.createTextNode("​")), this.contentElement.appendChild(t);
324
- }
325
- // Ensure caret is visible inside the editor scroll container
326
- ensureCaretVisible() {
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);
338
- }
339
- // Destroy the view
340
- destroy() {
341
- this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
342
- }
343
- resolveOffsetToDomPoint(e) {
344
- var l;
345
- var t;
346
- const i = Math.max(0, e);
347
- let s = 0;
348
- const n = document.createTreeWalker(
349
- this.contentElement,
350
- NodeFilter.SHOW_TEXT,
351
- null
352
- );
353
- let r = null, o;
354
- for (; o = n.nextNode(); ) {
355
- const h = o.parentElement;
356
- if (h != null && h.hasAttribute(this.trailingNewlineMarkerAttr))
357
- continue;
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;
362
- return {
363
- node: o,
364
- offset: u
365
- };
366
- }
367
- s += d;
368
- }
369
- if (r) {
370
- const h = ((t = r.textContent) == null ? void 0 : t.length) || 0;
371
- return { node: r, offset: h };
372
- }
373
- return null;
374
- }
375
- buildVisibleToDomMap(e) {
376
- const t = [0];
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);
381
- }
382
- return t;
383
- }
384
- }
385
- const F = class L {
386
- constructor(e, t = {}) {
387
- 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 = {
388
- value: "",
389
- theme: "default",
390
- readOnly: !1,
391
- tabSize: 2,
392
- lineWrapping: !1,
393
- lineNumbers: !0,
394
- ...t
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();
396
- }
397
- // Public accessors for extensions
398
- getTextModel() {
399
- return this.textModel;
400
- }
401
- getView() {
402
- return this.view;
403
- }
404
- getConfig() {
405
- return { ...this.config };
406
- }
407
- // Register built-in editor commands like undo/redo/insertTab
408
- registerBuiltInCommands() {
409
- this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("save", () => {
410
- this.emit("save");
411
- });
412
- }
413
- // Get keymap extension if available
414
- getKeymapExtension() {
415
- return this.extensions.get("keymap");
416
- }
417
- // Setup DOM event handlers
418
- setupEventHandlers() {
419
- const e = this.view.getContentElement();
420
- e.addEventListener("input", () => {
421
- const t = this.view.getText(), i = this.textModel.getText();
422
- if (t !== i) {
423
- if (!this.suppressHistory) {
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;
427
- }
428
- this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
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 }]);
432
- }
433
- }), e.addEventListener("selectionchange", () => {
434
- const t = this.getCursor(), i = this.getSelection();
435
- this.emit("cursor", t), i && this.emit("selection", i);
436
- }), e.addEventListener("keydown", (t) => {
437
- if (this.emit("keydown", t), t.key === "Tab") {
438
- this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
439
- return;
440
- }
441
- if (t.key === "Enter") {
442
- if (!this.config.readOnly) {
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();
452
- const c = document.createTextNode(`
453
- `);
454
- a.insertNode(c), a.setStartAfter(c), a.collapse(!0), i.removeAllRanges(), i.addRange(a), this.view.ensureCaretVisible();
455
- const d = this.view.getText();
456
- this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
457
- const p = Math.min(
458
- h + 1,
459
- this.textModel.getText().length
460
- );
461
- try {
462
- const u = this.textModel.offsetToPosition(p);
463
- this.setCursor(u), this.view.ensureCaretVisible();
464
- } catch (u) {
465
- }
466
- this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
467
- this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
468
- try {
469
- const u = this.textModel.offsetToPosition(p);
470
- this.setCursor(u), this.view.ensureCaretVisible();
471
- } catch (u) {
472
- }
473
- }), this.highlightTimeout = null;
474
- }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: this.getValue(), oldText: "" }]);
475
- }
476
- }
477
- t.preventDefault(), t.stopPropagation();
478
- return;
479
- }
480
- for (const i of this.extensions.values())
481
- if (i.onKeyDown && i.onKeyDown(t) === !1) {
482
- t.preventDefault(), t.stopPropagation();
483
- return;
484
- }
485
- }), e.addEventListener("mousedown", (t) => {
486
- this.emit("mousedown", t);
487
- for (const i of this.extensions.values())
488
- if (i.onMouseDown && i.onMouseDown(t) === !1) {
489
- t.preventDefault(), t.stopPropagation();
490
- return;
491
- }
492
- }), e.addEventListener("focus", () => {
493
- this.emit("focus");
494
- }), e.addEventListener("blur", () => {
495
- this.emit("blur");
496
- });
497
- }
498
- // Update line numbers display
499
- updateLineNumbers() {
500
- const e = this.textModel.getLineCount();
501
- this.view.updateLineNumbers(e);
502
- }
503
- // Get full range of document
504
- getFullRange() {
505
- return {
506
- start: { line: 0, column: 0 },
507
- end: {
508
- line: this.textModel.getLineCount() - 1,
509
- column: this.textModel.getLine(this.textModel.getLineCount() - 1).length
510
- }
511
- };
512
- }
513
- // Emit events to listeners
514
- emit(e, ...t) {
515
- const i = this.eventListeners.get(e);
516
- i && i.forEach((s) => s(...t));
517
- }
518
- // State management
519
- getValue() {
520
- return this.textModel.getText();
521
- }
522
- setValue(e) {
523
- const t = this.textModel.getText();
524
- this.textModel.setText(e), this.renderTextWithHighlight(e, !1), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: t }]);
525
- }
526
- getState() {
527
- return {
528
- text: this.getValue(),
529
- cursor: this.getCursor(),
530
- selection: this.getSelection(),
531
- readOnly: this.config.readOnly || !1,
532
- theme: this.currentTheme
533
- };
534
- }
535
- // Cursor & Selection
536
- getCursor() {
537
- const e = this.view.getCursorPosition();
538
- return {
539
- position: e,
540
- anchor: e
541
- // For now, cursor and anchor are the same
542
- };
543
- }
544
- setCursor(e) {
545
- this.view.setCursorPosition(e), this.emit("cursor", this.getCursor());
546
- }
547
- getSelection() {
548
- return this.view.getSelectionRange();
549
- }
550
- setSelection(e) {
551
- this.view.setSelectionRange(e), this.emit("selection", e);
552
- }
553
- // Configuration
554
- setTheme(e) {
555
- this.currentTheme = e;
556
- const t = {
557
- "editor-background": e === "dark" ? "#1e1e1e" : "#ffffff",
558
- "editor-foreground": e === "dark" ? "#f8f9fa" : "#1a1a1a",
559
- "editor-gutter-background": e === "dark" ? "#252526" : "#f8f9fa",
560
- "editor-gutter-foreground": e === "dark" ? "#858585" : "#666666",
561
- "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
562
- };
563
- this.view.applyTheme(t);
564
- const i = this.extensions.get("syntax-highlighting");
565
- if (i && typeof i.setTheme == "function")
566
- try {
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);
570
- }
571
- }
572
- setReadOnly(e) {
573
- this.config.readOnly = e, this.view.setReadOnly(e);
574
- }
575
- // Extensions & Commands
576
- addExtension(e) {
577
- if (this.extensions.has(e.name))
578
- throw new Error(`Extension '${e.name}' already exists`);
579
- this.extensions.set(e.name, e), e.setup(this), e.name === "syntax-highlighting" && typeof e.highlightHTML == "function" && this.renderTextWithHighlight(this.textModel.getText());
580
- }
581
- removeExtension(e) {
582
- const t = this.extensions.get(e);
583
- t && t.destroy && t.destroy(), this.extensions.delete(e);
584
- }
585
- executeCommand(e, ...t) {
586
- const i = this.commands.get(e);
587
- i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
588
- }
589
- // Register a command
590
- registerCommand(e, t) {
591
- this.commands.set(e, t);
592
- }
593
- // Search & Navigation
594
- search(e, t = {}) {
595
- var a;
596
- if (!e)
597
- return [];
598
- const i = {
599
- query: e,
600
- caseSensitive: !1,
601
- wholeWord: !1,
602
- regex: !1,
603
- ...t
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) {
606
- let c;
607
- try {
608
- c = new RegExp(e, i.caseSensitive ? "g" : "gi");
609
- } catch (p) {
610
- return [];
611
- }
612
- let d;
613
- for (; (d = c.exec(r)) !== null; ) {
614
- const p = (a = d[0]) != null ? a : "";
615
- if (p.length === 0) {
616
- c.lastIndex = d.index + 1;
617
- continue;
618
- }
619
- const u = d.index, g = d.index + p.length;
620
- i.wholeWord && !this.isWholeWordBoundary(r, u, g) || this.pushSearchResultFromOffsets(
621
- s,
622
- u,
623
- g,
624
- r,
625
- o
626
- );
627
- }
628
- } else {
629
- let c = 0, d = l.indexOf(h, c);
630
- for (; d !== -1; ) {
631
- const p = d + h.length;
632
- !i.wholeWord || this.isWholeWordBoundary(r, d, p) ? (this.pushSearchResultFromOffsets(
633
- s,
634
- d,
635
- p,
636
- r,
637
- o
638
- ), c = p) : c = d + 1, d = l.indexOf(h, c);
639
- }
640
- }
641
- return s;
642
- }
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);
646
- e.push({
647
- range: { start: l, end: h },
648
- match: s.substring(t, i)
649
- });
650
- }
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);
654
- }
655
- isWordChar(e) {
656
- return /^[A-Za-z0-9_]$/.test(e);
657
- }
658
- buildSearchTextAndOffsetMap(e) {
659
- const t = [], i = [0];
660
- let s = 0;
661
- for (let n = 0; n < e.length; n++) {
662
- const r = e[n];
663
- r === "​" || r === L.CURSOR_SENTINEL || (t.push(r), s += 1, i[s] = n + 1);
664
- }
665
- return i[s] = e.length, {
666
- normalizedText: t.join(""),
667
- normalizedToRawOffsets: i
668
- };
669
- }
670
- replace(e, t) {
671
- const i = this.getValue();
672
- if (!this.suppressHistory) {
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;
676
- }
677
- const s = this.textModel.replaceRange(e, t);
678
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [s]);
679
- }
680
- replaceAll(e, t, i = {}) {
681
- const s = this.search(e, i);
682
- let n = 0;
683
- for (let r = s.length - 1; r >= 0; r--)
684
- this.replace(s[r].range, t), n++;
685
- return n;
686
- }
687
- // Folding (basic implementation)
688
- fold(e) {
689
- const t = {
690
- start: e.start,
691
- end: e.end,
692
- collapsed: !0,
693
- level: 0
694
- };
695
- this.folds.push(t);
696
- }
697
- unfold(e) {
698
- this.folds = this.folds.filter(
699
- (t) => !(t.start.line === e.start.line && t.end.line === e.end.line)
700
- );
701
- }
702
- getFolds() {
703
- return [...this.folds];
704
- }
705
- // Utilities
706
- focus() {
707
- this.view.focus();
708
- }
709
- blur() {
710
- this.view.blur();
711
- }
712
- // Render text using syntax highlighting extension if available
713
- // If `restoreSelection` is true (default), the method captures current selection/caret
714
- // and restores it after updating the DOM. Callers that will explicitly set the caret
715
- // should pass `false` to avoid stomping programmatic cursor changes.
716
- renderTextWithHighlight(e, t = !0) {
717
- const i = this.extensions.get("syntax-highlighting");
718
- if (i && typeof i.highlightHTML == "function")
719
- try {
720
- const s = !t && !this.expectingProgrammaticCursor;
721
- let n, r, o, l;
722
- if (t || s) {
723
- n = this.getSelection();
724
- const d = this.getCollapsedSelectionOffsetInEditor();
725
- if (d !== void 0)
726
- r = d;
727
- else {
728
- const p = this.getCursor().position;
729
- r = this.textModel.positionToOffset(p);
730
- }
731
- n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end));
732
- }
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(() => {
735
- try {
736
- if (h && this.restoreCursorFromSentinel()) {
737
- this.view.ensureCaretVisible();
738
- return;
739
- }
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 });
743
- } else if (r !== void 0) {
744
- const d = this.textModel.offsetToPosition(r);
745
- this.view.setCursorPosition(d);
746
- }
747
- } catch (d) {
748
- }
749
- });
750
- return;
751
- } catch (s) {
752
- console.warn("Syntax highlighting failed, falling back to plain text", s);
753
- }
754
- this.view.setText(e);
755
- }
756
- hasCollapsedSelectionInEditor() {
757
- const e = window.getSelection();
758
- if (!e || e.rangeCount === 0 || !e.isCollapsed)
759
- return !1;
760
- const t = e.getRangeAt(0);
761
- return this.view.getContentElement().contains(t.commonAncestorContainer);
762
- }
763
- getCollapsedSelectionOffsetInEditor() {
764
- const e = window.getSelection();
765
- if (!e || e.rangeCount === 0 || !e.isCollapsed)
766
- return;
767
- const t = e.getRangeAt(0), i = this.view.getContentElement();
768
- if (!i.contains(t.commonAncestorContainer))
769
- return;
770
- const s = t.cloneRange();
771
- return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
772
- }
773
- stripVirtualMarkers(e) {
774
- return e.replace(/\u200B/g, "").split(L.CURSOR_SENTINEL).join("");
775
- }
776
- insertSentinelAtOffset(e, t) {
777
- const i = Math.max(0, Math.min(t, e.length));
778
- return e.slice(0, i) + L.CURSOR_SENTINEL + e.slice(i);
779
- }
780
- restoreCursorFromSentinel() {
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();
787
- }
788
- if (!n || !t)
789
- return !1;
790
- try {
791
- const l = document.createRange();
792
- return l.setStart(n, r), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
793
- } catch (l) {
794
- return !1;
795
- }
796
- }
797
- destroy() {
798
- if (!this.isDestroyed) {
799
- this.isDestroyed = !0;
800
- for (const e of this.extensions.values())
801
- e.destroy && e.destroy();
802
- this.extensions.clear(), this.view.destroy(), this.commands.clear(), this.eventListeners.clear();
803
- }
804
- }
805
- // History: undo/redo
806
- undo() {
807
- if (this.undoStack.length === 0)
808
- return;
809
- const e = this.undoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
810
- this.redoStack.push(t);
811
- try {
812
- this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
813
- let i, s;
814
- typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
815
- try {
816
- if (s != null)
817
- if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
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 });
820
- } else {
821
- const n = this.textModel.offsetToPosition(s);
822
- this.setCursor(n);
823
- }
824
- } catch (n) {
825
- }
826
- }), setTimeout(() => {
827
- this.expectingProgrammaticCursor = !1;
828
- }, 30);
829
- } finally {
830
- this.suppressHistory = !1;
831
- }
832
- }
833
- redo() {
834
- if (this.redoStack.length === 0)
835
- return;
836
- const e = this.redoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
837
- this.undoStack.push(t);
838
- try {
839
- this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
840
- let i, s;
841
- typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
842
- try {
843
- if (s != null)
844
- if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
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 });
847
- } else {
848
- const n = this.textModel.offsetToPosition(s);
849
- this.setCursor(n);
850
- }
851
- } catch (n) {
852
- }
853
- }), setTimeout(() => {
854
- this.expectingProgrammaticCursor = !1;
855
- }, 30);
856
- } finally {
857
- this.suppressHistory = !1;
858
- }
859
- }
860
- // Insert a tab character or spaces at current cursor
861
- insertTab() {
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);
865
- if (!this.suppressHistory) {
866
- const r = this.getSelection();
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;
869
- }
870
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(n), setTimeout(() => {
871
- this.expectingProgrammaticCursor = !1;
872
- }, 20), this.emit("change", [s]);
873
- }
874
- // Insert a newline at current cursor position
875
- insertNewLine() {
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);
880
- if (!this.suppressHistory) {
881
- const n = this.getSelection();
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;
884
- }
885
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
886
- this.expectingProgrammaticCursor = !1;
887
- }, 20), this.emit("change", [i]);
888
- }
889
- // Events
890
- on(e, t) {
891
- this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
892
- }
893
- off(e, t) {
894
- if (!this.eventListeners.has(e))
895
- return;
896
- const i = this.eventListeners.get(e);
897
- if (t) {
898
- const s = i.indexOf(t);
899
- s !== -1 && i.splice(s, 1);
900
- } else
901
- i.length = 0;
902
- }
903
- };
904
- F.CURSOR_SENTINEL = "";
905
- let X = F;
906
- class J {
907
- constructor(e) {
908
- this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
909
- }
910
- setup(e) {
911
- this.editor = e;
912
- }
913
- handleKeyDown(e) {
914
- if (!this.editor)
915
- return;
916
- const t = this.findMatchingBinding(e);
917
- if (t)
918
- return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
919
- }
920
- findMatchingBinding(e) {
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)
927
- return h;
928
- }
929
- return null;
930
- }
931
- // Allow EditorCore to call this directly when checking extension.onKeyDown
932
- onKeyDown(e) {
933
- return this.handleKeyDown(e);
934
- }
935
- getDefaultKeymap() {
936
- const e = {};
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;
938
- }
939
- addBinding(e, t, i, s) {
940
- const n = t.toLowerCase();
941
- e[n] || (e[n] = []), e[n].push({
942
- key: n,
943
- command: s,
944
- ...i
945
- });
946
- }
947
- // Public API for customizing keymap
948
- setKeymap(e) {
949
- this.keymap = { ...e };
950
- }
951
- addKeyBinding(e) {
952
- const t = e.key.toLowerCase();
953
- this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
954
- ...e,
955
- key: t
956
- });
957
- }
958
- removeKeyBinding(e, t) {
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];
961
- }
962
- getKeymap() {
963
- return { ...this.keymap };
964
- }
965
- getBindingsForCommand(e) {
966
- const t = [];
967
- for (const i in this.keymap)
968
- for (const s of this.keymap[i])
969
- s.command === e && t.push({ ...s });
970
- return t;
971
- }
972
- getPlatformInfo() {
973
- return {
974
- isMac: this.isMac,
975
- platform: navigator.platform
976
- };
977
- }
978
- destroy() {
979
- this.keymap = {}, this.editor = null;
980
- }
981
- }
982
- class Y {
983
- constructor() {
984
- this.name = "transaction", this.transactions = [];
985
- }
986
- setup(e) {
987
- e.on("change", (t) => {
988
- const i = {
989
- changes: t,
990
- selection: e.getSelection(),
991
- effects: [],
992
- annotations: []
993
- };
994
- this.transactions.push(i);
995
- });
996
- }
997
- getTransactions() {
998
- return this.transactions;
999
- }
1000
- destroy() {
1001
- this.transactions = [];
1002
- }
1003
- }
1004
- class G {
1005
- constructor() {
1006
- this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
1007
- }
1008
- setup(e) {
1009
- this.editor = e, this.createLineNumbers(), e.registerCommand("toggleLineNumbers", () => {
1010
- this.toggle();
1011
- }), e.on("change", () => {
1012
- this.updateLineNumbers();
1013
- }), this.updateLineNumbers();
1014
- }
1015
- createLineNumbers() {
1016
- if (!this.editor)
1017
- return;
1018
- const e = this.editor.getView().getLineNumbersElement();
1019
- e && (this.lineNumbersElement = e);
1020
- }
1021
- updateLineNumbers() {
1022
- if (!this.lineNumbersElement || !this.editor || !this.isEnabled)
1023
- return;
1024
- const e = this.editor.getValue().split(`
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("");
1027
- }
1028
- toggle() {
1029
- if (!this.editor)
1030
- return;
1031
- this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
1032
- const e = this.editor.getView().getContentElement();
1033
- e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
1034
- }
1035
- destroy() {
1036
- this.lineNumbersElement = null, this.editor = null;
1037
- }
1038
- }
1039
- class _ {
1040
- constructor() {
1041
- this.name = "theme", this.editor = null, this.currentTheme = "dark";
1042
- }
1043
- setup(e) {
1044
- this.editor = e, e.registerCommand("setTheme", (t) => {
1045
- this.setTheme(t);
1046
- }), e.registerCommand("toggleTheme", () => {
1047
- this.toggleTheme();
1048
- }), this.setTheme(this.currentTheme);
1049
- }
1050
- setTheme(e) {
1051
- this.editor && (this.currentTheme = e, this.editor.setTheme(e));
1052
- }
1053
- toggleTheme() {
1054
- const e = this.currentTheme === "dark" ? "light" : "dark";
1055
- this.setTheme(e);
1056
- }
1057
- getCurrentTheme() {
1058
- return this.currentTheme;
1059
- }
1060
- destroy() {
1061
- this.editor = null;
1062
- }
1063
- }
1064
- class ee {
1065
- constructor() {
1066
- this.name = "read-only", this.editor = null, this.isReadOnly = !1;
1067
- }
1068
- setup(e) {
1069
- this.editor = e, e.registerCommand("setReadOnly", (t) => {
1070
- this.setReadOnly(t);
1071
- }), e.registerCommand("toggleReadOnly", () => {
1072
- this.toggleReadOnly();
1073
- }), e.on("keydown", (t) => {
1074
- if (t.ctrlKey && t.key === "r")
1075
- return t.preventDefault(), this.toggleReadOnly(), !1;
1076
- });
1077
- }
1078
- setReadOnly(e) {
1079
- this.editor && (this.isReadOnly = e, this.editor.setReadOnly(e));
1080
- }
1081
- toggleReadOnly() {
1082
- this.setReadOnly(!this.isReadOnly);
1083
- }
1084
- isCurrentlyReadOnly() {
1085
- return this.isReadOnly;
1086
- }
1087
- destroy() {
1088
- this.editor = null;
1089
- }
1090
- }
1091
- let te = 0;
1092
- const W = class m {
1093
- constructor(e = {}) {
1094
- this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1, this.searchDebounceTimer = null, this.liveRefreshTimer = null, this.statusResetTimer = null, this.statusFreezeUntil = 0, this.findInput = null, this.replaceInputEl = null, this.statusDiv = null, this.modeDiv = null, this.caseSensitiveInput = null, this.wholeWordInput = null, this.regexInput = null, this.currentQuery = "", this.savedCursor = null, this.editorChangeHandler = null, this.searchOptions = {
1095
- caseSensitive: !1,
1096
- wholeWord: !1,
1097
- regex: !1
1098
- }, this.trailingMarkerAttr = "data-lce-trailing-newline-marker", this.editorContainerSelector = '[data-lce-editor-container="true"]', this.highlightId = ++te, this.highlightMatchName = `editora-search-match-${this.highlightId}`, this.highlightActiveName = `editora-search-active-${this.highlightId}`, this.highlightStyleId = `editora-search-highlight-style-${this.highlightId}`, this.maxCustomHighlightRanges = 2e3, this.virtualMarkerRegex = /[\u200B\uE000]/, this.hasCustomHighlightSupport = !1, this.config = {
1099
- replaceAndFindNext: !0,
1100
- ...e
1101
- };
1102
- }
1103
- setup(e) {
1104
- this.editor = e, this.hasCustomHighlightSupport = this.detectCustomHighlightSupport(), this.hasCustomHighlightSupport && this.ensureHighlightStyles(), e.registerCommand("find", () => {
1105
- this.showSearch();
1106
- }), e.registerCommand("findNext", () => {
1107
- this.findNext();
1108
- }), e.registerCommand("findPrev", () => {
1109
- this.findPrev();
1110
- }), e.registerCommand("replace", () => {
1111
- this.showReplace();
1112
- }), e.registerCommand("replaceAll", (t, i) => {
1113
- this.replaceAll(t, i);
1114
- }), this.editorChangeHandler = () => {
1115
- !this.isVisible || !this.currentQuery || this.scheduleLiveRefresh(!0);
1116
- }, e.on("change", this.editorChangeHandler);
1117
- }
1118
- showSearch() {
1119
- this.editor && (this.searchUI || this.createSearchUI(), this.isVisible || this.captureSelectionState(), this.isVisible = !0, this.searchUI && (this.searchUI.style.display = "block", this.updateModeHint(!1), this.findInput && (this.findInput.focus(), this.findInput.select())), this.currentQuery && this.performSearch(this.currentQuery, !0, !1));
1120
- }
1121
- showReplace() {
1122
- this.showSearch(), this.replaceInputEl && (this.replaceInputEl.style.display = "block", this.replaceInputEl.focus()), this.updateModeHint(!0), this.currentQuery && this.performSearch(this.currentQuery, !1, !0);
1123
- }
1124
- hideSearch() {
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();
1126
- }
1127
- createSearchUI() {
1128
- if (!this.editor)
1129
- return;
1130
- const e = this.editor.getView().getContentElement(), t = e.closest(
1131
- this.editorContainerSelector
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 = `
1136
- <div class="${m.css.row}">
1137
- <input type="text" class="${m.css.findInput} ${m.css.inputBase}" placeholder="Find..." />
1138
- <button class="${m.css.prevButton} ${m.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
1139
- <button class="${m.css.nextButton} ${m.css.buttonBase}" type="button" aria-label="Next match">↓</button>
1140
- <button class="${m.css.closeButton} ${m.css.buttonBase}" type="button" aria-label="Close search">×</button>
1141
- </div>
1142
- <div class="${m.css.options}">
1143
- <label class="${m.css.optionLabel}" title="Case sensitive">
1144
- <input type="checkbox" class="${m.css.optionInput} ${m.css.caseSensitive}" />
1145
- <span>Aa</span>
1146
- </label>
1147
- <label class="${m.css.optionLabel}" title="Whole word">
1148
- <input type="checkbox" class="${m.css.optionInput} ${m.css.wholeWord}" />
1149
- <span>Whole</span>
1150
- </label>
1151
- <label class="${m.css.optionLabel}" title="Regular expression">
1152
- <input type="checkbox" class="${m.css.optionInput} ${m.css.regex}" />
1153
- <span>.*</span>
1154
- </label>
1155
- </div>
1156
- <div class="${m.css.meta}">
1157
- <div class="${m.css.status} ${m.css.statusLayout}"></div>
1158
- <div class="${m.css.mode} ${m.css.modeLayout}" aria-live="polite"></div>
1159
- </div>
1160
- <input type="text" class="${m.css.replaceInput} ${m.css.inputBase} ${m.css.replaceInputLayout}" placeholder="Replace with..." />
1161
- `;
1162
- const s = this.searchUI.querySelector(
1163
- `.${m.css.findInput}`
1164
- ), n = this.searchUI.querySelector(
1165
- `.${m.css.replaceInput}`
1166
- ), r = this.searchUI.querySelector(
1167
- `.${m.css.prevButton}`
1168
- ), o = this.searchUI.querySelector(
1169
- `.${m.css.nextButton}`
1170
- ), l = this.searchUI.querySelector(
1171
- `.${m.css.closeButton}`
1172
- ), h = this.searchUI.querySelector(
1173
- `.${m.css.status}`
1174
- ), a = this.searchUI.querySelector(
1175
- `.${m.css.mode}`
1176
- ), c = this.searchUI.querySelector(
1177
- `.${m.css.caseSensitive}`
1178
- ), d = this.searchUI.querySelector(
1179
- `.${m.css.wholeWord}`
1180
- ), p = this.searchUI.querySelector(
1181
- `.${m.css.regex}`
1182
- );
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", () => {
1184
- this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
1185
- const g = s.value;
1186
- this.searchDebounceTimer = setTimeout(() => {
1187
- this.performSearch(g, !1, !1);
1188
- }, 120);
1189
- });
1190
- const u = () => {
1191
- this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = d.checked, this.searchOptions.regex = p.checked;
1192
- const g = s.value;
1193
- g.trim() ? this.performSearch(g, !1, !1) : this.performSearch("", !1, !1);
1194
- };
1195
- c.addEventListener("change", u), d.addEventListener("change", u), p.addEventListener("change", u), s.addEventListener("keydown", (g) => {
1196
- g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.findPrev() : this.findNext()) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
1197
- }), n.addEventListener("keydown", (g) => {
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);
1200
- }
1201
- updateModeHint(e) {
1202
- this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
1203
- }
1204
- performSearch(e, t, i) {
1205
- if (!this.editor || !e.trim()) {
1206
- this.currentQuery = "", this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("");
1207
- return;
1208
- }
1209
- if (this.searchOptions.regex && !this.isValidRegex(e)) {
1210
- this.currentQuery = e, this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Invalid regular expression");
1211
- return;
1212
- }
1213
- this.currentQuery = e;
1214
- const s = this.currentIndex, n = this.editor.search(e, this.searchOptions);
1215
- if (this.currentResults = n, n.length === 0) {
1216
- this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
1217
- return;
1218
- }
1219
- t && s >= 0 ? this.currentIndex = Math.min(s, n.length - 1) : this.currentIndex = 0, this.updateHighlights(i);
1220
- }
1221
- findNext() {
1222
- if (this.currentResults.length === 0) {
1223
- this.currentQuery && this.performSearch(this.currentQuery, !0, !0);
1224
- return;
1225
- }
1226
- this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights(!0);
1227
- }
1228
- findPrev() {
1229
- if (this.currentResults.length === 0) {
1230
- this.currentQuery && this.performSearch(this.currentQuery, !0, !0);
1231
- return;
1232
- }
1233
- this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights(!0);
1234
- }
1235
- replaceCurrent(e, t) {
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) {
1243
- this.currentQuery = e;
1244
- const n = this.editor.search(e, this.searchOptions);
1245
- if (this.currentResults = n, n.length === 0) {
1246
- this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
1247
- return;
1248
- }
1249
- this.currentIndex = this.findNextResultIndexAfter(s.end, n), this.updateHighlights(!0);
1250
- } else
1251
- this.scrollLogicalRangeIntoView(s, !0), this.performSearch(e, !0, !1);
1252
- this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
1253
- }
1254
- replaceAll(e, t) {
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();
1259
- }
1260
- updateHighlights(e) {
1261
- if (this.clearHighlights(), this.currentResults.length === 0 || this.currentIndex === -1 || !this.editor)
1262
- return;
1263
- this.applyCustomHighlights();
1264
- const t = this.currentResults[this.currentIndex];
1265
- t && ((e || !this.hasCustomHighlightSupport) && this.navigateToResult(t, !this.hasCustomHighlightSupport), this.updateStatus(
1266
- `${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`
1267
- ));
1268
- }
1269
- navigateToResult(e, t) {
1270
- if (!this.editor)
1271
- return;
1272
- const i = document.activeElement, s = !!i && (i === this.findInput || i === this.replaceInputEl);
1273
- t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
1274
- const n = this.editor.getView();
1275
- t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t && s && i && requestAnimationFrame(() => {
1276
- this.focusWithoutScrolling(i);
1277
- });
1278
- }
1279
- clearHighlights() {
1280
- var e, t;
1281
- if (this.hasCustomHighlightSupport)
1282
- try {
1283
- const i = CSS;
1284
- (e = i.highlights) == null || e.delete(this.highlightMatchName), (t = i.highlights) == null || t.delete(this.highlightActiveName);
1285
- } catch (i) {
1286
- }
1287
- }
1288
- scrollResultIntoView(e) {
1289
- this.scrollLogicalRangeIntoView(e.range, !0);
1290
- }
1291
- scrollLogicalRangeIntoView(e, t) {
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) {
1308
- h == null || h.scrollIntoView({
1309
- block: t ? "center" : "nearest",
1310
- inline: "nearest",
1311
- behavior: "smooth"
1312
- });
1313
- return;
1314
- }
1315
- (g !== a.scrollTop || f !== a.scrollLeft) && a.scrollTo({
1316
- top: g,
1317
- left: f,
1318
- behavior: "smooth"
1319
- });
1320
- return;
1321
- }
1322
- h == null || h.scrollIntoView({
1323
- block: t ? "center" : "nearest",
1324
- inline: "nearest",
1325
- behavior: "smooth"
1326
- });
1327
- }
1328
- restoreReplaceInputFocus() {
1329
- const e = this.replaceInputEl;
1330
- !e || e.style.display === "none" || requestAnimationFrame(() => {
1331
- this.focusWithoutScrolling(e);
1332
- const t = e.value.length;
1333
- try {
1334
- e.setSelectionRange(t, t);
1335
- } catch (i) {
1336
- }
1337
- });
1338
- }
1339
- centerCurrentSelectionInView() {
1340
- if (!this.editor)
1341
- return;
1342
- const e = this.editor.getView().getContentElement(), t = this.resolveScrollContainer(e);
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));
1352
- h !== t.scrollTop && t.scrollTo({
1353
- top: h,
1354
- behavior: "smooth"
1355
- });
1356
- }
1357
- computeReplacementRange(e, t) {
1358
- const i = t.replace(/\r\n?/g, `
1359
- `), s = i.split(`
1360
- `);
1361
- let n;
1362
- return s.length <= 1 ? (n = {
1363
- start: e,
1364
- end: {
1365
- line: e.line,
1366
- column: e.column + i.length
1367
- }
1368
- }, this.clampRangeToDocument(n)) : (n = {
1369
- start: e,
1370
- end: {
1371
- line: e.line + s.length - 1,
1372
- column: s[s.length - 1].length
1373
- }
1374
- }, this.clampRangeToDocument(n));
1375
- }
1376
- findNextResultIndexAfter(e, t) {
1377
- for (let i = 0; i < t.length; i++)
1378
- if (this.comparePositions(t[i].range.start, e) >= 0)
1379
- return i;
1380
- return 0;
1381
- }
1382
- comparePositions(e, t) {
1383
- return e.line !== t.line ? e.line - t.line : e.column - t.column;
1384
- }
1385
- clampRangeToDocument(e) {
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(
1392
- 0,
1393
- Math.min(e.start.column, ((t = n[o]) == null ? void 0 : t.length) || 0)
1394
- ), a = Math.max(
1395
- 0,
1396
- Math.min(e.end.column, ((i = n[l]) == null ? void 0 : i.length) || 0)
1397
- );
1398
- return {
1399
- start: { line: o, column: h },
1400
- end: { line: l, column: a }
1401
- };
1402
- }
1403
- focusWithoutScrolling(e) {
1404
- try {
1405
- e.focus({
1406
- preventScroll: !0
1407
- });
1408
- } catch (t) {
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;
1417
- const n = window.scrollX, r = window.scrollY;
1418
- e.focus();
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;
1422
- }
1423
- window.scrollTo(n, r);
1424
- }
1425
- }
1426
- findScrollContainer(e) {
1427
- let t = e;
1428
- for (; t; ) {
1429
- const i = window.getComputedStyle(t).overflowY;
1430
- if ((i === "auto" || i === "scroll") && t.scrollHeight > t.clientHeight)
1431
- return t;
1432
- t = t.parentElement;
1433
- }
1434
- return null;
1435
- }
1436
- resolveScrollContainer(e) {
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);
1440
- }
1441
- canScroll(e) {
1442
- return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
1443
- }
1444
- revealActiveResultAfterFocusRestore() {
1445
- !this.currentResults.length || this.currentIndex < 0 || requestAnimationFrame(() => {
1446
- const e = this.currentResults[this.currentIndex];
1447
- e && this.scrollResultIntoView(e);
1448
- });
1449
- }
1450
- applyCustomHighlights() {
1451
- if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
1452
- return;
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;
1458
- const h = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
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(
1461
- c.range,
1462
- i,
1463
- s,
1464
- n,
1465
- r,
1466
- d
1467
- );
1468
- p && (o.push(p), a === this.currentIndex && (l = p));
1469
- }
1470
- if (o.length !== 0)
1471
- try {
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) {
1477
- }
1478
- }
1479
- buildLineStarts(e) {
1480
- const t = e.split(`
1481
- `), i = new Array(t.length);
1482
- let s = 0;
1483
- for (let n = 0; n < t.length; n++)
1484
- i[n] = s, s += t[n].length + 1;
1485
- return { lineStarts: i, lines: t };
1486
- }
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;
1491
- }
1492
- buildTextNodeIndex(e) {
1493
- const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), i = [];
1494
- let s = 0, n;
1495
- for (; n = t.nextNode(); ) {
1496
- const r = n, o = r.parentElement;
1497
- if (o != null && o.hasAttribute(this.trailingMarkerAttr))
1498
- continue;
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,
1504
- visibleToDom: h
1505
- }), s += a);
1506
- }
1507
- return i;
1508
- }
1509
- resolveDomPoint(e, t) {
1510
- var o, l, h, a;
1511
- var i, s;
1512
- const n = Math.max(0, e);
1513
- for (let c = 0; c < t.length; c++) {
1514
- const d = t[c];
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;
1517
- return {
1518
- node: d.node,
1519
- offset: u
1520
- };
1521
- }
1522
- }
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
1527
- } : null;
1528
- }
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);
1532
- if (n && r) {
1533
- const u = r, g = n.slice(h, a);
1534
- if (g.length === u.length && g.toLowerCase() !== u.toLowerCase()) {
1535
- const f = this.findNearestMatchOffset(
1536
- n,
1537
- u,
1538
- h
1539
- );
1540
- f !== -1 && (h = f, a = f + u.length);
1541
- }
1542
- }
1543
- const c = this.resolveDomPoint(h, s), d = this.resolveDomPoint(a, s);
1544
- if (!c || !d)
1545
- return null;
1546
- const p = document.createRange();
1547
- try {
1548
- return p.setStart(c.node, c.offset), p.setEnd(d.node, d.offset), p;
1549
- } catch (u) {
1550
- return null;
1551
- }
1552
- }
1553
- buildVisibleDocumentText(e) {
1554
- let t = "";
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];
1559
- this.virtualMarkerRegex.test(r) || (t += r);
1560
- }
1561
- }
1562
- return t;
1563
- }
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);
1570
- for (; n !== -1; ) {
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);
1575
- }
1576
- return r;
1577
- }
1578
- scheduleLiveRefresh(e) {
1579
- this.liveRefreshTimer && clearTimeout(this.liveRefreshTimer);
1580
- const t = this.currentQuery;
1581
- this.liveRefreshTimer = setTimeout(() => {
1582
- !this.isVisible || !t || this.performSearch(t, e, !1);
1583
- }, 90);
1584
- }
1585
- updateStatus(e, t = !1) {
1586
- if (this.statusDiv) {
1587
- if (!t && Date.now() < this.statusFreezeUntil)
1588
- return;
1589
- this.statusDiv.textContent = e;
1590
- }
1591
- }
1592
- showTransientStatus(e, t = 900) {
1593
- this.statusFreezeUntil = Date.now() + t, this.updateStatus(e, !0), this.statusResetTimer && clearTimeout(this.statusResetTimer), this.statusResetTimer = setTimeout(() => {
1594
- this.statusFreezeUntil = 0, this.syncMatchStatus();
1595
- }, t);
1596
- }
1597
- syncMatchStatus() {
1598
- if (!this.currentQuery) {
1599
- this.updateStatus("", !0);
1600
- return;
1601
- }
1602
- if (this.currentResults.length === 0 || this.currentIndex < 0) {
1603
- this.updateStatus("No matches", !0);
1604
- return;
1605
- }
1606
- this.updateStatus(
1607
- `${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`,
1608
- !0
1609
- );
1610
- }
1611
- isValidRegex(e) {
1612
- try {
1613
- const t = this.searchOptions.caseSensitive ? "g" : "gi";
1614
- return new RegExp(e, t), !0;
1615
- } catch (t) {
1616
- return !1;
1617
- }
1618
- }
1619
- captureSelectionState() {
1620
- this.editor && (this.savedSelection = this.editor.getSelection(), this.savedCursor = this.editor.getCursor().position);
1621
- }
1622
- restoreSelectionState() {
1623
- this.editor && (this.savedSelection ? this.editor.setSelection(this.savedSelection) : this.savedCursor && this.editor.setCursor(this.savedCursor), this.savedSelection = void 0, this.savedCursor = null);
1624
- }
1625
- detectCustomHighlightSupport() {
1626
- try {
1627
- const e = CSS, t = window.Highlight;
1628
- return !!e.highlights && !!t;
1629
- } catch (e) {
1630
- return !1;
1631
- }
1632
- }
1633
- buildVisibleToDomMap(e) {
1634
- const t = [0];
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);
1639
- }
1640
- return t;
1641
- }
1642
- ensureHighlightStyles() {
1643
- if (document.getElementById(this.highlightStyleId))
1644
- return;
1645
- const e = document.createElement("style");
1646
- e.id = this.highlightStyleId, e.textContent = `
1647
- ::highlight(${this.highlightMatchName}) {
1648
- background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34));
1649
- border-radius: 2px;
1650
- }
1651
- ::highlight(${this.highlightActiveName}) {
1652
- background: var(--lce-search-active-bg, rgba(255, 154, 0, 0.45));
1653
- border-radius: 2px;
1654
- }
1655
- `, document.head.appendChild(e);
1656
- }
1657
- destroy() {
1658
- this.searchDebounceTimer && (clearTimeout(this.searchDebounceTimer), this.searchDebounceTimer = null), this.liveRefreshTimer && (clearTimeout(this.liveRefreshTimer), this.liveRefreshTimer = null), this.statusResetTimer && (clearTimeout(this.statusResetTimer), this.statusResetTimer = null), this.clearHighlights(), this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.editor && this.editorChangeHandler && this.editor.off("change", this.editorChangeHandler), this.editorChangeHandler = null, this.findInput = null, this.replaceInputEl = null, this.statusDiv = null, this.modeDiv = null, this.caseSensitiveInput = null, this.wholeWordInput = null, this.regexInput = null, this.searchUI = null;
1659
- const e = document.getElementById(this.highlightStyleId);
1660
- e != null && e.parentNode && e.parentNode.removeChild(e), this.editor = null;
1661
- }
1662
- };
1663
- W.css = {
1664
- root: "lce-search-ui",
1665
- row: "lce-search-row",
1666
- options: "lce-search-options",
1667
- optionLabel: "lce-search-option",
1668
- optionInput: "lce-search-option-input",
1669
- caseSensitive: "search-case-sensitive",
1670
- wholeWord: "search-whole-word",
1671
- regex: "search-regex",
1672
- meta: "lce-search-meta",
1673
- findInput: "search-find-input",
1674
- replaceInput: "search-replace-input",
1675
- inputBase: "lce-search-input",
1676
- replaceInputLayout: "lce-search-replace",
1677
- prevButton: "search-prev",
1678
- nextButton: "search-next",
1679
- closeButton: "search-close",
1680
- buttonBase: "lce-search-btn",
1681
- status: "search-status",
1682
- statusLayout: "lce-search-status",
1683
- mode: "search-mode",
1684
- modeLayout: "lce-search-mode"
1685
- };
1686
- let ie = W;
1687
- class se {
1688
- constructor() {
1689
- this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
1690
- "(": ")",
1691
- "[": "]",
1692
- "{": "}",
1693
- "<": ">"
1694
- }, this.reverseBracketPairs = {
1695
- ")": "(",
1696
- "]": "[",
1697
- "}": "{",
1698
- ">": "<"
1699
- }, this.currentMatch = null;
1700
- }
1701
- setup(e) {
1702
- this.editor = e, e.on("cursor", () => {
1703
- this.updateBracketMatching();
1704
- }), e.on("change", () => {
1705
- this.updateBracketMatching();
1706
- });
1707
- }
1708
- updateBracketMatching() {
1709
- if (!this.editor)
1710
- return;
1711
- const e = this.editor.getCursor(), t = this.editor.getValue();
1712
- this.clearBracketHighlighting();
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));
1718
- }
1719
- getBracketAtPosition(e, t) {
1720
- const i = e.split(`
1721
- `);
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];
1728
- return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
1729
- }
1730
- findMatchingBracket(e, t) {
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;
1734
- }
1735
- findClosingBracket(e, t, i, s, n) {
1736
- const r = this.bracketPairs[n];
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++) {
1741
- const d = h[c];
1742
- if (d === n)
1743
- o++;
1744
- else if (d === r && (o--, o === 0))
1745
- return {
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 } },
1748
- type: n
1749
- };
1750
- }
1751
- }
1752
- return null;
1753
- }
1754
- findOpeningBracket(e, t, i, s, n) {
1755
- const r = this.reverseBracketPairs[n];
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--) {
1760
- const d = h[c];
1761
- if (d === n)
1762
- o++;
1763
- else if (d === r && (o--, o === 0))
1764
- return {
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 } },
1767
- type: r
1768
- };
1769
- }
1770
- }
1771
- return null;
1772
- }
1773
- highlightBrackets(e) {
1774
- }
1775
- clearBracketHighlighting() {
1776
- this.currentMatch = null;
1777
- }
1778
- getCurrentMatch() {
1779
- return this.currentMatch;
1780
- }
1781
- destroy() {
1782
- this.clearBracketHighlighting(), this.editor = null;
1783
- }
1784
- }
1785
- class ne {
1786
- constructor() {
1787
- this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null, this.pendingUpdateRaf = null, this.lastSnapshot = "", this.changeHandler = null;
1788
- }
1789
- setup(e) {
1790
- this.editor = e, e.registerCommand("fold", () => {
1791
- this.foldAtCursor();
1792
- }), e.registerCommand("unfold", () => {
1793
- this.unfoldAtCursor();
1794
- }), e.registerCommand("foldAll", () => {
1795
- this.foldAll();
1796
- }), e.registerCommand("unfoldAll", () => {
1797
- this.unfoldAll();
1798
- }), this.changeHandler = () => {
1799
- this.scheduleFoldIndicatorUpdate();
1800
- }, e.on("change", this.changeHandler), this.createFoldingUI(), this.scheduleFoldIndicatorUpdate();
1801
- }
1802
- createFoldingUI() {
1803
- if (!this.editor)
1804
- return;
1805
- const e = this.editor.getView().getContentElement(), t = e.closest(".rte-source-editor-modal") || e.parentElement;
1806
- t && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
1807
- position: absolute;
1808
- left: 40px;
1809
- top: 0;
1810
- bottom: 0;
1811
- width: 20px;
1812
- pointer-events: none;
1813
- z-index: 2;
1814
- `, t.appendChild(this.foldingUI));
1815
- }
1816
- scheduleFoldIndicatorUpdate() {
1817
- this.pendingUpdateRaf === null && (this.pendingUpdateRaf = requestAnimationFrame(() => {
1818
- this.pendingUpdateRaf = null, this.updateFoldIndicators();
1819
- }));
1820
- }
1821
- updateFoldIndicators() {
1822
- if (!this.editor || !this.foldingUI)
1823
- return;
1824
- const e = this.editor.getValue();
1825
- if (e === this.lastSnapshot)
1826
- return;
1827
- this.lastSnapshot = e, this.foldingUI.innerHTML = "", this.foldIndicators = [];
1828
- const t = e.split(`
1829
- `), i = this.findFoldableLines(t), s = document.createDocumentFragment();
1830
- i.forEach((n) => {
1831
- const r = this.createFoldIndicator(n);
1832
- s.appendChild(r), this.foldIndicators.push(r);
1833
- }), this.foldingUI.appendChild(s);
1834
- }
1835
- findFoldableLines(e) {
1836
- const t = [];
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);
1840
- }
1841
- return t;
1842
- }
1843
- createFoldIndicator(e) {
1844
- const t = document.createElement("div");
1845
- return t.style.cssText = `
1846
- position: absolute;
1847
- left: 0;
1848
- top: ${e * 21}px;
1849
- width: 20px;
1850
- height: 21px;
1851
- display: flex;
1852
- align-items: center;
1853
- justify-content: center;
1854
- cursor: pointer;
1855
- pointer-events: auto;
1856
- color: var(--editor-gutter-foreground, #858585);
1857
- font-size: 10px;
1858
- user-select: none;
1859
- `, t.innerHTML = "▶", t.title = "Code folding not yet implemented - click shows fold indicators", t.addEventListener("click", () => {
1860
- }), t;
1861
- }
1862
- foldAtCursor() {
1863
- }
1864
- unfoldAtCursor() {
1865
- }
1866
- foldAll() {
1867
- }
1868
- unfoldAll() {
1869
- }
1870
- destroy() {
1871
- this.pendingUpdateRaf !== null && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.changeHandler = null, this.lastSnapshot = "", this.foldingUI = null, this.foldIndicators = [], this.editor = null;
1872
- }
1873
- }
1874
- class re {
1875
- constructor() {
1876
- this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
1877
- }
1878
- setup(e) {
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) });
1880
- }
1881
- // Extension provides methods that can be called by the editor
1882
- setTheme(e) {
1883
- this.currentTheme = e;
1884
- }
1885
- setLanguage(e) {
1886
- this.currentLanguage = e;
1887
- }
1888
- registerMode(e, t) {
1889
- this.modes.set(e.toLowerCase(), t);
1890
- }
1891
- // Method to get syntax highlighting colors for a given theme
1892
- getSyntaxColors() {
1893
- return this.currentTheme === "dark" ? {
1894
- tag: "#569cd6",
1895
- // Blue
1896
- comment: "#6a9955",
1897
- // Green
1898
- attrName: "#9cdcfe",
1899
- // Light blue for attribute names
1900
- attrValue: "#ce9178",
1901
- // Orange for attribute values
1902
- styleProp: "#c586c0",
1903
- // Purple for CSS property names
1904
- styleVal: "#dcdcaa",
1905
- // Yellow-ish for CSS values
1906
- doctype: "#808080",
1907
- // Gray for doctype
1908
- text: "#d4d4d4",
1909
- // Light gray for normal text
1910
- keyword: "#c586c0",
1911
- // JS/PHP keywords (purple)
1912
- string: "#ce9178",
1913
- // JS strings
1914
- number: "#b5cea8",
1915
- // numbers
1916
- variable: "#9cdcfe"
1917
- // php variable color
1918
- } : {
1919
- tag: "#0000ff",
1920
- // Blue
1921
- comment: "#008000",
1922
- // Green
1923
- attrName: "#001080",
1924
- attrValue: "#a31515",
1925
- // Red
1926
- styleProp: "#6a00a8",
1927
- styleVal: "#804000",
1928
- doctype: "#444444",
1929
- text: "#000000",
1930
- // Black
1931
- keyword: "#000080",
1932
- string: "#a31515",
1933
- number: "#0086b3",
1934
- variable: "#001080"
1935
- };
1936
- }
1937
- // Public API: highlight a source string using the chosen mode (or detect html)
1938
- highlight(e, t) {
1939
- const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
1940
- return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
1941
- }
1942
- // Backwards-compatible method
1943
- highlightHTML(e) {
1944
- return this.highlight(e, "html");
1945
- }
1946
- // --- Internal mode implementations ---
1947
- escapeHTML(e) {
1948
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;");
1949
- }
1950
- // Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
1951
- unescapeEntitiesRepeated(e) {
1952
- let t = e || "";
1953
- for (let i = 0; i < 5; i++) {
1954
- const s = t;
1955
- if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === s)
1956
- break;
1957
- }
1958
- return t;
1959
- }
1960
- _highlightHTML(e, t) {
1961
- const i = t, s = (h) => this.escapeHTML(h);
1962
- let n = s(e);
1963
- const r = (h) => {
1964
- let a = h.replace(/&quot;/g, '"').replace(/&#39;/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 = [];
1970
- try {
1971
- e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (h, a, c) => (o.push({ attrs: String(a || ""), inner: String(c || "") }), h));
1972
- } catch (h) {
1973
- }
1974
- let l = 0;
1975
- return n = n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/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(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (h, a, c, d) => {
1983
- const p = r(c);
1984
- return `${a}${p}${d}`;
1985
- }), n = n.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${i.comment};">$1</span>`), n = n.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${i.doctype};">$1</span>`), n = n.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (h, a, c, d, p) => {
1986
- const u = `<span style="color: ${i.tag};">${c}</span>`;
1987
- let g = d;
1988
- return g = g.replace(
1989
- /([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
1990
- (f, y, C, v) => {
1991
- const S = String(y).toLowerCase(), E = `<span style="color: ${i.attrName};">${y}</span>`;
1992
- let M = v, b = "";
1993
- v.startsWith("&quot;") && v.endsWith("&quot;") ? (M = v.slice(6, -6), b = "&quot;") : v.startsWith("&#39;") && v.endsWith("&#39;") && (M = v.slice(5, -5), b = "&#39;");
1994
- let T = v;
1995
- if (S === "style") {
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>`;
1998
- } else
1999
- b && (T = `${b}${M}${b}`), T = `<span style="color: ${i.attrValue};">${T}</span>`;
2000
- return `${E}${C}${T}`;
2001
- }
2002
- ), `${a}${u}${g}${p}`;
2003
- }), n;
2004
- }
2005
- _highlightJS(e, t) {
2006
- const i = this.unescapeEntitiesRepeated(e);
2007
- this.escapeHTML(i);
2008
- const s = [], n = (d) => {
2009
- let p = "", u = d;
2010
- do
2011
- p = String.fromCharCode(97 + u % 26) + p, u = Math.floor(u / 26) - 1;
2012
- while (u >= 0);
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);
2017
- };
2018
- let l;
2019
- const h = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
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;
2026
- }
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) => {
2031
- let u = 0;
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] || "";
2035
- });
2036
- }
2037
- _highlightPHP(e, t) {
2038
- const i = this.unescapeEntitiesRepeated(e);
2039
- let s = this.escapeHTML(i);
2040
- const n = [], r = (u) => {
2041
- let g = "", f = u;
2042
- do
2043
- g = String.fromCharCode(97 + f % 26) + g, f = Math.floor(f / 26) - 1;
2044
- while (f >= 0);
2045
- return g || "a";
2046
- }, o = (u) => {
2047
- const g = n.length;
2048
- return n.push(u), `\0${r(g)}\0`;
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);
2052
- };
2053
- let h;
2054
- const a = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, p = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
2055
- for (; h = a.exec(i); ) {
2056
- const u = h[0];
2057
- l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
2058
- }
2059
- for (; h = c.exec(i); ) {
2060
- const u = h[0];
2061
- l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
2062
- }
2063
- for (; h = d.exec(i); ) {
2064
- const u = h[0];
2065
- l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
2066
- }
2067
- for (; h = p.exec(i); ) {
2068
- const u = h[0];
2069
- l(this.escapeHTML(u), o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`));
2070
- }
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;
2073
- for (let y = 0; y < g.length; y++)
2074
- f = f * 26 + (g.charCodeAt(y) - 97 + 1);
2075
- return f = f - 1, n[f] || "";
2076
- }), s;
2077
- }
2078
- // Method to check if content contains syntax that should be highlighted
2079
- shouldHighlight(e) {
2080
- return /<\/?[\w:-]+|<!--/.test(e);
2081
- }
2082
- destroy() {
2083
- this.editor = null, this.modes.clear();
2084
- }
2085
- }
2086
- function oe(w, e) {
2087
- const t = { ...e };
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);
2089
- }
2090
- const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Editor Dialog Styles */
2091
- .rte-source-editor-overlay {
2092
- position: fixed !important;
2093
- top: 0 !important;
2094
- left: 0 !important;
2095
- right: 0 !important;
2096
- bottom: 0 !important;
2097
- width: 100vw !important;
2098
- height: 100vh !important;
2099
- background-color: rgba(0, 0, 0, 0.6) !important;
2100
- display: flex !important;
2101
- align-items: center !important;
2102
- justify-content: center !important;
2103
- z-index: 10000 !important;
2104
- padding: 20px !important;
2105
- box-sizing: border-box !important;
2106
- margin: 0 !important;
2107
- }
2108
-
2109
- .rte-source-editor-overlay.fullscreen {
2110
- padding: 0 !important;
2111
- }
2112
-
2113
- .rte-source-editor-modal {
2114
- background: white;
2115
- border-radius: 8px;
2116
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
2117
- width: 100%;
2118
- max-width: 1200px;
2119
- max-height: 90vh;
2120
- display: flex;
2121
- flex-direction: column;
2122
- overflow: hidden;
2123
- position: relative;
2124
- }
2125
-
2126
- .rte-source-editor-overlay.fullscreen .rte-source-editor-modal {
2127
- border-radius: 0;
2128
- max-width: 100%;
2129
- max-height: 100vh;
2130
- width: 100%;
2131
- height: 100vh;
2132
- }
2133
-
2134
- .rte-source-editor-header {
2135
- display: flex;
2136
- align-items: center;
2137
- justify-content: space-between;
2138
- padding: 16px 20px;
2139
- border-bottom: 1px solid #e1e5e9;
2140
- background: #f8f9fa;
2141
- border-radius: 8px 8px 0 0;
2142
- }
2143
-
2144
- .rte-source-editor-overlay.fullscreen .rte-source-editor-header {
2145
- border-radius: 0;
2146
- }
2147
-
2148
- .rte-source-editor-header h2 {
2149
- margin: 0;
2150
- font-size: 18px;
2151
- font-weight: 600;
2152
- color: #1a1a1a;
2153
- }
2154
-
2155
- .rte-source-editor-header-toolbar {
2156
- display: flex;
2157
- gap: 8px;
2158
- margin-left: auto;
2159
- margin-right: 16px;
2160
- }
2161
-
2162
- .rte-source-editor-toolbar-btn {
2163
- background: none;
2164
- border: none;
2165
- cursor: pointer;
2166
- padding: 6px;
2167
- border-radius: 4px;
2168
- font-size: 16px;
2169
- line-height: 1;
2170
- transition: all 0.2s ease;
2171
- color: #666;
2172
- }
2173
-
2174
- .rte-source-editor-toolbar-btn:hover:not(:disabled) {
2175
- background: #e1e5e9;
2176
- color: #1a1a1a;
2177
- }
2178
-
2179
- .rte-source-editor-toolbar-btn:disabled {
2180
- opacity: 0.5;
2181
- cursor: not-allowed;
2182
- }
2183
-
2184
- .rte-source-editor-toolbar-btn.active {
2185
- background: #007acc;
2186
- color: white;
2187
- }
2188
-
2189
- .rte-source-editor-toolbar-btn.active:hover {
2190
- background: #0056b3;
2191
- }
2192
-
2193
- .rte-source-editor-header-actions {
2194
- display: flex;
2195
- gap: 8px;
2196
- }
2197
-
2198
- .rte-source-editor-fullscreen-btn,
2199
- .rte-source-editor-close-btn {
2200
- background: none;
2201
- border: none;
2202
- cursor: pointer;
2203
- padding: 4px;
2204
- border-radius: 4px;
2205
- color: #666;
2206
- font-size: 16px;
2207
- line-height: 1;
2208
- transition: all 0.2s ease;
2209
- }
2210
-
2211
- .rte-source-editor-fullscreen-btn:hover,
2212
- .rte-source-editor-close-btn:hover {
2213
- background: #e1e5e9;
2214
- color: #1a1a1a;
2215
- }
2216
-
2217
- .rte-source-editor-body {
2218
- flex: 1;
2219
- overflow: hidden;
2220
- display: flex;
2221
- flex-direction: column;
2222
- }
2223
-
2224
- .rte-source-editor-loading {
2225
- display: flex;
2226
- flex-direction: column;
2227
- align-items: center;
2228
- justify-content: center;
2229
- padding: 40px;
2230
- color: #666;
2231
- position: absolute;
2232
- z-index: 9;
2233
- margin: 0 auto;
2234
- width: 100%;
2235
- top: 44%;
2236
- }
2237
-
2238
- .rte-source-editor-spinner {
2239
- width: 32px;
2240
- height: 32px;
2241
- border: 3px solid #e1e5e9;
2242
- border-top: 3px solid #007acc;
2243
- border-radius: 50%;
2244
- animation: spin 1s linear infinite;
2245
- margin-bottom: 16px;
2246
- }
2247
-
2248
- @keyframes spin {
2249
- 0% { transform: rotate(0deg); }
2250
- 100% { transform: rotate(360deg); }
2251
- }
2252
-
2253
- .rte-source-editor-error {
2254
- background: #fee;
2255
- color: #c53030;
2256
- padding: 12px 16px;
2257
- border-left: 4px solid #c53030;
2258
- margin: 16px;
2259
- border-radius: 4px;
2260
- font-size: 14px;
2261
- }
2262
-
2263
- .rte-source-editor-content {
2264
- flex: 1;
2265
- display: flex;
2266
- flex-direction: column;
2267
- overflow: hidden;
2268
- }
2269
-
2270
- .rte-source-editor-warning {
2271
- background: #fefcbf;
2272
- color: #744210;
2273
- padding: 8px 16px;
2274
- font-size: 12px;
2275
- font-weight: 500;
2276
- border-bottom: 1px solid #f6e05e;
2277
- }
2278
-
2279
- .rte-source-editor-codemirror {
2280
- flex: 1;
2281
- overflow: auto;
2282
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
2283
- font-size: 14px;
2284
- line-height: 1.5;
2285
- }
2286
-
2287
- .rte-source-editor-codemirror .cm-editor {
2288
- height: 100%;
2289
- }
2290
-
2291
- .rte-source-editor-codemirror .cm-focused {
2292
- outline: none;
2293
- }
2294
-
2295
- .rte-source-editor-footer {
2296
- display: flex;
2297
- align-items: center;
2298
- justify-content: space-between;
2299
- padding: 16px 20px;
2300
- border-top: 1px solid #e1e5e9;
2301
- background: #f8f9fa;
2302
- border-radius: 0 0 8px 8px;
2303
- }
2304
-
2305
- .rte-source-editor-overlay.fullscreen .rte-source-editor-footer {
2306
- border-radius: 0;
2307
- }
2308
-
2309
- .rte-source-editor-footer-info {
2310
- font-size: 12px;
2311
- color: #666;
2312
- }
2313
-
2314
- .unsaved-changes {
2315
- color: #d69e2e;
2316
- font-weight: 500;
2317
- }
2318
-
2319
- .rte-source-editor-footer-actions {
2320
- display: flex;
2321
- gap: 12px;
2322
- }
2323
-
2324
- .rte-source-editor-btn {
2325
- padding: 8px 16px;
2326
- border-radius: 4px;
2327
- font-size: 14px;
2328
- font-weight: 500;
2329
- cursor: pointer;
2330
- border: 1px solid transparent;
2331
- transition: all 0.2s ease;
2332
- }
2333
-
2334
- .rte-source-editor-btn:disabled {
2335
- opacity: 0.6;
2336
- cursor: not-allowed;
2337
- }
2338
-
2339
- .rte-source-editor-btn-cancel {
2340
- background: white;
2341
- border-color: #d1d5db;
2342
- color: #374151;
2343
- }
2344
-
2345
- .rte-source-editor-btn-cancel:hover:not(:disabled) {
2346
- background: #f9fafb;
2347
- border-color: #9ca3af;
2348
- }
2349
-
2350
- .rte-source-editor-btn-save {
2351
- background: #007acc;
2352
- color: white;
2353
- }
2354
-
2355
- .rte-source-editor-btn-save:hover:not(:disabled) {
2356
- background: #0056b3;
2357
- }
2358
-
2359
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
2360
- background: #1e1e1e;
2361
- color: #f8f9fa;
2362
- border: 1px solid #434d5f;
2363
- }
2364
-
2365
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
2366
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
2367
- background: #2a3442;
2368
- border-color: #434d5f;
2369
- }
2370
-
2371
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
2372
- color: #f8f9fa;
2373
- }
2374
-
2375
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
2376
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
2377
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
2378
- color: #c1cede;
2379
- }
2380
-
2381
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
2382
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
2383
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
2384
- background: #404a5a;
2385
- color: #f8fafc;
2386
- }
2387
-
2388
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
2389
- background: #3b82f6;
2390
- color: #ffffff;
2391
- }
2392
-
2393
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
2394
- background: #2563eb;
2395
- }
2396
-
2397
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
2398
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
2399
- color: #cbd5e1;
2400
- }
2401
-
2402
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
2403
- border-color: #3f4b60;
2404
- border-top-color: #58a6ff;
2405
- }
2406
-
2407
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
2408
- background: #3f2124;
2409
- color: #fecaca;
2410
- border-color: #ef4444;
2411
- }
2412
-
2413
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
2414
- background: #3b3220;
2415
- color: #fde68a;
2416
- border-color: #f59e0b;
2417
- }
2418
-
2419
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
2420
- background: #334155;
2421
- border-color: #475569;
2422
- color: #f1f5f9;
2423
- }
2424
-
2425
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
2426
- background: #475569;
2427
- border-color: #64748b;
2428
- }
2429
-
2430
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
2431
- background: #3b82f6;
2432
- }
2433
-
2434
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
2435
- background: #2563eb;
2436
- }
2437
-
2438
- /* Responsive design */
2439
- @media (max-width: 768px) {
2440
- .rte-source-editor-overlay {
2441
- padding: 10px;
2442
- }
2443
-
2444
- .rte-source-editor-modal {
2445
- max-height: 95vh;
2446
- }
2447
-
2448
- .rte-source-editor-header {
2449
- padding: 12px 16px;
2450
- }
2451
-
2452
- .rte-source-editor-footer {
2453
- padding: 12px 16px;
2454
- flex-direction: column;
2455
- gap: 12px;
2456
- align-items: stretch;
2457
- }
2458
-
2459
- .rte-source-editor-footer-actions {
2460
- justify-content: stretch;
2461
- }
2462
-
2463
- .rte-source-editor-btn {
2464
- flex: 1;
2465
- text-align: center;
2466
- }
2467
- }`, ae = () => ({
2468
- name: "code",
2469
- // Toolbar button configuration
2470
- toolbar: [
2471
- {
2472
- label: "Source",
2473
- command: "toggleSourceView",
2474
- // type: "button",
2475
- 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>',
2476
- shortcut: "Mod-Shift-S"
2477
- }
2478
- ],
2479
- // Native command implementations
2480
- commands: {
2481
- /**
2482
- * Toggle HTML source view
2483
- * Opens a dialog to edit raw HTML
2484
- */
2485
- toggleSourceView: () => {
2486
- const e = (() => {
2487
- var o, l, h;
2488
- const n = window.getSelection();
2489
- if (n && n.anchorNode) {
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;
2495
- }
2496
- }
2497
- if (document.activeElement) {
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(
2505
- ".rte-content"
2506
- );
2507
- if (c)
2508
- return c;
2509
- a = a.parentElement;
2510
- }
2511
- }
2512
- const r = document.querySelector("[data-editora-editor]");
2513
- if (r) {
2514
- const a = r.querySelector(
2515
- ".rte-content"
2516
- );
2517
- if (a)
2518
- return a;
2519
- }
2520
- return document.querySelector(".rte-content");
2521
- })();
2522
- if (!e)
2523
- return console.error("[CodePlugin] Editor content area not found"), alert(
2524
- "Editor content area not found. Please click inside the editor first."
2525
- ), !1;
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());
2534
- return r.trim();
2535
- };
2536
- return (() => {
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");
2541
- const g = document.createElement("div");
2542
- g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
2543
- const f = document.createElement("div");
2544
- f.className = "rte-source-editor-header", f.innerHTML = `
2545
- <h2 id="source-editor-title">Source Editor</h2>
2546
- <div class="rte-source-editor-header-toolbar">
2547
- <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
2548
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2549
- <circle cx="12" cy="12" r="5"/>
2550
- <line x1="12" y1="1" x2="12" y2="3"/>
2551
- <line x1="12" y1="21" x2="12" y2="23"/>
2552
- <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
2553
- <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
2554
- <line x1="1" y1="12" x2="3" y2="12"/>
2555
- <line x1="21" y1="12" x2="23" y2="12"/>
2556
- <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
2557
- <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
2558
- </svg>
2559
- </button>
2560
- <button class="rte-source-editor-toolbar-btn readonly-toggle-btn" title="Toggle read-only">
2561
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2562
- <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
2563
- <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
2564
- </svg>
2565
- </button>
2566
- </div>
2567
- <div class="rte-source-editor-header-actions">
2568
- <button class="rte-source-editor-fullscreen-btn" title="Toggle fullscreen">
2569
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2570
- <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
2571
- </svg>
2572
- </button>
2573
- <button class="rte-source-editor-close-btn" aria-label="Close source editor">
2574
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2575
- <line x1="18" y1="6" x2="6" y2="18"/>
2576
- <line x1="6" y1="6" x2="18" y2="18"/>
2577
- </svg>
2578
- </button>
2579
- </div>
2580
- `;
2581
- const y = document.createElement("div");
2582
- y.className = "rte-source-editor-body";
2583
- const C = document.createElement("div");
2584
- C.className = "rte-source-editor-content";
2585
- const v = document.createElement("div");
2586
- v.className = "rte-source-editor-warning", v.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
2587
- const S = document.createElement("div");
2588
- S.className = "rte-source-editor-light-editor", S.style.height = "400px", C.appendChild(v), C.appendChild(S), y.appendChild(C);
2589
- const E = document.createElement("div");
2590
- if (E.className = "rte-source-editor-footer", E.innerHTML = `
2591
- <div class="rte-source-editor-footer-info">
2592
- <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
2593
- </div>
2594
- <div class="rte-source-editor-footer-actions">
2595
- <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
2596
- <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
2597
- </div>
2598
- `, g.appendChild(f), g.appendChild(y), g.appendChild(E), u.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
2599
- const x = document.createElement("style");
2600
- x.id = "rte-source-editor-styles", x.textContent = le, document.head.appendChild(x);
2601
- }
2602
- const M = f.querySelector(
2603
- ".theme-toggle-btn"
2604
- ), b = f.querySelector(
2605
- ".readonly-toggle-btn"
2606
- ), T = f.querySelector(
2607
- ".rte-source-editor-fullscreen-btn"
2608
- ), I = f.querySelector(
2609
- ".rte-source-editor-close-btn"
2610
- ), B = E.querySelector(
2611
- ".rte-source-editor-btn-cancel"
2612
- ), $ = E.querySelector(
2613
- ".rte-source-editor-btn-save"
2614
- ), A = E.querySelector(
2615
- ".unsaved-changes"
2616
- ), O = [], R = (x, k, V, N) => {
2617
- x.addEventListener(k, V, N), O.push(
2618
- () => x.removeEventListener(k, V, N)
2619
- );
2620
- }, U = (x) => {
2621
- c !== x && (c = x, A && (A.style.display = c ? "inline" : "none"));
2622
- }, H = () => {
2623
- if (!d) {
2624
- for (d = !0; O.length; ) {
2625
- const x = O.pop();
2626
- x == null || x();
2627
- }
2628
- o && (o.destroy(), o = null), u.isConnected && u.remove();
2629
- }
2630
- }, K = () => {
2631
- l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l), M && (M.innerHTML = l === "light" ? `
2632
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2633
- <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
2634
- </svg>
2635
- ` : `
2636
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2637
- <circle cx="12" cy="12" r="5"/>
2638
- <line x1="12" y1="1" x2="12" y2="3"/>
2639
- <line x1="12" y1="21" x2="12" y2="23"/>
2640
- <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
2641
- <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
2642
- <line x1="1" y1="12" x2="3" y2="12"/>
2643
- <line x1="21" y1="12" x2="23" y2="12"/>
2644
- <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
2645
- <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
2646
- </svg>
2647
- `);
2648
- }, z = () => {
2649
- h = !h, o == null || o.setReadOnly(h), b && (b.classList.toggle("active", h), b.innerHTML = h ? `
2650
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2651
- <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
2652
- <circle cx="12" cy="16" r="1"/>
2653
- <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
2654
- </svg>
2655
- ` : `
2656
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2657
- <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
2658
- <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
2659
- </svg>
2660
- `);
2661
- }, q = () => {
2662
- a = !a, u.classList.toggle("fullscreen", a), S.style.height = a ? "calc(100vh - 200px)" : "400px", T && (T.innerHTML = a ? `
2663
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
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"/>
2665
- </svg>
2666
- ` : `
2667
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2668
- <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
2669
- </svg>
2670
- `);
2671
- }, Q = () => {
2672
- c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || H();
2673
- }, j = () => {
2674
- try {
2675
- const x = (o == null ? void 0 : o.getValue()) || "", k = document.createElement("div");
2676
- k.innerHTML = x, k.querySelectorAll(
2677
- 'script, iframe[src^="javascript:"], object, embed'
2678
- ).forEach((N) => N.remove()), e.innerHTML = k.innerHTML;
2679
- try {
2680
- e.dispatchEvent(
2681
- new InputEvent("input", {
2682
- bubbles: !0,
2683
- cancelable: !1,
2684
- inputType: "insertReplacementText"
2685
- })
2686
- );
2687
- } catch (N) {
2688
- e.dispatchEvent(
2689
- new Event("input", { bubbles: !0 })
2690
- );
2691
- }
2692
- e.dispatchEvent(
2693
- new Event("change", { bubbles: !0 })
2694
- ), U(!1), H();
2695
- } catch (x) {
2696
- alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", x);
2697
- }
2698
- };
2699
- M && R(M, "click", K), b && R(b, "click", z), T && R(T, "click", q), I && R(I, "click", H), B && R(B, "click", Q), $ && R($, "click", j), R(u, "click", (x) => {
2700
- x.target === u && H();
2701
- }), R(document, "keydown", (x) => {
2702
- const k = x;
2703
- k.key === "Escape" && (k.preventDefault(), H());
2704
- }), document.body.appendChild(u), requestAnimationFrame(() => {
2705
- if (!(d || !u.isConnected))
2706
- try {
2707
- o = oe(S, {
2708
- value: r,
2709
- theme: "dark",
2710
- readOnly: !1,
2711
- extensions: [
2712
- new G(),
2713
- new _(),
2714
- new ee(),
2715
- new se(),
2716
- new ie(),
2717
- new ne(),
2718
- new re()
2719
- ]
2720
- }), o.on("change", () => {
2721
- const x = (o == null ? void 0 : o.getValue()) || "";
2722
- U(x !== r);
2723
- }), requestAnimationFrame(() => o == null ? void 0 : o.focus());
2724
- } catch (x) {
2725
- console.error("Failed to initialize code editor:", x);
2726
- }
2727
- });
2728
- })(), !0;
2729
- }
2730
- },
2731
- // Keyboard shortcuts
2732
- keymap: {
2733
- "Mod-Shift-s": "toggleSourceView",
2734
- "Mod-Shift-S": "toggleSourceView"
2735
- }
2736
- });
2737
- export {
2738
- ae as CodePlugin
2739
- };
2740
- //# sourceMappingURL=CodePlugin.native-989cf0aa.mjs.map