@cocoar/vue-script-editor 1.9.0-script-editor.4

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/index.js ADDED
@@ -0,0 +1,693 @@
1
+ import { computed as e, createElementBlock as t, defineComponent as n, inject as r, normalizeClass as i, normalizeStyle as a, onBeforeUnmount as o, openBlock as s, ref as c, shallowRef as l, useId as u, watch as d } from "vue";
2
+ import * as f from "monaco-editor";
3
+ //#region src/theme.ts
4
+ var p = "coar-light", m = "coar-dark", h = !1;
5
+ function g(e) {
6
+ h ||= (e.editor.defineTheme(p, {
7
+ base: "vs",
8
+ inherit: !0,
9
+ rules: [],
10
+ colors: {
11
+ "editor.background": "#ffffff",
12
+ "editor.foreground": "#1a1a1a",
13
+ "editorLineNumber.foreground": "#9ca3af",
14
+ "editorLineNumber.activeForeground": "#1a1a1a",
15
+ "editor.selectionBackground": "#dbeafe",
16
+ "editor.inactiveSelectionBackground": "#e5e7eb",
17
+ "editorCursor.foreground": "#1a1a1a",
18
+ "editor.lineHighlightBackground": "#f3f4f6",
19
+ "editorIndentGuide.background": "#e5e7eb",
20
+ "editorGutter.background": "#ffffff"
21
+ }
22
+ }), e.editor.defineTheme(m, {
23
+ base: "vs-dark",
24
+ inherit: !0,
25
+ rules: [],
26
+ colors: {
27
+ "editor.background": "#1a1a1a",
28
+ "editor.foreground": "#f3f4f6",
29
+ "editorLineNumber.foreground": "#6b7280",
30
+ "editorLineNumber.activeForeground": "#f3f4f6",
31
+ "editor.selectionBackground": "#1e40af",
32
+ "editor.inactiveSelectionBackground": "#374151",
33
+ "editorCursor.foreground": "#f3f4f6",
34
+ "editor.lineHighlightBackground": "#262626",
35
+ "editorIndentGuide.background": "#374151",
36
+ "editorGutter.background": "#1a1a1a"
37
+ }
38
+ }), !0);
39
+ }
40
+ function _() {
41
+ if (typeof document > "u") return p;
42
+ let e = document.documentElement, t = document.body;
43
+ if (e?.classList.contains("dark-mode") || t?.classList.contains("dark-mode") || e?.classList.contains("dark") || t?.classList.contains("dark")) return m;
44
+ if (e?.classList.contains("light-mode") || t?.classList.contains("light-mode")) return p;
45
+ let n = e?.getAttribute("data-theme") ?? t?.getAttribute("data-theme");
46
+ return n === "dark" ? m : n === "light" ? p : typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches ? m : p;
47
+ }
48
+ function v(e) {
49
+ return e === "light" ? p : e === "dark" ? m : _();
50
+ }
51
+ function y(e) {
52
+ if (typeof window > "u" || typeof document > "u") return () => {};
53
+ let t = window.matchMedia?.("(prefers-color-scheme: dark)"), n = () => e();
54
+ t?.addEventListener?.("change", n);
55
+ let r = new MutationObserver(() => e()), i = [document.documentElement, document.body].filter(Boolean);
56
+ for (let e of i) r.observe(e, {
57
+ attributes: !0,
58
+ attributeFilter: ["class", "data-theme"]
59
+ });
60
+ return () => {
61
+ t?.removeEventListener?.("change", n), r.disconnect();
62
+ };
63
+ }
64
+ //#endregion
65
+ //#region src/composables/useMonacoEditor.ts
66
+ function b() {
67
+ try {
68
+ if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
69
+ } catch {}
70
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
71
+ }
72
+ var x = {
73
+ typescript: "ts",
74
+ javascript: "js",
75
+ json: "json"
76
+ }, S = [
77
+ 1375,
78
+ 2695,
79
+ 1108,
80
+ 7027,
81
+ 2304,
82
+ 1208
83
+ ], C = {
84
+ editor: {
85
+ lineNumbers: "on",
86
+ glyphMargin: !0,
87
+ folding: !0,
88
+ lineDecorationsWidth: 10,
89
+ lineNumbersMinChars: 3,
90
+ renderLineHighlight: "line",
91
+ contextmenu: !0,
92
+ overviewRulerLanes: 3,
93
+ overviewRulerBorder: !0,
94
+ hideCursorInOverviewRuler: !1,
95
+ scrollbar: {
96
+ vertical: "auto",
97
+ horizontal: "auto"
98
+ },
99
+ padding: {
100
+ top: 0,
101
+ bottom: 0
102
+ },
103
+ wordWrap: "off"
104
+ },
105
+ inline: {
106
+ lineNumbers: "off",
107
+ glyphMargin: !1,
108
+ folding: !1,
109
+ lineDecorationsWidth: 0,
110
+ lineNumbersMinChars: 0,
111
+ renderLineHighlight: "none",
112
+ contextmenu: !1,
113
+ overviewRulerLanes: 0,
114
+ overviewRulerBorder: !1,
115
+ hideCursorInOverviewRuler: !0,
116
+ scrollbar: {
117
+ vertical: "auto",
118
+ horizontal: "hidden",
119
+ verticalScrollbarSize: 8
120
+ },
121
+ padding: {
122
+ top: 8,
123
+ bottom: 8
124
+ },
125
+ wordWrap: "on"
126
+ }
127
+ };
128
+ function w(e) {
129
+ return e ? `${e}\n` : "";
130
+ }
131
+ function T(e) {
132
+ return e ? e.split("\n").length : 0;
133
+ }
134
+ function E(e, t) {
135
+ return t ? w(t) + e : e;
136
+ }
137
+ function D(e, t) {
138
+ if (!t) return e;
139
+ let n = w(t);
140
+ return e.startsWith(n) ? e.slice(n.length) : e;
141
+ }
142
+ function O(e, t) {
143
+ let n = T(t), r = n === 0 ? [] : [new f.Range(1, 1, n, 2 ** 53 - 1)];
144
+ e.setHiddenAreas(r);
145
+ }
146
+ function k(e, t) {
147
+ if (!t || e !== "typescript" && e !== "javascript") return;
148
+ let n = e === "javascript" ? f.languages.typescript.javascriptDefaults : f.languages.typescript.typescriptDefaults, r = typeof n.getDiagnosticsOptions == "function" ? n.getDiagnosticsOptions() : {}, i = new Set(r.diagnosticCodesToIgnore ?? []);
149
+ for (let e of S) i.add(e);
150
+ n.setDiagnosticsOptions({
151
+ ...r,
152
+ diagnosticCodesToIgnore: Array.from(i)
153
+ });
154
+ }
155
+ function A(e) {
156
+ let t = l(null), n = l(null), r = !1, i = null, a = null, s = null, c = null, u = !1;
157
+ function p() {
158
+ return e.variant?.() ?? "editor";
159
+ }
160
+ function m() {
161
+ c?.(), c = null, e.theme() === "auto" && (c = y(() => {
162
+ t.value && f.editor.setTheme(v(e.theme()));
163
+ }));
164
+ }
165
+ function h() {
166
+ if (u || !e.host.value) return;
167
+ u = !0, g(f);
168
+ let o = e.language(), c = e.preamble?.() ?? "";
169
+ k(o, e.scriptMode?.() ?? !1);
170
+ let l = f.editor.createModel(E(e.initialValue(), c), o, f.Uri.parse(`file:///coar-script-editor/${b()}.${x[o]}`));
171
+ n.value = l;
172
+ let d = e.overflowWidgetsDomNode?.() ?? null, h = f.editor.create(e.host.value, {
173
+ model: l,
174
+ theme: v(e.theme()),
175
+ readOnly: e.readonly(),
176
+ minimap: { enabled: e.minimap() },
177
+ automaticLayout: !0,
178
+ scrollBeyondLastLine: !1,
179
+ fontSize: 13,
180
+ tabSize: 2,
181
+ fixedOverflowWidgets: !0,
182
+ ...C[p()],
183
+ ...d ? { overflowWidgetsDomNode: d } : {}
184
+ });
185
+ t.value = h, O(h, c), m();
186
+ let _ = !1;
187
+ i = h.onDidChangeModelContent((n) => {
188
+ let i = e.preamble?.() ?? "";
189
+ if (i && !n.isFlush && !n.isUndoing) {
190
+ let e = w(i).length;
191
+ if (n.changes.some((t) => t.rangeOffset < e)) {
192
+ h.trigger("coar-script-editor-preamble", "undo", null);
193
+ return;
194
+ }
195
+ }
196
+ r || _ || (_ = !0, queueMicrotask(() => {
197
+ if (_ = !1, !t.value) return;
198
+ let n = h.getValue();
199
+ e.onContentChange(D(n, e.preamble?.() ?? ""));
200
+ }));
201
+ }), e.onFocused && (a = h.onDidFocusEditorWidget(() => e.onFocused?.())), e.onBlurred && (s = h.onDidBlurEditorWidget(() => e.onBlurred?.())), e.autofocus?.() && queueMicrotask(() => t.value?.focus()), e.onEditorReady?.(h);
202
+ }
203
+ d(e.host, (e) => {
204
+ e && h();
205
+ }, {
206
+ immediate: !0,
207
+ flush: "post"
208
+ }), o(() => {
209
+ c?.(), c = null, i?.dispose(), i = null, a?.dispose(), a = null, s?.dispose(), s = null, t.value?.dispose(), n.value?.dispose(), t.value = null, n.value = null, u = !1;
210
+ });
211
+ function _(n) {
212
+ let i = t.value;
213
+ if (!i) return;
214
+ let a = e.preamble?.() ?? "", o = E(n, a);
215
+ if (i.getValue() !== o) {
216
+ r = !0;
217
+ try {
218
+ i.setValue(o), O(i, a);
219
+ } finally {
220
+ r = !1;
221
+ }
222
+ }
223
+ }
224
+ function S(e) {
225
+ let t = r;
226
+ r = !0;
227
+ try {
228
+ return e();
229
+ } finally {
230
+ r = t;
231
+ }
232
+ }
233
+ return d(() => e.language(), (t) => {
234
+ let r = n.value;
235
+ r && f.editor.setModelLanguage(r, t), k(t, e.scriptMode?.() ?? !1);
236
+ }), d(() => e.readonly(), (e) => t.value?.updateOptions({ readOnly: e })), d(() => e.minimap(), (e) => t.value?.updateOptions({ minimap: { enabled: e } })), e.variant && d(() => p(), (e) => t.value?.updateOptions(C[e])), e.scriptMode && d(() => e.scriptMode(), (t) => k(e.language(), t)), e.preamble && d(() => e.preamble(), (e, n) => {
237
+ let i = t.value;
238
+ if (!i) return;
239
+ let a = E(D(i.getValue(), n ?? ""), e);
240
+ r = !0;
241
+ try {
242
+ i.setValue(a), O(i, e);
243
+ } finally {
244
+ r = !1;
245
+ }
246
+ }), d(() => e.theme(), (e) => {
247
+ t.value && f.editor.setTheme(v(e)), m();
248
+ }), {
249
+ editor: t,
250
+ model: n,
251
+ setValue: _,
252
+ withSuppressedChange: S
253
+ };
254
+ }
255
+ //#endregion
256
+ //#region src/composables/useExtraLibs.ts
257
+ function j(e) {
258
+ let t = [], n = /* @__PURE__ */ new Set(), r = !1;
259
+ function i() {
260
+ for (; t.length;) t.pop()?.dispose();
261
+ let i = e.language();
262
+ if (i === "json") {
263
+ e.libs().length > 0 && !r && (r = !0, console.warn("[coar-script-editor] extraLibs has entries but language is 'json' — extraLibs are ignored for JSON. Use monaco.languages.json.jsonDefaults.setDiagnosticsOptions for JSON schema configuration."));
264
+ return;
265
+ }
266
+ let a = i === "javascript" ? f.languages.typescript.javascriptDefaults : f.languages.typescript.typescriptDefaults;
267
+ for (let r of e.libs()) !r.filePath.startsWith("file:///") && !n.has(r.filePath) && (n.add(r.filePath), console.warn(`[coar-script-editor] extraLib filePath '${r.filePath}' does not start with 'file:///' — Monaco will register it but IntelliSense may not pick it up. Prefix with 'file:///' for reliable resolution.`)), t.push(a.addExtraLib(r.content, r.filePath));
268
+ }
269
+ d([() => e.language(), () => e.libs()], () => i(), { immediate: !0 }), o(() => {
270
+ for (; t.length;) t.pop()?.dispose();
271
+ });
272
+ }
273
+ //#endregion
274
+ //#region src/constrained/LockedLineScanner.ts
275
+ var M = /\/\/\s*@locked\b/, N = "// @locked";
276
+ function P(e) {
277
+ return M.test(e);
278
+ }
279
+ function F(e) {
280
+ let t = [], n = e.length, r = 0, i = 0;
281
+ for (let a = 0; a <= n; a++) if (a === n || e[a] === "\n") {
282
+ let o = a, s = o > i && e[o - 1] === "\r" ? o - 1 : o, c = e.slice(i, s);
283
+ M.test(c) && t.push({
284
+ lineIndex: r,
285
+ lineStart: i,
286
+ lineEnd: o,
287
+ protectedStart: i,
288
+ protectedEnd: o,
289
+ snapBefore: i === 0 ? null : i - 1,
290
+ snapAfter: o >= n ? null : o + 1
291
+ }), i = a + 1, r++;
292
+ }
293
+ return t;
294
+ }
295
+ function I(e) {
296
+ if (e.length === 0) return [];
297
+ let t = [...e].sort((e, t) => e.protectedStart - t.protectedStart), n = [], r = {
298
+ start: t[0].protectedStart,
299
+ end: t[0].protectedEnd,
300
+ snapBefore: t[0].snapBefore,
301
+ snapAfter: t[0].snapAfter
302
+ };
303
+ for (let e = 1; e < t.length; e++) {
304
+ let i = t[e];
305
+ i.protectedStart <= r.end + 1 ? (r.end = Math.max(r.end, i.protectedEnd), r.snapAfter = i.snapAfter) : (n.push(r), r = {
306
+ start: i.protectedStart,
307
+ end: i.protectedEnd,
308
+ snapBefore: i.snapBefore,
309
+ snapAfter: i.snapAfter
310
+ });
311
+ }
312
+ return n.push(r), n;
313
+ }
314
+ function L(e, t) {
315
+ return e.rangeStart <= t.end && e.rangeEnd >= t.start;
316
+ }
317
+ function R(e, t) {
318
+ return t.some((t) => L(e, t));
319
+ }
320
+ function z(e, t) {
321
+ for (let n of t) if (e >= n.start && e <= n.end) {
322
+ let t = n.snapBefore, r = n.snapAfter;
323
+ return t == null && r == null ? 0 : t == null ? r : r == null || e - t < r - e ? t : r;
324
+ }
325
+ return e;
326
+ }
327
+ function B(e) {
328
+ return F(e).length;
329
+ }
330
+ function V(e) {
331
+ return U(e).every((e) => e.trim().length > 0);
332
+ }
333
+ function H(e) {
334
+ let t = F(e), n = U(e), r = [];
335
+ return t.length > 0 && t[0].lineIndex === 0 && r.push("Source starts with a locked line — there is no space above for auto-import or helpers."), t.length > 0 && n.every((e) => e.length === 0) && r.push("Source has locked lines but no editable space between or around them."), {
336
+ ok: r.length === 0,
337
+ lockedLineCount: t.length,
338
+ segmentCount: n.length,
339
+ warnings: r
340
+ };
341
+ }
342
+ function U(e) {
343
+ let t = F(e);
344
+ if (t.length === 0) return [e];
345
+ let n = new Set(t.map((e) => e.lineIndex)), r = e.split("\n"), i = [], a = [];
346
+ for (let e = 0; e < r.length; e++) n.has(e) ? a.length > 0 || i.length === 0 ? (i.push(a.join("\n")), a = []) : i.push("") : a.push(r[e]);
347
+ return i.push(a.join("\n")), i;
348
+ }
349
+ //#endregion
350
+ //#region src/constrained/ChangeGuard.ts
351
+ var W = class {
352
+ disposables = [];
353
+ lockedLines;
354
+ protectedRanges;
355
+ constructor(e, t, n = {}) {
356
+ this.editor = e, this.authoring = t, this.callbacks = n;
357
+ let r = e.getModel();
358
+ if (!r) throw Error("ChangeGuard requires the editor to have an attached model");
359
+ this.lockedLines = F(r.getValue()), this.protectedRanges = I(this.lockedLines), this.disposables.push(r.onDidChangeContent((e) => this.handleChange(e)));
360
+ }
361
+ dispose() {
362
+ for (; this.disposables.length;) this.disposables.pop()?.dispose();
363
+ }
364
+ getLockedLines() {
365
+ return this.lockedLines;
366
+ }
367
+ getProtectedRanges() {
368
+ return this.protectedRanges;
369
+ }
370
+ refresh() {
371
+ let e = this.editor.getModel();
372
+ e && (this.lockedLines = F(e.getValue()), this.protectedRanges = I(this.lockedLines), this.callbacks.onLinesUpdated?.(this.lockedLines));
373
+ }
374
+ handleChange(e) {
375
+ let t = this.editor.getModel();
376
+ if (!t) return;
377
+ let n = e.isFlush || e.isUndoing || this.authoring();
378
+ if (e.isFlush && t.pushStackElement(), !n) {
379
+ let t = e.changes.find((e) => R({
380
+ rangeStart: e.rangeOffset,
381
+ rangeEnd: e.rangeOffset + e.rangeLength
382
+ }, this.protectedRanges));
383
+ if (t) {
384
+ this.editor.trigger("coar-script-editor-guard", "undo", null), this.callbacks.onReject?.({
385
+ reason: "edit-overlaps-locked-line",
386
+ range: {
387
+ startLineNumber: t.range.startLineNumber,
388
+ endLineNumber: t.range.endLineNumber
389
+ }
390
+ });
391
+ return;
392
+ }
393
+ }
394
+ this.lockedLines = F(t.getValue()), this.protectedRanges = I(this.lockedLines), this.callbacks.onLinesUpdated?.(this.lockedLines), this.callbacks.onContentChanged?.(t.getValue());
395
+ }
396
+ }, G = class {
397
+ disposables = [];
398
+ correcting = !1;
399
+ constructor(e, t, n) {
400
+ this.editor = e, this.getRanges = t, this.authoring = n, this.disposables.push(e.onDidChangeCursorSelection(() => this.handleSelectionChange()));
401
+ }
402
+ dispose() {
403
+ for (; this.disposables.length;) this.disposables.pop()?.dispose();
404
+ }
405
+ snapCurrent() {
406
+ this.handleSelectionChange();
407
+ }
408
+ handleSelectionChange() {
409
+ if (this.correcting || this.authoring()) return;
410
+ let e = this.editor.getModel();
411
+ if (!e) return;
412
+ let t = this.editor.getSelections();
413
+ if (!t || t.length === 0) return;
414
+ let n = this.getRanges();
415
+ if (n.length === 0) return;
416
+ let r = t[0].constructor, i = [], a = !1;
417
+ for (let o of t) {
418
+ let t = e.getOffsetAt(o.getStartPosition()), s = e.getOffsetAt(o.getEndPosition()), c = z(t, n), l = z(s, n);
419
+ if (c === t && l === s) {
420
+ i.push(o);
421
+ continue;
422
+ }
423
+ let u = e.getPositionAt(c), d = e.getPositionAt(l), f = c === l ? new r(u.lineNumber, u.column, u.lineNumber, u.column) : new r(u.lineNumber, u.column, d.lineNumber, d.column);
424
+ i.push(f), a = !0;
425
+ }
426
+ if (a) {
427
+ this.correcting = !0;
428
+ try {
429
+ this.editor.setSelections(i);
430
+ } finally {
431
+ this.correcting = !1;
432
+ }
433
+ }
434
+ }
435
+ }, K = class {
436
+ disposables = [];
437
+ filtering = !1;
438
+ constructor(e, t) {
439
+ this.editor = e, this.authoring = t, this.disposables.push(f.editor.onDidChangeMarkers((e) => this.handleMarkerChange(e))), this.filterMarkers();
440
+ }
441
+ dispose() {
442
+ for (; this.disposables.length;) this.disposables.pop()?.dispose();
443
+ }
444
+ refresh() {
445
+ this.filterMarkers();
446
+ }
447
+ handleMarkerChange(e) {
448
+ if (this.filtering) return;
449
+ let t = this.editor.getModel();
450
+ t && e.some((e) => e.toString() === t.uri.toString()) && this.filterMarkers();
451
+ }
452
+ filterMarkers() {
453
+ if (this.authoring()) return;
454
+ let e = this.editor.getModel();
455
+ if (!e) return;
456
+ let t = e.getValue(), n = new Set(F(t).map((e) => e.lineIndex + 1));
457
+ if (n.size === 0) return;
458
+ let r = f.editor.getModelMarkers({ resource: e.uri });
459
+ if (r.length === 0) return;
460
+ let i = /* @__PURE__ */ new Map();
461
+ for (let e of r) {
462
+ if (!e.owner) continue;
463
+ let t = i.get(e.owner) ?? [];
464
+ t.push(e), i.set(e.owner, t);
465
+ }
466
+ this.filtering = !0;
467
+ try {
468
+ for (let [t, r] of i) {
469
+ let i = r.filter((e) => e.severity === f.MarkerSeverity.Error ? !n.has(e.startLineNumber) : !0);
470
+ if (i.length !== r.length) {
471
+ let n = i.map((e) => ({
472
+ severity: e.severity,
473
+ code: e.code,
474
+ message: e.message,
475
+ source: e.source,
476
+ startLineNumber: e.startLineNumber,
477
+ startColumn: e.startColumn,
478
+ endLineNumber: e.endLineNumber,
479
+ endColumn: e.endColumn,
480
+ tags: e.tags,
481
+ relatedInformation: e.relatedInformation
482
+ }));
483
+ f.editor.setModelMarkers(e, t, n);
484
+ }
485
+ }
486
+ } finally {
487
+ this.filtering = !1;
488
+ }
489
+ }
490
+ }, q = "coar-script-editor-locked-line", J = "coar-script-editor-locked-marker", Y = /\/\/\s*@locked\b/g;
491
+ function X(e) {
492
+ let t = null, n = null, r = null, i = null;
493
+ function a() {
494
+ t?.dispose(), t = null, n?.dispose(), n = null, r?.dispose(), r = null, i?.clear(), i = null;
495
+ }
496
+ function s(e, t) {
497
+ let n = e.getModel();
498
+ if (!n) return;
499
+ let r = [];
500
+ for (let e of t) {
501
+ let t = e.lineIndex + 1, i = n.getLineLength(t);
502
+ r.push({
503
+ range: {
504
+ startLineNumber: t,
505
+ startColumn: 1,
506
+ endLineNumber: t,
507
+ endColumn: i + 1
508
+ },
509
+ options: {
510
+ className: q,
511
+ isWholeLine: !0,
512
+ stickiness: 1
513
+ }
514
+ });
515
+ let a = n.getLineContent(t), o = new RegExp(Y.source, "g"), s;
516
+ for (; (s = o.exec(a)) !== null;) r.push({
517
+ range: {
518
+ startLineNumber: t,
519
+ startColumn: s.index + 1,
520
+ endLineNumber: t,
521
+ endColumn: s.index + s[0].length + 1
522
+ },
523
+ options: {
524
+ inlineClassName: J,
525
+ stickiness: 1,
526
+ hoverMessage: { value: "Locked line marker" }
527
+ }
528
+ });
529
+ }
530
+ i ? i.set(r) : i = e.createDecorationsCollection(r);
531
+ }
532
+ function c(i) {
533
+ a(), i.updateOptions({
534
+ formatOnType: !1,
535
+ formatOnPaste: !1,
536
+ linkedEditing: !1
537
+ }), t = new W(i, e.authoring, {
538
+ onReject: e.onReject,
539
+ onLinesUpdated: (e) => {
540
+ s(i, e), r?.refresh();
541
+ }
542
+ }), n = new G(i, () => t?.getProtectedRanges() ?? [], e.authoring), r = new K(i, e.authoring), s(i, t.getLockedLines()), n.snapCurrent();
543
+ }
544
+ d([e.editor, () => P(e.value())], ([e, n]) => {
545
+ if (!e) {
546
+ a();
547
+ return;
548
+ }
549
+ if (!n) {
550
+ a();
551
+ return;
552
+ }
553
+ t || c(e);
554
+ }, {
555
+ immediate: !0,
556
+ flush: "post"
557
+ }), d(() => e.authoring(), (e) => {
558
+ e || n?.snapCurrent();
559
+ }), o(() => a());
560
+ }
561
+ //#endregion
562
+ //#region src/composables/useFormFieldContext.ts
563
+ var Z = Symbol.for("coar:form-field");
564
+ function Q() {
565
+ return r(Z, void 0);
566
+ }
567
+ //#endregion
568
+ //#region src/CoarScriptEditor.vue?vue&type=script&setup=true&lang.ts
569
+ var $ = [
570
+ "id",
571
+ "aria-invalid",
572
+ "aria-describedby",
573
+ "aria-disabled",
574
+ "aria-required",
575
+ "data-placeholder",
576
+ "data-name"
577
+ ], ee = /* @__PURE__ */ n({
578
+ __name: "CoarScriptEditor",
579
+ props: {
580
+ modelValue: { default: "" },
581
+ authoring: {
582
+ type: Boolean,
583
+ default: !1
584
+ },
585
+ language: { default: "typescript" },
586
+ readonly: {
587
+ type: Boolean,
588
+ default: !1
589
+ },
590
+ disabled: {
591
+ type: Boolean,
592
+ default: !1
593
+ },
594
+ error: {
595
+ type: Boolean,
596
+ default: !1
597
+ },
598
+ placeholder: { default: "" },
599
+ required: {
600
+ type: Boolean,
601
+ default: !1
602
+ },
603
+ autofocus: {
604
+ type: Boolean,
605
+ default: !1
606
+ },
607
+ id: { default: "" },
608
+ name: { default: "" },
609
+ height: { default: void 0 },
610
+ variant: { default: "editor" },
611
+ scriptMode: {
612
+ type: Boolean,
613
+ default: !1
614
+ },
615
+ preamble: { default: "" },
616
+ minimap: {
617
+ type: Boolean,
618
+ default: !1
619
+ },
620
+ theme: { default: "auto" },
621
+ extraLibs: { default: () => [] },
622
+ overflowWidgetsDomNode: { default: null }
623
+ },
624
+ emits: [
625
+ "update:modelValue",
626
+ "reject",
627
+ "focused",
628
+ "blurred"
629
+ ],
630
+ setup(n, { expose: r, emit: o }) {
631
+ let l = n, f = o, p = c(null), m = l.modelValue, h = Q(), g = `coar-script-editor-${u()}`, _ = e(() => l.id || h?.inputId.value || g), v = e(() => l.error || (h?.hasError.value ?? !1)), y = e(() => h?.messageId.value), b = e(() => l.disabled || (h?.disabled.value ?? !1)), x = c(!1), S = c(l.modelValue.length === 0), C = e(() => ({
632
+ "coar-script-editor": !0,
633
+ "coar-script-editor--authoring": l.authoring,
634
+ "coar-script-editor--inline": l.variant === "inline",
635
+ "coar-script-editor--disabled": b.value,
636
+ "coar-script-editor--error": v.value,
637
+ "coar-script-editor--show-placeholder": !!l.placeholder && S.value && !x.value && !b.value
638
+ })), w = e(() => l.height === void 0 || l.height === "" ? {} : {
639
+ height: typeof l.height == "number" ? `${l.height}px` : l.height,
640
+ minHeight: "0"
641
+ }), { editor: T, model: E, setValue: D } = A({
642
+ host: p,
643
+ initialValue: () => l.modelValue,
644
+ language: () => l.language,
645
+ readonly: () => l.readonly || b.value,
646
+ minimap: () => l.minimap,
647
+ theme: () => l.theme,
648
+ variant: () => l.variant,
649
+ preamble: () => l.preamble,
650
+ scriptMode: () => l.scriptMode,
651
+ autofocus: () => l.autofocus,
652
+ overflowWidgetsDomNode: () => l.overflowWidgetsDomNode,
653
+ onContentChange: (e) => {
654
+ m = e, S.value = e.length === 0, f("update:modelValue", e);
655
+ },
656
+ onFocused: () => {
657
+ x.value = !0, f("focused");
658
+ },
659
+ onBlurred: () => {
660
+ x.value = !1, f("blurred");
661
+ }
662
+ });
663
+ return j({
664
+ language: () => l.language,
665
+ libs: () => l.extraLibs
666
+ }), X({
667
+ editor: T,
668
+ value: () => l.modelValue,
669
+ authoring: () => l.authoring,
670
+ onReject: (e) => f("reject", e)
671
+ }), d(() => l.modelValue, (e) => {
672
+ S.value = e.length === 0, e !== m && D(e);
673
+ }), r({
674
+ getEditor: () => T.value,
675
+ getModel: () => E.value,
676
+ focus: () => T.value?.focus()
677
+ }), (e, r) => (s(), t("div", {
678
+ id: _.value,
679
+ ref_key: "host",
680
+ ref: p,
681
+ class: i(C.value),
682
+ style: a(w.value),
683
+ "aria-invalid": v.value ? "true" : void 0,
684
+ "aria-describedby": y.value,
685
+ "aria-disabled": b.value ? "true" : void 0,
686
+ "aria-required": n.required ? "true" : void 0,
687
+ "data-placeholder": n.placeholder || void 0,
688
+ "data-name": n.name || void 0
689
+ }, null, 14, $));
690
+ }
691
+ });
692
+ //#endregion
693
+ export { m as COAR_THEME_DARK, p as COAR_THEME_LIGHT, ee as CoarScriptEditor, N as LOCKED_MARKER_TEXT, I as computeProtectedRanges, B as countLockedLines, _ as detectAutoTheme, R as editIsProtected, g as ensureCoarThemes, U as getEditableSegments, P as hasLockedMarkers, V as isEverySegmentNonEmpty, L as overlapsProtectedRange, F as scanLockedLines, z as snapOffsetAwayFromLocked, H as validateSource, y as watchAutoTheme };