@editora/core 1.0.6 → 1.0.7

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 (43) hide show
  1. package/dist/{AnchorPlugin.native-C1Rw5m04.mjs → AnchorPlugin.native-BcYGEtd9.mjs} +129 -105
  2. package/dist/{BackgroundColorPlugin.native-BE-p9DRd.mjs → BackgroundColorPlugin.native-50iAT9xU.mjs} +119 -122
  3. package/dist/CodePlugin.native-DlpTPdkd.mjs +2691 -0
  4. package/dist/{CommentsPlugin.native-tMnWn8a2.mjs → CommentsPlugin.native-DPSqTkiv.mjs} +153 -135
  5. package/dist/{DocumentManagerPlugin.native-BvZL5CSG.mjs → DocumentManagerPlugin.native-C2cs_1w4.mjs} +43 -43
  6. package/dist/{EmbedIframePlugin.native-CSWIB1jm.mjs → EmbedIframePlugin.native-DKJx2OS7.mjs} +61 -58
  7. package/dist/{EmojisPlugin.native-DxTm_DL-.mjs → EmojisPlugin.native-CitxxlWX.mjs} +135 -104
  8. package/dist/{LinkPlugin.native-CS2g-G18.mjs → LinkPlugin.native-DYCIcdTm.mjs} +47 -45
  9. package/dist/{MathPlugin.native-KUxz0o8C.mjs → MathPlugin.native-f_mDp8VL.mjs} +149 -108
  10. package/dist/{MediaManagerPlugin.native-CgP5iInD.mjs → MediaManagerPlugin.native-BiXiK8FC.mjs} +238 -217
  11. package/dist/MergeTagPlugin.native-C3eOfEgw.mjs +559 -0
  12. package/dist/{PageBreakPlugin.native-CGiQxXqR.mjs → PageBreakPlugin.native-CXdX5fAv.mjs} +77 -68
  13. package/dist/{SpecialCharactersPlugin.native-DANrbExJ.mjs → SpecialCharactersPlugin.native-CZDato89.mjs} +143 -98
  14. package/dist/{SpellCheckPlugin.native-C8bPvRHy.mjs → SpellCheckPlugin.native-BZB9AewP.mjs} +239 -219
  15. package/dist/{TemplatePlugin.native-4lKEm-WY.mjs → TemplatePlugin.native-CrpfKRJ8.mjs} +167 -143
  16. package/dist/{TextColorPlugin.native-Clgtb50j.mjs → TextColorPlugin.native-Bwl_bSmc.mjs} +134 -118
  17. package/dist/_commonjsHelpers-DOllISpa.mjs +32 -0
  18. package/dist/anchoredPopover-Bxds0VoB.mjs +110 -0
  19. package/dist/documentManager-vQ1VkbUY.mjs +8418 -0
  20. package/dist/editora.min.js +10 -10
  21. package/dist/editora.umd.js +10 -10
  22. package/dist/html2canvas.esm-AYkPY5LS.mjs +4803 -0
  23. package/dist/{index-CqWQFb3D.js → index-BpE6GFbz.js} +4 -4
  24. package/dist/index-BslAFzmv.mjs +16544 -0
  25. package/dist/{index-OwnkG39N.mjs → index-yzU4NdPT.mjs} +200 -183
  26. package/dist/index.cjs.js +1 -1
  27. package/dist/{index.es-CuicffkQ.mjs → index.es-BYD2KEo6.mjs} +5 -4
  28. package/dist/index.esm.js +2 -2
  29. package/dist/jspdf.es.min-BJGtOnRT.mjs +7890 -0
  30. package/dist/plugin-loader.js +15 -15
  31. package/dist/webcomponent-core.js +241 -224
  32. package/dist/webcomponent-core.min.css +1 -1
  33. package/dist/webcomponent-core.min.js +86 -106
  34. package/dist/webcomponent.cjs.js +1 -1
  35. package/dist/webcomponent.esm.js +1 -1
  36. package/dist/webcomponent.js +205 -188
  37. package/dist/webcomponent.min.css +1 -1
  38. package/dist/webcomponent.min.js +477 -402
  39. package/package.json +1 -1
  40. package/dist/CodePlugin.native-B263UI8O.mjs +0 -2173
  41. package/dist/MergeTagPlugin.native-DIGWhdnF.mjs +0 -419
  42. package/dist/colorSelectionApply-CK1My9N2.mjs +0 -67
  43. package/dist/documentManager-irzj9n3V.mjs +0 -37627
