princess-python-editor 0.1.1 → 0.1.2

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,37 @@
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 ss = Object.defineProperty;
2
+ var as = (o, n, s) => n in o ? ss(o, n, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[n] = s;
3
+ var re = (o, n, s) => as(o, typeof n != "symbol" ? n + "" : n, s);
4
+ import { h as En, defineComponent as os, ref as q, reactive as xn, computed as H, onMounted as is, onBeforeUnmount as ls, watch as G, nextTick as Cn, resolveComponent as us, openBlock as f, createElementBlock as p, normalizeStyle as Pn, normalizeClass as se, createVNode as B, unref as N, createElementVNode as l, createCommentVNode as M, createBlock as Mn, withDirectives as Q, vModelText as ve, Fragment as A, toDisplayString as $, renderList as ae, vModelSelect as dt, withCtx as ds, withModifiers as On, withKeys as cs, createTextVNode as Lt, onScopeDispose as fs } from "vue";
5
+ import { EditorState as _t, StateEffect as ps, StateField as vs, Compartment as ct } from "@codemirror/state";
6
+ import { EditorView as Oe, keymap as Fn, lineNumbers as ms, highlightActiveLineGutter as ys, highlightActiveLine as hs, drawSelection as gs, placeholder as bs, Decoration as It } from "@codemirror/view";
7
+ import { oneDark as Nt } from "@codemirror/theme-one-dark";
8
+ import { linter as ks, forceLinting as ws } from "@codemirror/lint";
9
+ import { autocompletion as Ss, closeBrackets as qs, closeBracketsKeymap as Es } from "@codemirror/autocomplete";
10
+ import { history as xs, defaultKeymap as Cs, historyKeymap as Ps, indentWithTab as Ms } from "@codemirror/commands";
11
+ import { indentUnit as Os, syntaxHighlighting as Fs, defaultHighlightStyle as Ls, bracketMatching as Ts } from "@codemirror/language";
12
+ import { python as zn } from "@codemirror/lang-python";
13
+ import { javascript as $s } from "@codemirror/lang-javascript";
14
+ import { json as Rs } from "@codemirror/lang-json";
15
+ import { sql as _s } from "@codemirror/lang-sql";
16
+ const Is = "'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace", jn = ps.define();
17
+ function Ns(o, n) {
18
+ const s = o.filter((i) => Number.isFinite(i) && i >= 1 && i <= n.lines).sort((i, u) => i - u);
19
+ return It.set(
20
+ s.map((i) => It.line({ class: "vpe-error-line" }).range(n.line(i).from))
21
21
  );
22
22
  }
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;
23
+ const Hs = vs.define({
24
+ create: () => It.none,
25
+ update: (o, n) => {
26
+ let s = o;
27
+ for (const i of n.effects)
28
+ i.is(jn) && (s = Ns(i.value, n.state.doc));
29
+ return n.docChanged && (s = s.map(n.changes)), s;
30
30
  },
31
- provide: (u) => K.decorations.from(u)
32
- }), hn = K.theme({
31
+ provide: (o) => Oe.decorations.from(o)
32
+ }), Us = Oe.theme({
33
33
  "&": { height: "100%", fontSize: "13px" },
34
- ".cm-scroller": { fontFamily: cn, lineHeight: "1.65" },
34
+ ".cm-scroller": { fontFamily: Is, lineHeight: "1.65" },
35
35
  ".cm-content": { padding: "10px 0 14px" },
36
36
  ".cm-gutters": {
37
37
  borderRight: "none",
@@ -41,68 +41,69 @@ const fn = Kt.define({
41
41
  },
42
42
  "&.cm-focused": { outline: "none" }
43
43
  });
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([
44
+ function Bs(o, n) {
45
+ const s = Oe.updateListener.of((h) => {
46
+ h.docChanged && n.onDocChange(h.state.doc.toString());
47
+ }), i = Fn.of([
48
48
  {
49
49
  key: "Mod-Enter",
50
50
  preventDefault: !0,
51
- run: () => (r.onRunShortcut(), !0)
51
+ run: () => (n.onRunShortcut(), !0)
52
52
  }
53
- ]), s = Se.create({
54
- doc: r.value,
53
+ ]), u = _t.create({
54
+ doc: n.value,
55
55
  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,
56
+ Us,
57
+ ms(),
58
+ ys(),
59
+ hs(),
60
+ gs(),
61
+ xs(),
62
+ Os.of(" "),
63
+ n.language ?? zn(),
64
+ Fs(Ls, { fallback: !0 }),
65
+ Ss(),
66
+ qs(),
67
+ Ts(),
68
+ Oe.lineWrapping,
69
+ bs(n.placeholderText),
70
+ Hs,
70
71
  i,
71
- Je.of([...en, ...nn, ...rn, an]),
72
- ...r.dark ? [Fe] : [],
73
- ...r.extensions,
74
- a
72
+ Fn.of([...Es, ...Cs, ...Ps, Ms]),
73
+ ...n.dark ? [Nt] : [],
74
+ ...n.extensions,
75
+ s
75
76
  ]
76
77
  });
77
- return new K({ state: s, parent: u });
78
+ return new Oe({ state: u, parent: o });
78
79
  }
79
- function yn(u, r = 600) {
80
- return Gt(
81
- async (a) => {
82
- const i = a.state.doc.toString();
80
+ function As(o, n = 600) {
81
+ return ks(
82
+ async (s) => {
83
+ const i = s.state.doc.toString();
83
84
  if (!i.trim()) return [];
84
- let s = null;
85
+ let u = null;
85
86
  try {
86
- s = await u.checkSyntax(i);
87
+ u = await o.checkSyntax(i);
87
88
  } catch {
88
89
  return [];
89
90
  }
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);
91
+ if (!u) return [];
92
+ const h = Math.min(Math.max(Math.round(u.line) || 1, 1), s.state.doc.lines), w = s.state.doc.line(h), C = Math.min(Math.max(Math.round(u.column) || 1, 1), w.length + 1), _ = w.from + C - 1, O = Math.min(_ + 1, w.to);
92
93
  return [
93
94
  {
94
- from: H,
95
- to: C,
95
+ from: _,
96
+ to: O,
96
97
  severity: "error",
97
- message: s.message,
98
+ message: u.message,
98
99
  source: "python-syntax"
99
100
  }
100
101
  ];
101
102
  },
102
- { delay: r }
103
+ { delay: n }
103
104
  );
104
105
  }
105
- const gn = [
106
+ const Ds = [
106
107
  "import ast, json",
107
108
  "def _pye_check(src):",
108
109
  " try:",
@@ -110,15 +111,94 @@ const gn = [
110
111
  " return json.dumps({'ok': True})",
111
112
  " except SyntaxError as e:",
112
113
  " return json.dumps({'ok': False, 'line': int(e.lineno or 1), 'column': int(e.offset or 1), 'message': str(e.msg or 'invalid syntax')})"
114
+ ], zs = [
115
+ "import json",
116
+ "import sqlite3",
117
+ "",
118
+ "_pye_conns = {}",
119
+ "",
120
+ "def _pye_value(value):",
121
+ " if value is None or isinstance(value, (bool, int, float, str)):",
122
+ " return value",
123
+ " if isinstance(value, (bytes, bytearray, memoryview)):",
124
+ " return bytes(value).hex()",
125
+ " return str(value)",
126
+ "",
127
+ "def _pye_meaningful(stmt):",
128
+ " text = stmt.strip()",
129
+ " if not text:",
130
+ " return False",
131
+ ' text = text.replace(";", " ").strip()',
132
+ " if not text:",
133
+ " return False",
134
+ " for line in text.splitlines():",
135
+ " line = line.strip()",
136
+ ' if line and not line.startswith("--"):',
137
+ " return True",
138
+ " return False",
139
+ "",
140
+ "def _pye_exec_one(conn, stmt, max_rows):",
141
+ " cur = conn.cursor()",
142
+ " try:",
143
+ " cur.execute(stmt)",
144
+ " if cur.description:",
145
+ " columns = [str(item[0]) for item in cur.description]",
146
+ " rows = []",
147
+ " truncated = False",
148
+ " for row in cur:",
149
+ " if len(rows) >= max_rows:",
150
+ " truncated = True",
151
+ " break",
152
+ " rows.append([_pye_value(value) for value in row])",
153
+ ' return {"columns": columns, "rows": rows, "affectedRows": 0, "truncated": truncated}',
154
+ " affected = cur.rowcount",
155
+ " if affected is None or affected < 0:",
156
+ " affected = 0",
157
+ ' return {"columns": [], "rows": [], "affectedRows": affected, "truncated": False}',
158
+ " finally:",
159
+ " cur.close()",
160
+ "",
161
+ "def _pye_split(sql):",
162
+ " statements = []",
163
+ ' buf = ""',
164
+ " for ch in sql:",
165
+ " buf += ch",
166
+ ' if ch == ";" and sqlite3.complete_statement(buf):',
167
+ " statements.append(buf)",
168
+ ' buf = ""',
169
+ " if buf.strip():",
170
+ " statements.append(buf)",
171
+ " return statements",
172
+ "",
173
+ "def _pye_sql(database, sql, max_rows):",
174
+ ' database = database or ":memory:"',
175
+ " if max_rows < 1:",
176
+ " max_rows = 200",
177
+ " conn = _pye_conns.get(database)",
178
+ " if conn is None:",
179
+ " conn = sqlite3.connect(database, isolation_level=None)",
180
+ " _pye_conns[database] = conn",
181
+ " results = []",
182
+ " try:",
183
+ " for stmt in _pye_split(sql):",
184
+ " if _pye_meaningful(stmt):",
185
+ " results.append(_pye_exec_one(conn, stmt, max_rows))",
186
+ " except Exception as exc:",
187
+ ' error = {"type": type(exc).__name__, "message": str(exc)}',
188
+ ' return json.dumps({"ok": False, "results": results, "error": error})',
189
+ ' return json.dumps({"ok": True, "results": results})'
113
190
  ];
114
- function vn(u) {
115
- const r = u.endsWith("/") ? u : u + "/";
191
+ function js(o) {
192
+ const n = o.endsWith("/") ? o : o + "/";
116
193
  return `
117
- var INDEX_URL = ${JSON.stringify(r)};
118
- var CHECK_SOURCE = ${JSON.stringify(gn.join(`
194
+ var INDEX_URL = ${JSON.stringify(n)};
195
+ var CHECK_SOURCE = ${JSON.stringify(Ds.join(`
196
+ `))};
197
+ var SQL_SOURCE = ${JSON.stringify(zs.join(`
119
198
  `))};
120
199
  var pyodide = null;
121
200
  var checkFn = null;
201
+ var sqlFn = null;
122
202
  var currentId = 0;
123
203
 
124
204
  function post(msg) { self.postMessage(msg); }
@@ -292,6 +372,37 @@ self.onmessage = async function (ev) {
292
372
  }
293
373
  currentId = 0;
294
374
 
375
+ } else if (msg.kind === 'sql-run') {
376
+ currentId = msg.id;
377
+ if (!pyodide) {
378
+ currentId = 0;
379
+ post({ kind: 'sql-ran', id: msg.id, ok: false, results: [], error: { type: 'RuntimeError', message: 'Pyodide 未初始化' } });
380
+ return;
381
+ }
382
+ try {
383
+ if (!sqlFn) {
384
+ await pyodide.loadPackage('sqlite3');
385
+ pyodide.runPython(SQL_SOURCE);
386
+ sqlFn = pyodide.globals.get('_pye_sql');
387
+ }
388
+ var sqlJson = sqlFn(
389
+ String(msg.database || ':memory:'),
390
+ String(msg.sql || ''),
391
+ Number(msg.maxRows) || 200
392
+ );
393
+ var sqlParsed = JSON.parse(sqlJson);
394
+ post({
395
+ kind: 'sql-ran',
396
+ id: msg.id,
397
+ ok: !!sqlParsed.ok,
398
+ results: sqlParsed.results || [],
399
+ error: sqlParsed.error
400
+ });
401
+ } catch (e) {
402
+ post({ kind: 'sql-ran', id: msg.id, ok: false, results: [], error: parseError(e) });
403
+ }
404
+ currentId = 0;
405
+
295
406
  } else if (msg.kind === 'fs-write') {
296
407
  if (!pyodide) {
297
408
  post({ kind: 'fs-written', id: msg.id, ok: false, error: { type: 'RuntimeError', message: 'Pyodide 未初始化', traceback: '' } });
@@ -341,118 +452,141 @@ self.onmessage = async function (ev) {
341
452
  };
342
453
  `;
343
454
  }
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());
455
+ const Vn = "https://cdn.jsdelivr.net/pyodide/v0.27.2/full/";
456
+ class Vs {
457
+ constructor(n = {}) {
458
+ re(this, "status", "idle");
459
+ re(this, "version", "");
460
+ re(this, "pyodideUrl");
461
+ re(this, "worker", null);
462
+ re(this, "pending", /* @__PURE__ */ new Map());
463
+ re(this, "seq", 1);
464
+ re(this, "chain", Promise.resolve());
354
465
  /** 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;
466
+ re(this, "generation", 0);
467
+ re(this, "statusHandlers", /* @__PURE__ */ new Set());
468
+ re(this, "outputHandlers", /* @__PURE__ */ new Set());
469
+ re(this, "initErrorHandlers", /* @__PURE__ */ new Set());
470
+ this.pyodideUrl = n.pyodideUrl || Vn;
360
471
  }
361
- on(r, a) {
362
- if (r === "status") {
363
- const s = a;
364
- return this.statusHandlers.add(s), () => this.statusHandlers.delete(s);
472
+ on(n, s) {
473
+ if (n === "status") {
474
+ const u = s;
475
+ return this.statusHandlers.add(u), () => this.statusHandlers.delete(u);
365
476
  }
366
- if (r === "output") {
367
- const s = a;
368
- return this.outputHandlers.add(s), () => this.outputHandlers.delete(s);
477
+ if (n === "output") {
478
+ const u = s;
479
+ return this.outputHandlers.add(u), () => this.outputHandlers.delete(u);
369
480
  }
370
- const i = a;
481
+ const i = s;
371
482
  return this.initErrorHandlers.add(i), () => this.initErrorHandlers.delete(i);
372
483
  }
373
484
  /** 预加载 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 = () => {
485
+ waitReady(n = 18e4) {
486
+ const s = this.generation;
487
+ return this.ensureWorker(), this.status === "ready" || this.status === "running" ? Promise.resolve() : new Promise((i, u) => {
488
+ let h = () => {
378
489
  }, w = () => {
379
490
  };
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("执行已被中断"));
491
+ const C = () => {
492
+ clearTimeout(_), h(), w();
493
+ }, _ = setTimeout(() => {
494
+ C(), u(new Error("Pyodide 加载超时"));
495
+ }, n);
496
+ h = this.on("status", (O) => {
497
+ if (this.generation !== s) {
498
+ C(), u(new Error("执行已被中断"));
388
499
  return;
389
500
  }
390
- C === "ready" && (I(), i());
391
- }), w = this.on("initError", (C) => {
392
- I(), s(new Error(C));
501
+ O === "ready" && (C(), i());
502
+ }), w = this.on("initError", (O) => {
503
+ C(), u(new Error(O));
393
504
  });
394
505
  });
395
506
  }
396
507
  /** 执行一段 Python 代码(支持顶层 await);运行器未就绪时先等待初始化完成 */
397
- async run(r, a) {
508
+ async run(n, s) {
398
509
  await this.waitReady();
399
510
  const i = performance.now();
400
511
  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
512
+ const u = await this.send(
513
+ { kind: "run", id: this.seq++, code: n, stdin: s == null ? void 0 : s.stdin },
514
+ s == null ? void 0 : s.onOutput
404
515
  );
405
516
  return this.status === "running" && this.setStatus("ready"), {
406
- ok: s.ok,
407
- value: s.value,
408
- error: s.error,
409
- interrupted: s.interrupted,
517
+ ok: u.ok,
518
+ value: u.value,
519
+ error: u.error,
520
+ interrupted: u.interrupted,
410
521
  durationMs: performance.now() - i
411
522
  };
412
523
  }
413
524
  /** 语法检查:仅在运行器就绪时可用,否则返回 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 ?? "语法错误"
525
+ async checkSyntax(n) {
526
+ if (this.status !== "ready" || !n.trim()) return null;
527
+ const s = await this.send({ kind: "check", id: this.seq++, code: n });
528
+ return s.ok ? null : {
529
+ line: s.line ?? 1,
530
+ column: s.column ?? 1,
531
+ message: s.message ?? "语法错误"
421
532
  };
422
533
  }
423
534
  /** 写入虚拟文件系统(UTF-8 文本),相对路径基于当前工作目录 */
424
- async writeFile(r, a) {
535
+ async writeFile(n, s) {
425
536
  await this.waitReady();
426
- const i = await this.send({ kind: "fs-write", id: this.seq++, path: r, content: a });
537
+ const i = await this.send({ kind: "fs-write", id: this.seq++, path: n, content: s });
427
538
  return { ok: i.ok, path: i.path, error: i.error };
428
539
  }
429
540
  /** 读取虚拟文件系统中的文本文件;二进制内容会返回失败 */
430
- async readFile(r) {
541
+ async readFile(n) {
431
542
  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 };
543
+ const s = await this.send({ kind: "fs-read", id: this.seq++, path: n });
544
+ return { ok: s.ok, path: s.path, content: s.content, error: s.error };
434
545
  }
435
546
  /** 列出虚拟文件系统目录(递归,跳过 __pycache__ / .cache) */
436
- async listFiles(r = ".") {
547
+ async listFiles(n = ".") {
437
548
  await this.waitReady();
438
- const a = await this.send({
549
+ const s = await this.send({
439
550
  kind: "fs-list",
440
551
  id: this.seq++,
441
- path: r,
552
+ path: n,
442
553
  recursive: !0
443
554
  });
444
- return { ok: a.ok, path: a.path, entries: a.entries, error: a.error };
555
+ return { ok: s.ok, path: s.path, entries: s.entries, error: s.error };
556
+ }
557
+ /** 在浏览器内的 SQLite 中执行 SQL(首次调用时自动加载 sqlite3 包) */
558
+ async executeSql(n) {
559
+ await this.waitReady();
560
+ const s = performance.now();
561
+ this.setStatus("running");
562
+ try {
563
+ const i = await this.send({
564
+ kind: "sql-run",
565
+ id: this.seq++,
566
+ database: n.database,
567
+ sql: n.sql,
568
+ maxRows: n.maxRows
569
+ });
570
+ return {
571
+ ok: i.ok,
572
+ results: i.results ?? [],
573
+ error: i.sqlError ?? (i.interrupted ? { type: "AbortError", message: "SQL 执行已中断" } : void 0),
574
+ durationMs: performance.now() - s
575
+ };
576
+ } finally {
577
+ this.status === "running" && this.setStatus("ready");
578
+ }
445
579
  }
446
580
  /** 安装第三方包:先尝试内置 wheel(loadPackage),失败后回退 micropip */
447
- async loadPackages(r, a) {
581
+ async loadPackages(n, s) {
448
582
  await this.waitReady();
449
583
  const i = performance.now();
450
584
  this.setStatus("running");
451
- const s = await this.send(
452
- { kind: "install", id: this.seq++, packages: r },
453
- a == null ? void 0 : a.onOutput
585
+ const u = await this.send(
586
+ { kind: "install", id: this.seq++, packages: n },
587
+ s == null ? void 0 : s.onOutput
454
588
  );
455
- return this.status === "running" && this.setStatus("ready"), { ok: s.ok, error: s.error, durationMs: performance.now() - i };
589
+ return this.status === "running" && this.setStatus("ready"), { ok: u.ok, error: u.error, durationMs: performance.now() - i };
456
590
  }
457
591
  /**
458
592
  * 中断当前执行:terminate Worker(Pyodide 无法真正中断同步计算),
@@ -461,127 +595,666 @@ class kn {
461
595
  interrupt() {
462
596
  if (!this.worker) return;
463
597
  this.generation += 1, this.worker.terminate(), this.worker = null;
464
- const r = {
598
+ const n = {
465
599
  ok: !1,
466
600
  interrupted: !0,
467
601
  error: { type: "KeyboardInterrupt", message: "执行已被用户中断", traceback: "" }
468
602
  };
469
- this.pending.forEach((a) => a.resolve(r)), this.pending.clear(), this.chain = Promise.resolve(), this.setStatus("idle");
603
+ this.pending.forEach((s) => s.resolve(n)), this.pending.clear(), this.chain = Promise.resolve(), this.setStatus("idle");
470
604
  }
471
605
  ensureWorker() {
472
606
  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;
607
+ const n = new Blob([js(this.pyodideUrl)], { type: "text/javascript" }), s = new Worker(URL.createObjectURL(n));
608
+ return s.onmessage = (i) => this.handleMessage(i.data), this.worker = s, this.setStatus("loading"), s;
475
609
  }
476
- handleMessage(r) {
477
- switch (r.kind) {
610
+ handleMessage(n) {
611
+ switch (n.kind) {
478
612
  case "ready":
479
- this.version = r.version, this.setStatus("ready");
613
+ this.version = n.version, this.setStatus("ready");
480
614
  break;
481
615
  case "init-error":
482
- this.setStatus("idle"), this.initErrorHandlers.forEach((a) => a(r.message));
616
+ this.setStatus("idle"), this.initErrorHandlers.forEach((s) => s(n.message));
483
617
  break;
484
618
  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));
619
+ const s = n.runId ? this.pending.get(n.runId) : void 0;
620
+ s != null && s.onOutput ? s.onOutput(n.stream, n.text) : this.outputHandlers.forEach((i) => i(n.stream, n.text));
487
621
  break;
488
622
  }
489
623
  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 }));
624
+ const s = this.pending.get(n.id);
625
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, value: n.value, error: n.error }));
492
626
  break;
493
627
  }
494
628
  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
629
+ const s = this.pending.get(n.id);
630
+ s && (this.pending.delete(n.id), s.resolve({
631
+ ok: n.ok,
632
+ line: n.line,
633
+ column: n.column,
634
+ message: n.message
501
635
  }));
502
636
  break;
503
637
  }
504
638
  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 }));
639
+ const s = this.pending.get(n.id);
640
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, error: n.error }));
507
641
  break;
508
642
  }
509
643
  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 }));
644
+ const s = this.pending.get(n.id);
645
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, path: n.path, error: n.error }));
512
646
  break;
513
647
  }
514
648
  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
649
+ const s = this.pending.get(n.id);
650
+ s && (this.pending.delete(n.id), s.resolve({
651
+ ok: n.ok,
652
+ path: n.path,
653
+ content: n.content,
654
+ error: n.error
521
655
  }));
522
656
  break;
523
657
  }
524
658
  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
659
+ const s = this.pending.get(n.id);
660
+ s && (this.pending.delete(n.id), s.resolve({
661
+ ok: n.ok,
662
+ path: n.path,
663
+ entries: n.entries,
664
+ error: n.error
531
665
  }));
532
666
  break;
533
667
  }
668
+ case "sql-ran": {
669
+ const s = this.pending.get(n.id);
670
+ s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, results: n.results, sqlError: n.error }));
671
+ break;
672
+ }
534
673
  }
535
674
  }
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);
675
+ send(n, s) {
676
+ const i = this.ensureWorker(), u = this.chain.then(
677
+ () => new Promise((h) => {
678
+ this.pending.set(n.id, { resolve: h, onOutput: s }), i.postMessage(n);
540
679
  })
541
680
  );
542
- return this.chain = s.then(
681
+ return this.chain = u.then(
543
682
  () => {
544
683
  },
545
684
  () => {
546
685
  }
547
- ), s;
686
+ ), u;
548
687
  }
549
- setStatus(r) {
550
- this.status !== r && (this.status = r, this.statusHandlers.forEach((a) => a(r, this.version)));
688
+ setStatus(n) {
689
+ this.status !== n && (this.status = n, this.statusHandlers.forEach((s) => s(n, this.version)));
551
690
  }
552
691
  }
553
- let be = null;
554
- function nt(u) {
555
- return be ? u != null && u.pyodideUrl && u.pyodideUrl !== tt && console.warn(
692
+ let Tt = null;
693
+ function Ut(o) {
694
+ return Tt ? o != null && o.pyodideUrl && o.pyodideUrl !== Vn && console.warn(
556
695
  "[princess-python-editor] Pyodide 运行器已初始化,后续传入的 pyodideUrl 将被忽略。"
557
- ) : be = new kn(u), be;
696
+ ) : Tt = new Vs(o), Tt;
697
+ }
698
+ const Qs = 3e4;
699
+ function Js(o) {
700
+ const n = (o ?? "").trim().replace(/\/+$/, "");
701
+ if (!n)
702
+ throw new Error("未配置文件服务端点(filesEndpoint)");
703
+ return n;
704
+ }
705
+ async function mt(o, n, s, i = {}) {
706
+ var _, O;
707
+ const u = Js(o), h = new AbortController(), w = setTimeout(() => h.abort(), i.timeoutMs ?? Qs), C = () => h.abort();
708
+ i.signal && (i.signal.aborted ? h.abort() : i.signal.addEventListener("abort", C));
709
+ try {
710
+ const F = await fetch(u + n, {
711
+ ...s,
712
+ headers: {
713
+ "Content-Type": "application/json",
714
+ ...i.headers ?? {},
715
+ ...s.headers ?? {}
716
+ },
717
+ signal: h.signal
718
+ }), k = await F.text();
719
+ let T = null;
720
+ if (k)
721
+ try {
722
+ T = JSON.parse(k);
723
+ } catch {
724
+ throw new Error(`文件服务返回的不是合法 JSON(HTTP ${F.status})`);
725
+ }
726
+ if (!F.ok || !T || T.ok === !1)
727
+ throw new Error(((_ = T == null ? void 0 : T.error) == null ? void 0 : _.message) ?? `文件服务返回 HTTP ${F.status}`);
728
+ return T.data;
729
+ } finally {
730
+ clearTimeout(w), (O = i.signal) == null || O.removeEventListener("abort", C);
731
+ }
732
+ }
733
+ function Ks(o, n = {}) {
734
+ return mt(o, "", { method: "GET" }, n);
735
+ }
736
+ function Zs(o, n, s = {}) {
737
+ return mt(
738
+ o,
739
+ "",
740
+ { method: "POST", body: JSON.stringify(n) },
741
+ s
742
+ );
743
+ }
744
+ function Ws(o, n, s = {}) {
745
+ return mt(
746
+ o,
747
+ `/${encodeURIComponent(n)}`,
748
+ { method: "GET" },
749
+ s
750
+ );
751
+ }
752
+ async function Gs(o, n, s = {}) {
753
+ await mt(o, `/${encodeURIComponent(n)}`, { method: "DELETE" }, s);
754
+ }
755
+ const Ys = 6e4;
756
+ function Bt(o) {
757
+ const n = (o ?? "").trim().replace(/\/+$/, "");
758
+ if (!n)
759
+ throw new Error("未配置 Python 服务端点(pythonEndpoint)");
760
+ return n;
761
+ }
762
+ function Qn(o, n) {
763
+ if (o && typeof o == "object") {
764
+ const s = o, i = Number(s.line);
765
+ return {
766
+ type: typeof s.type == "string" && s.type ? s.type : "PythonError",
767
+ message: typeof s.message == "string" && s.message ? s.message : n,
768
+ line: Number.isFinite(i) && i > 0 ? Math.trunc(i) : void 0,
769
+ traceback: typeof s.traceback == "string" && s.traceback ? s.traceback : void 0
770
+ };
771
+ }
772
+ return { type: "PythonError", message: n };
773
+ }
774
+ async function pi(o, n, s = {}) {
775
+ var _;
776
+ const i = Bt(o), u = performance.now(), h = new AbortController(), w = setTimeout(() => h.abort(), s.timeoutMs ?? Ys), C = () => h.abort();
777
+ s.signal && (s.signal.aborted ? h.abort() : s.signal.addEventListener("abort", C));
778
+ try {
779
+ const O = await fetch(`${i}/run`, {
780
+ method: "POST",
781
+ headers: {
782
+ "Content-Type": "application/json",
783
+ ...s.headers ?? {}
784
+ },
785
+ body: JSON.stringify({ code: n, stdin: s.stdin ?? "" }),
786
+ signal: h.signal
787
+ }), F = await O.text();
788
+ let k = null;
789
+ if (F)
790
+ try {
791
+ k = JSON.parse(F);
792
+ } catch {
793
+ throw new Error(`Python 服务返回的不是合法 JSON(HTTP ${O.status})`);
794
+ }
795
+ const T = performance.now() - u;
796
+ if (!O.ok) {
797
+ const x = k == null ? void 0 : k.error, z = typeof (x == null ? void 0 : x.message) == "string" && x.message ? x.message : `Python 服务返回 HTTP ${O.status}`;
798
+ return {
799
+ ok: !1,
800
+ stdout: "",
801
+ stderr: "",
802
+ durationMs: T,
803
+ error: {
804
+ type: typeof (x == null ? void 0 : x.type) == "string" && x.type ? x.type : `Http${O.status}`,
805
+ message: z
806
+ }
807
+ };
808
+ }
809
+ if (!k)
810
+ return {
811
+ ok: !1,
812
+ stdout: "",
813
+ stderr: "",
814
+ durationMs: T,
815
+ error: { type: "BadResponse", message: "Python 服务返回内容为空" }
816
+ };
817
+ const S = k.ok === !0, K = Number(k.durationMs), de = Number(k.exitCode);
818
+ return {
819
+ ok: S,
820
+ stdout: typeof k.stdout == "string" ? k.stdout : "",
821
+ stderr: typeof k.stderr == "string" ? k.stderr : "",
822
+ exitCode: Number.isFinite(de) ? Math.trunc(de) : void 0,
823
+ durationMs: Number.isFinite(K) && K >= 0 ? K : T,
824
+ error: S ? void 0 : Qn(k.error, "服务端 Python 执行失败")
825
+ };
826
+ } finally {
827
+ clearTimeout(w), (_ = s.signal) == null || _.removeEventListener("abort", C);
828
+ }
829
+ }
830
+ function Xs(o) {
831
+ return o === "waiting" || o === "running" || o === "exited" ? o : "exited";
832
+ }
833
+ async function At(o, n, s, i, u) {
834
+ var F;
835
+ const h = Bt(o), w = performance.now(), C = new AbortController(), _ = setTimeout(() => C.abort(), i.timeoutMs ?? u), O = () => C.abort();
836
+ i.signal && (i.signal.aborted ? C.abort() : i.signal.addEventListener("abort", O));
837
+ try {
838
+ const k = await fetch(h + n, {
839
+ ...s,
840
+ headers: {
841
+ "Content-Type": "application/json",
842
+ ...i.headers ?? {}
843
+ },
844
+ signal: C.signal
845
+ }), T = await k.text();
846
+ let S = null;
847
+ if (T)
848
+ try {
849
+ S = JSON.parse(T);
850
+ } catch {
851
+ throw new Error(`Python 服务返回的不是合法 JSON(HTTP ${k.status})`);
852
+ }
853
+ const K = performance.now() - w;
854
+ if (!k.ok || !S) {
855
+ const z = S == null ? void 0 : S.error, Fe = typeof (z == null ? void 0 : z.message) == "string" && z.message ? z.message : `Python 服务返回 HTTP ${k.status}`;
856
+ return {
857
+ sessionId: typeof (S == null ? void 0 : S.sessionId) == "string" ? S.sessionId : "",
858
+ state: "exited",
859
+ stdout: "",
860
+ stderr: "",
861
+ durationMs: K,
862
+ error: {
863
+ type: typeof (z == null ? void 0 : z.type) == "string" && z.type ? z.type : `Http${k.status}`,
864
+ message: Fe
865
+ }
866
+ };
867
+ }
868
+ const de = Number(S.exitCode), x = Number(S.durationMs);
869
+ return {
870
+ sessionId: typeof S.sessionId == "string" ? S.sessionId : "",
871
+ state: Xs(S.state),
872
+ stdout: typeof S.stdout == "string" ? S.stdout : "",
873
+ stderr: typeof S.stderr == "string" ? S.stderr : "",
874
+ exitCode: Number.isFinite(de) ? Math.trunc(de) : void 0,
875
+ durationMs: Number.isFinite(x) ? x : K,
876
+ error: S.error ? Qn(S.error, "服务端 Python 执行失败") : void 0
877
+ };
878
+ } finally {
879
+ clearTimeout(_), (F = i.signal) == null || F.removeEventListener("abort", O);
880
+ }
881
+ }
882
+ function ea(o, n, s = {}) {
883
+ return At(
884
+ o,
885
+ "/sessions",
886
+ {
887
+ method: "POST",
888
+ body: JSON.stringify({
889
+ code: n,
890
+ stdin: s.stdin ?? "",
891
+ timeoutSeconds: s.timeoutSeconds
892
+ })
893
+ },
894
+ s,
895
+ 2e4
896
+ );
897
+ }
898
+ function ta(o, n, s = {}) {
899
+ return At(
900
+ o,
901
+ `/sessions/${encodeURIComponent(n)}`,
902
+ { method: "GET" },
903
+ s,
904
+ 5e3
905
+ );
906
+ }
907
+ function na(o, n, s, i = {}) {
908
+ return At(
909
+ o,
910
+ `/sessions/${encodeURIComponent(n)}/input`,
911
+ { method: "POST", body: JSON.stringify({ text: s }) },
912
+ i,
913
+ 2e4
914
+ );
915
+ }
916
+ async function Ln(o, n, s = {}) {
917
+ const i = Bt(o);
918
+ try {
919
+ await fetch(`${i}/sessions/${encodeURIComponent(n)}/interrupt`, {
920
+ method: "POST",
921
+ headers: { ...s.headers ?? {} },
922
+ signal: s.signal
923
+ });
924
+ } catch {
925
+ }
926
+ }
927
+ const Ye = [
928
+ { value: "sqlite", label: "SQLite" },
929
+ { value: "mysql", label: "MySQL", defaultPort: 3306 },
930
+ { value: "postgresql", label: "PostgreSQL", defaultPort: 5432 },
931
+ { value: "sqlserver", label: "SQL Server", defaultPort: 1433 },
932
+ { value: "oracle", label: "Oracle", defaultPort: 1521 },
933
+ { value: "clickhouse", label: "ClickHouse", defaultPort: 8123 },
934
+ { value: "other", label: "其他" }
935
+ ], vi = {
936
+ mode: "sqlite",
937
+ connection: { dialect: "sqlite", database: ":memory:" },
938
+ maxRows: 200,
939
+ timeoutMs: 3e4
940
+ }, Jn = 200, pt = 3e4;
941
+ function ra(o) {
942
+ return Ye.some((n) => n.value === o);
943
+ }
944
+ function Tn(o, n, s, i) {
945
+ const u = typeof o == "number" ? o : Number(o);
946
+ return Number.isFinite(u) ? Math.min(Math.max(Math.trunc(u), s), i) : n;
947
+ }
948
+ function sa(o) {
949
+ if (o == null || o === "") return;
950
+ const n = Number(o);
951
+ if (!(!Number.isFinite(n) || n <= 0))
952
+ return Math.min(Math.trunc(n), 65535);
953
+ }
954
+ function U(o = {}) {
955
+ var h, w, C, _, O, F, k;
956
+ const n = o.mode === "http" ? "http" : "sqlite", s = (h = o.connection) == null ? void 0 : h.dialect, i = ra(s) ? s : n === "http" ? "mysql" : "sqlite", u = (w = o.connection) == null ? void 0 : w.database;
957
+ return {
958
+ mode: n,
959
+ connectionId: o.connectionId === void 0 || o.connectionId === null ? void 0 : o.connectionId.trim() || void 0,
960
+ connection: {
961
+ dialect: i,
962
+ host: ((C = o.connection) == null ? void 0 : C.host) ?? "",
963
+ port: sa((_ = o.connection) == null ? void 0 : _.port),
964
+ user: ((O = o.connection) == null ? void 0 : O.user) ?? "",
965
+ password: ((F = o.connection) == null ? void 0 : F.password) ?? "",
966
+ database: u ?? (n === "sqlite" ? ":memory:" : ""),
967
+ options: (k = o.connection) != null && k.options ? { ...o.connection.options } : void 0
968
+ },
969
+ endpoint: o.endpoint ?? "",
970
+ headers: o.headers ? { ...o.headers } : void 0,
971
+ maxRows: Tn(o.maxRows, Jn, 1, 1e5),
972
+ timeoutMs: Tn(o.timeoutMs, pt, 1e3, 6e5)
973
+ };
974
+ }
975
+ function $n(o) {
976
+ if (o == null) return null;
977
+ const n = typeof o;
978
+ if (n === "string" || n === "number" || n === "boolean")
979
+ return o;
980
+ try {
981
+ return JSON.stringify(o);
982
+ } catch {
983
+ return String(o);
984
+ }
985
+ }
986
+ function Ht(o) {
987
+ const n = o ?? {}, s = Array.isArray(n.columns) ? n.columns.map((u) => String(u)) : [], i = Array.isArray(n.rows) ? n.rows.map((u) => Array.isArray(u) ? u.map($n) : [$n(u)]) : [];
988
+ return {
989
+ columns: s,
990
+ rows: i,
991
+ affectedRows: n.affectedRows === void 0 || n.affectedRows === null ? void 0 : Number(n.affectedRows) || 0,
992
+ truncated: !!n.truncated
993
+ };
994
+ }
995
+ function Dt(o, n) {
996
+ if (o && typeof o == "object") {
997
+ const s = o;
998
+ return {
999
+ type: typeof s.type == "string" && s.type ? s.type : "SqlError",
1000
+ message: typeof s.message == "string" && s.message ? s.message : typeof o == "string" ? o : n,
1001
+ code: typeof s.code == "string" || typeof s.code == "number" ? s.code : void 0
1002
+ };
1003
+ }
1004
+ return { type: "SqlError", message: typeof o == "string" && o ? o : n };
1005
+ }
1006
+ function aa(o) {
1007
+ return o instanceof DOMException && o.name === "AbortError" || o instanceof Error && o.name === "AbortError";
558
1008
  }
559
- const fe = [
1009
+ function Rn(o, n) {
1010
+ if (!o || typeof o != "object")
1011
+ return {
1012
+ ok: !1,
1013
+ results: [],
1014
+ error: { type: "BadResponse", message: "SQL 服务返回内容为空或格式不正确" },
1015
+ durationMs: n
1016
+ };
1017
+ const s = o, i = s.ok !== !1, u = Number(s.durationMs), h = Number.isFinite(u) && u >= 0 ? u : n;
1018
+ if (!i)
1019
+ return {
1020
+ ok: !1,
1021
+ results: [],
1022
+ error: Dt(s.error, "SQL 服务返回执行失败"),
1023
+ durationMs: h
1024
+ };
1025
+ let w = [];
1026
+ return Array.isArray(s.results) ? w = s.results : (Array.isArray(s.columns) || Array.isArray(s.rows)) && (w = [s]), {
1027
+ ok: !0,
1028
+ results: w.map(Ht),
1029
+ durationMs: h
1030
+ };
1031
+ }
1032
+ async function oa(o, n, s, i) {
1033
+ const u = (o.endpoint ?? "").trim();
1034
+ if (!u)
1035
+ return {
1036
+ ok: !1,
1037
+ results: [],
1038
+ error: {
1039
+ type: "NoEndpoint",
1040
+ message: "未配置 SQL 服务端点(endpoint),请在后端网关地址中填写完整 URL"
1041
+ },
1042
+ durationMs: 0
1043
+ };
1044
+ const h = performance.now(), w = new AbortController();
1045
+ let C = !1;
1046
+ const _ = setTimeout(() => {
1047
+ C = !0, w.abort();
1048
+ }, o.timeoutMs ?? pt), O = () => w.abort();
1049
+ i && (i.aborted ? w.abort() : i.addEventListener("abort", O));
1050
+ try {
1051
+ const F = await fetch(u, {
1052
+ method: "POST",
1053
+ headers: { "Content-Type": "application/json", ...o.headers ?? {} },
1054
+ body: JSON.stringify({
1055
+ connection: o.connection,
1056
+ connectionId: o.connectionId,
1057
+ sql: n,
1058
+ maxRows: s
1059
+ }),
1060
+ signal: w.signal
1061
+ }), k = await F.text();
1062
+ let T = null;
1063
+ if (k)
1064
+ try {
1065
+ T = JSON.parse(k);
1066
+ } catch {
1067
+ return {
1068
+ ok: !1,
1069
+ results: [],
1070
+ error: {
1071
+ type: "BadResponse",
1072
+ message: `SQL 服务返回的不是合法 JSON(HTTP ${F.status})`
1073
+ },
1074
+ durationMs: performance.now() - h
1075
+ };
1076
+ }
1077
+ if (!F.ok) {
1078
+ const S = T ? Rn(T, performance.now() - h) : null;
1079
+ return {
1080
+ ok: !1,
1081
+ results: [],
1082
+ error: (S == null ? void 0 : S.error) ?? {
1083
+ type: `Http${F.status}`,
1084
+ message: `SQL 服务返回 HTTP ${F.status}${F.statusText ? ` ${F.statusText}` : ""}`
1085
+ },
1086
+ durationMs: performance.now() - h
1087
+ };
1088
+ }
1089
+ return Rn(T, performance.now() - h);
1090
+ } catch (F) {
1091
+ if (C)
1092
+ return {
1093
+ ok: !1,
1094
+ results: [],
1095
+ error: {
1096
+ type: "Timeout",
1097
+ message: `SQL 请求超时(${o.timeoutMs ?? pt}ms)`
1098
+ },
1099
+ durationMs: performance.now() - h
1100
+ };
1101
+ throw F;
1102
+ } finally {
1103
+ clearTimeout(_), i == null || i.removeEventListener("abort", O);
1104
+ }
1105
+ }
1106
+ function _n(o, n) {
1107
+ if (!o || typeof o != "object")
1108
+ return {
1109
+ ok: !1,
1110
+ results: [],
1111
+ error: { type: "SqlError", message: "SQL 执行器没有返回结果" },
1112
+ durationMs: n
1113
+ };
1114
+ const s = Number.isFinite(o.durationMs) && o.durationMs >= 0 ? o.durationMs : n;
1115
+ return o.ok ? {
1116
+ ok: !0,
1117
+ results: (o.results ?? []).map(Ht),
1118
+ durationMs: s
1119
+ } : {
1120
+ ok: !1,
1121
+ results: (o.results ?? []).map(Ht),
1122
+ error: o.error ? Dt(o.error, "SQL 执行失败") : { type: "SqlError", message: "SQL 执行失败" },
1123
+ durationMs: s
1124
+ };
1125
+ }
1126
+ async function Kn(o, n, s = {}) {
1127
+ const i = U(o), u = i.maxRows ?? Jn, h = performance.now();
1128
+ if (!n.trim())
1129
+ return {
1130
+ ok: !1,
1131
+ results: [],
1132
+ error: { type: "EmptySql", message: "SQL 内容为空" },
1133
+ durationMs: 0
1134
+ };
1135
+ try {
1136
+ if (s.executor) {
1137
+ const C = await s.executor(
1138
+ { sql: n, connection: i.connection, maxRows: u },
1139
+ { signal: s.signal }
1140
+ );
1141
+ return _n(C, performance.now() - h);
1142
+ }
1143
+ if (i.mode === "http")
1144
+ return await oa(i, n, u, s.signal);
1145
+ const w = await Ut().executeSql({
1146
+ sql: n,
1147
+ database: i.connection.database || ":memory:",
1148
+ maxRows: u
1149
+ });
1150
+ return _n(w, performance.now() - h);
1151
+ } catch (w) {
1152
+ return aa(w) ? {
1153
+ ok: !1,
1154
+ results: [],
1155
+ error: { type: "AbortError", message: "SQL 执行已中断" },
1156
+ durationMs: performance.now() - h
1157
+ } : {
1158
+ ok: !1,
1159
+ results: [],
1160
+ error: Dt(w, "SQL 执行失败"),
1161
+ durationMs: performance.now() - h
1162
+ };
1163
+ }
1164
+ }
1165
+ function In(o) {
1166
+ var n;
1167
+ return (n = Ye.find((s) => s.value === o)) == null ? void 0 : n.defaultPort;
1168
+ }
1169
+ async function ia(o, n = {}) {
1170
+ var i;
1171
+ const s = await Kn(o, "SELECT 1", n);
1172
+ return s.ok ? {
1173
+ ok: !0,
1174
+ message: `连接成功(${Math.max(1, Math.round(s.durationMs))}ms)`,
1175
+ durationMs: s.durationMs
1176
+ } : {
1177
+ ok: !1,
1178
+ message: ((i = s.error) == null ? void 0 : i.message) ?? "连接失败",
1179
+ durationMs: s.durationMs
1180
+ };
1181
+ }
1182
+ async function zt(o, n, s, i = {}) {
1183
+ var O, F;
1184
+ const u = U(o), h = (u.endpoint ?? "").trim().replace(/\/+$/, "");
1185
+ if (!h)
1186
+ throw new Error("未配置 SQL 服务端点");
1187
+ const w = new AbortController(), C = setTimeout(() => w.abort(), u.timeoutMs ?? pt), _ = () => w.abort();
1188
+ i.signal && (i.signal.aborted ? w.abort() : i.signal.addEventListener("abort", _));
1189
+ try {
1190
+ const k = await fetch(h + n, {
1191
+ ...s,
1192
+ headers: {
1193
+ "Content-Type": "application/json",
1194
+ ...u.headers ?? {},
1195
+ ...s.headers ?? {}
1196
+ },
1197
+ signal: w.signal
1198
+ }), T = await k.text();
1199
+ let S = null;
1200
+ if (T)
1201
+ try {
1202
+ S = JSON.parse(T);
1203
+ } catch {
1204
+ throw new Error(`SQL 服务返回的不是合法 JSON(HTTP ${k.status})`);
1205
+ }
1206
+ if (!k.ok || !S || S.ok === !1)
1207
+ throw new Error(((O = S == null ? void 0 : S.error) == null ? void 0 : O.message) ?? `SQL 服务返回 HTTP ${k.status}`);
1208
+ return S.data;
1209
+ } finally {
1210
+ clearTimeout(C), (F = i.signal) == null || F.removeEventListener("abort", _);
1211
+ }
1212
+ }
1213
+ function la(o, n = {}) {
1214
+ return zt(o, "/connections", { method: "GET" }, n);
1215
+ }
1216
+ function ua(o, n, s, i = {}) {
1217
+ return zt(
1218
+ o,
1219
+ s ? `/connections/${encodeURIComponent(s)}` : "/connections",
1220
+ { method: s ? "PUT" : "POST", body: JSON.stringify(n) },
1221
+ i
1222
+ );
1223
+ }
1224
+ async function Nn(o, n, s = {}) {
1225
+ await zt(
1226
+ o,
1227
+ `/connections/${encodeURIComponent(n)}`,
1228
+ { method: "DELETE" },
1229
+ s
1230
+ );
1231
+ }
1232
+ const vt = [
560
1233
  { value: "python", label: "Python", extension: "py" },
561
1234
  { value: "sql", label: "SQL", extension: "sql" },
562
1235
  { value: "javascript", label: "JavaScript", extension: "js" },
563
1236
  { value: "json", label: "JSON", extension: "json" }
564
1237
  ];
565
- function pe(u) {
566
- return fe.find((r) => r.value === u) ?? fe[0];
1238
+ function ft(o) {
1239
+ return vt.find((n) => n.value === o) ?? vt[0];
567
1240
  }
568
- function we(u) {
569
- switch (u) {
1241
+ function $t(o) {
1242
+ switch (o) {
570
1243
  case "sql":
571
- return dn();
1244
+ return _s();
572
1245
  case "javascript":
573
- return ln();
1246
+ return $s();
574
1247
  case "json":
575
- return un();
1248
+ return Rs();
576
1249
  case "python":
577
1250
  default:
578
- return Qe();
1251
+ return zn();
579
1252
  }
580
1253
  }
581
- function bn(u) {
582
- const r = u.lastIndexOf(".");
583
- if (r < 0) return "python";
584
- switch (u.slice(r + 1).toLowerCase()) {
1254
+ function Hn(o) {
1255
+ const n = o.lastIndexOf(".");
1256
+ if (n < 0) return "python";
1257
+ switch (o.slice(n + 1).toLowerCase()) {
585
1258
  case "sql":
586
1259
  return "sql";
587
1260
  case "js":
@@ -596,9 +1269,9 @@ function bn(u) {
596
1269
  return "python";
597
1270
  }
598
1271
  }
599
- function R(u) {
600
- const r = Array.isArray(u) ? u : [u];
601
- return () => Ke(
1272
+ function J(o) {
1273
+ const n = Array.isArray(o) ? o : [o];
1274
+ return () => En(
602
1275
  "svg",
603
1276
  {
604
1277
  viewBox: "0 0 24 24",
@@ -607,44 +1280,111 @@ function R(u) {
607
1280
  fill: "currentColor",
608
1281
  "aria-hidden": "true"
609
1282
  },
610
- r.map((a) => Ke("path", { d: a }))
1283
+ n.map((s) => En("path", { d: s }))
611
1284
  );
612
1285
  }
613
- const wn = R(
1286
+ const da = J(
614
1287
  "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(
1288
+ ), ca = J("M6 6h12v12H6Z"), Un = J(
616
1289
  "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(
1290
+ ), fa = J(
618
1291
  "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(
1292
+ ), pa = J(
620
1293
  "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(
1294
+ ), Bn = J(
622
1295
  "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(
1296
+ ), An = J("M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"), va = J(
624
1297
  "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(
1298
+ ), ma = J("M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"), Ge = J(
626
1299
  "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 = {
1300
+ ), ya = J("M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6V5z"), ha = J([
1301
+ "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"
1302
+ ]), ga = J(
1303
+ "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"
1304
+ ), ba = J([
1305
+ "M4 4h16a1 1 0 0 1 1 1v5H3V5a1 1 0 0 1 1-1Zm-1 8h18v5H3v-5Z",
1306
+ "M18 15.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
1307
+ ]), ka = {
628
1308
  key: 0,
629
1309
  class: "vpe-toolbar"
630
- }, $n = ["title", "disabled"], Ln = ["disabled"], In = ["disabled"], Mn = ["title", "aria-label"], Rn = ["disabled"], Hn = {
1310
+ }, wa = ["title", "disabled"], Sa = ["disabled"], qa = ["disabled"], Ea = ["title", "disabled"], xa = ["title", "aria-label"], Ca = { key: 2 }, Pa = { key: 3 }, Ma = ["disabled"], Oa = {
631
1311
  class: "vpe-file",
632
1312
  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 = {
1313
+ }, Fa = ["disabled"], La = {
1314
+ value: "",
1315
+ disabled: ""
1316
+ }, Ta = ["value"], $a = ["value", "disabled"], Ra = ["value"], _a = ["aria-selected", "data-file-id", "title", "onClick", "onKeydown"], Ia = { class: "vpe-tab-name" }, Na = ["title", "aria-label", "disabled", "onClick"], Ha = ["disabled"], Ua = { class: "vpe-output-head" }, Ba = { class: "vpe-output-main" }, Aa = {
1317
+ key: 0,
1318
+ class: "vpe-sql-results"
1319
+ }, Da = { class: "vpe-sql-result-head" }, za = {
1320
+ key: 0,
1321
+ class: "vpe-sql-table-wrap"
1322
+ }, ja = { class: "vpe-sql-table" }, Va = {
1323
+ key: 0,
1324
+ class: "vpe-sql-empty"
1325
+ }, Qa = {
1326
+ key: 1,
1327
+ class: "vpe-sql-affected"
1328
+ }, Ja = {
634
1329
  key: 1,
635
1330
  class: "vpe-empty"
636
- }, zn = {
637
- key: 3,
1331
+ }, Ka = {
1332
+ key: 0,
1333
+ class: "vpe-terminal-input"
1334
+ }, Za = ["onKeydown"], Wa = {
1335
+ key: 4,
638
1336
  class: "vpe-fs-panel",
639
1337
  role: "dialog",
640
1338
  "aria-label": "虚拟文件"
641
- }, Kn = { class: "vpe-fs-head" }, An = ["disabled"], qn = { class: "vpe-fs-body" }, Wn = {
1339
+ }, Ga = { class: "vpe-fs-head" }, Ya = ["disabled"], Xa = { class: "vpe-fs-body" }, eo = {
1340
+ key: 0,
1341
+ class: "vpe-fs-empty"
1342
+ }, to = {
1343
+ key: 0,
1344
+ class: "vpe-fs-empty"
1345
+ }, no = ["title"], ro = { class: "vpe-fs-size" }, so = ["title", "aria-label", "onClick"], ao = {
1346
+ key: 5,
1347
+ class: "vpe-fs-panel",
1348
+ role: "dialog",
1349
+ "aria-label": "服务端文件"
1350
+ }, oo = { class: "vpe-fs-head" }, io = ["disabled"], lo = { class: "vpe-fs-body" }, uo = {
1351
+ key: 0,
1352
+ class: "vpe-fs-empty"
1353
+ }, co = {
642
1354
  key: 0,
643
1355
  class: "vpe-fs-empty"
644
- }, Jn = {
1356
+ }, fo = ["title"], po = ["title"], vo = ["title", "disabled", "onClick"], mo = ["title", "disabled", "onClick"], yo = {
1357
+ key: 1,
1358
+ class: "vpe-sql-hint vpe-sql-hint--error"
1359
+ }, ho = {
1360
+ key: 6,
1361
+ class: "vpe-sql-panel",
1362
+ role: "dialog",
1363
+ "aria-label": "SQL 连接配置"
1364
+ }, go = { class: "vpe-fs-head" }, bo = { class: "vpe-fs-title" }, ko = { class: "vpe-sql-body" }, wo = { class: "vpe-sql-field" }, So = { class: "vpe-sql-field" }, qo = { class: "vpe-sql-field" }, Eo = { class: "vpe-sql-field" }, xo = ["value"], Co = { class: "vpe-sql-row" }, Po = { class: "vpe-sql-field vpe-sql-field--grow" }, Mo = { class: "vpe-sql-field vpe-sql-field--grow" }, Oo = { class: "vpe-sql-row" }, Fo = { class: "vpe-sql-field vpe-sql-field--grow" }, Lo = { class: "vpe-sql-field vpe-sql-field--grow" }, To = ["placeholder"], $o = { class: "vpe-sql-field" }, Ro = {
1365
+ key: 0,
1366
+ class: "vpe-sql-field"
1367
+ }, _o = {
1368
+ key: 1,
1369
+ class: "vpe-sql-hint"
1370
+ }, Io = { class: "vpe-sql-actions" }, No = ["disabled"], Ho = ["disabled"], Uo = ["disabled"], Bo = {
1371
+ key: 3,
1372
+ class: "vpe-sql-test vpe-sql-test--err"
1373
+ }, Ao = {
1374
+ key: 7,
1375
+ class: "vpe-sql-manager-panel",
1376
+ role: "dialog",
1377
+ "aria-label": "连接管理"
1378
+ }, Do = { class: "vpe-fs-head" }, zo = ["disabled"], jo = { class: "vpe-sql-manager-body" }, Vo = {
645
1379
  key: 0,
646
1380
  class: "vpe-fs-empty"
647
- }, Zn = ["title"], Gn = { class: "vpe-fs-size" }, Xn = ["title", "aria-label", "onClick"], xe = 1, Yn = /* @__PURE__ */ Nt({
1381
+ }, Qo = {
1382
+ key: 0,
1383
+ class: "vpe-fs-empty"
1384
+ }, Jo = { class: "vpe-sql-manager-main" }, Ko = ["title"], Zo = { class: "vpe-sql-manager-meta" }, Wo = ["onClick"], Go = ["disabled", "onClick"], Yo = {
1385
+ key: 1,
1386
+ class: "vpe-sql-hint vpe-sql-hint--error"
1387
+ }, Rt = 1, Dn = 80, Xo = /* @__PURE__ */ os({
648
1388
  __name: "PythonEditor",
649
1389
  props: {
650
1390
  modelValue: { default: "" },
@@ -667,401 +1407,928 @@ const wn = R(
667
1407
  stdin: { default: "" },
668
1408
  syncFilesOnRun: { type: Boolean, default: !0 },
669
1409
  storageKey: { default: "" },
670
- preloadPackages: { default: () => [] }
1410
+ preloadPackages: { default: () => [] },
1411
+ sqlConfig: { default: () => ({}) },
1412
+ sqlExecutor: { type: Function, default: void 0 },
1413
+ showSqlConfig: { type: Boolean, default: !0 },
1414
+ sqlEndpointLocked: { type: Boolean, default: !1 },
1415
+ filesEndpoint: { default: "" },
1416
+ filesHeaders: { default: void 0 },
1417
+ pythonEndpoint: { default: "" },
1418
+ pythonHeaders: { default: void 0 },
1419
+ runtime: { default: "browser" }
671
1420
  },
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,
1421
+ 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"],
1422
+ setup(o, { expose: n, emit: s }) {
1423
+ const i = o, u = s, h = q(), w = q(), C = q(), _ = q(), O = q(), F = q(), k = q(null), T = q(!1), S = xn(/* @__PURE__ */ new Map()), K = H(() => le().lines), de = H(() => le().sqlResults), x = xn(/* @__PURE__ */ new Map()), z = H(() => x.get(b.value.id) ?? null), Fe = H(() => {
1424
+ var e;
1425
+ return !!((e = z.value) != null && e.busy);
1426
+ }), Le = H(() => {
1427
+ var e;
1428
+ return !!((e = z.value) != null && e.waiting);
1429
+ }), I = H({
1430
+ get: () => {
1431
+ var e;
1432
+ return ((e = z.value) == null ? void 0 : e.input) ?? "";
1433
+ },
683
1434
  set: (e) => {
684
- const t = y.value;
685
- t.name !== e && (t.name = e, s("update:fileName", e));
1435
+ const t = z.value;
1436
+ t && (t.input = e);
686
1437
  }
687
- }), Pe = new ce(), Ce = new ce(), me = new ce(), ye = new ce(), b = nt(i.pyodideUrl ? { pyodideUrl: i.pyodideUrl } : void 0), rt = ie(() => ({
1438
+ }), y = q(null), R = q("idle"), j = q(i.runtime), ce = q(!1), ge = q(!1), De = q(!1), ze = q([]), me = q(!1), Xe = q(!1), je = q([]), Te = q(""), Z = q(!1), Ee = q(!1), ye = q(!1), xe = q(!1), Ve = q(""), et = q(!1), c = q(U(i.sqlConfig)), be = q([]), $e = q(!1), ke = q(""), Y = q(""), X = q(!1), ee = q(""), Re = q(!1), Ce = q(!1), _e = q(""), tt = q(!1);
1439
+ let yt = !1, nt, jt = !1, ht = !1, Vt = !1, E = null, Zn = 0, Wn = 0, rt = null, st = null, gt, oe = null, W = null, te = null, ne = null, Gn = 0, Qe = 0;
1440
+ function Ie(e, t, a) {
1441
+ return { id: ++Wn, name: e, language: t, code: a };
1442
+ }
1443
+ const L = q([Ie(i.fileName, i.language, i.modelValue)]), he = q(L.value[0].id), b = H(
1444
+ () => L.value.find((e) => e.id === he.value) ?? L.value[0]
1445
+ ), Pe = H({
1446
+ get: () => b.value.name,
1447
+ set: (e) => {
1448
+ const t = b.value;
1449
+ t.name !== e && (t.name = e, u("update:fileName", e));
1450
+ }
1451
+ }), Qt = new ct(), Jt = new ct(), bt = new ct(), kt = new ct(), D = Ut(i.pyodideUrl ? { pyodideUrl: i.pyodideUrl } : void 0), Yn = H(() => ({
688
1452
  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) {
1453
+ }));
1454
+ let Kt = 0, wt = 0, Ne = null;
1455
+ const Xn = H(
1456
+ () => k.value !== null ? `${k.value}px` : typeof i.outputHeight == "number" ? `${i.outputHeight}px` : i.outputHeight
1457
+ ), ie = H(() => b.value.language === "sql"), Zt = H(() => b.value.language === "python"), at = H(() => !!(i.pythonEndpoint ?? "").trim()), He = H(
1458
+ () => Zt.value && at.value && j.value === "server"
1459
+ ), we = H(() => !!(i.filesEndpoint ?? "").trim()), St = H(() => Fe.value || ye.value && y.value === b.value.id ? !0 : R.value === "running" && y.value === b.value.id), er = H(() => ie.value && c.value.mode === "http" ? ye.value && y.value === b.value.id ? "查询中" : "外部服务" : He.value ? Fe.value ? Le.value ? "等待输入" : "执行中" : "服务端" : R.value === "running" && y.value !== b.value.id ? "就绪" : {
1460
+ idle: "未加载",
1461
+ loading: "正在加载 Pyodide…",
1462
+ ready: "就绪",
1463
+ running: "运行中"
1464
+ }[R.value]), tr = H(() => ie.value && c.value.mode === "http" ? ye.value && y.value === b.value.id ? "running" : "ready" : He.value ? Fe.value ? Le.value ? "loading" : "running" : "ready" : R.value === "running" && y.value !== b.value.id ? "ready" : R.value), nr = H(() => ie.value ? "执行 SQL (Ctrl+Enter)" : He.value ? "运行(服务端 Python,Ctrl+Enter)" : b.value.language === "python" ? "运行 (Ctrl+Enter)" : "仅支持执行 Python / SQL 文件"), rr = H(() => St.value ? !0 : He.value || ie.value ? !1 : R.value === "loading" || b.value.language !== "python"), sr = H(() => c.value.mode === "http" ? c.value.connectionId ? "SQL 连接配置" : "新建 SQL 连接" : "SQL 连接");
1465
+ function Ue(e) {
700
1466
  return { ...e };
701
1467
  }
702
- function Q(e, t) {
703
- C.value.push({ id: ++h, stream: e, text: t });
1468
+ function le(e = b.value.id) {
1469
+ let t = S.get(e);
1470
+ return t || (t = { lines: [], sqlResults: [] }, S.set(e, t)), t;
1471
+ }
1472
+ function fe(e, t, a) {
1473
+ le(a).lines.push({ id: ++Zn, stream: e, text: t });
704
1474
  }
705
- function p(e) {
706
- Q("system", e);
1475
+ function m(e, t) {
1476
+ fe("system", e, t);
707
1477
  }
708
- function st(e) {
709
- return fe.some((t) => t.value === e);
1478
+ function ar(e) {
1479
+ return vt.some((t) => t.value === e);
710
1480
  }
711
- function ot() {
1481
+ function or() {
712
1482
  if (!i.storageKey || typeof window > "u") return null;
713
1483
  try {
714
1484
  const e = window.localStorage.getItem(i.storageKey);
715
1485
  if (!e) return null;
716
1486
  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 });
1487
+ if (t.version !== Rt || !Array.isArray(t.files)) return null;
1488
+ const a = [];
1489
+ for (const v of t.files) {
1490
+ if (!v || typeof v.name != "string" || typeof v.code != "string" || !v.name.trim()) continue;
1491
+ const g = ar(v.language) ? v.language : "python";
1492
+ a.push({ name: v.name, language: g, code: v.code });
723
1493
  }
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 };
1494
+ if (!a.length) return null;
1495
+ const r = typeof t.activeIndex == "number" ? t.activeIndex : 0, d = Math.min(Math.max(Math.trunc(r) || 0, 0), a.length - 1);
1496
+ return { version: Rt, files: a, activeIndex: d };
727
1497
  } catch {
728
1498
  return null;
729
1499
  }
730
1500
  }
731
- function lt() {
732
- const e = ot();
1501
+ function ir() {
1502
+ const e = or();
733
1503
  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);
1504
+ L.value = e.files.map((a) => Ie(a.name, a.language, a.code));
1505
+ const t = L.value[e.activeIndex] ?? L.value[0];
1506
+ he.value = t.id, m(`已恢复上次编辑内容(${L.value.length} 个文件)`), u("update:modelValue", t.code), u("update:fileName", t.name), u("update:language", t.language);
737
1507
  }
738
- function Oe() {
739
- if (!(!J || oe || !i.storageKey || typeof window > "u"))
1508
+ function Wt() {
1509
+ if (!(!yt || ht || !i.storageKey || typeof window > "u"))
740
1510
  try {
741
1511
  const e = {
742
- version: xe,
743
- files: f.value.map((t) => ({
1512
+ version: Rt,
1513
+ files: L.value.map((t) => ({
744
1514
  name: t.name,
745
1515
  language: t.language,
746
1516
  code: t.code
747
1517
  })),
748
1518
  activeIndex: Math.max(
749
- f.value.findIndex((t) => t.id === _.value),
1519
+ L.value.findIndex((t) => t.id === he.value),
750
1520
  0
751
1521
  )
752
1522
  };
753
1523
  window.localStorage.setItem(i.storageKey, JSON.stringify(e));
754
1524
  } catch (e) {
755
- he || (he = !0, p(`本地草稿保存失败:${e instanceof Error ? e.message : String(e)}`));
1525
+ jt || (jt = !0, m(`本地草稿保存失败:${e instanceof Error ? e.message : String(e)}`));
756
1526
  }
757
1527
  }
758
- function ut() {
759
- !J || !i.storageKey || typeof window > "u" || (oe = !1, window.clearTimeout(Z), Z = window.setTimeout(Oe, 400));
1528
+ function lr() {
1529
+ !yt || !i.storageKey || typeof window > "u" || (ht = !1, window.clearTimeout(nt), nt = window.setTimeout(Wt, 400));
760
1530
  }
761
- function dt() {
1531
+ function ur() {
762
1532
  if (!(!i.storageKey || typeof window > "u")) {
763
- window.clearTimeout(Z);
1533
+ window.clearTimeout(nt);
764
1534
  try {
765
- window.localStorage.removeItem(i.storageKey), oe = !0, p("已清除本地草稿");
1535
+ window.localStorage.removeItem(i.storageKey), ht = !0, m("已清除本地草稿");
766
1536
  } catch (e) {
767
- p(`清除本地草稿失败:${e instanceof Error ? e.message : String(e)}`);
1537
+ m(`清除本地草稿失败:${e instanceof Error ? e.message : String(e)}`);
768
1538
  }
769
1539
  }
770
1540
  }
771
- function ee(e) {
772
- if (!o) return;
1541
+ function Se(e) {
1542
+ if (!E) return;
773
1543
  const t = e ? [e] : [];
774
- o.dispatch({ effects: et.of(t) });
1544
+ E.dispatch({ effects: jn.of(t) });
775
1545
  }
776
- function ct() {
1546
+ function dr() {
777
1547
  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 } });
1548
+ if (E) {
1549
+ e !== E.state.doc.toString() && E.dispatch({ changes: { from: 0, to: E.state.doc.length, insert: e } });
780
1550
  return;
781
1551
  }
782
- const t = y.value;
1552
+ const t = b.value;
783
1553
  t.code !== e && (t.code = e);
784
1554
  }
785
- function te() {
786
- return o ? o.state.doc.toString() : y.value.code;
1555
+ function qe() {
1556
+ return E ? E.state.doc.toString() : b.value.code;
787
1557
  }
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 } });
1558
+ function ot(e) {
1559
+ if (E) {
1560
+ e !== E.state.doc.toString() && E.dispatch({ changes: { from: 0, to: E.state.doc.length, insert: e } });
791
1561
  return;
792
1562
  }
793
- const t = y.value;
794
- t.code = e, e !== i.modelValue && s("update:modelValue", e);
1563
+ const t = b.value;
1564
+ t.code = e, e !== i.modelValue && u("update:modelValue", e);
795
1565
  }
796
- function ve(e) {
797
- return i.disableLint || e !== "python" ? [] : yn(b, i.lintDelay);
1566
+ function qt(e) {
1567
+ return i.disableLint || e !== "python" ? [] : As(D, i.lintDelay);
798
1568
  }
799
- function $e(e) {
800
- const t = y.value;
1569
+ function Et(e) {
1570
+ const t = b.value;
801
1571
  if (t.language !== e) {
802
- if (t.language = e, ee(void 0), o == null || o.dispatch({
1572
+ if (t.language = e, le(t.id).sqlResults = [], Se(void 0), E == null || E.dispatch({
803
1573
  effects: [
804
- me.reconfigure(we(e)),
805
- ye.reconfigure(ve(e))
1574
+ bt.reconfigure($t(e)),
1575
+ kt.reconfigure(qt(e))
806
1576
  ]
807
1577
  }), /^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));
1578
+ const r = `${t.name.slice(0, t.name.lastIndexOf("."))}.${ft(e).extension}`;
1579
+ L.value.some((d) => d.id !== t.id && d.name === r) || (t.name = r, u("update:fileName", r));
810
1580
  }
811
- s("update:language", e);
812
- }
813
- }
814
- function Le(e, t) {
815
- const l = e.trim().replace(/[\\/:*?"<>|]+/g, "_").replace(/\.+$/, "") || "untitled";
816
- return /\.[^.\\/]+$/.test(l) ? l : `${l}.${pe(t).extension}`;
817
- }
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;
824
- }
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;
832
- }
833
- let ne = 0;
834
- function ht(e) {
1581
+ u("update:language", e);
1582
+ }
1583
+ }
1584
+ function xt(e, t) {
1585
+ const r = e.trim().replace(/[\\/:*?"<>|]+/g, "_").replace(/\.+$/, "") || "untitled";
1586
+ return /\.[^.\\/]+$/.test(r) ? r : `${r}.${ft(t).extension}`;
1587
+ }
1588
+ function Gt(e) {
1589
+ const t = ft(e).extension, a = new Set(L.value.map((v) => v.name));
1590
+ let r = `untitled.${t}`, d = 2;
1591
+ for (; a.has(r); )
1592
+ r = `untitled-${d}.${t}`, d += 1;
1593
+ return r;
1594
+ }
1595
+ function Yt(e) {
1596
+ if (!L.value.some((g) => g.name === e)) return e;
1597
+ const t = e.lastIndexOf("."), a = t > 0 ? e.slice(0, t) : e, r = t > 0 ? e.slice(t) : "";
1598
+ let d = 2, v = `${a}-${d}${r}`;
1599
+ for (; L.value.some((g) => g.name === v); )
1600
+ d += 1, v = `${a}-${d}${r}`;
1601
+ return v;
1602
+ }
1603
+ let Be = 0;
1604
+ function cr(e) {
835
1605
  return !!e && e !== "." && e !== ".." && !e.includes("/") && !e.includes("\\");
836
1606
  }
837
- async function mt() {
1607
+ async function fr() {
838
1608
  var t;
839
1609
  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}(文件名不能包含路径分隔符)`);
1610
+ const e = L.value.filter((a) => a.language === "python");
1611
+ for (const a of e) {
1612
+ if (!cr(a.name)) {
1613
+ m(`跳过同步文件:${a.name}(文件名不能包含路径分隔符)`);
844
1614
  continue;
845
1615
  }
846
- const l = await b.writeFile(n.name, n.code);
847
- l.ok || p(`同步文件失败:${n.name}(${((t = l.error) == null ? void 0 : t.message) ?? "未知错误"})`);
1616
+ const r = await D.writeFile(a.name, a.code);
1617
+ r.ok || m(`同步文件失败:${a.name}(${((t = r.error) == null ? void 0 : t.message) ?? "未知错误"})`);
848
1618
  }
849
1619
  }
850
- async function Ie() {
851
- var d, m, k;
852
- if (M.value === "loading" || M.value === "running") return;
853
- const e = y.value.language;
1620
+ function Je() {
1621
+ W == null || W.abort(), W = null, xe.value = !1, Ve.value = "", et.value = !1;
1622
+ }
1623
+ function pe() {
1624
+ Je(), ee.value = "";
1625
+ const e = U(c.value);
1626
+ c.value = e, u("update:sqlConfig", U(e));
1627
+ }
1628
+ function pr() {
1629
+ Ce.value = !1, Ee.value = !0, ue();
1630
+ }
1631
+ function vr() {
1632
+ c.value.mode !== "http" && (c.value = U({ ...c.value, mode: "http" }), u("update:sqlConfig", U(c.value))), Ee.value = !1, Ce.value = !0, _e.value = "", tt.value = !1, ue();
1633
+ }
1634
+ function mr() {
1635
+ const e = c.value.connection.dialect, t = e === "sqlite" ? "mysql" : e;
1636
+ c.value = U({
1637
+ mode: "http",
1638
+ endpoint: c.value.endpoint,
1639
+ headers: c.value.headers,
1640
+ maxRows: c.value.maxRows,
1641
+ timeoutMs: c.value.timeoutMs,
1642
+ connection: { dialect: t, port: In(t) }
1643
+ }), Y.value = "", ee.value = "", ke.value = "", Je(), u("update:sqlConfig", U(c.value)), Ce.value = !1, Ee.value = !0, ue();
1644
+ }
1645
+ function Xt() {
1646
+ Ee.value = !1;
1647
+ }
1648
+ function yr() {
1649
+ const e = c.value;
1650
+ e.mode === "sqlite" ? (e.connectionId = void 0, e.connection.dialect = "sqlite", e.connection.database || (e.connection.database = ":memory:"), Y.value = "") : (e.connection.dialect === "sqlite" && (e.connection.dialect = "mysql", e.connection.port = In("mysql")), e.connection.database === ":memory:" && (e.connection.database = "")), pe(), e.mode === "http" && ue();
1651
+ }
1652
+ function hr() {
1653
+ const e = c.value.connection, t = Ye.find((r) => r.value === e.dialect), a = Ye.map((r) => r.defaultPort);
1654
+ t != null && t.defaultPort && (!e.port || a.includes(e.port)) && (e.port = t.defaultPort), pe();
1655
+ }
1656
+ async function ue() {
1657
+ const e = U(c.value);
1658
+ if (!e.endpoint) {
1659
+ be.value = [], ke.value = "";
1660
+ return;
1661
+ }
1662
+ te == null || te.abort();
1663
+ const t = new AbortController();
1664
+ te = t, $e.value = !0, ke.value = "";
1665
+ try {
1666
+ const a = await la(e, { signal: t.signal });
1667
+ if (te !== t) return;
1668
+ be.value = a;
1669
+ const r = a.find((d) => d.id === c.value.connectionId);
1670
+ r ? Y.value = r.name : c.value.connectionId && (c.value.connectionId = void 0, Y.value = "");
1671
+ } catch (a) {
1672
+ if (te !== t) return;
1673
+ be.value = [], ke.value = a instanceof Error ? a.message : String(a);
1674
+ } finally {
1675
+ te === t && (te = null, $e.value = !1);
1676
+ }
1677
+ }
1678
+ function en(e) {
1679
+ c.value = U({
1680
+ mode: "http",
1681
+ endpoint: c.value.endpoint,
1682
+ headers: c.value.headers,
1683
+ maxRows: c.value.maxRows,
1684
+ timeoutMs: c.value.timeoutMs,
1685
+ connectionId: e.id,
1686
+ connection: {
1687
+ dialect: e.dialect,
1688
+ host: e.host ?? "",
1689
+ port: e.port,
1690
+ user: e.user ?? "",
1691
+ password: "",
1692
+ database: e.database ?? "",
1693
+ options: e.options
1694
+ }
1695
+ }), Y.value = e.name, ee.value = "", Je(), u("update:sqlConfig", U(c.value));
1696
+ }
1697
+ function gr() {
1698
+ Ee.value = !1, Ce.value = !1;
1699
+ const e = be.value.find((t) => t.id === c.value.connectionId);
1700
+ if (!e) {
1701
+ c.value.connectionId = void 0, c.value.connection.password = "", Y.value = "", pe();
1702
+ return;
1703
+ }
1704
+ en(e);
1705
+ }
1706
+ function br(e) {
1707
+ en(e), Ce.value = !1, Ee.value = !0;
1708
+ }
1709
+ async function kr() {
1710
+ if (X.value) return;
1711
+ const e = Y.value.trim();
1712
+ if (!e) {
1713
+ Re.value = !1, ee.value = "请先填写连接名称";
1714
+ return;
1715
+ }
1716
+ const t = U(c.value), a = {
1717
+ name: e,
1718
+ dialect: t.connection.dialect,
1719
+ host: t.connection.host,
1720
+ port: t.connection.port,
1721
+ user: t.connection.user,
1722
+ password: t.connection.password || void 0,
1723
+ database: t.connection.database,
1724
+ options: t.connection.options
1725
+ };
1726
+ X.value = !0, ee.value = "";
1727
+ try {
1728
+ const r = await ua(t, a, t.connectionId);
1729
+ c.value = U({
1730
+ ...t,
1731
+ connectionId: r.id,
1732
+ connection: { ...t.connection, password: "" }
1733
+ }), Y.value = r.name, Re.value = !0, ee.value = "连接已保存", u("update:sqlConfig", U(c.value)), await ue();
1734
+ } catch (r) {
1735
+ Re.value = !1, ee.value = r instanceof Error ? r.message : String(r);
1736
+ } finally {
1737
+ X.value = !1;
1738
+ }
1739
+ }
1740
+ async function wr() {
1741
+ const e = c.value.connectionId;
1742
+ if (!(!e || X.value) && !(typeof window < "u" && !window.confirm("确定删除该连接配置?"))) {
1743
+ X.value = !0, ee.value = "";
1744
+ try {
1745
+ await Nn(c.value, e), c.value.connectionId = void 0, Y.value = "", Re.value = !0, ee.value = "连接已删除", u("update:sqlConfig", U(c.value)), await ue();
1746
+ } catch (t) {
1747
+ Re.value = !1, ee.value = t instanceof Error ? t.message : String(t);
1748
+ } finally {
1749
+ X.value = !1;
1750
+ }
1751
+ }
1752
+ }
1753
+ async function Sr(e) {
1754
+ if (!X.value && !(typeof window < "u" && !window.confirm(`确定删除连接“${e.name}”?`))) {
1755
+ X.value = !0, _e.value = "";
1756
+ try {
1757
+ await Nn(c.value, e.id), c.value.connectionId === e.id && (c.value.connectionId = void 0, c.value.connection.password = "", Y.value = "", u("update:sqlConfig", U(c.value))), tt.value = !0, _e.value = `已删除连接“${e.name}”`, await ue();
1758
+ } catch (t) {
1759
+ tt.value = !1, _e.value = t instanceof Error ? t.message : String(t);
1760
+ } finally {
1761
+ X.value = !1;
1762
+ }
1763
+ }
1764
+ }
1765
+ async function qr() {
1766
+ if (xe.value) return;
1767
+ Je(), xe.value = !0;
1768
+ const e = new AbortController();
1769
+ W = e;
1770
+ try {
1771
+ const t = await ia(U(c.value), {
1772
+ executor: i.sqlExecutor,
1773
+ signal: e.signal
1774
+ });
1775
+ if (W !== e) return;
1776
+ et.value = t.ok, Ve.value = t.message;
1777
+ } catch (t) {
1778
+ if (W !== e) return;
1779
+ et.value = !1, Ve.value = t instanceof Error ? t.message : String(t);
1780
+ } finally {
1781
+ W === e && (W = null, xe.value = !1);
1782
+ }
1783
+ }
1784
+ function Er(e) {
1785
+ return e === null ? "NULL" : String(e);
1786
+ }
1787
+ function xr(e) {
1788
+ return e.columns.length ? `${e.rows.length} 行${e.truncated ? "(已截断)" : ""}` : `影响 ${e.affectedRows ?? 0} 行`;
1789
+ }
1790
+ function tn(e) {
1791
+ if (e)
1792
+ return { type: e.type, message: e.message, traceback: "" };
1793
+ }
1794
+ async function nn() {
1795
+ if (ye.value)
1796
+ return y.value !== b.value.id && m("另一个 SQL 正在执行,请等待或停止后再试"), null;
1797
+ const e = qe();
1798
+ if (!e.trim())
1799
+ return m("SQL 内容为空,请输入要执行的语句"), null;
1800
+ const t = U(c.value), a = ++Qe, r = b.value.id;
1801
+ ye.value = !0, y.value = r, oe = new AbortController(), Se(void 0), i.clearOutputOnRun && (le(r).lines = [], le(r).sqlResults = []), m(
1802
+ `开始执行 SQL(${t.mode === "sqlite" ? "浏览器内 SQLite" : "HTTP 服务"})`,
1803
+ r
1804
+ ), u("runStart");
1805
+ try {
1806
+ const d = await Kn(t, e, {
1807
+ executor: i.sqlExecutor,
1808
+ signal: oe.signal
1809
+ });
1810
+ if (a !== Qe) return null;
1811
+ if (le(r).sqlResults = d.results ?? [], d.ok) {
1812
+ const v = d.results ?? [], g = v.reduce((P, V) => P + V.rows.length, 0);
1813
+ m(
1814
+ `SQL 执行完成:${v.length} 个结果集,共 ${g} 行,耗时 ${(d.durationMs / 1e3).toFixed(2)}s`,
1815
+ r
1816
+ );
1817
+ } else {
1818
+ const v = d.error ?? { type: "SqlError", message: "SQL 执行失败" };
1819
+ m(`SQL 执行出错:${v.type}`, r), fe("stderr", v.message, r), u("runOutput", { stream: "stderr", text: v.message }), u("sqlError", v);
1820
+ }
1821
+ return u("sqlResult", d), u("runFinish", {
1822
+ ok: d.ok,
1823
+ durationMs: d.durationMs,
1824
+ error: d.ok ? void 0 : tn(d.error)
1825
+ }), d;
1826
+ } catch (d) {
1827
+ if (a !== Qe) return null;
1828
+ const v = d instanceof Error ? d.message : String(d);
1829
+ m(`SQL 执行失败:${v}`, r);
1830
+ const g = { type: "SqlError", message: v };
1831
+ return u("sqlError", g), u("runFinish", { ok: !1, durationMs: 0, error: tn(g) }), null;
1832
+ } finally {
1833
+ a === Qe && (ye.value = !1, oe = null, y.value === r && (y.value = null));
1834
+ }
1835
+ }
1836
+ async function Cr(e) {
1837
+ return e !== void 0 && (ot(e), b.value.language !== "sql" && Et("sql")), b.value.language !== "sql" ? (m("当前文件不是 SQL,无法执行"), null) : nn();
1838
+ }
1839
+ function Pr(e) {
1840
+ const t = e.target.value === "server" ? "server" : "browser";
1841
+ if (t === "browser")
1842
+ for (const a of [...x.keys()])
1843
+ Ke(a, !1);
1844
+ j.value = t, u("update:runtime", t), m(t === "server" ? "已切换到服务端 Python 环境" : "已切换到浏览器 Python 环境");
1845
+ }
1846
+ function rn(e, t, a, r) {
1847
+ if (!r) return;
1848
+ const d = r.replace(/\r\n/g, `
1849
+ `);
1850
+ let v = a === "stdout" ? t.stdoutBuffer : t.stderrBuffer;
1851
+ v += d;
1852
+ const g = v.split(`
1853
+ `), P = g.pop() ?? "";
1854
+ a === "stdout" ? t.stdoutBuffer = P : t.stderrBuffer = P;
1855
+ for (const V of g)
1856
+ fe(a, V, e), u("runOutput", { stream: a, text: V });
1857
+ }
1858
+ function sn(e, t) {
1859
+ t.stdoutBuffer && (fe("stdout", t.stdoutBuffer, e), u("runOutput", { stream: "stdout", text: t.stdoutBuffer }), t.stdoutBuffer = ""), t.stderrBuffer && (fe("stderr", t.stderrBuffer, e), u("runOutput", { stream: "stderr", text: t.stderrBuffer }), t.stderrBuffer = "");
1860
+ }
1861
+ function it(e, t, a) {
1862
+ window.clearTimeout(t.pollTimer), sn(e, t);
1863
+ const r = x.get(e);
1864
+ if (r && r.token === t.token && x.delete(e), a.error) {
1865
+ m(`执行出错:${a.error.type}`, e), e === b.value.id && Se(a.error.line);
1866
+ const v = {
1867
+ type: a.error.type,
1868
+ message: a.error.message,
1869
+ line: a.error.line,
1870
+ traceback: a.error.traceback ?? ""
1871
+ };
1872
+ u("runError", v), u("runFinish", { ok: !1, durationMs: a.durationMs ?? 0, error: v });
1873
+ return;
1874
+ }
1875
+ const d = a.durationMs ?? 0;
1876
+ m(`执行完成,会话时长 ${(d / 1e3).toFixed(2)}s`, e), u("runFinish", { ok: !0, durationMs: d });
1877
+ }
1878
+ function Ct(e, t, a, r) {
1879
+ const d = x.get(e);
1880
+ if (!(!d || d.token !== r)) {
1881
+ if (rn(e, t, "stdout", a.stdout), rn(e, t, "stderr", a.stderr), a.state === "exited") {
1882
+ it(e, t, a);
1883
+ return;
1884
+ }
1885
+ if (sn(e, t), a.state === "waiting") {
1886
+ t.waiting = !0;
1887
+ return;
1888
+ }
1889
+ t.waiting = !1, Mr(e, t, r);
1890
+ }
1891
+ }
1892
+ function Mr(e, t, a) {
1893
+ window.clearTimeout(t.pollTimer), t.pollTimer = window.setTimeout(() => {
1894
+ Or(e, a);
1895
+ }, 250);
1896
+ }
1897
+ async function Or(e, t) {
1898
+ var r, d;
1899
+ const a = x.get(e);
1900
+ if (!(!a || a.token !== t || !a.sessionId))
1901
+ try {
1902
+ const v = await ta(i.pythonEndpoint, a.sessionId, {
1903
+ headers: i.pythonHeaders,
1904
+ signal: (r = a.abort) == null ? void 0 : r.signal
1905
+ });
1906
+ Ct(e, a, v, t);
1907
+ } catch (v) {
1908
+ if (((d = x.get(e)) == null ? void 0 : d.token) !== t) return;
1909
+ const g = v instanceof Error ? v.message : String(v);
1910
+ m(`执行失败:${g}`, e), it(e, a, {
1911
+ sessionId: a.sessionId,
1912
+ durationMs: 0,
1913
+ error: { type: "RuntimeError", message: g }
1914
+ });
1915
+ }
1916
+ }
1917
+ async function Fr() {
1918
+ var v;
1919
+ const e = b.value.id;
1920
+ if ((v = x.get(e)) != null && v.busy) return;
1921
+ if (!at.value) {
1922
+ m("未配置 Python 服务端点(pythonEndpoint)");
1923
+ return;
1924
+ }
1925
+ const t = qe();
1926
+ if (!t.trim()) {
1927
+ m("代码为空,请输入要执行的 Python 代码");
1928
+ return;
1929
+ }
1930
+ const a = ++Gn, r = {
1931
+ sessionId: "",
1932
+ busy: !0,
1933
+ waiting: !1,
1934
+ input: "",
1935
+ abort: new AbortController(),
1936
+ token: a,
1937
+ pollTimer: void 0,
1938
+ stdoutBuffer: "",
1939
+ stderrBuffer: ""
1940
+ };
1941
+ x.set(e, r);
1942
+ const d = x.get(e);
1943
+ Se(void 0), i.clearOutputOnRun && (le(e).lines = []), m("开始执行(服务端 Python)", e), u("runStart");
1944
+ try {
1945
+ const g = await ea(i.pythonEndpoint, t, {
1946
+ stdin: i.stdin,
1947
+ headers: i.pythonHeaders,
1948
+ signal: d.abort.signal
1949
+ }), P = x.get(e);
1950
+ if (!P || P.token !== a) {
1951
+ g.sessionId && Ln(i.pythonEndpoint, g.sessionId, {
1952
+ headers: i.pythonHeaders
1953
+ });
1954
+ return;
1955
+ }
1956
+ P.sessionId = g.sessionId, Ct(e, P, g, a);
1957
+ } catch (g) {
1958
+ const P = x.get(e);
1959
+ if (!P || P.token !== a) return;
1960
+ const V = g instanceof Error ? g.message : String(g);
1961
+ m(`执行失败:${V}`, e), it(e, P, {
1962
+ durationMs: 0,
1963
+ error: { type: "RuntimeError", message: V }
1964
+ });
1965
+ }
1966
+ }
1967
+ async function an() {
1968
+ var r, d;
1969
+ const e = b.value.id, t = x.get(e);
1970
+ if (!t || !t.waiting || !t.sessionId) return;
1971
+ const a = t.input;
1972
+ t.input = "", t.waiting = !1, fe("stdout", a, e), u("runOutput", { stream: "stdout", text: a });
1973
+ try {
1974
+ const v = await na(i.pythonEndpoint, t.sessionId, a, {
1975
+ headers: i.pythonHeaders,
1976
+ signal: (r = t.abort) == null ? void 0 : r.signal
1977
+ });
1978
+ Ct(e, t, v, t.token);
1979
+ } catch (v) {
1980
+ if (((d = x.get(e)) == null ? void 0 : d.token) !== t.token) return;
1981
+ const g = v instanceof Error ? v.message : String(v);
1982
+ m(`执行失败:${g}`, e), it(e, t, {
1983
+ sessionId: t.sessionId,
1984
+ durationMs: 0,
1985
+ error: { type: "RuntimeError", message: g }
1986
+ });
1987
+ }
1988
+ }
1989
+ function Ke(e, t = !0) {
1990
+ var r;
1991
+ const a = x.get(e);
1992
+ a && (window.clearTimeout(a.pollTimer), x.delete(e), (r = a.abort) == null || r.abort(), a.sessionId && Ln(i.pythonEndpoint, a.sessionId, {
1993
+ headers: i.pythonHeaders
1994
+ }), t && m("执行已中断", e));
1995
+ }
1996
+ async function on() {
1997
+ var d, v, g;
1998
+ if (b.value.language === "sql") {
1999
+ await nn();
2000
+ return;
2001
+ }
2002
+ if (He.value) {
2003
+ await Fr();
2004
+ return;
2005
+ }
2006
+ if (R.value === "running") {
2007
+ y.value !== b.value.id && m(
2008
+ "浏览器环境共享同一个 Pyodide 实例,暂不支持同时运行多个文件;可切换到服务端环境后并行执行"
2009
+ );
2010
+ return;
2011
+ }
2012
+ if (R.value === "loading") return;
2013
+ const e = b.value.language;
854
2014
  if (e !== "python") {
855
- p(`当前文件为 ${pe(e).label},仅支持执行 Python 代码`);
2015
+ m(`当前文件为 ${ft(e).label},仅支持执行 Python / SQL 代码`);
856
2016
  return;
857
2017
  }
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();
2018
+ Be += 1;
2019
+ const t = Be, a = b.value.id;
2020
+ y.value = a, Se(void 0), i.clearOutputOnRun && (le(a).lines = []), m("开始执行", a), u("runStart");
2021
+ const r = qe();
862
2022
  try {
863
- await mt();
864
- const E = await b.run(l, {
2023
+ await fr();
2024
+ const P = await D.run(r, {
865
2025
  stdin: i.stdin,
866
- onOutput: (re, ae) => {
867
- Q(re, ae), s("runOutput", { stream: re, text: ae });
2026
+ onOutput: (V, We) => {
2027
+ fe(V, We, a), u("runOutput", { stream: V, text: We });
868
2028
  }
869
2029
  });
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 });
2030
+ if (t !== Be) return;
2031
+ P.interrupted ? m("执行已中断", a) : P.ok ? m(`执行完成,耗时 ${(P.durationMs / 1e3).toFixed(2)}s`, a) : (m(`执行出错:${((d = P.error) == null ? void 0 : d.type) ?? "未知错误"}`, a), (v = P.error) != null && v.traceback && (fe("stderr", P.error.traceback, a), u("runOutput", { stream: "stderr", text: P.error.traceback })), b.value.id === a && Se((g = P.error) == null ? void 0 : g.line), P.error && u("runError", P.error)), u("runFinish", P);
2032
+ } catch (P) {
2033
+ if (t !== Be) return;
2034
+ const V = P instanceof Error ? P.message : String(P);
2035
+ m(`执行失败:${V}`, a);
2036
+ const We = { type: "RuntimeError", message: V, traceback: "" };
2037
+ u("runError", We), u("runFinish", { ok: !1, durationMs: 0, error: We });
2038
+ } finally {
2039
+ t === Be && y.value === a && (y.value = null);
878
2040
  }
879
2041
  }
880
- async function yt() {
2042
+ async function Lr() {
881
2043
  var t;
882
- if (G) return;
2044
+ if (Vt) return;
883
2045
  const e = i.preloadPackages;
884
2046
  if (e.length) {
885
- G = !0, p(`正在安装预置包:${e.join(", ")}`);
2047
+ Vt = !0, m(`正在安装预置包:${e.join(", ")}`);
886
2048
  try {
887
- const n = await b.loadPackages(e, {
888
- onOutput: (l, d) => Q(l, d)
2049
+ const a = await D.loadPackages(e, {
2050
+ onOutput: (r, d) => fe(r, d)
889
2051
  });
890
- p(
891
- n.ok ? `预置包安装完成(${(n.durationMs / 1e3).toFixed(1)}s)` : `预置包安装失败:${((t = n.error) == null ? void 0 : t.message) ?? "未知错误"}`
2052
+ m(
2053
+ a.ok ? `预置包安装完成(${(a.durationMs / 1e3).toFixed(1)}s)` : `预置包安装失败:${((t = a.error) == null ? void 0 : t.message) ?? "未知错误"}`
892
2054
  );
893
- } catch (n) {
894
- p(`预置包安装失败:${n instanceof Error ? n.message : String(n)}`);
2055
+ } catch (a) {
2056
+ m(`预置包安装失败:${a instanceof Error ? a.message : String(a)}`);
895
2057
  }
896
2058
  }
897
2059
  }
898
- jt(() => {
899
- const e = P.value;
2060
+ is(() => {
2061
+ const e = w.value;
900
2062
  if (!e) return;
901
- lt(), J = !0;
2063
+ ir(), yt = !0;
902
2064
  const t = [
903
- Pe.of(i.theme === "dark" ? [Fe] : []),
904
- Ce.of([
905
- Se.readOnly.of(i.readOnly),
906
- K.editable.of(!i.readOnly)
2065
+ Qt.of(i.theme === "dark" ? [Nt] : []),
2066
+ Jt.of([
2067
+ _t.readOnly.of(i.readOnly),
2068
+ Oe.editable.of(!i.readOnly)
907
2069
  ]),
908
- ye.of(ve(y.value.language))
2070
+ kt.of(qt(b.value.language))
909
2071
  ];
910
2072
  try {
911
- o = mn(e, {
912
- value: y.value.code,
2073
+ E = Bs(e, {
2074
+ value: b.value.code,
913
2075
  dark: i.theme === "dark",
914
2076
  placeholderText: i.placeholder,
915
- language: me.of(we(y.value.language)),
2077
+ language: bt.of($t(b.value.language)),
916
2078
  extensions: t,
917
- onDocChange: (n) => {
918
- y.value.code = n, n !== i.modelValue && s("update:modelValue", n);
2079
+ onDocChange: (a) => {
2080
+ b.value.code = a, a !== i.modelValue && u("update:modelValue", a);
919
2081
  },
920
- onRunShortcut: Ie
2082
+ onRunShortcut: on
921
2083
  });
922
- } catch (n) {
923
- const l = n instanceof Error ? n.message : String(n);
924
- console.error("[princess-python-editor] 编辑器初始化失败", n), p(`编辑器初始化失败:${l}`), e.innerHTML = "";
2084
+ } catch (a) {
2085
+ const r = a instanceof Error ? a.message : String(a);
2086
+ console.error("[princess-python-editor] 编辑器初始化失败", a), m(`编辑器初始化失败:${r}`), e.innerHTML = "";
925
2087
  const d = document.createElement("div");
926
- d.className = "vpe-init-error", d.textContent = `编辑器初始化失败:${l}`, e.appendChild(d);
2088
+ d.className = "vpe-init-error", d.textContent = `编辑器初始化失败:${r}`, e.appendChild(d);
927
2089
  return;
928
2090
  }
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(
2091
+ i.autofocus && E.focus(), rt = D.on("status", (a, r) => {
2092
+ R.value = a, a === "ready" && (r && m(`Pyodide ${r} 就绪`), u("ready"), E && !i.disableLint && b.value.language === "python" && ws(E)), u("statusChange", a);
2093
+ }), st = D.on("initError", (a) => {
2094
+ m(`Pyodide 加载失败:${a}`), u("loadError", a);
2095
+ }), R.value = D.status, ie.value && ue(), typeof ResizeObserver < "u" && h.value && (Ne = new ResizeObserver(() => {
2096
+ k.value !== null && Pt(k.value);
2097
+ }), Ne.observe(h.value)), i.preloadPackages.length ? D.waitReady().then(() => Lr()).catch((a) => m(a.message)) : i.preload && D.waitReady().catch((a) => m(a.message));
2098
+ }), ls(() => {
2099
+ rt == null || rt(), st == null || st(), Ze(), Ne == null || Ne.disconnect(), Ne = null, oe == null || oe.abort(), oe = null, W == null || W.abort(), W = null, te == null || te.abort(), te = null, ne == null || ne.abort(), ne = null;
2100
+ for (const e of [...x.keys()])
2101
+ Ke(e, !1);
2102
+ window.clearTimeout(gt), window.clearTimeout(nt), Wt(), E == null || E.destroy(), E = null;
2103
+ }), G(
937
2104
  () => i.modelValue,
938
- () => ct()
939
- ), V(
2105
+ () => dr()
2106
+ ), G(
2107
+ () => i.outputHeight,
2108
+ () => {
2109
+ k.value = null;
2110
+ }
2111
+ ), G(
940
2112
  () => i.fileName,
941
2113
  (e) => {
942
- e && e !== y.value.name && (A.value = e);
2114
+ e && e !== b.value.name && (Pe.value = e);
943
2115
  }
944
- ), V(
2116
+ ), G(
945
2117
  () => i.language,
946
2118
  (e) => {
947
- e !== y.value.language && $e(e);
2119
+ e !== b.value.language && Et(e);
948
2120
  }
949
- ), V(
2121
+ ), G(
2122
+ () => i.runtime,
2123
+ (e) => {
2124
+ e !== j.value && (j.value = e);
2125
+ }
2126
+ ), G(
2127
+ () => i.pythonEndpoint,
2128
+ () => {
2129
+ if (!at.value) {
2130
+ for (const e of [...x.keys()])
2131
+ Ke(e, !1);
2132
+ j.value !== "browser" && (j.value = "browser", u("update:runtime", "browser"));
2133
+ }
2134
+ }
2135
+ ), G(
2136
+ () => i.filesEndpoint,
2137
+ () => {
2138
+ if (!we.value) {
2139
+ me.value = !1, je.value = [], Te.value = "";
2140
+ return;
2141
+ }
2142
+ me.value && Ae();
2143
+ }
2144
+ ), G(
950
2145
  () => i.theme,
951
2146
  (e) => {
952
- o == null || o.dispatch({ effects: Pe.reconfigure(e === "dark" ? [Fe] : []) });
2147
+ E == null || E.dispatch({ effects: Qt.reconfigure(e === "dark" ? [Nt] : []) });
953
2148
  }
954
- ), V(
2149
+ ), G(
955
2150
  () => i.readOnly,
956
2151
  (e) => {
957
- o == null || o.dispatch({
958
- effects: Ce.reconfigure([Se.readOnly.of(e), K.editable.of(!e)])
2152
+ E == null || E.dispatch({
2153
+ effects: Jt.reconfigure([_t.readOnly.of(e), Oe.editable.of(!e)])
959
2154
  });
960
2155
  }
961
- ), V(
962
- () => C.value.length,
2156
+ ), G(
2157
+ () => i.sqlConfig,
2158
+ (e) => {
2159
+ if (!e) return;
2160
+ const t = U(e);
2161
+ JSON.stringify(t) !== JSON.stringify(c.value) && (c.value = t), ie.value && ue();
2162
+ },
2163
+ { deep: !0 }
2164
+ ), G(ie, (e) => {
2165
+ e && ue();
2166
+ }), G(
2167
+ () => K.value.length,
963
2168
  async () => {
964
- await Ae();
965
- const e = w.value;
2169
+ await Cn();
2170
+ const e = _.value;
966
2171
  e && (e.scrollTop = e.scrollHeight);
967
2172
  }
968
- ), V([f, _], () => ut(), { deep: !0 });
969
- function Me() {
970
- Ie();
2173
+ ), G([L, he], () => lr(), { deep: !0 });
2174
+ function ln() {
2175
+ on();
971
2176
  }
972
- function Re() {
973
- M.value === "running" && (ne += 1, b.interrupt(), p("执行已中断"));
2177
+ function un() {
2178
+ var t;
2179
+ const e = b.value.id;
2180
+ if (xe.value) {
2181
+ Je(), !i.sqlExecutor && c.value.mode === "sqlite" && D.interrupt(), m("已取消连接测试");
2182
+ return;
2183
+ }
2184
+ if ((t = x.get(e)) != null && t.busy) {
2185
+ Ke(e);
2186
+ return;
2187
+ }
2188
+ if (ye.value && y.value === e) {
2189
+ dn();
2190
+ return;
2191
+ }
2192
+ R.value === "running" && y.value === e && cn();
2193
+ }
2194
+ function dn(e = !0) {
2195
+ const t = y.value;
2196
+ Qe += 1, ye.value = !1, y.value = null, oe == null || oe.abort(), oe = null, !i.sqlExecutor && c.value.mode === "sqlite" && D.interrupt(), e && m("执行已中断", t ?? void 0);
974
2197
  }
975
- function He() {
976
- C.value = [];
2198
+ function cn(e = !0) {
2199
+ const t = y.value;
2200
+ Be += 1, y.value = null, D.interrupt(), e && m("执行已中断", t ?? void 0);
2201
+ }
2202
+ function fn() {
2203
+ le().lines = [], le().sqlResults = [];
2204
+ }
2205
+ function pn() {
2206
+ var e;
2207
+ return ((e = C.value) == null ? void 0 : e.getBoundingClientRect().height) ?? 180;
2208
+ }
2209
+ function Tr() {
2210
+ var t;
2211
+ const e = ((t = h.value) == null ? void 0 : t.clientHeight) ?? 0;
2212
+ return Math.max(Dn, e ? e - 180 : 600);
977
2213
  }
978
- function ke() {
2214
+ function Pt(e) {
2215
+ k.value = Math.round(Math.max(Dn, Math.min(e, Tr())));
2216
+ }
2217
+ function $r(e) {
2218
+ e.button === 0 && (e.preventDefault(), T.value = !0, Kt = e.clientY, wt = pn(), k.value = Math.round(wt), document.body.style.cursor = "ns-resize", document.body.style.userSelect = "none", window.addEventListener("pointermove", vn), window.addEventListener("pointerup", Ze), window.addEventListener("pointercancel", Ze));
2219
+ }
2220
+ function vn(e) {
2221
+ T.value && Pt(wt + (Kt - e.clientY));
2222
+ }
2223
+ function Ze() {
2224
+ T.value && (T.value = !1, document.body.style.cursor = "", document.body.style.userSelect = "", window.removeEventListener("pointermove", vn), window.removeEventListener("pointerup", Ze), window.removeEventListener("pointercancel", Ze));
2225
+ }
2226
+ function Rr() {
2227
+ k.value = null;
2228
+ }
2229
+ function _r(e) {
2230
+ if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
2231
+ e.preventDefault();
2232
+ const t = k.value ?? pn();
2233
+ Pt(t + (e.key === "ArrowUp" ? 16 : -16));
2234
+ }
2235
+ function Mt() {
979
2236
  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));
2237
+ const e = b.value.language, t = Ie(Gt(e), e, "");
2238
+ L.value.push(t), Me(t.id), u("newFile", Ue(t));
982
2239
  }
983
- function q(e) {
984
- if (e === _.value) {
985
- ue();
2240
+ function Me(e) {
2241
+ if (e === he.value) {
2242
+ ut();
986
2243
  return;
987
2244
  }
988
- const t = f.value.find((n) => n.id === e);
989
- t && (_.value = e, Ne(t));
2245
+ const t = L.value.find((a) => a.id === e);
2246
+ t && (he.value = e, Ot(t));
990
2247
  }
991
- function Te(e) {
992
- if (f.value.length <= 1) return;
993
- const t = f.value.findIndex((d) => d.id === e);
2248
+ function Ir(e) {
2249
+ Ke(e, !1), ye.value && y.value === e && dn(!1), R.value === "running" && y.value === e && cn(!1);
2250
+ }
2251
+ function mn(e) {
2252
+ if (i.readOnly) return;
2253
+ const t = L.value.findIndex((d) => d.id === e);
994
2254
  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));
2255
+ Ir(e);
2256
+ const a = L.value.splice(t, 1)[0];
2257
+ if (!a) return;
2258
+ if (S.delete(e), u("fileClose", Ue(a)), !L.value.length) {
2259
+ const d = Ie(Gt(a.language), a.language, "");
2260
+ L.value.push(d), he.value = d.id, Ot(d), u("newFile", Ue(d));
2261
+ return;
2262
+ }
2263
+ if (e !== he.value) return;
2264
+ const r = L.value[Math.min(t, L.value.length - 1)];
2265
+ r && (he.value = r.id, Ot(r));
999
2266
  }
1000
- function Ne(e) {
1001
- ee(void 0), ge(e.code), o == null || o.dispatch({
2267
+ function Ot(e) {
2268
+ Se(void 0), ot(e.code), E == null || E.dispatch({
1002
2269
  effects: [
1003
- me.reconfigure(we(e.language)),
1004
- ye.reconfigure(ve(e.language))
2270
+ bt.reconfigure($t(e.language)),
2271
+ kt.reconfigure(qt(e.language))
1005
2272
  ]
1006
- }), s("update:fileName", e.name), s("update:language", e.language), s("fileSwitch", Y(e)), ue();
2273
+ }), u("update:fileName", e.name), u("update:language", e.language), u("fileSwitch", Ue(e)), ut();
1007
2274
  }
1008
- function je() {
1009
- i.readOnly || (ee(void 0), ge(""), ue());
2275
+ function yn() {
2276
+ i.readOnly || (Se(void 0), ot(""), ut());
1010
2277
  }
1011
- async function _e() {
1012
- var n;
1013
- const e = te();
2278
+ async function hn() {
2279
+ var a;
2280
+ const e = qe();
1014
2281
  let t = !1;
1015
2282
  try {
1016
- (n = navigator.clipboard) != null && n.writeText && (await navigator.clipboard.writeText(e), t = !0);
2283
+ (a = navigator.clipboard) != null && a.writeText && (await navigator.clipboard.writeText(e), t = !0);
1017
2284
  } catch {
1018
2285
  t = !1;
1019
2286
  }
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);
2287
+ return t || (t = Nr(e)), t ? (ce.value = !0, window.clearTimeout(gt), gt = window.setTimeout(() => {
2288
+ ce.value = !1;
2289
+ }, 1600), u("copy", e), !0) : (m("复制失败,请手动选择代码复制"), !1);
1023
2290
  }
1024
- function gt(e) {
2291
+ function Nr(e) {
1025
2292
  const t = document.createElement("textarea");
1026
2293
  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;
2294
+ let a = !1;
1028
2295
  try {
1029
- n = document.execCommand("copy");
2296
+ a = document.execCommand("copy");
1030
2297
  } catch {
1031
- n = !1;
2298
+ a = !1;
1032
2299
  }
1033
- return t.remove(), n;
2300
+ return t.remove(), a;
1034
2301
  }
1035
- function De() {
1036
- const e = y.value, t = Le(e.name, e.language);
1037
- A.value = t;
1038
- const n = new Blob([te()], {
2302
+ function gn() {
2303
+ const e = b.value, t = xt(e.name, e.language);
2304
+ Pe.value = t;
2305
+ const a = new Blob([qe()], {
1039
2306
  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;
2307
+ }), r = URL.createObjectURL(a), d = document.createElement("a");
2308
+ return d.href = r, d.download = t, d.style.display = "none", document.body.appendChild(d), d.click(), d.remove(), window.setTimeout(() => URL.revokeObjectURL(r), 1e3), u("download", t), t;
1042
2309
  }
1043
- function vt() {
1044
- D.value = !D.value, D.value && Ue();
2310
+ function Hr() {
2311
+ ge.value = !ge.value, ge.value && (me.value = !1, bn());
1045
2312
  }
1046
- async function Ue() {
2313
+ async function bn() {
1047
2314
  var e;
1048
- if (!N.value) {
1049
- N.value = !0;
2315
+ if (!De.value) {
2316
+ De.value = !0;
1050
2317
  try {
1051
- const t = await b.listFiles(".");
2318
+ const t = await D.listFiles(".");
1052
2319
  if (!t.ok) {
1053
- j.value = [], p(`读取虚拟文件失败:${((e = t.error) == null ? void 0 : e.message) ?? "未知错误"}`);
2320
+ ze.value = [], m(`读取虚拟文件失败:${((e = t.error) == null ? void 0 : e.message) ?? "未知错误"}`);
1054
2321
  return;
1055
2322
  }
1056
- j.value = t.entries ?? [];
2323
+ ze.value = t.entries ?? [];
1057
2324
  } catch (t) {
1058
- j.value = [], p(`读取虚拟文件失败:${t instanceof Error ? t.message : String(t)}`);
2325
+ ze.value = [], m(`读取虚拟文件失败:${t instanceof Error ? t.message : String(t)}`);
1059
2326
  } finally {
1060
- N.value = !1;
2327
+ De.value = !1;
1061
2328
  }
1062
2329
  }
1063
2330
  }
1064
- function kt(e) {
2331
+ function Ur(e) {
1065
2332
  switch (e.slice(e.lastIndexOf(".") + 1).toLowerCase()) {
1066
2333
  case "csv":
1067
2334
  return "text/csv";
@@ -1078,505 +2345,1085 @@ const wn = R(
1078
2345
  return "text/plain";
1079
2346
  }
1080
2347
  }
1081
- function bt(e) {
2348
+ function Ft(e) {
1082
2349
  return e < 1024 ? `${e} B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)} KB` : `${(e / 1024 / 1024).toFixed(1)} MB`;
1083
2350
  }
1084
- async function Ve(e) {
2351
+ async function kn(e) {
1085
2352
  var t;
1086
2353
  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;
2354
+ const a = await D.readFile(e);
2355
+ if (!a.ok || a.content === void 0)
2356
+ return m(`下载失败:${e}(${((t = a.error) == null ? void 0 : t.message) ?? "未知错误"})`), null;
2357
+ const r = e.slice(e.lastIndexOf("/") + 1) || "download.txt", d = new Blob([a.content], {
2358
+ type: `${Ur(r)};charset=utf-8`
2359
+ }), v = URL.createObjectURL(d), g = document.createElement("a");
2360
+ return g.href = v, g.download = r, g.style.display = "none", document.body.appendChild(g), g.click(), g.remove(), window.setTimeout(() => URL.revokeObjectURL(v), 1e3), u("fsDownload", { path: a.path ?? e, name: r }), m(`已下载虚拟文件:${r}`), r;
2361
+ } catch (a) {
2362
+ return m(`下载失败:${a instanceof Error ? a.message : String(a)}`), null;
1096
2363
  }
1097
2364
  }
1098
- function wt(e, t) {
1099
- return b.writeFile(e, t);
2365
+ function Br(e, t) {
2366
+ return D.writeFile(e, t);
2367
+ }
2368
+ function Ar(e) {
2369
+ return D.readFile(e);
2370
+ }
2371
+ function Dr(e = ".") {
2372
+ return D.listFiles(e);
2373
+ }
2374
+ function lt(e) {
2375
+ return e instanceof Error ? e.message : String(e);
2376
+ }
2377
+ function zr(e) {
2378
+ if (!e) return "";
2379
+ const t = new Date(e);
2380
+ return Number.isNaN(t.getTime()) ? e : `更新时间:${t.toLocaleString()}`;
2381
+ }
2382
+ function jr() {
2383
+ me.value = !me.value, me.value && (ge.value = !1, Ae());
2384
+ }
2385
+ async function Ae() {
2386
+ if (!we.value) return;
2387
+ ne == null || ne.abort();
2388
+ const e = new AbortController();
2389
+ ne = e, Xe.value = !0, Te.value = "";
2390
+ try {
2391
+ const t = await Ks(i.filesEndpoint, {
2392
+ headers: i.filesHeaders,
2393
+ signal: e.signal
2394
+ });
2395
+ if (ne !== e) return;
2396
+ je.value = t;
2397
+ } catch (t) {
2398
+ if (ne !== e) return;
2399
+ je.value = [], Te.value = lt(t);
2400
+ } finally {
2401
+ ne === e && (ne = null, Xe.value = !1);
2402
+ }
2403
+ }
2404
+ async function wn() {
2405
+ if (!we.value)
2406
+ return m("未配置文件服务端点(filesEndpoint)"), null;
2407
+ if (Z.value) return null;
2408
+ const e = b.value, t = xt(e.name, e.language);
2409
+ t !== e.name && (Pe.value = t), Z.value = !0;
2410
+ try {
2411
+ const a = await Zs(
2412
+ i.filesEndpoint,
2413
+ { name: t, content: qe() },
2414
+ { headers: i.filesHeaders }
2415
+ );
2416
+ return m(`已保存到服务端:${a.name}(${Ft(a.size)})`), me.value && await Ae(), a;
2417
+ } catch (a) {
2418
+ return m(`保存到服务端失败:${lt(a)}`), null;
2419
+ } finally {
2420
+ Z.value = !1;
2421
+ }
1100
2422
  }
1101
- function xt(e) {
1102
- return b.readFile(e);
2423
+ async function Vr(e) {
2424
+ if (!we.value || Z.value) return !1;
2425
+ Z.value = !0;
2426
+ try {
2427
+ const t = await Ws(i.filesEndpoint, e.id, {
2428
+ headers: i.filesHeaders
2429
+ }), a = Hn(t.name), r = Ie(Yt(t.name), a, t.content);
2430
+ return L.value.push(r), Me(r.id), m(`已从服务端打开文件:${t.name}`), u("fileOpen", { name: r.name, code: t.content, language: a }), !0;
2431
+ } catch (t) {
2432
+ return m(`打开服务端文件失败:${lt(t)}`), !1;
2433
+ } finally {
2434
+ Z.value = !1;
2435
+ }
1103
2436
  }
1104
- function St(e = ".") {
1105
- return b.listFiles(e);
2437
+ async function Qr(e) {
2438
+ if (!(!we.value || Z.value) && !(typeof window < "u" && !window.confirm(`确定删除服务端文件“${e.name}”?`))) {
2439
+ Z.value = !0;
2440
+ try {
2441
+ await Gs(i.filesEndpoint, e.id, { headers: i.filesHeaders }), m(`已删除服务端文件:${e.name}`), await Ae();
2442
+ } catch (t) {
2443
+ m(`删除服务端文件失败:${lt(t)}`);
2444
+ } finally {
2445
+ Z.value = !1;
2446
+ }
2447
+ }
1106
2448
  }
1107
- function Be() {
2449
+ function Sn() {
1108
2450
  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)`);
2451
+ (e = F.value) == null || e.click();
2452
+ }
2453
+ async function Jr(e) {
2454
+ var r;
2455
+ const t = e.target, a = (r = t.files) == null ? void 0 : r[0];
2456
+ if (t.value = "", !!a) {
2457
+ if (a.size > 2 * 1024 * 1024) {
2458
+ m(`文件过大:${(a.size / 1024 / 1024).toFixed(1)} MB(最多 2 MB)`);
1117
2459
  return;
1118
2460
  }
1119
2461
  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 });
2462
+ const d = await a.text(), v = Hn(a.name), g = Ie(Yt(a.name), v, d);
2463
+ L.value.push(g), Me(g.id), m(`已打开文件:${g.name}`), u("fileOpen", { name: g.name, code: d, language: v });
1122
2464
  } catch (d) {
1123
- const m = d instanceof Error ? d.message : String(d);
1124
- p(`读取文件失败:${m}`);
2465
+ const v = d instanceof Error ? d.message : String(d);
2466
+ m(`读取文件失败:${v}`);
1125
2467
  }
1126
2468
  }
1127
2469
  }
1128
- function Ft() {
1129
- A.value = Le(A.value, y.value.language);
2470
+ function Kr() {
2471
+ Pe.value = xt(Pe.value, b.value.language);
1130
2472
  }
1131
- function Pt(e) {
2473
+ function Zr(e) {
1132
2474
  e.key === "Enter" && (e.preventDefault(), e.target.blur());
1133
2475
  }
1134
- function Ct(e) {
1135
- $e(e.target.value);
2476
+ function Wr(e) {
2477
+ Et(e.target.value);
1136
2478
  }
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();
2479
+ async function qn(e) {
2480
+ var t, a;
2481
+ await Cn(), (a = (t = O.value) == null ? void 0 : t.querySelector(`[data-file-id="${e}"]`)) == null || a.focus();
1140
2482
  }
1141
- function Ot(e, t) {
2483
+ function Gr(e, t) {
1142
2484
  if (e.target !== e.currentTarget) return;
1143
2485
  if (e.key === "Enter" || e.key === " ") {
1144
- e.preventDefault(), q(t.id), ze(t.id);
2486
+ e.preventDefault(), Me(t.id), qn(t.id);
1145
2487
  return;
1146
2488
  }
1147
2489
  if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
1148
2490
  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));
2491
+ const a = L.value.findIndex((v) => v.id === t.id);
2492
+ if (a < 0) return;
2493
+ const r = e.key === "ArrowLeft" ? -1 : 1, d = L.value[(a + r + L.value.length) % L.value.length];
2494
+ d && (Me(d.id), qn(d.id));
1153
2495
  }
1154
- function ue() {
1155
- o == null || o.focus();
2496
+ function ut() {
2497
+ E == null || E.focus();
1156
2498
  }
1157
- async function $t(e) {
1158
- var n;
1159
- p(`正在安装:${e.join(", ")}`);
2499
+ async function Yr(e) {
2500
+ var a;
2501
+ m(`正在安装:${e.join(", ")}`);
1160
2502
  let t;
1161
2503
  try {
1162
- t = await b.loadPackages(e, {
1163
- onOutput: (l, d) => Q(l, d)
2504
+ t = await D.loadPackages(e, {
2505
+ onOutput: (r, d) => fe(r, d)
1164
2506
  });
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 } };
2507
+ } catch (r) {
2508
+ const d = r instanceof Error ? r.message : String(r);
2509
+ return m(`安装失败:${d}`), { ok: !1, durationMs: 0, error: { type: "RuntimeError", message: d } };
1168
2510
  }
1169
- return p(t.ok ? "安装完成" : `安装失败:${((n = t.error) == null ? void 0 : n.message) ?? "未知错误"}`), t;
1170
- }
1171
- function Lt() {
1172
- return b.checkSyntax(te());
1173
- }
1174
- function It() {
1175
- return o;
1176
- }
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)
1210
- }, [
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", {
1223
- key: 1,
1224
- class: "vpe-btn vpe-btn--stop",
1225
- type: "button",
1226
- title: "中断执行",
1227
- onClick: Re
1228
- }, [
1229
- $(S(xn)),
1230
- t[3] || (t[3] = c("span", null, "停止", -1))
1231
- ])),
1232
- t[6] || (t[6] = c("span", {
1233
- class: "vpe-divider",
1234
- "aria-hidden": "true"
1235
- }, null, -1)),
1236
- c("button", {
1237
- class: "vpe-btn",
1238
- type: "button",
1239
- title: "新建文件",
1240
- "aria-label": "新建文件",
1241
- disabled: u.readOnly,
1242
- onClick: ke
1243
- }, [
1244
- $(S(Sn))
1245
- ], 8, Ln),
1246
- c("button", {
1247
- class: "vpe-btn",
1248
- type: "button",
1249
- title: "打开本地文件",
1250
- "aria-label": "打开本地文件",
1251
- disabled: u.readOnly,
1252
- onClick: Be
1253
- }, [
1254
- $(S(En))
1255
- ], 8, In),
1256
- c("button", {
1257
- class: "vpe-btn",
1258
- type: "button",
1259
- title: "下载当前文件",
1260
- "aria-label": "下载当前文件",
1261
- onClick: De
1262
- }, [
1263
- $(S(Xe))
1264
- ]),
1265
- c("button", {
1266
- class: "vpe-btn",
1267
- type: "button",
1268
- title: "虚拟文件(下载 Python 生成的文件)",
1269
- "aria-label": "虚拟文件",
1270
- onClick: vt
1271
- }, [
1272
- $(S(Ge)),
1273
- t[4] || (t[4] = c("span", null, "虚拟文件", -1))
1274
- ]),
1275
- c("button", {
1276
- class: B(["vpe-btn", { "vpe-btn--copied": T.value }]),
1277
- type: "button",
1278
- title: T.value ? "已复制" : "复制代码",
1279
- "aria-label": T.value ? "已复制" : "复制代码",
1280
- onClick: _e
1281
- }, [
1282
- T.value ? (g(), We(S(Pn), { key: 0 })) : (g(), We(S(Fn), { key: 1 }))
1283
- ], 10, Mn),
1284
- c("button", {
1285
- class: "vpe-btn",
1286
- type: "button",
1287
- title: "清空当前文件",
1288
- "aria-label": "清空当前文件",
1289
- disabled: u.readOnly,
1290
- onClick: je
1291
- }, [
1292
- $(S(Ze))
1293
- ], 8, Rn),
1294
- t[7] || (t[7] = c("span", {
1295
- class: "vpe-divider",
1296
- "aria-hidden": "true"
1297
- }, null, -1)),
1298
- c("label", Hn, [
1299
- $(S(Ge)),
1300
- Dt(c("input", {
1301
- "onUpdate:modelValue": t[0] || (t[0] = (n) => A.value = n),
1302
- class: "vpe-file-input",
1303
- type: "text",
1304
- spellcheck: "false",
1305
- "aria-label": "文件名",
1306
- onBlur: Ft,
1307
- onKeydown: Pt
1308
- }, null, 544), [
1309
- [Ut, A.value]
1310
- ])
1311
- ]),
1312
- t[8] || (t[8] = c("span", {
1313
- class: "vpe-spacer",
1314
- "aria-hidden": "true"
1315
- }, null, -1)),
1316
- c("span", {
1317
- class: B(["vpe-status", `vpe-status--${M.value}`])
1318
- }, [
1319
- t[5] || (t[5] = c("span", {
1320
- class: "vpe-status-dot",
1321
- "aria-hidden": "true"
1322
- }, null, -1)),
1323
- c("span", null, W(it.value), 1)
1324
- ], 2),
1325
- c("select", {
1326
- class: "vpe-lang",
1327
- value: y.value.language,
1328
- title: "编辑器语言",
1329
- "aria-label": "编辑器语言",
1330
- disabled: u.readOnly,
1331
- onChange: Ct
1332
- }, [
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", {
1340
- key: 1,
1341
- ref_key: "tabsEl",
1342
- ref: I,
1343
- class: "vpe-tabs",
1344
- role: "tablist",
1345
- "aria-label": "文件"
2511
+ return m(t.ok ? "安装完成" : `安装失败:${((a = t.error) == null ? void 0 : a.message) ?? "未知错误"}`), t;
2512
+ }
2513
+ function Xr() {
2514
+ return D.checkSyntax(qe());
2515
+ }
2516
+ function es() {
2517
+ return U(c.value);
2518
+ }
2519
+ function ts() {
2520
+ return E;
2521
+ }
2522
+ function ns() {
2523
+ return L.value.map(Ue);
2524
+ }
2525
+ function rs() {
2526
+ return Ue(b.value);
2527
+ }
2528
+ return n({
2529
+ run: ln,
2530
+ stop: un,
2531
+ clearOutput: fn,
2532
+ clearCode: yn,
2533
+ newFile: Mt,
2534
+ switchFile: Me,
2535
+ closeFile: mn,
2536
+ copyCode: hn,
2537
+ download: gn,
2538
+ openFile: Sn,
2539
+ focus: ut,
2540
+ install: Yr,
2541
+ checkSyntax: Xr,
2542
+ executeSql: Cr,
2543
+ getSqlConfig: es,
2544
+ openSqlConfig: pr,
2545
+ closeSqlConfig: Xt,
2546
+ getEditorView: ts,
2547
+ getCode: qe,
2548
+ setCode: ot,
2549
+ getFiles: ns,
2550
+ getActiveFile: rs,
2551
+ writeFile: Br,
2552
+ readFile: Ar,
2553
+ listFiles: Dr,
2554
+ downloadFile: kn,
2555
+ saveToServer: wn,
2556
+ refreshServerFiles: Ae,
2557
+ clearPersistedState: ur
2558
+ }), (e, t) => {
2559
+ const a = us("a-space");
2560
+ return f(), p("div", {
2561
+ ref_key: "rootEl",
2562
+ ref: h,
2563
+ class: se(["vpe-root", { "vpe-dark": o.theme === "dark" }]),
2564
+ style: Pn(Yn.value)
1346
2565
  }, [
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 }]),
1350
- role: "tab",
1351
- 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)
1357
- }, [
1358
- c("span", {
1359
- class: B(["vpe-tab-dot", `vpe-tab-dot--${n.language}`]),
1360
- "aria-hidden": "true"
1361
- }, null, 2),
1362
- c("span", _n, W(n.name), 1),
1363
- f.value.length > 1 ? (g(), v("button", {
2566
+ o.showToolbar ? (f(), p("div", ka, [
2567
+ St.value ? (f(), p("button", {
2568
+ key: 1,
2569
+ class: "vpe-btn vpe-btn--stop",
2570
+ type: "button",
2571
+ title: "中断执行",
2572
+ onClick: un
2573
+ }, [
2574
+ B(N(ca)),
2575
+ t[19] || (t[19] = l("span", null, "停止", -1))
2576
+ ])) : (f(), p("button", {
1364
2577
  key: 0,
1365
- class: "vpe-tab-close",
2578
+ class: "vpe-btn vpe-btn--primary",
1366
2579
  type: "button",
1367
- title: `关闭 ${n.name}`,
1368
- "aria-label": `关闭 ${n.name}`,
1369
- disabled: u.readOnly,
1370
- onClick: Vt((l) => Te(n.id), ["stop"])
2580
+ title: nr.value,
2581
+ disabled: rr.value,
2582
+ onClick: ln
1371
2583
  }, [
1372
- $(S(Ye))
1373
- ], 8, Dn)) : z("", !0)
1374
- ], 42, jn))), 128)),
1375
- c("button", {
1376
- class: "vpe-tabs-add",
1377
- type: "button",
1378
- title: "新建文件",
1379
- "aria-label": "新建文件",
1380
- disabled: u.readOnly,
1381
- onClick: ke
1382
- }, [
1383
- $(S(Cn))
1384
- ], 8, Un)
1385
- ], 512)) : z("", !0),
1386
- c("input", {
1387
- ref_key: "fileInputEl",
1388
- ref: H,
1389
- class: "vpe-file-hidden",
1390
- type: "file",
1391
- accept: ".py,.pyw,.sql,.js,.mjs,.cjs,.jsx,.ts,.json,.txt,text/x-python,text/plain,application/json",
1392
- onChange: Et
1393
- }, null, 544),
1394
- c("div", {
1395
- ref_key: "editorEl",
1396
- ref: P,
1397
- class: "vpe-editor"
1398
- }, null, 512),
1399
- u.showOutput ? (g(), v("div", {
1400
- key: 2,
1401
- class: "vpe-output",
1402
- style: qe({ height: at.value })
1403
- }, [
1404
- c("div", Vn, [
1405
- t[9] || (t[9] = c("span", null, "输出", -1)),
1406
- c("button", {
1407
- class: "vpe-btn vpe-btn--sm",
2584
+ B(N(da)),
2585
+ t[18] || (t[18] = l("span", null, "运行", -1))
2586
+ ], 8, wa)),
2587
+ t[31] || (t[31] = l("span", {
2588
+ class: "vpe-divider",
2589
+ "aria-hidden": "true"
2590
+ }, null, -1)),
2591
+ l("button", {
2592
+ class: "vpe-btn",
1408
2593
  type: "button",
1409
- title: "清空输出",
1410
- onClick: He
2594
+ title: "新建文件",
2595
+ "aria-label": "新建文件",
2596
+ disabled: o.readOnly,
2597
+ onClick: Mt
1411
2598
  }, [
1412
- $(S(Ze))
1413
- ])
1414
- ]),
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", {
2599
+ B(N(fa)),
2600
+ t[20] || (t[20] = l("span", null, "新建", -1))
2601
+ ], 8, Sa),
2602
+ l("button", {
2603
+ class: "vpe-btn",
2604
+ type: "button",
2605
+ title: "打开本地文件",
2606
+ "aria-label": "打开本地文件",
2607
+ disabled: o.readOnly,
2608
+ onClick: Sn
2609
+ }, [
2610
+ B(N(pa)),
2611
+ t[21] || (t[21] = l("span", null, "本地文件", -1))
2612
+ ], 8, qa),
2613
+ l("button", {
2614
+ class: "vpe-btn",
2615
+ type: "button",
2616
+ title: "下载当前文件",
2617
+ "aria-label": "下载当前文件",
2618
+ onClick: gn
2619
+ }, [
2620
+ B(N(An)),
2621
+ t[22] || (t[22] = l("span", null, "下载", -1))
2622
+ ]),
2623
+ l("button", {
2624
+ class: "vpe-btn",
2625
+ type: "button",
2626
+ title: "虚拟文件(下载 Python 生成的文件)",
2627
+ "aria-label": "虚拟文件",
2628
+ onClick: Hr
2629
+ }, [
2630
+ B(N(Bn)),
2631
+ t[23] || (t[23] = l("span", null, "虚拟文件", -1))
2632
+ ]),
2633
+ we.value ? (f(), p("button", {
2634
+ key: 2,
2635
+ class: "vpe-btn",
2636
+ type: "button",
2637
+ title: Z.value ? "正在处理服务端文件…" : "保存当前文件到服务端",
2638
+ "aria-label": "保存到服务端",
2639
+ disabled: Z.value,
2640
+ onClick: wn
2641
+ }, [
2642
+ B(N(ga)),
2643
+ t[24] || (t[24] = l("span", null, "保存", -1))
2644
+ ], 8, Ea)) : M("", !0),
2645
+ we.value ? (f(), p("button", {
2646
+ key: 3,
2647
+ class: "vpe-btn",
2648
+ type: "button",
2649
+ title: "查询服务端已保存文件",
2650
+ "aria-label": "已保存文件",
2651
+ onClick: jr
2652
+ }, [
2653
+ B(N(ba)),
2654
+ t[25] || (t[25] = l("span", null, "已保存文件", -1))
2655
+ ])) : M("", !0),
2656
+ o.showSqlConfig && ie.value ? (f(), p("button", {
2657
+ key: 4,
2658
+ class: "vpe-btn",
2659
+ type: "button",
2660
+ title: "新建连接",
2661
+ "aria-label": "新建连接",
2662
+ onClick: mr
2663
+ }, [
2664
+ B(N(ha)),
2665
+ t[26] || (t[26] = l("span", null, "新建连接", -1))
2666
+ ])) : M("", !0),
2667
+ l("button", {
2668
+ class: se(["vpe-btn", { "vpe-btn--copied": ce.value }]),
2669
+ type: "button",
2670
+ title: ce.value ? "已复制" : "复制代码",
2671
+ "aria-label": ce.value ? "已复制" : "复制代码",
2672
+ onClick: hn
2673
+ }, [
2674
+ ce.value ? (f(), Mn(N(ma), { key: 0 })) : (f(), Mn(N(va), { key: 1 })),
2675
+ ce.value ? (f(), p("span", Ca, "已复制")) : (f(), p("span", Pa, "复制"))
2676
+ ], 10, xa),
2677
+ l("button", {
2678
+ class: "vpe-btn",
2679
+ type: "button",
2680
+ title: "清空当前文件",
2681
+ "aria-label": "清空当前文件",
2682
+ disabled: o.readOnly,
2683
+ onClick: yn
2684
+ }, [
2685
+ B(N(Un)),
2686
+ t[27] || (t[27] = l("span", null, "清空", -1))
2687
+ ], 8, Ma),
2688
+ t[32] || (t[32] = l("span", {
2689
+ class: "vpe-divider",
2690
+ "aria-hidden": "true"
2691
+ }, null, -1)),
2692
+ l("label", Oa, [
2693
+ B(N(Bn)),
2694
+ Q(l("input", {
2695
+ "onUpdate:modelValue": t[0] || (t[0] = (r) => Pe.value = r),
2696
+ class: "vpe-file-input",
2697
+ type: "text",
2698
+ spellcheck: "false",
2699
+ "aria-label": "文件名",
2700
+ onBlur: Kr,
2701
+ onKeydown: Zr
2702
+ }, null, 544), [
2703
+ [ve, Pe.value]
2704
+ ])
2705
+ ]),
2706
+ t[33] || (t[33] = l("span", {
1431
2707
  class: "vpe-spacer",
1432
2708
  "aria-hidden": "true"
1433
2709
  }, null, -1)),
1434
- c("button", {
1435
- class: "vpe-btn vpe-btn--sm",
1436
- type: "button",
1437
- title: "刷新文件列表",
1438
- disabled: N.value,
1439
- onClick: Ue
1440
- }, " 刷新 ", 8, An),
1441
- c("button", {
1442
- class: "vpe-btn vpe-btn--sm",
2710
+ o.showSqlConfig && ie.value && (c.value.mode === "http" || c.value.endpoint) ? (f(), p(A, { key: 5 }, [
2711
+ Q(l("select", {
2712
+ "onUpdate:modelValue": t[1] || (t[1] = (r) => c.value.connectionId = r),
2713
+ class: "vpe-lang vpe-sql-connection",
2714
+ title: "切换已保存连接",
2715
+ "aria-label": "切换已保存连接",
2716
+ disabled: $e.value,
2717
+ onChange: gr
2718
+ }, [
2719
+ l("option", La, $($e.value ? "加载中…" : be.value.length ? "选择连接" : "暂无已保存连接"), 1),
2720
+ (f(!0), p(A, null, ae(be.value, (r) => (f(), p("option", {
2721
+ key: r.id,
2722
+ value: r.id
2723
+ }, $(r.name), 9, Ta))), 128))
2724
+ ], 40, Fa), [
2725
+ [dt, c.value.connectionId]
2726
+ ]),
2727
+ l("button", {
2728
+ class: "vpe-btn vpe-btn--sm",
2729
+ type: "button",
2730
+ title: "管理连接配置",
2731
+ "aria-label": "管理连接配置",
2732
+ onClick: vr
2733
+ }, " 管理 ")
2734
+ ], 64)) : M("", !0),
2735
+ B(a, null, {
2736
+ default: ds(() => [
2737
+ t[29] || (t[29] = l("span", null, "运行环境:", -1)),
2738
+ at.value && Zt.value ? Q((f(), p("select", {
2739
+ key: 0,
2740
+ "onUpdate:modelValue": t[2] || (t[2] = (r) => j.value = r),
2741
+ class: "vpe-lang vpe-runtime",
2742
+ title: "Python 运行环境",
2743
+ "aria-label": "Python 运行环境",
2744
+ onChange: Pr
2745
+ }, [...t[28] || (t[28] = [
2746
+ l("option", { value: "browser" }, "浏览器", -1),
2747
+ l("option", { value: "server" }, "服务端", -1)
2748
+ ])], 544)), [
2749
+ [dt, j.value]
2750
+ ]) : M("", !0)
2751
+ ]),
2752
+ _: 1
2753
+ }),
2754
+ l("span", {
2755
+ class: se(["vpe-status", `vpe-status--${tr.value}`])
2756
+ }, [
2757
+ t[30] || (t[30] = l("span", {
2758
+ class: "vpe-status-dot",
2759
+ "aria-hidden": "true"
2760
+ }, null, -1)),
2761
+ l("span", null, $(er.value), 1)
2762
+ ], 2),
2763
+ l("select", {
2764
+ class: "vpe-lang",
2765
+ value: b.value.language,
2766
+ title: "编辑器语言",
2767
+ "aria-label": "编辑器语言",
2768
+ disabled: o.readOnly,
2769
+ onChange: Wr
2770
+ }, [
2771
+ (f(!0), p(A, null, ae(N(vt), (r) => (f(), p("option", {
2772
+ key: r.value,
2773
+ value: r.value
2774
+ }, $(r.label), 9, Ra))), 128))
2775
+ ], 40, $a)
2776
+ ])) : M("", !0),
2777
+ o.showTabs ? (f(), p("div", {
2778
+ key: 1,
2779
+ ref_key: "tabsEl",
2780
+ ref: O,
2781
+ class: "vpe-tabs",
2782
+ role: "tablist",
2783
+ "aria-label": "文件"
2784
+ }, [
2785
+ (f(!0), p(A, null, ae(L.value, (r) => (f(), p("div", {
2786
+ key: r.id,
2787
+ class: se(["vpe-tab", { "vpe-tab--active": r.id === b.value.id }]),
2788
+ role: "tab",
2789
+ tabindex: "0",
2790
+ "aria-selected": r.id === b.value.id,
2791
+ "data-file-id": r.id,
2792
+ title: r.name,
2793
+ onClick: (d) => Me(r.id),
2794
+ onKeydown: (d) => Gr(d, r)
2795
+ }, [
2796
+ l("span", {
2797
+ class: se(["vpe-tab-dot", `vpe-tab-dot--${r.language}`]),
2798
+ "aria-hidden": "true"
2799
+ }, null, 2),
2800
+ l("span", Ia, $(r.name), 1),
2801
+ l("button", {
2802
+ class: "vpe-tab-close",
2803
+ type: "button",
2804
+ title: `关闭 ${r.name}`,
2805
+ "aria-label": `关闭 ${r.name}`,
2806
+ disabled: o.readOnly,
2807
+ onClick: On((d) => mn(r.id), ["stop"])
2808
+ }, [
2809
+ B(N(Ge))
2810
+ ], 8, Na)
2811
+ ], 42, _a))), 128)),
2812
+ l("button", {
2813
+ class: "vpe-tabs-add",
1443
2814
  type: "button",
1444
- title: "关闭虚拟文件面板",
1445
- "aria-label": "关闭虚拟文件面板",
1446
- onClick: t[1] || (t[1] = (n) => D.value = !1)
2815
+ title: "新建文件",
2816
+ "aria-label": "新建文件",
2817
+ disabled: o.readOnly,
2818
+ onClick: Mt
1447
2819
  }, [
1448
- $(S(Ye))
2820
+ B(N(ya))
2821
+ ], 8, Ha)
2822
+ ], 512)) : M("", !0),
2823
+ l("input", {
2824
+ ref_key: "fileInputEl",
2825
+ ref: F,
2826
+ class: "vpe-file-hidden",
2827
+ type: "file",
2828
+ accept: ".py,.pyw,.sql,.js,.mjs,.cjs,.jsx,.ts,.json,.txt,text/x-python,text/plain,application/json",
2829
+ onChange: Jr
2830
+ }, null, 544),
2831
+ l("div", {
2832
+ ref_key: "editorEl",
2833
+ ref: w,
2834
+ class: "vpe-editor"
2835
+ }, null, 512),
2836
+ o.showOutput ? (f(), p("div", {
2837
+ key: 2,
2838
+ class: se(["vpe-output-resizer", { "vpe-output-resizer--active": T.value }]),
2839
+ role: "separator",
2840
+ "aria-orientation": "horizontal",
2841
+ "aria-label": "调整输出面板高度",
2842
+ title: "拖动调整输出高度,双击复位",
2843
+ tabindex: "0",
2844
+ onPointerdown: $r,
2845
+ onDblclick: Rr,
2846
+ onKeydown: _r
2847
+ }, null, 34)) : M("", !0),
2848
+ o.showOutput ? (f(), p("div", {
2849
+ key: 3,
2850
+ ref_key: "outputPanelEl",
2851
+ ref: C,
2852
+ class: "vpe-output",
2853
+ style: Pn({ height: Xn.value })
2854
+ }, [
2855
+ l("div", Ua, [
2856
+ t[34] || (t[34] = l("span", null, "输出", -1)),
2857
+ l("button", {
2858
+ class: "vpe-btn vpe-btn--sm",
2859
+ type: "button",
2860
+ title: "清空输出",
2861
+ onClick: fn
2862
+ }, [
2863
+ B(N(Un))
2864
+ ])
2865
+ ]),
2866
+ l("div", Ba, [
2867
+ de.value.length ? (f(), p("div", Aa, [
2868
+ (f(!0), p(A, null, ae(de.value, (r, d) => (f(), p("section", {
2869
+ key: d,
2870
+ class: "vpe-sql-result"
2871
+ }, [
2872
+ l("div", Da, [
2873
+ l("span", null, "结果 " + $(d + 1), 1),
2874
+ l("span", null, $(xr(r)), 1)
2875
+ ]),
2876
+ r.columns.length ? (f(), p("div", za, [
2877
+ l("table", ja, [
2878
+ l("thead", null, [
2879
+ l("tr", null, [
2880
+ (f(!0), p(A, null, ae(r.columns, (v, g) => (f(), p("th", { key: g }, $(v), 1))), 128))
2881
+ ])
2882
+ ]),
2883
+ l("tbody", null, [
2884
+ (f(!0), p(A, null, ae(r.rows, (v, g) => (f(), p("tr", { key: g }, [
2885
+ (f(!0), p(A, null, ae(v, (P, V) => (f(), p("td", {
2886
+ key: V,
2887
+ class: se({ "vpe-sql-null": P === null })
2888
+ }, $(Er(P)), 3))), 128))
2889
+ ]))), 128))
2890
+ ])
2891
+ ]),
2892
+ r.rows.length ? M("", !0) : (f(), p("div", Va, "查询无数据"))
2893
+ ])) : (f(), p("div", Qa, "影响 " + $(r.affectedRows ?? 0) + " 行", 1))
2894
+ ]))), 128))
2895
+ ])) : M("", !0),
2896
+ l("pre", {
2897
+ ref_key: "outputEl",
2898
+ ref: _,
2899
+ class: "vpe-output-body"
2900
+ }, [
2901
+ K.value.length ? (f(!0), p(A, { key: 0 }, ae(K.value, (r) => (f(), p("span", {
2902
+ key: r.id,
2903
+ class: se(["vpe-line", `vpe-line--${r.stream}`])
2904
+ }, $(r.text) + `
2905
+ `, 3))), 128)) : (f(), p("span", Ja, "暂无输出,点击“运行”或按 Ctrl+Enter 执行代码"))
2906
+ ], 512)
2907
+ ]),
2908
+ He.value && Le.value && St.value ? (f(), p("div", Ka, [
2909
+ t[35] || (t[35] = l("span", {
2910
+ class: "vpe-terminal-prompt",
2911
+ "aria-hidden": "true"
2912
+ }, "›", -1)),
2913
+ Q(l("input", {
2914
+ "onUpdate:modelValue": t[3] || (t[3] = (r) => I.value = r),
2915
+ class: "vpe-terminal-field",
2916
+ type: "text",
2917
+ spellcheck: "false",
2918
+ placeholder: "输入后按 Enter 发送给 input()",
2919
+ "aria-label": "标准输入",
2920
+ onKeydown: cs(On(an, ["prevent"]), ["enter"])
2921
+ }, null, 40, Za), [
2922
+ [ve, I.value]
2923
+ ]),
2924
+ l("button", {
2925
+ class: "vpe-btn vpe-btn--sm",
2926
+ type: "button",
2927
+ onClick: an
2928
+ }, " 发送 ")
2929
+ ])) : M("", !0)
2930
+ ], 4)) : M("", !0),
2931
+ ge.value ? (f(), p("div", Wa, [
2932
+ l("div", Ga, [
2933
+ t[36] || (t[36] = l("span", { class: "vpe-fs-title" }, "虚拟文件", -1)),
2934
+ t[37] || (t[37] = l("span", {
2935
+ class: "vpe-spacer",
2936
+ "aria-hidden": "true"
2937
+ }, null, -1)),
2938
+ l("button", {
2939
+ class: "vpe-btn vpe-btn--sm",
2940
+ type: "button",
2941
+ title: "刷新文件列表",
2942
+ disabled: De.value,
2943
+ onClick: bn
2944
+ }, " 刷新 ", 8, Ya),
2945
+ l("button", {
2946
+ class: "vpe-btn vpe-btn--sm",
2947
+ type: "button",
2948
+ title: "关闭虚拟文件面板",
2949
+ "aria-label": "关闭虚拟文件面板",
2950
+ onClick: t[4] || (t[4] = (r) => ge.value = !1)
2951
+ }, [
2952
+ B(N(Ge))
2953
+ ])
2954
+ ]),
2955
+ l("div", Xa, [
2956
+ De.value ? (f(), p("div", eo, "正在读取虚拟文件…")) : (f(), p(A, { key: 1 }, [
2957
+ ze.value.length ? M("", !0) : (f(), p("div", to, " 暂无文件。运行 Python 代码创建文件后再刷新。 ")),
2958
+ (f(!0), p(A, null, ae(ze.value, (r) => (f(), p("div", {
2959
+ key: r.path,
2960
+ class: se(["vpe-fs-item", { "vpe-fs-item--dir": r.isDirectory }])
2961
+ }, [
2962
+ l("span", {
2963
+ class: "vpe-fs-name",
2964
+ title: r.path
2965
+ }, $(r.path), 9, no),
2966
+ l("span", ro, $(r.isDirectory ? "目录" : Ft(r.size)), 1),
2967
+ r.isDirectory ? M("", !0) : (f(), p("button", {
2968
+ key: 0,
2969
+ class: "vpe-btn vpe-btn--sm",
2970
+ type: "button",
2971
+ title: `下载 ${r.name}`,
2972
+ "aria-label": `下载 ${r.name}`,
2973
+ onClick: (d) => kn(r.path)
2974
+ }, [
2975
+ B(N(An))
2976
+ ], 8, so))
2977
+ ], 2))), 128))
2978
+ ], 64))
1449
2979
  ])
1450
- ]),
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 }])
2980
+ ])) : M("", !0),
2981
+ me.value && we.value ? (f(), p("div", ao, [
2982
+ l("div", oo, [
2983
+ t[38] || (t[38] = l("span", { class: "vpe-fs-title" }, "服务端文件", -1)),
2984
+ t[39] || (t[39] = l("span", {
2985
+ class: "vpe-spacer",
2986
+ "aria-hidden": "true"
2987
+ }, null, -1)),
2988
+ l("button", {
2989
+ class: "vpe-btn vpe-btn--sm",
2990
+ type: "button",
2991
+ title: "刷新文件列表",
2992
+ disabled: Xe.value,
2993
+ onClick: t[5] || (t[5] = (r) => Ae())
2994
+ }, " 刷新 ", 8, io),
2995
+ l("button", {
2996
+ class: "vpe-btn vpe-btn--sm",
2997
+ type: "button",
2998
+ title: "关闭服务端文件面板",
2999
+ "aria-label": "关闭服务端文件面板",
3000
+ onClick: t[6] || (t[6] = (r) => me.value = !1)
3001
+ }, [
3002
+ B(N(Ge))
3003
+ ])
3004
+ ]),
3005
+ l("div", lo, [
3006
+ Xe.value ? (f(), p("div", uo, "正在读取服务端文件…")) : (f(), p(A, { key: 1 }, [
3007
+ !je.value.length && !Te.value ? (f(), p("div", co, " 暂无已保存文件。点击工具栏“保存”按钮把当前文件保存到服务端。 ")) : M("", !0),
3008
+ (f(!0), p(A, null, ae(je.value, (r) => (f(), p("div", {
3009
+ key: r.id,
3010
+ class: "vpe-fs-item"
3011
+ }, [
3012
+ l("span", {
3013
+ class: "vpe-fs-name",
3014
+ title: r.name
3015
+ }, $(r.name), 9, fo),
3016
+ l("span", {
3017
+ class: "vpe-fs-size",
3018
+ title: zr(r.updatedAt)
3019
+ }, $(Ft(r.size)), 9, po),
3020
+ l("button", {
3021
+ class: "vpe-btn vpe-btn--sm",
3022
+ type: "button",
3023
+ title: `打开 ${r.name}`,
3024
+ disabled: Z.value,
3025
+ onClick: (d) => Vr(r)
3026
+ }, " 打开 ", 8, vo),
3027
+ l("button", {
3028
+ class: "vpe-btn vpe-btn--sm",
3029
+ type: "button",
3030
+ title: `删除 ${r.name}`,
3031
+ disabled: Z.value,
3032
+ onClick: (d) => Qr(r)
3033
+ }, " 删除 ", 8, mo)
3034
+ ]))), 128)),
3035
+ Te.value ? (f(), p("p", yo, $(Te.value), 1)) : M("", !0)
3036
+ ], 64))
3037
+ ])
3038
+ ])) : M("", !0),
3039
+ Ee.value && ie.value ? (f(), p("div", ho, [
3040
+ l("div", go, [
3041
+ l("span", bo, $(sr.value), 1),
3042
+ t[40] || (t[40] = l("span", {
3043
+ class: "vpe-spacer",
3044
+ "aria-hidden": "true"
3045
+ }, null, -1)),
3046
+ l("button", {
3047
+ class: "vpe-btn vpe-btn--sm",
3048
+ type: "button",
3049
+ title: "关闭 SQL 连接配置",
3050
+ "aria-label": "关闭 SQL 连接配置",
3051
+ onClick: Xt
1457
3052
  }, [
1458
- c("span", {
1459
- 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", {
3053
+ B(N(Ge))
3054
+ ])
3055
+ ]),
3056
+ l("div", ko, [
3057
+ l("label", wo, [
3058
+ t[42] || (t[42] = l("span", { class: "vpe-sql-label" }, "执行方式", -1)),
3059
+ Q(l("select", {
3060
+ "onUpdate:modelValue": t[7] || (t[7] = (r) => c.value.mode = r),
3061
+ class: "vpe-sql-input",
3062
+ onChange: yr
3063
+ }, [...t[41] || (t[41] = [
3064
+ l("option", { value: "sqlite" }, "浏览器内 SQLite(无需服务端)", -1),
3065
+ l("option", { value: "http" }, "HTTP 服务(后端网关)", -1)
3066
+ ])], 544), [
3067
+ [dt, c.value.mode]
3068
+ ])
3069
+ ]),
3070
+ c.value.mode === "sqlite" ? (f(), p(A, { key: 0 }, [
3071
+ l("label", So, [
3072
+ t[43] || (t[43] = l("span", { class: "vpe-sql-label" }, "数据库文件", -1)),
3073
+ Q(l("input", {
3074
+ "onUpdate:modelValue": t[8] || (t[8] = (r) => c.value.connection.database = r),
3075
+ class: "vpe-sql-input",
3076
+ type: "text",
3077
+ spellcheck: "false",
3078
+ placeholder: ":memory:",
3079
+ onChange: pe
3080
+ }, null, 544), [
3081
+ [ve, c.value.connection.database]
3082
+ ])
3083
+ ]),
3084
+ t[44] || (t[44] = l("p", { class: "vpe-sql-hint" }, " SQLite 在浏览器内运行,数据仅保存在当前页面内存;“停止”或刷新后会丢失。 ", -1))
3085
+ ], 64)) : (f(), p(A, { key: 1 }, [
3086
+ l("label", qo, [
3087
+ t[45] || (t[45] = l("span", { class: "vpe-sql-label" }, "连接名称", -1)),
3088
+ Q(l("input", {
3089
+ "onUpdate:modelValue": t[9] || (t[9] = (r) => Y.value = r),
3090
+ class: "vpe-sql-input",
3091
+ type: "text",
3092
+ spellcheck: "false",
3093
+ placeholder: "用于保存和切换连接"
3094
+ }, null, 512), [
3095
+ [ve, Y.value]
3096
+ ])
3097
+ ]),
3098
+ l("label", Eo, [
3099
+ t[46] || (t[46] = l("span", { class: "vpe-sql-label" }, "数据库类型", -1)),
3100
+ Q(l("select", {
3101
+ "onUpdate:modelValue": t[10] || (t[10] = (r) => c.value.connection.dialect = r),
3102
+ class: "vpe-sql-input",
3103
+ onChange: hr
3104
+ }, [
3105
+ (f(!0), p(A, null, ae(N(Ye), (r) => (f(), p("option", {
3106
+ key: r.value,
3107
+ value: r.value
3108
+ }, $(r.label), 9, xo))), 128))
3109
+ ], 544), [
3110
+ [dt, c.value.connection.dialect]
3111
+ ])
3112
+ ]),
3113
+ l("div", Co, [
3114
+ l("label", Po, [
3115
+ t[47] || (t[47] = l("span", { class: "vpe-sql-label" }, "主机", -1)),
3116
+ Q(l("input", {
3117
+ "onUpdate:modelValue": t[11] || (t[11] = (r) => c.value.connection.host = r),
3118
+ class: "vpe-sql-input",
3119
+ type: "text",
3120
+ spellcheck: "false",
3121
+ placeholder: "127.0.0.1",
3122
+ onChange: pe
3123
+ }, null, 544), [
3124
+ [ve, c.value.connection.host]
3125
+ ])
3126
+ ]),
3127
+ l("label", Mo, [
3128
+ t[48] || (t[48] = l("span", { class: "vpe-sql-label" }, "端口", -1)),
3129
+ Q(l("input", {
3130
+ "onUpdate:modelValue": t[12] || (t[12] = (r) => c.value.connection.port = r),
3131
+ class: "vpe-sql-input",
3132
+ type: "number",
3133
+ min: "1",
3134
+ max: "65535",
3135
+ placeholder: "3306",
3136
+ onChange: pe
3137
+ }, null, 544), [
3138
+ [
3139
+ ve,
3140
+ c.value.connection.port,
3141
+ void 0,
3142
+ { number: !0 }
3143
+ ]
3144
+ ])
3145
+ ])
3146
+ ]),
3147
+ l("div", Oo, [
3148
+ l("label", Fo, [
3149
+ t[49] || (t[49] = l("span", { class: "vpe-sql-label" }, "用户名", -1)),
3150
+ Q(l("input", {
3151
+ "onUpdate:modelValue": t[13] || (t[13] = (r) => c.value.connection.user = r),
3152
+ class: "vpe-sql-input",
3153
+ type: "text",
3154
+ autocomplete: "off",
3155
+ spellcheck: "false",
3156
+ onChange: pe
3157
+ }, null, 544), [
3158
+ [ve, c.value.connection.user]
3159
+ ])
3160
+ ]),
3161
+ l("label", Lo, [
3162
+ t[50] || (t[50] = l("span", { class: "vpe-sql-label" }, "密码", -1)),
3163
+ Q(l("input", {
3164
+ "onUpdate:modelValue": t[14] || (t[14] = (r) => c.value.connection.password = r),
3165
+ class: "vpe-sql-input",
3166
+ type: "password",
3167
+ autocomplete: "new-password",
3168
+ placeholder: c.value.connectionId ? "已保存(留空不修改)" : "",
3169
+ onChange: pe
3170
+ }, null, 40, To), [
3171
+ [ve, c.value.connection.password]
3172
+ ])
3173
+ ])
3174
+ ]),
3175
+ l("label", $o, [
3176
+ t[51] || (t[51] = l("span", { class: "vpe-sql-label" }, "数据库名", -1)),
3177
+ Q(l("input", {
3178
+ "onUpdate:modelValue": t[15] || (t[15] = (r) => c.value.connection.database = r),
3179
+ class: "vpe-sql-input",
3180
+ type: "text",
3181
+ spellcheck: "false",
3182
+ placeholder: "database",
3183
+ onChange: pe
3184
+ }, null, 544), [
3185
+ [ve, c.value.connection.database]
3186
+ ])
3187
+ ]),
3188
+ o.sqlEndpointLocked ? M("", !0) : (f(), p("label", Ro, [
3189
+ t[52] || (t[52] = l("span", { class: "vpe-sql-label" }, "服务端点", -1)),
3190
+ Q(l("input", {
3191
+ "onUpdate:modelValue": t[16] || (t[16] = (r) => c.value.endpoint = r),
3192
+ class: "vpe-sql-input",
3193
+ type: "url",
3194
+ spellcheck: "false",
3195
+ placeholder: "https://example.com/api/sql",
3196
+ onChange: pe
3197
+ }, null, 544), [
3198
+ [ve, c.value.endpoint]
3199
+ ])
3200
+ ])),
3201
+ o.sqlEndpointLocked ? (f(), p("p", _o, "服务端点由系统预置,无需填写。")) : M("", !0),
3202
+ t[53] || (t[53] = l("p", { class: "vpe-sql-hint" }, " 执行时会把连接信息与 SQL POST 到该端点,由后端网关连接真实数据库。建议使用 HTTPS,并避免在前端配置高权限账号。 ", -1))
3203
+ ], 64)),
3204
+ l("div", Io, [
3205
+ l("button", {
3206
+ class: "vpe-btn vpe-btn--primary",
3207
+ type: "button",
3208
+ disabled: xe.value,
3209
+ onClick: qr
3210
+ }, $(xe.value ? "测试中…" : "测试连接"), 9, No),
3211
+ c.value.mode === "http" ? (f(), p("button", {
1464
3212
  key: 0,
1465
- class: "vpe-btn vpe-btn--sm",
3213
+ class: "vpe-btn",
3214
+ type: "button",
3215
+ disabled: X.value,
3216
+ onClick: kr
3217
+ }, " 保存 ", 8, Ho)) : M("", !0),
3218
+ c.value.mode === "http" && c.value.connectionId ? (f(), p("button", {
3219
+ key: 1,
3220
+ class: "vpe-btn",
1466
3221
  type: "button",
1467
- title: `下载 ${n.name}`,
1468
- "aria-label": `下载 ${n.name}`,
1469
- onClick: (l) => Ve(n.path)
3222
+ disabled: X.value,
3223
+ onClick: wr
3224
+ }, " 删除 ", 8, Uo)) : M("", !0),
3225
+ Ve.value ? (f(), p("span", {
3226
+ key: 2,
3227
+ class: se(["vpe-sql-test", et.value ? "vpe-sql-test--ok" : "vpe-sql-test--err"])
3228
+ }, $(Ve.value), 3)) : M("", !0),
3229
+ c.value.mode === "http" && ke.value ? (f(), p("span", Bo, $(ke.value), 1)) : M("", !0),
3230
+ c.value.mode === "http" && ee.value ? (f(), p("span", {
3231
+ key: 4,
3232
+ class: se(["vpe-sql-test", Re.value ? "vpe-sql-test--ok" : "vpe-sql-test--err"])
3233
+ }, $(ee.value), 3)) : M("", !0)
3234
+ ])
3235
+ ])
3236
+ ])) : M("", !0),
3237
+ Ce.value && ie.value ? (f(), p("div", Ao, [
3238
+ l("div", Do, [
3239
+ t[54] || (t[54] = l("span", { class: "vpe-fs-title" }, "连接管理", -1)),
3240
+ t[55] || (t[55] = l("span", {
3241
+ class: "vpe-spacer",
3242
+ "aria-hidden": "true"
3243
+ }, null, -1)),
3244
+ l("button", {
3245
+ class: "vpe-btn vpe-btn--sm",
3246
+ type: "button",
3247
+ title: "刷新连接列表",
3248
+ disabled: $e.value,
3249
+ onClick: ue
3250
+ }, " 刷新 ", 8, zo),
3251
+ l("button", {
3252
+ class: "vpe-btn vpe-btn--sm",
3253
+ type: "button",
3254
+ title: "关闭连接管理",
3255
+ "aria-label": "关闭连接管理",
3256
+ onClick: t[17] || (t[17] = (r) => Ce.value = !1)
3257
+ }, [
3258
+ B(N(Ge))
3259
+ ])
3260
+ ]),
3261
+ l("div", jo, [
3262
+ $e.value ? (f(), p("div", Vo, "正在读取连接…")) : (f(), p(A, { key: 1 }, [
3263
+ be.value.length ? M("", !0) : (f(), p("div", Qo, " 暂无已保存连接,点击工具栏“新建连接”创建。 ")),
3264
+ (f(!0), p(A, null, ae(be.value, (r) => (f(), p("div", {
3265
+ key: r.id,
3266
+ class: "vpe-sql-manager-item"
1470
3267
  }, [
1471
- $(S(Xe))
1472
- ], 8, Xn))
1473
- ], 2))), 128))
1474
- ], 64))
1475
- ])
1476
- ])) : z("", !0)
1477
- ], 6));
3268
+ l("div", Jo, [
3269
+ l("span", {
3270
+ class: "vpe-sql-manager-name",
3271
+ title: r.name
3272
+ }, $(r.name), 9, Ko),
3273
+ l("span", Zo, [
3274
+ Lt($(r.dialect), 1),
3275
+ r.database ? (f(), p(A, { key: 0 }, [
3276
+ Lt(" · " + $(r.database), 1)
3277
+ ], 64)) : M("", !0),
3278
+ r.host ? (f(), p(A, { key: 1 }, [
3279
+ Lt(" · " + $(r.host), 1)
3280
+ ], 64)) : M("", !0)
3281
+ ])
3282
+ ]),
3283
+ l("button", {
3284
+ class: "vpe-btn vpe-btn--sm",
3285
+ type: "button",
3286
+ title: "编辑连接",
3287
+ onClick: (d) => br(r)
3288
+ }, " 编辑 ", 8, Wo),
3289
+ l("button", {
3290
+ class: "vpe-btn vpe-btn--sm",
3291
+ type: "button",
3292
+ title: "删除连接",
3293
+ disabled: X.value,
3294
+ onClick: (d) => Sr(r)
3295
+ }, " 删除 ", 8, Go)
3296
+ ]))), 128)),
3297
+ ke.value ? (f(), p("p", Yo, $(ke.value), 1)) : M("", !0),
3298
+ _e.value ? (f(), p("p", {
3299
+ key: 2,
3300
+ class: se(["vpe-sql-hint", tt.value ? "vpe-sql-hint--ok" : "vpe-sql-hint--error"])
3301
+ }, $(_e.value), 3)) : M("", !0)
3302
+ ], 64))
3303
+ ])
3304
+ ])) : M("", !0)
3305
+ ], 6);
3306
+ };
1478
3307
  }
1479
3308
  });
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}`);
3309
+ function mi(o = {}) {
3310
+ var Le;
3311
+ const n = Ut(o.pyodideUrl ? { pyodideUrl: o.pyodideUrl } : void 0), s = q(n.status), i = q(""), u = q([]);
3312
+ let h = 0;
3313
+ const w = (I, y) => {
3314
+ u.value.push({ id: ++h, stream: I, text: y });
3315
+ }, C = n.on("status", (I, y) => {
3316
+ s.value = I, y && (i.value = y);
3317
+ }), _ = n.on("initError", (I) => {
3318
+ w("system", `[pyodide] 加载失败:${I}`);
1490
3319
  });
1491
- Bt(() => {
1492
- I(), H();
3320
+ fs(() => {
3321
+ C(), _();
1493
3322
  });
1494
- const C = async (o, h = {}) => {
1495
- var x;
3323
+ const O = async (I, y = {}) => {
3324
+ var R;
1496
3325
  try {
1497
- const O = await r.run(o, {
1498
- stdin: h.stdin,
1499
- onOutput: (U, X) => w(U, X)
3326
+ const j = await n.run(I, {
3327
+ stdin: y.stdin,
3328
+ onOutput: (ce, ge) => w(ce, ge)
1500
3329
  });
1501
- return !O.ok && ((x = O.error) != null && x.traceback) && w("stderr", O.error.traceback), O;
1502
- } catch (O) {
3330
+ return !j.ok && ((R = j.error) != null && R.traceback) && w("stderr", j.error.traceback), j;
3331
+ } catch (j) {
1503
3332
  return {
1504
3333
  ok: !1,
1505
3334
  durationMs: 0,
1506
- error: { type: "RuntimeError", message: O instanceof Error ? O.message : String(O), traceback: "" }
3335
+ error: { type: "RuntimeError", message: j instanceof Error ? j.message : String(j), traceback: "" }
1507
3336
  };
1508
3337
  }
1509
- }, M = async (o, h) => {
3338
+ }, F = async (I, y) => {
1510
3339
  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: "" } };
3340
+ return await n.writeFile(I, y);
3341
+ } catch (R) {
3342
+ return { ok: !1, error: { type: "RuntimeError", message: R instanceof Error ? R.message : String(R), traceback: "" } };
1514
3343
  }
1515
- }, T = async (o) => {
3344
+ }, k = async (I) => {
1516
3345
  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: "" } };
3346
+ return await n.readFile(I);
3347
+ } catch (y) {
3348
+ return { ok: !1, error: { type: "RuntimeError", message: y instanceof Error ? y.message : String(y), traceback: "" } };
1520
3349
  }
1521
- }, D = async (o = ".") => {
3350
+ }, T = async (I = ".") => {
1522
3351
  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: "" } };
3352
+ return await n.listFiles(I);
3353
+ } catch (y) {
3354
+ return { ok: !1, error: { type: "RuntimeError", message: y instanceof Error ? y.message : String(y), traceback: "" } };
1526
3355
  }
1527
- }, N = async (o) => {
3356
+ }, S = async (I) => {
1528
3357
  try {
1529
- return await r.loadPackages(o, { onOutput: (h, x) => w(h, x) });
1530
- } catch (h) {
3358
+ return await n.loadPackages(I, { onOutput: (y, R) => w(y, R) });
3359
+ } catch (y) {
1531
3360
  return {
1532
3361
  ok: !1,
1533
3362
  durationMs: 0,
1534
- error: { type: "RuntimeError", message: h instanceof Error ? h.message : String(h), traceback: "" }
3363
+ error: { type: "RuntimeError", message: y instanceof Error ? y.message : String(y), traceback: "" }
1535
3364
  };
1536
3365
  }
1537
3366
  };
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);
3367
+ let K = !1;
3368
+ const de = async () => {
3369
+ var R;
3370
+ if (K) return;
3371
+ const I = o.preloadPackages ?? [];
3372
+ if (!I.length) return;
3373
+ K = !0, w("system", `[pyodide] 正在安装预置包:${I.join(", ")}`);
3374
+ const y = await S(I);
1546
3375
  w(
1547
3376
  "system",
1548
- h.ok ? `[pyodide] 预置包安装完成(${(h.durationMs / 1e3).toFixed(1)}s)` : `[pyodide] 预置包安装失败:${((x = h.error) == null ? void 0 : x.message) ?? "未知错误"}`
3377
+ y.ok ? `[pyodide] 预置包安装完成(${(y.durationMs / 1e3).toFixed(1)}s)` : `[pyodide] 预置包安装失败:${((R = y.error) == null ? void 0 : R.message) ?? "未知错误"}`
1549
3378
  );
1550
3379
  };
1551
- return (u.preload || (((G = u.preloadPackages) == null ? void 0 : G.length) ?? 0) > 0) && r.waitReady().then(() => J()).catch(() => {
3380
+ return (o.preload || (((Le = o.preloadPackages) == null ? void 0 : Le.length) ?? 0) > 0) && n.waitReady().then(() => de()).catch(() => {
1552
3381
  }), {
1553
- status: a,
3382
+ status: s,
1554
3383
  version: i,
1555
- outputs: s,
1556
- runPython: C,
1557
- install: N,
1558
- checkSyntax: (o) => r.checkSyntax(o),
1559
- interrupt: () => r.interrupt(),
3384
+ outputs: u,
3385
+ runPython: O,
3386
+ install: S,
3387
+ checkSyntax: (I) => n.checkSyntax(I),
3388
+ interrupt: () => n.interrupt(),
1560
3389
  clearOutputs: () => {
1561
- s.value = [];
3390
+ u.value = [];
1562
3391
  },
1563
- writeFile: M,
1564
- readFile: T,
1565
- listFiles: D,
3392
+ writeFile: F,
3393
+ readFile: k,
3394
+ listFiles: T,
1566
3395
  /** 预加载并在就绪后 resolve */
1567
- ready: () => r.waitReady()
3396
+ ready: () => n.waitReady()
1568
3397
  };
1569
3398
  }
1570
- const fr = Yn;
3399
+ const yi = Xo;
1571
3400
  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
3401
+ Vn as DEFAULT_PYODIDE_URL,
3402
+ vi as DEFAULT_SQL_CONFIG,
3403
+ Is as MONO_FONT_STACK,
3404
+ Vs as PyodideRunner,
3405
+ yi as PythonEditor,
3406
+ Ye as SQL_DIALECT_OPTIONS,
3407
+ Bs as createEditor,
3408
+ ea as createPythonSession,
3409
+ Xo as default,
3410
+ Gs as deleteServerFile,
3411
+ Nn as deleteSqlConnection,
3412
+ In as getDefaultSqlPort,
3413
+ Ut as getRunner,
3414
+ Ln as interruptPythonSession,
3415
+ Ks as listServerFiles,
3416
+ la as listSqlConnections,
3417
+ As as makePythonLinter,
3418
+ U as normalizeSqlConfig,
3419
+ ta as pollPythonSession,
3420
+ Ws as readServerFile,
3421
+ pi as runPythonOnServer,
3422
+ Kn as runSql,
3423
+ Zs as saveServerFile,
3424
+ ua as saveSqlConnection,
3425
+ na as sendPythonSessionInput,
3426
+ jn as setErrorLines,
3427
+ ia as testSqlConnection,
3428
+ mi as usePyodide
1582
3429
  };