princess-python-editor 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wangzihan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,355 @@
1
- # Temporary Holding Version
1
+ # princess-python-editor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue 3 + TypeScript 的 Python 代码编辑器组件:基于 CodeMirror 6 的编辑体验,通过 Pyodide 在浏览器端执行 Python,并支持实时语法检查。
4
+
5
+ [![npm version](https://img.shields.io/npm/v/princess-python-editor.svg)](https://www.npmjs.com/package/princess-python-editor)
6
+ [![license](https://img.shields.io/npm/l/princess-python-editor.svg)](LICENSE)
7
+
8
+ ## 特性
9
+
10
+ - **CodeMirror 6 编辑**:语法高亮、自动补全、括号匹配、撤销重做、错误行高亮
11
+ - **浏览器端执行 Python**:基于 Pyodide(CPython WASM),无需后端,支持顶层 `await`
12
+ - **实时语法检查**:停止输入后自动检查 Python 语法,可配置防抖时间或关闭
13
+ - **多文件 Tab**:新建、打开本地文件、下载、复制、清空、切换、关闭,文件名可编辑
14
+ - **多语言编辑**:Python、SQL、JavaScript、JSON 的语法高亮与补全
15
+ - **输出面板**:stdout / stderr 分色展示,自动滚动,可清空
16
+ - **主题与只读**:浅色 / 深色主题,只读模式,工具栏与输出面板均可按需显示
17
+ - **第三方包安装**:优先使用 Pyodide 内置 wheel,缺失时回退 micropip
18
+ - **可中断执行**:运行长时间计算时可停止,Worker 自动重建
19
+ - **Headless 能力**:额外导出 `usePyodide`、`PyodideRunner` 等 API,可在无编辑器场景下执行 Python
20
+
21
+ ## 环境要求
22
+
23
+ - Vue `>= 3.3.0`
24
+ - 支持 WebAssembly 与 Web Worker 的现代浏览器
25
+ - 首次加载 Pyodide 需要访问 CDN(默认 jsDelivr),也可以自托管
26
+
27
+ > 组件执行代码时运行在 Web Worker 中,无法直接访问页面 DOM。
28
+
29
+ ## 安装
30
+
31
+ ```bash
32
+ pnpm add princess-python-editor
33
+ # 或
34
+ npm install princess-python-editor
35
+ # 或
36
+ yarn add princess-python-editor
37
+ ```
38
+
39
+ ## 快速开始
40
+
41
+ 在应用入口引入组件样式:
42
+
43
+ ```ts
44
+ // main.ts
45
+ import 'princess-python-editor/style.css'
46
+ ```
47
+
48
+ 在页面中使用:
49
+
50
+ ```vue
51
+ <script setup lang="ts">
52
+ import { ref } from 'vue'
53
+ import { PythonEditor } from 'princess-python-editor'
54
+ import type { EditorLanguage, PyError, RunResult } from 'princess-python-editor'
55
+
56
+ const code = ref(`# 点击工具栏“运行”或按 Ctrl+Enter
57
+ def greet(name):
58
+ return f"Hello, {name}!"
59
+
60
+ print(greet("Pyodide"))
61
+ `)
62
+ const fileName = ref('main.py')
63
+ const language = ref<EditorLanguage>('python')
64
+
65
+ function onRunFinish(result: RunResult) {
66
+ console.log(result.ok ? `执行完成,耗时 ${result.durationMs}ms` : '执行失败')
67
+ }
68
+
69
+ function onRunError(error: PyError) {
70
+ console.error(error.type, error.message)
71
+ }
72
+ </script>
73
+
74
+ <template>
75
+ <PythonEditor
76
+ v-model="code"
77
+ v-model:file-name="fileName"
78
+ v-model:language="language"
79
+ height="100%"
80
+ :output-height="220"
81
+ placeholder="# 在这里编写 Python 代码"
82
+ @run-finish="onRunFinish"
83
+ @run-error="onRunError"
84
+ />
85
+ </template>
86
+ ```
87
+
88
+ > `height="100%"` 需要父容器具有明确高度;也可以直接传入数字(按 px 处理)。
89
+
90
+ ### 双向绑定
91
+
92
+ | 绑定 | 类型 | 说明 |
93
+ | ------------------- | ---------------- | ------------------------------------ |
94
+ | `v-model` | `string` | 当前 Tab 的代码内容 |
95
+ | `v-model:file-name` | `string` | 当前 Tab 的文件名,切换 Tab 时同步 |
96
+ | `v-model:language` | `EditorLanguage` | 当前 Tab 的语法类型,切换 Tab 时同步 |
97
+
98
+ ## Props
99
+
100
+ | 属性 | 类型 | 默认值 | 说明 |
101
+ | ------------------ | ------------------- | ----------- | -------------------------------------------------------- |
102
+ | `modelValue` | `string` | `''` | 当前 Tab 的代码内容,支持 `v-model` |
103
+ | `theme` | `'light' \| 'dark'` | `'light'` | 编辑器主题 |
104
+ | `height` | `number \| string` | `520` | 组件整体高度(含工具栏、Tab 与输出面板),数字按 px 处理 |
105
+ | `outputHeight` | `number \| string` | `180` | 输出面板高度 |
106
+ | `placeholder` | `string` | `''` | 内容为空时的占位提示 |
107
+ | `readOnly` | `boolean` | `false` | 只读模式,同时禁用文件操作与语言切换 |
108
+ | `autofocus` | `boolean` | `false` | 挂载后自动聚焦编辑器 |
109
+ | `showToolbar` | `boolean` | `true` | 是否显示工具栏 |
110
+ | `showTabs` | `boolean` | `true` | 是否显示文件 Tab 栏 |
111
+ | `showOutput` | `boolean` | `true` | 是否显示输出面板 |
112
+ | `clearOutputOnRun` | `boolean` | `true` | 运行前是否清空输出 |
113
+ | `lintDelay` | `number` | `600` | 语法检查防抖毫秒数 |
114
+ | `disableLint` | `boolean` | `false` | 关闭实时语法检查 |
115
+ | `preload` | `boolean` | `false` | 挂载后立即预加载 Pyodide |
116
+ | `pyodideUrl` | `string` | 见下文 | 自定义 Pyodide `indexURL`,必须以 `/` 结尾 |
117
+ | `fileName` | `string` | `'main.py'` | 初始文件名,支持 `v-model:file-name` |
118
+ | `language` | `EditorLanguage` | `'python'` | 初始语法类型,支持 `v-model:language` |
119
+
120
+ ## 事件
121
+
122
+ | 事件 | 参数 | 说明 |
123
+ | ------------------- | ------------------------------------------------ | -------------------------------------------------------- |
124
+ | `ready` | — | Pyodide 加载完成 |
125
+ | `status-change` | `PyodideStatus` | 运行器状态变化:`idle` / `loading` / `ready` / `running` |
126
+ | `run-start` | — | 开始执行 |
127
+ | `run-output` | `{ stream: 'stdout' \| 'stderr'; text: string }` | 执行期间的实时输出 |
128
+ | `run-error` | `PyError` | 执行过程中抛出 Python 异常 |
129
+ | `run-finish` | `RunResult` | 本次执行结束(成功、失败或中断) |
130
+ | `load-error` | `string` | Pyodide 加载失败 |
131
+ | `new-file` | `EditorFile` | 新建文件 |
132
+ | `file-switch` | `EditorFile` | 切换文件 |
133
+ | `file-close` | `EditorFile` | 关闭文件 |
134
+ | `copy` | `string` | 复制代码成功 |
135
+ | `download` | `string` | 下载文件,参数为最终文件名 |
136
+ | `file-open` | `FileOpenEvent` | 打开本地文件 |
137
+ | `update:modelValue` | `string` | 代码内容变化 |
138
+ | `update:fileName` | `string` | 文件名变化 |
139
+ | `update:language` | `EditorLanguage` | 语法类型变化 |
140
+
141
+ ## 实例方法
142
+
143
+ 通过模板 `ref` 调用:
144
+
145
+ ```vue
146
+ <script setup lang="ts">
147
+ import { ref } from 'vue'
148
+ import { PythonEditor } from 'princess-python-editor'
149
+
150
+ const editorRef = ref<InstanceType<typeof PythonEditor> | null>(null)
151
+
152
+ async function runAndInstall() {
153
+ editorRef.value?.run()
154
+ editorRef.value?.setCode('print("hello")')
155
+ const result = await editorRef.value?.install(['numpy'])
156
+ console.log(result?.ok)
157
+ }
158
+ </script>
159
+
160
+ <template>
161
+ <PythonEditor ref="editorRef" v-model="code" />
162
+ </template>
163
+ ```
164
+
165
+ | 方法 | 返回值 | 说明 |
166
+ | ------------------- | ------------------------------ | ------------------------------------------------------ |
167
+ | `run()` | `void` | 运行当前 Python 文件 |
168
+ | `stop()` | `void` | 中断执行(终止并重建 Worker,Python 运行时状态会丢失) |
169
+ | `clearOutput()` | `void` | 清空输出面板 |
170
+ | `clearCode()` | `void` | 清空当前文件内容(保留输出) |
171
+ | `newFile()` | `void` | 新建文件并切换过去 |
172
+ | `switchFile(id)` | `void` | 切换到指定文件 |
173
+ | `closeFile(id)` | `void` | 关闭指定文件(至少保留一个) |
174
+ | `copyCode()` | `Promise<boolean>` | 复制当前代码到剪贴板 |
175
+ | `download()` | `string` | 下载当前文件,返回最终文件名 |
176
+ | `openFile()` | `void` | 打开本地文件选择框 |
177
+ | `focus()` | `void` | 聚焦编辑器 |
178
+ | `install(packages)` | `Promise<InstallResult>` | 安装第三方包 |
179
+ | `checkSyntax()` | `Promise<SyntaxIssue \| null>` | 检查当前内容语法,未就绪时返回 `null` |
180
+ | `getEditorView()` | `EditorView \| null` | 获取 CodeMirror `EditorView` 实例 |
181
+ | `getCode()` | `string` | 获取当前代码 |
182
+ | `setCode(code)` | `void` | 替换当前代码(保留撤销历史) |
183
+ | `getFiles()` | `EditorFile[]` | 获取全部文件快照 |
184
+ | `getActiveFile()` | `EditorFile` | 获取当前文件快照 |
185
+
186
+ ## 语言与执行说明
187
+
188
+ `language` 可选值为 `'python' | 'sql' | 'javascript' | 'json'`,用于语法高亮、补全与文件扩展名推断。
189
+
190
+ **只有 Python 文件可以执行。** 切换到 SQL / JavaScript / JSON 后,运行按钮会被禁用,`Ctrl+Enter` 也只会在输出面板提示“仅支持执行 Python 代码”。这些语言目前是纯编辑模式,不具备运行时。
191
+
192
+ ## Pyodide 配置
193
+
194
+ ### 默认 CDN
195
+
196
+ 默认从 jsDelivr 加载 Pyodide `v0.27.2`:
197
+
198
+ ```ts
199
+ import { DEFAULT_PYODIDE_URL } from 'princess-python-editor'
200
+ // https://cdn.jsdelivr.net/pyodide/v0.27.2/full/
201
+ ```
202
+
203
+ ### 自托管
204
+
205
+ 将 Pyodide 发行包放到静态资源目录,然后传入以 `/` 结尾的 URL:
206
+
207
+ ```vue
208
+ <PythonEditor v-model="code" pyodide-url="/pyodide/v0.27.2/full/" />
209
+ ```
210
+
211
+ > 底层运行器是模块级单例,`pyodideUrl` 只在页面中第一次初始化前生效;之后再传入会被忽略并输出警告。
212
+
213
+ ### 安装第三方包
214
+
215
+ ```ts
216
+ const result = await editorRef.value?.install(['numpy', 'pandas'])
217
+ ```
218
+
219
+ 优先使用 Pyodide 内置 wheel,未内置的包会回退到 micropip 从 PyPI 下载。
220
+
221
+ ### CSP 提示
222
+
223
+ 组件通过 Blob URL 创建 Worker,并在 Worker 中加载 Pyodide。使用严格 CSP 时需要允许:
224
+
225
+ - `worker-src blob:`
226
+ - Pyodide 资源地址对应的 `script-src` / `connect-src`
227
+
228
+ ## 无编辑器使用 Python
229
+
230
+ `usePyodide` 与编辑器共享同一个 Pyodide 实例:
231
+
232
+ ```ts
233
+ import { usePyodide } from 'princess-python-editor'
234
+
235
+ const { status, version, outputs, runPython, install, checkSyntax, interrupt, clearOutputs } =
236
+ usePyodide({ preload: true })
237
+
238
+ const result = await runPython('print(1 + 1)')
239
+ console.log(result.ok, result.value, result.durationMs)
240
+ ```
241
+
242
+ 返回内容包括:
243
+
244
+ | 字段 | 类型 | 说明 |
245
+ | ------------------- | ------------------------------ | ------------ |
246
+ | `status` | `Ref<PyodideStatus>` | 运行器状态 |
247
+ | `version` | `Ref<string>` | Pyodide 版本 |
248
+ | `outputs` | `Ref<OutputLine[]>` | 输出行 |
249
+ | `runPython(code)` | `Promise<RunResult>` | 执行代码 |
250
+ | `install(packages)` | `Promise<InstallResult>` | 安装包 |
251
+ | `checkSyntax(code)` | `Promise<SyntaxIssue \| null>` | 语法检查 |
252
+ | `interrupt()` | `void` | 中断执行 |
253
+ | `clearOutputs()` | `void` | 清空输出 |
254
+ | `ready()` | `Promise<void>` | 等待就绪 |
255
+
256
+ ## 主题定制
257
+
258
+ 组件样式通过 CSS 变量控制,可在 `.vpe-root` 上覆盖:
259
+
260
+ ```css
261
+ .vpe-root {
262
+ --vpe-accent: #165dff;
263
+ --vpe-bg: #ffffff;
264
+ --vpe-text: #1d2129;
265
+ --vpe-border: #e5e6eb;
266
+ --vpe-output-bg: #f7f8fa;
267
+ --vpe-stderr: #f53f3f;
268
+ }
269
+ ```
270
+
271
+ 深色主题使用 `.vpe-root.vpe-dark` 下的变量,覆盖时注意同时处理两种主题。
272
+
273
+ ## 类型导出
274
+
275
+ ```ts
276
+ import type {
277
+ EditorLanguage,
278
+ EditorFile,
279
+ PyodideStatus,
280
+ OutputStream,
281
+ OutputLine,
282
+ PyError,
283
+ SyntaxIssue,
284
+ RunResult,
285
+ InstallResult,
286
+ RunOutputEvent,
287
+ FileOpenEvent,
288
+ PythonEditorProps,
289
+ } from 'princess-python-editor'
290
+ ```
291
+
292
+ ## 本地开发
293
+
294
+ ```bash
295
+ pnpm install
296
+ pnpm dev # 启动 playground(含 Vue DevTools)
297
+ pnpm build # 构建组件库到 dist
298
+ pnpm lint
299
+ pnpm format
300
+ pnpm typecheck
301
+ ```
302
+
303
+ ## 发布到 npm
304
+
305
+ 发布前确认:
306
+
307
+ 1. 包名 `princess-python-editor` 在 npm 上可用。
308
+ 2. 已在 npm 官方源登录:`npm whoami --registry=https://registry.npmjs.org/`。
309
+ 3. 代码已提交,工作区没有未提交改动(推荐)。
310
+
311
+ ```bash
312
+ # 1. 登录官方 npm(如果本机 registry 配置的是镜像,需要显式指定)
313
+ npm login --registry=https://registry.npmjs.org/
314
+
315
+ # 2. 更新版本号(会创建 commit 与 tag,也可手动修改 package.json)
316
+ npm version patch # 或 minor / major
317
+
318
+ # 3. 构建并检查将要发布的文件
319
+ pnpm build
320
+ npm pack --dry-run
321
+
322
+ # 4. 发布(package.json 的 publishConfig 已指定官方 registry)
323
+ npm publish --registry=https://registry.npmjs.org/
324
+
325
+ # 5. 验证
326
+ npm view princess-python-editor version --registry=https://registry.npmjs.org/
327
+ ```
328
+
329
+ 如果账号开启了 2FA,发布时需要提供动态验证码:
330
+
331
+ ```bash
332
+ npm publish --registry=https://registry.npmjs.org/ --otp=123456
333
+ ```
334
+
335
+ 如果希望发布时免验证码,可以创建 Granular Access Token,创建时必须:
336
+
337
+ - 权限选择 `Read and write`,不能选 `Read and write (stage only)`
338
+ - 勾选 `Bypass 2FA`
339
+
340
+ 然后替换用户级 `~/.npmrc` 中的 Token:
341
+
342
+ ```bash
343
+ npm config set //registry.npmjs.org/:_authToken "npm_你的token"
344
+ ```
345
+
346
+ 说明:
347
+
348
+ - `prepublishOnly` 会自动执行 `pnpm build`,无需手动构建。
349
+ - npm 正在收紧 Bypass 2FA Token 的直接发布权限;CI 发布建议使用 Trusted Publishing (OIDC),或使用 stage-only Token 配合 `npm stage publish` 人工审批。
350
+ - 如果包名被占用,可以改为作用域包,例如 `@your-scope/princess-python-editor`,并执行 `npm publish --access public`。
351
+ - 发布后建议在空目录中执行 `npm i princess-python-editor` 做一次安装冒烟测试。
352
+
353
+ ## License
354
+
355
+ [MIT](LICENSE)
@@ -0,0 +1,130 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { EditorFile, EditorLanguage } from './types';
3
+ export interface Props {
4
+ /** 绑定的代码内容(当前 Tab 的文件内容,v-model) */
5
+ modelValue?: string;
6
+ /** 编辑器主题 */
7
+ theme?: 'light' | 'dark';
8
+ /** 编辑器整体高度(含工具栏、Tab 栏与输出面板;数字按 px 处理,传 '100%' 可撑满父容器) */
9
+ height?: number | string;
10
+ /** 输出面板高度 */
11
+ outputHeight?: number | string;
12
+ /** 空内容时的占位提示 */
13
+ placeholder?: string;
14
+ /** 只读模式 */
15
+ readOnly?: boolean;
16
+ /** 挂载后自动聚焦 */
17
+ autofocus?: boolean;
18
+ /** 是否显示工具栏 */
19
+ showToolbar?: boolean;
20
+ /** 是否显示文件 Tab 栏 */
21
+ showTabs?: boolean;
22
+ /** 是否显示输出面板 */
23
+ showOutput?: boolean;
24
+ /** 运行前是否清空输出 */
25
+ clearOutputOnRun?: boolean;
26
+ /** 语法检查防抖毫秒数 */
27
+ lintDelay?: number;
28
+ /** 关闭实时语法检查 */
29
+ disableLint?: boolean;
30
+ /** 挂载后立即预加载 Pyodide(提前获得语法检查与更快的首次运行) */
31
+ preload?: boolean;
32
+ /** 自定义 Pyodide indexURL(以 / 结尾),默认 jsDelivr CDN;仅首次初始化生效 */
33
+ pyodideUrl?: string;
34
+ /** 初始文件名(支持 v-model:file-name) */
35
+ fileName?: string;
36
+ /** 初始语法类型(支持 v-model:language) */
37
+ language?: EditorLanguage;
38
+ }
39
+ /** 读取当前编辑器内容 */
40
+ declare function getCode(): string;
41
+ /** 替换编辑器内容(保留撤销历史) */
42
+ declare function setCode(code: string): void;
43
+ /** 运行当前编辑器中的代码 */
44
+ declare function run(): void;
45
+ /** 中断当前执行(Pyodide 限制:通过终止并重建 Worker 实现) */
46
+ declare function stop(): void;
47
+ /** 清空输出面板 */
48
+ declare function clearOutput(): void;
49
+ /** 新建文件 Tab(继承当前语言),并切换到新文件 */
50
+ declare function newFile(): void;
51
+ /** 切换 Tab */
52
+ declare function switchFile(id: number): void;
53
+ /** 关闭 Tab(始终保留至少一个文件) */
54
+ declare function closeFile(id: number): void;
55
+ /** 清空当前文件内容(保留输出面板) */
56
+ declare function clearCode(): void;
57
+ /** 复制当前代码到剪贴板,成功后按钮短暂显示对勾 */
58
+ declare function copyCode(): Promise<boolean>;
59
+ /** 下载当前文件 */
60
+ declare function download(): string;
61
+ /** 打开本地文件选择框 */
62
+ declare function openFile(): void;
63
+ /** 聚焦编辑器 */
64
+ declare function focus(): void;
65
+ /** 安装第三方包(内置 wheel 优先,回退 micropip),输出写入面板 */
66
+ declare function install(packages: string[]): Promise<import('./types').InstallResult | {
67
+ ok: boolean;
68
+ durationMs: number;
69
+ error: {
70
+ type: string;
71
+ message: string;
72
+ };
73
+ }>;
74
+ /** 语法检查(运行器未就绪时返回 null) */
75
+ declare function checkSyntax(): Promise<import('./types').SyntaxIssue | null>;
76
+ declare function getEditorView(): EditorView | null;
77
+ /** 获取全部 Tab 文件快照 */
78
+ declare function getFiles(): EditorFile[];
79
+ /** 获取当前 Tab 文件快照 */
80
+ declare function getActiveFile(): EditorFile;
81
+ declare const _default: import('vue').DefineComponent<Props, {
82
+ run: typeof run;
83
+ stop: typeof stop;
84
+ clearOutput: typeof clearOutput;
85
+ clearCode: typeof clearCode;
86
+ newFile: typeof newFile;
87
+ switchFile: typeof switchFile;
88
+ closeFile: typeof closeFile;
89
+ copyCode: typeof copyCode;
90
+ download: typeof download;
91
+ openFile: typeof openFile;
92
+ focus: typeof focus;
93
+ install: typeof install;
94
+ checkSyntax: typeof checkSyntax;
95
+ getEditorView: typeof getEditorView;
96
+ getCode: typeof getCode;
97
+ setCode: typeof setCode;
98
+ getFiles: typeof getFiles;
99
+ getActiveFile: typeof getActiveFile;
100
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
101
+ [x: string]: any;
102
+ } & {
103
+ [x: string]: any;
104
+ }, string, import('vue').PublicProps, Readonly<Props> & Readonly<{
105
+ [x: `on${Capitalize<any>}`]: ((...args: any) => any) | undefined;
106
+ }>, {
107
+ height: number | string;
108
+ pyodideUrl: string;
109
+ modelValue: string;
110
+ theme: "light" | "dark";
111
+ outputHeight: number | string;
112
+ placeholder: string;
113
+ readOnly: boolean;
114
+ autofocus: boolean;
115
+ showToolbar: boolean;
116
+ showTabs: boolean;
117
+ showOutput: boolean;
118
+ clearOutputOnRun: boolean;
119
+ lintDelay: number;
120
+ disableLint: boolean;
121
+ preload: boolean;
122
+ fileName: string;
123
+ language: EditorLanguage;
124
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
125
+ tabsEl: HTMLDivElement;
126
+ fileInputEl: HTMLInputElement;
127
+ editorEl: HTMLDivElement;
128
+ outputEl: HTMLPreElement;
129
+ }, HTMLDivElement>;
130
+ export default _default;
@@ -0,0 +1,18 @@
1
+ import { Extension } from '@codemirror/state';
2
+ import { EditorView } from '@codemirror/view';
3
+ export declare const MONO_FONT_STACK = "'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace";
4
+ /** 效果:设置错误行(1 起的行号数组),传空数组清除 */
5
+ export declare const setErrorLines: import('@codemirror/state').StateEffectType<number[]>;
6
+ export interface CreateEditorOptions {
7
+ value: string;
8
+ dark: boolean;
9
+ placeholderText: string;
10
+ /** 语言扩展,默认 Python */
11
+ language?: Extension;
12
+ /** 由组件注入的扩展(主题 / 只读 Compartment、linter 等) */
13
+ extensions: Extension[];
14
+ onDocChange: (code: string) => void;
15
+ /** Ctrl/Cmd + Enter 快捷运行回调 */
16
+ onRunShortcut: () => void;
17
+ }
18
+ export declare function createEditor(host: HTMLElement, opts: CreateEditorOptions): EditorView;
@@ -0,0 +1,8 @@
1
+ import { Extension } from '@codemirror/state';
2
+ import { PyodideRunner } from '../runtime/PyodideRunner';
3
+ /**
4
+ * 基于运行器 ast.parse 的实时语法 linter。
5
+ * 运行器未就绪时静默跳过(不触发 Pyodide 下载),
6
+ * 就绪后由组件调用 forceLinting 主动刷新一次。
7
+ */
8
+ export declare function makePythonLinter(runner: PyodideRunner, delay?: number): Extension;
@@ -0,0 +1,23 @@
1
+ import { FunctionalComponent } from 'vue';
2
+ /** 运行(实心三角) */
3
+ export declare const IconPlay: FunctionalComponent<{}, {}, any, {}>;
4
+ /** 停止(实心方块) */
5
+ export declare const IconStop: FunctionalComponent<{}, {}, any, {}>;
6
+ /** 清空(垃圾桶) */
7
+ export declare const IconClear: FunctionalComponent<{}, {}, any, {}>;
8
+ /** 新建文件(文件 + 加号) */
9
+ export declare const IconNew: FunctionalComponent<{}, {}, any, {}>;
10
+ /** 打开文件(文件夹) */
11
+ export declare const IconFolder: FunctionalComponent<{}, {}, any, {}>;
12
+ /** 文件 */
13
+ export declare const IconFile: FunctionalComponent<{}, {}, any, {}>;
14
+ /** 下载(向下箭头 + 托盘) */
15
+ export declare const IconDownload: FunctionalComponent<{}, {}, any, {}>;
16
+ /** 复制(双层纸张) */
17
+ export declare const IconCopy: FunctionalComponent<{}, {}, any, {}>;
18
+ /** 对勾(复制成功反馈) */
19
+ export declare const IconCheck: FunctionalComponent<{}, {}, any, {}>;
20
+ /** 关闭(叉号) */
21
+ export declare const IconClose: FunctionalComponent<{}, {}, any, {}>;
22
+ /** 加号(新建 Tab) */
23
+ export declare const IconPlus: FunctionalComponent<{}, {}, any, {}>;