@editora/plugins 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-sample.cjs.js +7 -7
- package/dist/code-sample.esm.js +51 -51
- package/dist/code.cjs.js +38 -30
- package/dist/code.esm.js +570 -440
- package/dist/history.cjs.js +1 -1
- package/dist/history.esm.js +8 -8
- package/dist/merge-tag.cjs.js +1 -1
- package/dist/merge-tag.esm.js +1 -1
- package/package.json +5 -4
package/dist/code.esm.js
CHANGED
|
@@ -30,28 +30,28 @@ class H {
|
|
|
30
30
|
return this.getLine(e.start.line).substring(e.start.column, e.end.column);
|
|
31
31
|
const t = [];
|
|
32
32
|
t.push(this.getLine(e.start.line).substring(e.start.column));
|
|
33
|
-
for (let
|
|
34
|
-
t.push(this.getLine(
|
|
33
|
+
for (let i = e.start.line + 1; i < e.end.line; i++)
|
|
34
|
+
t.push(this.getLine(i));
|
|
35
35
|
return e.end.line < this.getLineCount() && t.push(this.getLine(e.end.line).substring(0, e.end.column)), t.join(`
|
|
36
36
|
`);
|
|
37
37
|
}
|
|
38
38
|
// Replace text in range
|
|
39
39
|
replaceRange(e, t) {
|
|
40
|
-
const
|
|
40
|
+
const i = this.getTextInRange(e);
|
|
41
41
|
if (e.start.line === e.end.line) {
|
|
42
|
-
const
|
|
42
|
+
const s = this.getLine(e.start.line), r = s.substring(0, e.start.column) + t + s.substring(e.end.column);
|
|
43
43
|
this._lines[e.start.line] = r;
|
|
44
44
|
} else {
|
|
45
|
-
const
|
|
45
|
+
const s = this.getLine(e.start.line), r = this.getLine(e.end.line), o = s.substring(0, e.start.column) + t, n = r.substring(e.end.column), l = t.split(`
|
|
46
46
|
`);
|
|
47
|
-
|
|
47
|
+
l[0] = o + l[0], l[l.length - 1] = l[l.length - 1] + n, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...l);
|
|
48
48
|
}
|
|
49
|
-
return this._version++, { range: e, text: t, oldText:
|
|
49
|
+
return this._version++, { range: e, text: t, oldText: i };
|
|
50
50
|
}
|
|
51
51
|
// Insert text at position
|
|
52
52
|
insertText(e, t) {
|
|
53
|
-
const
|
|
54
|
-
return this.replaceRange(
|
|
53
|
+
const i = { start: e, end: e };
|
|
54
|
+
return this.replaceRange(i, t);
|
|
55
55
|
}
|
|
56
56
|
// Delete text in range
|
|
57
57
|
deleteRange(e) {
|
|
@@ -60,18 +60,18 @@ class H {
|
|
|
60
60
|
// Convert position to offset
|
|
61
61
|
positionToOffset(e) {
|
|
62
62
|
let t = 0;
|
|
63
|
-
for (let
|
|
64
|
-
t += this.getLine(
|
|
63
|
+
for (let i = 0; i < e.line; i++)
|
|
64
|
+
t += this.getLine(i).length + 1;
|
|
65
65
|
return t += e.column, t;
|
|
66
66
|
}
|
|
67
67
|
// Convert offset to position
|
|
68
68
|
offsetToPosition(e) {
|
|
69
69
|
let t = e;
|
|
70
|
-
for (let
|
|
71
|
-
const
|
|
72
|
-
if (t <=
|
|
73
|
-
return { line:
|
|
74
|
-
t -=
|
|
70
|
+
for (let i = 0; i < this.getLineCount(); i++) {
|
|
71
|
+
const s = this.getLine(i).length;
|
|
72
|
+
if (t <= s)
|
|
73
|
+
return { line: i, column: t };
|
|
74
|
+
t -= s + 1;
|
|
75
75
|
}
|
|
76
76
|
return {
|
|
77
77
|
line: this.getLineCount() - 1,
|
|
@@ -96,9 +96,9 @@ class H {
|
|
|
96
96
|
return e._lines = [...this._lines], e._version = this._version, e;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
class
|
|
99
|
+
class P {
|
|
100
100
|
constructor(e) {
|
|
101
|
-
this.gutterWidth = 50, this.lineHeight = 21, this.container = e, this.createDOM();
|
|
101
|
+
this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.container = e, this.createDOM();
|
|
102
102
|
}
|
|
103
103
|
createDOM() {
|
|
104
104
|
this.container.innerHTML = "";
|
|
@@ -149,8 +149,8 @@ class R {
|
|
|
149
149
|
}
|
|
150
150
|
// Update line numbers
|
|
151
151
|
updateLineNumbers(e) {
|
|
152
|
-
const t = Math.max(e, 20),
|
|
153
|
-
this.lineNumbersElement.innerHTML =
|
|
152
|
+
const t = Math.max(e, 20), i = Array.from({ length: t }, (s, r) => r + 1);
|
|
153
|
+
this.lineNumbersElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("");
|
|
154
154
|
}
|
|
155
155
|
// Get content element
|
|
156
156
|
getContentElement() {
|
|
@@ -162,88 +162,106 @@ class R {
|
|
|
162
162
|
}
|
|
163
163
|
// Get text content
|
|
164
164
|
getText() {
|
|
165
|
-
|
|
165
|
+
const e = this.contentElement.textContent || "";
|
|
166
|
+
return this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`) && e.endsWith("") ? e.slice(0, -1) : e;
|
|
166
167
|
}
|
|
167
168
|
// Set text content
|
|
168
169
|
setText(e) {
|
|
169
|
-
this.contentElement.textContent = e
|
|
170
|
+
this.contentElement.textContent = e, this.syncTrailingNewlineMarker(e.endsWith(`
|
|
171
|
+
`));
|
|
170
172
|
const t = e.split(`
|
|
171
173
|
`).length;
|
|
172
174
|
this.updateLineNumbers(t);
|
|
173
175
|
}
|
|
174
176
|
// Set inner HTML (used for syntax highlighted content)
|
|
175
177
|
setHTML(e) {
|
|
176
|
-
const t = /<|>/.test(e), s = /<span\b/i.test(e),
|
|
177
|
-
|
|
178
|
-
const
|
|
178
|
+
const t = /\n$/.test(e), i = /<|>/.test(e), s = /<span\b/i.test(e), r = /<[^>]+>/.test(e);
|
|
179
|
+
i && s ? this.contentElement.innerHTML = e : r && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
|
|
180
|
+
const o = (this.contentElement.textContent || "").split(`
|
|
179
181
|
`).length;
|
|
180
|
-
this.updateLineNumbers(
|
|
182
|
+
this.updateLineNumbers(o);
|
|
183
|
+
}
|
|
184
|
+
// Keep trailing-newline caret marker in sync for live contenteditable edits
|
|
185
|
+
// (without forcing a full setText/setHTML render).
|
|
186
|
+
syncTrailingNewlineMarkerForText(e) {
|
|
187
|
+
this.syncTrailingNewlineMarker(e.endsWith(`
|
|
188
|
+
`));
|
|
181
189
|
}
|
|
182
190
|
// Get cursor position from DOM selection
|
|
183
191
|
getCursorPosition() {
|
|
184
192
|
const e = window.getSelection();
|
|
185
193
|
if (!e || e.rangeCount === 0)
|
|
186
194
|
return { line: 0, column: 0 };
|
|
187
|
-
const t = e.getRangeAt(0),
|
|
188
|
-
|
|
189
|
-
const
|
|
195
|
+
const t = e.getRangeAt(0), i = t.cloneRange();
|
|
196
|
+
i.selectNodeContents(this.contentElement), i.setEnd(t.endContainer, t.endOffset);
|
|
197
|
+
const s = i.toString().replace(/\u200B/g, "").split(`
|
|
190
198
|
`);
|
|
191
199
|
return {
|
|
192
|
-
line:
|
|
193
|
-
column:
|
|
200
|
+
line: s.length - 1,
|
|
201
|
+
column: s[s.length - 1].length
|
|
194
202
|
};
|
|
195
203
|
}
|
|
196
204
|
// Set cursor position
|
|
197
205
|
setCursorPosition(e) {
|
|
198
206
|
const t = this.getText().split(`
|
|
199
|
-
`),
|
|
207
|
+
`), i = Math.min(e.line, t.length - 1), s = Math.min(e.column, t[i]?.length || 0);
|
|
200
208
|
let r = 0;
|
|
201
|
-
for (let u = 0; u <
|
|
209
|
+
for (let u = 0; u < i; u++)
|
|
202
210
|
r += t[u].length + 1;
|
|
203
|
-
r +=
|
|
204
|
-
const
|
|
205
|
-
let
|
|
211
|
+
r += s;
|
|
212
|
+
const o = document.createRange(), n = window.getSelection();
|
|
213
|
+
let l = 0, a = null, c = 0;
|
|
206
214
|
const g = document.createTreeWalker(
|
|
207
215
|
this.contentElement,
|
|
208
216
|
NodeFilter.SHOW_TEXT,
|
|
209
217
|
null
|
|
210
218
|
);
|
|
211
|
-
let
|
|
212
|
-
for (;
|
|
213
|
-
const u =
|
|
214
|
-
if (
|
|
215
|
-
|
|
219
|
+
let h;
|
|
220
|
+
for (; h = g.nextNode(); ) {
|
|
221
|
+
const u = h.textContent?.length || 0;
|
|
222
|
+
if (l + u >= r) {
|
|
223
|
+
a = h, c = r - l;
|
|
216
224
|
break;
|
|
217
225
|
}
|
|
218
|
-
|
|
226
|
+
l += u;
|
|
219
227
|
}
|
|
220
|
-
if (
|
|
228
|
+
if (a)
|
|
221
229
|
try {
|
|
222
|
-
|
|
230
|
+
o.setStart(a, c), o.setEnd(a, c), n?.removeAllRanges(), n?.addRange(o), this.ensureCaretVisible();
|
|
223
231
|
} catch (u) {
|
|
224
232
|
console.warn("Could not set cursor position:", u);
|
|
225
233
|
}
|
|
234
|
+
else {
|
|
235
|
+
const u = this.contentElement.querySelector(
|
|
236
|
+
`[${this.trailingNewlineMarkerAttr}]`
|
|
237
|
+
);
|
|
238
|
+
try {
|
|
239
|
+
u && u.parentNode === this.contentElement ? o.setStartBefore(u) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), n?.removeAllRanges(), n?.addRange(o), this.ensureCaretVisible();
|
|
240
|
+
} catch (d) {
|
|
241
|
+
console.warn("Could not set fallback cursor position:", d);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
226
244
|
}
|
|
227
245
|
// Get selection range
|
|
228
246
|
getSelectionRange() {
|
|
229
247
|
const e = window.getSelection();
|
|
230
248
|
if (!e || e.rangeCount === 0 || e.isCollapsed)
|
|
231
249
|
return;
|
|
232
|
-
const t = e.getRangeAt(0),
|
|
233
|
-
|
|
234
|
-
const
|
|
250
|
+
const t = e.getRangeAt(0), i = t.cloneRange();
|
|
251
|
+
i.selectNodeContents(this.contentElement), i.setEnd(t.startContainer, t.startOffset);
|
|
252
|
+
const s = i.toString().replace(/\u200B/g, "").split(`
|
|
235
253
|
`), r = t.cloneRange();
|
|
236
254
|
r.selectNodeContents(this.contentElement), r.setEnd(t.endContainer, t.endOffset);
|
|
237
|
-
const
|
|
255
|
+
const o = r.toString().replace(/\u200B/g, "").split(`
|
|
238
256
|
`);
|
|
239
257
|
return {
|
|
240
258
|
start: {
|
|
241
|
-
line:
|
|
242
|
-
column:
|
|
259
|
+
line: s.length - 1,
|
|
260
|
+
column: s[s.length - 1].length
|
|
243
261
|
},
|
|
244
262
|
end: {
|
|
245
|
-
line:
|
|
246
|
-
column:
|
|
263
|
+
line: o.length - 1,
|
|
264
|
+
column: o[o.length - 1].length
|
|
247
265
|
}
|
|
248
266
|
};
|
|
249
267
|
}
|
|
@@ -253,7 +271,7 @@ class R {
|
|
|
253
271
|
}
|
|
254
272
|
// Focus the editor
|
|
255
273
|
focus() {
|
|
256
|
-
this.contentElement.focus();
|
|
274
|
+
this.contentElement.focus(), this.ensureCaretVisible();
|
|
257
275
|
}
|
|
258
276
|
// Blur the editor
|
|
259
277
|
blur() {
|
|
@@ -265,8 +283,8 @@ class R {
|
|
|
265
283
|
}
|
|
266
284
|
// Apply theme
|
|
267
285
|
applyTheme(e) {
|
|
268
|
-
Object.entries(e).forEach(([t,
|
|
269
|
-
this.container.style.setProperty(`--${t}`,
|
|
286
|
+
Object.entries(e).forEach(([t, i]) => {
|
|
287
|
+
this.container.style.setProperty(`--${t}`, i);
|
|
270
288
|
});
|
|
271
289
|
}
|
|
272
290
|
// Scroll to position
|
|
@@ -282,14 +300,36 @@ class R {
|
|
|
282
300
|
setScrollTop(e) {
|
|
283
301
|
this.editorContainer.scrollTop = e;
|
|
284
302
|
}
|
|
303
|
+
syncTrailingNewlineMarker(e) {
|
|
304
|
+
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e) return;
|
|
305
|
+
const t = document.createElement("span");
|
|
306
|
+
t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
|
|
307
|
+
display: inline-block;
|
|
308
|
+
width: 0;
|
|
309
|
+
overflow: hidden;
|
|
310
|
+
pointer-events: none;
|
|
311
|
+
user-select: none;
|
|
312
|
+
`, t.appendChild(document.createTextNode("")), this.contentElement.appendChild(t);
|
|
313
|
+
}
|
|
314
|
+
// Ensure caret is visible inside the editor scroll container
|
|
315
|
+
ensureCaretVisible() {
|
|
316
|
+
const e = window.getSelection();
|
|
317
|
+
if (!e || e.rangeCount === 0) return;
|
|
318
|
+
const t = e.getRangeAt(0).cloneRange();
|
|
319
|
+
t.collapse(!1);
|
|
320
|
+
let i = t.getClientRects()[0] || t.getBoundingClientRect();
|
|
321
|
+
if ((!i || i.width === 0 && i.height === 0) && e.focusNode instanceof Element ? i = e.focusNode.getBoundingClientRect() : (!i || i.width === 0 && i.height === 0) && e.focusNode?.parentElement && (i = e.focusNode.parentElement.getBoundingClientRect()), !i) return;
|
|
322
|
+
const s = this.editorContainer.getBoundingClientRect(), r = 12;
|
|
323
|
+
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);
|
|
324
|
+
}
|
|
285
325
|
// Destroy the view
|
|
286
326
|
destroy() {
|
|
287
327
|
this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
|
|
288
328
|
}
|
|
289
329
|
}
|
|
290
|
-
class
|
|
330
|
+
const $ = class M {
|
|
291
331
|
constructor(e, t = {}) {
|
|
292
|
-
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.expectingProgrammaticCursor = !1, this.config = {
|
|
332
|
+
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 = {
|
|
293
333
|
value: "",
|
|
294
334
|
theme: "default",
|
|
295
335
|
readOnly: !1,
|
|
@@ -297,7 +337,7 @@ class I {
|
|
|
297
337
|
lineWrapping: !1,
|
|
298
338
|
lineNumbers: !0,
|
|
299
339
|
...t
|
|
300
|
-
}, this.textModel = new H(this.config.value), this.view = new
|
|
340
|
+
}, this.textModel = new H(this.config.value), this.view = new P(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();
|
|
301
341
|
}
|
|
302
342
|
// Public accessors for extensions
|
|
303
343
|
getTextModel() {
|
|
@@ -323,20 +363,21 @@ class I {
|
|
|
323
363
|
setupEventHandlers() {
|
|
324
364
|
const e = this.view.getContentElement();
|
|
325
365
|
e.addEventListener("input", () => {
|
|
326
|
-
const t = this.view.getText(),
|
|
327
|
-
if (t !==
|
|
366
|
+
const t = this.view.getText(), i = this.textModel.getText();
|
|
367
|
+
if (t !== i) {
|
|
328
368
|
if (!this.suppressHistory) {
|
|
329
|
-
const
|
|
330
|
-
let
|
|
331
|
-
|
|
369
|
+
const s = this.getCursor().position, r = this.textModel.positionToOffset(s), o = this.getSelection();
|
|
370
|
+
let n, l;
|
|
371
|
+
o && (n = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: n, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
332
372
|
}
|
|
333
|
-
this.textModel.setText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
334
|
-
this.
|
|
335
|
-
|
|
373
|
+
this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
374
|
+
const s = this.view.getText();
|
|
375
|
+
s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
|
|
376
|
+
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
|
|
336
377
|
}
|
|
337
378
|
}), e.addEventListener("selectionchange", () => {
|
|
338
|
-
const t = this.getCursor(),
|
|
339
|
-
this.emit("cursor", t),
|
|
379
|
+
const t = this.getCursor(), i = this.getSelection();
|
|
380
|
+
this.emit("cursor", t), i && this.emit("selection", i);
|
|
340
381
|
}), e.addEventListener("keydown", (t) => {
|
|
341
382
|
if (this.emit("keydown", t), t.key === "Tab") {
|
|
342
383
|
this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
|
|
@@ -344,30 +385,34 @@ class I {
|
|
|
344
385
|
}
|
|
345
386
|
if (t.key === "Enter") {
|
|
346
387
|
if (!this.config.readOnly) {
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
349
|
-
const
|
|
350
|
-
let
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
l.
|
|
354
|
-
const c =
|
|
388
|
+
const i = window.getSelection();
|
|
389
|
+
if (i && i.rangeCount > 0) {
|
|
390
|
+
const s = this.getCursor().position, r = this.textModel.positionToOffset(s), o = this.getSelection();
|
|
391
|
+
let n, l;
|
|
392
|
+
o && (n = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end));
|
|
393
|
+
const a = o && n !== void 0 && l !== void 0 ? Math.min(n, l) : r;
|
|
394
|
+
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: r, anchorOffset: n, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
|
|
395
|
+
const c = i.getRangeAt(0);
|
|
396
|
+
c.deleteContents();
|
|
397
|
+
const g = document.createTextNode(`
|
|
355
398
|
`);
|
|
356
|
-
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
399
|
+
c.insertNode(g), c.setStartAfter(g), c.collapse(!0), i.removeAllRanges(), i.addRange(c), this.view.ensureCaretVisible();
|
|
400
|
+
const h = this.view.getText();
|
|
401
|
+
this.textModel.setText(h), this.view.syncTrailingNewlineMarkerForText(h);
|
|
402
|
+
const u = Math.min(
|
|
403
|
+
a + 1,
|
|
404
|
+
this.textModel.getText().length
|
|
405
|
+
);
|
|
406
|
+
try {
|
|
407
|
+
const d = this.textModel.offsetToPosition(u);
|
|
408
|
+
this.setCursor(d), this.view.ensureCaretVisible();
|
|
409
|
+
} catch {
|
|
410
|
+
}
|
|
411
|
+
this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
|
|
362
412
|
this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
|
|
363
413
|
try {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this.setSelection({ start: L, end: w });
|
|
367
|
-
} else {
|
|
368
|
-
const x = this.textModel.offsetToPosition(d);
|
|
369
|
-
this.setCursor(x);
|
|
370
|
-
}
|
|
414
|
+
const d = this.textModel.offsetToPosition(u);
|
|
415
|
+
this.setCursor(d), this.view.ensureCaretVisible();
|
|
371
416
|
} catch {
|
|
372
417
|
}
|
|
373
418
|
}), this.highlightTimeout = null;
|
|
@@ -377,15 +422,15 @@ class I {
|
|
|
377
422
|
t.preventDefault(), t.stopPropagation();
|
|
378
423
|
return;
|
|
379
424
|
}
|
|
380
|
-
for (const
|
|
381
|
-
if (
|
|
425
|
+
for (const i of this.extensions.values())
|
|
426
|
+
if (i.onKeyDown && i.onKeyDown(t) === !1) {
|
|
382
427
|
t.preventDefault(), t.stopPropagation();
|
|
383
428
|
return;
|
|
384
429
|
}
|
|
385
430
|
}), e.addEventListener("mousedown", (t) => {
|
|
386
431
|
this.emit("mousedown", t);
|
|
387
|
-
for (const
|
|
388
|
-
if (
|
|
432
|
+
for (const i of this.extensions.values())
|
|
433
|
+
if (i.onMouseDown && i.onMouseDown(t) === !1) {
|
|
389
434
|
t.preventDefault(), t.stopPropagation();
|
|
390
435
|
return;
|
|
391
436
|
}
|
|
@@ -412,8 +457,8 @@ class I {
|
|
|
412
457
|
}
|
|
413
458
|
// Emit events to listeners
|
|
414
459
|
emit(e, ...t) {
|
|
415
|
-
const
|
|
416
|
-
|
|
460
|
+
const i = this.eventListeners.get(e);
|
|
461
|
+
i && i.forEach((s) => s(...t));
|
|
417
462
|
}
|
|
418
463
|
// State management
|
|
419
464
|
getValue() {
|
|
@@ -461,12 +506,12 @@ class I {
|
|
|
461
506
|
"editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
|
|
462
507
|
};
|
|
463
508
|
this.view.applyTheme(t);
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
509
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
510
|
+
if (i && typeof i.setTheme == "function")
|
|
466
511
|
try {
|
|
467
|
-
|
|
468
|
-
} catch (
|
|
469
|
-
console.warn("Error applying theme to syntax-highlighting extension",
|
|
512
|
+
i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
|
|
513
|
+
} catch (s) {
|
|
514
|
+
console.warn("Error applying theme to syntax-highlighting extension", s);
|
|
470
515
|
}
|
|
471
516
|
}
|
|
472
517
|
setReadOnly(e) {
|
|
@@ -483,8 +528,8 @@ class I {
|
|
|
483
528
|
t && t.destroy && t.destroy(), this.extensions.delete(e);
|
|
484
529
|
}
|
|
485
530
|
executeCommand(e, ...t) {
|
|
486
|
-
const
|
|
487
|
-
|
|
531
|
+
const i = this.commands.get(e);
|
|
532
|
+
i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
|
|
488
533
|
}
|
|
489
534
|
// Register a command
|
|
490
535
|
registerCommand(e, t) {
|
|
@@ -492,51 +537,51 @@ class I {
|
|
|
492
537
|
}
|
|
493
538
|
// Search & Navigation
|
|
494
539
|
search(e, t = {}) {
|
|
495
|
-
const
|
|
540
|
+
const i = {
|
|
496
541
|
caseSensitive: !1,
|
|
497
542
|
regex: !1,
|
|
498
543
|
...t
|
|
499
|
-
},
|
|
544
|
+
}, s = [], r = this.getValue();
|
|
500
545
|
r.split(`
|
|
501
546
|
`);
|
|
502
|
-
let
|
|
503
|
-
if (
|
|
504
|
-
const
|
|
505
|
-
let
|
|
506
|
-
for (; (
|
|
507
|
-
const c = this.textModel.offsetToPosition(
|
|
508
|
-
|
|
547
|
+
let o = i.caseSensitive ? r : r.toLowerCase(), n = i.caseSensitive ? e : e.toLowerCase();
|
|
548
|
+
if (i.regex) {
|
|
549
|
+
const l = new RegExp(n, i.caseSensitive ? "g" : "gi");
|
|
550
|
+
let a;
|
|
551
|
+
for (; (a = l.exec(o)) !== null; ) {
|
|
552
|
+
const c = this.textModel.offsetToPosition(a.index), g = this.textModel.offsetToPosition(a.index + a[0].length);
|
|
553
|
+
s.push({
|
|
509
554
|
range: { start: c, end: g },
|
|
510
|
-
match:
|
|
555
|
+
match: a[0]
|
|
511
556
|
});
|
|
512
557
|
}
|
|
513
558
|
} else {
|
|
514
|
-
let
|
|
515
|
-
for (;
|
|
516
|
-
const c =
|
|
517
|
-
|
|
518
|
-
range: { start: g, end:
|
|
519
|
-
match: r.substring(
|
|
520
|
-
}),
|
|
559
|
+
let l = 0, a = o.indexOf(n, l);
|
|
560
|
+
for (; a !== -1; ) {
|
|
561
|
+
const c = a + e.length, g = this.textModel.offsetToPosition(a), h = this.textModel.offsetToPosition(c);
|
|
562
|
+
s.push({
|
|
563
|
+
range: { start: g, end: h },
|
|
564
|
+
match: r.substring(a, c)
|
|
565
|
+
}), l = c, a = o.indexOf(n, l);
|
|
521
566
|
}
|
|
522
567
|
}
|
|
523
|
-
return
|
|
568
|
+
return s;
|
|
524
569
|
}
|
|
525
570
|
replace(e, t) {
|
|
526
|
-
const
|
|
571
|
+
const i = this.getValue();
|
|
527
572
|
if (!this.suppressHistory) {
|
|
528
|
-
const r = this.getCursor().position,
|
|
529
|
-
let
|
|
530
|
-
|
|
573
|
+
const r = this.getCursor().position, o = this.textModel.positionToOffset(r), n = this.getSelection();
|
|
574
|
+
let l, a;
|
|
575
|
+
n && (l = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: i, cursorOffset: o, anchorOffset: l, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
|
|
531
576
|
}
|
|
532
|
-
const
|
|
533
|
-
this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [
|
|
577
|
+
const s = this.textModel.replaceRange(e, t);
|
|
578
|
+
this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [s]);
|
|
534
579
|
}
|
|
535
|
-
replaceAll(e, t,
|
|
536
|
-
const
|
|
580
|
+
replaceAll(e, t, i = {}) {
|
|
581
|
+
const s = this.search(e, i);
|
|
537
582
|
let r = 0;
|
|
538
|
-
for (let
|
|
539
|
-
this.replace(
|
|
583
|
+
for (let o = s.length - 1; o >= 0; o--)
|
|
584
|
+
this.replace(s[o].range, t), r++;
|
|
540
585
|
return r;
|
|
541
586
|
}
|
|
542
587
|
// Folding (basic implementation)
|
|
@@ -569,35 +614,84 @@ class I {
|
|
|
569
614
|
// and restores it after updating the DOM. Callers that will explicitly set the caret
|
|
570
615
|
// should pass `false` to avoid stomping programmatic cursor changes.
|
|
571
616
|
renderTextWithHighlight(e, t = !0) {
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
617
|
+
const i = this.extensions.get("syntax-highlighting");
|
|
618
|
+
if (i && typeof i.highlightHTML == "function")
|
|
574
619
|
try {
|
|
575
|
-
const
|
|
576
|
-
let r,
|
|
577
|
-
if (t ||
|
|
620
|
+
const s = !t && !this.expectingProgrammaticCursor;
|
|
621
|
+
let r, o, n, l;
|
|
622
|
+
if (t || s) {
|
|
578
623
|
r = this.getSelection();
|
|
579
|
-
const
|
|
580
|
-
|
|
624
|
+
const h = this.getCollapsedSelectionOffsetInEditor();
|
|
625
|
+
if (h !== void 0)
|
|
626
|
+
o = h;
|
|
627
|
+
else {
|
|
628
|
+
const u = this.getCursor().position;
|
|
629
|
+
o = this.textModel.positionToOffset(u);
|
|
630
|
+
}
|
|
631
|
+
r && (n = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end));
|
|
581
632
|
}
|
|
582
|
-
const
|
|
583
|
-
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(
|
|
633
|
+
const a = (t || s) && !r && o !== void 0 && this.hasCollapsedSelectionInEditor(), c = a ? this.insertSentinelAtOffset(e, o) : e, g = i.highlightHTML(c);
|
|
634
|
+
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(g) : this.view.setHTML(g), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
|
|
584
635
|
try {
|
|
585
|
-
if (
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
this.
|
|
636
|
+
if (a && this.restoreCursorFromSentinel()) {
|
|
637
|
+
this.view.ensureCaretVisible();
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (r && (n !== void 0 || l !== void 0)) {
|
|
641
|
+
const h = n !== void 0 ? n : o, u = l !== void 0 ? l : o, d = Math.min(h, u), f = Math.max(h, u), m = this.textModel.offsetToPosition(d), y = this.textModel.offsetToPosition(f);
|
|
642
|
+
this.view.setSelectionRange({ start: m, end: y });
|
|
643
|
+
} else if (o !== void 0) {
|
|
644
|
+
const h = this.textModel.offsetToPosition(o);
|
|
645
|
+
this.view.setCursorPosition(h);
|
|
591
646
|
}
|
|
592
647
|
} catch {
|
|
593
648
|
}
|
|
594
649
|
});
|
|
595
650
|
return;
|
|
596
|
-
} catch (
|
|
597
|
-
console.warn("Syntax highlighting failed, falling back to plain text",
|
|
651
|
+
} catch (s) {
|
|
652
|
+
console.warn("Syntax highlighting failed, falling back to plain text", s);
|
|
598
653
|
}
|
|
599
654
|
this.view.setText(e);
|
|
600
655
|
}
|
|
656
|
+
hasCollapsedSelectionInEditor() {
|
|
657
|
+
const e = window.getSelection();
|
|
658
|
+
if (!e || e.rangeCount === 0 || !e.isCollapsed)
|
|
659
|
+
return !1;
|
|
660
|
+
const t = e.getRangeAt(0);
|
|
661
|
+
return this.view.getContentElement().contains(t.commonAncestorContainer);
|
|
662
|
+
}
|
|
663
|
+
getCollapsedSelectionOffsetInEditor() {
|
|
664
|
+
const e = window.getSelection();
|
|
665
|
+
if (!e || e.rangeCount === 0 || !e.isCollapsed)
|
|
666
|
+
return;
|
|
667
|
+
const t = e.getRangeAt(0), i = this.view.getContentElement();
|
|
668
|
+
if (!i.contains(t.commonAncestorContainer))
|
|
669
|
+
return;
|
|
670
|
+
const s = t.cloneRange();
|
|
671
|
+
return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
|
|
672
|
+
}
|
|
673
|
+
stripVirtualMarkers(e) {
|
|
674
|
+
return e.replace(/\u200B/g, "").split(M.CURSOR_SENTINEL).join("");
|
|
675
|
+
}
|
|
676
|
+
insertSentinelAtOffset(e, t) {
|
|
677
|
+
const i = Math.max(0, Math.min(t, e.length));
|
|
678
|
+
return e.slice(0, i) + M.CURSOR_SENTINEL + e.slice(i);
|
|
679
|
+
}
|
|
680
|
+
restoreCursorFromSentinel() {
|
|
681
|
+
const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
|
|
682
|
+
let s = i.nextNode(), r = null, o = 0;
|
|
683
|
+
for (; s; ) {
|
|
684
|
+
const n = s.textContent ?? "", l = n.indexOf(M.CURSOR_SENTINEL);
|
|
685
|
+
l !== -1 && (r || (r = s, o = l), s.textContent = n.split(M.CURSOR_SENTINEL).join("")), s = i.nextNode();
|
|
686
|
+
}
|
|
687
|
+
if (!r || !t) return !1;
|
|
688
|
+
try {
|
|
689
|
+
const n = document.createRange();
|
|
690
|
+
return n.setStart(r, o), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
|
|
691
|
+
} catch {
|
|
692
|
+
return !1;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
601
695
|
destroy() {
|
|
602
696
|
if (!this.isDestroyed) {
|
|
603
697
|
this.isDestroyed = !0;
|
|
@@ -613,15 +707,15 @@ class I {
|
|
|
613
707
|
this.redoStack.push(t);
|
|
614
708
|
try {
|
|
615
709
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
616
|
-
let
|
|
617
|
-
typeof e == "string" ?
|
|
710
|
+
let i, s;
|
|
711
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
618
712
|
try {
|
|
619
|
-
if (
|
|
713
|
+
if (s != null)
|
|
620
714
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
621
|
-
const r = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
622
|
-
this.setSelection({ start:
|
|
715
|
+
const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, o = e.focusOffset !== void 0 ? e.focusOffset : s, n = Math.min(r, o), l = Math.max(r, o), a = this.textModel.offsetToPosition(n), c = this.textModel.offsetToPosition(l);
|
|
716
|
+
this.setSelection({ start: a, end: c });
|
|
623
717
|
} else {
|
|
624
|
-
const r = this.textModel.offsetToPosition(
|
|
718
|
+
const r = this.textModel.offsetToPosition(s);
|
|
625
719
|
this.setCursor(r);
|
|
626
720
|
}
|
|
627
721
|
} catch {
|
|
@@ -639,15 +733,15 @@ class I {
|
|
|
639
733
|
this.undoStack.push(t);
|
|
640
734
|
try {
|
|
641
735
|
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
|
|
642
|
-
let
|
|
643
|
-
typeof e == "string" ?
|
|
736
|
+
let i, s;
|
|
737
|
+
typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
|
|
644
738
|
try {
|
|
645
|
-
if (
|
|
739
|
+
if (s != null)
|
|
646
740
|
if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
|
|
647
|
-
const r = e.anchorOffset !== void 0 ? e.anchorOffset :
|
|
648
|
-
this.setSelection({ start:
|
|
741
|
+
const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, o = e.focusOffset !== void 0 ? e.focusOffset : s, n = Math.min(r, o), l = Math.max(r, o), a = this.textModel.offsetToPosition(n), c = this.textModel.offsetToPosition(l);
|
|
742
|
+
this.setSelection({ start: a, end: c });
|
|
649
743
|
} else {
|
|
650
|
-
const r = this.textModel.offsetToPosition(
|
|
744
|
+
const r = this.textModel.offsetToPosition(s);
|
|
651
745
|
this.setCursor(r);
|
|
652
746
|
}
|
|
653
747
|
} catch {
|
|
@@ -662,29 +756,29 @@ class I {
|
|
|
662
756
|
// Insert a tab character or spaces at current cursor
|
|
663
757
|
insertTab() {
|
|
664
758
|
if (this.config.readOnly) return;
|
|
665
|
-
const e = this.getCursor().position, t = this.textModel.positionToOffset(e),
|
|
759
|
+
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);
|
|
666
760
|
if (!this.suppressHistory) {
|
|
667
|
-
const
|
|
668
|
-
let
|
|
669
|
-
|
|
761
|
+
const o = this.getSelection();
|
|
762
|
+
let n, l;
|
|
763
|
+
o && (n = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: n, focusOffset: l }), this.redoStack.length = 0;
|
|
670
764
|
}
|
|
671
765
|
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(r), setTimeout(() => {
|
|
672
766
|
this.expectingProgrammaticCursor = !1;
|
|
673
|
-
}, 20), this.emit("change", [
|
|
767
|
+
}, 20), this.emit("change", [s]);
|
|
674
768
|
}
|
|
675
769
|
// Insert a newline at current cursor position
|
|
676
770
|
insertNewLine() {
|
|
677
771
|
if (this.config.readOnly) return;
|
|
678
|
-
const e = this.getCursor().position, t = this.textModel.positionToOffset(e),
|
|
679
|
-
`),
|
|
772
|
+
const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
|
|
773
|
+
`), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
|
|
680
774
|
if (!this.suppressHistory) {
|
|
681
775
|
const r = this.getSelection();
|
|
682
|
-
let
|
|
683
|
-
r && (
|
|
776
|
+
let o, n;
|
|
777
|
+
r && (o = this.textModel.positionToOffset(r.start), n = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: n }), this.redoStack.length = 0;
|
|
684
778
|
}
|
|
685
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(
|
|
779
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
|
|
686
780
|
this.expectingProgrammaticCursor = !1;
|
|
687
|
-
}, 20), this.emit("change", [
|
|
781
|
+
}, 20), this.emit("change", [i]);
|
|
688
782
|
}
|
|
689
783
|
// Events
|
|
690
784
|
on(e, t) {
|
|
@@ -692,15 +786,17 @@ class I {
|
|
|
692
786
|
}
|
|
693
787
|
off(e, t) {
|
|
694
788
|
if (!this.eventListeners.has(e)) return;
|
|
695
|
-
const
|
|
789
|
+
const i = this.eventListeners.get(e);
|
|
696
790
|
if (t) {
|
|
697
|
-
const
|
|
698
|
-
|
|
791
|
+
const s = i.indexOf(t);
|
|
792
|
+
s !== -1 && i.splice(s, 1);
|
|
699
793
|
} else
|
|
700
|
-
|
|
794
|
+
i.length = 0;
|
|
701
795
|
}
|
|
702
|
-
}
|
|
703
|
-
|
|
796
|
+
};
|
|
797
|
+
$.CURSOR_SENTINEL = "";
|
|
798
|
+
let A = $;
|
|
799
|
+
class B {
|
|
704
800
|
constructor(e) {
|
|
705
801
|
this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
|
|
706
802
|
}
|
|
@@ -714,12 +810,12 @@ class N {
|
|
|
714
810
|
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
|
|
715
811
|
}
|
|
716
812
|
findMatchingBinding(e) {
|
|
717
|
-
const { key: t, ctrlKey:
|
|
718
|
-
if (!
|
|
719
|
-
for (const
|
|
720
|
-
const c =
|
|
721
|
-
if (c && g &&
|
|
722
|
-
return
|
|
813
|
+
const { key: t, ctrlKey: i, altKey: s, shiftKey: r, metaKey: o } = e, n = String(t).toLowerCase(), l = this.keymap[n];
|
|
814
|
+
if (!l) return null;
|
|
815
|
+
for (const a of l) {
|
|
816
|
+
const c = a.ctrlKey === void 0 || a.ctrlKey === i, g = a.altKey === void 0 || a.altKey === s, h = a.shiftKey === void 0 || a.shiftKey === r, u = a.metaKey === void 0 || a.metaKey === o;
|
|
817
|
+
if (c && g && h && u)
|
|
818
|
+
return a;
|
|
723
819
|
}
|
|
724
820
|
return null;
|
|
725
821
|
}
|
|
@@ -731,12 +827,12 @@ class N {
|
|
|
731
827
|
const e = {};
|
|
732
828
|
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;
|
|
733
829
|
}
|
|
734
|
-
addBinding(e, t,
|
|
830
|
+
addBinding(e, t, i, s) {
|
|
735
831
|
const r = t.toLowerCase();
|
|
736
832
|
e[r] || (e[r] = []), e[r].push({
|
|
737
833
|
key: r,
|
|
738
|
-
command:
|
|
739
|
-
...
|
|
834
|
+
command: s,
|
|
835
|
+
...i
|
|
740
836
|
});
|
|
741
837
|
}
|
|
742
838
|
// Public API for customizing keymap
|
|
@@ -745,23 +841,23 @@ class N {
|
|
|
745
841
|
}
|
|
746
842
|
addKeyBinding(e) {
|
|
747
843
|
const t = e.key.toLowerCase();
|
|
748
|
-
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((
|
|
844
|
+
this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
|
|
749
845
|
...e,
|
|
750
846
|
key: t
|
|
751
847
|
});
|
|
752
848
|
}
|
|
753
849
|
removeKeyBinding(e, t) {
|
|
754
|
-
const
|
|
755
|
-
t ? this.keymap[
|
|
850
|
+
const i = e.toLowerCase();
|
|
851
|
+
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];
|
|
756
852
|
}
|
|
757
853
|
getKeymap() {
|
|
758
854
|
return { ...this.keymap };
|
|
759
855
|
}
|
|
760
856
|
getBindingsForCommand(e) {
|
|
761
857
|
const t = [];
|
|
762
|
-
for (const
|
|
763
|
-
for (const
|
|
764
|
-
|
|
858
|
+
for (const i in this.keymap)
|
|
859
|
+
for (const s of this.keymap[i])
|
|
860
|
+
s.command === e && t.push({ ...s });
|
|
765
861
|
return t;
|
|
766
862
|
}
|
|
767
863
|
getPlatformInfo() {
|
|
@@ -774,19 +870,19 @@ class N {
|
|
|
774
870
|
this.keymap = {}, this.editor = null;
|
|
775
871
|
}
|
|
776
872
|
}
|
|
777
|
-
class
|
|
873
|
+
class V {
|
|
778
874
|
constructor() {
|
|
779
875
|
this.name = "transaction", this.transactions = [];
|
|
780
876
|
}
|
|
781
877
|
setup(e) {
|
|
782
878
|
e.on("change", (t) => {
|
|
783
|
-
const
|
|
784
|
-
changes:
|
|
879
|
+
const i = {
|
|
880
|
+
changes: t,
|
|
785
881
|
selection: e.getSelection(),
|
|
786
882
|
effects: [],
|
|
787
883
|
annotations: []
|
|
788
884
|
};
|
|
789
|
-
this.transactions.push(
|
|
885
|
+
this.transactions.push(i);
|
|
790
886
|
});
|
|
791
887
|
}
|
|
792
888
|
getTransactions() {
|
|
@@ -815,10 +911,11 @@ class K {
|
|
|
815
911
|
updateLineNumbers() {
|
|
816
912
|
if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
|
|
817
913
|
const e = this.editor.getValue().split(`
|
|
818
|
-
`).length, t = Array.from({ length: Math.max(e, 20) }, (
|
|
819
|
-
this.lineNumbersElement.innerHTML = t.map((
|
|
914
|
+
`).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
|
|
915
|
+
this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("");
|
|
820
916
|
}
|
|
821
917
|
toggle() {
|
|
918
|
+
if (!this.editor) return;
|
|
822
919
|
this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
|
|
823
920
|
const e = this.editor.getView().getContentElement();
|
|
824
921
|
e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
|
|
@@ -827,7 +924,7 @@ class K {
|
|
|
827
924
|
this.lineNumbersElement = null, this.editor = null;
|
|
828
925
|
}
|
|
829
926
|
}
|
|
830
|
-
class
|
|
927
|
+
class U {
|
|
831
928
|
constructor() {
|
|
832
929
|
this.name = "theme", this.editor = null, this.currentTheme = "dark";
|
|
833
930
|
}
|
|
@@ -852,7 +949,7 @@ class A {
|
|
|
852
949
|
this.editor = null;
|
|
853
950
|
}
|
|
854
951
|
}
|
|
855
|
-
class
|
|
952
|
+
class z {
|
|
856
953
|
constructor() {
|
|
857
954
|
this.name = "read-only", this.editor = null, this.isReadOnly = !1;
|
|
858
955
|
}
|
|
@@ -879,7 +976,7 @@ class V {
|
|
|
879
976
|
this.editor = null;
|
|
880
977
|
}
|
|
881
978
|
}
|
|
882
|
-
class
|
|
979
|
+
class q {
|
|
883
980
|
constructor() {
|
|
884
981
|
this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1;
|
|
885
982
|
}
|
|
@@ -892,8 +989,8 @@ class U {
|
|
|
892
989
|
this.findPrev();
|
|
893
990
|
}), e.registerCommand("replace", () => {
|
|
894
991
|
this.showReplace();
|
|
895
|
-
}), e.registerCommand("replaceAll", (t,
|
|
896
|
-
this.replaceAll(t,
|
|
992
|
+
}), e.registerCommand("replaceAll", (t, i) => {
|
|
993
|
+
this.replaceAll(t, i);
|
|
897
994
|
});
|
|
898
995
|
}
|
|
899
996
|
showSearch() {
|
|
@@ -987,35 +1084,35 @@ class U {
|
|
|
987
1084
|
margin-top: 4px;
|
|
988
1085
|
" />
|
|
989
1086
|
`;
|
|
990
|
-
const t = this.searchUI.querySelector("input"),
|
|
1087
|
+
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"), o = this.searchUI.querySelector(".search-close");
|
|
991
1088
|
t.addEventListener("input", () => {
|
|
992
1089
|
this.performSearch(t.value);
|
|
993
|
-
}), t.addEventListener("keydown", (
|
|
994
|
-
|
|
995
|
-
}),
|
|
996
|
-
|
|
997
|
-
}),
|
|
1090
|
+
}), t.addEventListener("keydown", (n) => {
|
|
1091
|
+
n.key === "Enter" && (n.preventDefault(), n.shiftKey ? this.findPrev() : this.findNext());
|
|
1092
|
+
}), i.addEventListener("keydown", (n) => {
|
|
1093
|
+
n.key === "Enter" && (n.preventDefault(), n.shiftKey ? this.replaceAll(t.value, i.value) : this.replaceCurrent(t.value, i.value));
|
|
1094
|
+
}), s.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), o.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
|
|
998
1095
|
}
|
|
999
1096
|
performSearch(e) {
|
|
1000
1097
|
if (!this.editor || !e.trim()) {
|
|
1001
1098
|
this.clearHighlights(), this.updateStatus("");
|
|
1002
1099
|
return;
|
|
1003
1100
|
}
|
|
1004
|
-
const t = this.editor.getValue(),
|
|
1005
|
-
let
|
|
1006
|
-
for (;
|
|
1007
|
-
const r = this.getPositionFromOffset(t,
|
|
1008
|
-
|
|
1009
|
-
range: { start: r, end:
|
|
1010
|
-
match: t.substring(
|
|
1011
|
-
}),
|
|
1101
|
+
const t = this.editor.getValue(), i = [];
|
|
1102
|
+
let s = t.toLowerCase().indexOf(e.toLowerCase());
|
|
1103
|
+
for (; s !== -1; ) {
|
|
1104
|
+
const r = this.getPositionFromOffset(t, s), o = this.getPositionFromOffset(t, s + e.length);
|
|
1105
|
+
i.push({
|
|
1106
|
+
range: { start: r, end: o },
|
|
1107
|
+
match: t.substring(s, s + e.length)
|
|
1108
|
+
}), s = t.toLowerCase().indexOf(e.toLowerCase(), s + 1);
|
|
1012
1109
|
}
|
|
1013
|
-
this.currentResults =
|
|
1110
|
+
this.currentResults = i, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
|
|
1014
1111
|
}
|
|
1015
1112
|
getPositionFromOffset(e, t) {
|
|
1016
|
-
const
|
|
1017
|
-
`),
|
|
1018
|
-
return { line:
|
|
1113
|
+
const i = e.substring(0, t).split(`
|
|
1114
|
+
`), s = i.length - 1, r = i[i.length - 1].length;
|
|
1115
|
+
return { line: s, column: r };
|
|
1019
1116
|
}
|
|
1020
1117
|
findNext() {
|
|
1021
1118
|
this.currentResults.length !== 0 && (this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights());
|
|
@@ -1025,25 +1122,25 @@ class U {
|
|
|
1025
1122
|
}
|
|
1026
1123
|
replaceCurrent(e, t) {
|
|
1027
1124
|
if (!this.editor || !e.trim() || this.currentIndex === -1) return;
|
|
1028
|
-
const
|
|
1029
|
-
if (!
|
|
1030
|
-
const
|
|
1031
|
-
this.editor.setValue(
|
|
1125
|
+
const i = this.currentResults[this.currentIndex];
|
|
1126
|
+
if (!i) return;
|
|
1127
|
+
const s = this.editor.getValue(), r = this.getOffsetFromPosition(s, i.range.start), o = s.substring(0, r), n = s.substring(r + e.length), l = o + t + n;
|
|
1128
|
+
this.editor.setValue(l), this.performSearch(e), this.updateStatus("Replaced current occurrence");
|
|
1032
1129
|
}
|
|
1033
1130
|
replaceAll(e, t) {
|
|
1034
1131
|
if (!this.editor || !e.trim()) return;
|
|
1035
|
-
let
|
|
1132
|
+
let i = this.editor.getValue(), s = 0, r = i.toLowerCase().indexOf(e.toLowerCase());
|
|
1036
1133
|
for (; r !== -1; )
|
|
1037
|
-
|
|
1038
|
-
|
|
1134
|
+
i = i.substring(0, r) + t + i.substring(r + e.length), s++, r = i.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
|
|
1135
|
+
s > 0 && (this.editor.setValue(i), this.updateStatus(`Replaced ${s} occurrences`));
|
|
1039
1136
|
}
|
|
1040
1137
|
getOffsetFromPosition(e, t) {
|
|
1041
|
-
const
|
|
1138
|
+
const i = e.split(`
|
|
1042
1139
|
`);
|
|
1043
|
-
let
|
|
1140
|
+
let s = 0;
|
|
1044
1141
|
for (let r = 0; r < t.line; r++)
|
|
1045
|
-
|
|
1046
|
-
return
|
|
1142
|
+
s += i[r].length + 1;
|
|
1143
|
+
return s += t.column, s;
|
|
1047
1144
|
}
|
|
1048
1145
|
updateHighlights() {
|
|
1049
1146
|
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})`));
|
|
@@ -1058,7 +1155,7 @@ class U {
|
|
|
1058
1155
|
this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.searchUI = null, this.editor = null;
|
|
1059
1156
|
}
|
|
1060
1157
|
}
|
|
1061
|
-
class
|
|
1158
|
+
class F {
|
|
1062
1159
|
constructor() {
|
|
1063
1160
|
this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
|
|
1064
1161
|
"(": ")",
|
|
@@ -1083,58 +1180,58 @@ class z {
|
|
|
1083
1180
|
if (!this.editor) return;
|
|
1084
1181
|
const e = this.editor.getCursor(), t = this.editor.getValue();
|
|
1085
1182
|
this.clearBracketHighlighting();
|
|
1086
|
-
const
|
|
1087
|
-
if (!
|
|
1088
|
-
const
|
|
1089
|
-
|
|
1183
|
+
const i = this.getBracketAtPosition(t, e.position);
|
|
1184
|
+
if (!i) return;
|
|
1185
|
+
const s = this.findMatchingBracket(t, i);
|
|
1186
|
+
s && (this.currentMatch = s, this.highlightBrackets(s));
|
|
1090
1187
|
}
|
|
1091
1188
|
getBracketAtPosition(e, t) {
|
|
1092
|
-
const
|
|
1189
|
+
const i = e.split(`
|
|
1093
1190
|
`);
|
|
1094
|
-
if (t.line >=
|
|
1095
|
-
const
|
|
1096
|
-
if (t.column >=
|
|
1097
|
-
const r =
|
|
1191
|
+
if (t.line >= i.length) return null;
|
|
1192
|
+
const s = i[t.line];
|
|
1193
|
+
if (t.column >= s.length) return null;
|
|
1194
|
+
const r = s[t.column];
|
|
1098
1195
|
return this.bracketPairs[r] || this.reverseBracketPairs[r] ? { char: r, position: t } : null;
|
|
1099
1196
|
}
|
|
1100
1197
|
findMatchingBracket(e, t) {
|
|
1101
|
-
const
|
|
1102
|
-
`),
|
|
1103
|
-
return this.bracketPairs[
|
|
1104
|
-
}
|
|
1105
|
-
findClosingBracket(e, t,
|
|
1106
|
-
const
|
|
1107
|
-
let
|
|
1108
|
-
for (let
|
|
1109
|
-
const
|
|
1110
|
-
for (let g = c; g <
|
|
1111
|
-
const
|
|
1112
|
-
if (
|
|
1113
|
-
|
|
1114
|
-
else if (
|
|
1198
|
+
const i = e.split(`
|
|
1199
|
+
`), s = t.position.line, r = t.position.column, o = t.char;
|
|
1200
|
+
return this.bracketPairs[o] ? this.findClosingBracket(e, i, s, r, o) : this.reverseBracketPairs[o] ? this.findOpeningBracket(e, i, s, r, o) : null;
|
|
1201
|
+
}
|
|
1202
|
+
findClosingBracket(e, t, i, s, r) {
|
|
1203
|
+
const o = this.bracketPairs[r];
|
|
1204
|
+
let n = 0;
|
|
1205
|
+
for (let l = i; l < t.length; l++) {
|
|
1206
|
+
const a = t[l], c = l === i ? s : 0;
|
|
1207
|
+
for (let g = c; g < a.length; g++) {
|
|
1208
|
+
const h = a[g];
|
|
1209
|
+
if (h === r)
|
|
1210
|
+
n++;
|
|
1211
|
+
else if (h === o && (n--, n === 0))
|
|
1115
1212
|
return {
|
|
1116
|
-
open: { start: { line:
|
|
1117
|
-
close: { start: { line:
|
|
1213
|
+
open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1214
|
+
close: { start: { line: l, column: g }, end: { line: l, column: g + 1 } },
|
|
1118
1215
|
type: r
|
|
1119
1216
|
};
|
|
1120
1217
|
}
|
|
1121
1218
|
}
|
|
1122
1219
|
return null;
|
|
1123
1220
|
}
|
|
1124
|
-
findOpeningBracket(e, t,
|
|
1125
|
-
const
|
|
1126
|
-
let
|
|
1127
|
-
for (let
|
|
1128
|
-
const
|
|
1221
|
+
findOpeningBracket(e, t, i, s, r) {
|
|
1222
|
+
const o = this.reverseBracketPairs[r];
|
|
1223
|
+
let n = 0;
|
|
1224
|
+
for (let l = i; l >= 0; l--) {
|
|
1225
|
+
const a = t[l], c = l === i ? s : a.length - 1;
|
|
1129
1226
|
for (let g = c; g >= 0; g--) {
|
|
1130
|
-
const
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
else if (
|
|
1227
|
+
const h = a[g];
|
|
1228
|
+
if (h === r)
|
|
1229
|
+
n++;
|
|
1230
|
+
else if (h === o && (n--, n === 0))
|
|
1134
1231
|
return {
|
|
1135
|
-
open: { start: { line:
|
|
1136
|
-
close: { start: { line:
|
|
1137
|
-
type:
|
|
1232
|
+
open: { start: { line: l, column: g }, end: { line: l, column: g + 1 } },
|
|
1233
|
+
close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
|
|
1234
|
+
type: o
|
|
1138
1235
|
};
|
|
1139
1236
|
}
|
|
1140
1237
|
}
|
|
@@ -1152,7 +1249,7 @@ class z {
|
|
|
1152
1249
|
this.clearBracketHighlighting(), this.editor = null;
|
|
1153
1250
|
}
|
|
1154
1251
|
}
|
|
1155
|
-
class
|
|
1252
|
+
class _ {
|
|
1156
1253
|
constructor() {
|
|
1157
1254
|
this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;
|
|
1158
1255
|
}
|
|
@@ -1193,9 +1290,9 @@ class q {
|
|
|
1193
1290
|
}
|
|
1194
1291
|
findFoldableLines(e) {
|
|
1195
1292
|
const t = [];
|
|
1196
|
-
for (let
|
|
1197
|
-
const
|
|
1198
|
-
(
|
|
1293
|
+
for (let i = 0; i < e.length; i++) {
|
|
1294
|
+
const s = e[i].trim();
|
|
1295
|
+
(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);
|
|
1199
1296
|
}
|
|
1200
1297
|
return t;
|
|
1201
1298
|
}
|
|
@@ -1231,12 +1328,12 @@ class q {
|
|
|
1231
1328
|
this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.foldingUI = null, this.foldIndicators = [], this.editor = null;
|
|
1232
1329
|
}
|
|
1233
1330
|
}
|
|
1234
|
-
class
|
|
1331
|
+
class W {
|
|
1235
1332
|
constructor() {
|
|
1236
1333
|
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
|
|
1237
1334
|
}
|
|
1238
1335
|
setup(e) {
|
|
1239
|
-
this.editor = e, this.registerMode("html", { name: "html", highlight: (t,
|
|
1336
|
+
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) });
|
|
1240
1337
|
}
|
|
1241
1338
|
// Extension provides methods that can be called by the editor
|
|
1242
1339
|
setTheme(e) {
|
|
@@ -1296,8 +1393,8 @@ class _ {
|
|
|
1296
1393
|
}
|
|
1297
1394
|
// Public API: highlight a source string using the chosen mode (or detect html)
|
|
1298
1395
|
highlight(e, t) {
|
|
1299
|
-
const
|
|
1300
|
-
return (this.modes.get(
|
|
1396
|
+
const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
|
|
1397
|
+
return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
|
|
1301
1398
|
}
|
|
1302
1399
|
// Backwards-compatible method
|
|
1303
1400
|
highlightHTML(e) {
|
|
@@ -1310,124 +1407,127 @@ class _ {
|
|
|
1310
1407
|
// Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;...
|
|
1311
1408
|
unescapeEntitiesRepeated(e) {
|
|
1312
1409
|
let t = e || "";
|
|
1313
|
-
for (let
|
|
1314
|
-
const
|
|
1315
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t ===
|
|
1410
|
+
for (let i = 0; i < 5; i++) {
|
|
1411
|
+
const s = t;
|
|
1412
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === s) break;
|
|
1316
1413
|
}
|
|
1317
1414
|
return t;
|
|
1318
1415
|
}
|
|
1319
1416
|
_highlightHTML(e, t) {
|
|
1320
|
-
const
|
|
1321
|
-
let r =
|
|
1322
|
-
const
|
|
1323
|
-
let c =
|
|
1324
|
-
return c = c.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${
|
|
1325
|
-
const m = String(
|
|
1326
|
-
return `<span style="color: ${
|
|
1417
|
+
const i = t, s = (a) => this.escapeHTML(a);
|
|
1418
|
+
let r = s(e);
|
|
1419
|
+
const o = (a) => {
|
|
1420
|
+
let c = a.replace(/"/g, '"').replace(/'/g, "'");
|
|
1421
|
+
return c = c.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), c = c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (g, h, u, d, f) => {
|
|
1422
|
+
const m = String(d).trim(), y = s(m);
|
|
1423
|
+
return `<span style="color: ${i.styleProp};">${h}</span>${u}<span style="color: ${i.styleVal};">${y}</span>${f}`;
|
|
1327
1424
|
}), c;
|
|
1328
|
-
},
|
|
1425
|
+
}, n = [];
|
|
1329
1426
|
try {
|
|
1330
|
-
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (
|
|
1427
|
+
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (a, c, g) => (n.push({ attrs: String(c || ""), inner: String(g || "") }), a));
|
|
1331
1428
|
} catch {
|
|
1332
1429
|
}
|
|
1333
|
-
let
|
|
1334
|
-
return r = r.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (
|
|
1335
|
-
const
|
|
1336
|
-
(
|
|
1337
|
-
const f = this._highlightJS(
|
|
1430
|
+
let l = 0;
|
|
1431
|
+
return r = r.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (a, c, g, h, u) => {
|
|
1432
|
+
const d = n[l++]?.inner ?? this.unescapeEntitiesRepeated(h || "");
|
|
1433
|
+
(n[l - 1]?.attrs || g || "").toLowerCase();
|
|
1434
|
+
const f = this._highlightJS(d, i);
|
|
1338
1435
|
return `${c}${f}${u}`;
|
|
1339
|
-
}), r = r.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (
|
|
1340
|
-
const u =
|
|
1341
|
-
return `${c}${u}${
|
|
1342
|
-
}), r = r.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${
|
|
1343
|
-
const
|
|
1344
|
-
let f =
|
|
1345
|
-
return f = f.replace(
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1436
|
+
}), r = r.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (a, c, g, h) => {
|
|
1437
|
+
const u = o(g);
|
|
1438
|
+
return `${c}${u}${h}`;
|
|
1439
|
+
}), r = r.replace(/(<!--[\s\S]*?-->)/g, `<span style="color: ${i.comment};">$1</span>`), r = r.replace(/(<!DOCTYPE[\s\S]*?>)/i, `<span style="color: ${i.doctype};">$1</span>`), r = r.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g, (a, c, g, h, u) => {
|
|
1440
|
+
const d = `<span style="color: ${i.tag};">${g}</span>`;
|
|
1441
|
+
let f = h;
|
|
1442
|
+
return f = f.replace(
|
|
1443
|
+
/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,
|
|
1444
|
+
(m, y, w, x) => {
|
|
1445
|
+
const E = String(y).toLowerCase(), L = `<span style="color: ${i.attrName};">${y}</span>`;
|
|
1446
|
+
let C = x, b = "";
|
|
1447
|
+
x.startsWith(""") && x.endsWith(""") ? (C = x.slice(6, -6), b = """) : x.startsWith("'") && x.endsWith("'") && (C = x.slice(5, -5), b = "'");
|
|
1448
|
+
let k = x;
|
|
1449
|
+
if (E === "style") {
|
|
1450
|
+
const S = C.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (O, p, T, N) => `<span style="color: ${i.styleProp};">${p}</span>:<span style="color: ${i.styleVal};">${T.trim()}</span>${N}`);
|
|
1451
|
+
b ? k = `${b}${S}${b}` : k = S, k = `<span style="color: ${i.attrValue};">${k}</span>`;
|
|
1452
|
+
} else
|
|
1453
|
+
b && (k = `${b}${C}${b}`), k = `<span style="color: ${i.attrValue};">${k}</span>`;
|
|
1454
|
+
return `${L}${w}${k}`;
|
|
1455
|
+
}
|
|
1456
|
+
), `${c}${d}${f}${u}`;
|
|
1357
1457
|
}), r;
|
|
1358
1458
|
}
|
|
1359
1459
|
_highlightJS(e, t) {
|
|
1360
|
-
const
|
|
1361
|
-
this.escapeHTML(
|
|
1362
|
-
const
|
|
1363
|
-
let u = "",
|
|
1460
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
1461
|
+
this.escapeHTML(i);
|
|
1462
|
+
const s = [], r = (h) => {
|
|
1463
|
+
let u = "", d = h;
|
|
1364
1464
|
do
|
|
1365
|
-
u = String.fromCharCode(97 +
|
|
1366
|
-
while (
|
|
1465
|
+
u = String.fromCharCode(97 + d % 26) + u, d = Math.floor(d / 26) - 1;
|
|
1466
|
+
while (d >= 0);
|
|
1367
1467
|
return u || "a";
|
|
1368
|
-
},
|
|
1369
|
-
const u =
|
|
1370
|
-
return
|
|
1468
|
+
}, o = (h) => `\0${r(h)}\0`, n = (h) => {
|
|
1469
|
+
const u = s.length;
|
|
1470
|
+
return s.push(h), o(u);
|
|
1371
1471
|
};
|
|
1372
|
-
let
|
|
1373
|
-
const
|
|
1472
|
+
let l;
|
|
1473
|
+
const a = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
1374
1474
|
let c = 0, g = "";
|
|
1375
|
-
for (;
|
|
1376
|
-
const
|
|
1377
|
-
c <
|
|
1378
|
-
const u =
|
|
1379
|
-
/^\/\*/.test(u) || /^\/\//.test(u) ? g +=
|
|
1475
|
+
for (; l = a.exec(i); ) {
|
|
1476
|
+
const h = l.index;
|
|
1477
|
+
c < h && (g += this.escapeHTML(i.slice(c, h)));
|
|
1478
|
+
const u = l[0];
|
|
1479
|
+
/^\/\*/.test(u) || /^\/\//.test(u) ? g += n(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`) : g += n(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`), c = a.lastIndex;
|
|
1380
1480
|
}
|
|
1381
|
-
return c <
|
|
1382
|
-
const f = g[
|
|
1383
|
-
return f === "&" || f === "#" || m === ";" || m === "#" ?
|
|
1384
|
-
}), g = g.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>`), g.replace(/\u0000([a-z]+)\u0000/g, (
|
|
1385
|
-
let
|
|
1481
|
+
return c < i.length && (g += this.escapeHTML(i.slice(c))), g = g.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (h, u, d) => {
|
|
1482
|
+
const f = g[d - 1] || "", m = g[d + h.length] || "";
|
|
1483
|
+
return f === "&" || f === "#" || m === ";" || m === "#" ? h : `<span style="color: ${t.number};">${h}</span>`;
|
|
1484
|
+
}), g = g.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>`), g.replace(/\u0000([a-z]+)\u0000/g, (h, u) => {
|
|
1485
|
+
let d = 0;
|
|
1386
1486
|
for (let f = 0; f < u.length; f++)
|
|
1387
|
-
|
|
1388
|
-
return
|
|
1487
|
+
d = d * 26 + (u.charCodeAt(f) - 97 + 1);
|
|
1488
|
+
return d = d - 1, s[d] || "";
|
|
1389
1489
|
});
|
|
1390
1490
|
}
|
|
1391
1491
|
_highlightPHP(e, t) {
|
|
1392
|
-
const
|
|
1393
|
-
let
|
|
1394
|
-
const r = [],
|
|
1395
|
-
let f = "", m =
|
|
1492
|
+
const i = this.unescapeEntitiesRepeated(e);
|
|
1493
|
+
let s = this.escapeHTML(i);
|
|
1494
|
+
const r = [], o = (d) => {
|
|
1495
|
+
let f = "", m = d;
|
|
1396
1496
|
do
|
|
1397
1497
|
f = String.fromCharCode(97 + m % 26) + f, m = Math.floor(m / 26) - 1;
|
|
1398
1498
|
while (m >= 0);
|
|
1399
1499
|
return f || "a";
|
|
1400
|
-
},
|
|
1500
|
+
}, n = (d) => {
|
|
1401
1501
|
const f = r.length;
|
|
1402
|
-
return r.push(
|
|
1403
|
-
},
|
|
1404
|
-
const m =
|
|
1405
|
-
return m === -1 ? !1 : (
|
|
1502
|
+
return r.push(d), `\0${o(f)}\0`;
|
|
1503
|
+
}, l = (d, f) => {
|
|
1504
|
+
const m = s.indexOf(d);
|
|
1505
|
+
return m === -1 ? !1 : (s = s.slice(0, m) + f + s.slice(m + d.length), !0);
|
|
1406
1506
|
};
|
|
1407
|
-
let
|
|
1408
|
-
const c = /\/\*[\s\S]*?\*\//g, g = /\/\/[^\n\r]*/g,
|
|
1409
|
-
for (;
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1507
|
+
let a;
|
|
1508
|
+
const c = /\/\*[\s\S]*?\*\//g, g = /\/\/[^\n\r]*/g, h = /\#([^\n\r]*)/g, u = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
1509
|
+
for (; a = c.exec(i); ) {
|
|
1510
|
+
const d = a[0];
|
|
1511
|
+
l(this.escapeHTML(d), n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
|
|
1412
1512
|
}
|
|
1413
|
-
for (;
|
|
1414
|
-
const
|
|
1415
|
-
|
|
1513
|
+
for (; a = g.exec(i); ) {
|
|
1514
|
+
const d = a[0];
|
|
1515
|
+
l(this.escapeHTML(d), n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
|
|
1416
1516
|
}
|
|
1417
|
-
for (;
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1517
|
+
for (; a = h.exec(i); ) {
|
|
1518
|
+
const d = a[0];
|
|
1519
|
+
l(this.escapeHTML(d), n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
|
|
1420
1520
|
}
|
|
1421
|
-
for (;
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1521
|
+
for (; a = u.exec(i); ) {
|
|
1522
|
+
const d = a[0];
|
|
1523
|
+
l(this.escapeHTML(d), n(`<span style="color: ${t.string};">${this.escapeHTML(d)}</span>`));
|
|
1424
1524
|
}
|
|
1425
|
-
return
|
|
1525
|
+
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, (d, f) => {
|
|
1426
1526
|
let m = 0;
|
|
1427
|
-
for (let
|
|
1428
|
-
m = m * 26 + (f.charCodeAt(
|
|
1527
|
+
for (let y = 0; y < f.length; y++)
|
|
1528
|
+
m = m * 26 + (f.charCodeAt(y) - 97 + 1);
|
|
1429
1529
|
return m = m - 1, r[m] || "";
|
|
1430
|
-
}),
|
|
1530
|
+
}), s;
|
|
1431
1531
|
}
|
|
1432
1532
|
// Method to check if content contains syntax that should be highlighted
|
|
1433
1533
|
shouldHighlight(e) {
|
|
@@ -1437,11 +1537,11 @@ class _ {
|
|
|
1437
1537
|
this.editor = null, this.modes.clear();
|
|
1438
1538
|
}
|
|
1439
1539
|
}
|
|
1440
|
-
function
|
|
1540
|
+
function D(v, e) {
|
|
1441
1541
|
const t = { ...e };
|
|
1442
|
-
return t.extensions || (t.extensions = []), t.extensions.some((
|
|
1542
|
+
return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new B(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new V()), new A(v, t);
|
|
1443
1543
|
}
|
|
1444
|
-
const
|
|
1544
|
+
const R = '[data-theme="dark"], .dark, .editora-theme-dark', j = `/* Source Editor Dialog Styles */
|
|
1445
1545
|
.rte-source-editor-overlay {
|
|
1446
1546
|
position: fixed !important;
|
|
1447
1547
|
top: 0 !important;
|
|
@@ -1818,15 +1918,15 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
1818
1918
|
flex: 1;
|
|
1819
1919
|
text-align: center;
|
|
1820
1920
|
}
|
|
1821
|
-
}`,
|
|
1921
|
+
}`, Z = () => ({
|
|
1822
1922
|
name: "code",
|
|
1823
1923
|
// Toolbar button configuration
|
|
1824
1924
|
toolbar: [
|
|
1825
1925
|
{
|
|
1826
1926
|
label: "Source",
|
|
1827
1927
|
command: "toggleSourceView",
|
|
1828
|
-
type: "button",
|
|
1829
|
-
icon: "
|
|
1928
|
+
// type: "button",
|
|
1929
|
+
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>',
|
|
1830
1930
|
shortcut: "Mod-Shift-S"
|
|
1831
1931
|
}
|
|
1832
1932
|
],
|
|
@@ -1840,52 +1940,58 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
1840
1940
|
const e = (() => {
|
|
1841
1941
|
const r = window.getSelection();
|
|
1842
1942
|
if (r && r.anchorNode) {
|
|
1843
|
-
let
|
|
1844
|
-
for (;
|
|
1845
|
-
if (
|
|
1846
|
-
return
|
|
1847
|
-
|
|
1943
|
+
let n = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
|
|
1944
|
+
for (; n; ) {
|
|
1945
|
+
if (n.classList?.contains("rte-content"))
|
|
1946
|
+
return n;
|
|
1947
|
+
n = n.parentElement;
|
|
1848
1948
|
}
|
|
1849
1949
|
}
|
|
1850
1950
|
if (document.activeElement) {
|
|
1851
|
-
let
|
|
1852
|
-
if (
|
|
1853
|
-
return
|
|
1854
|
-
for (;
|
|
1855
|
-
if (
|
|
1856
|
-
return
|
|
1857
|
-
const
|
|
1858
|
-
|
|
1859
|
-
|
|
1951
|
+
let n = document.activeElement;
|
|
1952
|
+
if (n.classList?.contains("rte-content"))
|
|
1953
|
+
return n;
|
|
1954
|
+
for (; n && n !== document.body; ) {
|
|
1955
|
+
if (n.classList?.contains("rte-content"))
|
|
1956
|
+
return n;
|
|
1957
|
+
const l = n.querySelector(
|
|
1958
|
+
".rte-content"
|
|
1959
|
+
);
|
|
1960
|
+
if (l) return l;
|
|
1961
|
+
n = n.parentElement;
|
|
1860
1962
|
}
|
|
1861
1963
|
}
|
|
1862
|
-
const
|
|
1863
|
-
if (
|
|
1864
|
-
const
|
|
1865
|
-
|
|
1964
|
+
const o = document.querySelector("[data-editora-editor]");
|
|
1965
|
+
if (o) {
|
|
1966
|
+
const n = o.querySelector(
|
|
1967
|
+
".rte-content"
|
|
1968
|
+
);
|
|
1969
|
+
if (n) return n;
|
|
1866
1970
|
}
|
|
1867
1971
|
return document.querySelector(".rte-content");
|
|
1868
1972
|
})();
|
|
1869
1973
|
if (!e)
|
|
1870
|
-
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
` + " ".repeat(
|
|
1879
|
-
|
|
1974
|
+
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
1975
|
+
"Editor content area not found. Please click inside the editor first."
|
|
1976
|
+
), !1;
|
|
1977
|
+
const t = e.innerHTML, i = (r) => {
|
|
1978
|
+
let o = "", n = 0;
|
|
1979
|
+
const l = 2, a = r.split(/(<\/?[a-zA-Z][^>]*>)/);
|
|
1980
|
+
for (const c of a)
|
|
1981
|
+
c.trim() && (c.match(/^<\/[a-zA-Z]/) ? (n = Math.max(0, n - 1), o += `
|
|
1982
|
+
` + " ".repeat(n * l) + c) : c.match(/^<[a-zA-Z]/) && !c.match(/\/>$/) ? (o += `
|
|
1983
|
+
` + " ".repeat(n * l) + c, n++) : c.match(/^<[a-zA-Z].*\/>$/) ? o += `
|
|
1984
|
+
` + " ".repeat(n * l) + c : o += c.trim());
|
|
1985
|
+
return o.trim();
|
|
1880
1986
|
};
|
|
1881
1987
|
return (() => {
|
|
1882
|
-
let r = null,
|
|
1883
|
-
const c = t, g = !!e.closest(
|
|
1884
|
-
|
|
1988
|
+
let r = null, o = "dark", n = !1, l = !1, a = !1;
|
|
1989
|
+
const c = t, g = !!e.closest(R) || document.body.matches(R) || document.documentElement.matches(R), h = document.createElement("div");
|
|
1990
|
+
h.className = "rte-source-editor-overlay", g && h.classList.add("rte-theme-dark");
|
|
1885
1991
|
const u = document.createElement("div");
|
|
1886
1992
|
u.className = "rte-source-editor-modal", u.setAttribute("role", "dialog"), u.setAttribute("aria-modal", "true"), u.setAttribute("aria-labelledby", "source-editor-title");
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1993
|
+
const d = document.createElement("div");
|
|
1994
|
+
d.className = "rte-source-editor-header", d.innerHTML = `
|
|
1889
1995
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
1890
1996
|
<div class="rte-source-editor-header-toolbar">
|
|
1891
1997
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -1926,12 +2032,12 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
1926
2032
|
f.className = "rte-source-editor-body";
|
|
1927
2033
|
const m = document.createElement("div");
|
|
1928
2034
|
m.className = "rte-source-editor-content";
|
|
1929
|
-
const x = document.createElement("div");
|
|
1930
|
-
x.className = "rte-source-editor-warning", x.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
|
|
1931
|
-
const k = document.createElement("div");
|
|
1932
|
-
k.className = "rte-source-editor-light-editor", k.style.height = "400px", m.appendChild(x), m.appendChild(k), f.appendChild(m);
|
|
1933
2035
|
const y = document.createElement("div");
|
|
1934
|
-
|
|
2036
|
+
y.className = "rte-source-editor-warning", y.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
|
|
2037
|
+
const w = document.createElement("div");
|
|
2038
|
+
w.className = "rte-source-editor-light-editor", w.style.height = "400px", m.appendChild(y), m.appendChild(w), f.appendChild(m);
|
|
2039
|
+
const x = document.createElement("div");
|
|
2040
|
+
if (x.className = "rte-source-editor-footer", x.innerHTML = `
|
|
1935
2041
|
<div class="rte-source-editor-footer-info">
|
|
1936
2042
|
<span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
|
|
1937
2043
|
</div>
|
|
@@ -1939,45 +2045,47 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
1939
2045
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
1940
2046
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
1941
2047
|
</div>
|
|
1942
|
-
`, u.appendChild(
|
|
2048
|
+
`, u.appendChild(d), u.appendChild(f), u.appendChild(x), h.appendChild(u), !document.getElementById("rte-source-editor-styles")) {
|
|
1943
2049
|
const p = document.createElement("style");
|
|
1944
|
-
p.id = "rte-source-editor-styles", p.textContent =
|
|
2050
|
+
p.id = "rte-source-editor-styles", p.textContent = j, document.head.appendChild(p);
|
|
1945
2051
|
}
|
|
1946
|
-
document.body.appendChild(
|
|
2052
|
+
document.body.appendChild(h);
|
|
1947
2053
|
try {
|
|
1948
|
-
r =
|
|
1949
|
-
value:
|
|
2054
|
+
r = D(w, {
|
|
2055
|
+
value: i(t),
|
|
1950
2056
|
theme: "dark",
|
|
1951
2057
|
readOnly: !1,
|
|
1952
2058
|
extensions: [
|
|
1953
2059
|
new K(),
|
|
1954
|
-
new A(),
|
|
1955
|
-
new V(),
|
|
1956
|
-
new z(),
|
|
1957
2060
|
new U(),
|
|
2061
|
+
new z(),
|
|
2062
|
+
new F(),
|
|
1958
2063
|
new q(),
|
|
1959
|
-
new _()
|
|
2064
|
+
new _(),
|
|
2065
|
+
new W()
|
|
1960
2066
|
]
|
|
1961
2067
|
}), r.on("change", () => {
|
|
1962
|
-
|
|
1963
|
-
const
|
|
1964
|
-
|
|
2068
|
+
a = (r?.getValue() || "") !== i(c);
|
|
2069
|
+
const T = x.querySelector(
|
|
2070
|
+
".unsaved-changes"
|
|
2071
|
+
);
|
|
2072
|
+
T && (T.style.display = a ? "inline" : "none");
|
|
1965
2073
|
}), setTimeout(() => r?.focus(), 100);
|
|
1966
2074
|
} catch (p) {
|
|
1967
2075
|
console.error("Failed to initialize code editor:", p);
|
|
1968
2076
|
}
|
|
1969
|
-
const
|
|
1970
|
-
|
|
1971
|
-
const p =
|
|
1972
|
-
p &&
|
|
2077
|
+
const E = () => {
|
|
2078
|
+
o = o === "dark" ? "light" : "dark", r?.setTheme(o);
|
|
2079
|
+
const p = d.querySelector(".theme-toggle-btn");
|
|
2080
|
+
p && o === "light" && (p.innerHTML = `
|
|
1973
2081
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1974
2082
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
1975
2083
|
</svg>
|
|
1976
2084
|
`);
|
|
1977
2085
|
}, L = () => {
|
|
1978
|
-
|
|
1979
|
-
const p =
|
|
1980
|
-
p && (
|
|
2086
|
+
n = !n, r?.setReadOnly(n);
|
|
2087
|
+
const p = d.querySelector(".readonly-toggle-btn");
|
|
2088
|
+
p && (n ? (p.classList.add("active"), p.innerHTML = `
|
|
1981
2089
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1982
2090
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
1983
2091
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -1989,10 +2097,12 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
1989
2097
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
1990
2098
|
</svg>
|
|
1991
2099
|
`));
|
|
1992
|
-
},
|
|
1993
|
-
|
|
1994
|
-
const p =
|
|
1995
|
-
|
|
2100
|
+
}, C = () => {
|
|
2101
|
+
l = !l, l ? (h.classList.add("fullscreen"), w.style.height = "calc(100vh - 200px)") : (h.classList.remove("fullscreen"), w.style.height = "400px");
|
|
2102
|
+
const p = d.querySelector(
|
|
2103
|
+
".rte-source-editor-fullscreen-btn"
|
|
2104
|
+
);
|
|
2105
|
+
p && (p.innerHTML = l ? `
|
|
1996
2106
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1997
2107
|
<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"/>
|
|
1998
2108
|
</svg>
|
|
@@ -2002,24 +2112,44 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
2002
2112
|
</svg>
|
|
2003
2113
|
`);
|
|
2004
2114
|
}, b = () => {
|
|
2005
|
-
r && (r.destroy(), r = null), document.body.removeChild(
|
|
2006
|
-
},
|
|
2007
|
-
|
|
2115
|
+
r && (r.destroy(), r = null), document.body.removeChild(h);
|
|
2116
|
+
}, k = () => {
|
|
2117
|
+
a && !confirm(
|
|
2118
|
+
"You have unsaved changes. Are you sure you want to cancel?"
|
|
2119
|
+
) || b();
|
|
2008
2120
|
}, S = () => {
|
|
2009
2121
|
try {
|
|
2010
|
-
const p = r?.getValue() || "",
|
|
2011
|
-
|
|
2122
|
+
const p = r?.getValue() || "", T = document.createElement("div");
|
|
2123
|
+
T.innerHTML = p, T.querySelectorAll(
|
|
2124
|
+
'script, iframe[src^="javascript:"], object, embed'
|
|
2125
|
+
).forEach((I) => I.remove()), e.innerHTML = T.innerHTML;
|
|
2126
|
+
try {
|
|
2127
|
+
e.dispatchEvent(
|
|
2128
|
+
new InputEvent("input", {
|
|
2129
|
+
bubbles: !0,
|
|
2130
|
+
cancelable: !1,
|
|
2131
|
+
inputType: "insertReplacementText"
|
|
2132
|
+
})
|
|
2133
|
+
);
|
|
2134
|
+
} catch {
|
|
2135
|
+
e.dispatchEvent(
|
|
2136
|
+
new Event("input", { bubbles: !0 })
|
|
2137
|
+
);
|
|
2138
|
+
}
|
|
2139
|
+
e.dispatchEvent(
|
|
2140
|
+
new Event("change", { bubbles: !0 })
|
|
2141
|
+
), a = !1, b();
|
|
2012
2142
|
} catch (p) {
|
|
2013
2143
|
alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", p);
|
|
2014
2144
|
}
|
|
2015
2145
|
};
|
|
2016
|
-
|
|
2017
|
-
p.target ===
|
|
2146
|
+
d.querySelector(".theme-toggle-btn")?.addEventListener("click", E), d.querySelector(".readonly-toggle-btn")?.addEventListener("click", L), d.querySelector(".rte-source-editor-fullscreen-btn")?.addEventListener("click", C), d.querySelector(".rte-source-editor-close-btn")?.addEventListener("click", b), x.querySelector(".rte-source-editor-btn-cancel")?.addEventListener("click", k), x.querySelector(".rte-source-editor-btn-save")?.addEventListener("click", S), h.addEventListener("click", (p) => {
|
|
2147
|
+
p.target === h && b();
|
|
2018
2148
|
});
|
|
2019
|
-
const
|
|
2020
|
-
p.key === "Escape" && (b(), document.removeEventListener("keydown",
|
|
2149
|
+
const O = (p) => {
|
|
2150
|
+
p.key === "Escape" && (b(), document.removeEventListener("keydown", O));
|
|
2021
2151
|
};
|
|
2022
|
-
document.addEventListener("keydown",
|
|
2152
|
+
document.addEventListener("keydown", O);
|
|
2023
2153
|
})(), !0;
|
|
2024
2154
|
}
|
|
2025
2155
|
},
|
|
@@ -2030,5 +2160,5 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
|
|
|
2030
2160
|
}
|
|
2031
2161
|
});
|
|
2032
2162
|
export {
|
|
2033
|
-
|
|
2163
|
+
Z as CodePlugin
|
|
2034
2164
|
};
|