@@ -1,2173 +0,0 @@
1
- class P {
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), r = s.substring(0, e.start.column) + t + s.substring(e.end.column);
43
- this._lines[e.start.line] = r;
44
- } else {
45
- const s = this.getLine(e.start.line), r = this.getLine(e.end.line), n = s.substring(0, e.start.column) + t, o = r.substring(e.end.column), l = t.split(`
46
- `);
47
- l[0] = n + l[0], l[l.length - 1] = l[l.length - 1] + o, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...l);
48
- }
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 P();
96
- return e._lines = [...this._lines], e._version = this._version, e;
97
- }
98
- }
99
- class U {
100
- constructor(e) {
101
- this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.container = e, this.createDOM();
102
- }
103
- createDOM() {
104
- this.container.innerHTML = "";
105
- const e = document.createElement("div");
106
- this.editorContainer = e, 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, r) => r + 1);
153
- this.lineNumbersElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("");
154
- }
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), r = /<[^>]+>/.test(e);
179
- i && s ? this.contentElement.innerHTML = e : r && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
180
- const n = (this.contentElement.textContent || "").split(`
181
- `).length;
182
- this.updateLineNumbers(n);
183
- }
184
- // Keep trailing-newline caret marker in sync for live contenteditable edits
185
- // (without forcing a full setText/setHTML render).
186
- syncTrailingNewlineMarkerForText(e) {
187
- this.syncTrailingNewlineMarker(e.endsWith(`
188
- `));
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 g, h;
207
- const t = this.getText().split(`
208
- `), i = Math.min(e.line, t.length - 1), s = Math.min(e.column, ((g = t[i]) == null ? void 0 : g.length) || 0);
209
- let r = 0;
210
- for (let f = 0; f < i; f++)
211
- r += t[f].length + 1;
212
- r += s;
213
- const n = document.createRange(), o = window.getSelection();
214
- let l = 0, c = null, a = 0;
215
- const u = document.createTreeWalker(
216
- this.contentElement,
217
- NodeFilter.SHOW_TEXT,
218
- null
219
- );
220
- let d;
221
- for (; d = u.nextNode(); ) {
222
- const f = ((h = d.textContent) == null ? void 0 : h.length) || 0;
223
- if (l + f >= r) {
224
- c = d, a = r - l;
225
- break;
226
- }
227
- l += f;
228
- }
229
- if (c)
230
- try {
231
- n.setStart(c, a), n.setEnd(c, a), o == null || o.removeAllRanges(), o == null || o.addRange(n), this.ensureCaretVisible();
232
- } catch (f) {
233
- console.warn("Could not set cursor position:", f);
234
- }
235
- else {
236
- const f = this.contentElement.querySelector(
237
- `[${this.trailingNewlineMarkerAttr}]`
238
- );
239
- try {
240
- f && f.parentNode === this.contentElement ? n.setStartBefore(f) : (n.selectNodeContents(this.contentElement), n.collapse(!1)), n.collapse(!0), o == null || o.removeAllRanges(), o == null || o.addRange(n), this.ensureCaretVisible();
241
- } catch (p) {
242
- console.warn("Could not set fallback cursor position:", p);
243
- }
244
- }
245
- }
246
- // Get selection range
247
- getSelectionRange() {
248
- const e = window.getSelection();
249
- if (!e || e.rangeCount === 0 || e.isCollapsed)
250
- return;
251
- const t = e.getRangeAt(0), i = t.cloneRange();
252
- i.selectNodeContents(this.contentElement), i.setEnd(t.startContainer, t.startOffset);
253
- const s = i.toString().replace(/\u200B/g, "").split(`
254
- `), r = t.cloneRange();
255
- r.selectNodeContents(this.contentElement), r.setEnd(t.endContainer, t.endOffset);
256
- const n = r.toString().replace(/\u200B/g, "").split(`
257
- `);
258
- return {
259
- start: {
260
- line: s.length - 1,
261
- column: s[s.length - 1].length
262
- },
263
- end: {
264
- line: n.length - 1,
265
- column: n[n.length - 1].length
266
- }
267
- };
268
- }
269
- // Set selection range
270
- setSelectionRange(e) {
271
- this.setCursorPosition(e.start);
272
- }
273
- // Focus the editor
274
- focus() {
275
- this.contentElement.focus(), this.ensureCaretVisible();
276
- }
277
- // Blur the editor
278
- blur() {
279
- this.contentElement.blur();
280
- }
281
- // Set read-only mode
282
- setReadOnly(e) {
283
- this.contentElement.contentEditable = e ? "false" : "true";
284
- }
285
- // Apply theme
286
- applyTheme(e) {
287
- Object.entries(e).forEach(([t, i]) => {
288
- this.container.style.setProperty(`--${t}`, i);
289
- });
290
- }
291
- // Scroll to position
292
- scrollToPosition(e) {
293
- const t = this.lineNumbersElement.children[e.line];
294
- t && t.scrollIntoView({ block: "center", behavior: "smooth" });
295
- }
296
- // Get scroll position
297
- getScrollTop() {
298
- return this.editorContainer.scrollTop;
299
- }
300
- // Set scroll position
301
- setScrollTop(e) {
302
- this.editorContainer.scrollTop = e;
303
- }
304
- syncTrailingNewlineMarker(e) {
305
- if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e) return;
306
- const t = document.createElement("span");
307
- t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
308
- display: inline-block;
309
- width: 0;
310
- overflow: hidden;
311
- pointer-events: none;
312
- user-select: none;
313
- `, t.appendChild(document.createTextNode("​")), this.contentElement.appendChild(t);
314
- }
315
- // Ensure caret is visible inside the editor scroll container
316
- ensureCaretVisible() {
317
- var n;
318
- const e = window.getSelection();
319
- if (!e || e.rangeCount === 0) return;
320
- const t = e.getRangeAt(0).cloneRange();
321
- t.collapse(!1);
322
- let i = t.getClientRects()[0] || t.getBoundingClientRect();
323
- if ((!i || i.width === 0 && i.height === 0) && e.focusNode instanceof Element ? i = e.focusNode.getBoundingClientRect() : (!i || i.width === 0 && i.height === 0) && ((n = e.focusNode) != null && n.parentElement) && (i = e.focusNode.parentElement.getBoundingClientRect()), !i) return;
324
- const s = this.editorContainer.getBoundingClientRect(), r = 12;
325
- i.bottom > s.bottom - r ? this.editorContainer.scrollTop += i.bottom - (s.bottom - r) : i.top < s.top + r && (this.editorContainer.scrollTop -= s.top + r - i.top);
326
- }
327
- // Destroy the view
328
- destroy() {
329
- this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
330
- }
331
- }
332
- const K = class M {
333
- constructor(e, t = {}) {
334
- this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.config = {
335
- value: "",
336
- theme: "default",
337
- readOnly: !1,
338
- tabSize: 2,
339
- lineWrapping: !1,
340
- lineNumbers: !0,
341
- ...t
342
- }, this.textModel = new P(this.config.value), this.view = new U(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
343
- }
344
- // Public accessors for extensions
345
- getTextModel() {
346
- return this.textModel;
347
- }
348
- getView() {
349
- return this.view;
350
- }
351
- getConfig() {
352
- return { ...this.config };
353
- }
354
- // Register built-in editor commands like undo/redo/insertTab
355
- registerBuiltInCommands() {
356
- this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("save", () => {
357
- this.emit("save");
358
- });
359
- }
360
- // Get keymap extension if available
361
- getKeymapExtension() {
362
- return this.extensions.get("keymap");
363
- }
364
- // Setup DOM event handlers
365
- setupEventHandlers() {
366
- const e = this.view.getContentElement();
367
- e.addEventListener("input", () => {
368
- const t = this.view.getText(), i = this.textModel.getText();
369
- if (t !== i) {
370
- if (!this.suppressHistory) {
371
- const s = this.getCursor().position, r = this.textModel.positionToOffset(s), n = this.getSelection();
372
- let o, l;
373
- n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
374
- }
375
- this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
376
- const s = this.view.getText();
377
- s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
378
- }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
379
- }
380
- }), e.addEventListener("selectionchange", () => {
381
- const t = this.getCursor(), i = this.getSelection();
382
- this.emit("cursor", t), i && this.emit("selection", i);
383
- }), e.addEventListener("keydown", (t) => {
384
- if (this.emit("keydown", t), t.key === "Tab") {
385
- this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
386
- return;
387
- }
388
- if (t.key === "Enter") {
389
- if (!this.config.readOnly) {
390
- const i = window.getSelection();
391
- if (i && i.rangeCount > 0) {
392
- const s = this.getCursor().position, r = this.textModel.positionToOffset(s), n = this.getSelection();
393
- let o, l;
394
- n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end));
395
- const c = n && o !== void 0 && l !== void 0 ? Math.min(o, l) : r;
396
- this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: r, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
397
- const a = i.getRangeAt(0);
398
- a.deleteContents();
399
- const u = document.createTextNode(`
400
- `);
401
- a.insertNode(u), a.setStartAfter(u), a.collapse(!0), i.removeAllRanges(), i.addRange(a), this.view.ensureCaretVisible();
402
- const d = this.view.getText();
403
- this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
404
- const g = Math.min(
405
- c + 1,
406
- this.textModel.getText().length
407
- );
408
- try {
409
- const h = this.textModel.offsetToPosition(g);
410
- this.setCursor(h), this.view.ensureCaretVisible();
411
- } catch (h) {
412
- }
413
- this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
414
- this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
415
- try {
416
- const h = this.textModel.offsetToPosition(g);
417
- this.setCursor(h), this.view.ensureCaretVisible();
418
- } catch (h) {
419
- }
420
- }), this.highlightTimeout = null;
421
- }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: this.getValue(), oldText: "" }]);
422
- }
423
- }
424
- t.preventDefault(), t.stopPropagation();
425
- return;
426
- }
427
- for (const i of this.extensions.values())
428
- if (i.onKeyDown && i.onKeyDown(t) === !1) {
429
- t.preventDefault(), t.stopPropagation();
430
- return;
431
- }
432
- }), e.addEventListener("mousedown", (t) => {
433
- this.emit("mousedown", t);
434
- for (const i of this.extensions.values())
435
- if (i.onMouseDown && i.onMouseDown(t) === !1) {
436
- t.preventDefault(), t.stopPropagation();
437
- return;
438
- }
439
- }), e.addEventListener("focus", () => {
440
- this.emit("focus");
441
- }), e.addEventListener("blur", () => {
442
- this.emit("blur");
443
- });
444
- }
445
- // Update line numbers display
446
- updateLineNumbers() {
447
- const e = this.textModel.getLineCount();
448
- this.view.updateLineNumbers(e);
449
- }
450
- // Get full range of document
451
- getFullRange() {
452
- return {
453
- start: { line: 0, column: 0 },
454
- end: {
455
- line: this.textModel.getLineCount() - 1,
456
- column: this.textModel.getLine(this.textModel.getLineCount() - 1).length
457
- }
458
- };
459
- }
460
- // Emit events to listeners
461
- emit(e, ...t) {
462
- const i = this.eventListeners.get(e);
463
- i && i.forEach((s) => s(...t));
464
- }
465
- // State management
466
- getValue() {
467
- return this.textModel.getText();
468
- }
469
- setValue(e) {
470
- const t = this.textModel.getText();
471
- this.textModel.setText(e), this.renderTextWithHighlight(e, !1), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: t }]);
472
- }
473
- getState() {
474
- return {
475
- text: this.getValue(),
476
- cursor: this.getCursor(),
477
- selection: this.getSelection(),
478
- readOnly: this.config.readOnly || !1,
479
- theme: this.currentTheme
480
- };
481
- }
482
- // Cursor & Selection
483
- getCursor() {
484
- const e = this.view.getCursorPosition();
485
- return {
486
- position: e,
487
- anchor: e
488
- // For now, cursor and anchor are the same
489
- };
490
- }
491
- setCursor(e) {
492
- this.view.setCursorPosition(e), this.emit("cursor", this.getCursor());
493
- }
494
- getSelection() {
495
- return this.view.getSelectionRange();
496
- }
497
- setSelection(e) {
498
- this.view.setSelectionRange(e), this.emit("selection", e);
499
- }
500
- // Configuration
501
- setTheme(e) {
502
- this.currentTheme = e;
503
- const t = {
504
- "editor-background": e === "dark" ? "#1e1e1e" : "#ffffff",
505
- "editor-foreground": e === "dark" ? "#f8f9fa" : "#1a1a1a",
506
- "editor-gutter-background": e === "dark" ? "#252526" : "#f8f9fa",
507
- "editor-gutter-foreground": e === "dark" ? "#858585" : "#666666",
508
- "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
509
- };
510
- this.view.applyTheme(t);
511
- const i = this.extensions.get("syntax-highlighting");
512
- if (i && typeof i.setTheme == "function")
513
- try {
514
- i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
515
- } catch (s) {
516
- console.warn("Error applying theme to syntax-highlighting extension", s);
517
- }
518
- }
519
- setReadOnly(e) {
520
- this.config.readOnly = e, this.view.setReadOnly(e);
521
- }
522
- // Extensions & Commands
523
- addExtension(e) {
524
- if (this.extensions.has(e.name))
525
- throw new Error(`Extension '${e.name}' already exists`);
526
- this.extensions.set(e.name, e), e.setup(this), e.name === "syntax-highlighting" && typeof e.highlightHTML == "function" && this.renderTextWithHighlight(this.textModel.getText());
527
- }
528
- removeExtension(e) {
529
- const t = this.extensions.get(e);
530
- t && t.destroy && t.destroy(), this.extensions.delete(e);
531
- }
532
- executeCommand(e, ...t) {
533
- const i = this.commands.get(e);
534
- i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
535
- }
536
- // Register a command
537
- registerCommand(e, t) {
538
- this.commands.set(e, t);
539
- }
540
- // Search & Navigation
541
- search(e, t = {}) {
542
- const i = {
543
- caseSensitive: !1,
544
- regex: !1,
545
- ...t
546
- }, s = [], r = this.getValue();
547
- r.split(`
548
- `);
549
- let n = i.caseSensitive ? r : r.toLowerCase(), o = i.caseSensitive ? e : e.toLowerCase();
550
- if (i.regex) {
551
- const l = new RegExp(o, i.caseSensitive ? "g" : "gi");
552
- let c;
553
- for (; (c = l.exec(n)) !== null; ) {
554
- const a = this.textModel.offsetToPosition(c.index), u = this.textModel.offsetToPosition(c.index + c[0].length);
555
- s.push({
556
- range: { start: a, end: u },
557
- match: c[0]
558
- });
559
- }
560
- } else {
561
- let l = 0, c = n.indexOf(o, l);
562
- for (; c !== -1; ) {
563
- const a = c + e.length, u = this.textModel.offsetToPosition(c), d = this.textModel.offsetToPosition(a);
564
- s.push({
565
- range: { start: u, end: d },
566
- match: r.substring(c, a)
567
- }), l = a, c = n.indexOf(o, l);
568
- }
569
- }
570
- return s;
571
- }
572
- replace(e, t) {
573
- const i = this.getValue();
574
- if (!this.suppressHistory) {
575
- const r = this.getCursor().position, n = this.textModel.positionToOffset(r), o = this.getSelection();
576
- let l, c;
577
- o && (l = this.textModel.positionToOffset(o.start), c = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: n, anchorOffset: l, focusOffset: c }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
578
- }
579
- const s = this.textModel.replaceRange(e, t);
580
- this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [s]);
581
- }
582
- replaceAll(e, t, i = {}) {
583
- const s = this.search(e, i);
584
- let r = 0;
585
- for (let n = s.length - 1; n >= 0; n--)
586
- this.replace(s[n].range, t), r++;
587
- return r;
588
- }
589
- // Folding (basic implementation)
590
- fold(e) {
591
- const t = {
592
- start: e.start,
593
- end: e.end,
594
- collapsed: !0,
595
- level: 0
596
- };
597
- this.folds.push(t);
598
- }
599
- unfold(e) {
600
- this.folds = this.folds.filter(
601
- (t) => !(t.start.line === e.start.line && t.end.line === e.end.line)
602
- );
603
- }
604
- getFolds() {
605
- return [...this.folds];
606
- }
607
- // Utilities
608
- focus() {
609
- this.view.focus();
610
- }
611
- blur() {
612
- this.view.blur();
613
- }
614
- // Render text using syntax highlighting extension if available
615
- // If `restoreSelection` is true (default), the method captures current selection/caret
616
- // and restores it after updating the DOM. Callers that will explicitly set the caret
617
- // should pass `false` to avoid stomping programmatic cursor changes.
618
- renderTextWithHighlight(e, t = !0) {
619
- const i = this.extensions.get("syntax-highlighting");
620
- if (i && typeof i.highlightHTML == "function")
621
- try {
622
- const s = !t && !this.expectingProgrammaticCursor;
623
- let r, n, o, l;
624
- if (t || s) {
625
- r = this.getSelection();
626
- const d = this.getCollapsedSelectionOffsetInEditor();
627
- if (d !== void 0)
628
- n = d;
629
- else {
630
- const g = this.getCursor().position;
631
- n = this.textModel.positionToOffset(g);
632
- }
633
- r && (o = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end));
634
- }
635
- const c = (t || s) && !r && n !== void 0 && this.hasCollapsedSelectionInEditor(), a = c ? this.insertSentinelAtOffset(e, n) : e, u = i.highlightHTML(a);
636
- typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(u) : this.view.setHTML(u), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
637
- try {
638
- if (c && this.restoreCursorFromSentinel()) {
639
- this.view.ensureCaretVisible();
640
- return;
641
- }
642
- if (r && (o !== void 0 || l !== void 0)) {
643
- const d = o !== void 0 ? o : n, g = l !== void 0 ? l : n, h = Math.min(d, g), f = Math.max(d, g), p = this.textModel.offsetToPosition(h), x = this.textModel.offsetToPosition(f);
644
- this.view.setSelectionRange({ start: p, end: x });
645
- } else if (n !== void 0) {
646
- const d = this.textModel.offsetToPosition(n);
647
- this.view.setCursorPosition(d);
648
- }
649
- } catch (d) {
650
- }
651
- });
652
- return;
653
- } catch (s) {
654
- console.warn("Syntax highlighting failed, falling back to plain text", s);
655
- }
656
- this.view.setText(e);
657
- }
658
- hasCollapsedSelectionInEditor() {
659
- const e = window.getSelection();
660
- if (!e || e.rangeCount === 0 || !e.isCollapsed)
661
- return !1;
662
- const t = e.getRangeAt(0);
663
- return this.view.getContentElement().contains(t.commonAncestorContainer);
664
- }
665
- getCollapsedSelectionOffsetInEditor() {
666
- const e = window.getSelection();
667
- if (!e || e.rangeCount === 0 || !e.isCollapsed)
668
- return;
669
- const t = e.getRangeAt(0), i = this.view.getContentElement();
670
- if (!i.contains(t.commonAncestorContainer))
671
- return;
672
- const s = t.cloneRange();
673
- return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
674
- }
675
- stripVirtualMarkers(e) {
676
- return e.replace(/\u200B/g, "").split(M.CURSOR_SENTINEL).join("");
677
- }
678
- insertSentinelAtOffset(e, t) {
679
- const i = Math.max(0, Math.min(t, e.length));
680
- return e.slice(0, i) + M.CURSOR_SENTINEL + e.slice(i);
681
- }
682
- restoreCursorFromSentinel() {
683
- var o;
684
- const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
685
- let s = i.nextNode(), r = null, n = 0;
686
- for (; s; ) {
687
- const l = (o = s.textContent) != null ? o : "", c = l.indexOf(M.CURSOR_SENTINEL);
688
- c !== -1 && (r || (r = s, n = c), s.textContent = l.split(M.CURSOR_SENTINEL).join("")), s = i.nextNode();
689
- }
690
- if (!r || !t) return !1;
691
- try {
692
- const l = document.createRange();
693
- return l.setStart(r, n), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
694
- } catch (l) {
695
- return !1;
696
- }
697
- }
698
- destroy() {
699
- if (!this.isDestroyed) {
700
- this.isDestroyed = !0;
701
- for (const e of this.extensions.values())
702
- e.destroy && e.destroy();
703
- this.extensions.clear(), this.view.destroy(), this.commands.clear(), this.eventListeners.clear();
704
- }
705
- }
706
- // History: undo/redo
707
- undo() {
708
- if (this.undoStack.length === 0) return;
709
- const e = this.undoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
710
- this.redoStack.push(t);
711
- try {
712
- this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
713
- let i, s;
714
- typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
715
- try {
716
- if (s != null)
717
- if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
718
- const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, n = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(r, n), l = Math.max(r, n), c = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
719
- this.setSelection({ start: c, end: a });
720
- } else {
721
- const r = this.textModel.offsetToPosition(s);
722
- this.setCursor(r);
723
- }
724
- } catch (r) {
725
- }
726
- }), setTimeout(() => {
727
- this.expectingProgrammaticCursor = !1;
728
- }, 30);
729
- } finally {
730
- this.suppressHistory = !1;
731
- }
732
- }
733
- redo() {
734
- if (this.redoStack.length === 0) return;
735
- const e = this.redoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
736
- this.undoStack.push(t);
737
- try {
738
- this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
739
- let i, s;
740
- typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
741
- try {
742
- if (s != null)
743
- if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
744
- const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, n = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(r, n), l = Math.max(r, n), c = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
745
- this.setSelection({ start: c, end: a });
746
- } else {
747
- const r = this.textModel.offsetToPosition(s);
748
- this.setCursor(r);
749
- }
750
- } catch (r) {
751
- }
752
- }), setTimeout(() => {
753
- this.expectingProgrammaticCursor = !1;
754
- }, 30);
755
- } finally {
756
- this.suppressHistory = !1;
757
- }
758
- }
759
- // Insert a tab character or spaces at current cursor
760
- insertTab() {
761
- if (this.config.readOnly) return;
762
- const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = " ".repeat(this.config.tabSize || 2), s = this.textModel.insertText(e, i), r = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + i.length);
763
- if (!this.suppressHistory) {
764
- const n = this.getSelection();
765
- let o, l;
766
- n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: l }), this.redoStack.length = 0;
767
- }
768
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(r), setTimeout(() => {
769
- this.expectingProgrammaticCursor = !1;
770
- }, 20), this.emit("change", [s]);
771
- }
772
- // Insert a newline at current cursor position
773
- insertNewLine() {
774
- if (this.config.readOnly) return;
775
- const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
776
- `), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
777
- if (!this.suppressHistory) {
778
- const r = this.getSelection();
779
- let n, o;
780
- r && (n = this.textModel.positionToOffset(r.start), o = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: n, focusOffset: o }), this.redoStack.length = 0;
781
- }
782
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
783
- this.expectingProgrammaticCursor = !1;
784
- }, 20), this.emit("change", [i]);
785
- }
786
- // Events
787
- on(e, t) {
788
- this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
789
- }
790
- off(e, t) {
791
- if (!this.eventListeners.has(e)) return;
792
- const i = this.eventListeners.get(e);
793
- if (t) {
794
- const s = i.indexOf(t);
795
- s !== -1 && i.splice(s, 1);
796
- } else
797
- i.length = 0;
798
- }
799
- };
800
- K.CURSOR_SENTINEL = "";
801
- let z = K;
802
- class q {
803
- constructor(e) {
804
- this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
805
- }
806
- setup(e) {
807
- this.editor = e;
808
- }
809
- handleKeyDown(e) {
810
- if (!this.editor) return;
811
- const t = this.findMatchingBinding(e);
812
- if (t)
813
- return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
814
- }
815
- findMatchingBinding(e) {
816
- const { key: t, ctrlKey: i, altKey: s, shiftKey: r, metaKey: n } = e, o = String(t).toLowerCase(), l = this.keymap[o];
817
- if (!l) return null;
818
- for (const c of l) {
819
- const a = c.ctrlKey === void 0 || c.ctrlKey === i, u = c.altKey === void 0 || c.altKey === s, d = c.shiftKey === void 0 || c.shiftKey === r, g = c.metaKey === void 0 || c.metaKey === n;
820
- if (a && u && d && g)
821
- return c;
822
- }
823
- return null;
824
- }
825
- // Allow EditorCore to call this directly when checking extension.onKeyDown
826
- onKeyDown(e) {
827
- return this.handleKeyDown(e);
828
- }
829
- getDefaultKeymap() {
830
- const e = {};
831
- return this.addBinding(e, "f", { ctrlKey: !this.isMac, metaKey: this.isMac }, "find"), this.addBinding(e, "h", { ctrlKey: !this.isMac, metaKey: this.isMac }, "replace"), this.addBinding(e, "f3", {}, "findNext"), this.addBinding(e, "f3", { shiftKey: !0 }, "findPrev"), this.addBinding(e, "g", { ctrlKey: !this.isMac, metaKey: this.isMac }, "findNext"), this.addBinding(e, "[", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "fold"), this.addBinding(e, "]", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "unfold"), this.addBinding(e, "s", { ctrlKey: !0 }, "save"), this.addBinding(e, "s", { metaKey: !0 }, "save"), this.addBinding(e, "z", { ctrlKey: !0 }, "undo"), this.addBinding(e, "z", { metaKey: !0 }, "undo"), this.addBinding(e, "y", { ctrlKey: !0 }, "redo"), this.addBinding(e, "y", { metaKey: !0 }, "redo"), this.addBinding(e, "z", { ctrlKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "z", { metaKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "tab", {}, "insertTab"), this.addBinding(e, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), e;
832
- }
833
- addBinding(e, t, i, s) {
834
- const r = t.toLowerCase();
835
- e[r] || (e[r] = []), e[r].push({
836
- key: r,
837
- command: s,
838
- ...i
839
- });
840
- }
841
- // Public API for customizing keymap
842
- setKeymap(e) {
843
- this.keymap = { ...e };
844
- }
845
- addKeyBinding(e) {
846
- const t = e.key.toLowerCase();
847
- this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
848
- ...e,
849
- key: t
850
- });
851
- }
852
- removeKeyBinding(e, t) {
853
- const i = e.toLowerCase();
854
- t ? this.keymap[i] && (this.keymap[i] = this.keymap[i].filter((s) => s.command !== t), this.keymap[i].length === 0 && delete this.keymap[i]) : delete this.keymap[i];
855
- }
856
- getKeymap() {
857
- return { ...this.keymap };
858
- }
859
- getBindingsForCommand(e) {
860
- const t = [];
861
- for (const i in this.keymap)
862
- for (const s of this.keymap[i])
863
- s.command === e && t.push({ ...s });
864
- return t;
865
- }
866
- getPlatformInfo() {
867
- return {
868
- isMac: this.isMac,
869
- platform: navigator.platform
870
- };
871
- }
872
- destroy() {
873
- this.keymap = {}, this.editor = null;
874
- }
875
- }
876
- class F {
877
- constructor() {
878
- this.name = "transaction", this.transactions = [];
879
- }
880
- setup(e) {
881
- e.on("change", (t) => {
882
- const i = {
883
- changes: t,
884
- selection: e.getSelection(),
885
- effects: [],
886
- annotations: []
887
- };
888
- this.transactions.push(i);
889
- });
890
- }
891
- getTransactions() {
892
- return this.transactions;
893
- }
894
- destroy() {
895
- this.transactions = [];
896
- }
897
- }
898
- class _ {
899
- constructor() {
900
- this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
901
- }
902
- setup(e) {
903
- this.editor = e, this.createLineNumbers(), e.registerCommand("toggleLineNumbers", () => {
904
- this.toggle();
905
- }), e.on("change", () => {
906
- this.updateLineNumbers();
907
- }), this.updateLineNumbers();
908
- }
909
- createLineNumbers() {
910
- if (!this.editor) return;
911
- const e = this.editor.getView().getLineNumbersElement();
912
- e && (this.lineNumbersElement = e);
913
- }
914
- updateLineNumbers() {
915
- if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
916
- const e = this.editor.getValue().split(`
917
- `).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
918
- this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("");
919
- }
920
- toggle() {
921
- if (!this.editor) return;
922
- this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
923
- const e = this.editor.getView().getContentElement();
924
- e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
925
- }
926
- destroy() {
927
- this.lineNumbersElement = null, this.editor = null;
928
- }
929
- }
930
- class W {
931
- constructor() {
932
- this.name = "theme", this.editor = null, this.currentTheme = "dark";
933
- }
934
- setup(e) {
935
- this.editor = e, e.registerCommand("setTheme", (t) => {
936
- this.setTheme(t);
937
- }), e.registerCommand("toggleTheme", () => {
938
- this.toggleTheme();
939
- }), this.setTheme(this.currentTheme);
940
- }
941
- setTheme(e) {
942
- this.editor && (this.currentTheme = e, this.editor.setTheme(e));
943
- }
944
- toggleTheme() {
945
- const e = this.currentTheme === "dark" ? "light" : "dark";
946
- this.setTheme(e);
947
- }
948
- getCurrentTheme() {
949
- return this.currentTheme;
950
- }
951
- destroy() {
952
- this.editor = null;
953
- }
954
- }
955
- class D {
956
- constructor() {
957
- this.name = "read-only", this.editor = null, this.isReadOnly = !1;
958
- }
959
- setup(e) {
960
- this.editor = e, e.registerCommand("setReadOnly", (t) => {
961
- this.setReadOnly(t);
962
- }), e.registerCommand("toggleReadOnly", () => {
963
- this.toggleReadOnly();
964
- }), e.on("keydown", (t) => {
965
- if (t.ctrlKey && t.key === "r")
966
- return t.preventDefault(), this.toggleReadOnly(), !1;
967
- });
968
- }
969
- setReadOnly(e) {
970
- this.editor && (this.isReadOnly = e, this.editor.setReadOnly(e));
971
- }
972
- toggleReadOnly() {
973
- this.setReadOnly(!this.isReadOnly);
974
- }
975
- isCurrentlyReadOnly() {
976
- return this.isReadOnly;
977
- }
978
- destroy() {
979
- this.editor = null;
980
- }
981
- }
982
- class j {
983
- constructor() {
984
- this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1;
985
- }
986
- setup(e) {
987
- this.editor = e, e.registerCommand("find", () => {
988
- this.showSearch();
989
- }), e.registerCommand("findNext", () => {
990
- this.findNext();
991
- }), e.registerCommand("findPrev", () => {
992
- this.findPrev();
993
- }), e.registerCommand("replace", () => {
994
- this.showReplace();
995
- }), e.registerCommand("replaceAll", (t, i) => {
996
- this.replaceAll(t, i);
997
- });
998
- }
999
- showSearch() {
1000
- if (this.editor && (this.searchUI || this.createSearchUI(), this.isVisible = !0, this.searchUI)) {
1001
- this.searchUI.style.display = "block";
1002
- const e = this.searchUI.querySelector("input");
1003
- e && (e.focus(), e.select());
1004
- }
1005
- }
1006
- showReplace() {
1007
- var i, s;
1008
- this.showSearch();
1009
- const e = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-replace-input");
1010
- e && (e.style.display = "block", e.focus());
1011
- const t = (s = this.searchUI) == null ? void 0 : s.querySelector(".search-status");
1012
- t && (t.textContent = "Replace mode - Enter to replace, Shift+Enter to replace all");
1013
- }
1014
- hideSearch() {
1015
- this.isVisible = !1, this.searchUI && (this.searchUI.style.display = "none"), this.clearHighlights();
1016
- }
1017
- createSearchUI() {
1018
- if (!this.editor) return;
1019
- const e = document.querySelector(".rte-source-editor-modal");
1020
- if (!e) return;
1021
- this.searchUI = document.createElement("div"), this.searchUI.style.cssText = `
1022
- position: absolute;
1023
- top: 10px;
1024
- right: 10px;
1025
- background: var(--editor-background, #1e1e1e);
1026
- border: 1px solid var(--editor-gutter-border, #3e3e42);
1027
- border-radius: 4px;
1028
- padding: 8px;
1029
- z-index: 1000;
1030
- display: none;
1031
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
1032
- min-width: 250px;
1033
- `, this.searchUI.innerHTML = `
1034
- <div style="display: flex; align-items: center; gap: 4px; margin-bottom: 4px;">
1035
- <input type="text" placeholder="Find..." style="
1036
- flex: 1;
1037
- padding: 4px 8px;
1038
- background: var(--editor-gutter-background, #252526);
1039
- color: var(--editor-foreground, #f8f9fa);
1040
- border: 1px solid var(--editor-gutter-border, #3e3e42);
1041
- border-radius: 3px;
1042
- font-size: 12px;
1043
- outline: none;
1044
- " />
1045
- <button class="search-prev" style="
1046
- padding: 2px 6px;
1047
- background: var(--editor-gutter-background, #252526);
1048
- color: var(--editor-gutter-foreground, #858585);
1049
- border: 1px solid var(--editor-gutter-border, #3e3e42);
1050
- border-radius: 3px;
1051
- cursor: pointer;
1052
- font-size: 11px;
1053
- ">↑</button>
1054
- <button class="search-next" style="
1055
- padding: 2px 6px;
1056
- background: var(--editor-gutter-background, #252526);
1057
- color: var(--editor-gutter-foreground, #858585);
1058
- border: 1px solid var(--editor-gutter-border, #3e3e42);
1059
- border-radius: 3px;
1060
- cursor: pointer;
1061
- font-size: 11px;
1062
- ">↓</button>
1063
- <button class="search-close" style="
1064
- padding: 2px 6px;
1065
- background: var(--editor-gutter-background, #252526);
1066
- color: var(--editor-gutter-foreground, #858585);
1067
- border: 1px solid var(--editor-gutter-border, #3e3e42);
1068
- border-radius: 3px;
1069
- cursor: pointer;
1070
- font-size: 11px;
1071
- ">×</button>
1072
- </div>
1073
- <div class="search-status" style="
1074
- font-size: 11px;
1075
- color: var(--editor-gutter-foreground, #858585);
1076
- text-align: center;
1077
- "></div>
1078
- <input type="text" class="search-replace-input" placeholder="Replace with..." style="
1079
- width: 100%;
1080
- padding: 4px 8px;
1081
- background: var(--editor-gutter-background, #252526);
1082
- color: var(--editor-foreground, #f8f9fa);
1083
- border: 1px solid var(--editor-gutter-border, #3e3e42);
1084
- border-radius: 3px;
1085
- font-size: 12px;
1086
- outline: none;
1087
- display: none;
1088
- margin-top: 4px;
1089
- " />
1090
- `;
1091
- const t = this.searchUI.querySelector("input"), i = this.searchUI.querySelector(".search-replace-input"), s = this.searchUI.querySelector(".search-prev"), r = this.searchUI.querySelector(".search-next"), n = this.searchUI.querySelector(".search-close");
1092
- t.addEventListener("input", () => {
1093
- this.performSearch(t.value);
1094
- }), t.addEventListener("keydown", (o) => {
1095
- o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.findPrev() : this.findNext());
1096
- }), i.addEventListener("keydown", (o) => {
1097
- o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.replaceAll(t.value, i.value) : this.replaceCurrent(t.value, i.value));
1098
- }), s.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), n.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
1099
- }
1100
- performSearch(e) {
1101
- if (!this.editor || !e.trim()) {
1102
- this.clearHighlights(), this.updateStatus("");
1103
- return;
1104
- }
1105
- const t = this.editor.getValue(), i = [];
1106
- let s = t.toLowerCase().indexOf(e.toLowerCase());
1107
- for (; s !== -1; ) {
1108
- const r = this.getPositionFromOffset(t, s), n = this.getPositionFromOffset(t, s + e.length);
1109
- i.push({
1110
- range: { start: r, end: n },
1111
- match: t.substring(s, s + e.length)
1112
- }), s = t.toLowerCase().indexOf(e.toLowerCase(), s + 1);
1113
- }
1114
- this.currentResults = i, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
1115
- }
1116
- getPositionFromOffset(e, t) {
1117
- const i = e.substring(0, t).split(`
1118
- `), s = i.length - 1, r = i[i.length - 1].length;
1119
- return { line: s, column: r };
1120
- }
1121
- findNext() {
1122
- this.currentResults.length !== 0 && (this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights());
1123
- }
1124
- findPrev() {
1125
- this.currentResults.length !== 0 && (this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights());
1126
- }
1127
- replaceCurrent(e, t) {
1128
- if (!this.editor || !e.trim() || this.currentIndex === -1) return;
1129
- const i = this.currentResults[this.currentIndex];
1130
- if (!i) return;
1131
- const s = this.editor.getValue(), r = this.getOffsetFromPosition(s, i.range.start), n = s.substring(0, r), o = s.substring(r + e.length), l = n + t + o;
1132
- this.editor.setValue(l), this.performSearch(e), this.updateStatus("Replaced current occurrence");
1133
- }
1134
- replaceAll(e, t) {
1135
- if (!this.editor || !e.trim()) return;
1136
- let i = this.editor.getValue(), s = 0, r = i.toLowerCase().indexOf(e.toLowerCase());
1137
- for (; r !== -1; )
1138
- i = i.substring(0, r) + t + i.substring(r + e.length), s++, r = i.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
1139
- s > 0 && (this.editor.setValue(i), this.updateStatus(`Replaced ${s} occurrences`));
1140
- }
1141
- getOffsetFromPosition(e, t) {
1142
- const i = e.split(`
1143
- `);
1144
- let s = 0;
1145
- for (let r = 0; r < t.line; r++)
1146
- s += i[r].length + 1;
1147
- return s += t.column, s;
1148
- }
1149
- updateHighlights() {
1150
- this.clearHighlights(), !(this.currentResults.length === 0 || this.currentIndex === -1) && (this.currentResults[this.currentIndex], this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`));
1151
- }
1152
- clearHighlights() {
1153
- }
1154
- updateStatus(e) {
1155
- var i;
1156
- const t = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-status");
1157
- t && (t.textContent = e);
1158
- }
1159
- destroy() {
1160
- this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.searchUI = null, this.editor = null;
1161
- }
1162
- }
1163
- class Z {
1164
- constructor() {
1165
- this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
1166
- "(": ")",
1167
- "[": "]",
1168
- "{": "}",
1169
- "<": ">"
1170
- }, this.reverseBracketPairs = {
1171
- ")": "(",
1172
- "]": "[",
1173
- "}": "{",
1174
- ">": "<"
1175
- }, this.currentMatch = null;
1176
- }
1177
- setup(e) {
1178
- this.editor = e, e.on("cursor", () => {
1179
- this.updateBracketMatching();
1180
- }), e.on("change", () => {
1181
- this.updateBracketMatching();
1182
- });
1183
- }
1184
- updateBracketMatching() {
1185
- if (!this.editor) return;
1186
- const e = this.editor.getCursor(), t = this.editor.getValue();
1187
- this.clearBracketHighlighting();
1188
- const i = this.getBracketAtPosition(t, e.position);
1189
- if (!i) return;
1190
- const s = this.findMatchingBracket(t, i);
1191
- s && (this.currentMatch = s, this.highlightBrackets(s));
1192
- }
1193
- getBracketAtPosition(e, t) {
1194
- const i = e.split(`
1195
- `);
1196
- if (t.line >= i.length) return null;
1197
- const s = i[t.line];
1198
- if (t.column >= s.length) return null;
1199
- const r = s[t.column];
1200
- return this.bracketPairs[r] || this.reverseBracketPairs[r] ? { char: r, position: t } : null;
1201
- }
1202
- findMatchingBracket(e, t) {
1203
- const i = e.split(`
1204
- `), s = t.position.line, r = t.position.column, n = t.char;
1205
- return this.bracketPairs[n] ? this.findClosingBracket(e, i, s, r, n) : this.reverseBracketPairs[n] ? this.findOpeningBracket(e, i, s, r, n) : null;
1206
- }
1207
- findClosingBracket(e, t, i, s, r) {
1208
- const n = this.bracketPairs[r];
1209
- let o = 0;
1210
- for (let l = i; l < t.length; l++) {
1211
- const c = t[l], a = l === i ? s : 0;
1212
- for (let u = a; u < c.length; u++) {
1213
- const d = c[u];
1214
- if (d === r)
1215
- o++;
1216
- else if (d === n && (o--, o === 0))
1217
- return {
1218
- open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
1219
- close: { start: { line: l, column: u }, end: { line: l, column: u + 1 } },
1220
- type: r
1221
- };
1222
- }
1223
- }
1224
- return null;
1225
- }
1226
- findOpeningBracket(e, t, i, s, r) {
1227
- const n = this.reverseBracketPairs[r];
1228
- let o = 0;
1229
- for (let l = i; l >= 0; l--) {
1230
- const c = t[l], a = l === i ? s : c.length - 1;
1231
- for (let u = a; u >= 0; u--) {
1232
- const d = c[u];
1233
- if (d === r)
1234
- o++;
1235
- else if (d === n && (o--, o === 0))
1236
- return {
1237
- open: { start: { line: l, column: u }, end: { line: l, column: u + 1 } },
1238
- close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
1239
- type: n
1240
- };
1241
- }
1242
- }
1243
- return null;
1244
- }
1245
- highlightBrackets(e) {
1246
- }
1247
- clearBracketHighlighting() {
1248
- this.currentMatch = null;
1249
- }
1250
- getCurrentMatch() {
1251
- return this.currentMatch;
1252
- }
1253
- destroy() {
1254
- this.clearBracketHighlighting(), this.editor = null;
1255
- }
1256
- }
1257
- class J {
1258
- constructor() {
1259
- this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;
1260
- }
1261
- setup(e) {
1262
- this.editor = e, e.registerCommand("fold", () => {
1263
- this.foldAtCursor();
1264
- }), e.registerCommand("unfold", () => {
1265
- this.unfoldAtCursor();
1266
- }), e.registerCommand("foldAll", () => {
1267
- this.foldAll();
1268
- }), e.registerCommand("unfoldAll", () => {
1269
- this.unfoldAll();
1270
- }), e.on("change", () => {
1271
- this.updateFoldIndicators();
1272
- }), this.createFoldingUI(), this.updateFoldIndicators();
1273
- }
1274
- createFoldingUI() {
1275
- if (!this.editor) return;
1276
- const e = document.querySelector(".rte-source-editor-modal");
1277
- e && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
1278
- position: absolute;
1279
- left: 40px;
1280
- top: 0;
1281
- bottom: 0;
1282
- width: 20px;
1283
- pointer-events: none;
1284
- z-index: 2;
1285
- `, e.appendChild(this.foldingUI));
1286
- }
1287
- updateFoldIndicators() {
1288
- if (!this.editor || !this.foldingUI) return;
1289
- this.foldingUI.innerHTML = "", this.foldIndicators = [];
1290
- const e = this.editor.getValue().split(`
1291
- `);
1292
- this.findFoldableLines(e).forEach((t) => {
1293
- this.createFoldIndicator(t);
1294
- });
1295
- }
1296
- findFoldableLines(e) {
1297
- const t = [];
1298
- for (let i = 0; i < e.length; i++) {
1299
- const s = e[i].trim();
1300
- (s.startsWith("{") || s.startsWith("function") || s.startsWith("class") || s.startsWith("if") || s.includes("=>") || s.startsWith("for") || s.startsWith("while") || s.startsWith("try")) && t.push(i);
1301
- }
1302
- return t;
1303
- }
1304
- createFoldIndicator(e) {
1305
- if (!this.foldingUI) return;
1306
- const t = document.createElement("div");
1307
- t.style.cssText = `
1308
- position: absolute;
1309
- left: 0;
1310
- top: ${e * 21}px;
1311
- width: 20px;
1312
- height: 21px;
1313
- display: flex;
1314
- align-items: center;
1315
- justify-content: center;
1316
- cursor: pointer;
1317
- pointer-events: auto;
1318
- color: var(--editor-gutter-foreground, #858585);
1319
- font-size: 10px;
1320
- user-select: none;
1321
- `, t.innerHTML = "▶", t.title = "Code folding not yet implemented - click shows fold indicators", t.addEventListener("click", () => {
1322
- }), this.foldingUI.appendChild(t), this.foldIndicators.push(t);
1323
- }
1324
- foldAtCursor() {
1325
- }
1326
- unfoldAtCursor() {
1327
- }
1328
- foldAll() {
1329
- }
1330
- unfoldAll() {
1331
- }
1332
- destroy() {
1333
- this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.foldingUI = null, this.foldIndicators = [], this.editor = null;
1334
- }
1335
- }
1336
- class X {
1337
- constructor() {
1338
- this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
1339
- }
1340
- setup(e) {
1341
- this.editor = e, this.registerMode("html", { name: "html", highlight: (t, i) => this._highlightHTML(t, i) }), this.registerMode("javascript", { name: "javascript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("typescript", { name: "typescript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("php", { name: "php", highlight: (t, i) => this._highlightPHP(t, i) });
1342
- }
1343
- // Extension provides methods that can be called by the editor
1344
- setTheme(e) {
1345
- this.currentTheme = e;
1346
- }
1347
- setLanguage(e) {
1348
- this.currentLanguage = e;
1349
- }
1350
- registerMode(e, t) {
1351
- this.modes.set(e.toLowerCase(), t);
1352
- }
1353
- // Method to get syntax highlighting colors for a given theme
1354
- getSyntaxColors() {
1355
- return this.currentTheme === "dark" ? {
1356
- tag: "#569cd6",
1357
- // Blue
1358
- comment: "#6a9955",
1359
- // Green
1360
- attrName: "#9cdcfe",
1361
- // Light blue for attribute names
1362
- attrValue: "#ce9178",
1363
- // Orange for attribute values
1364
- styleProp: "#c586c0",
1365
- // Purple for CSS property names
1366
- styleVal: "#dcdcaa",
1367
- // Yellow-ish for CSS values
1368
- doctype: "#808080",
1369
- // Gray for doctype
1370
- text: "#d4d4d4",
1371
- // Light gray for normal text
1372
- keyword: "#c586c0",
1373
- // JS/PHP keywords (purple)
1374
- string: "#ce9178",
1375
- // JS strings
1376
- number: "#b5cea8",
1377
- // numbers
1378
- variable: "#9cdcfe"
1379
- // php variable color
1380
- } : {
1381
- tag: "#0000ff",
1382
- // Blue
1383
- comment: "#008000",
1384
- // Green
1385
- attrName: "#001080",
1386
- attrValue: "#a31515",
1387
- // Red
1388
- styleProp: "#6a00a8",
1389
- styleVal: "#804000",
1390
- doctype: "#444444",
1391
- text: "#000000",
1392
- // Black
1393
- keyword: "#000080",
1394
- string: "#a31515",
1395
- number: "#0086b3",
1396
- variable: "#001080"
1397
- };
1398
- }
1399
- // Public API: highlight a source string using the chosen mode (or detect html)
1400
- highlight(e, t) {
1401
- const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
1402
- return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
1403
- }
1404
- // Backwards-compatible method
1405
- highlightHTML(e) {
1406
- return this.highlight(e, "html");
1407
- }
1408
- // --- Internal mode implementations ---
1409
- escapeHTML(e) {
1410
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;");
1411
- }
1412
- // Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
1413
- unescapeEntitiesRepeated(e) {
1414
- let t = e || "";
1415
- for (let i = 0; i < 5; i++) {
1416
- const s = t;
1417
- if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === s) break;
1418
- }
1419
- return t;
1420
- }
1421
- _highlightHTML(e, t) {
1422
- const i = t, s = (c) => this.escapeHTML(c);
1423
- let r = s(e);
1424
- const n = (c) => {
1425
- let a = c.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
1426
- return a = a.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), a = a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (u, d, g, h, f) => {
1427
- const p = String(h).trim(), x = s(p);
1428
- return `<span style="color: ${i.styleProp};">${d}</span>${g}<span style="color: ${i.styleVal};">${x}</span>${f}`;
1429
- }), a;
1430
- }, o = [];
1431
- try {
1432
- e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (c, a, u) => (o.push({ attrs: String(a || ""), inner: String(u || "") }), c));
1433
- } catch (c) {
1434
- }
1435
- let l = 0;
1436
- return r = r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (c, a, u, d, g) => {
1437
- var p, x, k;
1438
- const h = (x = (p = o[l++]) == null ? void 0 : p.inner) != null ? x : this.unescapeEntitiesRepeated(d || "");
1439
- (((k = o[l - 1]) == null ? void 0 : k.attrs) || u || "").toLowerCase();
1440
- const f = this._highlightJS(h, i);
1441
- return `${a}${f}${g}`;
1442
- }), r = r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (c, a, u, d) => {
1443
- const g = n(u);
1444
- return `${a}${g}${d}`;
1445
- }), r = r.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${i.comment};">$1</span>`), r = r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${i.doctype};">$1</span>`), r = r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (c, a, u, d, g) => {
1446
- const h = `<span style="color: ${i.tag};">${u}</span>`;
1447
- let f = d;
1448
- return f = f.replace(
1449
- /([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
1450
- (p, x, k, y) => {
1451
- const R = String(x).toLowerCase(), H = `<span style="color: ${i.attrName};">${x}</span>`;
1452
- let T = y, b = "";
1453
- y.startsWith("&quot;") && y.endsWith("&quot;") ? (T = y.slice(6, -6), b = "&quot;") : y.startsWith("&#39;") && y.endsWith("&#39;") && (T = y.slice(5, -5), b = "&#39;");
1454
- let w = y;
1455
- if (R === "style") {
1456
- const S = T.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (N, E, L, O) => `<span style="color: ${i.styleProp};">${E}</span>:<span style="color: ${i.styleVal};">${L.trim()}</span>${O}`);
1457
- b ? w = `${b}${S}${b}` : w = S, w = `<span style="color: ${i.attrValue};">${w}</span>`;
1458
- } else
1459
- b && (w = `${b}${T}${b}`), w = `<span style="color: ${i.attrValue};">${w}</span>`;
1460
- return `${H}${k}${w}`;
1461
- }
1462
- ), `${a}${h}${f}${g}`;
1463
- }), r;
1464
- }
1465
- _highlightJS(e, t) {
1466
- const i = this.unescapeEntitiesRepeated(e);
1467
- this.escapeHTML(i);
1468
- const s = [], r = (d) => {
1469
- let g = "", h = d;
1470
- do
1471
- g = String.fromCharCode(97 + h % 26) + g, h = Math.floor(h / 26) - 1;
1472
- while (h >= 0);
1473
- return g || "a";
1474
- }, n = (d) => `\0${r(d)}\0`, o = (d) => {
1475
- const g = s.length;
1476
- return s.push(d), n(g);
1477
- };
1478
- let l;
1479
- const c = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
1480
- let a = 0, u = "";
1481
- for (; l = c.exec(i); ) {
1482
- const d = l.index;
1483
- a < d && (u += this.escapeHTML(i.slice(a, d)));
1484
- const g = l[0];
1485
- /^\/\*/.test(g) || /^\/\//.test(g) ? u += o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`) : u += o(`<span style="color: ${t.string};">${this.escapeHTML(g)}</span>`), a = c.lastIndex;
1486
- }
1487
- return a < i.length && (u += this.escapeHTML(i.slice(a))), u = u.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, g, h) => {
1488
- const f = u[h - 1] || "", p = u[h + d.length] || "";
1489
- return f === "&" || f === "#" || p === ";" || p === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
1490
- }), u = u.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), u.replace(/\u0000([a-z]+)\u0000/g, (d, g) => {
1491
- let h = 0;
1492
- for (let f = 0; f < g.length; f++)
1493
- h = h * 26 + (g.charCodeAt(f) - 97 + 1);
1494
- return h = h - 1, s[h] || "";
1495
- });
1496
- }
1497
- _highlightPHP(e, t) {
1498
- const i = this.unescapeEntitiesRepeated(e);
1499
- let s = this.escapeHTML(i);
1500
- const r = [], n = (h) => {
1501
- let f = "", p = h;
1502
- do
1503
- f = String.fromCharCode(97 + p % 26) + f, p = Math.floor(p / 26) - 1;
1504
- while (p >= 0);
1505
- return f || "a";
1506
- }, o = (h) => {
1507
- const f = r.length;
1508
- return r.push(h), `\0${n(f)}\0`;
1509
- }, l = (h, f) => {
1510
- const p = s.indexOf(h);
1511
- return p === -1 ? !1 : (s = s.slice(0, p) + f + s.slice(p + h.length), !0);
1512
- };
1513
- let c;
1514
- const a = /\/\*[\s\S]*?\*\//g, u = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, g = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
1515
- for (; c = a.exec(i); ) {
1516
- const h = c[0];
1517
- l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1518
- }
1519
- for (; c = u.exec(i); ) {
1520
- const h = c[0];
1521
- l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1522
- }
1523
- for (; c = d.exec(i); ) {
1524
- const h = c[0];
1525
- l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1526
- }
1527
- for (; c = g.exec(i); ) {
1528
- const h = c[0];
1529
- l(this.escapeHTML(h), o(`<span style="color: ${t.string};">${this.escapeHTML(h)}</span>`));
1530
- }
1531
- return s = s.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), s = s.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${t.keyword};">$1</span>`), s = s.replace(/\u0000([a-z]+)\u0000/g, (h, f) => {
1532
- let p = 0;
1533
- for (let x = 0; x < f.length; x++)
1534
- p = p * 26 + (f.charCodeAt(x) - 97 + 1);
1535
- return p = p - 1, r[p] || "";
1536
- }), s;
1537
- }
1538
- // Method to check if content contains syntax that should be highlighted
1539
- shouldHighlight(e) {
1540
- return /<\/?[\w:-]+|<!--/.test(e);
1541
- }
1542
- destroy() {
1543
- this.editor = null, this.modes.clear();
1544
- }
1545
- }
1546
- function Y(v, e) {
1547
- const t = { ...e };
1548
- return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new q(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new F()), new z(v, t);
1549
- }
1550
- const $ = '[data-theme="dark"], .dark, .editora-theme-dark', G = `/* Source Editor Dialog Styles */
1551
- .rte-source-editor-overlay {
1552
- position: fixed !important;
1553
- top: 0 !important;
1554
- left: 0 !important;
1555
- right: 0 !important;
1556
- bottom: 0 !important;
1557
- width: 100vw !important;
1558
- height: 100vh !important;
1559
- background-color: rgba(0, 0, 0, 0.6) !important;
1560
- display: flex !important;
1561
- align-items: center !important;
1562
- justify-content: center !important;
1563
- z-index: 10000 !important;
1564
- padding: 20px !important;
1565
- box-sizing: border-box !important;
1566
- margin: 0 !important;
1567
- }
1568
-
1569
- .rte-source-editor-overlay.fullscreen {
1570
- padding: 0 !important;
1571
- }
1572
-
1573
- .rte-source-editor-modal {
1574
- background: white;
1575
- border-radius: 8px;
1576
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
1577
- width: 100%;
1578
- max-width: 1200px;
1579
- max-height: 90vh;
1580
- display: flex;
1581
- flex-direction: column;
1582
- overflow: hidden;
1583
- position: relative;
1584
- }
1585
-
1586
- .rte-source-editor-overlay.fullscreen .rte-source-editor-modal {
1587
- border-radius: 0;
1588
- max-width: 100%;
1589
- max-height: 100vh;
1590
- width: 100%;
1591
- height: 100vh;
1592
- }
1593
-
1594
- .rte-source-editor-header {
1595
- display: flex;
1596
- align-items: center;
1597
- justify-content: space-between;
1598
- padding: 16px 20px;
1599
- border-bottom: 1px solid #e1e5e9;
1600
- background: #f8f9fa;
1601
- border-radius: 8px 8px 0 0;
1602
- }
1603
-
1604
- .rte-source-editor-overlay.fullscreen .rte-source-editor-header {
1605
- border-radius: 0;
1606
- }
1607
-
1608
- .rte-source-editor-header h2 {
1609
- margin: 0;
1610
- font-size: 18px;
1611
- font-weight: 600;
1612
- color: #1a1a1a;
1613
- }
1614
-
1615
- .rte-source-editor-header-toolbar {
1616
- display: flex;
1617
- gap: 8px;
1618
- margin-left: auto;
1619
- margin-right: 16px;
1620
- }
1621
-
1622
- .rte-source-editor-toolbar-btn {
1623
- background: none;
1624
- border: none;
1625
- cursor: pointer;
1626
- padding: 6px;
1627
- border-radius: 4px;
1628
- font-size: 16px;
1629
- line-height: 1;
1630
- transition: all 0.2s ease;
1631
- color: #666;
1632
- }
1633
-
1634
- .rte-source-editor-toolbar-btn:hover:not(:disabled) {
1635
- background: #e1e5e9;
1636
- color: #1a1a1a;
1637
- }
1638
-
1639
- .rte-source-editor-toolbar-btn:disabled {
1640
- opacity: 0.5;
1641
- cursor: not-allowed;
1642
- }
1643
-
1644
- .rte-source-editor-toolbar-btn.active {
1645
- background: #007acc;
1646
- color: white;
1647
- }
1648
-
1649
- .rte-source-editor-toolbar-btn.active:hover {
1650
- background: #0056b3;
1651
- }
1652
-
1653
- .rte-source-editor-header-actions {
1654
- display: flex;
1655
- gap: 8px;
1656
- }
1657
-
1658
- .rte-source-editor-fullscreen-btn,
1659
- .rte-source-editor-close-btn {
1660
- background: none;
1661
- border: none;
1662
- cursor: pointer;
1663
- padding: 4px;
1664
- border-radius: 4px;
1665
- color: #666;
1666
- font-size: 16px;
1667
- line-height: 1;
1668
- transition: all 0.2s ease;
1669
- }
1670
-
1671
- .rte-source-editor-fullscreen-btn:hover,
1672
- .rte-source-editor-close-btn:hover {
1673
- background: #e1e5e9;
1674
- color: #1a1a1a;
1675
- }
1676
-
1677
- .rte-source-editor-body {
1678
- flex: 1;
1679
- overflow: hidden;
1680
- display: flex;
1681
- flex-direction: column;
1682
- }
1683
-
1684
- .rte-source-editor-loading {
1685
- display: flex;
1686
- flex-direction: column;
1687
- align-items: center;
1688
- justify-content: center;
1689
- padding: 40px;
1690
- color: #666;
1691
- position: absolute;
1692
- z-index: 9;
1693
- margin: 0 auto;
1694
- width: 100%;
1695
- top: 44%;
1696
- }
1697
-
1698
- .rte-source-editor-spinner {
1699
- width: 32px;
1700
- height: 32px;
1701
- border: 3px solid #e1e5e9;
1702
- border-top: 3px solid #007acc;
1703
- border-radius: 50%;
1704
- animation: spin 1s linear infinite;
1705
- margin-bottom: 16px;
1706
- }
1707
-
1708
- @keyframes spin {
1709
- 0% { transform: rotate(0deg); }
1710
- 100% { transform: rotate(360deg); }
1711
- }
1712
-
1713
- .rte-source-editor-error {
1714
- background: #fee;
1715
- color: #c53030;
1716
- padding: 12px 16px;
1717
- border-left: 4px solid #c53030;
1718
- margin: 16px;
1719
- border-radius: 4px;
1720
- font-size: 14px;
1721
- }
1722
-
1723
- .rte-source-editor-content {
1724
- flex: 1;
1725
- display: flex;
1726
- flex-direction: column;
1727
- overflow: hidden;
1728
- }
1729
-
1730
- .rte-source-editor-warning {
1731
- background: #fefcbf;
1732
- color: #744210;
1733
- padding: 8px 16px;
1734
- font-size: 12px;
1735
- font-weight: 500;
1736
- border-bottom: 1px solid #f6e05e;
1737
- }
1738
-
1739
- .rte-source-editor-codemirror {
1740
- flex: 1;
1741
- overflow: auto;
1742
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
1743
- font-size: 14px;
1744
- line-height: 1.5;
1745
- }
1746
-
1747
- .rte-source-editor-codemirror .cm-editor {
1748
- height: 100%;
1749
- }
1750
-
1751
- .rte-source-editor-codemirror .cm-focused {
1752
- outline: none;
1753
- }
1754
-
1755
- .rte-source-editor-footer {
1756
- display: flex;
1757
- align-items: center;
1758
- justify-content: space-between;
1759
- padding: 16px 20px;
1760
- border-top: 1px solid #e1e5e9;
1761
- background: #f8f9fa;
1762
- border-radius: 0 0 8px 8px;
1763
- }
1764
-
1765
- .rte-source-editor-overlay.fullscreen .rte-source-editor-footer {
1766
- border-radius: 0;
1767
- }
1768
-
1769
- .rte-source-editor-footer-info {
1770
- font-size: 12px;
1771
- color: #666;
1772
- }
1773
-
1774
- .unsaved-changes {
1775
- color: #d69e2e;
1776
- font-weight: 500;
1777
- }
1778
-
1779
- .rte-source-editor-footer-actions {
1780
- display: flex;
1781
- gap: 12px;
1782
- }
1783
-
1784
- .rte-source-editor-btn {
1785
- padding: 8px 16px;
1786
- border-radius: 4px;
1787
- font-size: 14px;
1788
- font-weight: 500;
1789
- cursor: pointer;
1790
- border: 1px solid transparent;
1791
- transition: all 0.2s ease;
1792
- }
1793
-
1794
- .rte-source-editor-btn:disabled {
1795
- opacity: 0.6;
1796
- cursor: not-allowed;
1797
- }
1798
-
1799
- .rte-source-editor-btn-cancel {
1800
- background: white;
1801
- border-color: #d1d5db;
1802
- color: #374151;
1803
- }
1804
-
1805
- .rte-source-editor-btn-cancel:hover:not(:disabled) {
1806
- background: #f9fafb;
1807
- border-color: #9ca3af;
1808
- }
1809
-
1810
- .rte-source-editor-btn-save {
1811
- background: #007acc;
1812
- color: white;
1813
- }
1814
-
1815
- .rte-source-editor-btn-save:hover:not(:disabled) {
1816
- background: #0056b3;
1817
- }
1818
-
1819
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
1820
- background: #1e1e1e;
1821
- color: #f8f9fa;
1822
- border: 1px solid #434d5f;
1823
- }
1824
-
1825
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
1826
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
1827
- background: #2a3442;
1828
- border-color: #434d5f;
1829
- }
1830
-
1831
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
1832
- color: #f8f9fa;
1833
- }
1834
-
1835
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
1836
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
1837
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
1838
- color: #c1cede;
1839
- }
1840
-
1841
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
1842
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
1843
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
1844
- background: #404a5a;
1845
- color: #f8fafc;
1846
- }
1847
-
1848
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
1849
- background: #3b82f6;
1850
- color: #ffffff;
1851
- }
1852
-
1853
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
1854
- background: #2563eb;
1855
- }
1856
-
1857
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
1858
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
1859
- color: #cbd5e1;
1860
- }
1861
-
1862
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
1863
- border-color: #3f4b60;
1864
- border-top-color: #58a6ff;
1865
- }
1866
-
1867
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
1868
- background: #3f2124;
1869
- color: #fecaca;
1870
- border-color: #ef4444;
1871
- }
1872
-
1873
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
1874
- background: #3b3220;
1875
- color: #fde68a;
1876
- border-color: #f59e0b;
1877
- }
1878
-
1879
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
1880
- background: #334155;
1881
- border-color: #475569;
1882
- color: #f1f5f9;
1883
- }
1884
-
1885
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
1886
- background: #475569;
1887
- border-color: #64748b;
1888
- }
1889
-
1890
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
1891
- background: #3b82f6;
1892
- }
1893
-
1894
- .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
1895
- background: #2563eb;
1896
- }
1897
-
1898
- /* Responsive design */
1899
- @media (max-width: 768px) {
1900
- .rte-source-editor-overlay {
1901
- padding: 10px;
1902
- }
1903
-
1904
- .rte-source-editor-modal {
1905
- max-height: 95vh;
1906
- }
1907
-
1908
- .rte-source-editor-header {
1909
- padding: 12px 16px;
1910
- }
1911
-
1912
- .rte-source-editor-footer {
1913
- padding: 12px 16px;
1914
- flex-direction: column;
1915
- gap: 12px;
1916
- align-items: stretch;
1917
- }
1918
-
1919
- .rte-source-editor-footer-actions {
1920
- justify-content: stretch;
1921
- }
1922
-
1923
- .rte-source-editor-btn {
1924
- flex: 1;
1925
- text-align: center;
1926
- }
1927
- }`, ee = () => ({
1928
- name: "code",
1929
- // Toolbar button configuration
1930
- toolbar: [
1931
- {
1932
- label: "Source",
1933
- command: "toggleSourceView",
1934
- // type: "button",
1935
- icon: '<svg width="24" height="24" focusable="false"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7ZM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7Z"></path></g></svg>',
1936
- shortcut: "Mod-Shift-S"
1937
- }
1938
- ],
1939
- // Native command implementations
1940
- commands: {
1941
- /**
1942
- * Toggle HTML source view
1943
- * Opens a dialog to edit raw HTML
1944
- */
1945
- toggleSourceView: () => {
1946
- const e = (() => {
1947
- var o, l, c;
1948
- const r = window.getSelection();
1949
- if (r && r.anchorNode) {
1950
- let a = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
1951
- for (; a; ) {
1952
- if ((o = a.classList) != null && o.contains("rte-content"))
1953
- return a;
1954
- a = a.parentElement;
1955
- }
1956
- }
1957
- if (document.activeElement) {
1958
- let a = document.activeElement;
1959
- if ((l = a.classList) != null && l.contains("rte-content"))
1960
- return a;
1961
- for (; a && a !== document.body; ) {
1962
- if ((c = a.classList) != null && c.contains("rte-content"))
1963
- return a;
1964
- const u = a.querySelector(
1965
- ".rte-content"
1966
- );
1967
- if (u) return u;
1968
- a = a.parentElement;
1969
- }
1970
- }
1971
- const n = document.querySelector("[data-editora-editor]");
1972
- if (n) {
1973
- const a = n.querySelector(
1974
- ".rte-content"
1975
- );
1976
- if (a) return a;
1977
- }
1978
- return document.querySelector(".rte-content");
1979
- })();
1980
- if (!e)
1981
- return console.error("[CodePlugin] Editor content area not found"), alert(
1982
- "Editor content area not found. Please click inside the editor first."
1983
- ), !1;
1984
- const t = e.innerHTML, i = (r) => {
1985
- let n = "", o = 0;
1986
- const l = 2, c = r.split(/(<\/?[a-zA-Z][^>]*>)/);
1987
- for (const a of c)
1988
- a.trim() && (a.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), n += `
1989
- ` + " ".repeat(o * l) + a) : a.match(/^<[a-zA-Z]/) && !a.match(/\/>$/) ? (n += `
1990
- ` + " ".repeat(o * l) + a, o++) : a.match(/^<[a-zA-Z].*\/>$/) ? n += `
1991
- ` + " ".repeat(o * l) + a : n += a.trim());
1992
- return n.trim();
1993
- };
1994
- return (() => {
1995
- var E, L, O, I, A, B;
1996
- let r = null, n = "dark", o = !1, l = !1, c = !1;
1997
- const a = t, u = !!e.closest($) || document.body.matches($) || document.documentElement.matches($), d = document.createElement("div");
1998
- d.className = "rte-source-editor-overlay", u && d.classList.add("rte-theme-dark");
1999
- const g = document.createElement("div");
2000
- g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
2001
- const h = document.createElement("div");
2002
- h.className = "rte-source-editor-header", h.innerHTML = `
2003
- <h2 id="source-editor-title">Source Editor</h2>
2004
- <div class="rte-source-editor-header-toolbar">
2005
- <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
2006
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2007
- <circle cx="12" cy="12" r="5"/>
2008
- <line x1="12" y1="1" x2="12" y2="3"/>
2009
- <line x1="12" y1="21" x2="12" y2="23"/>
2010
- <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
2011
- <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
2012
- <line x1="1" y1="12" x2="3" y2="12"/>
2013
- <line x1="21" y1="12" x2="23" y2="12"/>
2014
- <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
2015
- <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
2016
- </svg>
2017
- </button>
2018
- <button class="rte-source-editor-toolbar-btn readonly-toggle-btn" title="Toggle read-only">
2019
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2020
- <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
2021
- <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
2022
- </svg>
2023
- </button>
2024
- </div>
2025
- <div class="rte-source-editor-header-actions">
2026
- <button class="rte-source-editor-fullscreen-btn" title="Toggle fullscreen">
2027
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2028
- <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
2029
- </svg>
2030
- </button>
2031
- <button class="rte-source-editor-close-btn" aria-label="Close source editor">
2032
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2033
- <line x1="18" y1="6" x2="6" y2="18"/>
2034
- <line x1="6" y1="6" x2="18" y2="18"/>
2035
- </svg>
2036
- </button>
2037
- </div>
2038
- `;
2039
- const f = document.createElement("div");
2040
- f.className = "rte-source-editor-body";
2041
- const p = document.createElement("div");
2042
- p.className = "rte-source-editor-content";
2043
- const x = document.createElement("div");
2044
- x.className = "rte-source-editor-warning", x.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
2045
- const k = document.createElement("div");
2046
- k.className = "rte-source-editor-light-editor", k.style.height = "400px", p.appendChild(x), p.appendChild(k), f.appendChild(p);
2047
- const y = document.createElement("div");
2048
- if (y.className = "rte-source-editor-footer", y.innerHTML = `
2049
- <div class="rte-source-editor-footer-info">
2050
- <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
2051
- </div>
2052
- <div class="rte-source-editor-footer-actions">
2053
- <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
2054
- <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
2055
- </div>
2056
- `, g.appendChild(h), g.appendChild(f), g.appendChild(y), d.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
2057
- const m = document.createElement("style");
2058
- m.id = "rte-source-editor-styles", m.textContent = G, document.head.appendChild(m);
2059
- }
2060
- document.body.appendChild(d);
2061
- try {
2062
- r = Y(k, {
2063
- value: i(t),
2064
- theme: "dark",
2065
- readOnly: !1,
2066
- extensions: [
2067
- new _(),
2068
- new W(),
2069
- new D(),
2070
- new Z(),
2071
- new j(),
2072
- new J(),
2073
- new X()
2074
- ]
2075
- }), r.on("change", () => {
2076
- c = ((r == null ? void 0 : r.getValue()) || "") !== i(a);
2077
- const C = y.querySelector(
2078
- ".unsaved-changes"
2079
- );
2080
- C && (C.style.display = c ? "inline" : "none");
2081
- }), setTimeout(() => r == null ? void 0 : r.focus(), 100);
2082
- } catch (m) {
2083
- console.error("Failed to initialize code editor:", m);
2084
- }
2085
- const R = () => {
2086
- n = n === "dark" ? "light" : "dark", r == null || r.setTheme(n);
2087
- const m = h.querySelector(".theme-toggle-btn");
2088
- m && n === "light" && (m.innerHTML = `
2089
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2090
- <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
2091
- </svg>
2092
- `);
2093
- }, H = () => {
2094
- o = !o, r == null || r.setReadOnly(o);
2095
- const m = h.querySelector(".readonly-toggle-btn");
2096
- m && (o ? (m.classList.add("active"), m.innerHTML = `
2097
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2098
- <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
2099
- <circle cx="12" cy="16" r="1"/>
2100
- <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
2101
- </svg>
2102
- `) : (m.classList.remove("active"), m.innerHTML = `
2103
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2104
- <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
2105
- <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
2106
- </svg>
2107
- `));
2108
- }, T = () => {
2109
- l = !l, l ? (d.classList.add("fullscreen"), k.style.height = "calc(100vh - 200px)") : (d.classList.remove("fullscreen"), k.style.height = "400px");
2110
- const m = h.querySelector(
2111
- ".rte-source-editor-fullscreen-btn"
2112
- );
2113
- m && (m.innerHTML = l ? `
2114
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2115
- <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
2116
- </svg>
2117
- ` : `
2118
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2119
- <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
2120
- </svg>
2121
- `);
2122
- }, b = () => {
2123
- r && (r.destroy(), r = null), document.body.removeChild(d);
2124
- }, w = () => {
2125
- c && !confirm(
2126
- "You have unsaved changes. Are you sure you want to cancel?"
2127
- ) || b();
2128
- }, S = () => {
2129
- try {
2130
- const m = (r == null ? void 0 : r.getValue()) || "", C = document.createElement("div");
2131
- C.innerHTML = m, C.querySelectorAll(
2132
- 'script, iframe[src^="javascript:"], object, embed'
2133
- ).forEach((V) => V.remove()), e.innerHTML = C.innerHTML;
2134
- try {
2135
- e.dispatchEvent(
2136
- new InputEvent("input", {
2137
- bubbles: !0,
2138
- cancelable: !1,
2139
- inputType: "insertReplacementText"
2140
- })
2141
- );
2142
- } catch (V) {
2143
- e.dispatchEvent(
2144
- new Event("input", { bubbles: !0 })
2145
- );
2146
- }
2147
- e.dispatchEvent(
2148
- new Event("change", { bubbles: !0 })
2149
- ), c = !1, b();
2150
- } catch (m) {
2151
- alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", m);
2152
- }
2153
- };
2154
- (E = h.querySelector(".theme-toggle-btn")) == null || E.addEventListener("click", R), (L = h.querySelector(".readonly-toggle-btn")) == null || L.addEventListener("click", H), (O = h.querySelector(".rte-source-editor-fullscreen-btn")) == null || O.addEventListener("click", T), (I = h.querySelector(".rte-source-editor-close-btn")) == null || I.addEventListener("click", b), (A = y.querySelector(".rte-source-editor-btn-cancel")) == null || A.addEventListener("click", w), (B = y.querySelector(".rte-source-editor-btn-save")) == null || B.addEventListener("click", S), d.addEventListener("click", (m) => {
2155
- m.target === d && b();
2156
- });
2157
- const N = (m) => {
2158
- m.key === "Escape" && (b(), document.removeEventListener("keydown", N));
2159
- };
2160
- document.addEventListener("keydown", N);
2161
- })(), !0;
2162
- }
2163
- },
2164
- // Keyboard shortcuts
2165
- keymap: {
2166
- "Mod-Shift-s": "toggleSourceView",
2167
- "Mod-Shift-S": "toggleSourceView"
2168
- }
2169
- });
2170
- export {
2171
- ee as CodePlugin
2172
- };
2173
- //# sourceMappingURL=CodePlugin.native-B263UI8O.mjs.map