princess-python-editor 0.1.1 → 0.1.3

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.es.js CHANGED
@@ -1,37 +1,810 @@
1
- var Ht = Object.defineProperty;
2
- var Tt = (u, r, a) => r in u ? Ht(u, r, { enumerable: !0, configurable: !0, writable: !0, value: a }) : u[r] = a;
3
- var L = (u, r, a) => Tt(u, typeof r != "symbol" ? r + "" : r, a);
4
- import { h as Ke, defineComponent as Nt, ref as F, computed as ie, onMounted as jt, onBeforeUnmount as _t, watch as V, nextTick as Ae, openBlock as g, createElementBlock as v, normalizeStyle as qe, normalizeClass as B, createVNode as $, unref as S, createElementVNode as c, createBlock as We, withDirectives as Dt, vModelText as Ut, toDisplayString as W, Fragment as se, renderList as de, createCommentVNode as z, withModifiers as Vt, onScopeDispose as Bt } from "vue";
5
- import { EditorState as Se, StateEffect as zt, StateField as Kt, Compartment as ce } from "@codemirror/state";
6
- import { EditorView as K, keymap as Je, lineNumbers as At, highlightActiveLineGutter as qt, highlightActiveLine as Wt, drawSelection as Jt, placeholder as Zt, Decoration as Ee } from "@codemirror/view";
7
- import { oneDark as Fe } from "@codemirror/theme-one-dark";
8
- import { linter as Gt, forceLinting as Xt } from "@codemirror/lint";
9
- import { autocompletion as Yt, closeBrackets as Qt, closeBracketsKeymap as en } from "@codemirror/autocomplete";
10
- import { history as tn, defaultKeymap as nn, historyKeymap as rn, indentWithTab as an } from "@codemirror/commands";
11
- import { indentUnit as sn, bracketMatching as on } from "@codemirror/language";
12
- import { python as Qe } from "@codemirror/lang-python";
13
- import { javascript as ln } from "@codemirror/lang-javascript";
14
- import { json as un } from "@codemirror/lang-json";
15
- import { sql as dn } from "@codemirror/lang-sql";
16
- const cn = "'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace", et = zt.define();
17
- function pn(u, r) {
18
- const a = u.filter((i) => Number.isFinite(i) && i >= 1 && i <= r.lines).sort((i, s) => i - s);
19
- return Ee.set(
20
- a.map((i) => Ee.line({ class: "vpe-error-line" }).range(r.line(i).from))
1
+ var Ps = Object.defineProperty;
2
+ var Os = (a, n, s) => n in a ? Ps(a, n, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[n] = s;
3
+ var ae = (a, n, s) => Os(a, typeof n != "symbol" ? n + "" : n, s);
4
+ import { h as An, defineComponent as Ms, ref as C, reactive as Dn, computed as U, onMounted as Ns, onBeforeUnmount as Ts, watch as oe, nextTick as zn, openBlock as m, createElementBlock as g, normalizeStyle as jn, normalizeClass as ie, createVNode as j, unref as B, createElementVNode as l, createCommentVNode as N, createBlock as Vn, withDirectives as J, vModelText as he, Fragment as D, toDisplayString as _, renderList as le, vModelSelect as St, withModifiers as Qn, withKeys as Ls, createTextVNode as Qt, onScopeDispose as $s } from "vue";
5
+ import { EditorState as Yt, StateEffect as Fs, StateField as Rs, Compartment as Kt } from "@codemirror/state";
6
+ import { EditorView as $e, keymap as Kn, lineNumbers as _s, highlightActiveLineGutter as Is, highlightActiveLine as Hs, drawSelection as Bs, placeholder as Us, Decoration as Xt } from "@codemirror/view";
7
+ import { linter as As, forceLinting as Ds } from "@codemirror/lint";
8
+ import { autocompletion as zs, closeBrackets as js, closeBracketsKeymap as Vs } from "@codemirror/autocomplete";
9
+ import { history as Qs, defaultKeymap as Ks, historyKeymap as Js, indentWithTab as Zs } from "@codemirror/commands";
10
+ import { syntaxHighlighting as Gs, HighlightStyle as Ws, indentUnit as Ys, bracketMatching as Xs } from "@codemirror/language";
11
+ import { python as dr } from "@codemirror/lang-python";
12
+ import { javascript as ea } from "@codemirror/lang-javascript";
13
+ import { json as ta } from "@codemirror/lang-json";
14
+ import { sql as na } from "@codemirror/lang-sql";
15
+ let ra = 0;
16
+ class K {
17
+ /**
18
+ Create a new node prop type.
19
+ */
20
+ constructor(n = {}) {
21
+ this.id = ra++, this.perNode = !!n.perNode, this.deserialize = n.deserialize || (() => {
22
+ throw new Error("This node type doesn't define a deserialize function");
23
+ }), this.combine = n.combine || null;
24
+ }
25
+ /**
26
+ This is meant to be used with
27
+ [`NodeSet.extend`](#common.NodeSet.extend) or
28
+ [`LRParser.configure`](#lr.ParserConfig.props) to compute
29
+ prop values for each node type in the set. Takes a [match
30
+ object](#common.NodeType^match) or function that returns undefined
31
+ if the node type doesn't get this prop, and the prop's value if
32
+ it does.
33
+ */
34
+ add(n) {
35
+ if (this.perNode)
36
+ throw new RangeError("Can't add per-node props to node types");
37
+ return typeof n != "function" && (n = ct.match(n)), (s) => {
38
+ let o = n(s);
39
+ return o === void 0 ? null : [this, o];
40
+ };
41
+ }
42
+ }
43
+ K.closedBy = new K({ deserialize: (a) => a.split(" ") });
44
+ K.openedBy = new K({ deserialize: (a) => a.split(" ") });
45
+ K.group = new K({ deserialize: (a) => a.split(" ") });
46
+ K.isolate = new K({ deserialize: (a) => {
47
+ if (a && a != "rtl" && a != "ltr" && a != "auto")
48
+ throw new RangeError("Invalid value for isolate: " + a);
49
+ return a || "auto";
50
+ } });
51
+ K.contextHash = new K({ perNode: !0 });
52
+ K.lookAhead = new K({ perNode: !0 });
53
+ K.mounted = new K({ perNode: !0 });
54
+ const sa = /* @__PURE__ */ Object.create(null);
55
+ class ct {
56
+ /**
57
+ @internal
58
+ */
59
+ constructor(n, s, o, i = 0) {
60
+ this.name = n, this.props = s, this.id = o, this.flags = i;
61
+ }
62
+ /**
63
+ Define a node type.
64
+ */
65
+ static define(n) {
66
+ let s = n.props && n.props.length ? /* @__PURE__ */ Object.create(null) : sa, o = (n.top ? 1 : 0) | (n.skipped ? 2 : 0) | (n.error ? 4 : 0) | (n.name == null ? 8 : 0), i = new ct(n.name || "", s, n.id, o);
67
+ if (n.props) {
68
+ for (let p of n.props)
69
+ if (Array.isArray(p) || (p = p(i)), p) {
70
+ if (p[0].perNode)
71
+ throw new RangeError("Can't store a per-node prop on a node type");
72
+ s[p[0].id] = p[1];
73
+ }
74
+ }
75
+ return i;
76
+ }
77
+ /**
78
+ Retrieves a node prop for this type. Will return `undefined` if
79
+ the prop isn't present on this node.
80
+ */
81
+ prop(n) {
82
+ return this.props[n.id];
83
+ }
84
+ /**
85
+ True when this is the top node of a grammar.
86
+ */
87
+ get isTop() {
88
+ return (this.flags & 1) > 0;
89
+ }
90
+ /**
91
+ True when this node is produced by a skip rule.
92
+ */
93
+ get isSkipped() {
94
+ return (this.flags & 2) > 0;
95
+ }
96
+ /**
97
+ Indicates whether this is an error node.
98
+ */
99
+ get isError() {
100
+ return (this.flags & 4) > 0;
101
+ }
102
+ /**
103
+ When true, this node type doesn't correspond to a user-declared
104
+ named node, for example because it is used to cache repetition.
105
+ */
106
+ get isAnonymous() {
107
+ return (this.flags & 8) > 0;
108
+ }
109
+ /**
110
+ Returns true when this node's name or one of its
111
+ [groups](#common.NodeProp^group) matches the given string.
112
+ */
113
+ is(n) {
114
+ if (typeof n == "string") {
115
+ if (this.name == n)
116
+ return !0;
117
+ let s = this.prop(K.group);
118
+ return s ? s.indexOf(n) > -1 : !1;
119
+ }
120
+ return this.id == n;
121
+ }
122
+ /**
123
+ Create a function from node types to arbitrary values by
124
+ specifying an object whose property names are node or
125
+ [group](#common.NodeProp^group) names. Often useful with
126
+ [`NodeProp.add`](#common.NodeProp.add). You can put multiple
127
+ names, separated by spaces, in a single property name to map
128
+ multiple node names to a single value.
129
+ */
130
+ static match(n) {
131
+ let s = /* @__PURE__ */ Object.create(null);
132
+ for (let o in n)
133
+ for (let i of o.split(" "))
134
+ s[i] = n[o];
135
+ return (o) => {
136
+ for (let i = o.prop(K.group), p = -1; p < (i ? i.length : 0); p++) {
137
+ let b = s[p < 0 ? o.name : i[p]];
138
+ if (b)
139
+ return b;
140
+ }
141
+ };
142
+ }
143
+ }
144
+ ct.none = new ct(
145
+ "",
146
+ /* @__PURE__ */ Object.create(null),
147
+ 0,
148
+ 8
149
+ /* NodeFlag.Anonymous */
150
+ );
151
+ var Jn;
152
+ (function(a) {
153
+ a[a.ExcludeBuffers = 1] = "ExcludeBuffers", a[a.IncludeAnonymous = 2] = "IncludeAnonymous", a[a.IgnoreMounts = 4] = "IgnoreMounts", a[a.IgnoreOverlays = 8] = "IgnoreOverlays", a[a.EnterBracketed = 16] = "EnterBracketed";
154
+ })(Jn || (Jn = {}));
155
+ new K({ perNode: !0 });
156
+ let aa = 0;
157
+ class ue {
158
+ /**
159
+ @internal
160
+ */
161
+ constructor(n, s, o, i) {
162
+ this.name = n, this.set = s, this.base = o, this.modified = i, this.id = aa++;
163
+ }
164
+ toString() {
165
+ let { name: n } = this;
166
+ for (let s of this.modified)
167
+ s.name && (n = `${s.name}(${n})`);
168
+ return n;
169
+ }
170
+ static define(n, s) {
171
+ let o = typeof n == "string" ? n : "?";
172
+ if (n instanceof ue && (s = n), s != null && s.base)
173
+ throw new Error("Can not derive from a modified tag");
174
+ let i = new ue(o, [], null, []);
175
+ if (i.set.push(i), s)
176
+ for (let p of s.set)
177
+ i.set.push(p);
178
+ return i;
179
+ }
180
+ /**
181
+ Define a tag _modifier_, which is a function that, given a tag,
182
+ will return a tag that is a subtag of the original. Applying the
183
+ same modifier to a twice tag will return the same value (`m1(t1)
184
+ == m1(t1)`) and applying multiple modifiers will, regardless or
185
+ order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
186
+
187
+ When multiple modifiers are applied to a given base tag, each
188
+ smaller set of modifiers is registered as a parent, so that for
189
+ example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
190
+ `m1(m3(t1)`, and so on.
191
+ */
192
+ static defineModifier(n) {
193
+ let s = new Pt(n);
194
+ return (o) => o.modified.indexOf(s) > -1 ? o : Pt.get(o.base || o, o.modified.concat(s).sort((i, p) => i.id - p.id));
195
+ }
196
+ }
197
+ let oa = 0;
198
+ class Pt {
199
+ constructor(n) {
200
+ this.name = n, this.instances = [], this.id = oa++;
201
+ }
202
+ static get(n, s) {
203
+ if (!s.length)
204
+ return n;
205
+ let o = s[0].instances.find((E) => E.base == n && ia(s, E.modified));
206
+ if (o)
207
+ return o;
208
+ let i = [], p = new ue(n.name, i, n, s);
209
+ for (let E of s)
210
+ E.instances.push(p);
211
+ let b = la(s);
212
+ for (let E of n.set)
213
+ if (!E.modified.length)
214
+ for (let R of b)
215
+ i.push(Pt.get(E, R));
216
+ return p;
217
+ }
218
+ }
219
+ function ia(a, n) {
220
+ return a.length == n.length && a.every((s, o) => s == n[o]);
221
+ }
222
+ function la(a) {
223
+ let n = [[]];
224
+ for (let s = 0; s < a.length; s++)
225
+ for (let o = 0, i = n.length; o < i; o++)
226
+ n.push(n[o].concat(a[s]));
227
+ return n.sort((s, o) => o.length - s.length);
228
+ }
229
+ new K({
230
+ combine(a, n) {
231
+ let s, o, i;
232
+ for (; a || n; ) {
233
+ if (!a || n && a.depth <= n.depth ? (i = n, n = n.next) : (i = a, a = a.next), s && s.mode == i.mode && !i.context && !s.context)
234
+ continue;
235
+ let p = new en(i.tags, i.mode, i.context);
236
+ s ? s.next = p : o = p, s = p;
237
+ }
238
+ return o;
239
+ }
240
+ });
241
+ class en {
242
+ constructor(n, s, o, i) {
243
+ this.tags = n, this.mode = s, this.context = o, this.next = i;
244
+ }
245
+ get opaque() {
246
+ return this.mode == 0;
247
+ }
248
+ get inherit() {
249
+ return this.mode == 1;
250
+ }
251
+ sort(n) {
252
+ return !n || n.depth < this.depth ? (this.next = n, this) : (n.next = this.sort(n.next), n);
253
+ }
254
+ get depth() {
255
+ return this.context ? this.context.length : 0;
256
+ }
257
+ }
258
+ en.empty = new en([], 2, null);
259
+ function ua(a, n) {
260
+ let s = /* @__PURE__ */ Object.create(null);
261
+ for (let p of a)
262
+ if (!Array.isArray(p.tag))
263
+ s[p.tag.id] = p.class;
264
+ else
265
+ for (let b of p.tag)
266
+ s[b.id] = p.class;
267
+ let { scope: o, all: i = null } = {};
268
+ return {
269
+ style: (p) => {
270
+ let b = i;
271
+ for (let E of p)
272
+ for (let R of E.set) {
273
+ let P = s[R.id];
274
+ if (P) {
275
+ b = b ? b + " " + P : P;
276
+ break;
277
+ }
278
+ }
279
+ return b;
280
+ },
281
+ scope: o
282
+ };
283
+ }
284
+ const v = ue.define, xt = v(), Te = v(), Zn = v(Te), Gn = v(Te), Le = v(), Et = v(Le), Jt = v(Le), we = v(), Be = v(we), be = v(), ke = v(), tn = v(), it = v(tn), qt = v(), d = {
285
+ /**
286
+ A comment.
287
+ */
288
+ comment: xt,
289
+ /**
290
+ A line [comment](#highlight.tags.comment).
291
+ */
292
+ lineComment: v(xt),
293
+ /**
294
+ A block [comment](#highlight.tags.comment).
295
+ */
296
+ blockComment: v(xt),
297
+ /**
298
+ A documentation [comment](#highlight.tags.comment).
299
+ */
300
+ docComment: v(xt),
301
+ /**
302
+ Any kind of identifier.
303
+ */
304
+ name: Te,
305
+ /**
306
+ The [name](#highlight.tags.name) of a variable.
307
+ */
308
+ variableName: v(Te),
309
+ /**
310
+ A type [name](#highlight.tags.name).
311
+ */
312
+ typeName: Zn,
313
+ /**
314
+ A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
315
+ */
316
+ tagName: v(Zn),
317
+ /**
318
+ A property or field [name](#highlight.tags.name).
319
+ */
320
+ propertyName: Gn,
321
+ /**
322
+ An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
323
+ */
324
+ attributeName: v(Gn),
325
+ /**
326
+ The [name](#highlight.tags.name) of a class.
327
+ */
328
+ className: v(Te),
329
+ /**
330
+ A label [name](#highlight.tags.name).
331
+ */
332
+ labelName: v(Te),
333
+ /**
334
+ A namespace [name](#highlight.tags.name).
335
+ */
336
+ namespace: v(Te),
337
+ /**
338
+ The [name](#highlight.tags.name) of a macro.
339
+ */
340
+ macroName: v(Te),
341
+ /**
342
+ A literal value.
343
+ */
344
+ literal: Le,
345
+ /**
346
+ A string [literal](#highlight.tags.literal).
347
+ */
348
+ string: Et,
349
+ /**
350
+ A documentation [string](#highlight.tags.string).
351
+ */
352
+ docString: v(Et),
353
+ /**
354
+ A character literal (subtag of [string](#highlight.tags.string)).
355
+ */
356
+ character: v(Et),
357
+ /**
358
+ An attribute value (subtag of [string](#highlight.tags.string)).
359
+ */
360
+ attributeValue: v(Et),
361
+ /**
362
+ A number [literal](#highlight.tags.literal).
363
+ */
364
+ number: Jt,
365
+ /**
366
+ An integer [number](#highlight.tags.number) literal.
367
+ */
368
+ integer: v(Jt),
369
+ /**
370
+ A floating-point [number](#highlight.tags.number) literal.
371
+ */
372
+ float: v(Jt),
373
+ /**
374
+ A boolean [literal](#highlight.tags.literal).
375
+ */
376
+ bool: v(Le),
377
+ /**
378
+ Regular expression [literal](#highlight.tags.literal).
379
+ */
380
+ regexp: v(Le),
381
+ /**
382
+ An escape [literal](#highlight.tags.literal), for example a
383
+ backslash escape in a string.
384
+ */
385
+ escape: v(Le),
386
+ /**
387
+ A color [literal](#highlight.tags.literal).
388
+ */
389
+ color: v(Le),
390
+ /**
391
+ A URL [literal](#highlight.tags.literal).
392
+ */
393
+ url: v(Le),
394
+ /**
395
+ A language keyword.
396
+ */
397
+ keyword: be,
398
+ /**
399
+ The [keyword](#highlight.tags.keyword) for the self or this
400
+ object.
401
+ */
402
+ self: v(be),
403
+ /**
404
+ The [keyword](#highlight.tags.keyword) for null.
405
+ */
406
+ null: v(be),
407
+ /**
408
+ A [keyword](#highlight.tags.keyword) denoting some atomic value.
409
+ */
410
+ atom: v(be),
411
+ /**
412
+ A [keyword](#highlight.tags.keyword) that represents a unit.
413
+ */
414
+ unit: v(be),
415
+ /**
416
+ A modifier [keyword](#highlight.tags.keyword).
417
+ */
418
+ modifier: v(be),
419
+ /**
420
+ A [keyword](#highlight.tags.keyword) that acts as an operator.
421
+ */
422
+ operatorKeyword: v(be),
423
+ /**
424
+ A control-flow related [keyword](#highlight.tags.keyword).
425
+ */
426
+ controlKeyword: v(be),
427
+ /**
428
+ A [keyword](#highlight.tags.keyword) that defines something.
429
+ */
430
+ definitionKeyword: v(be),
431
+ /**
432
+ A [keyword](#highlight.tags.keyword) related to defining or
433
+ interfacing with modules.
434
+ */
435
+ moduleKeyword: v(be),
436
+ /**
437
+ An operator.
438
+ */
439
+ operator: ke,
440
+ /**
441
+ An [operator](#highlight.tags.operator) that dereferences something.
442
+ */
443
+ derefOperator: v(ke),
444
+ /**
445
+ Arithmetic-related [operator](#highlight.tags.operator).
446
+ */
447
+ arithmeticOperator: v(ke),
448
+ /**
449
+ Logical [operator](#highlight.tags.operator).
450
+ */
451
+ logicOperator: v(ke),
452
+ /**
453
+ Bit [operator](#highlight.tags.operator).
454
+ */
455
+ bitwiseOperator: v(ke),
456
+ /**
457
+ Comparison [operator](#highlight.tags.operator).
458
+ */
459
+ compareOperator: v(ke),
460
+ /**
461
+ [Operator](#highlight.tags.operator) that updates its operand.
462
+ */
463
+ updateOperator: v(ke),
464
+ /**
465
+ [Operator](#highlight.tags.operator) that defines something.
466
+ */
467
+ definitionOperator: v(ke),
468
+ /**
469
+ Type-related [operator](#highlight.tags.operator).
470
+ */
471
+ typeOperator: v(ke),
472
+ /**
473
+ Control-flow [operator](#highlight.tags.operator).
474
+ */
475
+ controlOperator: v(ke),
476
+ /**
477
+ Program or markup punctuation.
478
+ */
479
+ punctuation: tn,
480
+ /**
481
+ [Punctuation](#highlight.tags.punctuation) that separates
482
+ things.
483
+ */
484
+ separator: v(tn),
485
+ /**
486
+ Bracket-style [punctuation](#highlight.tags.punctuation).
487
+ */
488
+ bracket: it,
489
+ /**
490
+ Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
491
+ tokens).
492
+ */
493
+ angleBracket: v(it),
494
+ /**
495
+ Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
496
+ tokens).
497
+ */
498
+ squareBracket: v(it),
499
+ /**
500
+ Parentheses (usually `(` and `)` tokens). Subtag of
501
+ [bracket](#highlight.tags.bracket).
502
+ */
503
+ paren: v(it),
504
+ /**
505
+ Braces (usually `{` and `}` tokens). Subtag of
506
+ [bracket](#highlight.tags.bracket).
507
+ */
508
+ brace: v(it),
509
+ /**
510
+ Content, for example plain text in XML or markup documents.
511
+ */
512
+ content: we,
513
+ /**
514
+ [Content](#highlight.tags.content) that represents a heading.
515
+ */
516
+ heading: Be,
517
+ /**
518
+ A level 1 [heading](#highlight.tags.heading).
519
+ */
520
+ heading1: v(Be),
521
+ /**
522
+ A level 2 [heading](#highlight.tags.heading).
523
+ */
524
+ heading2: v(Be),
525
+ /**
526
+ A level 3 [heading](#highlight.tags.heading).
527
+ */
528
+ heading3: v(Be),
529
+ /**
530
+ A level 4 [heading](#highlight.tags.heading).
531
+ */
532
+ heading4: v(Be),
533
+ /**
534
+ A level 5 [heading](#highlight.tags.heading).
535
+ */
536
+ heading5: v(Be),
537
+ /**
538
+ A level 6 [heading](#highlight.tags.heading).
539
+ */
540
+ heading6: v(Be),
541
+ /**
542
+ A prose [content](#highlight.tags.content) separator (such as a horizontal rule).
543
+ */
544
+ contentSeparator: v(we),
545
+ /**
546
+ [Content](#highlight.tags.content) that represents a list.
547
+ */
548
+ list: v(we),
549
+ /**
550
+ [Content](#highlight.tags.content) that represents a quote.
551
+ */
552
+ quote: v(we),
553
+ /**
554
+ [Content](#highlight.tags.content) that is emphasized.
555
+ */
556
+ emphasis: v(we),
557
+ /**
558
+ [Content](#highlight.tags.content) that is styled strong.
559
+ */
560
+ strong: v(we),
561
+ /**
562
+ [Content](#highlight.tags.content) that is part of a link.
563
+ */
564
+ link: v(we),
565
+ /**
566
+ [Content](#highlight.tags.content) that is styled as code or
567
+ monospace.
568
+ */
569
+ monospace: v(we),
570
+ /**
571
+ [Content](#highlight.tags.content) that has a strike-through
572
+ style.
573
+ */
574
+ strikethrough: v(we),
575
+ /**
576
+ Inserted text in a change-tracking format.
577
+ */
578
+ inserted: v(),
579
+ /**
580
+ Deleted text.
581
+ */
582
+ deleted: v(),
583
+ /**
584
+ Changed text.
585
+ */
586
+ changed: v(),
587
+ /**
588
+ An invalid or unsyntactic element.
589
+ */
590
+ invalid: v(),
591
+ /**
592
+ Metadata or meta-instruction.
593
+ */
594
+ meta: qt,
595
+ /**
596
+ [Metadata](#highlight.tags.meta) that applies to the entire
597
+ document.
598
+ */
599
+ documentMeta: v(qt),
600
+ /**
601
+ [Metadata](#highlight.tags.meta) that annotates or adds
602
+ attributes to a given syntactic element.
603
+ */
604
+ annotation: v(qt),
605
+ /**
606
+ Processing instruction or preprocessor directive. Subtag of
607
+ [meta](#highlight.tags.meta).
608
+ */
609
+ processingInstruction: v(qt),
610
+ /**
611
+ [Modifier](#highlight.Tag^defineModifier) that indicates that a
612
+ given element is being defined. Expected to be used with the
613
+ various [name](#highlight.tags.name) tags.
614
+ */
615
+ definition: ue.defineModifier("definition"),
616
+ /**
617
+ [Modifier](#highlight.Tag^defineModifier) that indicates that
618
+ something is constant. Mostly expected to be used with
619
+ [variable names](#highlight.tags.variableName).
620
+ */
621
+ constant: ue.defineModifier("constant"),
622
+ /**
623
+ [Modifier](#highlight.Tag^defineModifier) used to indicate that
624
+ a [variable](#highlight.tags.variableName) or [property
625
+ name](#highlight.tags.propertyName) is being called or defined
626
+ as a function.
627
+ */
628
+ function: ue.defineModifier("function"),
629
+ /**
630
+ [Modifier](#highlight.Tag^defineModifier) that can be applied to
631
+ [names](#highlight.tags.name) to indicate that they belong to
632
+ the language's standard environment.
633
+ */
634
+ standard: ue.defineModifier("standard"),
635
+ /**
636
+ [Modifier](#highlight.Tag^defineModifier) that indicates a given
637
+ [names](#highlight.tags.name) is local to some scope.
638
+ */
639
+ local: ue.defineModifier("local"),
640
+ /**
641
+ A generic variant [modifier](#highlight.Tag^defineModifier) that
642
+ can be used to tag language-specific alternative variants of
643
+ some common tag. It is recommended for themes to define special
644
+ forms of at least the [string](#highlight.tags.string) and
645
+ [variable name](#highlight.tags.variableName) tags, since those
646
+ come up a lot.
647
+ */
648
+ special: ue.defineModifier("special")
649
+ };
650
+ for (let a in d) {
651
+ let n = d[a];
652
+ n instanceof ue && (n.name = a);
653
+ }
654
+ ua([
655
+ { tag: d.link, class: "tok-link" },
656
+ { tag: d.heading, class: "tok-heading" },
657
+ { tag: d.emphasis, class: "tok-emphasis" },
658
+ { tag: d.strong, class: "tok-strong" },
659
+ { tag: d.keyword, class: "tok-keyword" },
660
+ { tag: d.atom, class: "tok-atom" },
661
+ { tag: d.bool, class: "tok-bool" },
662
+ { tag: d.url, class: "tok-url" },
663
+ { tag: d.labelName, class: "tok-labelName" },
664
+ { tag: d.inserted, class: "tok-inserted" },
665
+ { tag: d.deleted, class: "tok-deleted" },
666
+ { tag: d.literal, class: "tok-literal" },
667
+ { tag: d.string, class: "tok-string" },
668
+ { tag: d.number, class: "tok-number" },
669
+ { tag: [d.regexp, d.escape, d.special(d.string)], class: "tok-string2" },
670
+ { tag: d.variableName, class: "tok-variableName" },
671
+ { tag: d.local(d.variableName), class: "tok-variableName tok-local" },
672
+ { tag: d.definition(d.variableName), class: "tok-variableName tok-definition" },
673
+ { tag: d.special(d.variableName), class: "tok-variableName2" },
674
+ { tag: d.definition(d.propertyName), class: "tok-propertyName tok-definition" },
675
+ { tag: d.typeName, class: "tok-typeName" },
676
+ { tag: d.namespace, class: "tok-namespace" },
677
+ { tag: d.className, class: "tok-className" },
678
+ { tag: d.macroName, class: "tok-macroName" },
679
+ { tag: d.propertyName, class: "tok-propertyName" },
680
+ { tag: d.operator, class: "tok-operator" },
681
+ { tag: d.comment, class: "tok-comment" },
682
+ { tag: d.meta, class: "tok-meta" },
683
+ { tag: d.invalid, class: "tok-invalid" },
684
+ { tag: d.punctuation, class: "tok-punctuation" }
685
+ ]);
686
+ const ca = {
687
+ "&": {
688
+ backgroundColor: "var(--vpe-editor-bg)",
689
+ color: "var(--vpe-text)"
690
+ },
691
+ ".cm-content": {
692
+ caretColor: "var(--vpe-accent)"
693
+ },
694
+ ".cm-cursor, .cm-dropCursor": {
695
+ borderLeftColor: "var(--vpe-accent)"
696
+ },
697
+ "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
698
+ backgroundColor: "var(--vpe-selection)"
699
+ },
700
+ ".cm-activeLine": {
701
+ backgroundColor: "var(--vpe-active-line)"
702
+ },
703
+ ".cm-activeLineGutter": {
704
+ backgroundColor: "var(--vpe-active-line)",
705
+ color: "var(--vpe-text)"
706
+ },
707
+ ".cm-gutters": {
708
+ color: "var(--vpe-gutter)",
709
+ backgroundColor: "transparent"
710
+ },
711
+ ".cm-matchingBracket, .cm-nonmatchingBracket": {
712
+ backgroundColor: "var(--vpe-matching-bracket)",
713
+ outline: "1px solid var(--vpe-border)"
714
+ },
715
+ ".cm-selectionMatch": {
716
+ backgroundColor: "var(--vpe-matching-bracket)"
717
+ },
718
+ ".cm-searchMatch": {
719
+ backgroundColor: "var(--vpe-search-match)",
720
+ outline: "1px solid var(--vpe-border)"
721
+ },
722
+ ".cm-tooltip": {
723
+ backgroundColor: "var(--vpe-bg)",
724
+ border: "1px solid var(--vpe-border)",
725
+ color: "var(--vpe-text)"
726
+ },
727
+ ".cm-tooltip-autocomplete > ul > li[aria-selected]": {
728
+ backgroundColor: "var(--vpe-hover)",
729
+ color: "var(--vpe-text)"
730
+ },
731
+ ".cm-panels": {
732
+ backgroundColor: "var(--vpe-toolbar-bg)",
733
+ color: "var(--vpe-text)"
734
+ },
735
+ ".cm-panels.cm-panels-top": {
736
+ borderBottom: "1px solid var(--vpe-border)"
737
+ },
738
+ ".cm-panels.cm-panels-bottom": {
739
+ borderTop: "1px solid var(--vpe-border)"
740
+ }
741
+ }, da = Ws.define([
742
+ { tag: d.comment, color: "var(--vpe-syn-comment)", fontStyle: "italic" },
743
+ {
744
+ tag: [
745
+ d.keyword,
746
+ d.controlKeyword,
747
+ d.moduleKeyword,
748
+ d.definitionKeyword,
749
+ d.operatorKeyword,
750
+ d.modifier
751
+ ],
752
+ color: "var(--vpe-syn-keyword)"
753
+ },
754
+ { tag: [d.string, d.special(d.string), d.regexp], color: "var(--vpe-syn-string)" },
755
+ { tag: [d.number, d.bool, d.null, d.atom], color: "var(--vpe-syn-number)" },
756
+ {
757
+ tag: [
758
+ d.function(d.variableName),
759
+ d.function(d.propertyName),
760
+ d.definition(d.function(d.variableName))
761
+ ],
762
+ color: "var(--vpe-syn-function)"
763
+ },
764
+ { tag: [d.className, d.typeName, d.namespace], color: "var(--vpe-syn-type)" },
765
+ { tag: [d.propertyName, d.attributeName, d.labelName], color: "var(--vpe-syn-property)" },
766
+ { tag: [d.operator, d.punctuation, d.bracket, d.separator], color: "var(--vpe-syn-operator)" },
767
+ { tag: d.standard(d.variableName), color: "var(--vpe-syn-builtin)" },
768
+ {
769
+ tag: [d.self, d.special(d.variableName)],
770
+ color: "var(--vpe-syn-self)",
771
+ fontStyle: "italic"
772
+ },
773
+ { tag: [d.variableName, d.definition(d.variableName)], color: "var(--vpe-syn-variable)" },
774
+ { tag: [d.meta, d.annotation], color: "var(--vpe-syn-meta)" },
775
+ { tag: d.tagName, color: "var(--vpe-syn-tag)" },
776
+ { tag: [d.link, d.url], color: "var(--vpe-syn-link)", textDecoration: "underline" },
777
+ {
778
+ tag: [d.heading, d.strong],
779
+ color: "var(--vpe-syn-heading)",
780
+ fontWeight: "bold"
781
+ },
782
+ { tag: d.emphasis, fontStyle: "italic" },
783
+ { tag: d.strikethrough, textDecoration: "line-through" },
784
+ { tag: d.invalid, color: "var(--vpe-syn-invalid)" }
785
+ ]);
786
+ function pa(a) {
787
+ return [$e.theme(ca, { dark: a }), Gs(da)];
788
+ }
789
+ const fa = "'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace", pr = Fs.define();
790
+ function va(a, n) {
791
+ const s = a.filter((o) => Number.isFinite(o) && o >= 1 && o <= n.lines).sort((o, i) => o - i);
792
+ return Xt.set(
793
+ s.map((o) => Xt.line({ class: "vpe-error-line" }).range(n.line(o).from))
21
794
  );
22
795
  }
23
- const fn = Kt.define({
24
- create: () => Ee.none,
25
- update: (u, r) => {
26
- let a = u;
27
- for (const i of r.effects)
28
- i.is(et) && (a = pn(i.value, r.state.doc));
29
- return r.docChanged && (a = a.map(r.changes)), a;
796
+ const ma = Rs.define({
797
+ create: () => Xt.none,
798
+ update: (a, n) => {
799
+ let s = a;
800
+ for (const o of n.effects)
801
+ o.is(pr) && (s = va(o.value, n.state.doc));
802
+ return n.docChanged && (s = s.map(n.changes)), s;
30
803
  },
31
- provide: (u) => K.decorations.from(u)
32
- }), hn = K.theme({
804
+ provide: (a) => $e.decorations.from(a)
805
+ }), ga = $e.theme({
33
806
  "&": { height: "100%", fontSize: "13px" },
34
- ".cm-scroller": { fontFamily: cn, lineHeight: "1.65" },
807
+ ".cm-scroller": { fontFamily: fa, lineHeight: "1.65" },
35
808
  ".cm-content": { padding: "10px 0 14px" },
36
809
  ".cm-gutters": {
37
810
  borderRight: "none",
@@ -41,68 +814,68 @@ const fn = Kt.define({
41
814
  },
42
815
  "&.cm-focused": { outline: "none" }
43
816
  });
44
- function mn(u, r) {
45
- const a = K.updateListener.of((P) => {
46
- P.docChanged && r.onDocChange(P.state.doc.toString());
47
- }), i = Je.of([
817
+ function ya(a, n) {
818
+ const s = $e.updateListener.of((p) => {
819
+ p.docChanged && n.onDocChange(p.state.doc.toString());
820
+ }), o = Kn.of([
48
821
  {
49
822
  key: "Mod-Enter",
50
823
  preventDefault: !0,
51
- run: () => (r.onRunShortcut(), !0)
824
+ run: () => (n.onRunShortcut(), !0)
52
825
  }
53
- ]), s = Se.create({
54
- doc: r.value,
826
+ ]), i = Yt.create({
827
+ doc: n.value,
55
828
  extensions: [
56
- hn,
57
- At(),
58
- qt(),
59
- Wt(),
60
- Jt(),
61
- tn(),
62
- sn.of(" "),
63
- r.language ?? Qe(),
64
- Yt(),
65
- Qt(),
66
- on(),
67
- K.lineWrapping,
68
- Zt(r.placeholderText),
69
- fn,
70
- i,
71
- Je.of([...en, ...nn, ...rn, an]),
72
- ...r.dark ? [Fe] : [],
73
- ...r.extensions,
74
- a
829
+ ga,
830
+ _s(),
831
+ Is(),
832
+ Hs(),
833
+ Bs(),
834
+ Qs(),
835
+ Ys.of(" "),
836
+ n.language ?? dr(),
837
+ pa(n.dark),
838
+ zs(),
839
+ js(),
840
+ Xs(),
841
+ $e.lineWrapping,
842
+ Us(n.placeholderText),
843
+ ma,
844
+ o,
845
+ Kn.of([...Vs, ...Ks, ...Js, Zs]),
846
+ ...n.extensions,
847
+ s
75
848
  ]
76
849
  });
77
- return new K({ state: s, parent: u });
850
+ return new $e({ state: i, parent: a });
78
851
  }
79
- function yn(u, r = 600) {
80
- return Gt(
81
- async (a) => {
82
- const i = a.state.doc.toString();
83
- if (!i.trim()) return [];
84
- let s = null;
852
+ function ha(a, n = 600) {
853
+ return As(
854
+ async (s) => {
855
+ const o = s.state.doc.toString();
856
+ if (!o.trim()) return [];
857
+ let i = null;
85
858
  try {
86
- s = await u.checkSyntax(i);
859
+ i = await a.checkSyntax(o);
87
860
  } catch {
88
861
  return [];
89
862
  }
90
- if (!s) return [];
91
- const P = Math.min(Math.max(Math.round(s.line) || 1, 1), a.state.doc.lines), w = a.state.doc.line(P), I = Math.min(Math.max(Math.round(s.column) || 1, 1), w.length + 1), H = w.from + I - 1, C = Math.min(H + 1, w.to);
863
+ if (!i) return [];
864
+ const p = Math.min(Math.max(Math.round(i.line) || 1, 1), s.state.doc.lines), b = s.state.doc.line(p), E = Math.min(Math.max(Math.round(i.column) || 1, 1), b.length + 1), R = b.from + E - 1, P = Math.min(R + 1, b.to);
92
865
  return [
93
866
  {
94
- from: H,
95
- to: C,
867
+ from: R,
868
+ to: P,
96
869
  severity: "error",
97
- message: s.message,
870
+ message: i.message,
98
871
  source: "python-syntax"
99
872
  }
100
873
  ];
101
874
  },
102
- { delay: r }
875
+ { delay: n }
103
876
  );
104
877
  }
105
- const gn = [
878
+ const ba = [
106
879
  "import ast, json",
107
880
  "def _pye_check(src):",
108
881
  " try:",
@@ -110,15 +883,94 @@ const gn = [
110
883
  " return json.dumps({'ok': True})",
111
884
  " except SyntaxError as e:",
112
885
  " return json.dumps({'ok': False, 'line': int(e.lineno or 1), 'column': int(e.offset or 1), 'message': str(e.msg or 'invalid syntax')})"
886
+ ], ka = [
887
+ "import json",
888
+ "import sqlite3",
889
+ "",
890
+ "_pye_conns = {}",
891
+ "",
892
+ "def _pye_value(value):",
893
+ " if value is None or isinstance(value, (bool, int, float, str)):",
894
+ " return value",
895
+ " if isinstance(value, (bytes, bytearray, memoryview)):",
896
+ " return bytes(value).hex()",
897
+ " return str(value)",
898
+ "",
899
+ "def _pye_meaningful(stmt):",
900
+ " text = stmt.strip()",
901
+ " if not text:",
902
+ " return False",
903
+ ' text = text.replace(";", " ").strip()',
904
+ " if not text:",
905
+ " return False",
906
+ " for line in text.splitlines():",
907
+ " line = line.strip()",
908
+ ' if line and not line.startswith("--"):',
909
+ " return True",
910
+ " return False",
911
+ "",
912
+ "def _pye_exec_one(conn, stmt, max_rows):",
913
+ " cur = conn.cursor()",
914
+ " try:",
915
+ " cur.execute(stmt)",
916
+ " if cur.description:",
917
+ " columns = [str(item[0]) for item in cur.description]",
918
+ " rows = []",
919
+ " truncated = False",
920
+ " for row in cur:",
921
+ " if len(rows) >= max_rows:",
922
+ " truncated = True",
923
+ " break",
924
+ " rows.append([_pye_value(value) for value in row])",
925
+ ' return {"columns": columns, "rows": rows, "affectedRows": 0, "truncated": truncated}',
926
+ " affected = cur.rowcount",
927
+ " if affected is None or affected < 0:",
928
+ " affected = 0",
929
+ ' return {"columns": [], "rows": [], "affectedRows": affected, "truncated": False}',
930
+ " finally:",
931
+ " cur.close()",
932
+ "",
933
+ "def _pye_split(sql):",
934
+ " statements = []",
935
+ ' buf = ""',
936
+ " for ch in sql:",
937
+ " buf += ch",
938
+ ' if ch == ";" and sqlite3.complete_statement(buf):',
939
+ " statements.append(buf)",
940
+ ' buf = ""',
941
+ " if buf.strip():",
942
+ " statements.append(buf)",
943
+ " return statements",
944
+ "",
945
+ "def _pye_sql(database, sql, max_rows):",
946
+ ' database = database or ":memory:"',
947
+ " if max_rows < 1:",
948
+ " max_rows = 200",
949
+ " conn = _pye_conns.get(database)",
950
+ " if conn is None:",
951
+ " conn = sqlite3.connect(database, isolation_level=None)",
952
+ " _pye_conns[database] = conn",
953
+ " results = []",
954
+ " try:",
955
+ " for stmt in _pye_split(sql):",
956
+ " if _pye_meaningful(stmt):",
957
+ " results.append(_pye_exec_one(conn, stmt, max_rows))",
958
+ " except Exception as exc:",
959
+ ' error = {"type": type(exc).__name__, "message": str(exc)}',
960
+ ' return json.dumps({"ok": False, "results": results, "error": error})',
961
+ ' return json.dumps({"ok": True, "results": results})'
113
962
  ];
114
- function vn(u) {
115
- const r = u.endsWith("/") ? u : u + "/";
963
+ function wa(a) {
964
+ const n = a.endsWith("/") ? a : a + "/";
116
965
  return `
117
- var INDEX_URL = ${JSON.stringify(r)};
118
- var CHECK_SOURCE = ${JSON.stringify(gn.join(`
966
+ var INDEX_URL = ${JSON.stringify(n)};
967
+ var CHECK_SOURCE = ${JSON.stringify(ba.join(`
968
+ `))};
969
+ var SQL_SOURCE = ${JSON.stringify(ka.join(`
119
970
  `))};
120
971
  var pyodide = null;
121
972
  var checkFn = null;
973
+ var sqlFn = null;
122
974
  var currentId = 0;
123
975
 
124
976
  function post(msg) { self.postMessage(msg); }
@@ -292,6 +1144,37 @@ self.onmessage = async function (ev) {
292
1144
  }
293
1145
  currentId = 0;
294
1146
 
1147
+ } else if (msg.kind === 'sql-run') {
1148
+ currentId = msg.id;
1149
+ if (!pyodide) {
1150
+ currentId = 0;
1151
+ post({ kind: 'sql-ran', id: msg.id, ok: false, results: [], error: { type: 'RuntimeError', message: 'Pyodide 未初始化' } });
1152
+ return;
1153
+ }
1154
+ try {
1155
+ if (!sqlFn) {
1156
+ await pyodide.loadPackage('sqlite3');
1157
+ pyodide.runPython(SQL_SOURCE);
1158
+ sqlFn = pyodide.globals.get('_pye_sql');
1159
+ }
1160
+ var sqlJson = sqlFn(
1161
+ String(msg.database || ':memory:'),
1162
+ String(msg.sql || ''),
1163
+ Number(msg.maxRows) || 200
1164
+ );
1165
+ var sqlParsed = JSON.parse(sqlJson);
1166
+ post({
1167
+ kind: 'sql-ran',
1168
+ id: msg.id,
1169
+ ok: !!sqlParsed.ok,
1170
+ results: sqlParsed.results || [],
1171
+ error: sqlParsed.error
1172
+ });
1173
+ } catch (e) {
1174
+ post({ kind: 'sql-ran', id: msg.id, ok: false, results: [], error: parseError(e) });
1175
+ }
1176
+ currentId = 0;
1177
+
295
1178
  } else if (msg.kind === 'fs-write') {
296
1179
  if (!pyodide) {
297
1180
  post({ kind: 'fs-written', id: msg.id, ok: false, error: { type: 'RuntimeError', message: 'Pyodide 未初始化', traceback: '' } });
@@ -341,118 +1224,141 @@ self.onmessage = async function (ev) {
341
1224
  };
342
1225
  `;
343
1226
  }
344
- const tt = "https://cdn.jsdelivr.net/pyodide/v0.27.2/full/";
345
- class kn {
346
- constructor(r = {}) {
347
- L(this, "status", "idle");
348
- L(this, "version", "");
349
- L(this, "pyodideUrl");
350
- L(this, "worker", null);
351
- L(this, "pending", /* @__PURE__ */ new Map());
352
- L(this, "seq", 1);
353
- L(this, "chain", Promise.resolve());
1227
+ const fr = "https://cdn.jsdelivr.net/pyodide/v0.27.2/full/";
1228
+ class Sa {
1229
+ constructor(n = {}) {
1230
+ ae(this, "status", "idle");
1231
+ ae(this, "version", "");
1232
+ ae(this, "pyodideUrl");
1233
+ ae(this, "worker", null);
1234
+ ae(this, "pending", /* @__PURE__ */ new Map());
1235
+ ae(this, "seq", 1);
1236
+ ae(this, "chain", Promise.resolve());
354
1237
  /** Worker 生命周期代数:interrupt 后递增,用于废弃旧的 waitReady 等待 */
355
- L(this, "generation", 0);
356
- L(this, "statusHandlers", /* @__PURE__ */ new Set());
357
- L(this, "outputHandlers", /* @__PURE__ */ new Set());
358
- L(this, "initErrorHandlers", /* @__PURE__ */ new Set());
359
- this.pyodideUrl = r.pyodideUrl || tt;
1238
+ ae(this, "generation", 0);
1239
+ ae(this, "statusHandlers", /* @__PURE__ */ new Set());
1240
+ ae(this, "outputHandlers", /* @__PURE__ */ new Set());
1241
+ ae(this, "initErrorHandlers", /* @__PURE__ */ new Set());
1242
+ this.pyodideUrl = n.pyodideUrl || fr;
360
1243
  }
361
- on(r, a) {
362
- if (r === "status") {
363
- const s = a;
364
- return this.statusHandlers.add(s), () => this.statusHandlers.delete(s);
1244
+ on(n, s) {
1245
+ if (n === "status") {
1246
+ const i = s;
1247
+ return this.statusHandlers.add(i), () => this.statusHandlers.delete(i);
365
1248
  }
366
- if (r === "output") {
367
- const s = a;
368
- return this.outputHandlers.add(s), () => this.outputHandlers.delete(s);
1249
+ if (n === "output") {
1250
+ const i = s;
1251
+ return this.outputHandlers.add(i), () => this.outputHandlers.delete(i);
369
1252
  }
370
- const i = a;
371
- return this.initErrorHandlers.add(i), () => this.initErrorHandlers.delete(i);
1253
+ const o = s;
1254
+ return this.initErrorHandlers.add(o), () => this.initErrorHandlers.delete(o);
372
1255
  }
373
1256
  /** 预加载 Pyodide(返回 Promise,在就绪或失败时 settle) */
374
- waitReady(r = 18e4) {
375
- const a = this.generation;
376
- return this.ensureWorker(), this.status === "ready" || this.status === "running" ? Promise.resolve() : new Promise((i, s) => {
377
- let P = () => {
378
- }, w = () => {
1257
+ waitReady(n = 18e4) {
1258
+ const s = this.generation;
1259
+ return this.ensureWorker(), this.status === "ready" || this.status === "running" ? Promise.resolve() : new Promise((o, i) => {
1260
+ let p = () => {
1261
+ }, b = () => {
379
1262
  };
380
- const I = () => {
381
- clearTimeout(H), P(), w();
382
- }, H = setTimeout(() => {
383
- I(), s(new Error("Pyodide 加载超时"));
384
- }, r);
385
- P = this.on("status", (C) => {
386
- if (this.generation !== a) {
387
- I(), s(new Error("执行已被中断"));
1263
+ const E = () => {
1264
+ clearTimeout(R), p(), b();
1265
+ }, R = setTimeout(() => {
1266
+ E(), i(new Error("Pyodide 加载超时"));
1267
+ }, n);
1268
+ p = this.on("status", (P) => {
1269
+ if (this.generation !== s) {
1270
+ E(), i(new Error("执行已被中断"));
388
1271
  return;
389
1272
  }
390
- C === "ready" && (I(), i());
391
- }), w = this.on("initError", (C) => {
392
- I(), s(new Error(C));
1273
+ P === "ready" && (E(), o());
1274
+ }), b = this.on("initError", (P) => {
1275
+ E(), i(new Error(P));
393
1276
  });
394
1277
  });
395
1278
  }
396
1279
  /** 执行一段 Python 代码(支持顶层 await);运行器未就绪时先等待初始化完成 */
397
- async run(r, a) {
1280
+ async run(n, s) {
398
1281
  await this.waitReady();
399
- const i = performance.now();
1282
+ const o = performance.now();
400
1283
  this.setStatus("running");
401
- const s = await this.send(
402
- { kind: "run", id: this.seq++, code: r, stdin: a == null ? void 0 : a.stdin },
403
- a == null ? void 0 : a.onOutput
1284
+ const i = await this.send(
1285
+ { kind: "run", id: this.seq++, code: n, stdin: s == null ? void 0 : s.stdin },
1286
+ s == null ? void 0 : s.onOutput
404
1287
  );
405
1288
  return this.status === "running" && this.setStatus("ready"), {
406
- ok: s.ok,
407
- value: s.value,
408
- error: s.error,
409
- interrupted: s.interrupted,
410
- durationMs: performance.now() - i
1289
+ ok: i.ok,
1290
+ value: i.value,
1291
+ error: i.error,
1292
+ interrupted: i.interrupted,
1293
+ durationMs: performance.now() - o
411
1294
  };
412
1295
  }
413
1296
  /** 语法检查:仅在运行器就绪时可用,否则返回 null(静默跳过) */
414
- async checkSyntax(r) {
415
- if (this.status !== "ready" || !r.trim()) return null;
416
- const a = await this.send({ kind: "check", id: this.seq++, code: r });
417
- return a.ok ? null : {
418
- line: a.line ?? 1,
419
- column: a.column ?? 1,
420
- message: a.message ?? "语法错误"
1297
+ async checkSyntax(n) {
1298
+ if (this.status !== "ready" || !n.trim()) return null;
1299
+ const s = await this.send({ kind: "check", id: this.seq++, code: n });
1300
+ return s.ok ? null : {
1301
+ line: s.line ?? 1,
1302
+ column: s.column ?? 1,
1303
+ message: s.message ?? "语法错误"
421
1304
  };
422
1305
  }
423
1306
  /** 写入虚拟文件系统(UTF-8 文本),相对路径基于当前工作目录 */
424
- async writeFile(r, a) {
1307
+ async writeFile(n, s) {
425
1308
  await this.waitReady();
426
- const i = await this.send({ kind: "fs-write", id: this.seq++, path: r, content: a });
427
- return { ok: i.ok, path: i.path, error: i.error };
1309
+ const o = await this.send({ kind: "fs-write", id: this.seq++, path: n, content: s });
1310
+ return { ok: o.ok, path: o.path, error: o.error };
428
1311
  }
429
1312
  /** 读取虚拟文件系统中的文本文件;二进制内容会返回失败 */
430
- async readFile(r) {
1313
+ async readFile(n) {
431
1314
  await this.waitReady();
432
- const a = await this.send({ kind: "fs-read", id: this.seq++, path: r });
433
- return { ok: a.ok, path: a.path, content: a.content, error: a.error };
1315
+ const s = await this.send({ kind: "fs-read", id: this.seq++, path: n });
1316
+ return { ok: s.ok, path: s.path, content: s.content, error: s.error };
434
1317
  }
435
1318
  /** 列出虚拟文件系统目录(递归,跳过 __pycache__ / .cache) */
436
- async listFiles(r = ".") {
1319
+ async listFiles(n = ".") {
437
1320
  await this.waitReady();
438
- const a = await this.send({
1321
+ const s = await this.send({
439
1322
  kind: "fs-list",
440
1323
  id: this.seq++,
441
- path: r,
1324
+ path: n,
442
1325
  recursive: !0
443
1326
  });
444
- return { ok: a.ok, path: a.path, entries: a.entries, error: a.error };
1327
+ return { ok: s.ok, path: s.path, entries: s.entries, error: s.error };
1328
+ }
1329
+ /** 在浏览器内的 SQLite 中执行 SQL(首次调用时自动加载 sqlite3 包) */
1330
+ async executeSql(n) {
1331
+ await this.waitReady();
1332
+ const s = performance.now();
1333
+ this.setStatus("running");
1334
+ try {
1335
+ const o = await this.send({
1336
+ kind: "sql-run",
1337
+ id: this.seq++,
1338
+ database: n.database,
1339
+ sql: n.sql,
1340
+ maxRows: n.maxRows
1341
+ });
1342
+ return {
1343
+ ok: o.ok,
1344
+ results: o.results ?? [],
1345
+ error: o.sqlError ?? (o.interrupted ? { type: "AbortError", message: "SQL 执行已中断" } : void 0),
1346
+ durationMs: performance.now() - s
1347
+ };
1348
+ } finally {
1349
+ this.status === "running" && this.setStatus("ready");
1350
+ }
445
1351
  }
446
1352
  /** 安装第三方包:先尝试内置 wheel(loadPackage),失败后回退 micropip */
447
- async loadPackages(r, a) {
1353
+ async loadPackages(n, s) {
448
1354
  await this.waitReady();
449
- const i = performance.now();
1355
+ const o = performance.now();
450
1356
  this.setStatus("running");
451
- const s = await this.send(
452
- { kind: "install", id: this.seq++, packages: r },
453
- a == null ? void 0 : a.onOutput
1357
+ const i = await this.send(
1358
+ { kind: "install", id: this.seq++, packages: n },
1359
+ s == null ? void 0 : s.onOutput
454
1360
  );
455
- return this.status === "running" && this.setStatus("ready"), { ok: s.ok, error: s.error, durationMs: performance.now() - i };
1361
+ return this.status === "running" && this.setStatus("ready"), { ok: i.ok, error: i.error, durationMs: performance.now() - o };
456
1362
  }
457
1363
  /**
458
1364
  * 中断当前执行:terminate Worker(Pyodide 无法真正中断同步计算),
@@ -461,198 +1367,823 @@ class kn {
461
1367
  interrupt() {
462
1368
  if (!this.worker) return;
463
1369
  this.generation += 1, this.worker.terminate(), this.worker = null;
464
- const r = {
1370
+ const n = {
465
1371
  ok: !1,
466
1372
  interrupted: !0,
467
1373
  error: { type: "KeyboardInterrupt", message: "执行已被用户中断", traceback: "" }
468
1374
  };
469
- this.pending.forEach((a) => a.resolve(r)), this.pending.clear(), this.chain = Promise.resolve(), this.setStatus("idle");
1375
+ this.pending.forEach((s) => s.resolve(n)), this.pending.clear(), this.chain = Promise.resolve(), this.setStatus("idle");
470
1376
  }
471
1377
  ensureWorker() {
472
1378
  if (this.worker) return this.worker;
473
- const r = new Blob([vn(this.pyodideUrl)], { type: "text/javascript" }), a = new Worker(URL.createObjectURL(r));
474
- return a.onmessage = (i) => this.handleMessage(i.data), this.worker = a, this.setStatus("loading"), a;
1379
+ const n = new Blob([wa(this.pyodideUrl)], { type: "text/javascript" }), s = new Worker(URL.createObjectURL(n));
1380
+ return s.onmessage = (o) => this.handleMessage(o.data), this.worker = s, this.setStatus("loading"), s;
475
1381
  }
476
- handleMessage(r) {
477
- switch (r.kind) {
1382
+ handleMessage(n) {
1383
+ switch (n.kind) {
478
1384
  case "ready":
479
- this.version = r.version, this.setStatus("ready");
1385
+ this.version = n.version, this.setStatus("ready");
480
1386
  break;
481
1387
  case "init-error":
482
- this.setStatus("idle"), this.initErrorHandlers.forEach((a) => a(r.message));
1388
+ this.setStatus("idle"), this.initErrorHandlers.forEach((s) => s(n.message));
483
1389
  break;
484
1390
  case "output": {
485
- const a = r.runId ? this.pending.get(r.runId) : void 0;
486
- a != null && a.onOutput ? a.onOutput(r.stream, r.text) : this.outputHandlers.forEach((i) => i(r.stream, r.text));
1391
+ const s = n.runId ? this.pending.get(n.runId) : void 0;
1392
+ s != null && s.onOutput ? s.onOutput(n.stream, n.text) : this.outputHandlers.forEach((o) => o(n.stream, n.text));
487
1393
  break;
488
1394
  }
489
1395
  case "result": {
490
- const a = this.pending.get(r.id);
491
- a && (this.pending.delete(r.id), a.resolve({ ok: r.ok, value: r.value, error: r.error }));
1396
+ const s = this.pending.get(n.id);
1397
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, value: n.value, error: n.error }));
492
1398
  break;
493
1399
  }
494
1400
  case "checked": {
495
- const a = this.pending.get(r.id);
496
- a && (this.pending.delete(r.id), a.resolve({
497
- ok: r.ok,
498
- line: r.line,
499
- column: r.column,
500
- message: r.message
1401
+ const s = this.pending.get(n.id);
1402
+ s && (this.pending.delete(n.id), s.resolve({
1403
+ ok: n.ok,
1404
+ line: n.line,
1405
+ column: n.column,
1406
+ message: n.message
501
1407
  }));
502
1408
  break;
503
1409
  }
504
1410
  case "installed": {
505
- const a = this.pending.get(r.id);
506
- a && (this.pending.delete(r.id), a.resolve({ ok: r.ok, error: r.error }));
1411
+ const s = this.pending.get(n.id);
1412
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, error: n.error }));
507
1413
  break;
508
1414
  }
509
1415
  case "fs-written": {
510
- const a = this.pending.get(r.id);
511
- a && (this.pending.delete(r.id), a.resolve({ ok: r.ok, path: r.path, error: r.error }));
1416
+ const s = this.pending.get(n.id);
1417
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, path: n.path, error: n.error }));
512
1418
  break;
513
1419
  }
514
1420
  case "fs-read": {
515
- const a = this.pending.get(r.id);
516
- a && (this.pending.delete(r.id), a.resolve({
517
- ok: r.ok,
518
- path: r.path,
519
- content: r.content,
520
- error: r.error
1421
+ const s = this.pending.get(n.id);
1422
+ s && (this.pending.delete(n.id), s.resolve({
1423
+ ok: n.ok,
1424
+ path: n.path,
1425
+ content: n.content,
1426
+ error: n.error
521
1427
  }));
522
1428
  break;
523
1429
  }
524
1430
  case "fs-list": {
525
- const a = this.pending.get(r.id);
526
- a && (this.pending.delete(r.id), a.resolve({
527
- ok: r.ok,
528
- path: r.path,
529
- entries: r.entries,
530
- error: r.error
1431
+ const s = this.pending.get(n.id);
1432
+ s && (this.pending.delete(n.id), s.resolve({
1433
+ ok: n.ok,
1434
+ path: n.path,
1435
+ entries: n.entries,
1436
+ error: n.error
531
1437
  }));
532
1438
  break;
533
1439
  }
1440
+ case "sql-ran": {
1441
+ const s = this.pending.get(n.id);
1442
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, results: n.results, sqlError: n.error }));
1443
+ break;
1444
+ }
534
1445
  }
535
1446
  }
536
- send(r, a) {
537
- const i = this.ensureWorker(), s = this.chain.then(
538
- () => new Promise((P) => {
539
- this.pending.set(r.id, { resolve: P, onOutput: a }), i.postMessage(r);
1447
+ send(n, s) {
1448
+ const o = this.ensureWorker(), i = this.chain.then(
1449
+ () => new Promise((p) => {
1450
+ this.pending.set(n.id, { resolve: p, onOutput: s }), o.postMessage(n);
540
1451
  })
541
1452
  );
542
- return this.chain = s.then(
1453
+ return this.chain = i.then(
543
1454
  () => {
544
1455
  },
545
1456
  () => {
546
1457
  }
547
- ), s;
1458
+ ), i;
548
1459
  }
549
- setStatus(r) {
550
- this.status !== r && (this.status = r, this.statusHandlers.forEach((a) => a(r, this.version)));
1460
+ setStatus(n) {
1461
+ this.status !== n && (this.status = n, this.statusHandlers.forEach((s) => s(n, this.version)));
551
1462
  }
552
1463
  }
553
- let be = null;
554
- function nt(u) {
555
- return be ? u != null && u.pyodideUrl && u.pyodideUrl !== tt && console.warn(
1464
+ let Zt = null;
1465
+ function rn(a) {
1466
+ return Zt ? a != null && a.pyodideUrl && a.pyodideUrl !== fr && console.warn(
556
1467
  "[princess-python-editor] Pyodide 运行器已初始化,后续传入的 pyodideUrl 将被忽略。"
557
- ) : be = new kn(u), be;
1468
+ ) : Zt = new Sa(a), Zt;
558
1469
  }
559
- const fe = [
560
- { value: "python", label: "Python", extension: "py" },
561
- { value: "sql", label: "SQL", extension: "sql" },
562
- { value: "javascript", label: "JavaScript", extension: "js" },
563
- { value: "json", label: "JSON", extension: "json" }
564
- ];
565
- function pe(u) {
566
- return fe.find((r) => r.value === u) ?? fe[0];
1470
+ const xa = 3e4;
1471
+ function Ea(a) {
1472
+ const n = (a ?? "").trim().replace(/\/+$/, "");
1473
+ if (!n)
1474
+ throw new Error("未配置文件服务端点(filesEndpoint)");
1475
+ return n;
567
1476
  }
568
- function we(u) {
569
- switch (u) {
570
- case "sql":
571
- return dn();
572
- case "javascript":
573
- return ln();
574
- case "json":
575
- return un();
576
- case "python":
577
- default:
578
- return Qe();
1477
+ async function Nt(a, n, s, o = {}) {
1478
+ var R, P;
1479
+ const i = Ea(a), p = new AbortController(), b = setTimeout(() => p.abort(), o.timeoutMs ?? xa), E = () => p.abort();
1480
+ o.signal && (o.signal.aborted ? p.abort() : o.signal.addEventListener("abort", E));
1481
+ try {
1482
+ const T = await fetch(i + n, {
1483
+ ...s,
1484
+ headers: {
1485
+ "Content-Type": "application/json",
1486
+ ...o.headers ?? {},
1487
+ ...s.headers ?? {}
1488
+ },
1489
+ signal: p.signal
1490
+ }), x = await T.text();
1491
+ let F = null;
1492
+ if (x)
1493
+ try {
1494
+ F = JSON.parse(x);
1495
+ } catch {
1496
+ throw new Error(`文件服务返回的不是合法 JSON(HTTP ${T.status})`);
1497
+ }
1498
+ if (!T.ok || !F || F.ok === !1)
1499
+ throw new Error(((R = F == null ? void 0 : F.error) == null ? void 0 : R.message) ?? `文件服务返回 HTTP ${T.status}`);
1500
+ return F.data;
1501
+ } finally {
1502
+ clearTimeout(b), (P = o.signal) == null || P.removeEventListener("abort", E);
579
1503
  }
580
1504
  }
581
- function bn(u) {
582
- const r = u.lastIndexOf(".");
583
- if (r < 0) return "python";
584
- switch (u.slice(r + 1).toLowerCase()) {
585
- case "sql":
586
- return "sql";
587
- case "js":
588
- case "mjs":
589
- case "cjs":
590
- case "jsx":
591
- case "ts":
592
- return "javascript";
593
- case "json":
594
- return "json";
595
- default:
596
- return "python";
597
- }
1505
+ function qa(a, n = {}) {
1506
+ return Nt(a, "", { method: "GET" }, n);
598
1507
  }
599
- function R(u) {
600
- const r = Array.isArray(u) ? u : [u];
601
- return () => Ke(
602
- "svg",
603
- {
604
- viewBox: "0 0 24 24",
605
- width: "1em",
606
- height: "1em",
607
- fill: "currentColor",
608
- "aria-hidden": "true"
609
- },
610
- r.map((a) => Ke("path", { d: a }))
1508
+ function Ca(a, n, s = {}) {
1509
+ return Nt(
1510
+ a,
1511
+ "",
1512
+ { method: "POST", body: JSON.stringify(n) },
1513
+ s
611
1514
  );
612
1515
  }
613
- const wn = R(
614
- "M8 5.14v13.72a1 1 0 0 0 1.54.84l10.3-6.86a1 1 0 0 0 0-1.68L9.54 4.3A1 1 0 0 0 8 5.14Z"
615
- ), xn = R("M6 6h12v12H6Z"), Ze = R(
616
- "M9 3h6a1 1 0 0 1 1 1v1h4a1 1 0 1 1 0 2h-1.06l-.87 12.13A2 2 0 0 1 16.08 21H7.92a2 2 0 0 1-1.99-1.87L5.06 7H4a1 1 0 0 1 0-2h4V4a1 1 0 0 1 1-1Zm1 2h4V5h-4v0Zm-2.92 2h9.84l-.85 12.07a.5.5 0 0 1-.5.43H7.93a.5.5 0 0 1-.5-.43Z"
617
- ), Sn = R(
618
- "M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 14h-3v3h-2v-3H8v-2h3v-3h2v3h3v2zm-3-7V3.5L18.5 9H13z"
619
- ), En = R(
620
- "M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"
621
- ), Ge = R(
622
- "M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"
623
- ), Xe = R("M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"), Fn = R(
624
- "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"
625
- ), Pn = R("M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"), Ye = R(
626
- "M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7A1 1 0 0 0 5.7 7.11L10.59 12 5.7 16.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 0 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4Z"
627
- ), Cn = R("M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6V5z"), On = {
628
- key: 0,
629
- class: "vpe-toolbar"
630
- }, $n = ["title", "disabled"], Ln = ["disabled"], In = ["disabled"], Mn = ["title", "aria-label"], Rn = ["disabled"], Hn = {
631
- class: "vpe-file",
632
- title: "当前文件名(下载时使用)"
633
- }, Tn = ["value", "disabled"], Nn = ["value"], jn = ["aria-selected", "data-file-id", "title", "onClick", "onKeydown"], _n = { class: "vpe-tab-name" }, Dn = ["title", "aria-label", "disabled", "onClick"], Un = ["disabled"], Vn = { class: "vpe-output-head" }, Bn = {
634
- key: 1,
635
- class: "vpe-empty"
636
- }, zn = {
637
- key: 3,
638
- class: "vpe-fs-panel",
639
- role: "dialog",
640
- "aria-label": "虚拟文件"
641
- }, Kn = { class: "vpe-fs-head" }, An = ["disabled"], qn = { class: "vpe-fs-body" }, Wn = {
642
- key: 0,
643
- class: "vpe-fs-empty"
644
- }, Jn = {
645
- key: 0,
646
- class: "vpe-fs-empty"
647
- }, Zn = ["title"], Gn = { class: "vpe-fs-size" }, Xn = ["title", "aria-label", "onClick"], xe = 1, Yn = /* @__PURE__ */ Nt({
648
- __name: "PythonEditor",
649
- props: {
650
- modelValue: { default: "" },
651
- theme: { default: "light" },
652
- height: { default: 520 },
653
- outputHeight: { default: 180 },
654
- placeholder: { default: "" },
655
- readOnly: { type: Boolean, default: !1 },
1516
+ function Pa(a, n, s = {}) {
1517
+ return Nt(
1518
+ a,
1519
+ `/${encodeURIComponent(n)}`,
1520
+ { method: "GET" },
1521
+ s
1522
+ );
1523
+ }
1524
+ async function Oa(a, n, s = {}) {
1525
+ await Nt(a, `/${encodeURIComponent(n)}`, { method: "DELETE" }, s);
1526
+ }
1527
+ const Ma = 6e4;
1528
+ function sn(a) {
1529
+ const n = (a ?? "").trim().replace(/\/+$/, "");
1530
+ if (!n)
1531
+ throw new Error("未配置 Python 服务端点(pythonEndpoint)");
1532
+ return n;
1533
+ }
1534
+ function vr(a, n) {
1535
+ if (a && typeof a == "object") {
1536
+ const s = a, o = Number(s.line);
1537
+ return {
1538
+ type: typeof s.type == "string" && s.type ? s.type : "PythonError",
1539
+ message: typeof s.message == "string" && s.message ? s.message : n,
1540
+ line: Number.isFinite(o) && o > 0 ? Math.trunc(o) : void 0,
1541
+ traceback: typeof s.traceback == "string" && s.traceback ? s.traceback : void 0
1542
+ };
1543
+ }
1544
+ return { type: "PythonError", message: n };
1545
+ }
1546
+ async function Vi(a, n, s = {}) {
1547
+ var R;
1548
+ const o = sn(a), i = performance.now(), p = new AbortController(), b = setTimeout(() => p.abort(), s.timeoutMs ?? Ma), E = () => p.abort();
1549
+ s.signal && (s.signal.aborted ? p.abort() : s.signal.addEventListener("abort", E));
1550
+ try {
1551
+ const P = await fetch(`${o}/run`, {
1552
+ method: "POST",
1553
+ headers: {
1554
+ "Content-Type": "application/json",
1555
+ ...s.headers ?? {}
1556
+ },
1557
+ body: JSON.stringify({ code: n, stdin: s.stdin ?? "" }),
1558
+ signal: p.signal
1559
+ }), T = await P.text();
1560
+ let x = null;
1561
+ if (T)
1562
+ try {
1563
+ x = JSON.parse(T);
1564
+ } catch {
1565
+ throw new Error(`Python 服务返回的不是合法 JSON(HTTP ${P.status})`);
1566
+ }
1567
+ const F = performance.now() - i;
1568
+ if (!P.ok) {
1569
+ const O = x == null ? void 0 : x.error, V = typeof (O == null ? void 0 : O.message) == "string" && O.message ? O.message : `Python 服务返回 HTTP ${P.status}`;
1570
+ return {
1571
+ ok: !1,
1572
+ stdout: "",
1573
+ stderr: "",
1574
+ durationMs: F,
1575
+ error: {
1576
+ type: typeof (O == null ? void 0 : O.type) == "string" && O.type ? O.type : `Http${P.status}`,
1577
+ message: V
1578
+ }
1579
+ };
1580
+ }
1581
+ if (!x)
1582
+ return {
1583
+ ok: !1,
1584
+ stdout: "",
1585
+ stderr: "",
1586
+ durationMs: F,
1587
+ error: { type: "BadResponse", message: "Python 服务返回内容为空" }
1588
+ };
1589
+ const q = x.ok === !0, G = Number(x.durationMs), ve = Number(x.exitCode);
1590
+ return {
1591
+ ok: q,
1592
+ stdout: typeof x.stdout == "string" ? x.stdout : "",
1593
+ stderr: typeof x.stderr == "string" ? x.stderr : "",
1594
+ exitCode: Number.isFinite(ve) ? Math.trunc(ve) : void 0,
1595
+ durationMs: Number.isFinite(G) && G >= 0 ? G : F,
1596
+ error: q ? void 0 : vr(x.error, "服务端 Python 执行失败")
1597
+ };
1598
+ } finally {
1599
+ clearTimeout(b), (R = s.signal) == null || R.removeEventListener("abort", E);
1600
+ }
1601
+ }
1602
+ function Na(a) {
1603
+ return a === "waiting" || a === "running" || a === "exited" ? a : "exited";
1604
+ }
1605
+ async function an(a, n, s, o, i) {
1606
+ var T;
1607
+ const p = sn(a), b = performance.now(), E = new AbortController(), R = setTimeout(() => E.abort(), o.timeoutMs ?? i), P = () => E.abort();
1608
+ o.signal && (o.signal.aborted ? E.abort() : o.signal.addEventListener("abort", P));
1609
+ try {
1610
+ const x = await fetch(p + n, {
1611
+ ...s,
1612
+ headers: {
1613
+ "Content-Type": "application/json",
1614
+ ...o.headers ?? {}
1615
+ },
1616
+ signal: E.signal
1617
+ }), F = await x.text();
1618
+ let q = null;
1619
+ if (F)
1620
+ try {
1621
+ q = JSON.parse(F);
1622
+ } catch {
1623
+ throw new Error(`Python 服务返回的不是合法 JSON(HTTP ${x.status})`);
1624
+ }
1625
+ const G = performance.now() - b;
1626
+ if (!x.ok || !q) {
1627
+ const V = q == null ? void 0 : q.error, Ue = typeof (V == null ? void 0 : V.message) == "string" && V.message ? V.message : `Python 服务返回 HTTP ${x.status}`;
1628
+ return {
1629
+ sessionId: typeof (q == null ? void 0 : q.sessionId) == "string" ? q.sessionId : "",
1630
+ state: "exited",
1631
+ stdout: "",
1632
+ stderr: "",
1633
+ durationMs: G,
1634
+ error: {
1635
+ type: typeof (V == null ? void 0 : V.type) == "string" && V.type ? V.type : `Http${x.status}`,
1636
+ message: Ue
1637
+ }
1638
+ };
1639
+ }
1640
+ const ve = Number(q.exitCode), O = Number(q.durationMs);
1641
+ return {
1642
+ sessionId: typeof q.sessionId == "string" ? q.sessionId : "",
1643
+ state: Na(q.state),
1644
+ stdout: typeof q.stdout == "string" ? q.stdout : "",
1645
+ stderr: typeof q.stderr == "string" ? q.stderr : "",
1646
+ exitCode: Number.isFinite(ve) ? Math.trunc(ve) : void 0,
1647
+ durationMs: Number.isFinite(O) ? O : G,
1648
+ error: q.error ? vr(q.error, "服务端 Python 执行失败") : void 0
1649
+ };
1650
+ } finally {
1651
+ clearTimeout(R), (T = o.signal) == null || T.removeEventListener("abort", P);
1652
+ }
1653
+ }
1654
+ function Ta(a, n, s = {}) {
1655
+ return an(
1656
+ a,
1657
+ "/sessions",
1658
+ {
1659
+ method: "POST",
1660
+ body: JSON.stringify({
1661
+ code: n,
1662
+ stdin: s.stdin ?? "",
1663
+ timeoutSeconds: s.timeoutSeconds
1664
+ })
1665
+ },
1666
+ s,
1667
+ 2e4
1668
+ );
1669
+ }
1670
+ function La(a, n, s = {}) {
1671
+ return an(
1672
+ a,
1673
+ `/sessions/${encodeURIComponent(n)}`,
1674
+ { method: "GET" },
1675
+ s,
1676
+ 5e3
1677
+ );
1678
+ }
1679
+ function $a(a, n, s, o = {}) {
1680
+ return an(
1681
+ a,
1682
+ `/sessions/${encodeURIComponent(n)}/input`,
1683
+ { method: "POST", body: JSON.stringify({ text: s }) },
1684
+ o,
1685
+ 2e4
1686
+ );
1687
+ }
1688
+ async function Wn(a, n, s = {}) {
1689
+ const o = sn(a);
1690
+ try {
1691
+ await fetch(`${o}/sessions/${encodeURIComponent(n)}/interrupt`, {
1692
+ method: "POST",
1693
+ headers: { ...s.headers ?? {} },
1694
+ signal: s.signal
1695
+ });
1696
+ } catch {
1697
+ }
1698
+ }
1699
+ const ut = [
1700
+ { value: "sqlite", label: "SQLite" },
1701
+ { value: "mysql", label: "MySQL", defaultPort: 3306 },
1702
+ { value: "postgresql", label: "PostgreSQL", defaultPort: 5432 },
1703
+ { value: "sqlserver", label: "SQL Server", defaultPort: 1433 },
1704
+ { value: "oracle", label: "Oracle", defaultPort: 1521 },
1705
+ { value: "clickhouse", label: "ClickHouse", defaultPort: 8123 },
1706
+ { value: "other", label: "其他" }
1707
+ ], Qi = {
1708
+ mode: "sqlite",
1709
+ connection: { dialect: "sqlite", database: ":memory:" },
1710
+ maxRows: 200,
1711
+ timeoutMs: 3e4
1712
+ }, mr = 200, Ot = 3e4;
1713
+ function Fa(a) {
1714
+ return ut.some((n) => n.value === a);
1715
+ }
1716
+ function Yn(a, n, s, o) {
1717
+ const i = typeof a == "number" ? a : Number(a);
1718
+ return Number.isFinite(i) ? Math.min(Math.max(Math.trunc(i), s), o) : n;
1719
+ }
1720
+ function Ra(a) {
1721
+ if (a == null || a === "") return;
1722
+ const n = Number(a);
1723
+ if (!(!Number.isFinite(n) || n <= 0))
1724
+ return Math.min(Math.trunc(n), 65535);
1725
+ }
1726
+ function A(a = {}) {
1727
+ var p, b, E, R, P, T, x;
1728
+ const n = a.mode === "http" ? "http" : "sqlite", s = (p = a.connection) == null ? void 0 : p.dialect, o = Fa(s) ? s : n === "http" ? "mysql" : "sqlite", i = (b = a.connection) == null ? void 0 : b.database;
1729
+ return {
1730
+ mode: n,
1731
+ connectionId: a.connectionId === void 0 || a.connectionId === null ? void 0 : a.connectionId.trim() || void 0,
1732
+ connection: {
1733
+ dialect: o,
1734
+ host: ((E = a.connection) == null ? void 0 : E.host) ?? "",
1735
+ port: Ra((R = a.connection) == null ? void 0 : R.port),
1736
+ user: ((P = a.connection) == null ? void 0 : P.user) ?? "",
1737
+ password: ((T = a.connection) == null ? void 0 : T.password) ?? "",
1738
+ database: i ?? (n === "sqlite" ? ":memory:" : ""),
1739
+ options: (x = a.connection) != null && x.options ? { ...a.connection.options } : void 0
1740
+ },
1741
+ endpoint: a.endpoint ?? "",
1742
+ headers: a.headers ? { ...a.headers } : void 0,
1743
+ maxRows: Yn(a.maxRows, mr, 1, 1e5),
1744
+ timeoutMs: Yn(a.timeoutMs, Ot, 1e3, 6e5)
1745
+ };
1746
+ }
1747
+ function Xn(a) {
1748
+ if (a == null) return null;
1749
+ const n = typeof a;
1750
+ if (n === "string" || n === "number" || n === "boolean")
1751
+ return a;
1752
+ try {
1753
+ return JSON.stringify(a);
1754
+ } catch {
1755
+ return String(a);
1756
+ }
1757
+ }
1758
+ function nn(a) {
1759
+ const n = a ?? {}, s = Array.isArray(n.columns) ? n.columns.map((i) => String(i)) : [], o = Array.isArray(n.rows) ? n.rows.map((i) => Array.isArray(i) ? i.map(Xn) : [Xn(i)]) : [];
1760
+ return {
1761
+ columns: s,
1762
+ rows: o,
1763
+ affectedRows: n.affectedRows === void 0 || n.affectedRows === null ? void 0 : Number(n.affectedRows) || 0,
1764
+ truncated: !!n.truncated
1765
+ };
1766
+ }
1767
+ function on(a, n) {
1768
+ if (a && typeof a == "object") {
1769
+ const s = a;
1770
+ return {
1771
+ type: typeof s.type == "string" && s.type ? s.type : "SqlError",
1772
+ message: typeof s.message == "string" && s.message ? s.message : typeof a == "string" ? a : n,
1773
+ code: typeof s.code == "string" || typeof s.code == "number" ? s.code : void 0
1774
+ };
1775
+ }
1776
+ return { type: "SqlError", message: typeof a == "string" && a ? a : n };
1777
+ }
1778
+ function _a(a) {
1779
+ return a instanceof DOMException && a.name === "AbortError" || a instanceof Error && a.name === "AbortError";
1780
+ }
1781
+ function er(a, n) {
1782
+ if (!a || typeof a != "object")
1783
+ return {
1784
+ ok: !1,
1785
+ results: [],
1786
+ error: { type: "BadResponse", message: "SQL 服务返回内容为空或格式不正确" },
1787
+ durationMs: n
1788
+ };
1789
+ const s = a, o = s.ok !== !1, i = Number(s.durationMs), p = Number.isFinite(i) && i >= 0 ? i : n;
1790
+ if (!o)
1791
+ return {
1792
+ ok: !1,
1793
+ results: [],
1794
+ error: on(s.error, "SQL 服务返回执行失败"),
1795
+ durationMs: p
1796
+ };
1797
+ let b = [];
1798
+ return Array.isArray(s.results) ? b = s.results : (Array.isArray(s.columns) || Array.isArray(s.rows)) && (b = [s]), {
1799
+ ok: !0,
1800
+ results: b.map(nn),
1801
+ durationMs: p
1802
+ };
1803
+ }
1804
+ async function Ia(a, n, s, o) {
1805
+ const i = (a.endpoint ?? "").trim();
1806
+ if (!i)
1807
+ return {
1808
+ ok: !1,
1809
+ results: [],
1810
+ error: {
1811
+ type: "NoEndpoint",
1812
+ message: "未配置 SQL 服务端点(endpoint),请在后端网关地址中填写完整 URL"
1813
+ },
1814
+ durationMs: 0
1815
+ };
1816
+ const p = performance.now(), b = new AbortController();
1817
+ let E = !1;
1818
+ const R = setTimeout(() => {
1819
+ E = !0, b.abort();
1820
+ }, a.timeoutMs ?? Ot), P = () => b.abort();
1821
+ o && (o.aborted ? b.abort() : o.addEventListener("abort", P));
1822
+ try {
1823
+ const T = await fetch(i, {
1824
+ method: "POST",
1825
+ headers: { "Content-Type": "application/json", ...a.headers ?? {} },
1826
+ body: JSON.stringify({
1827
+ connection: a.connection,
1828
+ connectionId: a.connectionId,
1829
+ sql: n,
1830
+ maxRows: s
1831
+ }),
1832
+ signal: b.signal
1833
+ }), x = await T.text();
1834
+ let F = null;
1835
+ if (x)
1836
+ try {
1837
+ F = JSON.parse(x);
1838
+ } catch {
1839
+ return {
1840
+ ok: !1,
1841
+ results: [],
1842
+ error: {
1843
+ type: "BadResponse",
1844
+ message: `SQL 服务返回的不是合法 JSON(HTTP ${T.status})`
1845
+ },
1846
+ durationMs: performance.now() - p
1847
+ };
1848
+ }
1849
+ if (!T.ok) {
1850
+ const q = F ? er(F, performance.now() - p) : null;
1851
+ return {
1852
+ ok: !1,
1853
+ results: [],
1854
+ error: (q == null ? void 0 : q.error) ?? {
1855
+ type: `Http${T.status}`,
1856
+ message: `SQL 服务返回 HTTP ${T.status}${T.statusText ? ` ${T.statusText}` : ""}`
1857
+ },
1858
+ durationMs: performance.now() - p
1859
+ };
1860
+ }
1861
+ return er(F, performance.now() - p);
1862
+ } catch (T) {
1863
+ if (E)
1864
+ return {
1865
+ ok: !1,
1866
+ results: [],
1867
+ error: {
1868
+ type: "Timeout",
1869
+ message: `SQL 请求超时(${a.timeoutMs ?? Ot}ms)`
1870
+ },
1871
+ durationMs: performance.now() - p
1872
+ };
1873
+ throw T;
1874
+ } finally {
1875
+ clearTimeout(R), o == null || o.removeEventListener("abort", P);
1876
+ }
1877
+ }
1878
+ function tr(a, n) {
1879
+ if (!a || typeof a != "object")
1880
+ return {
1881
+ ok: !1,
1882
+ results: [],
1883
+ error: { type: "SqlError", message: "SQL 执行器没有返回结果" },
1884
+ durationMs: n
1885
+ };
1886
+ const s = Number.isFinite(a.durationMs) && a.durationMs >= 0 ? a.durationMs : n;
1887
+ return a.ok ? {
1888
+ ok: !0,
1889
+ results: (a.results ?? []).map(nn),
1890
+ durationMs: s
1891
+ } : {
1892
+ ok: !1,
1893
+ results: (a.results ?? []).map(nn),
1894
+ error: a.error ? on(a.error, "SQL 执行失败") : { type: "SqlError", message: "SQL 执行失败" },
1895
+ durationMs: s
1896
+ };
1897
+ }
1898
+ async function gr(a, n, s = {}) {
1899
+ const o = A(a), i = o.maxRows ?? mr, p = performance.now();
1900
+ if (!n.trim())
1901
+ return {
1902
+ ok: !1,
1903
+ results: [],
1904
+ error: { type: "EmptySql", message: "SQL 内容为空" },
1905
+ durationMs: 0
1906
+ };
1907
+ try {
1908
+ if (s.executor) {
1909
+ const E = await s.executor(
1910
+ { sql: n, connection: o.connection, maxRows: i },
1911
+ { signal: s.signal }
1912
+ );
1913
+ return tr(E, performance.now() - p);
1914
+ }
1915
+ if (o.mode === "http")
1916
+ return await Ia(o, n, i, s.signal);
1917
+ const b = await rn().executeSql({
1918
+ sql: n,
1919
+ database: o.connection.database || ":memory:",
1920
+ maxRows: i
1921
+ });
1922
+ return tr(b, performance.now() - p);
1923
+ } catch (b) {
1924
+ return _a(b) ? {
1925
+ ok: !1,
1926
+ results: [],
1927
+ error: { type: "AbortError", message: "SQL 执行已中断" },
1928
+ durationMs: performance.now() - p
1929
+ } : {
1930
+ ok: !1,
1931
+ results: [],
1932
+ error: on(b, "SQL 执行失败"),
1933
+ durationMs: performance.now() - p
1934
+ };
1935
+ }
1936
+ }
1937
+ function nr(a) {
1938
+ var n;
1939
+ return (n = ut.find((s) => s.value === a)) == null ? void 0 : n.defaultPort;
1940
+ }
1941
+ async function Ha(a, n = {}) {
1942
+ var o;
1943
+ const s = await gr(a, "SELECT 1", n);
1944
+ return s.ok ? {
1945
+ ok: !0,
1946
+ message: `连接成功(${Math.max(1, Math.round(s.durationMs))}ms)`,
1947
+ durationMs: s.durationMs
1948
+ } : {
1949
+ ok: !1,
1950
+ message: ((o = s.error) == null ? void 0 : o.message) ?? "连接失败",
1951
+ durationMs: s.durationMs
1952
+ };
1953
+ }
1954
+ async function ln(a, n, s, o = {}) {
1955
+ var P, T;
1956
+ const i = A(a), p = (i.endpoint ?? "").trim().replace(/\/+$/, "");
1957
+ if (!p)
1958
+ throw new Error("未配置 SQL 服务端点");
1959
+ const b = new AbortController(), E = setTimeout(() => b.abort(), i.timeoutMs ?? Ot), R = () => b.abort();
1960
+ o.signal && (o.signal.aborted ? b.abort() : o.signal.addEventListener("abort", R));
1961
+ try {
1962
+ const x = await fetch(p + n, {
1963
+ ...s,
1964
+ headers: {
1965
+ "Content-Type": "application/json",
1966
+ ...i.headers ?? {},
1967
+ ...s.headers ?? {}
1968
+ },
1969
+ signal: b.signal
1970
+ }), F = await x.text();
1971
+ let q = null;
1972
+ if (F)
1973
+ try {
1974
+ q = JSON.parse(F);
1975
+ } catch {
1976
+ throw new Error(`SQL 服务返回的不是合法 JSON(HTTP ${x.status})`);
1977
+ }
1978
+ if (!x.ok || !q || q.ok === !1)
1979
+ throw new Error(((P = q == null ? void 0 : q.error) == null ? void 0 : P.message) ?? `SQL 服务返回 HTTP ${x.status}`);
1980
+ return q.data;
1981
+ } finally {
1982
+ clearTimeout(E), (T = o.signal) == null || T.removeEventListener("abort", R);
1983
+ }
1984
+ }
1985
+ function Ba(a, n = {}) {
1986
+ return ln(a, "/connections", { method: "GET" }, n);
1987
+ }
1988
+ function Ua(a, n, s, o = {}) {
1989
+ return ln(
1990
+ a,
1991
+ s ? `/connections/${encodeURIComponent(s)}` : "/connections",
1992
+ { method: s ? "PUT" : "POST", body: JSON.stringify(n) },
1993
+ o
1994
+ );
1995
+ }
1996
+ async function rr(a, n, s = {}) {
1997
+ await ln(
1998
+ a,
1999
+ `/connections/${encodeURIComponent(n)}`,
2000
+ { method: "DELETE" },
2001
+ s
2002
+ );
2003
+ }
2004
+ const Mt = [
2005
+ { value: "python", label: "Python", extension: "py" },
2006
+ { value: "sql", label: "SQL", extension: "sql" },
2007
+ { value: "javascript", label: "JavaScript", extension: "js" },
2008
+ { value: "json", label: "JSON", extension: "json" }
2009
+ ];
2010
+ function Ct(a) {
2011
+ return Mt.find((n) => n.value === a) ?? Mt[0];
2012
+ }
2013
+ function Gt(a) {
2014
+ switch (a) {
2015
+ case "sql":
2016
+ return na();
2017
+ case "javascript":
2018
+ return ea();
2019
+ case "json":
2020
+ return ta();
2021
+ case "python":
2022
+ default:
2023
+ return dr();
2024
+ }
2025
+ }
2026
+ function sr(a) {
2027
+ const n = a.lastIndexOf(".");
2028
+ if (n < 0) return "python";
2029
+ switch (a.slice(n + 1).toLowerCase()) {
2030
+ case "sql":
2031
+ return "sql";
2032
+ case "js":
2033
+ case "mjs":
2034
+ case "cjs":
2035
+ case "jsx":
2036
+ case "ts":
2037
+ return "javascript";
2038
+ case "json":
2039
+ return "json";
2040
+ default:
2041
+ return "python";
2042
+ }
2043
+ }
2044
+ const ar = [
2045
+ { value: "light", label: "明亮", dark: !1 },
2046
+ { value: "dark", label: "深色", dark: !0 },
2047
+ { value: "github-light", label: "GitHub 浅色", dark: !1 },
2048
+ { value: "github-dark", label: "GitHub 深色", dark: !0 },
2049
+ { value: "dracula", label: "Dracula", dark: !0 },
2050
+ { value: "nord", label: "Nord", dark: !0 },
2051
+ { value: "solarized-light", label: "Solarized 浅色", dark: !1 },
2052
+ { value: "monokai", label: "Monokai", dark: !0 }
2053
+ ];
2054
+ function Aa(a) {
2055
+ return ar.find((n) => n.value === a) ?? ar[0];
2056
+ }
2057
+ function or(a) {
2058
+ return Aa(a).dark;
2059
+ }
2060
+ function Z(a) {
2061
+ const n = Array.isArray(a) ? a : [a];
2062
+ return () => An(
2063
+ "svg",
2064
+ {
2065
+ viewBox: "0 0 24 24",
2066
+ width: "1em",
2067
+ height: "1em",
2068
+ fill: "currentColor",
2069
+ "aria-hidden": "true"
2070
+ },
2071
+ n.map((s) => An("path", { d: s }))
2072
+ );
2073
+ }
2074
+ const Da = Z(
2075
+ "M8 5.14v13.72a1 1 0 0 0 1.54.84l10.3-6.86a1 1 0 0 0 0-1.68L9.54 4.3A1 1 0 0 0 8 5.14Z"
2076
+ ), za = Z("M6 6h12v12H6Z"), ir = Z(
2077
+ "M9 3h6a1 1 0 0 1 1 1v1h4a1 1 0 1 1 0 2h-1.06l-.87 12.13A2 2 0 0 1 16.08 21H7.92a2 2 0 0 1-1.99-1.87L5.06 7H4a1 1 0 0 1 0-2h4V4a1 1 0 0 1 1-1Zm1 2h4V5h-4v0Zm-2.92 2h9.84l-.85 12.07a.5.5 0 0 1-.5.43H7.93a.5.5 0 0 1-.5-.43Z"
2078
+ ), ja = Z(
2079
+ "M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 14h-3v3h-2v-3H8v-2h3v-3h2v3h3v2zm-3-7V3.5L18.5 9H13z"
2080
+ ), Va = Z(
2081
+ "M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"
2082
+ ), lr = Z(
2083
+ "M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"
2084
+ ), ur = Z("M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"), Qa = Z(
2085
+ "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"
2086
+ ), Ka = Z("M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"), lt = Z(
2087
+ "M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7A1 1 0 0 0 5.7 7.11L10.59 12 5.7 16.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 0 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4Z"
2088
+ ), Ja = Z("M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6V5z"), Za = Z([
2089
+ "M12 2C7.58 2 4 3.34 4 5v14c0 1.66 3.58 3 8 3s8-1.34 8-3V5c0-1.66-3.58-3-8-3Zm6 17c0 .35-2.03 1.4-6 1.4S6 19.35 6 19v-2.68c1.45.74 3.6 1.18 6 1.18s4.55-.44 6-1.18V19Zm0-5c0 .35-2.03 1.4-6 1.4S6 14.35 6 14v-2.68c1.45.74 3.6 1.18 6 1.18s4.55-.44 6-1.18V14Zm-6-3.6c-3.87 0-6-1.02-6-1.4V6.32C7.45 7.06 9.6 7.5 12 7.5s4.55-.44 6-1.18V9c0 .38-2.13 1.4-6 1.4Z"
2090
+ ]), Ga = Z(
2091
+ "M17 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V7l-4-4zm-5 16a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm3-10H5V5h10v4z"
2092
+ ), Wa = Z([
2093
+ "M4 4h16a1 1 0 0 1 1 1v5H3V5a1 1 0 0 1 1-1Zm-1 8h18v5H3v-5Z",
2094
+ "M18 15.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
2095
+ ]), Ya = {
2096
+ key: 0,
2097
+ class: "vpe-toolbar"
2098
+ }, Xa = ["title", "disabled"], eo = ["disabled"], to = ["disabled"], no = ["title", "disabled"], ro = ["title", "aria-label"], so = { key: 2 }, ao = { key: 3 }, oo = ["disabled"], io = {
2099
+ class: "vpe-file",
2100
+ title: "当前文件名(下载时使用)"
2101
+ }, lo = ["disabled"], uo = {
2102
+ value: "",
2103
+ disabled: ""
2104
+ }, co = ["value"], po = {
2105
+ key: 6,
2106
+ class: "vpe-runtime-group"
2107
+ }, fo = ["value", "disabled"], vo = ["value"], mo = ["aria-selected", "data-file-id", "title", "onClick", "onKeydown"], go = { class: "vpe-tab-name" }, yo = ["title", "aria-label", "disabled", "onClick"], ho = ["disabled"], bo = { class: "vpe-output-head" }, ko = { class: "vpe-output-main" }, wo = {
2108
+ key: 0,
2109
+ class: "vpe-sql-results"
2110
+ }, So = { class: "vpe-sql-result-head" }, xo = {
2111
+ key: 0,
2112
+ class: "vpe-sql-table-wrap"
2113
+ }, Eo = { class: "vpe-sql-table" }, qo = {
2114
+ key: 0,
2115
+ class: "vpe-sql-empty"
2116
+ }, Co = {
2117
+ key: 1,
2118
+ class: "vpe-sql-affected"
2119
+ }, Po = {
2120
+ key: 1,
2121
+ class: "vpe-empty"
2122
+ }, Oo = {
2123
+ key: 0,
2124
+ class: "vpe-terminal-input"
2125
+ }, Mo = ["onKeydown"], No = {
2126
+ key: 4,
2127
+ class: "vpe-fs-panel",
2128
+ role: "dialog",
2129
+ "aria-label": "虚拟文件"
2130
+ }, To = { class: "vpe-fs-head" }, Lo = ["disabled"], $o = { class: "vpe-fs-body" }, Fo = {
2131
+ key: 0,
2132
+ class: "vpe-fs-empty"
2133
+ }, Ro = {
2134
+ key: 0,
2135
+ class: "vpe-fs-empty"
2136
+ }, _o = ["title"], Io = { class: "vpe-fs-size" }, Ho = ["title", "aria-label", "onClick"], Bo = {
2137
+ key: 5,
2138
+ class: "vpe-fs-panel",
2139
+ role: "dialog",
2140
+ "aria-label": "服务端文件"
2141
+ }, Uo = { class: "vpe-fs-head" }, Ao = ["disabled"], Do = { class: "vpe-fs-body" }, zo = {
2142
+ key: 0,
2143
+ class: "vpe-fs-empty"
2144
+ }, jo = {
2145
+ key: 0,
2146
+ class: "vpe-fs-empty"
2147
+ }, Vo = ["title"], Qo = ["title"], Ko = ["title", "disabled", "onClick"], Jo = ["title", "disabled", "onClick"], Zo = {
2148
+ key: 1,
2149
+ class: "vpe-sql-hint vpe-sql-hint--error"
2150
+ }, Go = {
2151
+ key: 6,
2152
+ class: "vpe-sql-panel",
2153
+ role: "dialog",
2154
+ "aria-label": "SQL 连接配置"
2155
+ }, Wo = { class: "vpe-fs-head" }, Yo = { class: "vpe-fs-title" }, Xo = { class: "vpe-sql-body" }, ei = { class: "vpe-sql-field" }, ti = { class: "vpe-sql-field" }, ni = { class: "vpe-sql-field" }, ri = { class: "vpe-sql-field" }, si = ["value"], ai = { class: "vpe-sql-row" }, oi = { class: "vpe-sql-field vpe-sql-field--grow" }, ii = { class: "vpe-sql-field vpe-sql-field--grow" }, li = { class: "vpe-sql-row" }, ui = { class: "vpe-sql-field vpe-sql-field--grow" }, ci = { class: "vpe-sql-field vpe-sql-field--grow" }, di = ["placeholder"], pi = { class: "vpe-sql-field" }, fi = {
2156
+ key: 0,
2157
+ class: "vpe-sql-field"
2158
+ }, vi = {
2159
+ key: 1,
2160
+ class: "vpe-sql-hint"
2161
+ }, mi = { class: "vpe-sql-actions" }, gi = ["disabled"], yi = ["disabled"], hi = ["disabled"], bi = {
2162
+ key: 3,
2163
+ class: "vpe-sql-test vpe-sql-test--err"
2164
+ }, ki = {
2165
+ key: 7,
2166
+ class: "vpe-sql-manager-panel",
2167
+ role: "dialog",
2168
+ "aria-label": "连接管理"
2169
+ }, wi = { class: "vpe-fs-head" }, Si = ["disabled"], xi = { class: "vpe-sql-manager-body" }, Ei = {
2170
+ key: 0,
2171
+ class: "vpe-fs-empty"
2172
+ }, qi = {
2173
+ key: 0,
2174
+ class: "vpe-fs-empty"
2175
+ }, Ci = { class: "vpe-sql-manager-main" }, Pi = ["title"], Oi = { class: "vpe-sql-manager-meta" }, Mi = ["onClick"], Ni = ["disabled", "onClick"], Ti = {
2176
+ key: 1,
2177
+ class: "vpe-sql-hint vpe-sql-hint--error"
2178
+ }, Wt = 1, cr = 80, Li = /* @__PURE__ */ Ms({
2179
+ __name: "PythonEditor",
2180
+ props: {
2181
+ modelValue: { default: "" },
2182
+ theme: { default: "light" },
2183
+ height: { default: 520 },
2184
+ outputHeight: { default: 180 },
2185
+ placeholder: { default: "" },
2186
+ readOnly: { type: Boolean, default: !1 },
656
2187
  autofocus: { type: Boolean, default: !1 },
657
2188
  showToolbar: { type: Boolean, default: !0 },
658
2189
  showTabs: { type: Boolean, default: !0 },
@@ -667,401 +2198,925 @@ const wn = R(
667
2198
  stdin: { default: "" },
668
2199
  syncFilesOnRun: { type: Boolean, default: !0 },
669
2200
  storageKey: { default: "" },
670
- preloadPackages: { default: () => [] }
2201
+ preloadPackages: { default: () => [] },
2202
+ sqlConfig: { default: () => ({}) },
2203
+ sqlExecutor: { type: Function, default: void 0 },
2204
+ showSqlConfig: { type: Boolean, default: !0 },
2205
+ sqlEndpointLocked: { type: Boolean, default: !1 },
2206
+ filesEndpoint: { default: "" },
2207
+ filesHeaders: { default: void 0 },
2208
+ pythonEndpoint: { default: "" },
2209
+ pythonHeaders: { default: void 0 },
2210
+ runtime: { default: "browser" }
671
2211
  },
672
- emits: ["update:modelValue", "ready", "statusChange", "runStart", "runOutput", "runError", "runFinish", "loadError", "update:fileName", "update:language", "newFile", "fileClose", "fileSwitch", "copy", "download", "fileOpen", "fsDownload"],
673
- setup(u, { expose: r, emit: a }) {
674
- const i = u, s = a, P = F(), w = F(), I = F(), H = F(), C = F([]), M = F("idle"), T = F(!1), D = F(!1), N = F(!1), j = F([]);
675
- let J = !1, Z, he = !1, oe = !1, G = !1, o = null, h = 0, x = 0, O = null, U = null, X;
676
- function le(e, t, n) {
677
- return { id: ++x, name: e, language: t, code: n };
678
- }
679
- const f = F([le(i.fileName, i.language, i.modelValue)]), _ = F(f.value[0].id), y = ie(
680
- () => f.value.find((e) => e.id === _.value) ?? f.value[0]
681
- ), A = ie({
682
- get: () => y.value.name,
2212
+ emits: ["update:modelValue", "ready", "statusChange", "runStart", "runOutput", "runError", "runFinish", "loadError", "update:fileName", "update:language", "newFile", "fileClose", "fileSwitch", "copy", "download", "fileOpen", "fsDownload", "update:sqlConfig", "update:runtime", "sqlResult", "sqlError"],
2213
+ setup(a, { expose: n, emit: s }) {
2214
+ const o = a, i = s, p = C(), b = C(), E = C(), R = C(), P = C(), T = C(), x = C(null), F = C(!1), q = Dn(/* @__PURE__ */ new Map()), G = U(() => pe().lines), ve = U(() => pe().sqlResults), O = Dn(/* @__PURE__ */ new Map()), V = U(() => O.get(w.value.id) ?? null), Ue = U(() => {
2215
+ var e;
2216
+ return !!((e = V.value) != null && e.busy);
2217
+ }), Ae = U(() => {
2218
+ var e;
2219
+ return !!((e = V.value) != null && e.waiting);
2220
+ }), H = U({
2221
+ get: () => {
2222
+ var e;
2223
+ return ((e = V.value) == null ? void 0 : e.input) ?? "";
2224
+ },
683
2225
  set: (e) => {
684
- const t = y.value;
685
- t.name !== e && (t.name = e, s("update:fileName", e));
686
- }
687
- }), Pe = new ce(), Ce = new ce(), me = new ce(), ye = new ce(), b = nt(i.pyodideUrl ? { pyodideUrl: i.pyodideUrl } : void 0), rt = ie(() => ({
688
- height: typeof i.height == "number" ? `${i.height}px` : i.height
689
- })), at = ie(
690
- () => typeof i.outputHeight == "number" ? `${i.outputHeight}px` : i.outputHeight
691
- ), it = ie(
692
- () => ({
693
- idle: "未加载",
694
- loading: "正在加载 Pyodide…",
695
- ready: "就绪",
696
- running: "运行中"
697
- })[M.value]
698
- );
699
- function Y(e) {
2226
+ const t = V.value;
2227
+ t && (t.input = e);
2228
+ }
2229
+ }), k = C(null), I = C("idle"), Q = C(o.runtime), me = C(!1), qe = C(!1), Ye = C(!1), Xe = C([]), Se = C(!1), dt = C(!1), et = C([]), De = C(""), W = C(!1), Fe = C(!1), xe = C(!1), Re = C(!1), tt = C(""), pt = C(!1), f = C(A(o.sqlConfig)), Ce = C([]), ze = C(!1), Pe = C(""), ee = C(""), te = C(!1), ne = C(""), je = C(!1), _e = C(!1), Ve = C(""), ft = C(!1);
2230
+ let Tt = !1, vt, un = !1, Lt = !1, cn = !1, M = null, yr = 0, hr = 0, mt = null, gt = null, $t, ce = null, Y = null, re = null, se = null, br = 0, nt = 0;
2231
+ function Qe(e, t, r) {
2232
+ return { id: ++hr, name: e, language: t, code: r };
2233
+ }
2234
+ const L = C([Qe(o.fileName, o.language, o.modelValue)]), Ee = C(L.value[0].id), w = U(
2235
+ () => L.value.find((e) => e.id === Ee.value) ?? L.value[0]
2236
+ ), Ie = U({
2237
+ get: () => w.value.name,
2238
+ set: (e) => {
2239
+ const t = w.value;
2240
+ t.name !== e && (t.name = e, i("update:fileName", e));
2241
+ }
2242
+ }), dn = new Kt(), Ft = new Kt(), Rt = new Kt(), z = rn(o.pyodideUrl ? { pyodideUrl: o.pyodideUrl } : void 0), kr = U(() => ({
2243
+ height: typeof o.height == "number" ? `${o.height}px` : o.height
2244
+ })), wr = U(() => [
2245
+ `vpe-theme-${o.theme}`,
2246
+ or(o.theme) ? "vpe-dark" : ""
2247
+ ]);
2248
+ let pn = 0, _t = 0, Ke = null;
2249
+ const Sr = U(
2250
+ () => x.value !== null ? `${x.value}px` : typeof o.outputHeight == "number" ? `${o.outputHeight}px` : o.outputHeight
2251
+ ), de = U(() => w.value.language === "sql"), fn = U(() => w.value.language === "python"), yt = U(() => !!(o.pythonEndpoint ?? "").trim()), Je = U(
2252
+ () => fn.value && yt.value && Q.value === "server"
2253
+ ), Oe = U(() => !!(o.filesEndpoint ?? "").trim()), It = U(() => Ue.value || xe.value && k.value === w.value.id ? !0 : I.value === "running" && k.value === w.value.id), xr = U(() => de.value && f.value.mode === "http" ? xe.value && k.value === w.value.id ? "查询中" : "外部服务" : Je.value ? Ue.value ? Ae.value ? "等待输入" : "执行中" : "服务端" : I.value === "running" && k.value !== w.value.id ? "就绪" : {
2254
+ idle: "未加载",
2255
+ loading: "正在加载 Pyodide…",
2256
+ ready: "就绪",
2257
+ running: "运行中"
2258
+ }[I.value]), Er = U(() => de.value && f.value.mode === "http" ? xe.value && k.value === w.value.id ? "running" : "ready" : Je.value ? Ue.value ? Ae.value ? "loading" : "running" : "ready" : I.value === "running" && k.value !== w.value.id ? "ready" : I.value), qr = U(() => de.value ? "执行 SQL (Ctrl+Enter)" : Je.value ? "运行(服务端 Python,Ctrl+Enter)" : w.value.language === "python" ? "运行 (Ctrl+Enter)" : "仅支持执行 Python / SQL 文件"), Cr = U(() => It.value ? !0 : Je.value || de.value ? !1 : I.value === "loading" || w.value.language !== "python"), Pr = U(() => f.value.mode === "http" ? f.value.connectionId ? "SQL 连接配置" : "新建 SQL 连接" : "SQL 连接");
2259
+ function Ze(e) {
700
2260
  return { ...e };
701
2261
  }
702
- function Q(e, t) {
703
- C.value.push({ id: ++h, stream: e, text: t });
2262
+ function pe(e = w.value.id) {
2263
+ let t = q.get(e);
2264
+ return t || (t = { lines: [], sqlResults: [] }, q.set(e, t)), t;
704
2265
  }
705
- function p(e) {
706
- Q("system", e);
2266
+ function ge(e, t, r) {
2267
+ pe(r).lines.push({ id: ++yr, stream: e, text: t });
707
2268
  }
708
- function st(e) {
709
- return fe.some((t) => t.value === e);
2269
+ function h(e, t) {
2270
+ ge("system", e, t);
710
2271
  }
711
- function ot() {
712
- if (!i.storageKey || typeof window > "u") return null;
2272
+ function Or(e) {
2273
+ return Mt.some((t) => t.value === e);
2274
+ }
2275
+ function Mr() {
2276
+ if (!o.storageKey || typeof window > "u") return null;
713
2277
  try {
714
- const e = window.localStorage.getItem(i.storageKey);
2278
+ const e = window.localStorage.getItem(o.storageKey);
715
2279
  if (!e) return null;
716
2280
  const t = JSON.parse(e);
717
- if (t.version !== xe || !Array.isArray(t.files)) return null;
718
- const n = [];
719
- for (const m of t.files) {
720
- if (!m || typeof m.name != "string" || typeof m.code != "string" || !m.name.trim()) continue;
721
- const k = st(m.language) ? m.language : "python";
722
- n.push({ name: m.name, language: k, code: m.code });
2281
+ if (t.version !== Wt || !Array.isArray(t.files)) return null;
2282
+ const r = [];
2283
+ for (const y of t.files) {
2284
+ if (!y || typeof y.name != "string" || typeof y.code != "string" || !y.name.trim()) continue;
2285
+ const S = Or(y.language) ? y.language : "python";
2286
+ r.push({ name: y.name, language: S, code: y.code });
723
2287
  }
724
- if (!n.length) return null;
725
- const l = typeof t.activeIndex == "number" ? t.activeIndex : 0, d = Math.min(Math.max(Math.trunc(l) || 0, 0), n.length - 1);
726
- return { version: xe, files: n, activeIndex: d };
2288
+ if (!r.length) return null;
2289
+ const u = typeof t.activeIndex == "number" ? t.activeIndex : 0, c = Math.min(Math.max(Math.trunc(u) || 0, 0), r.length - 1);
2290
+ return { version: Wt, files: r, activeIndex: c };
727
2291
  } catch {
728
2292
  return null;
729
2293
  }
730
2294
  }
731
- function lt() {
732
- const e = ot();
2295
+ function Nr() {
2296
+ const e = Mr();
733
2297
  if (!e) return;
734
- f.value = e.files.map((n) => le(n.name, n.language, n.code));
735
- const t = f.value[e.activeIndex] ?? f.value[0];
736
- _.value = t.id, p(`已恢复上次编辑内容(${f.value.length} 个文件)`), s("update:modelValue", t.code), s("update:fileName", t.name), s("update:language", t.language);
2298
+ L.value = e.files.map((r) => Qe(r.name, r.language, r.code));
2299
+ const t = L.value[e.activeIndex] ?? L.value[0];
2300
+ Ee.value = t.id, h(`已恢复上次编辑内容(${L.value.length} 个文件)`), i("update:modelValue", t.code), i("update:fileName", t.name), i("update:language", t.language);
737
2301
  }
738
- function Oe() {
739
- if (!(!J || oe || !i.storageKey || typeof window > "u"))
2302
+ function vn() {
2303
+ if (!(!Tt || Lt || !o.storageKey || typeof window > "u"))
740
2304
  try {
741
2305
  const e = {
742
- version: xe,
743
- files: f.value.map((t) => ({
2306
+ version: Wt,
2307
+ files: L.value.map((t) => ({
744
2308
  name: t.name,
745
2309
  language: t.language,
746
2310
  code: t.code
747
2311
  })),
748
2312
  activeIndex: Math.max(
749
- f.value.findIndex((t) => t.id === _.value),
2313
+ L.value.findIndex((t) => t.id === Ee.value),
750
2314
  0
751
2315
  )
752
2316
  };
753
- window.localStorage.setItem(i.storageKey, JSON.stringify(e));
2317
+ window.localStorage.setItem(o.storageKey, JSON.stringify(e));
754
2318
  } catch (e) {
755
- he || (he = !0, p(`本地草稿保存失败:${e instanceof Error ? e.message : String(e)}`));
2319
+ un || (un = !0, h(`本地草稿保存失败:${e instanceof Error ? e.message : String(e)}`));
756
2320
  }
757
2321
  }
758
- function ut() {
759
- !J || !i.storageKey || typeof window > "u" || (oe = !1, window.clearTimeout(Z), Z = window.setTimeout(Oe, 400));
2322
+ function Tr() {
2323
+ !Tt || !o.storageKey || typeof window > "u" || (Lt = !1, window.clearTimeout(vt), vt = window.setTimeout(vn, 400));
760
2324
  }
761
- function dt() {
762
- if (!(!i.storageKey || typeof window > "u")) {
763
- window.clearTimeout(Z);
2325
+ function Lr() {
2326
+ if (!(!o.storageKey || typeof window > "u")) {
2327
+ window.clearTimeout(vt);
764
2328
  try {
765
- window.localStorage.removeItem(i.storageKey), oe = !0, p("已清除本地草稿");
2329
+ window.localStorage.removeItem(o.storageKey), Lt = !0, h("已清除本地草稿");
766
2330
  } catch (e) {
767
- p(`清除本地草稿失败:${e instanceof Error ? e.message : String(e)}`);
2331
+ h(`清除本地草稿失败:${e instanceof Error ? e.message : String(e)}`);
768
2332
  }
769
2333
  }
770
2334
  }
771
- function ee(e) {
772
- if (!o) return;
2335
+ function Me(e) {
2336
+ if (!M) return;
773
2337
  const t = e ? [e] : [];
774
- o.dispatch({ effects: et.of(t) });
2338
+ M.dispatch({ effects: pr.of(t) });
775
2339
  }
776
- function ct() {
777
- const e = i.modelValue;
778
- if (o) {
779
- e !== o.state.doc.toString() && o.dispatch({ changes: { from: 0, to: o.state.doc.length, insert: e } });
2340
+ function $r() {
2341
+ const e = o.modelValue;
2342
+ if (M) {
2343
+ e !== M.state.doc.toString() && M.dispatch({ changes: { from: 0, to: M.state.doc.length, insert: e } });
780
2344
  return;
781
2345
  }
782
- const t = y.value;
2346
+ const t = w.value;
783
2347
  t.code !== e && (t.code = e);
784
2348
  }
785
- function te() {
786
- return o ? o.state.doc.toString() : y.value.code;
2349
+ function Ne() {
2350
+ return M ? M.state.doc.toString() : w.value.code;
787
2351
  }
788
- function ge(e) {
789
- if (o) {
790
- e !== o.state.doc.toString() && o.dispatch({ changes: { from: 0, to: o.state.doc.length, insert: e } });
2352
+ function ht(e) {
2353
+ if (M) {
2354
+ e !== M.state.doc.toString() && M.dispatch({ changes: { from: 0, to: M.state.doc.length, insert: e } });
791
2355
  return;
792
2356
  }
793
- const t = y.value;
794
- t.code = e, e !== i.modelValue && s("update:modelValue", e);
2357
+ const t = w.value;
2358
+ t.code = e, e !== o.modelValue && i("update:modelValue", e);
795
2359
  }
796
- function ve(e) {
797
- return i.disableLint || e !== "python" ? [] : yn(b, i.lintDelay);
2360
+ function Ht(e) {
2361
+ return o.disableLint || e !== "python" ? [] : ha(z, o.lintDelay);
798
2362
  }
799
- function $e(e) {
800
- const t = y.value;
2363
+ function Bt(e) {
2364
+ const t = w.value;
801
2365
  if (t.language !== e) {
802
- if (t.language = e, ee(void 0), o == null || o.dispatch({
2366
+ if (t.language = e, pe(t.id).sqlResults = [], Me(void 0), M == null || M.dispatch({
803
2367
  effects: [
804
- me.reconfigure(we(e)),
805
- ye.reconfigure(ve(e))
2368
+ Ft.reconfigure(Gt(e)),
2369
+ Rt.reconfigure(Ht(e))
806
2370
  ]
807
2371
  }), /^untitled(-\d+)?\.[^.]+$/.test(t.name)) {
808
- const l = `${t.name.slice(0, t.name.lastIndexOf("."))}.${pe(e).extension}`;
809
- f.value.some((d) => d.id !== t.id && d.name === l) || (t.name = l, s("update:fileName", l));
2372
+ const u = `${t.name.slice(0, t.name.lastIndexOf("."))}.${Ct(e).extension}`;
2373
+ L.value.some((c) => c.id !== t.id && c.name === u) || (t.name = u, i("update:fileName", u));
810
2374
  }
811
- s("update:language", e);
2375
+ i("update:language", e);
812
2376
  }
813
2377
  }
814
- function Le(e, t) {
815
- const l = e.trim().replace(/[\\/:*?"<>|]+/g, "_").replace(/\.+$/, "") || "untitled";
816
- return /\.[^.\\/]+$/.test(l) ? l : `${l}.${pe(t).extension}`;
2378
+ function Ut(e, t) {
2379
+ const u = e.trim().replace(/[\\/:*?"<>|]+/g, "_").replace(/\.+$/, "") || "untitled";
2380
+ return /\.[^.\\/]+$/.test(u) ? u : `${u}.${Ct(t).extension}`;
817
2381
  }
818
- function pt(e) {
819
- const t = pe(e).extension, n = new Set(f.value.map((m) => m.name));
820
- let l = `untitled.${t}`, d = 2;
821
- for (; n.has(l); )
822
- l = `untitled-${d}.${t}`, d += 1;
823
- return l;
2382
+ function mn(e) {
2383
+ const t = Ct(e).extension, r = new Set(L.value.map((y) => y.name));
2384
+ let u = `untitled.${t}`, c = 2;
2385
+ for (; r.has(u); )
2386
+ u = `untitled-${c}.${t}`, c += 1;
2387
+ return u;
824
2388
  }
825
- function ft(e) {
826
- if (!f.value.some((k) => k.name === e)) return e;
827
- const t = e.lastIndexOf("."), n = t > 0 ? e.slice(0, t) : e, l = t > 0 ? e.slice(t) : "";
828
- let d = 2, m = `${n}-${d}${l}`;
829
- for (; f.value.some((k) => k.name === m); )
830
- d += 1, m = `${n}-${d}${l}`;
831
- return m;
2389
+ function gn(e) {
2390
+ if (!L.value.some((S) => S.name === e)) return e;
2391
+ const t = e.lastIndexOf("."), r = t > 0 ? e.slice(0, t) : e, u = t > 0 ? e.slice(t) : "";
2392
+ let c = 2, y = `${r}-${c}${u}`;
2393
+ for (; L.value.some((S) => S.name === y); )
2394
+ c += 1, y = `${r}-${c}${u}`;
2395
+ return y;
832
2396
  }
833
- let ne = 0;
834
- function ht(e) {
2397
+ let Ge = 0;
2398
+ function Fr(e) {
835
2399
  return !!e && e !== "." && e !== ".." && !e.includes("/") && !e.includes("\\");
836
2400
  }
837
- async function mt() {
2401
+ async function Rr() {
838
2402
  var t;
839
- if (!i.syncFilesOnRun) return;
840
- const e = f.value.filter((n) => n.language === "python");
841
- for (const n of e) {
842
- if (!ht(n.name)) {
843
- p(`跳过同步文件:${n.name}(文件名不能包含路径分隔符)`);
2403
+ if (!o.syncFilesOnRun) return;
2404
+ const e = L.value.filter((r) => r.language === "python");
2405
+ for (const r of e) {
2406
+ if (!Fr(r.name)) {
2407
+ h(`跳过同步文件:${r.name}(文件名不能包含路径分隔符)`);
844
2408
  continue;
845
2409
  }
846
- const l = await b.writeFile(n.name, n.code);
847
- l.ok || p(`同步文件失败:${n.name}(${((t = l.error) == null ? void 0 : t.message) ?? "未知错误"})`);
2410
+ const u = await z.writeFile(r.name, r.code);
2411
+ u.ok || h(`同步文件失败:${r.name}(${((t = u.error) == null ? void 0 : t.message) ?? "未知错误"})`);
848
2412
  }
849
2413
  }
850
- async function Ie() {
851
- var d, m, k;
852
- if (M.value === "loading" || M.value === "running") return;
853
- const e = y.value.language;
2414
+ function rt() {
2415
+ Y == null || Y.abort(), Y = null, Re.value = !1, tt.value = "", pt.value = !1;
2416
+ }
2417
+ function ye() {
2418
+ rt(), ne.value = "";
2419
+ const e = A(f.value);
2420
+ f.value = e, i("update:sqlConfig", A(e));
2421
+ }
2422
+ function _r() {
2423
+ _e.value = !1, Fe.value = !0, fe();
2424
+ }
2425
+ function Ir() {
2426
+ f.value.mode !== "http" && (f.value = A({ ...f.value, mode: "http" }), i("update:sqlConfig", A(f.value))), Fe.value = !1, _e.value = !0, Ve.value = "", ft.value = !1, fe();
2427
+ }
2428
+ function Hr() {
2429
+ const e = f.value.connection.dialect, t = e === "sqlite" ? "mysql" : e;
2430
+ f.value = A({
2431
+ mode: "http",
2432
+ endpoint: f.value.endpoint,
2433
+ headers: f.value.headers,
2434
+ maxRows: f.value.maxRows,
2435
+ timeoutMs: f.value.timeoutMs,
2436
+ connection: { dialect: t, port: nr(t) }
2437
+ }), ee.value = "", ne.value = "", Pe.value = "", rt(), i("update:sqlConfig", A(f.value)), _e.value = !1, Fe.value = !0, fe();
2438
+ }
2439
+ function yn() {
2440
+ Fe.value = !1;
2441
+ }
2442
+ function Br() {
2443
+ const e = f.value;
2444
+ e.mode === "sqlite" ? (e.connectionId = void 0, e.connection.dialect = "sqlite", e.connection.database || (e.connection.database = ":memory:"), ee.value = "") : (e.connection.dialect === "sqlite" && (e.connection.dialect = "mysql", e.connection.port = nr("mysql")), e.connection.database === ":memory:" && (e.connection.database = "")), ye(), e.mode === "http" && fe();
2445
+ }
2446
+ function Ur() {
2447
+ const e = f.value.connection, t = ut.find((u) => u.value === e.dialect), r = ut.map((u) => u.defaultPort);
2448
+ t != null && t.defaultPort && (!e.port || r.includes(e.port)) && (e.port = t.defaultPort), ye();
2449
+ }
2450
+ async function fe() {
2451
+ const e = A(f.value);
2452
+ if (!e.endpoint) {
2453
+ Ce.value = [], Pe.value = "";
2454
+ return;
2455
+ }
2456
+ re == null || re.abort();
2457
+ const t = new AbortController();
2458
+ re = t, ze.value = !0, Pe.value = "";
2459
+ try {
2460
+ const r = await Ba(e, { signal: t.signal });
2461
+ if (re !== t) return;
2462
+ Ce.value = r;
2463
+ const u = r.find((c) => c.id === f.value.connectionId);
2464
+ u ? ee.value = u.name : f.value.connectionId && (f.value.connectionId = void 0, ee.value = "");
2465
+ } catch (r) {
2466
+ if (re !== t) return;
2467
+ Ce.value = [], Pe.value = r instanceof Error ? r.message : String(r);
2468
+ } finally {
2469
+ re === t && (re = null, ze.value = !1);
2470
+ }
2471
+ }
2472
+ function hn(e) {
2473
+ f.value = A({
2474
+ mode: "http",
2475
+ endpoint: f.value.endpoint,
2476
+ headers: f.value.headers,
2477
+ maxRows: f.value.maxRows,
2478
+ timeoutMs: f.value.timeoutMs,
2479
+ connectionId: e.id,
2480
+ connection: {
2481
+ dialect: e.dialect,
2482
+ host: e.host ?? "",
2483
+ port: e.port,
2484
+ user: e.user ?? "",
2485
+ password: "",
2486
+ database: e.database ?? "",
2487
+ options: e.options
2488
+ }
2489
+ }), ee.value = e.name, ne.value = "", rt(), i("update:sqlConfig", A(f.value));
2490
+ }
2491
+ function Ar() {
2492
+ Fe.value = !1, _e.value = !1;
2493
+ const e = Ce.value.find((t) => t.id === f.value.connectionId);
2494
+ if (!e) {
2495
+ f.value.connectionId = void 0, f.value.connection.password = "", ee.value = "", ye();
2496
+ return;
2497
+ }
2498
+ hn(e);
2499
+ }
2500
+ function Dr(e) {
2501
+ hn(e), _e.value = !1, Fe.value = !0;
2502
+ }
2503
+ async function zr() {
2504
+ if (te.value) return;
2505
+ const e = ee.value.trim();
2506
+ if (!e) {
2507
+ je.value = !1, ne.value = "请先填写连接名称";
2508
+ return;
2509
+ }
2510
+ const t = A(f.value), r = {
2511
+ name: e,
2512
+ dialect: t.connection.dialect,
2513
+ host: t.connection.host,
2514
+ port: t.connection.port,
2515
+ user: t.connection.user,
2516
+ password: t.connection.password || void 0,
2517
+ database: t.connection.database,
2518
+ options: t.connection.options
2519
+ };
2520
+ te.value = !0, ne.value = "";
2521
+ try {
2522
+ const u = await Ua(t, r, t.connectionId);
2523
+ f.value = A({
2524
+ ...t,
2525
+ connectionId: u.id,
2526
+ connection: { ...t.connection, password: "" }
2527
+ }), ee.value = u.name, je.value = !0, ne.value = "连接已保存", i("update:sqlConfig", A(f.value)), await fe();
2528
+ } catch (u) {
2529
+ je.value = !1, ne.value = u instanceof Error ? u.message : String(u);
2530
+ } finally {
2531
+ te.value = !1;
2532
+ }
2533
+ }
2534
+ async function jr() {
2535
+ const e = f.value.connectionId;
2536
+ if (!(!e || te.value) && !(typeof window < "u" && !window.confirm("确定删除该连接配置?"))) {
2537
+ te.value = !0, ne.value = "";
2538
+ try {
2539
+ await rr(f.value, e), f.value.connectionId = void 0, ee.value = "", je.value = !0, ne.value = "连接已删除", i("update:sqlConfig", A(f.value)), await fe();
2540
+ } catch (t) {
2541
+ je.value = !1, ne.value = t instanceof Error ? t.message : String(t);
2542
+ } finally {
2543
+ te.value = !1;
2544
+ }
2545
+ }
2546
+ }
2547
+ async function Vr(e) {
2548
+ if (!te.value && !(typeof window < "u" && !window.confirm(`确定删除连接“${e.name}”?`))) {
2549
+ te.value = !0, Ve.value = "";
2550
+ try {
2551
+ await rr(f.value, e.id), f.value.connectionId === e.id && (f.value.connectionId = void 0, f.value.connection.password = "", ee.value = "", i("update:sqlConfig", A(f.value))), ft.value = !0, Ve.value = `已删除连接“${e.name}”`, await fe();
2552
+ } catch (t) {
2553
+ ft.value = !1, Ve.value = t instanceof Error ? t.message : String(t);
2554
+ } finally {
2555
+ te.value = !1;
2556
+ }
2557
+ }
2558
+ }
2559
+ async function Qr() {
2560
+ if (Re.value) return;
2561
+ rt(), Re.value = !0;
2562
+ const e = new AbortController();
2563
+ Y = e;
2564
+ try {
2565
+ const t = await Ha(A(f.value), {
2566
+ executor: o.sqlExecutor,
2567
+ signal: e.signal
2568
+ });
2569
+ if (Y !== e) return;
2570
+ pt.value = t.ok, tt.value = t.message;
2571
+ } catch (t) {
2572
+ if (Y !== e) return;
2573
+ pt.value = !1, tt.value = t instanceof Error ? t.message : String(t);
2574
+ } finally {
2575
+ Y === e && (Y = null, Re.value = !1);
2576
+ }
2577
+ }
2578
+ function Kr(e) {
2579
+ return e === null ? "NULL" : String(e);
2580
+ }
2581
+ function Jr(e) {
2582
+ return e.columns.length ? `${e.rows.length} 行${e.truncated ? "(已截断)" : ""}` : `影响 ${e.affectedRows ?? 0} 行`;
2583
+ }
2584
+ function bn(e) {
2585
+ if (e)
2586
+ return { type: e.type, message: e.message, traceback: "" };
2587
+ }
2588
+ async function kn() {
2589
+ if (xe.value)
2590
+ return k.value !== w.value.id && h("另一个 SQL 正在执行,请等待或停止后再试"), null;
2591
+ const e = Ne();
2592
+ if (!e.trim())
2593
+ return h("SQL 内容为空,请输入要执行的语句"), null;
2594
+ const t = A(f.value), r = ++nt, u = w.value.id;
2595
+ xe.value = !0, k.value = u, ce = new AbortController(), Me(void 0), o.clearOutputOnRun && (pe(u).lines = [], pe(u).sqlResults = []), h(
2596
+ `开始执行 SQL(${t.mode === "sqlite" ? "浏览器内 SQLite" : "HTTP 服务"})`,
2597
+ u
2598
+ ), i("runStart");
2599
+ try {
2600
+ const c = await gr(t, e, {
2601
+ executor: o.sqlExecutor,
2602
+ signal: ce.signal
2603
+ });
2604
+ if (r !== nt) return null;
2605
+ if (pe(u).sqlResults = c.results ?? [], c.ok) {
2606
+ const y = c.results ?? [], S = y.reduce(($, X) => $ + X.rows.length, 0);
2607
+ h(
2608
+ `SQL 执行完成:${y.length} 个结果集,共 ${S} 行,耗时 ${(c.durationMs / 1e3).toFixed(2)}s`,
2609
+ u
2610
+ );
2611
+ } else {
2612
+ const y = c.error ?? { type: "SqlError", message: "SQL 执行失败" };
2613
+ h(`SQL 执行出错:${y.type}`, u), ge("stderr", y.message, u), i("runOutput", { stream: "stderr", text: y.message }), i("sqlError", y);
2614
+ }
2615
+ return i("sqlResult", c), i("runFinish", {
2616
+ ok: c.ok,
2617
+ durationMs: c.durationMs,
2618
+ error: c.ok ? void 0 : bn(c.error)
2619
+ }), c;
2620
+ } catch (c) {
2621
+ if (r !== nt) return null;
2622
+ const y = c instanceof Error ? c.message : String(c);
2623
+ h(`SQL 执行失败:${y}`, u);
2624
+ const S = { type: "SqlError", message: y };
2625
+ return i("sqlError", S), i("runFinish", { ok: !1, durationMs: 0, error: bn(S) }), null;
2626
+ } finally {
2627
+ r === nt && (xe.value = !1, ce = null, k.value === u && (k.value = null));
2628
+ }
2629
+ }
2630
+ async function Zr(e) {
2631
+ return e !== void 0 && (ht(e), w.value.language !== "sql" && Bt("sql")), w.value.language !== "sql" ? (h("当前文件不是 SQL,无法执行"), null) : kn();
2632
+ }
2633
+ function Gr(e) {
2634
+ const t = e.target.value === "server" ? "server" : "browser";
2635
+ if (t === "browser")
2636
+ for (const r of [...O.keys()])
2637
+ st(r, !1);
2638
+ Q.value = t, i("update:runtime", t), h(t === "server" ? "已切换到服务端 Python 环境" : "已切换到浏览器 Python 环境");
2639
+ }
2640
+ function wn(e, t, r, u) {
2641
+ if (!u) return;
2642
+ const c = u.replace(/\r\n/g, `
2643
+ `);
2644
+ let y = r === "stdout" ? t.stdoutBuffer : t.stderrBuffer;
2645
+ y += c;
2646
+ const S = y.split(`
2647
+ `), $ = S.pop() ?? "";
2648
+ r === "stdout" ? t.stdoutBuffer = $ : t.stderrBuffer = $;
2649
+ for (const X of S)
2650
+ ge(r, X, e), i("runOutput", { stream: r, text: X });
2651
+ }
2652
+ function Sn(e, t) {
2653
+ t.stdoutBuffer && (ge("stdout", t.stdoutBuffer, e), i("runOutput", { stream: "stdout", text: t.stdoutBuffer }), t.stdoutBuffer = ""), t.stderrBuffer && (ge("stderr", t.stderrBuffer, e), i("runOutput", { stream: "stderr", text: t.stderrBuffer }), t.stderrBuffer = "");
2654
+ }
2655
+ function bt(e, t, r) {
2656
+ window.clearTimeout(t.pollTimer), Sn(e, t);
2657
+ const u = O.get(e);
2658
+ if (u && u.token === t.token && O.delete(e), r.error) {
2659
+ h(`执行出错:${r.error.type}`, e), e === w.value.id && Me(r.error.line);
2660
+ const y = {
2661
+ type: r.error.type,
2662
+ message: r.error.message,
2663
+ line: r.error.line,
2664
+ traceback: r.error.traceback ?? ""
2665
+ };
2666
+ i("runError", y), i("runFinish", { ok: !1, durationMs: r.durationMs ?? 0, error: y });
2667
+ return;
2668
+ }
2669
+ const c = r.durationMs ?? 0;
2670
+ h(`执行完成,会话时长 ${(c / 1e3).toFixed(2)}s`, e), i("runFinish", { ok: !0, durationMs: c });
2671
+ }
2672
+ function At(e, t, r, u) {
2673
+ const c = O.get(e);
2674
+ if (!(!c || c.token !== u)) {
2675
+ if (wn(e, t, "stdout", r.stdout), wn(e, t, "stderr", r.stderr), r.state === "exited") {
2676
+ bt(e, t, r);
2677
+ return;
2678
+ }
2679
+ if (Sn(e, t), r.state === "waiting") {
2680
+ t.waiting = !0;
2681
+ return;
2682
+ }
2683
+ t.waiting = !1, Wr(e, t, u);
2684
+ }
2685
+ }
2686
+ function Wr(e, t, r) {
2687
+ window.clearTimeout(t.pollTimer), t.pollTimer = window.setTimeout(() => {
2688
+ Yr(e, r);
2689
+ }, 250);
2690
+ }
2691
+ async function Yr(e, t) {
2692
+ var u, c;
2693
+ const r = O.get(e);
2694
+ if (!(!r || r.token !== t || !r.sessionId))
2695
+ try {
2696
+ const y = await La(o.pythonEndpoint, r.sessionId, {
2697
+ headers: o.pythonHeaders,
2698
+ signal: (u = r.abort) == null ? void 0 : u.signal
2699
+ });
2700
+ At(e, r, y, t);
2701
+ } catch (y) {
2702
+ if (((c = O.get(e)) == null ? void 0 : c.token) !== t) return;
2703
+ const S = y instanceof Error ? y.message : String(y);
2704
+ h(`执行失败:${S}`, e), bt(e, r, {
2705
+ sessionId: r.sessionId,
2706
+ durationMs: 0,
2707
+ error: { type: "RuntimeError", message: S }
2708
+ });
2709
+ }
2710
+ }
2711
+ async function Xr() {
2712
+ var y;
2713
+ const e = w.value.id;
2714
+ if ((y = O.get(e)) != null && y.busy) return;
2715
+ if (!yt.value) {
2716
+ h("未配置 Python 服务端点(pythonEndpoint)");
2717
+ return;
2718
+ }
2719
+ const t = Ne();
2720
+ if (!t.trim()) {
2721
+ h("代码为空,请输入要执行的 Python 代码");
2722
+ return;
2723
+ }
2724
+ const r = ++br, u = {
2725
+ sessionId: "",
2726
+ busy: !0,
2727
+ waiting: !1,
2728
+ input: "",
2729
+ abort: new AbortController(),
2730
+ token: r,
2731
+ pollTimer: void 0,
2732
+ stdoutBuffer: "",
2733
+ stderrBuffer: ""
2734
+ };
2735
+ O.set(e, u);
2736
+ const c = O.get(e);
2737
+ Me(void 0), o.clearOutputOnRun && (pe(e).lines = []), h("开始执行(服务端 Python)", e), i("runStart");
2738
+ try {
2739
+ const S = await Ta(o.pythonEndpoint, t, {
2740
+ stdin: o.stdin,
2741
+ headers: o.pythonHeaders,
2742
+ signal: c.abort.signal
2743
+ }), $ = O.get(e);
2744
+ if (!$ || $.token !== r) {
2745
+ S.sessionId && Wn(o.pythonEndpoint, S.sessionId, {
2746
+ headers: o.pythonHeaders
2747
+ });
2748
+ return;
2749
+ }
2750
+ $.sessionId = S.sessionId, At(e, $, S, r);
2751
+ } catch (S) {
2752
+ const $ = O.get(e);
2753
+ if (!$ || $.token !== r) return;
2754
+ const X = S instanceof Error ? S.message : String(S);
2755
+ h(`执行失败:${X}`, e), bt(e, $, {
2756
+ durationMs: 0,
2757
+ error: { type: "RuntimeError", message: X }
2758
+ });
2759
+ }
2760
+ }
2761
+ async function xn() {
2762
+ var u, c;
2763
+ const e = w.value.id, t = O.get(e);
2764
+ if (!t || !t.waiting || !t.sessionId) return;
2765
+ const r = t.input;
2766
+ t.input = "", t.waiting = !1, ge("stdout", r, e), i("runOutput", { stream: "stdout", text: r });
2767
+ try {
2768
+ const y = await $a(o.pythonEndpoint, t.sessionId, r, {
2769
+ headers: o.pythonHeaders,
2770
+ signal: (u = t.abort) == null ? void 0 : u.signal
2771
+ });
2772
+ At(e, t, y, t.token);
2773
+ } catch (y) {
2774
+ if (((c = O.get(e)) == null ? void 0 : c.token) !== t.token) return;
2775
+ const S = y instanceof Error ? y.message : String(y);
2776
+ h(`执行失败:${S}`, e), bt(e, t, {
2777
+ sessionId: t.sessionId,
2778
+ durationMs: 0,
2779
+ error: { type: "RuntimeError", message: S }
2780
+ });
2781
+ }
2782
+ }
2783
+ function st(e, t = !0) {
2784
+ var u;
2785
+ const r = O.get(e);
2786
+ r && (window.clearTimeout(r.pollTimer), O.delete(e), (u = r.abort) == null || u.abort(), r.sessionId && Wn(o.pythonEndpoint, r.sessionId, {
2787
+ headers: o.pythonHeaders
2788
+ }), t && h("执行已中断", e));
2789
+ }
2790
+ async function En() {
2791
+ var c, y, S;
2792
+ if (w.value.language === "sql") {
2793
+ await kn();
2794
+ return;
2795
+ }
2796
+ if (Je.value) {
2797
+ await Xr();
2798
+ return;
2799
+ }
2800
+ if (I.value === "running") {
2801
+ k.value !== w.value.id && h(
2802
+ "浏览器环境共享同一个 Pyodide 实例,暂不支持同时运行多个文件;可切换到服务端环境后并行执行"
2803
+ );
2804
+ return;
2805
+ }
2806
+ if (I.value === "loading") return;
2807
+ const e = w.value.language;
854
2808
  if (e !== "python") {
855
- p(`当前文件为 ${pe(e).label},仅支持执行 Python 代码`);
2809
+ h(`当前文件为 ${Ct(e).label},仅支持执行 Python / SQL 代码`);
856
2810
  return;
857
2811
  }
858
- ne += 1;
859
- const t = ne, n = y.value.id;
860
- ee(void 0), i.clearOutputOnRun && (C.value = []), p("开始执行"), s("runStart");
861
- const l = te();
2812
+ Ge += 1;
2813
+ const t = Ge, r = w.value.id;
2814
+ k.value = r, Me(void 0), o.clearOutputOnRun && (pe(r).lines = []), h("开始执行", r), i("runStart");
2815
+ const u = Ne();
862
2816
  try {
863
- await mt();
864
- const E = await b.run(l, {
865
- stdin: i.stdin,
866
- onOutput: (re, ae) => {
867
- Q(re, ae), s("runOutput", { stream: re, text: ae });
2817
+ await Rr();
2818
+ const $ = await z.run(u, {
2819
+ stdin: o.stdin,
2820
+ onOutput: (X, ot) => {
2821
+ ge(X, ot, r), i("runOutput", { stream: X, text: ot });
868
2822
  }
869
2823
  });
870
- if (t !== ne) return;
871
- E.interrupted ? p("执行已中断") : E.ok ? p(`执行完成,耗时 ${(E.durationMs / 1e3).toFixed(2)}s`) : (p(`执行出错:${((d = E.error) == null ? void 0 : d.type) ?? "未知错误"}`), (m = E.error) != null && m.traceback && (Q("stderr", E.error.traceback), s("runOutput", { stream: "stderr", text: E.error.traceback })), y.value.id === n && ee((k = E.error) == null ? void 0 : k.line), E.error && s("runError", E.error)), s("runFinish", E);
872
- } catch (E) {
873
- if (t !== ne) return;
874
- const re = E instanceof Error ? E.message : String(E);
875
- p(`执行失败:${re}`);
876
- const ae = { type: "RuntimeError", message: re, traceback: "" };
877
- s("runError", ae), s("runFinish", { ok: !1, durationMs: 0, error: ae });
2824
+ if (t !== Ge) return;
2825
+ $.interrupted ? h("执行已中断", r) : $.ok ? h(`执行完成,耗时 ${($.durationMs / 1e3).toFixed(2)}s`, r) : (h(`执行出错:${((c = $.error) == null ? void 0 : c.type) ?? "未知错误"}`, r), (y = $.error) != null && y.traceback && (ge("stderr", $.error.traceback, r), i("runOutput", { stream: "stderr", text: $.error.traceback })), w.value.id === r && Me((S = $.error) == null ? void 0 : S.line), $.error && i("runError", $.error)), i("runFinish", $);
2826
+ } catch ($) {
2827
+ if (t !== Ge) return;
2828
+ const X = $ instanceof Error ? $.message : String($);
2829
+ h(`执行失败:${X}`, r);
2830
+ const ot = { type: "RuntimeError", message: X, traceback: "" };
2831
+ i("runError", ot), i("runFinish", { ok: !1, durationMs: 0, error: ot });
2832
+ } finally {
2833
+ t === Ge && k.value === r && (k.value = null);
878
2834
  }
879
2835
  }
880
- async function yt() {
2836
+ async function es() {
881
2837
  var t;
882
- if (G) return;
883
- const e = i.preloadPackages;
2838
+ if (cn) return;
2839
+ const e = o.preloadPackages;
884
2840
  if (e.length) {
885
- G = !0, p(`正在安装预置包:${e.join(", ")}`);
2841
+ cn = !0, h(`正在安装预置包:${e.join(", ")}`);
886
2842
  try {
887
- const n = await b.loadPackages(e, {
888
- onOutput: (l, d) => Q(l, d)
2843
+ const r = await z.loadPackages(e, {
2844
+ onOutput: (u, c) => ge(u, c)
889
2845
  });
890
- p(
891
- n.ok ? `预置包安装完成(${(n.durationMs / 1e3).toFixed(1)}s)` : `预置包安装失败:${((t = n.error) == null ? void 0 : t.message) ?? "未知错误"}`
2846
+ h(
2847
+ r.ok ? `预置包安装完成(${(r.durationMs / 1e3).toFixed(1)}s)` : `预置包安装失败:${((t = r.error) == null ? void 0 : t.message) ?? "未知错误"}`
892
2848
  );
893
- } catch (n) {
894
- p(`预置包安装失败:${n instanceof Error ? n.message : String(n)}`);
2849
+ } catch (r) {
2850
+ h(`预置包安装失败:${r instanceof Error ? r.message : String(r)}`);
895
2851
  }
896
2852
  }
897
2853
  }
898
- jt(() => {
899
- const e = P.value;
2854
+ Ns(() => {
2855
+ const e = b.value;
900
2856
  if (!e) return;
901
- lt(), J = !0;
2857
+ Nr(), Tt = !0;
902
2858
  const t = [
903
- Pe.of(i.theme === "dark" ? [Fe] : []),
904
- Ce.of([
905
- Se.readOnly.of(i.readOnly),
906
- K.editable.of(!i.readOnly)
2859
+ dn.of([
2860
+ Yt.readOnly.of(o.readOnly),
2861
+ $e.editable.of(!o.readOnly)
907
2862
  ]),
908
- ye.of(ve(y.value.language))
2863
+ Rt.of(Ht(w.value.language))
909
2864
  ];
910
2865
  try {
911
- o = mn(e, {
912
- value: y.value.code,
913
- dark: i.theme === "dark",
914
- placeholderText: i.placeholder,
915
- language: me.of(we(y.value.language)),
2866
+ M = ya(e, {
2867
+ value: w.value.code,
2868
+ dark: or(o.theme),
2869
+ placeholderText: o.placeholder,
2870
+ language: Ft.of(Gt(w.value.language)),
916
2871
  extensions: t,
917
- onDocChange: (n) => {
918
- y.value.code = n, n !== i.modelValue && s("update:modelValue", n);
2872
+ onDocChange: (r) => {
2873
+ w.value.code = r, r !== o.modelValue && i("update:modelValue", r);
919
2874
  },
920
- onRunShortcut: Ie
2875
+ onRunShortcut: En
921
2876
  });
922
- } catch (n) {
923
- const l = n instanceof Error ? n.message : String(n);
924
- console.error("[princess-python-editor] 编辑器初始化失败", n), p(`编辑器初始化失败:${l}`), e.innerHTML = "";
925
- const d = document.createElement("div");
926
- d.className = "vpe-init-error", d.textContent = `编辑器初始化失败:${l}`, e.appendChild(d);
2877
+ } catch (r) {
2878
+ const u = r instanceof Error ? r.message : String(r);
2879
+ console.error("[princess-python-editor] 编辑器初始化失败", r), h(`编辑器初始化失败:${u}`), e.innerHTML = "";
2880
+ const c = document.createElement("div");
2881
+ c.className = "vpe-init-error", c.textContent = `编辑器初始化失败:${u}`, e.appendChild(c);
927
2882
  return;
928
2883
  }
929
- i.autofocus && o.focus(), O = b.on("status", (n, l) => {
930
- M.value = n, n === "ready" && (l && p(`Pyodide ${l} 就绪`), s("ready"), o && !i.disableLint && y.value.language === "python" && Xt(o)), s("statusChange", n);
931
- }), U = b.on("initError", (n) => {
932
- p(`Pyodide 加载失败:${n}`), s("loadError", n);
933
- }), M.value = b.status, i.preloadPackages.length ? b.waitReady().then(() => yt()).catch((n) => p(n.message)) : i.preload && b.waitReady().catch((n) => p(n.message));
934
- }), _t(() => {
935
- O == null || O(), U == null || U(), window.clearTimeout(X), window.clearTimeout(Z), Oe(), o == null || o.destroy(), o = null;
936
- }), V(
937
- () => i.modelValue,
938
- () => ct()
939
- ), V(
940
- () => i.fileName,
2884
+ o.autofocus && M.focus(), mt = z.on("status", (r, u) => {
2885
+ I.value = r, r === "ready" && (u && h(`Pyodide ${u} 就绪`), i("ready"), M && !o.disableLint && w.value.language === "python" && Ds(M)), i("statusChange", r);
2886
+ }), gt = z.on("initError", (r) => {
2887
+ h(`Pyodide 加载失败:${r}`), i("loadError", r);
2888
+ }), I.value = z.status, de.value && fe(), typeof ResizeObserver < "u" && p.value && (Ke = new ResizeObserver(() => {
2889
+ x.value !== null && Dt(x.value);
2890
+ }), Ke.observe(p.value)), o.preloadPackages.length ? z.waitReady().then(() => es()).catch((r) => h(r.message)) : o.preload && z.waitReady().catch((r) => h(r.message));
2891
+ }), Ts(() => {
2892
+ mt == null || mt(), gt == null || gt(), at(), Ke == null || Ke.disconnect(), Ke = null, ce == null || ce.abort(), ce = null, Y == null || Y.abort(), Y = null, re == null || re.abort(), re = null, se == null || se.abort(), se = null;
2893
+ for (const e of [...O.keys()])
2894
+ st(e, !1);
2895
+ window.clearTimeout($t), window.clearTimeout(vt), vn(), M == null || M.destroy(), M = null;
2896
+ }), oe(
2897
+ () => o.modelValue,
2898
+ () => $r()
2899
+ ), oe(
2900
+ () => o.outputHeight,
2901
+ () => {
2902
+ x.value = null;
2903
+ }
2904
+ ), oe(
2905
+ () => o.fileName,
941
2906
  (e) => {
942
- e && e !== y.value.name && (A.value = e);
2907
+ e && e !== w.value.name && (Ie.value = e);
943
2908
  }
944
- ), V(
945
- () => i.language,
2909
+ ), oe(
2910
+ () => o.language,
946
2911
  (e) => {
947
- e !== y.value.language && $e(e);
2912
+ e !== w.value.language && Bt(e);
948
2913
  }
949
- ), V(
950
- () => i.theme,
2914
+ ), oe(
2915
+ () => o.runtime,
951
2916
  (e) => {
952
- o == null || o.dispatch({ effects: Pe.reconfigure(e === "dark" ? [Fe] : []) });
2917
+ e !== Q.value && (Q.value = e);
2918
+ }
2919
+ ), oe(
2920
+ () => o.pythonEndpoint,
2921
+ () => {
2922
+ if (!yt.value) {
2923
+ for (const e of [...O.keys()])
2924
+ st(e, !1);
2925
+ Q.value !== "browser" && (Q.value = "browser", i("update:runtime", "browser"));
2926
+ }
2927
+ }
2928
+ ), oe(
2929
+ () => o.filesEndpoint,
2930
+ () => {
2931
+ if (!Oe.value) {
2932
+ Se.value = !1, et.value = [], De.value = "";
2933
+ return;
2934
+ }
2935
+ Se.value && We();
953
2936
  }
954
- ), V(
955
- () => i.readOnly,
2937
+ ), oe(
2938
+ () => o.readOnly,
956
2939
  (e) => {
957
- o == null || o.dispatch({
958
- effects: Ce.reconfigure([Se.readOnly.of(e), K.editable.of(!e)])
2940
+ M == null || M.dispatch({
2941
+ effects: dn.reconfigure([Yt.readOnly.of(e), $e.editable.of(!e)])
959
2942
  });
960
2943
  }
961
- ), V(
962
- () => C.value.length,
2944
+ ), oe(
2945
+ () => o.sqlConfig,
2946
+ (e) => {
2947
+ if (!e) return;
2948
+ const t = A(e);
2949
+ JSON.stringify(t) !== JSON.stringify(f.value) && (f.value = t), de.value && fe();
2950
+ },
2951
+ { deep: !0 }
2952
+ ), oe(de, (e) => {
2953
+ e && fe();
2954
+ }), oe(
2955
+ () => G.value.length,
963
2956
  async () => {
964
- await Ae();
965
- const e = w.value;
2957
+ await zn();
2958
+ const e = R.value;
966
2959
  e && (e.scrollTop = e.scrollHeight);
967
2960
  }
968
- ), V([f, _], () => ut(), { deep: !0 });
969
- function Me() {
970
- Ie();
2961
+ ), oe([L, Ee], () => Tr(), { deep: !0 });
2962
+ function qn() {
2963
+ En();
2964
+ }
2965
+ function Cn() {
2966
+ var t;
2967
+ const e = w.value.id;
2968
+ if (Re.value) {
2969
+ rt(), !o.sqlExecutor && f.value.mode === "sqlite" && z.interrupt(), h("已取消连接测试");
2970
+ return;
2971
+ }
2972
+ if ((t = O.get(e)) != null && t.busy) {
2973
+ st(e);
2974
+ return;
2975
+ }
2976
+ if (xe.value && k.value === e) {
2977
+ Pn();
2978
+ return;
2979
+ }
2980
+ I.value === "running" && k.value === e && On();
2981
+ }
2982
+ function Pn(e = !0) {
2983
+ const t = k.value;
2984
+ nt += 1, xe.value = !1, k.value = null, ce == null || ce.abort(), ce = null, !o.sqlExecutor && f.value.mode === "sqlite" && z.interrupt(), e && h("执行已中断", t ?? void 0);
2985
+ }
2986
+ function On(e = !0) {
2987
+ const t = k.value;
2988
+ Ge += 1, k.value = null, z.interrupt(), e && h("执行已中断", t ?? void 0);
2989
+ }
2990
+ function Mn() {
2991
+ pe().lines = [], pe().sqlResults = [];
2992
+ }
2993
+ function Nn() {
2994
+ var e;
2995
+ return ((e = E.value) == null ? void 0 : e.getBoundingClientRect().height) ?? 180;
2996
+ }
2997
+ function ts() {
2998
+ var t;
2999
+ const e = ((t = p.value) == null ? void 0 : t.clientHeight) ?? 0;
3000
+ return Math.max(cr, e ? e - 180 : 600);
3001
+ }
3002
+ function Dt(e) {
3003
+ x.value = Math.round(Math.max(cr, Math.min(e, ts())));
971
3004
  }
972
- function Re() {
973
- M.value === "running" && (ne += 1, b.interrupt(), p("执行已中断"));
3005
+ function ns(e) {
3006
+ e.button === 0 && (e.preventDefault(), F.value = !0, pn = e.clientY, _t = Nn(), x.value = Math.round(_t), document.body.style.cursor = "ns-resize", document.body.style.userSelect = "none", window.addEventListener("pointermove", Tn), window.addEventListener("pointerup", at), window.addEventListener("pointercancel", at));
974
3007
  }
975
- function He() {
976
- C.value = [];
3008
+ function Tn(e) {
3009
+ F.value && Dt(_t + (pn - e.clientY));
977
3010
  }
978
- function ke() {
979
- if (i.readOnly) return;
980
- const e = y.value.language, t = le(pt(e), e, "");
981
- f.value.push(t), q(t.id), s("newFile", Y(t));
3011
+ function at() {
3012
+ F.value && (F.value = !1, document.body.style.cursor = "", document.body.style.userSelect = "", window.removeEventListener("pointermove", Tn), window.removeEventListener("pointerup", at), window.removeEventListener("pointercancel", at));
982
3013
  }
983
- function q(e) {
984
- if (e === _.value) {
985
- ue();
3014
+ function rs() {
3015
+ x.value = null;
3016
+ }
3017
+ function ss(e) {
3018
+ if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
3019
+ e.preventDefault();
3020
+ const t = x.value ?? Nn();
3021
+ Dt(t + (e.key === "ArrowUp" ? 16 : -16));
3022
+ }
3023
+ function zt() {
3024
+ if (o.readOnly) return;
3025
+ const e = w.value.language, t = Qe(mn(e), e, "");
3026
+ L.value.push(t), He(t.id), i("newFile", Ze(t));
3027
+ }
3028
+ function He(e) {
3029
+ if (e === Ee.value) {
3030
+ wt();
986
3031
  return;
987
3032
  }
988
- const t = f.value.find((n) => n.id === e);
989
- t && (_.value = e, Ne(t));
3033
+ const t = L.value.find((r) => r.id === e);
3034
+ t && (Ee.value = e, jt(t));
990
3035
  }
991
- function Te(e) {
992
- if (f.value.length <= 1) return;
993
- const t = f.value.findIndex((d) => d.id === e);
3036
+ function as(e) {
3037
+ st(e, !1), xe.value && k.value === e && Pn(!1), I.value === "running" && k.value === e && On(!1);
3038
+ }
3039
+ function Ln(e) {
3040
+ if (o.readOnly) return;
3041
+ const t = L.value.findIndex((c) => c.id === e);
994
3042
  if (t === -1) return;
995
- const n = f.value.splice(t, 1)[0];
996
- if (!n || (s("fileClose", Y(n)), e !== _.value)) return;
997
- const l = f.value[Math.min(t, f.value.length - 1)];
998
- l && (_.value = l.id, Ne(l));
3043
+ as(e);
3044
+ const r = L.value.splice(t, 1)[0];
3045
+ if (!r) return;
3046
+ if (q.delete(e), i("fileClose", Ze(r)), !L.value.length) {
3047
+ const c = Qe(mn(r.language), r.language, "");
3048
+ L.value.push(c), Ee.value = c.id, jt(c), i("newFile", Ze(c));
3049
+ return;
3050
+ }
3051
+ if (e !== Ee.value) return;
3052
+ const u = L.value[Math.min(t, L.value.length - 1)];
3053
+ u && (Ee.value = u.id, jt(u));
999
3054
  }
1000
- function Ne(e) {
1001
- ee(void 0), ge(e.code), o == null || o.dispatch({
3055
+ function jt(e) {
3056
+ Me(void 0), ht(e.code), M == null || M.dispatch({
1002
3057
  effects: [
1003
- me.reconfigure(we(e.language)),
1004
- ye.reconfigure(ve(e.language))
3058
+ Ft.reconfigure(Gt(e.language)),
3059
+ Rt.reconfigure(Ht(e.language))
1005
3060
  ]
1006
- }), s("update:fileName", e.name), s("update:language", e.language), s("fileSwitch", Y(e)), ue();
3061
+ }), i("update:fileName", e.name), i("update:language", e.language), i("fileSwitch", Ze(e)), wt();
1007
3062
  }
1008
- function je() {
1009
- i.readOnly || (ee(void 0), ge(""), ue());
3063
+ function $n() {
3064
+ o.readOnly || (Me(void 0), ht(""), wt());
1010
3065
  }
1011
- async function _e() {
1012
- var n;
1013
- const e = te();
3066
+ async function Fn() {
3067
+ var r;
3068
+ const e = Ne();
1014
3069
  let t = !1;
1015
3070
  try {
1016
- (n = navigator.clipboard) != null && n.writeText && (await navigator.clipboard.writeText(e), t = !0);
3071
+ (r = navigator.clipboard) != null && r.writeText && (await navigator.clipboard.writeText(e), t = !0);
1017
3072
  } catch {
1018
3073
  t = !1;
1019
3074
  }
1020
- return t || (t = gt(e)), t ? (T.value = !0, window.clearTimeout(X), X = window.setTimeout(() => {
1021
- T.value = !1;
1022
- }, 1600), s("copy", e), !0) : (p("复制失败,请手动选择代码复制"), !1);
3075
+ return t || (t = os(e)), t ? (me.value = !0, window.clearTimeout($t), $t = window.setTimeout(() => {
3076
+ me.value = !1;
3077
+ }, 1600), i("copy", e), !0) : (h("复制失败,请手动选择代码复制"), !1);
1023
3078
  }
1024
- function gt(e) {
3079
+ function os(e) {
1025
3080
  const t = document.createElement("textarea");
1026
3081
  t.value = e, t.setAttribute("readonly", ""), t.style.position = "fixed", t.style.top = "0", t.style.left = "-9999px", t.style.opacity = "0", document.body.appendChild(t), t.select(), t.setSelectionRange(0, t.value.length);
1027
- let n = !1;
3082
+ let r = !1;
1028
3083
  try {
1029
- n = document.execCommand("copy");
3084
+ r = document.execCommand("copy");
1030
3085
  } catch {
1031
- n = !1;
3086
+ r = !1;
1032
3087
  }
1033
- return t.remove(), n;
3088
+ return t.remove(), r;
1034
3089
  }
1035
- function De() {
1036
- const e = y.value, t = Le(e.name, e.language);
1037
- A.value = t;
1038
- const n = new Blob([te()], {
3090
+ function Rn() {
3091
+ const e = w.value, t = Ut(e.name, e.language);
3092
+ Ie.value = t;
3093
+ const r = new Blob([Ne()], {
1039
3094
  type: e.language === "python" ? "text/x-python;charset=utf-8" : "text/plain;charset=utf-8"
1040
- }), l = URL.createObjectURL(n), d = document.createElement("a");
1041
- return d.href = l, d.download = t, d.style.display = "none", document.body.appendChild(d), d.click(), d.remove(), window.setTimeout(() => URL.revokeObjectURL(l), 1e3), s("download", t), t;
3095
+ }), u = URL.createObjectURL(r), c = document.createElement("a");
3096
+ return c.href = u, c.download = t, c.style.display = "none", document.body.appendChild(c), c.click(), c.remove(), window.setTimeout(() => URL.revokeObjectURL(u), 1e3), i("download", t), t;
1042
3097
  }
1043
- function vt() {
1044
- D.value = !D.value, D.value && Ue();
3098
+ function is() {
3099
+ qe.value = !qe.value, qe.value && (Se.value = !1, _n());
1045
3100
  }
1046
- async function Ue() {
3101
+ async function _n() {
1047
3102
  var e;
1048
- if (!N.value) {
1049
- N.value = !0;
3103
+ if (!Ye.value) {
3104
+ Ye.value = !0;
1050
3105
  try {
1051
- const t = await b.listFiles(".");
3106
+ const t = await z.listFiles(".");
1052
3107
  if (!t.ok) {
1053
- j.value = [], p(`读取虚拟文件失败:${((e = t.error) == null ? void 0 : e.message) ?? "未知错误"}`);
3108
+ Xe.value = [], h(`读取虚拟文件失败:${((e = t.error) == null ? void 0 : e.message) ?? "未知错误"}`);
1054
3109
  return;
1055
3110
  }
1056
- j.value = t.entries ?? [];
3111
+ Xe.value = t.entries ?? [];
1057
3112
  } catch (t) {
1058
- j.value = [], p(`读取虚拟文件失败:${t instanceof Error ? t.message : String(t)}`);
3113
+ Xe.value = [], h(`读取虚拟文件失败:${t instanceof Error ? t.message : String(t)}`);
1059
3114
  } finally {
1060
- N.value = !1;
3115
+ Ye.value = !1;
1061
3116
  }
1062
3117
  }
1063
3118
  }
1064
- function kt(e) {
3119
+ function ls(e) {
1065
3120
  switch (e.slice(e.lastIndexOf(".") + 1).toLowerCase()) {
1066
3121
  case "csv":
1067
3122
  return "text/csv";
@@ -1078,505 +3133,1081 @@ const wn = R(
1078
3133
  return "text/plain";
1079
3134
  }
1080
3135
  }
1081
- function bt(e) {
3136
+ function Vt(e) {
1082
3137
  return e < 1024 ? `${e} B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)} KB` : `${(e / 1024 / 1024).toFixed(1)} MB`;
1083
3138
  }
1084
- async function Ve(e) {
3139
+ async function In(e) {
1085
3140
  var t;
1086
3141
  try {
1087
- const n = await b.readFile(e);
1088
- if (!n.ok || n.content === void 0)
1089
- return p(`下载失败:${e}(${((t = n.error) == null ? void 0 : t.message) ?? "未知错误"})`), null;
1090
- const l = e.slice(e.lastIndexOf("/") + 1) || "download.txt", d = new Blob([n.content], {
1091
- type: `${kt(l)};charset=utf-8`
1092
- }), m = URL.createObjectURL(d), k = document.createElement("a");
1093
- return k.href = m, k.download = l, k.style.display = "none", document.body.appendChild(k), k.click(), k.remove(), window.setTimeout(() => URL.revokeObjectURL(m), 1e3), s("fsDownload", { path: n.path ?? e, name: l }), p(`已下载虚拟文件:${l}`), l;
1094
- } catch (n) {
1095
- return p(`下载失败:${n instanceof Error ? n.message : String(n)}`), null;
3142
+ const r = await z.readFile(e);
3143
+ if (!r.ok || r.content === void 0)
3144
+ return h(`下载失败:${e}(${((t = r.error) == null ? void 0 : t.message) ?? "未知错误"})`), null;
3145
+ const u = e.slice(e.lastIndexOf("/") + 1) || "download.txt", c = new Blob([r.content], {
3146
+ type: `${ls(u)};charset=utf-8`
3147
+ }), y = URL.createObjectURL(c), S = document.createElement("a");
3148
+ return S.href = y, S.download = u, S.style.display = "none", document.body.appendChild(S), S.click(), S.remove(), window.setTimeout(() => URL.revokeObjectURL(y), 1e3), i("fsDownload", { path: r.path ?? e, name: u }), h(`已下载虚拟文件:${u}`), u;
3149
+ } catch (r) {
3150
+ return h(`下载失败:${r instanceof Error ? r.message : String(r)}`), null;
3151
+ }
3152
+ }
3153
+ function us(e, t) {
3154
+ return z.writeFile(e, t);
3155
+ }
3156
+ function cs(e) {
3157
+ return z.readFile(e);
3158
+ }
3159
+ function ds(e = ".") {
3160
+ return z.listFiles(e);
3161
+ }
3162
+ function kt(e) {
3163
+ return e instanceof Error ? e.message : String(e);
3164
+ }
3165
+ function ps(e) {
3166
+ if (!e) return "";
3167
+ const t = new Date(e);
3168
+ return Number.isNaN(t.getTime()) ? e : `更新时间:${t.toLocaleString()}`;
3169
+ }
3170
+ function fs() {
3171
+ Se.value = !Se.value, Se.value && (qe.value = !1, We());
3172
+ }
3173
+ async function We() {
3174
+ if (!Oe.value) return;
3175
+ se == null || se.abort();
3176
+ const e = new AbortController();
3177
+ se = e, dt.value = !0, De.value = "";
3178
+ try {
3179
+ const t = await qa(o.filesEndpoint, {
3180
+ headers: o.filesHeaders,
3181
+ signal: e.signal
3182
+ });
3183
+ if (se !== e) return;
3184
+ et.value = t;
3185
+ } catch (t) {
3186
+ if (se !== e) return;
3187
+ et.value = [], De.value = kt(t);
3188
+ } finally {
3189
+ se === e && (se = null, dt.value = !1);
1096
3190
  }
1097
3191
  }
1098
- function wt(e, t) {
1099
- return b.writeFile(e, t);
3192
+ async function Hn() {
3193
+ if (!Oe.value)
3194
+ return h("未配置文件服务端点(filesEndpoint)"), null;
3195
+ if (W.value) return null;
3196
+ const e = w.value, t = Ut(e.name, e.language);
3197
+ t !== e.name && (Ie.value = t), W.value = !0;
3198
+ try {
3199
+ const r = await Ca(
3200
+ o.filesEndpoint,
3201
+ { name: t, content: Ne() },
3202
+ { headers: o.filesHeaders }
3203
+ );
3204
+ return h(`已保存到服务端:${r.name}(${Vt(r.size)})`), Se.value && await We(), r;
3205
+ } catch (r) {
3206
+ return h(`保存到服务端失败:${kt(r)}`), null;
3207
+ } finally {
3208
+ W.value = !1;
3209
+ }
1100
3210
  }
1101
- function xt(e) {
1102
- return b.readFile(e);
3211
+ async function vs(e) {
3212
+ if (!Oe.value || W.value) return !1;
3213
+ W.value = !0;
3214
+ try {
3215
+ const t = await Pa(o.filesEndpoint, e.id, {
3216
+ headers: o.filesHeaders
3217
+ }), r = sr(t.name), u = Qe(gn(t.name), r, t.content);
3218
+ return L.value.push(u), He(u.id), h(`已从服务端打开文件:${t.name}`), i("fileOpen", { name: u.name, code: t.content, language: r }), !0;
3219
+ } catch (t) {
3220
+ return h(`打开服务端文件失败:${kt(t)}`), !1;
3221
+ } finally {
3222
+ W.value = !1;
3223
+ }
1103
3224
  }
1104
- function St(e = ".") {
1105
- return b.listFiles(e);
3225
+ async function ms(e) {
3226
+ if (!(!Oe.value || W.value) && !(typeof window < "u" && !window.confirm(`确定删除服务端文件“${e.name}”?`))) {
3227
+ W.value = !0;
3228
+ try {
3229
+ await Oa(o.filesEndpoint, e.id, { headers: o.filesHeaders }), h(`已删除服务端文件:${e.name}`), await We();
3230
+ } catch (t) {
3231
+ h(`删除服务端文件失败:${kt(t)}`);
3232
+ } finally {
3233
+ W.value = !1;
3234
+ }
3235
+ }
1106
3236
  }
1107
- function Be() {
3237
+ function Bn() {
1108
3238
  var e;
1109
- (e = H.value) == null || e.click();
1110
- }
1111
- async function Et(e) {
1112
- var l;
1113
- const t = e.target, n = (l = t.files) == null ? void 0 : l[0];
1114
- if (t.value = "", !!n) {
1115
- if (n.size > 2 * 1024 * 1024) {
1116
- p(`文件过大:${(n.size / 1024 / 1024).toFixed(1)} MB(最多 2 MB)`);
3239
+ (e = T.value) == null || e.click();
3240
+ }
3241
+ async function gs(e) {
3242
+ var u;
3243
+ const t = e.target, r = (u = t.files) == null ? void 0 : u[0];
3244
+ if (t.value = "", !!r) {
3245
+ if (r.size > 2 * 1024 * 1024) {
3246
+ h(`文件过大:${(r.size / 1024 / 1024).toFixed(1)} MB(最多 2 MB)`);
1117
3247
  return;
1118
3248
  }
1119
3249
  try {
1120
- const d = await n.text(), m = bn(n.name), k = le(ft(n.name), m, d);
1121
- f.value.push(k), q(k.id), p(`已打开文件:${k.name}`), s("fileOpen", { name: k.name, code: d, language: m });
1122
- } catch (d) {
1123
- const m = d instanceof Error ? d.message : String(d);
1124
- p(`读取文件失败:${m}`);
3250
+ const c = await r.text(), y = sr(r.name), S = Qe(gn(r.name), y, c);
3251
+ L.value.push(S), He(S.id), h(`已打开文件:${S.name}`), i("fileOpen", { name: S.name, code: c, language: y });
3252
+ } catch (c) {
3253
+ const y = c instanceof Error ? c.message : String(c);
3254
+ h(`读取文件失败:${y}`);
1125
3255
  }
1126
3256
  }
1127
3257
  }
1128
- function Ft() {
1129
- A.value = Le(A.value, y.value.language);
3258
+ function ys() {
3259
+ Ie.value = Ut(Ie.value, w.value.language);
1130
3260
  }
1131
- function Pt(e) {
3261
+ function hs(e) {
1132
3262
  e.key === "Enter" && (e.preventDefault(), e.target.blur());
1133
3263
  }
1134
- function Ct(e) {
1135
- $e(e.target.value);
3264
+ function bs(e) {
3265
+ Bt(e.target.value);
1136
3266
  }
1137
- async function ze(e) {
1138
- var t, n;
1139
- await Ae(), (n = (t = I.value) == null ? void 0 : t.querySelector(`[data-file-id="${e}"]`)) == null || n.focus();
3267
+ async function Un(e) {
3268
+ var t, r;
3269
+ await zn(), (r = (t = P.value) == null ? void 0 : t.querySelector(`[data-file-id="${e}"]`)) == null || r.focus();
1140
3270
  }
1141
- function Ot(e, t) {
3271
+ function ks(e, t) {
1142
3272
  if (e.target !== e.currentTarget) return;
1143
3273
  if (e.key === "Enter" || e.key === " ") {
1144
- e.preventDefault(), q(t.id), ze(t.id);
3274
+ e.preventDefault(), He(t.id), Un(t.id);
1145
3275
  return;
1146
3276
  }
1147
3277
  if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
1148
3278
  e.preventDefault();
1149
- const n = f.value.findIndex((m) => m.id === t.id);
1150
- if (n < 0) return;
1151
- const l = e.key === "ArrowLeft" ? -1 : 1, d = f.value[(n + l + f.value.length) % f.value.length];
1152
- d && (q(d.id), ze(d.id));
3279
+ const r = L.value.findIndex((y) => y.id === t.id);
3280
+ if (r < 0) return;
3281
+ const u = e.key === "ArrowLeft" ? -1 : 1, c = L.value[(r + u + L.value.length) % L.value.length];
3282
+ c && (He(c.id), Un(c.id));
1153
3283
  }
1154
- function ue() {
1155
- o == null || o.focus();
3284
+ function wt() {
3285
+ M == null || M.focus();
1156
3286
  }
1157
- async function $t(e) {
1158
- var n;
1159
- p(`正在安装:${e.join(", ")}`);
3287
+ async function ws(e) {
3288
+ var r;
3289
+ h(`正在安装:${e.join(", ")}`);
1160
3290
  let t;
1161
3291
  try {
1162
- t = await b.loadPackages(e, {
1163
- onOutput: (l, d) => Q(l, d)
3292
+ t = await z.loadPackages(e, {
3293
+ onOutput: (u, c) => ge(u, c)
1164
3294
  });
1165
- } catch (l) {
1166
- const d = l instanceof Error ? l.message : String(l);
1167
- return p(`安装失败:${d}`), { ok: !1, durationMs: 0, error: { type: "RuntimeError", message: d } };
3295
+ } catch (u) {
3296
+ const c = u instanceof Error ? u.message : String(u);
3297
+ return h(`安装失败:${c}`), { ok: !1, durationMs: 0, error: { type: "RuntimeError", message: c } };
1168
3298
  }
1169
- return p(t.ok ? "安装完成" : `安装失败:${((n = t.error) == null ? void 0 : n.message) ?? "未知错误"}`), t;
3299
+ return h(t.ok ? "安装完成" : `安装失败:${((r = t.error) == null ? void 0 : r.message) ?? "未知错误"}`), t;
1170
3300
  }
1171
- function Lt() {
1172
- return b.checkSyntax(te());
3301
+ function Ss() {
3302
+ return z.checkSyntax(Ne());
1173
3303
  }
1174
- function It() {
1175
- return o;
3304
+ function xs() {
3305
+ return A(f.value);
3306
+ }
3307
+ function Es() {
3308
+ return M;
3309
+ }
3310
+ function qs() {
3311
+ return L.value.map(Ze);
1176
3312
  }
1177
- function Mt() {
1178
- return f.value.map(Y);
1179
- }
1180
- function Rt() {
1181
- return Y(y.value);
1182
- }
1183
- return r({
1184
- run: Me,
1185
- stop: Re,
1186
- clearOutput: He,
1187
- clearCode: je,
1188
- newFile: ke,
1189
- switchFile: q,
1190
- closeFile: Te,
1191
- copyCode: _e,
1192
- download: De,
1193
- openFile: Be,
1194
- focus: ue,
1195
- install: $t,
1196
- checkSyntax: Lt,
1197
- getEditorView: It,
1198
- getCode: te,
1199
- setCode: ge,
1200
- getFiles: Mt,
1201
- getActiveFile: Rt,
1202
- writeFile: wt,
1203
- readFile: xt,
1204
- listFiles: St,
1205
- downloadFile: Ve,
1206
- clearPersistedState: dt
1207
- }), (e, t) => (g(), v("div", {
1208
- class: B(["vpe-root", { "vpe-dark": u.theme === "dark" }]),
1209
- style: qe(rt.value)
3313
+ function Cs() {
3314
+ return Ze(w.value);
3315
+ }
3316
+ return n({
3317
+ run: qn,
3318
+ stop: Cn,
3319
+ clearOutput: Mn,
3320
+ clearCode: $n,
3321
+ newFile: zt,
3322
+ switchFile: He,
3323
+ closeFile: Ln,
3324
+ copyCode: Fn,
3325
+ download: Rn,
3326
+ openFile: Bn,
3327
+ focus: wt,
3328
+ install: ws,
3329
+ checkSyntax: Ss,
3330
+ executeSql: Zr,
3331
+ getSqlConfig: xs,
3332
+ openSqlConfig: _r,
3333
+ closeSqlConfig: yn,
3334
+ getEditorView: Es,
3335
+ getCode: Ne,
3336
+ setCode: ht,
3337
+ getFiles: qs,
3338
+ getActiveFile: Cs,
3339
+ writeFile: us,
3340
+ readFile: cs,
3341
+ listFiles: ds,
3342
+ downloadFile: In,
3343
+ saveToServer: Hn,
3344
+ refreshServerFiles: We,
3345
+ clearPersistedState: Lr
3346
+ }), (e, t) => (m(), g("div", {
3347
+ ref_key: "rootEl",
3348
+ ref: p,
3349
+ class: ie(["vpe-root", wr.value]),
3350
+ style: jn(kr.value)
1210
3351
  }, [
1211
- u.showToolbar ? (g(), v("div", On, [
1212
- M.value !== "running" ? (g(), v("button", {
1213
- key: 0,
1214
- class: "vpe-btn vpe-btn--primary",
1215
- type: "button",
1216
- title: y.value.language === "python" ? "运行 (Ctrl+Enter)" : "仅支持执行 Python 文件",
1217
- disabled: M.value === "loading" || y.value.language !== "python",
1218
- onClick: Me
1219
- }, [
1220
- $(S(wn)),
1221
- t[2] || (t[2] = c("span", null, "运行", -1))
1222
- ], 8, $n)) : (g(), v("button", {
3352
+ a.showToolbar ? (m(), g("div", Ya, [
3353
+ It.value ? (m(), g("button", {
1223
3354
  key: 1,
1224
3355
  class: "vpe-btn vpe-btn--stop",
1225
3356
  type: "button",
1226
3357
  title: "中断执行",
1227
- onClick: Re
3358
+ onClick: Cn
1228
3359
  }, [
1229
- $(S(xn)),
1230
- t[3] || (t[3] = c("span", null, "停止", -1))
1231
- ])),
1232
- t[6] || (t[6] = c("span", {
3360
+ j(B(za)),
3361
+ t[19] || (t[19] = l("span", null, "停止", -1))
3362
+ ])) : (m(), g("button", {
3363
+ key: 0,
3364
+ class: "vpe-btn vpe-btn--primary",
3365
+ type: "button",
3366
+ title: qr.value,
3367
+ disabled: Cr.value,
3368
+ onClick: qn
3369
+ }, [
3370
+ j(B(Da)),
3371
+ t[18] || (t[18] = l("span", null, "运行", -1))
3372
+ ], 8, Xa)),
3373
+ t[31] || (t[31] = l("span", {
1233
3374
  class: "vpe-divider",
1234
3375
  "aria-hidden": "true"
1235
3376
  }, null, -1)),
1236
- c("button", {
3377
+ l("button", {
1237
3378
  class: "vpe-btn",
1238
3379
  type: "button",
1239
3380
  title: "新建文件",
1240
3381
  "aria-label": "新建文件",
1241
- disabled: u.readOnly,
1242
- onClick: ke
3382
+ disabled: a.readOnly,
3383
+ onClick: zt
1243
3384
  }, [
1244
- $(S(Sn))
1245
- ], 8, Ln),
1246
- c("button", {
3385
+ j(B(ja)),
3386
+ t[20] || (t[20] = l("span", null, "新建", -1))
3387
+ ], 8, eo),
3388
+ l("button", {
1247
3389
  class: "vpe-btn",
1248
3390
  type: "button",
1249
3391
  title: "打开本地文件",
1250
3392
  "aria-label": "打开本地文件",
1251
- disabled: u.readOnly,
1252
- onClick: Be
3393
+ disabled: a.readOnly,
3394
+ onClick: Bn
1253
3395
  }, [
1254
- $(S(En))
1255
- ], 8, In),
1256
- c("button", {
3396
+ j(B(Va)),
3397
+ t[21] || (t[21] = l("span", null, "本地文件", -1))
3398
+ ], 8, to),
3399
+ l("button", {
1257
3400
  class: "vpe-btn",
1258
3401
  type: "button",
1259
3402
  title: "下载当前文件",
1260
3403
  "aria-label": "下载当前文件",
1261
- onClick: De
3404
+ onClick: Rn
1262
3405
  }, [
1263
- $(S(Xe))
3406
+ j(B(ur)),
3407
+ t[22] || (t[22] = l("span", null, "下载", -1))
1264
3408
  ]),
1265
- c("button", {
3409
+ l("button", {
1266
3410
  class: "vpe-btn",
1267
3411
  type: "button",
1268
3412
  title: "虚拟文件(下载 Python 生成的文件)",
1269
3413
  "aria-label": "虚拟文件",
1270
- onClick: vt
3414
+ onClick: is
1271
3415
  }, [
1272
- $(S(Ge)),
1273
- t[4] || (t[4] = c("span", null, "虚拟文件", -1))
3416
+ j(B(lr)),
3417
+ t[23] || (t[23] = l("span", null, "虚拟文件", -1))
1274
3418
  ]),
1275
- c("button", {
1276
- class: B(["vpe-btn", { "vpe-btn--copied": T.value }]),
3419
+ Oe.value ? (m(), g("button", {
3420
+ key: 2,
3421
+ class: "vpe-btn",
1277
3422
  type: "button",
1278
- title: T.value ? "已复制" : "复制代码",
1279
- "aria-label": T.value ? "已复制" : "复制代码",
1280
- onClick: _e
3423
+ title: W.value ? "正在处理服务端文件…" : "保存当前文件到服务端",
3424
+ "aria-label": "保存到服务端",
3425
+ disabled: W.value,
3426
+ onClick: Hn
1281
3427
  }, [
1282
- T.value ? (g(), We(S(Pn), { key: 0 })) : (g(), We(S(Fn), { key: 1 }))
1283
- ], 10, Mn),
1284
- c("button", {
3428
+ j(B(Ga)),
3429
+ t[24] || (t[24] = l("span", null, "保存", -1))
3430
+ ], 8, no)) : N("", !0),
3431
+ Oe.value ? (m(), g("button", {
3432
+ key: 3,
3433
+ class: "vpe-btn",
3434
+ type: "button",
3435
+ title: "查询服务端已保存文件",
3436
+ "aria-label": "已保存文件",
3437
+ onClick: fs
3438
+ }, [
3439
+ j(B(Wa)),
3440
+ t[25] || (t[25] = l("span", null, "已保存文件", -1))
3441
+ ])) : N("", !0),
3442
+ a.showSqlConfig && de.value ? (m(), g("button", {
3443
+ key: 4,
3444
+ class: "vpe-btn",
3445
+ type: "button",
3446
+ title: "新建连接",
3447
+ "aria-label": "新建连接",
3448
+ onClick: Hr
3449
+ }, [
3450
+ j(B(Za)),
3451
+ t[26] || (t[26] = l("span", null, "新建连接", -1))
3452
+ ])) : N("", !0),
3453
+ l("button", {
3454
+ class: ie(["vpe-btn", { "vpe-btn--copied": me.value }]),
3455
+ type: "button",
3456
+ title: me.value ? "已复制" : "复制代码",
3457
+ "aria-label": me.value ? "已复制" : "复制代码",
3458
+ onClick: Fn
3459
+ }, [
3460
+ me.value ? (m(), Vn(B(Ka), { key: 0 })) : (m(), Vn(B(Qa), { key: 1 })),
3461
+ me.value ? (m(), g("span", so, "已复制")) : (m(), g("span", ao, "复制"))
3462
+ ], 10, ro),
3463
+ l("button", {
1285
3464
  class: "vpe-btn",
1286
3465
  type: "button",
1287
3466
  title: "清空当前文件",
1288
3467
  "aria-label": "清空当前文件",
1289
- disabled: u.readOnly,
1290
- onClick: je
3468
+ disabled: a.readOnly,
3469
+ onClick: $n
1291
3470
  }, [
1292
- $(S(Ze))
1293
- ], 8, Rn),
1294
- t[7] || (t[7] = c("span", {
3471
+ j(B(ir)),
3472
+ t[27] || (t[27] = l("span", null, "清空", -1))
3473
+ ], 8, oo),
3474
+ t[32] || (t[32] = l("span", {
1295
3475
  class: "vpe-divider",
1296
3476
  "aria-hidden": "true"
1297
3477
  }, null, -1)),
1298
- c("label", Hn, [
1299
- $(S(Ge)),
1300
- Dt(c("input", {
1301
- "onUpdate:modelValue": t[0] || (t[0] = (n) => A.value = n),
3478
+ l("label", io, [
3479
+ j(B(lr)),
3480
+ J(l("input", {
3481
+ "onUpdate:modelValue": t[0] || (t[0] = (r) => Ie.value = r),
1302
3482
  class: "vpe-file-input",
1303
3483
  type: "text",
1304
3484
  spellcheck: "false",
1305
3485
  "aria-label": "文件名",
1306
- onBlur: Ft,
1307
- onKeydown: Pt
3486
+ onBlur: ys,
3487
+ onKeydown: hs
1308
3488
  }, null, 544), [
1309
- [Ut, A.value]
3489
+ [he, Ie.value]
1310
3490
  ])
1311
3491
  ]),
1312
- t[8] || (t[8] = c("span", {
3492
+ t[33] || (t[33] = l("span", {
1313
3493
  class: "vpe-spacer",
1314
3494
  "aria-hidden": "true"
1315
3495
  }, null, -1)),
1316
- c("span", {
1317
- class: B(["vpe-status", `vpe-status--${M.value}`])
3496
+ a.showSqlConfig && de.value && (f.value.mode === "http" || f.value.endpoint) ? (m(), g(D, { key: 5 }, [
3497
+ J(l("select", {
3498
+ "onUpdate:modelValue": t[1] || (t[1] = (r) => f.value.connectionId = r),
3499
+ class: "vpe-lang vpe-sql-connection",
3500
+ title: "切换已保存连接",
3501
+ "aria-label": "切换已保存连接",
3502
+ disabled: ze.value,
3503
+ onChange: Ar
3504
+ }, [
3505
+ l("option", uo, _(ze.value ? "加载中…" : Ce.value.length ? "选择连接" : "暂无已保存连接"), 1),
3506
+ (m(!0), g(D, null, le(Ce.value, (r) => (m(), g("option", {
3507
+ key: r.id,
3508
+ value: r.id
3509
+ }, _(r.name), 9, co))), 128))
3510
+ ], 40, lo), [
3511
+ [St, f.value.connectionId]
3512
+ ]),
3513
+ l("button", {
3514
+ class: "vpe-btn vpe-btn--sm",
3515
+ type: "button",
3516
+ title: "管理连接配置",
3517
+ "aria-label": "管理连接配置",
3518
+ onClick: Ir
3519
+ }, " 管理 ")
3520
+ ], 64)) : N("", !0),
3521
+ yt.value && fn.value ? (m(), g("div", po, [
3522
+ t[29] || (t[29] = l("span", { class: "vpe-runtime-label" }, "运行环境:", -1)),
3523
+ J(l("select", {
3524
+ "onUpdate:modelValue": t[2] || (t[2] = (r) => Q.value = r),
3525
+ class: "vpe-lang vpe-runtime",
3526
+ title: "Python 运行环境",
3527
+ "aria-label": "Python 运行环境",
3528
+ onChange: Gr
3529
+ }, [...t[28] || (t[28] = [
3530
+ l("option", { value: "browser" }, "浏览器", -1),
3531
+ l("option", { value: "server" }, "服务端", -1)
3532
+ ])], 544), [
3533
+ [St, Q.value]
3534
+ ])
3535
+ ])) : N("", !0),
3536
+ l("span", {
3537
+ class: ie(["vpe-status", `vpe-status--${Er.value}`])
1318
3538
  }, [
1319
- t[5] || (t[5] = c("span", {
3539
+ t[30] || (t[30] = l("span", {
1320
3540
  class: "vpe-status-dot",
1321
3541
  "aria-hidden": "true"
1322
3542
  }, null, -1)),
1323
- c("span", null, W(it.value), 1)
3543
+ l("span", null, _(xr.value), 1)
1324
3544
  ], 2),
1325
- c("select", {
3545
+ l("select", {
1326
3546
  class: "vpe-lang",
1327
- value: y.value.language,
3547
+ value: w.value.language,
1328
3548
  title: "编辑器语言",
1329
3549
  "aria-label": "编辑器语言",
1330
- disabled: u.readOnly,
1331
- onChange: Ct
3550
+ disabled: a.readOnly,
3551
+ onChange: bs
1332
3552
  }, [
1333
- (g(!0), v(se, null, de(S(fe), (n) => (g(), v("option", {
1334
- key: n.value,
1335
- value: n.value
1336
- }, W(n.label), 9, Nn))), 128))
1337
- ], 40, Tn)
1338
- ])) : z("", !0),
1339
- u.showTabs ? (g(), v("div", {
3553
+ (m(!0), g(D, null, le(B(Mt), (r) => (m(), g("option", {
3554
+ key: r.value,
3555
+ value: r.value
3556
+ }, _(r.label), 9, vo))), 128))
3557
+ ], 40, fo)
3558
+ ])) : N("", !0),
3559
+ a.showTabs ? (m(), g("div", {
1340
3560
  key: 1,
1341
3561
  ref_key: "tabsEl",
1342
- ref: I,
3562
+ ref: P,
1343
3563
  class: "vpe-tabs",
1344
3564
  role: "tablist",
1345
3565
  "aria-label": "文件"
1346
3566
  }, [
1347
- (g(!0), v(se, null, de(f.value, (n) => (g(), v("div", {
1348
- key: n.id,
1349
- class: B(["vpe-tab", { "vpe-tab--active": n.id === y.value.id }]),
3567
+ (m(!0), g(D, null, le(L.value, (r) => (m(), g("div", {
3568
+ key: r.id,
3569
+ class: ie(["vpe-tab", { "vpe-tab--active": r.id === w.value.id }]),
1350
3570
  role: "tab",
1351
3571
  tabindex: "0",
1352
- "aria-selected": n.id === y.value.id,
1353
- "data-file-id": n.id,
1354
- title: n.name,
1355
- onClick: (l) => q(n.id),
1356
- onKeydown: (l) => Ot(l, n)
3572
+ "aria-selected": r.id === w.value.id,
3573
+ "data-file-id": r.id,
3574
+ title: r.name,
3575
+ onClick: (u) => He(r.id),
3576
+ onKeydown: (u) => ks(u, r)
1357
3577
  }, [
1358
- c("span", {
1359
- class: B(["vpe-tab-dot", `vpe-tab-dot--${n.language}`]),
3578
+ l("span", {
3579
+ class: ie(["vpe-tab-dot", `vpe-tab-dot--${r.language}`]),
1360
3580
  "aria-hidden": "true"
1361
3581
  }, null, 2),
1362
- c("span", _n, W(n.name), 1),
1363
- f.value.length > 1 ? (g(), v("button", {
1364
- key: 0,
3582
+ l("span", go, _(r.name), 1),
3583
+ l("button", {
1365
3584
  class: "vpe-tab-close",
1366
3585
  type: "button",
1367
- title: `关闭 ${n.name}`,
1368
- "aria-label": `关闭 ${n.name}`,
1369
- disabled: u.readOnly,
1370
- onClick: Vt((l) => Te(n.id), ["stop"])
3586
+ title: `关闭 ${r.name}`,
3587
+ "aria-label": `关闭 ${r.name}`,
3588
+ disabled: a.readOnly,
3589
+ onClick: Qn((u) => Ln(r.id), ["stop"])
1371
3590
  }, [
1372
- $(S(Ye))
1373
- ], 8, Dn)) : z("", !0)
1374
- ], 42, jn))), 128)),
1375
- c("button", {
3591
+ j(B(lt))
3592
+ ], 8, yo)
3593
+ ], 42, mo))), 128)),
3594
+ l("button", {
1376
3595
  class: "vpe-tabs-add",
1377
3596
  type: "button",
1378
3597
  title: "新建文件",
1379
3598
  "aria-label": "新建文件",
1380
- disabled: u.readOnly,
1381
- onClick: ke
3599
+ disabled: a.readOnly,
3600
+ onClick: zt
1382
3601
  }, [
1383
- $(S(Cn))
1384
- ], 8, Un)
1385
- ], 512)) : z("", !0),
1386
- c("input", {
3602
+ j(B(Ja))
3603
+ ], 8, ho)
3604
+ ], 512)) : N("", !0),
3605
+ l("input", {
1387
3606
  ref_key: "fileInputEl",
1388
- ref: H,
3607
+ ref: T,
1389
3608
  class: "vpe-file-hidden",
1390
3609
  type: "file",
1391
3610
  accept: ".py,.pyw,.sql,.js,.mjs,.cjs,.jsx,.ts,.json,.txt,text/x-python,text/plain,application/json",
1392
- onChange: Et
3611
+ onChange: gs
1393
3612
  }, null, 544),
1394
- c("div", {
3613
+ l("div", {
1395
3614
  ref_key: "editorEl",
1396
- ref: P,
3615
+ ref: b,
1397
3616
  class: "vpe-editor"
1398
3617
  }, null, 512),
1399
- u.showOutput ? (g(), v("div", {
3618
+ a.showOutput ? (m(), g("div", {
1400
3619
  key: 2,
3620
+ class: ie(["vpe-output-resizer", { "vpe-output-resizer--active": F.value }]),
3621
+ role: "separator",
3622
+ "aria-orientation": "horizontal",
3623
+ "aria-label": "调整输出面板高度",
3624
+ title: "拖动调整输出高度,双击复位",
3625
+ tabindex: "0",
3626
+ onPointerdown: ns,
3627
+ onDblclick: rs,
3628
+ onKeydown: ss
3629
+ }, null, 34)) : N("", !0),
3630
+ a.showOutput ? (m(), g("div", {
3631
+ key: 3,
3632
+ ref_key: "outputPanelEl",
3633
+ ref: E,
1401
3634
  class: "vpe-output",
1402
- style: qe({ height: at.value })
3635
+ style: jn({ height: Sr.value })
1403
3636
  }, [
1404
- c("div", Vn, [
1405
- t[9] || (t[9] = c("span", null, "输出", -1)),
1406
- c("button", {
3637
+ l("div", bo, [
3638
+ t[34] || (t[34] = l("span", null, "输出", -1)),
3639
+ l("button", {
1407
3640
  class: "vpe-btn vpe-btn--sm",
1408
3641
  type: "button",
1409
3642
  title: "清空输出",
1410
- onClick: He
3643
+ onClick: Mn
1411
3644
  }, [
1412
- $(S(Ze))
3645
+ j(B(ir))
1413
3646
  ])
1414
3647
  ]),
1415
- c("pre", {
1416
- ref_key: "outputEl",
1417
- ref: w,
1418
- class: "vpe-output-body"
1419
- }, [
1420
- C.value.length ? (g(!0), v(se, { key: 0 }, de(C.value, (n) => (g(), v("span", {
1421
- key: n.id,
1422
- class: B(["vpe-line", `vpe-line--${n.stream}`])
1423
- }, W(n.text) + `
1424
- `, 3))), 128)) : (g(), v("span", Bn, "暂无输出,点击“运行”或按 Ctrl+Enter 执行代码"))
1425
- ], 512)
1426
- ], 4)) : z("", !0),
1427
- D.value ? (g(), v("div", zn, [
1428
- c("div", Kn, [
1429
- t[10] || (t[10] = c("span", { class: "vpe-fs-title" }, "虚拟文件", -1)),
1430
- t[11] || (t[11] = c("span", {
3648
+ l("div", ko, [
3649
+ ve.value.length ? (m(), g("div", wo, [
3650
+ (m(!0), g(D, null, le(ve.value, (r, u) => (m(), g("section", {
3651
+ key: u,
3652
+ class: "vpe-sql-result"
3653
+ }, [
3654
+ l("div", So, [
3655
+ l("span", null, "结果 " + _(u + 1), 1),
3656
+ l("span", null, _(Jr(r)), 1)
3657
+ ]),
3658
+ r.columns.length ? (m(), g("div", xo, [
3659
+ l("table", Eo, [
3660
+ l("thead", null, [
3661
+ l("tr", null, [
3662
+ (m(!0), g(D, null, le(r.columns, (c, y) => (m(), g("th", { key: y }, _(c), 1))), 128))
3663
+ ])
3664
+ ]),
3665
+ l("tbody", null, [
3666
+ (m(!0), g(D, null, le(r.rows, (c, y) => (m(), g("tr", { key: y }, [
3667
+ (m(!0), g(D, null, le(c, (S, $) => (m(), g("td", {
3668
+ key: $,
3669
+ class: ie({ "vpe-sql-null": S === null })
3670
+ }, _(Kr(S)), 3))), 128))
3671
+ ]))), 128))
3672
+ ])
3673
+ ]),
3674
+ r.rows.length ? N("", !0) : (m(), g("div", qo, "查询无数据"))
3675
+ ])) : (m(), g("div", Co, "影响 " + _(r.affectedRows ?? 0) + " 行", 1))
3676
+ ]))), 128))
3677
+ ])) : N("", !0),
3678
+ l("pre", {
3679
+ ref_key: "outputEl",
3680
+ ref: R,
3681
+ class: "vpe-output-body"
3682
+ }, [
3683
+ G.value.length ? (m(!0), g(D, { key: 0 }, le(G.value, (r) => (m(), g("span", {
3684
+ key: r.id,
3685
+ class: ie(["vpe-line", `vpe-line--${r.stream}`])
3686
+ }, _(r.text) + `
3687
+ `, 3))), 128)) : (m(), g("span", Po, "暂无输出,点击“运行”或按 Ctrl+Enter 执行代码"))
3688
+ ], 512)
3689
+ ]),
3690
+ Je.value && Ae.value && It.value ? (m(), g("div", Oo, [
3691
+ t[35] || (t[35] = l("span", {
3692
+ class: "vpe-terminal-prompt",
3693
+ "aria-hidden": "true"
3694
+ }, "›", -1)),
3695
+ J(l("input", {
3696
+ "onUpdate:modelValue": t[3] || (t[3] = (r) => H.value = r),
3697
+ class: "vpe-terminal-field",
3698
+ type: "text",
3699
+ spellcheck: "false",
3700
+ placeholder: "输入后按 Enter 发送给 input()",
3701
+ "aria-label": "标准输入",
3702
+ onKeydown: Ls(Qn(xn, ["prevent"]), ["enter"])
3703
+ }, null, 40, Mo), [
3704
+ [he, H.value]
3705
+ ]),
3706
+ l("button", {
3707
+ class: "vpe-btn vpe-btn--sm",
3708
+ type: "button",
3709
+ onClick: xn
3710
+ }, " 发送 ")
3711
+ ])) : N("", !0)
3712
+ ], 4)) : N("", !0),
3713
+ qe.value ? (m(), g("div", No, [
3714
+ l("div", To, [
3715
+ t[36] || (t[36] = l("span", { class: "vpe-fs-title" }, "虚拟文件", -1)),
3716
+ t[37] || (t[37] = l("span", {
1431
3717
  class: "vpe-spacer",
1432
3718
  "aria-hidden": "true"
1433
3719
  }, null, -1)),
1434
- c("button", {
3720
+ l("button", {
1435
3721
  class: "vpe-btn vpe-btn--sm",
1436
3722
  type: "button",
1437
3723
  title: "刷新文件列表",
1438
- disabled: N.value,
1439
- onClick: Ue
1440
- }, " 刷新 ", 8, An),
1441
- c("button", {
3724
+ disabled: Ye.value,
3725
+ onClick: _n
3726
+ }, " 刷新 ", 8, Lo),
3727
+ l("button", {
1442
3728
  class: "vpe-btn vpe-btn--sm",
1443
3729
  type: "button",
1444
3730
  title: "关闭虚拟文件面板",
1445
3731
  "aria-label": "关闭虚拟文件面板",
1446
- onClick: t[1] || (t[1] = (n) => D.value = !1)
3732
+ onClick: t[4] || (t[4] = (r) => qe.value = !1)
1447
3733
  }, [
1448
- $(S(Ye))
3734
+ j(B(lt))
1449
3735
  ])
1450
3736
  ]),
1451
- c("div", qn, [
1452
- N.value ? (g(), v("div", Wn, "正在读取虚拟文件…")) : (g(), v(se, { key: 1 }, [
1453
- j.value.length ? z("", !0) : (g(), v("div", Jn, " 暂无文件。运行 Python 代码创建文件后再刷新。 ")),
1454
- (g(!0), v(se, null, de(j.value, (n) => (g(), v("div", {
1455
- key: n.path,
1456
- class: B(["vpe-fs-item", { "vpe-fs-item--dir": n.isDirectory }])
3737
+ l("div", $o, [
3738
+ Ye.value ? (m(), g("div", Fo, "正在读取虚拟文件…")) : (m(), g(D, { key: 1 }, [
3739
+ Xe.value.length ? N("", !0) : (m(), g("div", Ro, " 暂无文件。运行 Python 代码创建文件后再刷新。 ")),
3740
+ (m(!0), g(D, null, le(Xe.value, (r) => (m(), g("div", {
3741
+ key: r.path,
3742
+ class: ie(["vpe-fs-item", { "vpe-fs-item--dir": r.isDirectory }])
1457
3743
  }, [
1458
- c("span", {
3744
+ l("span", {
1459
3745
  class: "vpe-fs-name",
1460
- title: n.path
1461
- }, W(n.path), 9, Zn),
1462
- c("span", Gn, W(n.isDirectory ? "目录" : bt(n.size)), 1),
1463
- n.isDirectory ? z("", !0) : (g(), v("button", {
3746
+ title: r.path
3747
+ }, _(r.path), 9, _o),
3748
+ l("span", Io, _(r.isDirectory ? "目录" : Vt(r.size)), 1),
3749
+ r.isDirectory ? N("", !0) : (m(), g("button", {
1464
3750
  key: 0,
1465
3751
  class: "vpe-btn vpe-btn--sm",
1466
3752
  type: "button",
1467
- title: `下载 ${n.name}`,
1468
- "aria-label": `下载 ${n.name}`,
1469
- onClick: (l) => Ve(n.path)
3753
+ title: `下载 ${r.name}`,
3754
+ "aria-label": `下载 ${r.name}`,
3755
+ onClick: (u) => In(r.path)
1470
3756
  }, [
1471
- $(S(Xe))
1472
- ], 8, Xn))
3757
+ j(B(ur))
3758
+ ], 8, Ho))
1473
3759
  ], 2))), 128))
1474
3760
  ], 64))
1475
3761
  ])
1476
- ])) : z("", !0)
3762
+ ])) : N("", !0),
3763
+ Se.value && Oe.value ? (m(), g("div", Bo, [
3764
+ l("div", Uo, [
3765
+ t[38] || (t[38] = l("span", { class: "vpe-fs-title" }, "服务端文件", -1)),
3766
+ t[39] || (t[39] = l("span", {
3767
+ class: "vpe-spacer",
3768
+ "aria-hidden": "true"
3769
+ }, null, -1)),
3770
+ l("button", {
3771
+ class: "vpe-btn vpe-btn--sm",
3772
+ type: "button",
3773
+ title: "刷新文件列表",
3774
+ disabled: dt.value,
3775
+ onClick: t[5] || (t[5] = (r) => We())
3776
+ }, " 刷新 ", 8, Ao),
3777
+ l("button", {
3778
+ class: "vpe-btn vpe-btn--sm",
3779
+ type: "button",
3780
+ title: "关闭服务端文件面板",
3781
+ "aria-label": "关闭服务端文件面板",
3782
+ onClick: t[6] || (t[6] = (r) => Se.value = !1)
3783
+ }, [
3784
+ j(B(lt))
3785
+ ])
3786
+ ]),
3787
+ l("div", Do, [
3788
+ dt.value ? (m(), g("div", zo, "正在读取服务端文件…")) : (m(), g(D, { key: 1 }, [
3789
+ !et.value.length && !De.value ? (m(), g("div", jo, " 暂无已保存文件。点击工具栏“保存”按钮把当前文件保存到服务端。 ")) : N("", !0),
3790
+ (m(!0), g(D, null, le(et.value, (r) => (m(), g("div", {
3791
+ key: r.id,
3792
+ class: "vpe-fs-item"
3793
+ }, [
3794
+ l("span", {
3795
+ class: "vpe-fs-name",
3796
+ title: r.name
3797
+ }, _(r.name), 9, Vo),
3798
+ l("span", {
3799
+ class: "vpe-fs-size",
3800
+ title: ps(r.updatedAt)
3801
+ }, _(Vt(r.size)), 9, Qo),
3802
+ l("button", {
3803
+ class: "vpe-btn vpe-btn--sm",
3804
+ type: "button",
3805
+ title: `打开 ${r.name}`,
3806
+ disabled: W.value,
3807
+ onClick: (u) => vs(r)
3808
+ }, " 打开 ", 8, Ko),
3809
+ l("button", {
3810
+ class: "vpe-btn vpe-btn--sm",
3811
+ type: "button",
3812
+ title: `删除 ${r.name}`,
3813
+ disabled: W.value,
3814
+ onClick: (u) => ms(r)
3815
+ }, " 删除 ", 8, Jo)
3816
+ ]))), 128)),
3817
+ De.value ? (m(), g("p", Zo, _(De.value), 1)) : N("", !0)
3818
+ ], 64))
3819
+ ])
3820
+ ])) : N("", !0),
3821
+ Fe.value && de.value ? (m(), g("div", Go, [
3822
+ l("div", Wo, [
3823
+ l("span", Yo, _(Pr.value), 1),
3824
+ t[40] || (t[40] = l("span", {
3825
+ class: "vpe-spacer",
3826
+ "aria-hidden": "true"
3827
+ }, null, -1)),
3828
+ l("button", {
3829
+ class: "vpe-btn vpe-btn--sm",
3830
+ type: "button",
3831
+ title: "关闭 SQL 连接配置",
3832
+ "aria-label": "关闭 SQL 连接配置",
3833
+ onClick: yn
3834
+ }, [
3835
+ j(B(lt))
3836
+ ])
3837
+ ]),
3838
+ l("div", Xo, [
3839
+ l("label", ei, [
3840
+ t[42] || (t[42] = l("span", { class: "vpe-sql-label" }, "执行方式", -1)),
3841
+ J(l("select", {
3842
+ "onUpdate:modelValue": t[7] || (t[7] = (r) => f.value.mode = r),
3843
+ class: "vpe-sql-input",
3844
+ onChange: Br
3845
+ }, [...t[41] || (t[41] = [
3846
+ l("option", { value: "sqlite" }, "浏览器内 SQLite(无需服务端)", -1),
3847
+ l("option", { value: "http" }, "HTTP 服务(后端网关)", -1)
3848
+ ])], 544), [
3849
+ [St, f.value.mode]
3850
+ ])
3851
+ ]),
3852
+ f.value.mode === "sqlite" ? (m(), g(D, { key: 0 }, [
3853
+ l("label", ti, [
3854
+ t[43] || (t[43] = l("span", { class: "vpe-sql-label" }, "数据库文件", -1)),
3855
+ J(l("input", {
3856
+ "onUpdate:modelValue": t[8] || (t[8] = (r) => f.value.connection.database = r),
3857
+ class: "vpe-sql-input",
3858
+ type: "text",
3859
+ spellcheck: "false",
3860
+ placeholder: ":memory:",
3861
+ onChange: ye
3862
+ }, null, 544), [
3863
+ [he, f.value.connection.database]
3864
+ ])
3865
+ ]),
3866
+ t[44] || (t[44] = l("p", { class: "vpe-sql-hint" }, " SQLite 在浏览器内运行,数据仅保存在当前页面内存;“停止”或刷新后会丢失。 ", -1))
3867
+ ], 64)) : (m(), g(D, { key: 1 }, [
3868
+ l("label", ni, [
3869
+ t[45] || (t[45] = l("span", { class: "vpe-sql-label" }, "连接名称", -1)),
3870
+ J(l("input", {
3871
+ "onUpdate:modelValue": t[9] || (t[9] = (r) => ee.value = r),
3872
+ class: "vpe-sql-input",
3873
+ type: "text",
3874
+ spellcheck: "false",
3875
+ placeholder: "用于保存和切换连接"
3876
+ }, null, 512), [
3877
+ [he, ee.value]
3878
+ ])
3879
+ ]),
3880
+ l("label", ri, [
3881
+ t[46] || (t[46] = l("span", { class: "vpe-sql-label" }, "数据库类型", -1)),
3882
+ J(l("select", {
3883
+ "onUpdate:modelValue": t[10] || (t[10] = (r) => f.value.connection.dialect = r),
3884
+ class: "vpe-sql-input",
3885
+ onChange: Ur
3886
+ }, [
3887
+ (m(!0), g(D, null, le(B(ut), (r) => (m(), g("option", {
3888
+ key: r.value,
3889
+ value: r.value
3890
+ }, _(r.label), 9, si))), 128))
3891
+ ], 544), [
3892
+ [St, f.value.connection.dialect]
3893
+ ])
3894
+ ]),
3895
+ l("div", ai, [
3896
+ l("label", oi, [
3897
+ t[47] || (t[47] = l("span", { class: "vpe-sql-label" }, "主机", -1)),
3898
+ J(l("input", {
3899
+ "onUpdate:modelValue": t[11] || (t[11] = (r) => f.value.connection.host = r),
3900
+ class: "vpe-sql-input",
3901
+ type: "text",
3902
+ spellcheck: "false",
3903
+ placeholder: "127.0.0.1",
3904
+ onChange: ye
3905
+ }, null, 544), [
3906
+ [he, f.value.connection.host]
3907
+ ])
3908
+ ]),
3909
+ l("label", ii, [
3910
+ t[48] || (t[48] = l("span", { class: "vpe-sql-label" }, "端口", -1)),
3911
+ J(l("input", {
3912
+ "onUpdate:modelValue": t[12] || (t[12] = (r) => f.value.connection.port = r),
3913
+ class: "vpe-sql-input",
3914
+ type: "number",
3915
+ min: "1",
3916
+ max: "65535",
3917
+ placeholder: "3306",
3918
+ onChange: ye
3919
+ }, null, 544), [
3920
+ [
3921
+ he,
3922
+ f.value.connection.port,
3923
+ void 0,
3924
+ { number: !0 }
3925
+ ]
3926
+ ])
3927
+ ])
3928
+ ]),
3929
+ l("div", li, [
3930
+ l("label", ui, [
3931
+ t[49] || (t[49] = l("span", { class: "vpe-sql-label" }, "用户名", -1)),
3932
+ J(l("input", {
3933
+ "onUpdate:modelValue": t[13] || (t[13] = (r) => f.value.connection.user = r),
3934
+ class: "vpe-sql-input",
3935
+ type: "text",
3936
+ autocomplete: "off",
3937
+ spellcheck: "false",
3938
+ onChange: ye
3939
+ }, null, 544), [
3940
+ [he, f.value.connection.user]
3941
+ ])
3942
+ ]),
3943
+ l("label", ci, [
3944
+ t[50] || (t[50] = l("span", { class: "vpe-sql-label" }, "密码", -1)),
3945
+ J(l("input", {
3946
+ "onUpdate:modelValue": t[14] || (t[14] = (r) => f.value.connection.password = r),
3947
+ class: "vpe-sql-input",
3948
+ type: "password",
3949
+ autocomplete: "new-password",
3950
+ placeholder: f.value.connectionId ? "已保存(留空不修改)" : "",
3951
+ onChange: ye
3952
+ }, null, 40, di), [
3953
+ [he, f.value.connection.password]
3954
+ ])
3955
+ ])
3956
+ ]),
3957
+ l("label", pi, [
3958
+ t[51] || (t[51] = l("span", { class: "vpe-sql-label" }, "数据库名", -1)),
3959
+ J(l("input", {
3960
+ "onUpdate:modelValue": t[15] || (t[15] = (r) => f.value.connection.database = r),
3961
+ class: "vpe-sql-input",
3962
+ type: "text",
3963
+ spellcheck: "false",
3964
+ placeholder: "database",
3965
+ onChange: ye
3966
+ }, null, 544), [
3967
+ [he, f.value.connection.database]
3968
+ ])
3969
+ ]),
3970
+ a.sqlEndpointLocked ? N("", !0) : (m(), g("label", fi, [
3971
+ t[52] || (t[52] = l("span", { class: "vpe-sql-label" }, "服务端点", -1)),
3972
+ J(l("input", {
3973
+ "onUpdate:modelValue": t[16] || (t[16] = (r) => f.value.endpoint = r),
3974
+ class: "vpe-sql-input",
3975
+ type: "url",
3976
+ spellcheck: "false",
3977
+ placeholder: "https://example.com/api/sql",
3978
+ onChange: ye
3979
+ }, null, 544), [
3980
+ [he, f.value.endpoint]
3981
+ ])
3982
+ ])),
3983
+ a.sqlEndpointLocked ? (m(), g("p", vi, "服务端点由系统预置,无需填写。")) : N("", !0),
3984
+ t[53] || (t[53] = l("p", { class: "vpe-sql-hint" }, " 执行时会把连接信息与 SQL POST 到该端点,由后端网关连接真实数据库。建议使用 HTTPS,并避免在前端配置高权限账号。 ", -1))
3985
+ ], 64)),
3986
+ l("div", mi, [
3987
+ l("button", {
3988
+ class: "vpe-btn vpe-btn--primary",
3989
+ type: "button",
3990
+ disabled: Re.value,
3991
+ onClick: Qr
3992
+ }, _(Re.value ? "测试中…" : "测试连接"), 9, gi),
3993
+ f.value.mode === "http" ? (m(), g("button", {
3994
+ key: 0,
3995
+ class: "vpe-btn",
3996
+ type: "button",
3997
+ disabled: te.value,
3998
+ onClick: zr
3999
+ }, " 保存 ", 8, yi)) : N("", !0),
4000
+ f.value.mode === "http" && f.value.connectionId ? (m(), g("button", {
4001
+ key: 1,
4002
+ class: "vpe-btn",
4003
+ type: "button",
4004
+ disabled: te.value,
4005
+ onClick: jr
4006
+ }, " 删除 ", 8, hi)) : N("", !0),
4007
+ tt.value ? (m(), g("span", {
4008
+ key: 2,
4009
+ class: ie(["vpe-sql-test", pt.value ? "vpe-sql-test--ok" : "vpe-sql-test--err"])
4010
+ }, _(tt.value), 3)) : N("", !0),
4011
+ f.value.mode === "http" && Pe.value ? (m(), g("span", bi, _(Pe.value), 1)) : N("", !0),
4012
+ f.value.mode === "http" && ne.value ? (m(), g("span", {
4013
+ key: 4,
4014
+ class: ie(["vpe-sql-test", je.value ? "vpe-sql-test--ok" : "vpe-sql-test--err"])
4015
+ }, _(ne.value), 3)) : N("", !0)
4016
+ ])
4017
+ ])
4018
+ ])) : N("", !0),
4019
+ _e.value && de.value ? (m(), g("div", ki, [
4020
+ l("div", wi, [
4021
+ t[54] || (t[54] = l("span", { class: "vpe-fs-title" }, "连接管理", -1)),
4022
+ t[55] || (t[55] = l("span", {
4023
+ class: "vpe-spacer",
4024
+ "aria-hidden": "true"
4025
+ }, null, -1)),
4026
+ l("button", {
4027
+ class: "vpe-btn vpe-btn--sm",
4028
+ type: "button",
4029
+ title: "刷新连接列表",
4030
+ disabled: ze.value,
4031
+ onClick: fe
4032
+ }, " 刷新 ", 8, Si),
4033
+ l("button", {
4034
+ class: "vpe-btn vpe-btn--sm",
4035
+ type: "button",
4036
+ title: "关闭连接管理",
4037
+ "aria-label": "关闭连接管理",
4038
+ onClick: t[17] || (t[17] = (r) => _e.value = !1)
4039
+ }, [
4040
+ j(B(lt))
4041
+ ])
4042
+ ]),
4043
+ l("div", xi, [
4044
+ ze.value ? (m(), g("div", Ei, "正在读取连接…")) : (m(), g(D, { key: 1 }, [
4045
+ Ce.value.length ? N("", !0) : (m(), g("div", qi, " 暂无已保存连接,点击工具栏“新建连接”创建。 ")),
4046
+ (m(!0), g(D, null, le(Ce.value, (r) => (m(), g("div", {
4047
+ key: r.id,
4048
+ class: "vpe-sql-manager-item"
4049
+ }, [
4050
+ l("div", Ci, [
4051
+ l("span", {
4052
+ class: "vpe-sql-manager-name",
4053
+ title: r.name
4054
+ }, _(r.name), 9, Pi),
4055
+ l("span", Oi, [
4056
+ Qt(_(r.dialect), 1),
4057
+ r.database ? (m(), g(D, { key: 0 }, [
4058
+ Qt(" · " + _(r.database), 1)
4059
+ ], 64)) : N("", !0),
4060
+ r.host ? (m(), g(D, { key: 1 }, [
4061
+ Qt(" · " + _(r.host), 1)
4062
+ ], 64)) : N("", !0)
4063
+ ])
4064
+ ]),
4065
+ l("button", {
4066
+ class: "vpe-btn vpe-btn--sm",
4067
+ type: "button",
4068
+ title: "编辑连接",
4069
+ onClick: (u) => Dr(r)
4070
+ }, " 编辑 ", 8, Mi),
4071
+ l("button", {
4072
+ class: "vpe-btn vpe-btn--sm",
4073
+ type: "button",
4074
+ title: "删除连接",
4075
+ disabled: te.value,
4076
+ onClick: (u) => Vr(r)
4077
+ }, " 删除 ", 8, Ni)
4078
+ ]))), 128)),
4079
+ Pe.value ? (m(), g("p", Ti, _(Pe.value), 1)) : N("", !0),
4080
+ Ve.value ? (m(), g("p", {
4081
+ key: 2,
4082
+ class: ie(["vpe-sql-hint", ft.value ? "vpe-sql-hint--ok" : "vpe-sql-hint--error"])
4083
+ }, _(Ve.value), 3)) : N("", !0)
4084
+ ], 64))
4085
+ ])
4086
+ ])) : N("", !0)
1477
4087
  ], 6));
1478
4088
  }
1479
4089
  });
1480
- function pr(u = {}) {
1481
- var G;
1482
- const r = nt(u.pyodideUrl ? { pyodideUrl: u.pyodideUrl } : void 0), a = F(r.status), i = F(""), s = F([]);
1483
- let P = 0;
1484
- const w = (o, h) => {
1485
- s.value.push({ id: ++P, stream: o, text: h });
1486
- }, I = r.on("status", (o, h) => {
1487
- a.value = o, h && (i.value = h);
1488
- }), H = r.on("initError", (o) => {
1489
- w("system", `[pyodide] 加载失败:${o}`);
4090
+ function Ki(a = {}) {
4091
+ var Ae;
4092
+ const n = rn(a.pyodideUrl ? { pyodideUrl: a.pyodideUrl } : void 0), s = C(n.status), o = C(""), i = C([]);
4093
+ let p = 0;
4094
+ const b = (H, k) => {
4095
+ i.value.push({ id: ++p, stream: H, text: k });
4096
+ }, E = n.on("status", (H, k) => {
4097
+ s.value = H, k && (o.value = k);
4098
+ }), R = n.on("initError", (H) => {
4099
+ b("system", `[pyodide] 加载失败:${H}`);
1490
4100
  });
1491
- Bt(() => {
1492
- I(), H();
4101
+ $s(() => {
4102
+ E(), R();
1493
4103
  });
1494
- const C = async (o, h = {}) => {
1495
- var x;
4104
+ const P = async (H, k = {}) => {
4105
+ var I;
1496
4106
  try {
1497
- const O = await r.run(o, {
1498
- stdin: h.stdin,
1499
- onOutput: (U, X) => w(U, X)
4107
+ const Q = await n.run(H, {
4108
+ stdin: k.stdin,
4109
+ onOutput: (me, qe) => b(me, qe)
1500
4110
  });
1501
- return !O.ok && ((x = O.error) != null && x.traceback) && w("stderr", O.error.traceback), O;
1502
- } catch (O) {
4111
+ return !Q.ok && ((I = Q.error) != null && I.traceback) && b("stderr", Q.error.traceback), Q;
4112
+ } catch (Q) {
1503
4113
  return {
1504
4114
  ok: !1,
1505
4115
  durationMs: 0,
1506
- error: { type: "RuntimeError", message: O instanceof Error ? O.message : String(O), traceback: "" }
4116
+ error: { type: "RuntimeError", message: Q instanceof Error ? Q.message : String(Q), traceback: "" }
1507
4117
  };
1508
4118
  }
1509
- }, M = async (o, h) => {
4119
+ }, T = async (H, k) => {
1510
4120
  try {
1511
- return await r.writeFile(o, h);
1512
- } catch (x) {
1513
- return { ok: !1, error: { type: "RuntimeError", message: x instanceof Error ? x.message : String(x), traceback: "" } };
4121
+ return await n.writeFile(H, k);
4122
+ } catch (I) {
4123
+ return { ok: !1, error: { type: "RuntimeError", message: I instanceof Error ? I.message : String(I), traceback: "" } };
1514
4124
  }
1515
- }, T = async (o) => {
4125
+ }, x = async (H) => {
1516
4126
  try {
1517
- return await r.readFile(o);
1518
- } catch (h) {
1519
- return { ok: !1, error: { type: "RuntimeError", message: h instanceof Error ? h.message : String(h), traceback: "" } };
4127
+ return await n.readFile(H);
4128
+ } catch (k) {
4129
+ return { ok: !1, error: { type: "RuntimeError", message: k instanceof Error ? k.message : String(k), traceback: "" } };
1520
4130
  }
1521
- }, D = async (o = ".") => {
4131
+ }, F = async (H = ".") => {
1522
4132
  try {
1523
- return await r.listFiles(o);
1524
- } catch (h) {
1525
- return { ok: !1, error: { type: "RuntimeError", message: h instanceof Error ? h.message : String(h), traceback: "" } };
4133
+ return await n.listFiles(H);
4134
+ } catch (k) {
4135
+ return { ok: !1, error: { type: "RuntimeError", message: k instanceof Error ? k.message : String(k), traceback: "" } };
1526
4136
  }
1527
- }, N = async (o) => {
4137
+ }, q = async (H) => {
1528
4138
  try {
1529
- return await r.loadPackages(o, { onOutput: (h, x) => w(h, x) });
1530
- } catch (h) {
4139
+ return await n.loadPackages(H, { onOutput: (k, I) => b(k, I) });
4140
+ } catch (k) {
1531
4141
  return {
1532
4142
  ok: !1,
1533
4143
  durationMs: 0,
1534
- error: { type: "RuntimeError", message: h instanceof Error ? h.message : String(h), traceback: "" }
4144
+ error: { type: "RuntimeError", message: k instanceof Error ? k.message : String(k), traceback: "" }
1535
4145
  };
1536
4146
  }
1537
4147
  };
1538
- let j = !1;
1539
- const J = async () => {
1540
- var x;
1541
- if (j) return;
1542
- const o = u.preloadPackages ?? [];
1543
- if (!o.length) return;
1544
- j = !0, w("system", `[pyodide] 正在安装预置包:${o.join(", ")}`);
1545
- const h = await N(o);
1546
- w(
4148
+ let G = !1;
4149
+ const ve = async () => {
4150
+ var I;
4151
+ if (G) return;
4152
+ const H = a.preloadPackages ?? [];
4153
+ if (!H.length) return;
4154
+ G = !0, b("system", `[pyodide] 正在安装预置包:${H.join(", ")}`);
4155
+ const k = await q(H);
4156
+ b(
1547
4157
  "system",
1548
- h.ok ? `[pyodide] 预置包安装完成(${(h.durationMs / 1e3).toFixed(1)}s)` : `[pyodide] 预置包安装失败:${((x = h.error) == null ? void 0 : x.message) ?? "未知错误"}`
4158
+ k.ok ? `[pyodide] 预置包安装完成(${(k.durationMs / 1e3).toFixed(1)}s)` : `[pyodide] 预置包安装失败:${((I = k.error) == null ? void 0 : I.message) ?? "未知错误"}`
1549
4159
  );
1550
4160
  };
1551
- return (u.preload || (((G = u.preloadPackages) == null ? void 0 : G.length) ?? 0) > 0) && r.waitReady().then(() => J()).catch(() => {
4161
+ return (a.preload || (((Ae = a.preloadPackages) == null ? void 0 : Ae.length) ?? 0) > 0) && n.waitReady().then(() => ve()).catch(() => {
1552
4162
  }), {
1553
- status: a,
1554
- version: i,
1555
- outputs: s,
1556
- runPython: C,
1557
- install: N,
1558
- checkSyntax: (o) => r.checkSyntax(o),
1559
- interrupt: () => r.interrupt(),
4163
+ status: s,
4164
+ version: o,
4165
+ outputs: i,
4166
+ runPython: P,
4167
+ install: q,
4168
+ checkSyntax: (H) => n.checkSyntax(H),
4169
+ interrupt: () => n.interrupt(),
1560
4170
  clearOutputs: () => {
1561
- s.value = [];
4171
+ i.value = [];
1562
4172
  },
1563
- writeFile: M,
1564
- readFile: T,
1565
- listFiles: D,
4173
+ writeFile: T,
4174
+ readFile: x,
4175
+ listFiles: F,
1566
4176
  /** 预加载并在就绪后 resolve */
1567
- ready: () => r.waitReady()
4177
+ ready: () => n.waitReady()
1568
4178
  };
1569
4179
  }
1570
- const fr = Yn;
4180
+ const Ji = Li;
1571
4181
  export {
1572
- tt as DEFAULT_PYODIDE_URL,
1573
- cn as MONO_FONT_STACK,
1574
- kn as PyodideRunner,
1575
- fr as PythonEditor,
1576
- mn as createEditor,
1577
- Yn as default,
1578
- nt as getRunner,
1579
- yn as makePythonLinter,
1580
- et as setErrorLines,
1581
- pr as usePyodide
4182
+ fr as DEFAULT_PYODIDE_URL,
4183
+ Qi as DEFAULT_SQL_CONFIG,
4184
+ ar as EDITOR_THEMES,
4185
+ fa as MONO_FONT_STACK,
4186
+ Sa as PyodideRunner,
4187
+ Ji as PythonEditor,
4188
+ ut as SQL_DIALECT_OPTIONS,
4189
+ ya as createEditor,
4190
+ Ta as createPythonSession,
4191
+ Li as default,
4192
+ Oa as deleteServerFile,
4193
+ rr as deleteSqlConnection,
4194
+ nr as getDefaultSqlPort,
4195
+ rn as getRunner,
4196
+ Aa as getThemeOption,
4197
+ Wn as interruptPythonSession,
4198
+ or as isDarkTheme,
4199
+ qa as listServerFiles,
4200
+ Ba as listSqlConnections,
4201
+ ha as makePythonLinter,
4202
+ A as normalizeSqlConfig,
4203
+ La as pollPythonSession,
4204
+ Pa as readServerFile,
4205
+ Vi as runPythonOnServer,
4206
+ gr as runSql,
4207
+ Ca as saveServerFile,
4208
+ Ua as saveSqlConnection,
4209
+ $a as sendPythonSessionInput,
4210
+ pr as setErrorLines,
4211
+ Ha as testSqlConnection,
4212
+ Ki as usePyodide
1582
4213
  };