princess-python-editor 0.1.2 → 0.2.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/README.md +33 -5
- package/dist/PythonEditor.vue.d.ts +3 -3
- package/dist/editor/theme.d.ts +3 -0
- package/dist/index.cjs.js +7 -7
- package/dist/index.d.ts +4 -2
- package/dist/index.es.js +2629 -1838
- package/dist/style.css +1 -1
- package/dist/themes.d.ts +12 -0
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Vue 3 + TypeScript 的 Python 代码编辑器组件:基于 CodeMirror 6 的编
|
|
|
21
21
|
- **服务端文件**:配置 `files-endpoint` 后,工具栏可把当前文件保存到 python-server,并在“已保存文件”面板查询、打开或删除
|
|
22
22
|
- **草稿持久化**:传入 `storage-key` 后自动把全部 Tab 与当前选中项保存到 localStorage,刷新页面不丢失
|
|
23
23
|
- **预置包**:通过 `preload-packages` 在 Pyodide 就绪后自动安装常用包(如 `sqlite3`)
|
|
24
|
-
-
|
|
24
|
+
- **主题与只读**:内置明亮、深色、GitHub 浅/深、Dracula、Nord、Solarized 浅色、Monokai 共 8 套主题,支持只读模式,工具栏与输出面板均可按需显示
|
|
25
25
|
- **第三方包安装**:优先使用 Pyodide 内置 wheel,缺失时回退 micropip
|
|
26
26
|
- **可中断执行**:运行长时间计算时可停止,Worker 自动重建
|
|
27
27
|
- **Headless 能力**:额外导出 `usePyodide`、`PyodideRunner` 等 API,可在无编辑器场景下执行 Python
|
|
@@ -108,7 +108,7 @@ function onRunError(error: PyError) {
|
|
|
108
108
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
109
109
|
| ------------------- | ------------------------ | ----------- | -------------------------------------------------------- |
|
|
110
110
|
| `modelValue` | `string` | `''` | 当前 Tab 的代码内容,支持 `v-model` |
|
|
111
|
-
| `theme` | `
|
|
111
|
+
| `theme` | `EditorTheme` | `'light'` | 编辑器主题,见下文“主题” |
|
|
112
112
|
| `height` | `number \| string` | `520` | 组件整体高度(含工具栏、Tab 与输出面板),数字按 px 处理 |
|
|
113
113
|
| `outputHeight` | `number \| string` | `180` | 输出面板初始高度;拖动分隔条可调整,双击复位 |
|
|
114
114
|
| `placeholder` | `string` | `''` | 内容为空时的占位提示 |
|
|
@@ -691,22 +691,50 @@ const listed = await listFiles()
|
|
|
691
691
|
| `listFiles(path?)` | `Promise<FsListResult>` | 列出虚拟文件目录 |
|
|
692
692
|
| `ready()` | `Promise<void>` | 等待就绪 |
|
|
693
693
|
|
|
694
|
-
##
|
|
694
|
+
## 主题
|
|
695
695
|
|
|
696
|
-
|
|
696
|
+
内置 8 套主题,通过 `theme` 属性切换:
|
|
697
|
+
|
|
698
|
+
| 值 | 名称 | 明暗 |
|
|
699
|
+
| ----------------- | -------------- | ---- |
|
|
700
|
+
| `light` | 明亮(默认) | 浅色 |
|
|
701
|
+
| `dark` | 深色 | 深色 |
|
|
702
|
+
| `github-light` | GitHub 浅色 | 浅色 |
|
|
703
|
+
| `github-dark` | GitHub 深色 | 深色 |
|
|
704
|
+
| `dracula` | Dracula | 深色 |
|
|
705
|
+
| `nord` | Nord | 深色 |
|
|
706
|
+
| `solarized-light` | Solarized 浅色 | 浅色 |
|
|
707
|
+
| `monokai` | Monokai | 深色 |
|
|
708
|
+
|
|
709
|
+
```vue
|
|
710
|
+
<PythonEditor v-model="code" theme="dracula" />
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
```ts
|
|
714
|
+
import { EDITOR_THEMES, getThemeOption, isDarkTheme } from 'princess-python-editor'
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
### 主题定制
|
|
718
|
+
|
|
719
|
+
组件样式与语法高亮都通过 CSS 变量控制,可在根元素上覆盖。内置主题类名为 `.vpe-theme-{theme}`,深色主题同时带有 `.vpe-dark`:
|
|
697
720
|
|
|
698
721
|
```css
|
|
699
722
|
.vpe-root {
|
|
700
723
|
--vpe-accent: #165dff;
|
|
701
724
|
--vpe-bg: #ffffff;
|
|
725
|
+
--vpe-editor-bg: #ffffff;
|
|
702
726
|
--vpe-text: #1d2129;
|
|
703
727
|
--vpe-border: #e5e6eb;
|
|
704
728
|
--vpe-output-bg: #f7f8fa;
|
|
705
729
|
--vpe-stderr: #f53f3f;
|
|
730
|
+
/* 语法高亮 */
|
|
731
|
+
--vpe-syn-keyword: #770088;
|
|
732
|
+
--vpe-syn-string: #aa1111;
|
|
733
|
+
--vpe-syn-comment: #9a4a00;
|
|
706
734
|
}
|
|
707
735
|
```
|
|
708
736
|
|
|
709
|
-
|
|
737
|
+
完整变量包括界面色(`--vpe-bg`、`--vpe-toolbar-bg`、`--vpe-text`、`--vpe-accent` 等)、编辑器色(`--vpe-editor-bg`、`--vpe-selection`、`--vpe-active-line`、`--vpe-gutter` 等)和语法色(`--vpe-syn-keyword`、`--vpe-syn-string`、`--vpe-syn-number`、`--vpe-syn-function`、`--vpe-syn-type` 等)。新增主题只需定义一组变量并加上 `.vpe-theme-xxx` 类名。
|
|
710
738
|
|
|
711
739
|
## 类型导出
|
|
712
740
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { EditorView } from '@codemirror/view';
|
|
2
|
-
import { EditorFile, EditorLanguage, PythonRuntime, ServerFile, SqlConfig, SqlConfigInput, SqlExecutor, SqlQueryResult } from './types';
|
|
2
|
+
import { EditorFile, EditorLanguage, EditorTheme, PythonRuntime, ServerFile, SqlConfig, SqlConfigInput, SqlExecutor, SqlQueryResult } from './types';
|
|
3
3
|
export interface Props {
|
|
4
4
|
/** 绑定的代码内容(当前 Tab 的文件内容,v-model) */
|
|
5
5
|
modelValue?: string;
|
|
6
6
|
/** 编辑器主题 */
|
|
7
|
-
theme?:
|
|
7
|
+
theme?: EditorTheme;
|
|
8
8
|
/** 编辑器整体高度(含工具栏、Tab 栏与输出面板;数字按 px 处理,传 '100%' 可撑满父容器) */
|
|
9
9
|
height?: number | string;
|
|
10
10
|
/** 输出面板高度 */
|
|
@@ -165,7 +165,7 @@ declare const _default: import('vue').DefineComponent<Props, {
|
|
|
165
165
|
stdin: string;
|
|
166
166
|
pyodideUrl: string;
|
|
167
167
|
modelValue: string;
|
|
168
|
-
theme:
|
|
168
|
+
theme: EditorTheme;
|
|
169
169
|
outputHeight: number | string;
|
|
170
170
|
placeholder: string;
|
|
171
171
|
readOnly: boolean;
|