princess-python-editor 0.1.0 → 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/README.md +513 -55
- package/dist/PythonEditor.vue.d.ts +75 -3
- package/dist/icons.d.ts +6 -0
- package/dist/index.cjs.js +166 -4
- package/dist/index.d.ts +35 -1
- package/dist/index.es.js +3004 -695
- package/dist/runtime/PyodideRunner.d.ts +15 -1
- package/dist/runtime/files.d.ts +17 -0
- package/dist/runtime/python.d.ts +36 -0
- package/dist/runtime/sql.d.ts +41 -0
- package/dist/runtime/usePyodide.d.ts +9 -2
- package/dist/style.css +1 -1
- package/dist/types.d.ts +237 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { h as
|
|
5
|
-
import { EditorState as
|
|
6
|
-
import { EditorView as
|
|
7
|
-
import { oneDark as
|
|
8
|
-
import { linter as
|
|
9
|
-
import { autocompletion as
|
|
10
|
-
import { history as
|
|
11
|
-
import { indentUnit as
|
|
12
|
-
import { python as
|
|
13
|
-
import { javascript as
|
|
14
|
-
import { json as
|
|
15
|
-
import { sql as
|
|
16
|
-
const
|
|
17
|
-
function
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
|
|
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
|
|
24
|
-
create: () =>
|
|
25
|
-
update: (
|
|
26
|
-
let
|
|
27
|
-
for (const
|
|
28
|
-
|
|
29
|
-
return n.docChanged && (
|
|
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: (
|
|
32
|
-
}),
|
|
31
|
+
provide: (o) => Oe.decorations.from(o)
|
|
32
|
+
}), Us = Oe.theme({
|
|
33
33
|
"&": { height: "100%", fontSize: "13px" },
|
|
34
|
-
".cm-scroller": { fontFamily:
|
|
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,58 +41,61 @@ const Nt = ht.define({
|
|
|
41
41
|
},
|
|
42
42
|
"&.cm-focused": { outline: "none" }
|
|
43
43
|
});
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
}),
|
|
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
51
|
run: () => (n.onRunShortcut(), !0)
|
|
52
52
|
}
|
|
53
|
-
]),
|
|
53
|
+
]), u = _t.create({
|
|
54
54
|
doc: n.value,
|
|
55
55
|
extensions: [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
n.language ??
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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,
|
|
71
|
+
i,
|
|
72
|
+
Fn.of([...Es, ...Cs, ...Ps, Ms]),
|
|
73
|
+
...n.dark ? [Nt] : [],
|
|
71
74
|
...n.extensions,
|
|
72
|
-
|
|
75
|
+
s
|
|
73
76
|
]
|
|
74
77
|
});
|
|
75
|
-
return new
|
|
78
|
+
return new Oe({ state: u, parent: o });
|
|
76
79
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
79
|
-
async (
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
-
let
|
|
80
|
+
function As(o, n = 600) {
|
|
81
|
+
return ks(
|
|
82
|
+
async (s) => {
|
|
83
|
+
const i = s.state.doc.toString();
|
|
84
|
+
if (!i.trim()) return [];
|
|
85
|
+
let u = null;
|
|
83
86
|
try {
|
|
84
|
-
|
|
87
|
+
u = await o.checkSyntax(i);
|
|
85
88
|
} catch {
|
|
86
89
|
return [];
|
|
87
90
|
}
|
|
88
|
-
if (!
|
|
89
|
-
const
|
|
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);
|
|
90
93
|
return [
|
|
91
94
|
{
|
|
92
|
-
from:
|
|
93
|
-
to:
|
|
95
|
+
from: _,
|
|
96
|
+
to: O,
|
|
94
97
|
severity: "error",
|
|
95
|
-
message:
|
|
98
|
+
message: u.message,
|
|
96
99
|
source: "python-syntax"
|
|
97
100
|
}
|
|
98
101
|
];
|
|
@@ -100,7 +103,7 @@ function jt(s, n = 600) {
|
|
|
100
103
|
{ delay: n }
|
|
101
104
|
);
|
|
102
105
|
}
|
|
103
|
-
const
|
|
106
|
+
const Ds = [
|
|
104
107
|
"import ast, json",
|
|
105
108
|
"def _pye_check(src):",
|
|
106
109
|
" try:",
|
|
@@ -108,15 +111,94 @@ const Tt = [
|
|
|
108
111
|
" return json.dumps({'ok': True})",
|
|
109
112
|
" except SyntaxError as e:",
|
|
110
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})'
|
|
111
190
|
];
|
|
112
|
-
function
|
|
113
|
-
const n =
|
|
191
|
+
function js(o) {
|
|
192
|
+
const n = o.endsWith("/") ? o : o + "/";
|
|
114
193
|
return `
|
|
115
194
|
var INDEX_URL = ${JSON.stringify(n)};
|
|
116
|
-
var CHECK_SOURCE = ${JSON.stringify(
|
|
195
|
+
var CHECK_SOURCE = ${JSON.stringify(Ds.join(`
|
|
196
|
+
`))};
|
|
197
|
+
var SQL_SOURCE = ${JSON.stringify(zs.join(`
|
|
117
198
|
`))};
|
|
118
199
|
var pyodide = null;
|
|
119
200
|
var checkFn = null;
|
|
201
|
+
var sqlFn = null;
|
|
120
202
|
var currentId = 0;
|
|
121
203
|
|
|
122
204
|
function post(msg) { self.postMessage(msg); }
|
|
@@ -135,6 +217,85 @@ function parseError(e) {
|
|
|
135
217
|
return { type: type, message: detail, line: line, traceback: msg };
|
|
136
218
|
}
|
|
137
219
|
|
|
220
|
+
function fsError(e) {
|
|
221
|
+
return {
|
|
222
|
+
type: String((e && e.name) || 'OSError'),
|
|
223
|
+
message: String((e && e.message) || e),
|
|
224
|
+
traceback: ''
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** 将相对路径解析为虚拟文件系统中的绝对路径(默认基于 /home/pyodide) */
|
|
229
|
+
function normPath(p) {
|
|
230
|
+
var raw = String(p == null ? '' : p);
|
|
231
|
+
if (!raw) return pyodide.FS.cwd();
|
|
232
|
+
var full = raw.charAt(0) === '/' ? raw : pyodide.FS.cwd() + '/' + raw;
|
|
233
|
+
var parts = full.split('/');
|
|
234
|
+
var out = [];
|
|
235
|
+
for (var i = 0; i < parts.length; i++) {
|
|
236
|
+
var seg = parts[i];
|
|
237
|
+
if (!seg || seg === '.') continue;
|
|
238
|
+
if (seg === '..') {
|
|
239
|
+
if (out.length) out.pop();
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
out.push(seg);
|
|
243
|
+
}
|
|
244
|
+
return '/' + out.join('/');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** 将预置文本按行切分,逐行提供给 input();text 为 null 时立即 EOF */
|
|
248
|
+
function makeStdin(text) {
|
|
249
|
+
var lines = null;
|
|
250
|
+
if (text !== undefined && text !== null) {
|
|
251
|
+
lines = String(text).split(/\\r\\n|\\n|\\r/);
|
|
252
|
+
if (lines.length && lines[lines.length - 1] === '') lines.pop();
|
|
253
|
+
}
|
|
254
|
+
var index = 0;
|
|
255
|
+
return function () {
|
|
256
|
+
if (!lines || index >= lines.length) return null;
|
|
257
|
+
var line = lines[index];
|
|
258
|
+
index += 1;
|
|
259
|
+
return line + '\\n';
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** 递归列出虚拟文件;跳过缓存目录并限制深度与条目数,避免大目录阻塞 */
|
|
264
|
+
function listFs(path, recursive) {
|
|
265
|
+
var entries = [];
|
|
266
|
+
function walk(dir, depth) {
|
|
267
|
+
var names = pyodide.FS.readdir(dir);
|
|
268
|
+
for (var i = 0; i < names.length; i++) {
|
|
269
|
+
var name = names[i];
|
|
270
|
+
if (name === '.' || name === '..') continue;
|
|
271
|
+
if (name === '__pycache__' || name === '.cache') continue;
|
|
272
|
+
var full = dir === '/' ? '/' + name : dir + '/' + name;
|
|
273
|
+
var stat;
|
|
274
|
+
try {
|
|
275
|
+
stat = pyodide.FS.stat(full);
|
|
276
|
+
} catch (e) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
var isDir = pyodide.FS.isDir(stat.mode);
|
|
280
|
+
entries.push({
|
|
281
|
+
name: name,
|
|
282
|
+
path: full,
|
|
283
|
+
isDirectory: isDir,
|
|
284
|
+
size: isDir ? 0 : stat.size
|
|
285
|
+
});
|
|
286
|
+
if (isDir && recursive && depth < 4 && entries.length < 500) {
|
|
287
|
+
walk(full, depth + 1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
walk(path, 0);
|
|
292
|
+
entries.sort(function (a, b) {
|
|
293
|
+
if (a.isDirectory !== b.isDirectory) return a.isDirectory ? -1 : 1;
|
|
294
|
+
return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
295
|
+
});
|
|
296
|
+
return entries;
|
|
297
|
+
}
|
|
298
|
+
|
|
138
299
|
async function init() {
|
|
139
300
|
try {
|
|
140
301
|
self.importScripts(INDEX_URL + 'pyodide.js');
|
|
@@ -167,6 +328,7 @@ self.onmessage = async function (ev) {
|
|
|
167
328
|
return;
|
|
168
329
|
}
|
|
169
330
|
try {
|
|
331
|
+
pyodide.setStdin({ stdin: makeStdin(msg.stdin) });
|
|
170
332
|
var result = await pyodide.runPythonAsync(msg.code);
|
|
171
333
|
var value;
|
|
172
334
|
if (result !== undefined && result !== null) {
|
|
@@ -209,99 +371,222 @@ self.onmessage = async function (ev) {
|
|
|
209
371
|
}
|
|
210
372
|
}
|
|
211
373
|
currentId = 0;
|
|
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
|
+
|
|
406
|
+
} else if (msg.kind === 'fs-write') {
|
|
407
|
+
if (!pyodide) {
|
|
408
|
+
post({ kind: 'fs-written', id: msg.id, ok: false, error: { type: 'RuntimeError', message: 'Pyodide 未初始化', traceback: '' } });
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
var writePath = normPath(msg.path);
|
|
413
|
+
var slash = writePath.lastIndexOf('/');
|
|
414
|
+
var dir = slash <= 0 ? '/' : writePath.slice(0, slash);
|
|
415
|
+
try {
|
|
416
|
+
pyodide.FS.mkdirTree(dir);
|
|
417
|
+
} catch (e0) {
|
|
418
|
+
// 目录已存在时忽略
|
|
419
|
+
}
|
|
420
|
+
pyodide.FS.writeFile(writePath, String(msg.content == null ? '' : msg.content), { encoding: 'utf8' });
|
|
421
|
+
post({ kind: 'fs-written', id: msg.id, ok: true, path: writePath });
|
|
422
|
+
} catch (e) {
|
|
423
|
+
post({ kind: 'fs-written', id: msg.id, ok: false, error: fsError(e) });
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
} else if (msg.kind === 'fs-read') {
|
|
427
|
+
if (!pyodide) {
|
|
428
|
+
post({ kind: 'fs-read', id: msg.id, ok: false, error: { type: 'RuntimeError', message: 'Pyodide 未初始化', traceback: '' } });
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
try {
|
|
432
|
+
var readPath = normPath(msg.path);
|
|
433
|
+
var content = pyodide.FS.readFile(readPath, { encoding: 'utf8' });
|
|
434
|
+
post({ kind: 'fs-read', id: msg.id, ok: true, path: readPath, content: content });
|
|
435
|
+
} catch (e) {
|
|
436
|
+
post({ kind: 'fs-read', id: msg.id, ok: false, error: fsError(e) });
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
} else if (msg.kind === 'fs-list') {
|
|
440
|
+
if (!pyodide) {
|
|
441
|
+
post({ kind: 'fs-list', id: msg.id, ok: false, error: { type: 'RuntimeError', message: 'Pyodide 未初始化', traceback: '' } });
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
try {
|
|
445
|
+
var listPath = normPath(msg.path);
|
|
446
|
+
var entries = listFs(listPath, msg.recursive !== false);
|
|
447
|
+
post({ kind: 'fs-list', id: msg.id, ok: true, path: listPath, entries: entries });
|
|
448
|
+
} catch (e) {
|
|
449
|
+
post({ kind: 'fs-list', id: msg.id, ok: false, error: fsError(e) });
|
|
450
|
+
}
|
|
212
451
|
}
|
|
213
452
|
};
|
|
214
453
|
`;
|
|
215
454
|
}
|
|
216
|
-
const
|
|
217
|
-
class
|
|
455
|
+
const Vn = "https://cdn.jsdelivr.net/pyodide/v0.27.2/full/";
|
|
456
|
+
class Vs {
|
|
218
457
|
constructor(n = {}) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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());
|
|
226
465
|
/** Worker 生命周期代数:interrupt 后递增,用于废弃旧的 waitReady 等待 */
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this.pyodideUrl = n.pyodideUrl ||
|
|
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;
|
|
232
471
|
}
|
|
233
|
-
on(n,
|
|
472
|
+
on(n, s) {
|
|
234
473
|
if (n === "status") {
|
|
235
|
-
const
|
|
236
|
-
return this.statusHandlers.add(
|
|
474
|
+
const u = s;
|
|
475
|
+
return this.statusHandlers.add(u), () => this.statusHandlers.delete(u);
|
|
237
476
|
}
|
|
238
477
|
if (n === "output") {
|
|
239
|
-
const
|
|
240
|
-
return this.outputHandlers.add(
|
|
478
|
+
const u = s;
|
|
479
|
+
return this.outputHandlers.add(u), () => this.outputHandlers.delete(u);
|
|
241
480
|
}
|
|
242
|
-
const
|
|
243
|
-
return this.initErrorHandlers.add(
|
|
481
|
+
const i = s;
|
|
482
|
+
return this.initErrorHandlers.add(i), () => this.initErrorHandlers.delete(i);
|
|
244
483
|
}
|
|
245
484
|
/** 预加载 Pyodide(返回 Promise,在就绪或失败时 settle) */
|
|
246
485
|
waitReady(n = 18e4) {
|
|
247
|
-
const
|
|
248
|
-
return this.ensureWorker(), this.status === "ready" || this.status === "running" ? Promise.resolve() : new Promise((
|
|
249
|
-
let
|
|
486
|
+
const s = this.generation;
|
|
487
|
+
return this.ensureWorker(), this.status === "ready" || this.status === "running" ? Promise.resolve() : new Promise((i, u) => {
|
|
488
|
+
let h = () => {
|
|
250
489
|
}, w = () => {
|
|
251
490
|
};
|
|
252
|
-
const
|
|
253
|
-
clearTimeout(
|
|
254
|
-
},
|
|
255
|
-
|
|
491
|
+
const C = () => {
|
|
492
|
+
clearTimeout(_), h(), w();
|
|
493
|
+
}, _ = setTimeout(() => {
|
|
494
|
+
C(), u(new Error("Pyodide 加载超时"));
|
|
256
495
|
}, n);
|
|
257
|
-
|
|
258
|
-
if (this.generation !==
|
|
259
|
-
|
|
496
|
+
h = this.on("status", (O) => {
|
|
497
|
+
if (this.generation !== s) {
|
|
498
|
+
C(), u(new Error("执行已被中断"));
|
|
260
499
|
return;
|
|
261
500
|
}
|
|
262
|
-
|
|
263
|
-
}), w = this.on("initError", (
|
|
264
|
-
|
|
501
|
+
O === "ready" && (C(), i());
|
|
502
|
+
}), w = this.on("initError", (O) => {
|
|
503
|
+
C(), u(new Error(O));
|
|
265
504
|
});
|
|
266
505
|
});
|
|
267
506
|
}
|
|
268
507
|
/** 执行一段 Python 代码(支持顶层 await);运行器未就绪时先等待初始化完成 */
|
|
269
|
-
async run(n,
|
|
508
|
+
async run(n, s) {
|
|
270
509
|
await this.waitReady();
|
|
271
|
-
const
|
|
510
|
+
const i = performance.now();
|
|
272
511
|
this.setStatus("running");
|
|
273
|
-
const
|
|
274
|
-
{ kind: "run", id: this.seq++, code: n },
|
|
275
|
-
|
|
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
|
|
276
515
|
);
|
|
277
516
|
return this.status === "running" && this.setStatus("ready"), {
|
|
278
|
-
ok:
|
|
279
|
-
value:
|
|
280
|
-
error:
|
|
281
|
-
interrupted:
|
|
282
|
-
durationMs: performance.now() -
|
|
517
|
+
ok: u.ok,
|
|
518
|
+
value: u.value,
|
|
519
|
+
error: u.error,
|
|
520
|
+
interrupted: u.interrupted,
|
|
521
|
+
durationMs: performance.now() - i
|
|
283
522
|
};
|
|
284
523
|
}
|
|
285
524
|
/** 语法检查:仅在运行器就绪时可用,否则返回 null(静默跳过) */
|
|
286
525
|
async checkSyntax(n) {
|
|
287
526
|
if (this.status !== "ready" || !n.trim()) return null;
|
|
288
|
-
const
|
|
289
|
-
return
|
|
290
|
-
line:
|
|
291
|
-
column:
|
|
292
|
-
message:
|
|
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 ?? "语法错误"
|
|
293
532
|
};
|
|
294
533
|
}
|
|
534
|
+
/** 写入虚拟文件系统(UTF-8 文本),相对路径基于当前工作目录 */
|
|
535
|
+
async writeFile(n, s) {
|
|
536
|
+
await this.waitReady();
|
|
537
|
+
const i = await this.send({ kind: "fs-write", id: this.seq++, path: n, content: s });
|
|
538
|
+
return { ok: i.ok, path: i.path, error: i.error };
|
|
539
|
+
}
|
|
540
|
+
/** 读取虚拟文件系统中的文本文件;二进制内容会返回失败 */
|
|
541
|
+
async readFile(n) {
|
|
542
|
+
await this.waitReady();
|
|
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 };
|
|
545
|
+
}
|
|
546
|
+
/** 列出虚拟文件系统目录(递归,跳过 __pycache__ / .cache) */
|
|
547
|
+
async listFiles(n = ".") {
|
|
548
|
+
await this.waitReady();
|
|
549
|
+
const s = await this.send({
|
|
550
|
+
kind: "fs-list",
|
|
551
|
+
id: this.seq++,
|
|
552
|
+
path: n,
|
|
553
|
+
recursive: !0
|
|
554
|
+
});
|
|
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
|
+
}
|
|
579
|
+
}
|
|
295
580
|
/** 安装第三方包:先尝试内置 wheel(loadPackage),失败后回退 micropip */
|
|
296
|
-
async loadPackages(n,
|
|
581
|
+
async loadPackages(n, s) {
|
|
297
582
|
await this.waitReady();
|
|
298
|
-
const
|
|
583
|
+
const i = performance.now();
|
|
299
584
|
this.setStatus("running");
|
|
300
|
-
const
|
|
585
|
+
const u = await this.send(
|
|
301
586
|
{ kind: "install", id: this.seq++, packages: n },
|
|
302
|
-
|
|
587
|
+
s == null ? void 0 : s.onOutput
|
|
303
588
|
);
|
|
304
|
-
return this.status === "running" && this.setStatus("ready"), { ok:
|
|
589
|
+
return this.status === "running" && this.setStatus("ready"), { ok: u.ok, error: u.error, durationMs: performance.now() - i };
|
|
305
590
|
}
|
|
306
591
|
/**
|
|
307
592
|
* 中断当前执行:terminate Worker(Pyodide 无法真正中断同步计算),
|
|
@@ -315,12 +600,12 @@ class Vt {
|
|
|
315
600
|
interrupted: !0,
|
|
316
601
|
error: { type: "KeyboardInterrupt", message: "执行已被用户中断", traceback: "" }
|
|
317
602
|
};
|
|
318
|
-
this.pending.forEach((
|
|
603
|
+
this.pending.forEach((s) => s.resolve(n)), this.pending.clear(), this.chain = Promise.resolve(), this.setStatus("idle");
|
|
319
604
|
}
|
|
320
605
|
ensureWorker() {
|
|
321
606
|
if (this.worker) return this.worker;
|
|
322
|
-
const n = new Blob([
|
|
323
|
-
return
|
|
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;
|
|
324
609
|
}
|
|
325
610
|
handleMessage(n) {
|
|
326
611
|
switch (n.kind) {
|
|
@@ -328,21 +613,21 @@ class Vt {
|
|
|
328
613
|
this.version = n.version, this.setStatus("ready");
|
|
329
614
|
break;
|
|
330
615
|
case "init-error":
|
|
331
|
-
this.setStatus("idle"), this.initErrorHandlers.forEach((
|
|
616
|
+
this.setStatus("idle"), this.initErrorHandlers.forEach((s) => s(n.message));
|
|
332
617
|
break;
|
|
333
618
|
case "output": {
|
|
334
|
-
const
|
|
335
|
-
|
|
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));
|
|
336
621
|
break;
|
|
337
622
|
}
|
|
338
623
|
case "result": {
|
|
339
|
-
const
|
|
340
|
-
|
|
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 }));
|
|
341
626
|
break;
|
|
342
627
|
}
|
|
343
628
|
case "checked": {
|
|
344
|
-
const
|
|
345
|
-
|
|
629
|
+
const s = this.pending.get(n.id);
|
|
630
|
+
s && (this.pending.delete(n.id), s.resolve({
|
|
346
631
|
ok: n.ok,
|
|
347
632
|
line: n.line,
|
|
348
633
|
column: n.column,
|
|
@@ -351,61 +636,625 @@ class Vt {
|
|
|
351
636
|
break;
|
|
352
637
|
}
|
|
353
638
|
case "installed": {
|
|
354
|
-
const
|
|
355
|
-
|
|
639
|
+
const s = this.pending.get(n.id);
|
|
640
|
+
s && (this.pending.delete(n.id), s.resolve({ ok: n.ok, error: n.error }));
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
case "fs-written": {
|
|
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 }));
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
case "fs-read": {
|
|
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
|
|
655
|
+
}));
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
case "fs-list": {
|
|
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
|
|
665
|
+
}));
|
|
666
|
+
break;
|
|
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 }));
|
|
356
671
|
break;
|
|
357
672
|
}
|
|
358
673
|
}
|
|
359
674
|
}
|
|
360
|
-
send(n,
|
|
361
|
-
const
|
|
362
|
-
() => new Promise((
|
|
363
|
-
this.pending.set(n.id, { resolve:
|
|
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);
|
|
364
679
|
})
|
|
365
680
|
);
|
|
366
|
-
return this.chain =
|
|
681
|
+
return this.chain = u.then(
|
|
367
682
|
() => {
|
|
368
683
|
},
|
|
369
684
|
() => {
|
|
370
685
|
}
|
|
371
|
-
),
|
|
686
|
+
), u;
|
|
372
687
|
}
|
|
373
688
|
setStatus(n) {
|
|
374
|
-
this.status !== n && (this.status = n, this.statusHandlers.forEach((
|
|
689
|
+
this.status !== n && (this.status = n, this.statusHandlers.forEach((s) => s(n, this.version)));
|
|
375
690
|
}
|
|
376
691
|
}
|
|
377
|
-
let
|
|
378
|
-
function
|
|
379
|
-
return
|
|
692
|
+
let Tt = null;
|
|
693
|
+
function Ut(o) {
|
|
694
|
+
return Tt ? o != null && o.pyodideUrl && o.pyodideUrl !== Vn && console.warn(
|
|
380
695
|
"[princess-python-editor] Pyodide 运行器已初始化,后续传入的 pyodideUrl 将被忽略。"
|
|
381
|
-
) :
|
|
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";
|
|
1008
|
+
}
|
|
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
|
+
}
|
|
382
1212
|
}
|
|
383
|
-
|
|
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 = [
|
|
384
1233
|
{ value: "python", label: "Python", extension: "py" },
|
|
385
1234
|
{ value: "sql", label: "SQL", extension: "sql" },
|
|
386
1235
|
{ value: "javascript", label: "JavaScript", extension: "js" },
|
|
387
1236
|
{ value: "json", label: "JSON", extension: "json" }
|
|
388
1237
|
];
|
|
389
|
-
function
|
|
390
|
-
return
|
|
1238
|
+
function ft(o) {
|
|
1239
|
+
return vt.find((n) => n.value === o) ?? vt[0];
|
|
391
1240
|
}
|
|
392
|
-
function
|
|
393
|
-
switch (
|
|
1241
|
+
function $t(o) {
|
|
1242
|
+
switch (o) {
|
|
394
1243
|
case "sql":
|
|
395
|
-
return
|
|
1244
|
+
return _s();
|
|
396
1245
|
case "javascript":
|
|
397
|
-
return
|
|
1246
|
+
return $s();
|
|
398
1247
|
case "json":
|
|
399
|
-
return
|
|
1248
|
+
return Rs();
|
|
400
1249
|
case "python":
|
|
401
1250
|
default:
|
|
402
|
-
return
|
|
1251
|
+
return zn();
|
|
403
1252
|
}
|
|
404
1253
|
}
|
|
405
|
-
function
|
|
406
|
-
const n =
|
|
1254
|
+
function Hn(o) {
|
|
1255
|
+
const n = o.lastIndexOf(".");
|
|
407
1256
|
if (n < 0) return "python";
|
|
408
|
-
switch (
|
|
1257
|
+
switch (o.slice(n + 1).toLowerCase()) {
|
|
409
1258
|
case "sql":
|
|
410
1259
|
return "sql";
|
|
411
1260
|
case "js":
|
|
@@ -420,9 +1269,9 @@ function zt(s) {
|
|
|
420
1269
|
return "python";
|
|
421
1270
|
}
|
|
422
1271
|
}
|
|
423
|
-
function
|
|
424
|
-
const n = Array.isArray(
|
|
425
|
-
return () =>
|
|
1272
|
+
function J(o) {
|
|
1273
|
+
const n = Array.isArray(o) ? o : [o];
|
|
1274
|
+
return () => En(
|
|
426
1275
|
"svg",
|
|
427
1276
|
{
|
|
428
1277
|
viewBox: "0 0 24 24",
|
|
@@ -431,33 +1280,111 @@ function F(s) {
|
|
|
431
1280
|
fill: "currentColor",
|
|
432
1281
|
"aria-hidden": "true"
|
|
433
1282
|
},
|
|
434
|
-
n.map((
|
|
1283
|
+
n.map((s) => En("path", { d: s }))
|
|
435
1284
|
);
|
|
436
1285
|
}
|
|
437
|
-
const
|
|
1286
|
+
const da = J(
|
|
438
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"
|
|
439
|
-
),
|
|
1288
|
+
), ca = J("M6 6h12v12H6Z"), Un = J(
|
|
440
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"
|
|
441
|
-
),
|
|
1290
|
+
), fa = J(
|
|
442
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"
|
|
443
|
-
),
|
|
1292
|
+
), pa = J(
|
|
444
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"
|
|
445
|
-
),
|
|
1294
|
+
), Bn = J(
|
|
446
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"
|
|
447
|
-
),
|
|
1296
|
+
), An = J("M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"), va = J(
|
|
448
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"
|
|
449
|
-
),
|
|
1298
|
+
), ma = J("M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"), Ge = J(
|
|
450
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"
|
|
451
|
-
),
|
|
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 = {
|
|
452
1308
|
key: 0,
|
|
453
1309
|
class: "vpe-toolbar"
|
|
454
|
-
},
|
|
1310
|
+
}, wa = ["title", "disabled"], Sa = ["disabled"], qa = ["disabled"], Ea = ["title", "disabled"], xa = ["title", "aria-label"], Ca = { key: 2 }, Pa = { key: 3 }, Ma = ["disabled"], Oa = {
|
|
455
1311
|
class: "vpe-file",
|
|
456
1312
|
title: "当前文件名(下载时使用)"
|
|
457
|
-
},
|
|
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 = {
|
|
458
1329
|
key: 1,
|
|
459
1330
|
class: "vpe-empty"
|
|
460
|
-
},
|
|
1331
|
+
}, Ka = {
|
|
1332
|
+
key: 0,
|
|
1333
|
+
class: "vpe-terminal-input"
|
|
1334
|
+
}, Za = ["onKeydown"], Wa = {
|
|
1335
|
+
key: 4,
|
|
1336
|
+
class: "vpe-fs-panel",
|
|
1337
|
+
role: "dialog",
|
|
1338
|
+
"aria-label": "虚拟文件"
|
|
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 = {
|
|
1354
|
+
key: 0,
|
|
1355
|
+
class: "vpe-fs-empty"
|
|
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 = {
|
|
1379
|
+
key: 0,
|
|
1380
|
+
class: "vpe-fs-empty"
|
|
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({
|
|
461
1388
|
__name: "PythonEditor",
|
|
462
1389
|
props: {
|
|
463
1390
|
modelValue: { default: "" },
|
|
@@ -476,645 +1403,2027 @@ const Dt = F(
|
|
|
476
1403
|
preload: { type: Boolean, default: !1 },
|
|
477
1404
|
pyodideUrl: { default: "" },
|
|
478
1405
|
fileName: { default: "main.py" },
|
|
479
|
-
language: { default: "python" }
|
|
1406
|
+
language: { default: "python" },
|
|
1407
|
+
stdin: { default: "" },
|
|
1408
|
+
syncFilesOnRun: { type: Boolean, default: !0 },
|
|
1409
|
+
storageKey: { 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" }
|
|
480
1420
|
},
|
|
481
|
-
emits: ["update:modelValue", "ready", "statusChange", "runStart", "runOutput", "runError", "runFinish", "loadError", "update:fileName", "update:language", "newFile", "fileClose", "fileSwitch", "copy", "download", "fileOpen"],
|
|
482
|
-
setup(
|
|
483
|
-
const o = s,
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
+
},
|
|
492
1434
|
set: (e) => {
|
|
493
|
-
const t =
|
|
494
|
-
t
|
|
495
|
-
}
|
|
496
|
-
}),
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
1435
|
+
const t = z.value;
|
|
1436
|
+
t && (t.input = e);
|
|
1437
|
+
}
|
|
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(() => ({
|
|
1452
|
+
height: typeof i.height == "number" ? `${i.height}px` : i.height
|
|
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) {
|
|
509
1466
|
return { ...e };
|
|
510
1467
|
}
|
|
511
|
-
function
|
|
512
|
-
|
|
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 });
|
|
1474
|
+
}
|
|
1475
|
+
function m(e, t) {
|
|
1476
|
+
fe("system", e, t);
|
|
1477
|
+
}
|
|
1478
|
+
function ar(e) {
|
|
1479
|
+
return vt.some((t) => t.value === e);
|
|
1480
|
+
}
|
|
1481
|
+
function or() {
|
|
1482
|
+
if (!i.storageKey || typeof window > "u") return null;
|
|
1483
|
+
try {
|
|
1484
|
+
const e = window.localStorage.getItem(i.storageKey);
|
|
1485
|
+
if (!e) return null;
|
|
1486
|
+
const t = JSON.parse(e);
|
|
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 });
|
|
1493
|
+
}
|
|
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 };
|
|
1497
|
+
} catch {
|
|
1498
|
+
return null;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
function ir() {
|
|
1502
|
+
const e = or();
|
|
1503
|
+
if (!e) return;
|
|
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);
|
|
1507
|
+
}
|
|
1508
|
+
function Wt() {
|
|
1509
|
+
if (!(!yt || ht || !i.storageKey || typeof window > "u"))
|
|
1510
|
+
try {
|
|
1511
|
+
const e = {
|
|
1512
|
+
version: Rt,
|
|
1513
|
+
files: L.value.map((t) => ({
|
|
1514
|
+
name: t.name,
|
|
1515
|
+
language: t.language,
|
|
1516
|
+
code: t.code
|
|
1517
|
+
})),
|
|
1518
|
+
activeIndex: Math.max(
|
|
1519
|
+
L.value.findIndex((t) => t.id === he.value),
|
|
1520
|
+
0
|
|
1521
|
+
)
|
|
1522
|
+
};
|
|
1523
|
+
window.localStorage.setItem(i.storageKey, JSON.stringify(e));
|
|
1524
|
+
} catch (e) {
|
|
1525
|
+
jt || (jt = !0, m(`本地草稿保存失败:${e instanceof Error ? e.message : String(e)}`));
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
function lr() {
|
|
1529
|
+
!yt || !i.storageKey || typeof window > "u" || (ht = !1, window.clearTimeout(nt), nt = window.setTimeout(Wt, 400));
|
|
513
1530
|
}
|
|
514
|
-
function
|
|
515
|
-
|
|
1531
|
+
function ur() {
|
|
1532
|
+
if (!(!i.storageKey || typeof window > "u")) {
|
|
1533
|
+
window.clearTimeout(nt);
|
|
1534
|
+
try {
|
|
1535
|
+
window.localStorage.removeItem(i.storageKey), ht = !0, m("已清除本地草稿");
|
|
1536
|
+
} catch (e) {
|
|
1537
|
+
m(`清除本地草稿失败:${e instanceof Error ? e.message : String(e)}`);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
516
1540
|
}
|
|
517
|
-
function
|
|
518
|
-
if (!
|
|
1541
|
+
function Se(e) {
|
|
1542
|
+
if (!E) return;
|
|
519
1543
|
const t = e ? [e] : [];
|
|
520
|
-
|
|
1544
|
+
E.dispatch({ effects: jn.of(t) });
|
|
521
1545
|
}
|
|
522
|
-
function
|
|
523
|
-
const e =
|
|
524
|
-
if (
|
|
525
|
-
e !==
|
|
1546
|
+
function dr() {
|
|
1547
|
+
const e = i.modelValue;
|
|
1548
|
+
if (E) {
|
|
1549
|
+
e !== E.state.doc.toString() && E.dispatch({ changes: { from: 0, to: E.state.doc.length, insert: e } });
|
|
526
1550
|
return;
|
|
527
1551
|
}
|
|
528
|
-
const t =
|
|
1552
|
+
const t = b.value;
|
|
529
1553
|
t.code !== e && (t.code = e);
|
|
530
1554
|
}
|
|
531
|
-
function
|
|
532
|
-
return
|
|
1555
|
+
function qe() {
|
|
1556
|
+
return E ? E.state.doc.toString() : b.value.code;
|
|
533
1557
|
}
|
|
534
|
-
function
|
|
535
|
-
if (
|
|
536
|
-
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 } });
|
|
537
1561
|
return;
|
|
538
1562
|
}
|
|
539
|
-
const t =
|
|
540
|
-
t.code = e, e !==
|
|
1563
|
+
const t = b.value;
|
|
1564
|
+
t.code = e, e !== i.modelValue && u("update:modelValue", e);
|
|
541
1565
|
}
|
|
542
|
-
function
|
|
543
|
-
return
|
|
1566
|
+
function qt(e) {
|
|
1567
|
+
return i.disableLint || e !== "python" ? [] : As(D, i.lintDelay);
|
|
544
1568
|
}
|
|
545
|
-
function
|
|
546
|
-
const t =
|
|
1569
|
+
function Et(e) {
|
|
1570
|
+
const t = b.value;
|
|
547
1571
|
if (t.language !== e) {
|
|
548
|
-
if (t.language = e,
|
|
1572
|
+
if (t.language = e, le(t.id).sqlResults = [], Se(void 0), E == null || E.dispatch({
|
|
549
1573
|
effects: [
|
|
550
|
-
|
|
551
|
-
|
|
1574
|
+
bt.reconfigure($t(e)),
|
|
1575
|
+
kt.reconfigure(qt(e))
|
|
552
1576
|
]
|
|
553
1577
|
}), /^untitled(-\d+)?\.[^.]+$/.test(t.name)) {
|
|
554
|
-
const
|
|
555
|
-
|
|
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));
|
|
556
1580
|
}
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
function ke(e, t) {
|
|
561
|
-
const l = e.trim().replace(/[\\/:*?"<>|]+/g, "_").replace(/\.+$/, "") || "untitled";
|
|
562
|
-
return /\.[^.\\/]+$/.test(l) ? l : `${l}.${Y(t).extension}`;
|
|
563
|
-
}
|
|
564
|
-
function qe(e) {
|
|
565
|
-
const t = Y(e).extension, r = new Set(f.value.map((g) => g.name));
|
|
566
|
-
let l = `untitled.${t}`, u = 2;
|
|
567
|
-
for (; r.has(l); )
|
|
568
|
-
l = `untitled-${u}.${t}`, u += 1;
|
|
569
|
-
return l;
|
|
570
|
-
}
|
|
571
|
-
function Ke(e) {
|
|
572
|
-
if (!f.value.some((m) => m.name === e)) return e;
|
|
573
|
-
const t = e.lastIndexOf("."), r = t > 0 ? e.slice(0, t) : e, l = t > 0 ? e.slice(t) : "";
|
|
574
|
-
let u = 2, g = `${r}-${u}${l}`;
|
|
575
|
-
for (; f.value.some((m) => m.name === g); )
|
|
576
|
-
u += 1, g = `${r}-${u}${l}`;
|
|
577
|
-
return g;
|
|
578
|
-
}
|
|
579
|
-
let A = 0;
|
|
580
|
-
async function be() {
|
|
581
|
-
var u, g;
|
|
582
|
-
if (H.value === "loading" || H.value === "running") return;
|
|
583
|
-
const e = c.value.language;
|
|
584
|
-
if (e !== "python") {
|
|
585
|
-
y(`当前文件为 ${Y(e).label},仅支持执行 Python 代码`);
|
|
586
|
-
return;
|
|
1581
|
+
u("update:language", e);
|
|
587
1582
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
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) {
|
|
1605
|
+
return !!e && e !== "." && e !== ".." && !e.includes("/") && !e.includes("\\");
|
|
1606
|
+
}
|
|
1607
|
+
async function fr() {
|
|
1608
|
+
var t;
|
|
1609
|
+
if (!i.syncFilesOnRun) return;
|
|
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}(文件名不能包含路径分隔符)`);
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
const r = await D.writeFile(a.name, a.code);
|
|
1617
|
+
r.ok || m(`同步文件失败:${a.name}(${((t = r.error) == null ? void 0 : t.message) ?? "未知错误"})`);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
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;
|
|
2014
|
+
if (e !== "python") {
|
|
2015
|
+
m(`当前文件为 ${ft(e).label},仅支持执行 Python / SQL 代码`);
|
|
2016
|
+
return;
|
|
2017
|
+
}
|
|
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();
|
|
2022
|
+
try {
|
|
2023
|
+
await fr();
|
|
2024
|
+
const P = await D.run(r, {
|
|
2025
|
+
stdin: i.stdin,
|
|
2026
|
+
onOutput: (V, We) => {
|
|
2027
|
+
fe(V, We, a), u("runOutput", { stream: V, text: We });
|
|
2028
|
+
}
|
|
2029
|
+
});
|
|
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);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
async function Lr() {
|
|
2043
|
+
var t;
|
|
2044
|
+
if (Vt) return;
|
|
2045
|
+
const e = i.preloadPackages;
|
|
2046
|
+
if (e.length) {
|
|
2047
|
+
Vt = !0, m(`正在安装预置包:${e.join(", ")}`);
|
|
2048
|
+
try {
|
|
2049
|
+
const a = await D.loadPackages(e, {
|
|
2050
|
+
onOutput: (r, d) => fe(r, d)
|
|
2051
|
+
});
|
|
2052
|
+
m(
|
|
2053
|
+
a.ok ? `预置包安装完成(${(a.durationMs / 1e3).toFixed(1)}s)` : `预置包安装失败:${((t = a.error) == null ? void 0 : t.message) ?? "未知错误"}`
|
|
2054
|
+
);
|
|
2055
|
+
} catch (a) {
|
|
2056
|
+
m(`预置包安装失败:${a instanceof Error ? a.message : String(a)}`);
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
is(() => {
|
|
2061
|
+
const e = w.value;
|
|
2062
|
+
if (!e) return;
|
|
2063
|
+
ir(), yt = !0;
|
|
2064
|
+
const t = [
|
|
2065
|
+
Qt.of(i.theme === "dark" ? [Nt] : []),
|
|
2066
|
+
Jt.of([
|
|
2067
|
+
_t.readOnly.of(i.readOnly),
|
|
2068
|
+
Oe.editable.of(!i.readOnly)
|
|
2069
|
+
]),
|
|
2070
|
+
kt.of(qt(b.value.language))
|
|
2071
|
+
];
|
|
2072
|
+
try {
|
|
2073
|
+
E = Bs(e, {
|
|
2074
|
+
value: b.value.code,
|
|
2075
|
+
dark: i.theme === "dark",
|
|
2076
|
+
placeholderText: i.placeholder,
|
|
2077
|
+
language: bt.of($t(b.value.language)),
|
|
625
2078
|
extensions: t,
|
|
626
|
-
onDocChange: (
|
|
627
|
-
|
|
2079
|
+
onDocChange: (a) => {
|
|
2080
|
+
b.value.code = a, a !== i.modelValue && u("update:modelValue", a);
|
|
628
2081
|
},
|
|
629
|
-
onRunShortcut:
|
|
2082
|
+
onRunShortcut: on
|
|
630
2083
|
});
|
|
631
|
-
} catch (
|
|
632
|
-
const
|
|
633
|
-
console.error("[princess-python-editor] 编辑器初始化失败",
|
|
634
|
-
const
|
|
635
|
-
|
|
2084
|
+
} catch (a) {
|
|
2085
|
+
const r = a instanceof Error ? a.message : String(a);
|
|
2086
|
+
console.error("[princess-python-editor] 编辑器初始化失败", a), m(`编辑器初始化失败:${r}`), e.innerHTML = "";
|
|
2087
|
+
const d = document.createElement("div");
|
|
2088
|
+
d.className = "vpe-init-error", d.textContent = `编辑器初始化失败:${r}`, e.appendChild(d);
|
|
636
2089
|
return;
|
|
637
2090
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}),
|
|
641
|
-
|
|
642
|
-
}),
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}),
|
|
646
|
-
()
|
|
647
|
-
(
|
|
648
|
-
|
|
649
|
-
()
|
|
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(
|
|
2104
|
+
() => i.modelValue,
|
|
2105
|
+
() => dr()
|
|
2106
|
+
), G(
|
|
2107
|
+
() => i.outputHeight,
|
|
2108
|
+
() => {
|
|
2109
|
+
k.value = null;
|
|
2110
|
+
}
|
|
2111
|
+
), G(
|
|
2112
|
+
() => i.fileName,
|
|
650
2113
|
(e) => {
|
|
651
|
-
e && e !==
|
|
2114
|
+
e && e !== b.value.name && (Pe.value = e);
|
|
652
2115
|
}
|
|
653
|
-
),
|
|
654
|
-
() =>
|
|
2116
|
+
), G(
|
|
2117
|
+
() => i.language,
|
|
655
2118
|
(e) => {
|
|
656
|
-
e !==
|
|
2119
|
+
e !== b.value.language && Et(e);
|
|
657
2120
|
}
|
|
658
|
-
),
|
|
659
|
-
() =>
|
|
2121
|
+
), G(
|
|
2122
|
+
() => i.runtime,
|
|
660
2123
|
(e) => {
|
|
661
|
-
|
|
2124
|
+
e !== j.value && (j.value = e);
|
|
662
2125
|
}
|
|
663
|
-
),
|
|
664
|
-
() =>
|
|
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(
|
|
2145
|
+
() => i.theme,
|
|
2146
|
+
(e) => {
|
|
2147
|
+
E == null || E.dispatch({ effects: Qt.reconfigure(e === "dark" ? [Nt] : []) });
|
|
2148
|
+
}
|
|
2149
|
+
), G(
|
|
2150
|
+
() => i.readOnly,
|
|
665
2151
|
(e) => {
|
|
666
|
-
|
|
667
|
-
effects:
|
|
2152
|
+
E == null || E.dispatch({
|
|
2153
|
+
effects: Jt.reconfigure([_t.readOnly.of(e), Oe.editable.of(!e)])
|
|
668
2154
|
});
|
|
669
2155
|
}
|
|
670
|
-
),
|
|
671
|
-
() =>
|
|
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,
|
|
672
2168
|
async () => {
|
|
673
|
-
await
|
|
674
|
-
const e =
|
|
2169
|
+
await Cn();
|
|
2170
|
+
const e = _.value;
|
|
675
2171
|
e && (e.scrollTop = e.scrollHeight);
|
|
676
2172
|
}
|
|
677
|
-
);
|
|
678
|
-
function
|
|
679
|
-
|
|
2173
|
+
), G([L, he], () => lr(), { deep: !0 });
|
|
2174
|
+
function ln() {
|
|
2175
|
+
on();
|
|
680
2176
|
}
|
|
681
|
-
function
|
|
682
|
-
|
|
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);
|
|
2197
|
+
}
|
|
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;
|
|
683
2208
|
}
|
|
684
|
-
function
|
|
685
|
-
|
|
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);
|
|
686
2213
|
}
|
|
687
|
-
function
|
|
688
|
-
|
|
689
|
-
const e = c.value.language, t = ee(qe(e), e, "");
|
|
690
|
-
f.value.push(t), T(t.id), i("newFile", D(t));
|
|
2214
|
+
function Pt(e) {
|
|
2215
|
+
k.value = Math.round(Math.max(Dn, Math.min(e, Tr())));
|
|
691
2216
|
}
|
|
692
|
-
function
|
|
693
|
-
|
|
694
|
-
|
|
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() {
|
|
2236
|
+
if (i.readOnly) return;
|
|
2237
|
+
const e = b.value.language, t = Ie(Gt(e), e, "");
|
|
2238
|
+
L.value.push(t), Me(t.id), u("newFile", Ue(t));
|
|
2239
|
+
}
|
|
2240
|
+
function Me(e) {
|
|
2241
|
+
if (e === he.value) {
|
|
2242
|
+
ut();
|
|
695
2243
|
return;
|
|
696
2244
|
}
|
|
697
|
-
const t =
|
|
698
|
-
t && (
|
|
2245
|
+
const t = L.value.find((a) => a.id === e);
|
|
2246
|
+
t && (he.value = e, Ot(t));
|
|
699
2247
|
}
|
|
700
|
-
function
|
|
701
|
-
|
|
702
|
-
|
|
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);
|
|
703
2254
|
if (t === -1) return;
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
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));
|
|
708
2266
|
}
|
|
709
|
-
function
|
|
710
|
-
|
|
2267
|
+
function Ot(e) {
|
|
2268
|
+
Se(void 0), ot(e.code), E == null || E.dispatch({
|
|
711
2269
|
effects: [
|
|
712
|
-
|
|
713
|
-
|
|
2270
|
+
bt.reconfigure($t(e.language)),
|
|
2271
|
+
kt.reconfigure(qt(e.language))
|
|
714
2272
|
]
|
|
715
|
-
}),
|
|
2273
|
+
}), u("update:fileName", e.name), u("update:language", e.language), u("fileSwitch", Ue(e)), ut();
|
|
716
2274
|
}
|
|
717
|
-
function
|
|
718
|
-
|
|
2275
|
+
function yn() {
|
|
2276
|
+
i.readOnly || (Se(void 0), ot(""), ut());
|
|
719
2277
|
}
|
|
720
|
-
async function
|
|
721
|
-
var
|
|
722
|
-
const e =
|
|
2278
|
+
async function hn() {
|
|
2279
|
+
var a;
|
|
2280
|
+
const e = qe();
|
|
723
2281
|
let t = !1;
|
|
724
2282
|
try {
|
|
725
|
-
(
|
|
2283
|
+
(a = navigator.clipboard) != null && a.writeText && (await navigator.clipboard.writeText(e), t = !0);
|
|
726
2284
|
} catch {
|
|
727
2285
|
t = !1;
|
|
728
2286
|
}
|
|
729
|
-
return t || (t =
|
|
730
|
-
|
|
731
|
-
}, 1600),
|
|
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);
|
|
732
2290
|
}
|
|
733
|
-
function
|
|
2291
|
+
function Nr(e) {
|
|
734
2292
|
const t = document.createElement("textarea");
|
|
735
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);
|
|
736
|
-
let
|
|
2294
|
+
let a = !1;
|
|
737
2295
|
try {
|
|
738
|
-
|
|
2296
|
+
a = document.execCommand("copy");
|
|
739
2297
|
} catch {
|
|
740
|
-
|
|
2298
|
+
a = !1;
|
|
741
2299
|
}
|
|
742
|
-
return t.remove(),
|
|
2300
|
+
return t.remove(), a;
|
|
743
2301
|
}
|
|
744
|
-
function
|
|
745
|
-
const e =
|
|
746
|
-
|
|
747
|
-
const
|
|
2302
|
+
function gn() {
|
|
2303
|
+
const e = b.value, t = xt(e.name, e.language);
|
|
2304
|
+
Pe.value = t;
|
|
2305
|
+
const a = new Blob([qe()], {
|
|
748
2306
|
type: e.language === "python" ? "text/x-python;charset=utf-8" : "text/plain;charset=utf-8"
|
|
749
|
-
}),
|
|
750
|
-
return
|
|
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;
|
|
751
2309
|
}
|
|
752
|
-
function
|
|
2310
|
+
function Hr() {
|
|
2311
|
+
ge.value = !ge.value, ge.value && (me.value = !1, bn());
|
|
2312
|
+
}
|
|
2313
|
+
async function bn() {
|
|
753
2314
|
var e;
|
|
754
|
-
(
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
2315
|
+
if (!De.value) {
|
|
2316
|
+
De.value = !0;
|
|
2317
|
+
try {
|
|
2318
|
+
const t = await D.listFiles(".");
|
|
2319
|
+
if (!t.ok) {
|
|
2320
|
+
ze.value = [], m(`读取虚拟文件失败:${((e = t.error) == null ? void 0 : e.message) ?? "未知错误"}`);
|
|
2321
|
+
return;
|
|
2322
|
+
}
|
|
2323
|
+
ze.value = t.entries ?? [];
|
|
2324
|
+
} catch (t) {
|
|
2325
|
+
ze.value = [], m(`读取虚拟文件失败:${t instanceof Error ? t.message : String(t)}`);
|
|
2326
|
+
} finally {
|
|
2327
|
+
De.value = !1;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
function Ur(e) {
|
|
2332
|
+
switch (e.slice(e.lastIndexOf(".") + 1).toLowerCase()) {
|
|
2333
|
+
case "csv":
|
|
2334
|
+
return "text/csv";
|
|
2335
|
+
case "json":
|
|
2336
|
+
return "application/json";
|
|
2337
|
+
case "html":
|
|
2338
|
+
case "htm":
|
|
2339
|
+
return "text/html";
|
|
2340
|
+
case "md":
|
|
2341
|
+
return "text/markdown";
|
|
2342
|
+
case "py":
|
|
2343
|
+
return "text/x-python";
|
|
2344
|
+
default:
|
|
2345
|
+
return "text/plain";
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
function Ft(e) {
|
|
2349
|
+
return e < 1024 ? `${e} B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)} KB` : `${(e / 1024 / 1024).toFixed(1)} MB`;
|
|
2350
|
+
}
|
|
2351
|
+
async function kn(e) {
|
|
2352
|
+
var t;
|
|
2353
|
+
try {
|
|
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;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
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
|
+
}
|
|
2422
|
+
}
|
|
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
|
+
}
|
|
2436
|
+
}
|
|
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
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
function Sn() {
|
|
2450
|
+
var e;
|
|
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)`);
|
|
762
2459
|
return;
|
|
763
2460
|
}
|
|
764
2461
|
try {
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
} catch (
|
|
768
|
-
const
|
|
769
|
-
|
|
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 });
|
|
2464
|
+
} catch (d) {
|
|
2465
|
+
const v = d instanceof Error ? d.message : String(d);
|
|
2466
|
+
m(`读取文件失败:${v}`);
|
|
770
2467
|
}
|
|
771
2468
|
}
|
|
772
2469
|
}
|
|
773
|
-
function
|
|
774
|
-
|
|
2470
|
+
function Kr() {
|
|
2471
|
+
Pe.value = xt(Pe.value, b.value.language);
|
|
775
2472
|
}
|
|
776
|
-
function
|
|
2473
|
+
function Zr(e) {
|
|
777
2474
|
e.key === "Enter" && (e.preventDefault(), e.target.blur());
|
|
778
2475
|
}
|
|
779
|
-
function
|
|
780
|
-
|
|
2476
|
+
function Wr(e) {
|
|
2477
|
+
Et(e.target.value);
|
|
781
2478
|
}
|
|
782
|
-
async function
|
|
783
|
-
var t,
|
|
784
|
-
await
|
|
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();
|
|
785
2482
|
}
|
|
786
|
-
function
|
|
2483
|
+
function Gr(e, t) {
|
|
787
2484
|
if (e.target !== e.currentTarget) return;
|
|
788
2485
|
if (e.key === "Enter" || e.key === " ") {
|
|
789
|
-
e.preventDefault(),
|
|
2486
|
+
e.preventDefault(), Me(t.id), qn(t.id);
|
|
790
2487
|
return;
|
|
791
2488
|
}
|
|
792
2489
|
if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
|
|
793
2490
|
e.preventDefault();
|
|
794
|
-
const
|
|
795
|
-
if (
|
|
796
|
-
const
|
|
797
|
-
|
|
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));
|
|
798
2495
|
}
|
|
799
|
-
function
|
|
800
|
-
|
|
2496
|
+
function ut() {
|
|
2497
|
+
E == null || E.focus();
|
|
801
2498
|
}
|
|
802
|
-
async function
|
|
803
|
-
var
|
|
804
|
-
|
|
2499
|
+
async function Yr(e) {
|
|
2500
|
+
var a;
|
|
2501
|
+
m(`正在安装:${e.join(", ")}`);
|
|
805
2502
|
let t;
|
|
806
2503
|
try {
|
|
807
|
-
t = await
|
|
808
|
-
onOutput: (
|
|
2504
|
+
t = await D.loadPackages(e, {
|
|
2505
|
+
onOutput: (r, d) => fe(r, d)
|
|
809
2506
|
});
|
|
810
|
-
} catch (
|
|
811
|
-
const
|
|
812
|
-
return
|
|
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 } };
|
|
813
2510
|
}
|
|
814
|
-
return
|
|
2511
|
+
return m(t.ok ? "安装完成" : `安装失败:${((a = t.error) == null ? void 0 : a.message) ?? "未知错误"}`), t;
|
|
815
2512
|
}
|
|
816
|
-
function
|
|
817
|
-
return
|
|
2513
|
+
function Xr() {
|
|
2514
|
+
return D.checkSyntax(qe());
|
|
818
2515
|
}
|
|
819
|
-
function
|
|
820
|
-
return
|
|
2516
|
+
function es() {
|
|
2517
|
+
return U(c.value);
|
|
821
2518
|
}
|
|
822
|
-
function
|
|
823
|
-
return
|
|
2519
|
+
function ts() {
|
|
2520
|
+
return E;
|
|
824
2521
|
}
|
|
825
|
-
function
|
|
826
|
-
return
|
|
2522
|
+
function ns() {
|
|
2523
|
+
return L.value.map(Ue);
|
|
2524
|
+
}
|
|
2525
|
+
function rs() {
|
|
2526
|
+
return Ue(b.value);
|
|
827
2527
|
}
|
|
828
2528
|
return n({
|
|
829
|
-
run:
|
|
830
|
-
stop:
|
|
831
|
-
clearOutput:
|
|
832
|
-
clearCode:
|
|
833
|
-
newFile:
|
|
834
|
-
switchFile:
|
|
835
|
-
closeFile:
|
|
836
|
-
copyCode:
|
|
837
|
-
download:
|
|
838
|
-
openFile:
|
|
839
|
-
focus:
|
|
840
|
-
install:
|
|
841
|
-
checkSyntax:
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
type: "button",
|
|
866
|
-
title: "中断执行",
|
|
867
|
-
onClick: xe
|
|
868
|
-
}, [
|
|
869
|
-
$(S(_t)),
|
|
870
|
-
t[2] || (t[2] = p("span", null, "停止", -1))
|
|
871
|
-
])),
|
|
872
|
-
t[4] || (t[4] = p("span", {
|
|
873
|
-
class: "vpe-divider",
|
|
874
|
-
"aria-hidden": "true"
|
|
875
|
-
}, null, -1)),
|
|
876
|
-
p("button", {
|
|
877
|
-
class: "vpe-btn",
|
|
878
|
-
type: "button",
|
|
879
|
-
title: "新建文件",
|
|
880
|
-
"aria-label": "新建文件",
|
|
881
|
-
disabled: s.readOnly,
|
|
882
|
-
onClick: ie
|
|
883
|
-
}, [
|
|
884
|
-
$(S(Bt))
|
|
885
|
-
], 8, Qt),
|
|
886
|
-
p("button", {
|
|
887
|
-
class: "vpe-btn",
|
|
888
|
-
type: "button",
|
|
889
|
-
title: "打开本地文件",
|
|
890
|
-
"aria-label": "打开本地文件",
|
|
891
|
-
disabled: s.readOnly,
|
|
892
|
-
onClick: He
|
|
893
|
-
}, [
|
|
894
|
-
$(S(At))
|
|
895
|
-
], 8, en),
|
|
896
|
-
p("button", {
|
|
897
|
-
class: "vpe-btn",
|
|
898
|
-
type: "button",
|
|
899
|
-
title: "下载当前文件",
|
|
900
|
-
"aria-label": "下载当前文件",
|
|
901
|
-
onClick: Fe
|
|
902
|
-
}, [
|
|
903
|
-
$(S(Kt))
|
|
904
|
-
]),
|
|
905
|
-
p("button", {
|
|
906
|
-
class: V(["vpe-btn", { "vpe-btn--copied": P.value }]),
|
|
907
|
-
type: "button",
|
|
908
|
-
title: P.value ? "已复制" : "复制代码",
|
|
909
|
-
"aria-label": P.value ? "已复制" : "复制代码",
|
|
910
|
-
onClick: Le
|
|
911
|
-
}, [
|
|
912
|
-
P.value ? (v(), Pe(S(Zt), { key: 0 })) : (v(), Pe(S(Wt), { key: 1 }))
|
|
913
|
-
], 10, tn),
|
|
914
|
-
p("button", {
|
|
915
|
-
class: "vpe-btn",
|
|
916
|
-
type: "button",
|
|
917
|
-
title: "清空当前文件",
|
|
918
|
-
"aria-label": "清空当前文件",
|
|
919
|
-
disabled: s.readOnly,
|
|
920
|
-
onClick: Oe
|
|
921
|
-
}, [
|
|
922
|
-
$(S(je))
|
|
923
|
-
], 8, nn),
|
|
924
|
-
t[5] || (t[5] = p("span", {
|
|
925
|
-
class: "vpe-divider",
|
|
926
|
-
"aria-hidden": "true"
|
|
927
|
-
}, null, -1)),
|
|
928
|
-
p("label", rn, [
|
|
929
|
-
$(S(qt)),
|
|
930
|
-
ut(p("input", {
|
|
931
|
-
"onUpdate:modelValue": t[0] || (t[0] = (r) => j.value = r),
|
|
932
|
-
class: "vpe-file-input",
|
|
933
|
-
type: "text",
|
|
934
|
-
spellcheck: "false",
|
|
935
|
-
"aria-label": "文件名",
|
|
936
|
-
onBlur: Je,
|
|
937
|
-
onKeydown: Ge
|
|
938
|
-
}, null, 544), [
|
|
939
|
-
[dt, j.value]
|
|
940
|
-
])
|
|
941
|
-
]),
|
|
942
|
-
t[6] || (t[6] = p("span", {
|
|
943
|
-
class: "vpe-spacer",
|
|
944
|
-
"aria-hidden": "true"
|
|
945
|
-
}, null, -1)),
|
|
946
|
-
p("span", {
|
|
947
|
-
class: V(["vpe-status", `vpe-status--${H.value}`])
|
|
948
|
-
}, [
|
|
949
|
-
t[3] || (t[3] = p("span", {
|
|
950
|
-
class: "vpe-status-dot",
|
|
951
|
-
"aria-hidden": "true"
|
|
952
|
-
}, null, -1)),
|
|
953
|
-
p("span", null, J(Be.value), 1)
|
|
954
|
-
], 2),
|
|
955
|
-
p("select", {
|
|
956
|
-
class: "vpe-lang",
|
|
957
|
-
value: c.value.language,
|
|
958
|
-
title: "编辑器语言",
|
|
959
|
-
"aria-label": "编辑器语言",
|
|
960
|
-
disabled: s.readOnly,
|
|
961
|
-
onChange: Xe
|
|
962
|
-
}, [
|
|
963
|
-
(v(!0), b(se, null, le(S(he), (r) => (v(), b("option", {
|
|
964
|
-
key: r.value,
|
|
965
|
-
value: r.value
|
|
966
|
-
}, J(r.label), 9, on))), 128))
|
|
967
|
-
], 40, an)
|
|
968
|
-
])) : G("", !0),
|
|
969
|
-
s.showTabs ? (v(), b("div", {
|
|
970
|
-
key: 1,
|
|
971
|
-
ref_key: "tabsEl",
|
|
972
|
-
ref: L,
|
|
973
|
-
class: "vpe-tabs",
|
|
974
|
-
role: "tablist",
|
|
975
|
-
"aria-label": "文件"
|
|
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)
|
|
976
2565
|
}, [
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
p("span", {
|
|
989
|
-
class: V(["vpe-tab-dot", `vpe-tab-dot--${r.language}`]),
|
|
990
|
-
"aria-hidden": "true"
|
|
991
|
-
}, null, 2),
|
|
992
|
-
p("span", ln, J(r.name), 1),
|
|
993
|
-
f.value.length > 1 ? (v(), b("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", {
|
|
994
2577
|
key: 0,
|
|
995
|
-
class: "vpe-
|
|
2578
|
+
class: "vpe-btn vpe-btn--primary",
|
|
996
2579
|
type: "button",
|
|
997
|
-
title:
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
onClick: ct((l) => Se(r.id), ["stop"])
|
|
2580
|
+
title: nr.value,
|
|
2581
|
+
disabled: rr.value,
|
|
2582
|
+
onClick: ln
|
|
1001
2583
|
}, [
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
"
|
|
1010
|
-
|
|
1011
|
-
|
|
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",
|
|
2593
|
+
type: "button",
|
|
2594
|
+
title: "新建文件",
|
|
2595
|
+
"aria-label": "新建文件",
|
|
2596
|
+
disabled: o.readOnly,
|
|
2597
|
+
onClick: Mt
|
|
2598
|
+
}, [
|
|
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", {
|
|
2707
|
+
class: "vpe-spacer",
|
|
2708
|
+
"aria-hidden": "true"
|
|
2709
|
+
}, null, -1)),
|
|
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": "文件"
|
|
1012
2784
|
}, [
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
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",
|
|
1038
2814
|
type: "button",
|
|
1039
|
-
title: "
|
|
1040
|
-
|
|
2815
|
+
title: "新建文件",
|
|
2816
|
+
"aria-label": "新建文件",
|
|
2817
|
+
disabled: o.readOnly,
|
|
2818
|
+
onClick: Mt
|
|
1041
2819
|
}, [
|
|
1042
|
-
|
|
1043
|
-
])
|
|
1044
|
-
]),
|
|
1045
|
-
|
|
1046
|
-
ref_key: "
|
|
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",
|
|
1047
2833
|
ref: w,
|
|
1048
|
-
class: "vpe-
|
|
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 })
|
|
1049
2854
|
}, [
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
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))
|
|
2979
|
+
])
|
|
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
|
|
3052
|
+
}, [
|
|
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", {
|
|
3212
|
+
key: 0,
|
|
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",
|
|
3221
|
+
type: "button",
|
|
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"
|
|
3267
|
+
}, [
|
|
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
|
+
};
|
|
1058
3307
|
}
|
|
1059
3308
|
});
|
|
1060
|
-
function
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
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}`);
|
|
3319
|
+
});
|
|
3320
|
+
fs(() => {
|
|
3321
|
+
C(), _();
|
|
1069
3322
|
});
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
3323
|
+
const O = async (I, y = {}) => {
|
|
3324
|
+
var R;
|
|
3325
|
+
try {
|
|
3326
|
+
const j = await n.run(I, {
|
|
3327
|
+
stdin: y.stdin,
|
|
3328
|
+
onOutput: (ce, ge) => w(ce, ge)
|
|
3329
|
+
});
|
|
3330
|
+
return !j.ok && ((R = j.error) != null && R.traceback) && w("stderr", j.error.traceback), j;
|
|
3331
|
+
} catch (j) {
|
|
3332
|
+
return {
|
|
3333
|
+
ok: !1,
|
|
3334
|
+
durationMs: 0,
|
|
3335
|
+
error: { type: "RuntimeError", message: j instanceof Error ? j.message : String(j), traceback: "" }
|
|
3336
|
+
};
|
|
3337
|
+
}
|
|
3338
|
+
}, F = async (I, y) => {
|
|
3339
|
+
try {
|
|
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: "" } };
|
|
3343
|
+
}
|
|
3344
|
+
}, k = async (I) => {
|
|
3345
|
+
try {
|
|
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: "" } };
|
|
3349
|
+
}
|
|
3350
|
+
}, T = async (I = ".") => {
|
|
3351
|
+
try {
|
|
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: "" } };
|
|
3355
|
+
}
|
|
3356
|
+
}, S = async (I) => {
|
|
3357
|
+
try {
|
|
3358
|
+
return await n.loadPackages(I, { onOutput: (y, R) => w(y, R) });
|
|
3359
|
+
} catch (y) {
|
|
3360
|
+
return {
|
|
3361
|
+
ok: !1,
|
|
3362
|
+
durationMs: 0,
|
|
3363
|
+
error: { type: "RuntimeError", message: y instanceof Error ? y.message : String(y), traceback: "" }
|
|
3364
|
+
};
|
|
3365
|
+
}
|
|
3366
|
+
};
|
|
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);
|
|
3375
|
+
w(
|
|
3376
|
+
"system",
|
|
3377
|
+
y.ok ? `[pyodide] 预置包安装完成(${(y.durationMs / 1e3).toFixed(1)}s)` : `[pyodide] 预置包安装失败:${((R = y.error) == null ? void 0 : R.message) ?? "未知错误"}`
|
|
3378
|
+
);
|
|
3379
|
+
};
|
|
3380
|
+
return (o.preload || (((Le = o.preloadPackages) == null ? void 0 : Le.length) ?? 0) > 0) && n.waitReady().then(() => de()).catch(() => {
|
|
1073
3381
|
}), {
|
|
1074
|
-
status:
|
|
1075
|
-
version:
|
|
1076
|
-
outputs:
|
|
1077
|
-
runPython:
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
} catch (h) {
|
|
1081
|
-
return {
|
|
1082
|
-
ok: !1,
|
|
1083
|
-
durationMs: 0,
|
|
1084
|
-
error: { type: "RuntimeError", message: h instanceof Error ? h.message : String(h), traceback: "" }
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
},
|
|
1088
|
-
install: async (E) => {
|
|
1089
|
-
try {
|
|
1090
|
-
return await n.loadPackages(E, { onOutput: (h, M) => w(h, M) });
|
|
1091
|
-
} catch (h) {
|
|
1092
|
-
return {
|
|
1093
|
-
ok: !1,
|
|
1094
|
-
durationMs: 0,
|
|
1095
|
-
error: { type: "RuntimeError", message: h instanceof Error ? h.message : String(h), traceback: "" }
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
},
|
|
1099
|
-
checkSyntax: (E) => n.checkSyntax(E),
|
|
3382
|
+
status: s,
|
|
3383
|
+
version: i,
|
|
3384
|
+
outputs: u,
|
|
3385
|
+
runPython: O,
|
|
3386
|
+
install: S,
|
|
3387
|
+
checkSyntax: (I) => n.checkSyntax(I),
|
|
1100
3388
|
interrupt: () => n.interrupt(),
|
|
1101
3389
|
clearOutputs: () => {
|
|
1102
|
-
|
|
3390
|
+
u.value = [];
|
|
1103
3391
|
},
|
|
3392
|
+
writeFile: F,
|
|
3393
|
+
readFile: k,
|
|
3394
|
+
listFiles: T,
|
|
1104
3395
|
/** 预加载并在就绪后 resolve */
|
|
1105
3396
|
ready: () => n.waitReady()
|
|
1106
3397
|
};
|
|
1107
3398
|
}
|
|
1108
|
-
const
|
|
3399
|
+
const yi = Xo;
|
|
1109
3400
|
export {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
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
|
|
1120
3429
|
};
|