princess-python-editor 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +401 -50
- package/dist/PythonEditor.vue.d.ts +48 -3
- package/dist/icons.d.ts +6 -0
- package/dist/index.cjs.js +41 -5
- package/dist/index.d.ts +26 -1
- package/dist/index.es.js +2721 -874
- package/dist/runtime/PyodideRunner.d.ts +7 -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/style.css +1 -1
- package/dist/types.d.ts +196 -0
- package/package.json +1 -1
- package/README.html +0 -1013
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FsListResult, FsReadResult, FsWriteResult, InstallResult, PyodideStatus, RunResult, SyntaxIssue } from '../types';
|
|
1
|
+
import { FsListResult, FsReadResult, FsWriteResult, InstallResult, PyodideStatus, RunResult, SqlQueryResult, SyntaxIssue } from '../types';
|
|
2
2
|
/** 默认 Pyodide CDN 地址(jsDelivr),可通过 options.pyodideUrl 覆盖 */
|
|
3
3
|
export declare const DEFAULT_PYODIDE_URL = "https://cdn.jsdelivr.net/pyodide/v0.27.2/full/";
|
|
4
4
|
export interface PyodideRunnerOptions {
|
|
@@ -47,6 +47,12 @@ export declare class PyodideRunner {
|
|
|
47
47
|
readFile(path: string): Promise<FsReadResult>;
|
|
48
48
|
/** 列出虚拟文件系统目录(递归,跳过 __pycache__ / .cache) */
|
|
49
49
|
listFiles(path?: string): Promise<FsListResult>;
|
|
50
|
+
/** 在浏览器内的 SQLite 中执行 SQL(首次调用时自动加载 sqlite3 包) */
|
|
51
|
+
executeSql(options: {
|
|
52
|
+
sql: string;
|
|
53
|
+
database?: string;
|
|
54
|
+
maxRows?: number;
|
|
55
|
+
}): Promise<SqlQueryResult>;
|
|
50
56
|
/** 安装第三方包:先尝试内置 wheel(loadPackage),失败后回退 micropip */
|
|
51
57
|
loadPackages(packages: string[], hooks?: RunHooks): Promise<InstallResult>;
|
|
52
58
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ServerFile, ServerFileDetail, ServerFileSaveInput } from '../types';
|
|
2
|
+
export interface FilesApiOptions {
|
|
3
|
+
/** 附加请求头,例如鉴权 token */
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
/** 中断信号 */
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
/** 请求超时(毫秒),默认 30000 */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** 查询服务端已保存文件列表(不含内容) */
|
|
11
|
+
export declare function listServerFiles(endpoint: string, options?: FilesApiOptions): Promise<ServerFile[]>;
|
|
12
|
+
/** 保存文件到服务端,同名文件会被覆盖 */
|
|
13
|
+
export declare function saveServerFile(endpoint: string, input: ServerFileSaveInput, options?: FilesApiOptions): Promise<ServerFile>;
|
|
14
|
+
/** 读取服务端文件内容 */
|
|
15
|
+
export declare function readServerFile(endpoint: string, id: string, options?: FilesApiOptions): Promise<ServerFileDetail>;
|
|
16
|
+
/** 删除服务端文件 */
|
|
17
|
+
export declare function deleteServerFile(endpoint: string, id: string, options?: FilesApiOptions): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PythonRuntimeResult, PythonSessionResult, PythonSessionStartInput } from '../types';
|
|
2
|
+
export interface PythonRunClientOptions {
|
|
3
|
+
/** 预置标准输入(按行提供给 input()) */
|
|
4
|
+
stdin?: string;
|
|
5
|
+
/** 请求超时(毫秒),默认 60000 */
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
/** 附加请求头,例如鉴权 token */
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
/** 中断信号 */
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 在服务端真实 Python 环境中执行代码。
|
|
14
|
+
* 端点约定:POST { code, stdin } → { ok, stdout, stderr, exitCode, durationMs, error? }
|
|
15
|
+
*/
|
|
16
|
+
export declare function runPythonOnServer(endpoint: string, code: string, options?: PythonRunClientOptions): Promise<PythonRuntimeResult>;
|
|
17
|
+
export interface PythonSessionClientOptions {
|
|
18
|
+
/** 会话启动时预先写入 stdin 的文本 */
|
|
19
|
+
stdin?: string;
|
|
20
|
+
/** 会话最长运行秒数 */
|
|
21
|
+
timeoutSeconds?: number;
|
|
22
|
+
/** 附加请求头,例如鉴权 token */
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
/** 中断信号 */
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
/** 单次请求超时(毫秒) */
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
}
|
|
29
|
+
/** 创建交互式 Python 会话(服务端真实环境) */
|
|
30
|
+
export declare function createPythonSession(endpoint: string, code: string, options?: PythonSessionClientOptions & PythonSessionStartInput): Promise<PythonSessionResult>;
|
|
31
|
+
/** 轮询会话增量输出 */
|
|
32
|
+
export declare function pollPythonSession(endpoint: string, sessionId: string, options?: PythonSessionClientOptions): Promise<PythonSessionResult>;
|
|
33
|
+
/** 向会话提交一行标准输入,继续执行 */
|
|
34
|
+
export declare function sendPythonSessionInput(endpoint: string, sessionId: string, text: string, options?: PythonSessionClientOptions): Promise<PythonSessionResult>;
|
|
35
|
+
/** 中断并释放会话(失败时忽略,服务端会按空闲超时自动回收) */
|
|
36
|
+
export declare function interruptPythonSession(endpoint: string, sessionId: string, options?: PythonSessionClientOptions): Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SqlConfig, SqlConfigInput, SqlConnectionProfile, SqlConnectionSaveInput, SqlDialect, SqlExecutor, SqlQueryResult, SqlTestResult } from '../types';
|
|
2
|
+
/** 方言选项与默认端口(仅用于连接配置表单) */
|
|
3
|
+
export interface SqlDialectOption {
|
|
4
|
+
value: SqlDialect;
|
|
5
|
+
label: string;
|
|
6
|
+
defaultPort?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const SQL_DIALECT_OPTIONS: SqlDialectOption[];
|
|
9
|
+
/** 默认 SQL 配置:浏览器内 SQLite,内存数据库 */
|
|
10
|
+
export declare const DEFAULT_SQL_CONFIG: SqlConfig;
|
|
11
|
+
/** 合并默认值,得到组件内部使用的完整 SQL 配置 */
|
|
12
|
+
export declare function normalizeSqlConfig(input?: SqlConfigInput): SqlConfig;
|
|
13
|
+
export interface RunSqlOptions {
|
|
14
|
+
/** 自定义执行器,优先级高于内置的 sqlite / http 模式 */
|
|
15
|
+
executor?: SqlExecutor;
|
|
16
|
+
/** 中断信号(http 模式会中止请求;sqlite 模式请改用 PyodideRunner.interrupt) */
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 执行 SQL:
|
|
21
|
+
* - 配置了 executor → 使用自定义执行器
|
|
22
|
+
* - mode = 'http' → POST { connection, sql, maxRows } 到 endpoint
|
|
23
|
+
* - mode = 'sqlite' → 交给 Pyodide 内置 sqlite3 执行
|
|
24
|
+
*/
|
|
25
|
+
export declare function runSql(config: SqlConfigInput, sql: string, options?: RunSqlOptions): Promise<SqlQueryResult>;
|
|
26
|
+
/** 读取连接配置中的方言默认端口 */
|
|
27
|
+
export declare function getDefaultSqlPort(dialect: SqlDialect): number | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 测试连接:执行一条 `SELECT 1`,验证网关可达、认证通过、数据库可访问。
|
|
30
|
+
* 不新增网关协议,能复用现有的 SQL 查询接口。
|
|
31
|
+
*/
|
|
32
|
+
export declare function testSqlConnection(config: SqlConfigInput, options?: RunSqlOptions): Promise<SqlTestResult>;
|
|
33
|
+
export interface SqlConnectionApiOptions {
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
/** 获取服务端保存的连接列表(不包含密码) */
|
|
37
|
+
export declare function listSqlConnections(config: SqlConfigInput, options?: SqlConnectionApiOptions): Promise<SqlConnectionProfile[]>;
|
|
38
|
+
/** 新建或更新连接配置;id 为空时新建 */
|
|
39
|
+
export declare function saveSqlConnection(config: SqlConfigInput, input: SqlConnectionSaveInput, id?: string, options?: SqlConnectionApiOptions): Promise<SqlConnectionProfile>;
|
|
40
|
+
/** 删除已保存的连接配置 */
|
|
41
|
+
export declare function deleteSqlConnection(config: SqlConfigInput, id: string, options?: SqlConnectionApiOptions): Promise<void>;
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.princess-python-editor-host,.vpe-root{--vpe-mono: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;--vpe-ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif}.vpe-root{--vpe-border: #e5e6eb;--vpe-bg: #ffffff;--vpe-toolbar-bg: #f7f8fa;--vpe-text: #1d2129;--vpe-text-secondary: #86909c;--vpe-hover: rgba(29, 33, 41, .08);--vpe-output-bg: #f7f8fa;--vpe-stdout: #1d2129;--vpe-stderr: #f53f3f;--vpe-system: #86909c;--vpe-accent: #165dff;--vpe-accent-hover: #4080ff;--vpe-danger: #f53f3f;--vpe-ok: #00b42a;--vpe-warn: #ff7d00;--vpe-err-line: rgba(245, 63, 63, .12);--vpe-error-btn-hover: #f76560;color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;overflow:hidden;border:1px solid var(--vpe-border);background:var(--vpe-bg);color:var(--vpe-text);font-family:var(--vpe-ui-font)}.vpe-root.vpe-dark{--vpe-border: #3e4451;--vpe-bg: #282c34;--vpe-toolbar-bg: #21252b;--vpe-text: #abb2bf;--vpe-text-secondary: #7f848e;--vpe-hover: rgba(255, 255, 255, .08);--vpe-output-bg: #21252b;--vpe-stdout: #abb2bf;--vpe-stderr: #e06c75;--vpe-system: #7f848e;--vpe-accent: #61afef;--vpe-accent-hover: #528bce;--vpe-danger: #e06c75;--vpe-ok: #98c379;--vpe-warn: #d19a66;--vpe-err-line: rgba(224, 108, 117, .18);--vpe-error-btn-hover: #c25d64;color-scheme:dark}.vpe-root *,.vpe-root *:before,.vpe-root *:after{box-sizing:border-box}.vpe-toolbar{display:flex;align-items:center;flex-shrink:0;gap:6px;padding:6px 10px;overflow-x:auto;background:var(--vpe-toolbar-bg);border-bottom:1px solid var(--vpe-border);scrollbar-width:none}.vpe-toolbar::-webkit-scrollbar{display:none}.vpe-btn{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;gap:6px;height:28px;min-width:28px;padding:0 8px;border:none;border-radius:4px;background:transparent;color:var(--vpe-text);cursor:pointer;font-size:12px;font-family:inherit;line-height:1}.vpe-btn svg{font-size:14px}.vpe-btn:hover:not(:disabled){background:var(--vpe-hover)}.vpe-btn:disabled{opacity:.45;cursor:not-allowed}.vpe-btn--primary{color:#fff;background:var(--vpe-accent)}.vpe-btn--primary:hover:not(:disabled){background:var(--vpe-accent-hover)}.vpe-btn--stop{color:#fff;background:var(--vpe-danger)}.vpe-btn--stop:hover:not(:disabled){background:var(--vpe-error-btn-hover)}.vpe-btn--sm{height:24px;min-width:24px;padding:0 6px}.vpe-btn--copied{color:var(--vpe-ok)}.vpe-divider{flex-shrink:0;width:1px;height:16px;margin:0 2px;background:var(--vpe-border)}.vpe-file{display:inline-flex;align-items:center;flex-shrink:1;gap:5px;height:26px;min-width:0;max-width:180px;padding:0 7px;border:1px solid transparent;border-radius:4px;color:var(--vpe-text-secondary);font-size:12px;line-height:1}.vpe-file:hover,.vpe-file:focus-within{border-color:var(--vpe-border);background:var(--vpe-bg)}.vpe-file svg{flex-shrink:0;font-size:13px}.vpe-file-input{flex:1 1 auto;width:108px;min-width:40px;padding:0;border:none;outline:none;background:transparent;color:var(--vpe-text);font-family:var(--vpe-mono);font-size:12px}.vpe-file-hidden{display:none}.vpe-spacer{flex:1}.vpe-status{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--vpe-text-secondary)}.vpe-status-dot{width:8px;height:8px;border-radius:50%;background:var(--vpe-text-secondary)}.vpe-status--loading .vpe-status-dot{background:var(--vpe-warn);animation:vpe-pulse 1.2s ease-in-out infinite}.vpe-status--ready .vpe-status-dot{background:var(--vpe-ok)}.vpe-status--running .vpe-status-dot{background:var(--vpe-accent);animation:vpe-pulse .8s ease-in-out infinite}@keyframes vpe-pulse{50%{opacity:.35}}.vpe-lang{flex-shrink:0;height:24px;padding:0 6px;border:1px solid var(--vpe-border);border-radius:999px;outline:none;background:transparent;color:var(--vpe-text-secondary);font-family:inherit;font-size:12px;cursor:pointer}.vpe-lang:hover:not(:disabled),.vpe-lang:focus{color:var(--vpe-text);border-color:var(--vpe-accent)}.vpe-lang:disabled{opacity:.45;cursor:not-allowed}.vpe-tabs{display:flex;align-items:center;flex-shrink:0;gap:2px;padding:4px 8px 0;overflow-x:auto;background:var(--vpe-toolbar-bg);border-bottom:1px solid var(--vpe-border);scrollbar-width:thin}.vpe-tab{display:inline-flex;align-items:center;flex-shrink:0;gap:6px;max-width:180px;height:30px;padding:0 6px 0 10px;border:1px solid transparent;border-bottom:none;border-radius:6px 6px 0 0;color:var(--vpe-text-secondary);font-size:12px;white-space:nowrap;cursor:pointer;-webkit-user-select:none;user-select:none}.vpe-tab:hover{color:var(--vpe-text);background:var(--vpe-hover)}.vpe-tab:focus-visible{outline:1px solid var(--vpe-accent);outline-offset:-1px}.vpe-tab--active{color:var(--vpe-text);background:var(--vpe-bg);border-color:var(--vpe-border)}.vpe-tab-name{min-width:0;overflow:hidden;text-overflow:ellipsis}.vpe-tab-dot{flex-shrink:0;width:6px;height:6px;border-radius:50%;background:var(--vpe-text-secondary)}.vpe-tab-dot--python{background:#3776ab}.vpe-tab-dot--sql{background:#e38c00}.vpe-tab-dot--javascript{background:#c9a900}.vpe-tab-dot--json{background:#86909c}.vpe-tab-close{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:18px;height:18px;padding:0;border:none;border-radius:3px;background:transparent;color:inherit;opacity:.55;cursor:pointer}.vpe-tab-close:hover:not(:disabled){opacity:1;background:var(--vpe-hover)}.vpe-tab-close:disabled{opacity:.3;cursor:not-allowed}.vpe-tab-close svg{font-size:11px}.vpe-tabs-add{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:26px;height:26px;margin:0 2px;padding:0;border:none;border-radius:4px;background:transparent;color:var(--vpe-text-secondary);cursor:pointer}.vpe-tabs-add:hover:not(:disabled){color:var(--vpe-text);background:var(--vpe-hover)}.vpe-tabs-add:disabled{opacity:.45;cursor:not-allowed}.vpe-tabs-add svg{font-size:14px}.vpe-editor{flex:1 1 auto;min-height:0;background:var(--vpe-bg)}.vpe-editor .cm-editor{height:100%}.vpe-root .cm-placeholder{color:var(--vpe-text-secondary);font-style:italic}.vpe-error-line{background:var(--vpe-err-line)}.vpe-init-error{height:100%;display:flex;align-items:center;justify-content:center;padding:16px;color:var(--vpe-stderr);font-size:13px;word-break:break-all}.vpe-output{display:flex;flex-direction:column;background:var(--vpe-output-bg);border-top:1px solid var(--vpe-border);flex-shrink:0}.vpe-output-head{display:flex;align-items:center;justify-content:space-between;padding:3px 8px 3px 12px;font-size:12px;color:var(--vpe-text-secondary);border-bottom:1px dashed var(--vpe-border);flex-shrink:0}.vpe-output-body{margin:0;padding:8px 12px;overflow:auto;flex:1;min-height:0;font-size:12px;font-family:var(--vpe-mono);line-height:1.7;white-space:pre-wrap;word-break:break-word}.vpe-line{display:block}.vpe-line--stdout{color:var(--vpe-stdout)}.vpe-line--stderr{color:var(--vpe-stderr)}.vpe-line--system{color:var(--vpe-system);font-style:italic}.vpe-empty{color:var(--vpe-text-secondary);font-style:italic}.vpe-fs-panel{position:absolute;top:46px;right:10px;z-index:20;display:flex;flex-direction:column;width:min(380px,calc(100% - 20px));max-height:min(420px,calc(100% - 60px));overflow:hidden;border:1px solid var(--vpe-border);border-radius:6px;background:var(--vpe-bg);box-shadow:0 8px 24px #00000029}.vpe-fs-head{display:flex;align-items:center;flex-shrink:0;gap:6px;padding:5px 8px 5px 12px;border-bottom:1px solid var(--vpe-border);background:var(--vpe-toolbar-bg);color:var(--vpe-text-secondary);font-size:12px}.vpe-fs-title{color:var(--vpe-text);font-weight:600}.vpe-fs-body{flex:1 1 auto;min-height:0;padding:4px;overflow:auto}.vpe-fs-empty{padding:20px 12px;color:var(--vpe-text-secondary);font-size:12px;line-height:1.6;text-align:center}.vpe-fs-item{display:flex;align-items:center;gap:8px;padding:4px 6px;border-radius:4px;font-size:12px}.vpe-fs-item:hover{background:var(--vpe-hover)}.vpe-fs-name{flex:1 1 auto;min-width:0;overflow:hidden;color:var(--vpe-text);font-family:var(--vpe-mono);text-overflow:ellipsis;white-space:nowrap}.vpe-fs-item--dir .vpe-fs-name{color:var(--vpe-text-secondary)}.vpe-fs-size{flex-shrink:0;color:var(--vpe-text-secondary)}
|
|
1
|
+
.princess-python-editor-host,.vpe-root{--vpe-mono: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;--vpe-ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif}.vpe-root{--vpe-border: #e5e6eb;--vpe-bg: #ffffff;--vpe-toolbar-bg: #f7f8fa;--vpe-text: #1d2129;--vpe-text-secondary: #86909c;--vpe-hover: rgba(29, 33, 41, .08);--vpe-output-bg: #f7f8fa;--vpe-stdout: #1d2129;--vpe-stderr: #f53f3f;--vpe-system: #86909c;--vpe-accent: #165dff;--vpe-accent-hover: #4080ff;--vpe-danger: #f53f3f;--vpe-ok: #00b42a;--vpe-warn: #ff7d00;--vpe-err-line: rgba(245, 63, 63, .12);--vpe-error-btn-hover: #f76560;color-scheme:light;position:relative;display:flex;flex-direction:column;min-height:0;overflow:hidden;border:1px solid var(--vpe-border);background:var(--vpe-bg);color:var(--vpe-text);font-family:var(--vpe-ui-font)}.vpe-root.vpe-dark{--vpe-border: #3e4451;--vpe-bg: #282c34;--vpe-toolbar-bg: #21252b;--vpe-text: #abb2bf;--vpe-text-secondary: #7f848e;--vpe-hover: rgba(255, 255, 255, .08);--vpe-output-bg: #21252b;--vpe-stdout: #abb2bf;--vpe-stderr: #e06c75;--vpe-system: #7f848e;--vpe-accent: #61afef;--vpe-accent-hover: #528bce;--vpe-danger: #e06c75;--vpe-ok: #98c379;--vpe-warn: #d19a66;--vpe-err-line: rgba(224, 108, 117, .18);--vpe-error-btn-hover: #c25d64;color-scheme:dark}.vpe-root *,.vpe-root *:before,.vpe-root *:after{box-sizing:border-box}.vpe-toolbar{display:flex;align-items:center;flex-shrink:0;gap:6px;padding:6px 10px;overflow-x:auto;background:var(--vpe-toolbar-bg);border-bottom:1px solid var(--vpe-border);scrollbar-width:none}.vpe-toolbar::-webkit-scrollbar{display:none}.vpe-btn{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;gap:3px;height:28px;min-width:28px;padding:0 8px;border:none;border-radius:4px;background:transparent;color:var(--vpe-text);cursor:pointer;font-size:12px;font-family:inherit;line-height:1}.vpe-btn svg{font-size:14px}.vpe-btn:hover:not(:disabled){background:var(--vpe-hover)}.vpe-btn:disabled{opacity:.45;cursor:not-allowed}.vpe-btn--primary{color:#fff;background:var(--vpe-accent)}.vpe-btn--primary:hover:not(:disabled){background:var(--vpe-accent-hover)}.vpe-btn--stop{color:#fff;background:var(--vpe-danger)}.vpe-btn--stop:hover:not(:disabled){background:var(--vpe-error-btn-hover)}.vpe-btn--sm{height:24px;min-width:24px;padding:0 6px}.vpe-btn--copied{color:var(--vpe-ok)}.vpe-divider{flex-shrink:0;width:1px;height:16px;margin:0 2px;background:var(--vpe-border)}.vpe-file{display:inline-flex;align-items:center;flex-shrink:1;gap:5px;height:26px;min-width:0;max-width:180px;padding:0 7px;border:1px solid transparent;border-radius:4px;color:var(--vpe-text-secondary);font-size:12px;line-height:1}.vpe-file:hover,.vpe-file:focus-within{border-color:var(--vpe-border);background:var(--vpe-bg)}.vpe-file svg{flex-shrink:0;font-size:13px}.vpe-file-input{flex:1 1 auto;width:108px;min-width:40px;padding:0;border:none;outline:none;background:transparent;color:var(--vpe-text);font-family:var(--vpe-mono);font-size:12px}.vpe-file-hidden{display:none}.vpe-spacer{flex:1}.vpe-status{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--vpe-text-secondary)}.vpe-status-dot{width:8px;height:8px;border-radius:50%;background:var(--vpe-text-secondary)}.vpe-status--loading .vpe-status-dot{background:var(--vpe-warn);animation:vpe-pulse 1.2s ease-in-out infinite}.vpe-status--ready .vpe-status-dot{background:var(--vpe-ok)}.vpe-status--running .vpe-status-dot{background:var(--vpe-accent);animation:vpe-pulse .8s ease-in-out infinite}@keyframes vpe-pulse{50%{opacity:.35}}.vpe-lang{flex-shrink:0;height:24px;padding:0 6px;border:1px solid var(--vpe-border);border-radius:999px;outline:none;background:transparent;color:var(--vpe-text-secondary);font-family:inherit;font-size:12px;cursor:pointer}.vpe-lang:hover:not(:disabled),.vpe-lang:focus{color:var(--vpe-text);border-color:var(--vpe-accent)}.vpe-lang:disabled{opacity:.45;cursor:not-allowed}.vpe-tabs{display:flex;align-items:center;flex-shrink:0;gap:2px;padding:4px 8px 0;overflow-x:auto;background:var(--vpe-toolbar-bg);border-bottom:1px solid var(--vpe-border);scrollbar-width:thin}.vpe-tab{display:inline-flex;align-items:center;flex-shrink:0;gap:6px;max-width:180px;height:30px;padding:0 6px 0 10px;border:1px solid transparent;border-bottom:none;border-radius:6px 6px 0 0;color:var(--vpe-text-secondary);font-size:12px;white-space:nowrap;cursor:pointer;-webkit-user-select:none;user-select:none}.vpe-tab:hover{color:var(--vpe-text);background:var(--vpe-hover)}.vpe-tab:focus-visible{outline:1px solid var(--vpe-accent);outline-offset:-1px}.vpe-tab--active{color:var(--vpe-text);background:var(--vpe-bg);border-color:var(--vpe-border)}.vpe-tab-name{min-width:0;overflow:hidden;text-overflow:ellipsis}.vpe-tab-dot{flex-shrink:0;width:6px;height:6px;border-radius:50%;background:var(--vpe-text-secondary)}.vpe-tab-dot--python{background:#3776ab}.vpe-tab-dot--sql{background:#e38c00}.vpe-tab-dot--javascript{background:#c9a900}.vpe-tab-dot--json{background:#86909c}.vpe-tab-close{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:18px;height:18px;padding:0;border:none;border-radius:3px;background:transparent;color:inherit;opacity:.55;cursor:pointer}.vpe-tab-close:hover:not(:disabled){opacity:1;background:var(--vpe-hover)}.vpe-tab-close:disabled{opacity:.3;cursor:not-allowed}.vpe-tab-close svg{font-size:11px}.vpe-tabs-add{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:26px;height:26px;margin:0 2px;padding:0;border:none;border-radius:4px;background:transparent;color:var(--vpe-text-secondary);cursor:pointer}.vpe-tabs-add:hover:not(:disabled){color:var(--vpe-text);background:var(--vpe-hover)}.vpe-tabs-add:disabled{opacity:.45;cursor:not-allowed}.vpe-tabs-add svg{font-size:14px}.vpe-editor{flex:1 1 auto;min-height:0;background:var(--vpe-bg)}.vpe-editor .cm-editor{height:100%}.vpe-root .cm-placeholder{color:var(--vpe-text-secondary);font-style:italic}.vpe-error-line{background:var(--vpe-err-line)}.vpe-init-error{height:100%;display:flex;align-items:center;justify-content:center;padding:16px;color:var(--vpe-stderr);font-size:13px;word-break:break-all}.vpe-output-resizer{position:relative;flex:0 0 6px;background:var(--vpe-toolbar-bg);cursor:ns-resize;touch-action:none;-webkit-user-select:none;user-select:none}.vpe-output-resizer:before{content:"";position:absolute;top:50%;left:50%;width:32px;height:2px;transform:translate(-50%,-50%);border-radius:1px;background:var(--vpe-border)}.vpe-output-resizer:hover,.vpe-output-resizer--active{background:var(--vpe-hover)}.vpe-output-resizer:hover:before,.vpe-output-resizer--active:before{background:var(--vpe-accent)}.vpe-output-resizer:focus-visible{outline:1px solid var(--vpe-accent);outline-offset:-1px}.vpe-output{display:flex;flex-direction:column;background:var(--vpe-output-bg);border-top:1px solid var(--vpe-border);flex-shrink:0}.vpe-output-head{display:flex;align-items:center;justify-content:space-between;padding:3px 8px 3px 12px;font-size:12px;color:var(--vpe-text-secondary);border-bottom:1px dashed var(--vpe-border);flex-shrink:0}.vpe-output-body{margin:0;padding:8px 12px;overflow:auto;flex:1;min-height:0;font-size:12px;font-family:var(--vpe-mono);line-height:1.7;white-space:pre-wrap;word-break:break-word}.vpe-line{display:block}.vpe-line--stdout{color:var(--vpe-stdout)}.vpe-line--stderr{color:var(--vpe-stderr)}.vpe-line--system{color:var(--vpe-system);font-style:italic}.vpe-empty{color:var(--vpe-text-secondary);font-style:italic}.vpe-terminal-input{display:flex;align-items:center;flex-shrink:0;gap:6px;padding:5px 10px;border-top:1px solid var(--vpe-border);background:var(--vpe-toolbar-bg)}.vpe-terminal-prompt{color:var(--vpe-accent);font-family:var(--vpe-mono);font-size:13px;font-weight:600}.vpe-terminal-field{flex:1 1 auto;min-width:0;height:24px;padding:0 6px;border:1px solid var(--vpe-border);border-radius:4px;outline:none;background:var(--vpe-bg);color:var(--vpe-text);font-family:var(--vpe-mono);font-size:12px}.vpe-terminal-field:focus{border-color:var(--vpe-accent)}.vpe-fs-panel,.vpe-sql-panel,.vpe-sql-manager-panel{position:absolute;top:46px;right:10px;z-index:20;display:flex;flex-direction:column;width:min(380px,calc(100% - 20px));max-height:min(420px,calc(100% - 60px));overflow:hidden;border:1px solid var(--vpe-border);border-radius:6px;background:var(--vpe-bg);box-shadow:0 8px 24px #00000029}.vpe-fs-head{display:flex;align-items:center;flex-shrink:0;gap:6px;padding:5px 8px 5px 12px;border-bottom:1px solid var(--vpe-border);background:var(--vpe-toolbar-bg);color:var(--vpe-text-secondary);font-size:12px}.vpe-fs-title{color:var(--vpe-text);font-weight:600}.vpe-fs-body{flex:1 1 auto;min-height:0;padding:4px;overflow:auto}.vpe-fs-empty{padding:20px 12px;color:var(--vpe-text-secondary);font-size:12px;line-height:1.6;text-align:center}.vpe-fs-item{display:flex;align-items:center;gap:8px;padding:4px 6px;border-radius:4px;font-size:12px}.vpe-fs-item:hover{background:var(--vpe-hover)}.vpe-fs-name{flex:1 1 auto;min-width:0;overflow:hidden;color:var(--vpe-text);font-family:var(--vpe-mono);text-overflow:ellipsis;white-space:nowrap}.vpe-fs-item--dir .vpe-fs-name{color:var(--vpe-text-secondary)}.vpe-fs-size{flex-shrink:0;color:var(--vpe-text-secondary)}.vpe-sql-body{flex:1 1 auto;min-height:0;padding:10px 12px 12px;overflow:auto}.vpe-sql-field{display:flex;flex-direction:column;gap:4px}.vpe-sql-body>.vpe-sql-field+.vpe-sql-field,.vpe-sql-body>.vpe-sql-field+.vpe-sql-row,.vpe-sql-body>.vpe-sql-row+.vpe-sql-field,.vpe-sql-body>.vpe-sql-row+.vpe-sql-row{margin-top:10px}.vpe-sql-row{display:flex;gap:8px}.vpe-sql-field--grow{flex:1 1 0;min-width:0}.vpe-sql-connection{max-width:180px}.vpe-sql-label{color:var(--vpe-text-secondary);font-size:12px}.vpe-sql-manager-body{flex:1 1 auto;min-height:0;padding:4px;overflow:auto}.vpe-sql-manager-item{display:flex;align-items:center;gap:6px;padding:6px;border-radius:4px}.vpe-sql-manager-item:hover{background:var(--vpe-hover)}.vpe-sql-manager-main{display:flex;flex:1 1 auto;flex-direction:column;gap:2px;min-width:0}.vpe-sql-manager-name{overflow:hidden;color:var(--vpe-text);font-size:12px;text-overflow:ellipsis;white-space:nowrap}.vpe-sql-manager-meta{overflow:hidden;color:var(--vpe-text-secondary);font-size:11px;text-overflow:ellipsis;white-space:nowrap}.vpe-sql-input{width:100%;height:28px;padding:0 8px;border:1px solid var(--vpe-border);border-radius:4px;outline:none;background:var(--vpe-bg);color:var(--vpe-text);font-family:inherit;font-size:12px}.vpe-sql-input:focus{border-color:var(--vpe-accent)}.vpe-sql-hint{margin:10px 0 0;color:var(--vpe-text-secondary);font-size:12px;line-height:1.6}.vpe-sql-hint--error{color:var(--vpe-danger)}.vpe-sql-hint--ok{color:var(--vpe-ok)}.vpe-sql-actions{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin-top:12px;padding-top:10px;border-top:1px solid var(--vpe-border)}.vpe-sql-test{min-width:0;font-size:12px;line-height:1.5;word-break:break-word}.vpe-sql-test--ok{color:var(--vpe-ok)}.vpe-sql-test--err{color:var(--vpe-danger)}.vpe-output-main{display:flex;flex:1 1 auto;flex-direction:column;min-height:0}.vpe-sql-results{flex:0 1 auto;max-height:70%;overflow:auto;border-bottom:1px solid var(--vpe-border)}.vpe-sql-result+.vpe-sql-result{border-top:1px dashed var(--vpe-border)}.vpe-sql-result-head{position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 12px;color:var(--vpe-text-secondary);font-size:12px;background:var(--vpe-toolbar-bg)}.vpe-sql-table-wrap{overflow:auto}.vpe-sql-table{width:100%;border-collapse:collapse;font-family:var(--vpe-mono);font-size:12px}.vpe-sql-table th,.vpe-sql-table td{padding:4px 10px;border-right:1px solid var(--vpe-border);border-bottom:1px solid var(--vpe-border);text-align:left;white-space:nowrap}.vpe-sql-table th{position:sticky;top:0;background:var(--vpe-output-bg);color:var(--vpe-text-secondary);font-weight:600}.vpe-sql-table tr:last-child td{border-bottom:none}.vpe-sql-table td.vpe-sql-null{color:var(--vpe-text-secondary);font-style:italic}.vpe-sql-empty,.vpe-sql-affected{padding:8px 12px;color:var(--vpe-text-secondary);font-size:12px;font-style:italic}
|
package/dist/types.d.ts
CHANGED
|
@@ -13,6 +13,54 @@ export interface EditorFile {
|
|
|
13
13
|
}
|
|
14
14
|
/** Pyodide 运行器状态机 */
|
|
15
15
|
export type PyodideStatus = 'idle' | 'loading' | 'ready' | 'running';
|
|
16
|
+
/** Python 运行环境:浏览器内 Pyodide,或服务端真实 Python */
|
|
17
|
+
export type PythonRuntime = 'browser' | 'server';
|
|
18
|
+
/** 服务端 Python 执行错误 */
|
|
19
|
+
export interface PythonRuntimeError {
|
|
20
|
+
/** 异常类型,如 ZeroDivisionError、Timeout、PythonUnavailable */
|
|
21
|
+
type: string;
|
|
22
|
+
/** 异常消息 */
|
|
23
|
+
message: string;
|
|
24
|
+
/** 出错行号(1 起,可能缺失) */
|
|
25
|
+
line?: number;
|
|
26
|
+
/** 完整 traceback */
|
|
27
|
+
traceback?: string;
|
|
28
|
+
}
|
|
29
|
+
/** 服务端 Python 执行结果 */
|
|
30
|
+
export interface PythonRuntimeResult {
|
|
31
|
+
ok: boolean;
|
|
32
|
+
stdout: string;
|
|
33
|
+
stderr: string;
|
|
34
|
+
/** 进程退出码,超时时缺失 */
|
|
35
|
+
exitCode?: number;
|
|
36
|
+
durationMs: number;
|
|
37
|
+
error?: PythonRuntimeError;
|
|
38
|
+
}
|
|
39
|
+
/** 服务端交互式 Python 会话状态 */
|
|
40
|
+
export type PythonSessionState = 'running' | 'waiting' | 'exited';
|
|
41
|
+
/** 服务端交互式 Python 会话的增量结果 */
|
|
42
|
+
export interface PythonSessionResult {
|
|
43
|
+
/** 会话 id */
|
|
44
|
+
sessionId: string;
|
|
45
|
+
/** running:继续执行;waiting:等待 input();exited:已结束 */
|
|
46
|
+
state: PythonSessionState;
|
|
47
|
+
/** 自上次轮询以来的标准输出增量 */
|
|
48
|
+
stdout: string;
|
|
49
|
+
/** 自上次轮询以来的标准错误增量 */
|
|
50
|
+
stderr: string;
|
|
51
|
+
/** 进程退出码,仅 exited 时存在 */
|
|
52
|
+
exitCode?: number;
|
|
53
|
+
/** 会话已运行时长(毫秒) */
|
|
54
|
+
durationMs?: number;
|
|
55
|
+
error?: PythonRuntimeError;
|
|
56
|
+
}
|
|
57
|
+
/** 创建交互式 Python 会话的输入 */
|
|
58
|
+
export interface PythonSessionStartInput {
|
|
59
|
+
/** 会话启动时预先写入 stdin 的文本 */
|
|
60
|
+
stdin?: string;
|
|
61
|
+
/** 会话最长运行秒数 */
|
|
62
|
+
timeoutSeconds?: number;
|
|
63
|
+
}
|
|
16
64
|
/** 输出行流类型:stdout / stderr / system(系统消息) */
|
|
17
65
|
export type OutputStream = 'stdout' | 'stderr' | 'system';
|
|
18
66
|
/** 输出面板中的一行 */
|
|
@@ -113,3 +161,151 @@ export interface FsDownloadEvent {
|
|
|
113
161
|
/** 下载时使用的文件名 */
|
|
114
162
|
name: string;
|
|
115
163
|
}
|
|
164
|
+
/** 服务端已保存文件的元信息(不含内容) */
|
|
165
|
+
export interface ServerFile {
|
|
166
|
+
/** 文件标识,当前与文件名一致 */
|
|
167
|
+
id: string;
|
|
168
|
+
/** 文件名 */
|
|
169
|
+
name: string;
|
|
170
|
+
/** 文件大小(字节) */
|
|
171
|
+
size: number;
|
|
172
|
+
/** 最后更新时间(ISO 字符串) */
|
|
173
|
+
updatedAt?: string;
|
|
174
|
+
}
|
|
175
|
+
/** 服务端文件的完整内容 */
|
|
176
|
+
export interface ServerFileDetail extends ServerFile {
|
|
177
|
+
content: string;
|
|
178
|
+
}
|
|
179
|
+
/** 保存服务端文件的输入,同名文件会被覆盖 */
|
|
180
|
+
export interface ServerFileSaveInput {
|
|
181
|
+
name: string;
|
|
182
|
+
content: string;
|
|
183
|
+
}
|
|
184
|
+
/** 支持的 SQL 方言(用于连接配置与默认端口,不限制执行器实现) */
|
|
185
|
+
export type SqlDialect = 'sqlite' | 'mysql' | 'postgresql' | 'sqlserver' | 'oracle' | 'clickhouse' | 'other';
|
|
186
|
+
/**
|
|
187
|
+
* SQL 执行模式:
|
|
188
|
+
* - sqlite:在浏览器内通过 Pyodide 的 sqlite3 执行,无需服务端
|
|
189
|
+
* - http:把连接信息与 SQL 发送到后端网关执行(可对接 MySQL/PostgreSQL 等)
|
|
190
|
+
*/
|
|
191
|
+
export type SqlMode = 'sqlite' | 'http';
|
|
192
|
+
/** SQL 连接信息(http 模式下原样传给执行器 / 后端网关) */
|
|
193
|
+
export interface SqlConnection {
|
|
194
|
+
/** 数据库类型 */
|
|
195
|
+
dialect: SqlDialect;
|
|
196
|
+
/** 主机地址(sqlite 模式忽略) */
|
|
197
|
+
host?: string;
|
|
198
|
+
/** 端口(sqlite 模式忽略) */
|
|
199
|
+
port?: number;
|
|
200
|
+
/** 用户名(sqlite 模式忽略) */
|
|
201
|
+
user?: string;
|
|
202
|
+
/** 密码(sqlite 模式忽略) */
|
|
203
|
+
password?: string;
|
|
204
|
+
/** 数据库名;sqlite 模式为数据库文件路径,默认 :memory: */
|
|
205
|
+
database?: string;
|
|
206
|
+
/** 透传给执行器的额外连接参数,如 ssl、charset */
|
|
207
|
+
options?: Record<string, string | number | boolean>;
|
|
208
|
+
}
|
|
209
|
+
/** SQL 配置(组件内部保存完整配置,宿主可传入部分字段) */
|
|
210
|
+
export interface SqlConfig {
|
|
211
|
+
mode: SqlMode;
|
|
212
|
+
connection: SqlConnection;
|
|
213
|
+
/** 已保存连接的 id;设置后后端优先使用服务端保存的连接信息 */
|
|
214
|
+
connectionId?: string;
|
|
215
|
+
/** http 模式下的执行端点,为空时无法执行 */
|
|
216
|
+
endpoint?: string;
|
|
217
|
+
/** http 模式附加的请求头 */
|
|
218
|
+
headers?: Record<string, string>;
|
|
219
|
+
/** 单条语句最多返回行数,默认 200 */
|
|
220
|
+
maxRows?: number;
|
|
221
|
+
/** http 请求超时(毫秒),默认 30000 */
|
|
222
|
+
timeoutMs?: number;
|
|
223
|
+
}
|
|
224
|
+
/** SqlConfig 的输入形态:所有字段可选,便于通过 props 局部覆盖 */
|
|
225
|
+
export interface SqlConfigInput {
|
|
226
|
+
mode?: SqlMode;
|
|
227
|
+
connection?: Partial<SqlConnection>;
|
|
228
|
+
/** 已保存连接的 id */
|
|
229
|
+
connectionId?: string;
|
|
230
|
+
endpoint?: string;
|
|
231
|
+
headers?: Record<string, string>;
|
|
232
|
+
maxRows?: number;
|
|
233
|
+
timeoutMs?: number;
|
|
234
|
+
}
|
|
235
|
+
/** 服务端保存的 SQL 连接配置(不包含密码) */
|
|
236
|
+
export interface SqlConnectionProfile {
|
|
237
|
+
id: string;
|
|
238
|
+
name: string;
|
|
239
|
+
dialect: SqlDialect;
|
|
240
|
+
host?: string;
|
|
241
|
+
port?: number;
|
|
242
|
+
user?: string;
|
|
243
|
+
/** 是否已保存密码 */
|
|
244
|
+
hasPassword: boolean;
|
|
245
|
+
database?: string;
|
|
246
|
+
options?: Record<string, string | number | boolean>;
|
|
247
|
+
createdAt?: string;
|
|
248
|
+
updatedAt?: string;
|
|
249
|
+
}
|
|
250
|
+
/** 新建或更新连接配置的输入 */
|
|
251
|
+
export interface SqlConnectionSaveInput {
|
|
252
|
+
name: string;
|
|
253
|
+
dialect: SqlDialect;
|
|
254
|
+
host?: string;
|
|
255
|
+
port?: number;
|
|
256
|
+
user?: string;
|
|
257
|
+
/** 更新时留空表示保持原密码 */
|
|
258
|
+
password?: string;
|
|
259
|
+
database?: string;
|
|
260
|
+
options?: Record<string, string | number | boolean>;
|
|
261
|
+
}
|
|
262
|
+
/** 结果单元格值(JSON 安全的基本类型) */
|
|
263
|
+
export type SqlValue = string | number | boolean | null;
|
|
264
|
+
/** 一个 SQL 结果集(多语句时按顺序返回多个) */
|
|
265
|
+
export interface SqlResultSet {
|
|
266
|
+
/** 列名 */
|
|
267
|
+
columns: string[];
|
|
268
|
+
/** 数据行;无结果集时为空数组 */
|
|
269
|
+
rows: SqlValue[][];
|
|
270
|
+
/** 受影响行数(INSERT / UPDATE / DELETE) */
|
|
271
|
+
affectedRows?: number;
|
|
272
|
+
/** 是否因 maxRows 被截断 */
|
|
273
|
+
truncated?: boolean;
|
|
274
|
+
}
|
|
275
|
+
/** SQL 执行错误 */
|
|
276
|
+
export interface SqlError {
|
|
277
|
+
/** 错误类型,如 OperationalError、NoEndpoint */
|
|
278
|
+
type: string;
|
|
279
|
+
/** 错误消息 */
|
|
280
|
+
message: string;
|
|
281
|
+
/** 数据库或网关返回的错误码 */
|
|
282
|
+
code?: string | number;
|
|
283
|
+
}
|
|
284
|
+
/** SQL 执行结果 */
|
|
285
|
+
export interface SqlQueryResult {
|
|
286
|
+
ok: boolean;
|
|
287
|
+
/** 按语句顺序返回的结果集 */
|
|
288
|
+
results?: SqlResultSet[];
|
|
289
|
+
error?: SqlError;
|
|
290
|
+
durationMs: number;
|
|
291
|
+
}
|
|
292
|
+
/** SQL 连接测试结果 */
|
|
293
|
+
export interface SqlTestResult {
|
|
294
|
+
ok: boolean;
|
|
295
|
+
/** 面向用户的结果描述 */
|
|
296
|
+
message: string;
|
|
297
|
+
durationMs: number;
|
|
298
|
+
}
|
|
299
|
+
/** 自定义 SQL 执行器的请求负载 */
|
|
300
|
+
export interface SqlExecuteRequest {
|
|
301
|
+
sql: string;
|
|
302
|
+
connection: SqlConnection;
|
|
303
|
+
maxRows: number;
|
|
304
|
+
}
|
|
305
|
+
/** 自定义 SQL 执行器的上下文 */
|
|
306
|
+
export interface SqlExecuteContext {
|
|
307
|
+
/** 用户点击“停止”时触发 */
|
|
308
|
+
signal?: AbortSignal;
|
|
309
|
+
}
|
|
310
|
+
/** 自定义 SQL 执行器:传入请求,返回标准化结果 */
|
|
311
|
+
export type SqlExecutor = (request: SqlExecuteRequest, context?: SqlExecuteContext) => Promise<SqlQueryResult>;
|
package/package.json
CHANGED