@hep-code-runner/vue3 2.3.2 → 2.3.4
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 +91 -172
- package/dist/index.d.ts +10 -8
- package/dist/index.js +3 -3
- package/dist/index.mjs +251 -251
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,185 +1,88 @@
|
|
|
1
1
|
# @hep-code-runner/vue3
|
|
2
2
|
|
|
3
|
-
Vue 3
|
|
4
|
-
|
|
5
|
-
## 功能特性
|
|
6
|
-
|
|
7
|
-
- 支持多种编程语言(JavaScript、Python、Go、Java、C、Rust 等)
|
|
8
|
-
- 多版本语言支持(如 Python 2、Python 3)
|
|
9
|
-
- 代码语法高亮(PrismJS)
|
|
10
|
-
- 亮色/暗色主题切换
|
|
11
|
-
- 可拖拽调整编辑器宽度
|
|
12
|
-
- 支持自定义 Piston API 地址
|
|
13
|
-
- 完整的事件回调
|
|
3
|
+
Vue 3 代码运行器组件,基于 Piston API 支持多种编程语言在线执行。
|
|
14
4
|
|
|
15
5
|
## 安装
|
|
16
6
|
|
|
17
7
|
```bash
|
|
18
8
|
npm install @hep-code-runner/vue3
|
|
19
|
-
# 或
|
|
20
|
-
pnpm add @hep-code-runner/vue3
|
|
21
9
|
```
|
|
22
10
|
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
```vue
|
|
26
|
-
<template>
|
|
27
|
-
<CodeRunner />
|
|
28
|
-
</template>
|
|
11
|
+
## 引入
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</script>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Props 属性
|
|
37
|
-
|
|
38
|
-
| 属性 | 类型 | 默认值 | 说明 |
|
|
39
|
-
| -------------------- | ----------------- | ------------- | --------------------- |
|
|
40
|
-
| v-model | string | - | 绑定代码内容(双向) |
|
|
41
|
-
| v-model:language | string | 'javascript' | 绑定当前语言(双向) |
|
|
42
|
-
| pistonUrl | string | '/api/piston' | Piston API 地址 |
|
|
43
|
-
| language | string | 'javascript' | 当前语言(受控) |
|
|
44
|
-
| theme | 'light' \| 'dark' | 'light' | 主题 |
|
|
45
|
-
| themeColor | string | - | 自定义主题色 |
|
|
46
|
-
| showLanguageSelector | boolean | true | 显示语言选择器 |
|
|
47
|
-
| showEditor | boolean | true | 显示代码编辑器 |
|
|
48
|
-
| editable | boolean | true | 是否可编辑 |
|
|
49
|
-
| executorLabel | string | '运行' | 运行按钮文字 |
|
|
50
|
-
|
|
51
|
-
## Events 事件
|
|
52
|
-
|
|
53
|
-
| 事件名 | 参数 | 说明 |
|
|
54
|
-
| ------------------ | -------------- | -------------- |
|
|
55
|
-
| update:modelValue | value | 代码内容变化 |
|
|
56
|
-
| update:language | language | 语言变化 |
|
|
57
|
-
| execute-start | - | 代码开始执行 |
|
|
58
|
-
| execute-end | result | 代码执行完成 |
|
|
59
|
-
| language-change | language, code | 语言切换 |
|
|
60
|
-
| change | code | 代码变化(防抖)|
|
|
61
|
-
|
|
62
|
-
## 主题切换
|
|
63
|
-
|
|
64
|
-
```vue
|
|
65
|
-
<CodeRunner theme="dark" />
|
|
13
|
+
```js
|
|
14
|
+
import { CodeRunner } from "@hep-code-runner/vue3";
|
|
15
|
+
import "@hep-code-runner/vue3/dist/style.css";
|
|
66
16
|
```
|
|
67
17
|
|
|
68
|
-
|
|
18
|
+
---
|
|
69
19
|
|
|
70
|
-
##
|
|
20
|
+
## CodeRunner
|
|
71
21
|
|
|
72
|
-
|
|
22
|
+
### 用法
|
|
73
23
|
|
|
74
24
|
```vue
|
|
75
|
-
|
|
76
|
-
<CodeRunner
|
|
77
|
-
|
|
78
|
-
<!-- 深色主题 -->
|
|
79
|
-
<CodeRunner themeColor="#9c27b0" theme="dark" />
|
|
80
|
-
|
|
81
|
-
<!-- 动态切换主题色 -->
|
|
82
|
-
<CodeRunner :themeColor="currentColor" />
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## 自定义 Piston API
|
|
25
|
+
<template>
|
|
26
|
+
<CodeRunner />
|
|
27
|
+
</template>
|
|
86
28
|
|
|
87
|
-
|
|
88
|
-
|
|
29
|
+
<script setup>
|
|
30
|
+
import { CodeRunner } from "@hep-code-runner/vue3";
|
|
31
|
+
</script>
|
|
89
32
|
```
|
|
90
33
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
### 默认配置
|
|
34
|
+
### Props
|
|
94
35
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
36
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
37
|
+
|------|------|--------|------|
|
|
38
|
+
| pistonUrl | string | '/api/piston' | Piston API 地址 |
|
|
39
|
+
| modelValue / v-model | string | '' | 当前代码 |
|
|
40
|
+
| v-model:language | string | 'javascript' | 当前语言 |
|
|
41
|
+
| theme | 'light' \| 'dark' | 'light' | 主题 |
|
|
42
|
+
| themeColor | string | - | 自定义主题色 |
|
|
43
|
+
| showLanguageSelector | boolean | true | 显示语言选择器 |
|
|
44
|
+
| showEditor | boolean | true | 显示代码编辑器 |
|
|
45
|
+
| editable | boolean | true | 是否可编辑 |
|
|
46
|
+
| executorLabel | string | '运行' | 运行按钮文字 |
|
|
98
47
|
|
|
99
|
-
###
|
|
48
|
+
### 受控模式
|
|
100
49
|
|
|
101
50
|
```vue
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
### 受控模式(v-model)
|
|
51
|
+
<script setup>
|
|
52
|
+
import { ref } from "vue";
|
|
106
53
|
|
|
107
|
-
|
|
54
|
+
const currentLanguage = ref("javascript");
|
|
55
|
+
const currentCode = ref('console.log("hello")');
|
|
56
|
+
</script>
|
|
108
57
|
|
|
109
|
-
```vue
|
|
110
58
|
<template>
|
|
111
59
|
<CodeRunner
|
|
112
|
-
v-model:language="currentLanguage"
|
|
113
60
|
v-model="currentCode"
|
|
114
|
-
|
|
61
|
+
v-model:language="currentLanguage"
|
|
115
62
|
/>
|
|
116
63
|
</template>
|
|
117
|
-
|
|
118
|
-
<script setup>
|
|
119
|
-
import { ref } from 'vue'
|
|
120
|
-
const currentLanguage = ref('javascript')
|
|
121
|
-
const currentCode = ref('console.log("hello")')
|
|
122
|
-
</script>
|
|
123
64
|
```
|
|
124
65
|
|
|
125
|
-
###
|
|
66
|
+
### Events
|
|
126
67
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
68
|
+
| 事件名 | 参数 | 说明 |
|
|
69
|
+
|--------|------|------|
|
|
70
|
+
| update:modelValue | code | 代码变化 |
|
|
71
|
+
| update:language | language | 语言变化 |
|
|
72
|
+
| execute-start | - | 代码开始执行 |
|
|
73
|
+
| execute-end | result | 代码执行完成 |
|
|
74
|
+
| language-change | language, code | 语言切换 |
|
|
75
|
+
| change | code | 代码变化(防抖) |
|
|
135
76
|
|
|
136
|
-
|
|
137
|
-
function handleStart() {
|
|
138
|
-
console.log("开始执行");
|
|
139
|
-
}
|
|
77
|
+
---
|
|
140
78
|
|
|
141
|
-
|
|
142
|
-
console.log("执行完成", result);
|
|
143
|
-
}
|
|
79
|
+
## CodeRunnerDialog
|
|
144
80
|
|
|
145
|
-
|
|
146
|
-
console.log("语言切换", language);
|
|
147
|
-
}
|
|
148
|
-
</script>
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## 依赖
|
|
152
|
-
|
|
153
|
-
- vue: ^3.0.0
|
|
154
|
-
- prismjs: ^1.30.0
|
|
155
|
-
|
|
156
|
-
## CodeRunnerDialog 弹窗组件
|
|
157
|
-
|
|
158
|
-
提供弹窗模式的代码执行器,支持受控和非受控模式。
|
|
159
|
-
|
|
160
|
-
### 引入
|
|
161
|
-
|
|
162
|
-
```vue
|
|
163
|
-
<script setup>
|
|
164
|
-
import { CodeRunnerDialog } from "@hep-code-runner/vue3";
|
|
165
|
-
import "@hep-code-runner/vue3/dist/style.css";
|
|
166
|
-
</script>
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### 受控模式
|
|
81
|
+
### 用法
|
|
170
82
|
|
|
171
83
|
```vue
|
|
172
84
|
<template>
|
|
173
|
-
<
|
|
174
|
-
|
|
175
|
-
<CodeRunnerDialog
|
|
176
|
-
v-model:visible="visible"
|
|
177
|
-
v-model:language="currentLang"
|
|
178
|
-
v-model="currentCode"
|
|
179
|
-
title="代码执行器"
|
|
180
|
-
width="800"
|
|
181
|
-
@close="handleClose"
|
|
182
|
-
>
|
|
85
|
+
<CodeRunnerDialog ref="dialog" title="代码执行器">
|
|
183
86
|
<template #footer="{ close }">
|
|
184
87
|
<button @click="close">取消</button>
|
|
185
88
|
<button @click="handleSave">保存</button>
|
|
@@ -189,67 +92,83 @@ import "@hep-code-runner/vue3/dist/style.css";
|
|
|
189
92
|
|
|
190
93
|
<script setup>
|
|
191
94
|
import { ref } from "vue";
|
|
95
|
+
import { CodeRunnerDialog } from "@hep-code-runner/vue3";
|
|
192
96
|
|
|
193
|
-
const
|
|
194
|
-
const currentLang = ref('python');
|
|
195
|
-
const currentCode = ref('print("hello")');
|
|
196
|
-
|
|
197
|
-
function handleClose() {
|
|
198
|
-
console.log('language:', currentLang.value, 'code:', currentCode.value);
|
|
199
|
-
}
|
|
97
|
+
const dialog = ref(null);
|
|
200
98
|
|
|
201
99
|
function handleSave() {
|
|
202
|
-
|
|
203
|
-
visible.value = false;
|
|
100
|
+
dialog.value.close();
|
|
204
101
|
}
|
|
205
102
|
</script>
|
|
206
103
|
```
|
|
207
104
|
|
|
208
|
-
###
|
|
105
|
+
### 受控模式
|
|
209
106
|
|
|
210
107
|
```vue
|
|
108
|
+
<script setup>
|
|
109
|
+
import { ref } from "vue";
|
|
110
|
+
|
|
111
|
+
const visible = ref(false);
|
|
112
|
+
const currentLanguage = ref("python");
|
|
113
|
+
const currentCode = ref('print("hello")');
|
|
114
|
+
</script>
|
|
115
|
+
|
|
211
116
|
<template>
|
|
212
|
-
<button @click="
|
|
117
|
+
<button @click="visible = true">打开</button>
|
|
213
118
|
|
|
214
119
|
<CodeRunnerDialog
|
|
215
|
-
|
|
120
|
+
v-model="visible"
|
|
121
|
+
v-model:language="currentLanguage"
|
|
122
|
+
v-model:code="currentCode"
|
|
216
123
|
title="代码执行器"
|
|
124
|
+
width="800"
|
|
125
|
+
@close="onClose"
|
|
217
126
|
>
|
|
218
127
|
<template #footer="{ close }">
|
|
219
128
|
<button @click="close">取消</button>
|
|
220
|
-
<button @click="
|
|
129
|
+
<button @click="handleSave(close)">保存</button>
|
|
221
130
|
</template>
|
|
222
131
|
</CodeRunnerDialog>
|
|
223
132
|
</template>
|
|
224
|
-
|
|
225
|
-
<script setup>
|
|
226
|
-
import { ref } from "vue";
|
|
227
|
-
|
|
228
|
-
const dialogRef = ref(null);
|
|
229
|
-
</script>
|
|
230
133
|
```
|
|
231
134
|
|
|
232
|
-
### Props
|
|
135
|
+
### Props
|
|
233
136
|
|
|
234
137
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
235
138
|
|------|------|--------|------|
|
|
236
|
-
| v-model
|
|
139
|
+
| v-model | boolean | false | 控制显隐 |
|
|
237
140
|
| v-model:language | string | 'javascript' | 当前语言 |
|
|
238
|
-
| v-model | string | '' | 当前代码 |
|
|
141
|
+
| v-model:code | string | '' | 当前代码 |
|
|
239
142
|
| title | string | '代码执行器' | 弹窗标题 |
|
|
240
143
|
| width | string \| number | 800 | 弹窗宽度 |
|
|
144
|
+
| pistonUrl | string | '/api/piston' | Piston API 地址 |
|
|
145
|
+
| theme | 'light' \| 'dark' | 'light' | 主题 |
|
|
146
|
+
| themeColor | string | - | 自定义主题色 |
|
|
147
|
+
| showLanguageSelector | boolean | true | 显示语言选择器 |
|
|
148
|
+
| showEditor | boolean | true | 显示代码编辑器 |
|
|
149
|
+
| editable | boolean | true | 是否可编辑 |
|
|
150
|
+
| executorLabel | string | '运行' | 运行按钮文字 |
|
|
241
151
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
### Slots 插槽
|
|
152
|
+
### Slots
|
|
245
153
|
|
|
246
|
-
| 插槽名 |
|
|
247
|
-
|
|
248
|
-
| footer | { close } |
|
|
154
|
+
| 插槽名 | 参数 | 说明 |
|
|
155
|
+
|--------|------|------|
|
|
156
|
+
| footer | { close } | 底部自定义内容 |
|
|
249
157
|
|
|
250
|
-
###
|
|
158
|
+
### Methods
|
|
251
159
|
|
|
252
160
|
| 方法 | 说明 |
|
|
253
161
|
|------|------|
|
|
254
162
|
| open() | 打开弹窗 |
|
|
255
163
|
| close() | 关闭弹窗 |
|
|
164
|
+
|
|
165
|
+
### Events
|
|
166
|
+
|
|
167
|
+
| 事件名 | 参数 | 说明 |
|
|
168
|
+
|--------|------|------|
|
|
169
|
+
| close | - | 弹窗关闭 |
|
|
170
|
+
|
|
171
|
+
## 依赖
|
|
172
|
+
|
|
173
|
+
- vue: ^3.0.0
|
|
174
|
+
- prismjs: ^1.30.0
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { PropType } from 'vue';
|
|
|
8
8
|
import { PublicProps } from 'vue';
|
|
9
9
|
|
|
10
10
|
declare const __VLS_component: DefineComponent<ExtractPropTypes<__VLS_WithDefaults_2<__VLS_TypePropsToRuntimeProps_2<Props_2>, {
|
|
11
|
-
visible: boolean;
|
|
12
11
|
title: string;
|
|
13
12
|
width: number;
|
|
14
13
|
pistonUrl: string;
|
|
@@ -24,12 +23,11 @@ executorLabel: string;
|
|
|
24
23
|
open: typeof open_2;
|
|
25
24
|
close: typeof close_2;
|
|
26
25
|
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
26
|
+
"update:modelValue": (value: boolean) => void;
|
|
27
27
|
"update:language": (value: string) => void;
|
|
28
|
-
close: () => void;
|
|
29
|
-
"update:visible": (value: boolean) => void;
|
|
30
28
|
"update:code": (value: string) => void;
|
|
29
|
+
close: () => void;
|
|
31
30
|
}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults_2<__VLS_TypePropsToRuntimeProps_2<Props_2>, {
|
|
32
|
-
visible: boolean;
|
|
33
31
|
title: string;
|
|
34
32
|
width: number;
|
|
35
33
|
pistonUrl: string;
|
|
@@ -42,10 +40,10 @@ showEditor: boolean;
|
|
|
42
40
|
editable: boolean;
|
|
43
41
|
executorLabel: string;
|
|
44
42
|
}>>> & Readonly<{
|
|
43
|
+
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
45
44
|
"onUpdate:language"?: ((value: string) => any) | undefined;
|
|
46
|
-
onClose?: (() => any) | undefined;
|
|
47
|
-
"onUpdate:visible"?: ((value: boolean) => any) | undefined;
|
|
48
45
|
"onUpdate:code"?: ((value: string) => any) | undefined;
|
|
46
|
+
onClose?: (() => any) | undefined;
|
|
49
47
|
}>, {
|
|
50
48
|
code: string;
|
|
51
49
|
title: string;
|
|
@@ -58,7 +56,6 @@ showEditor: boolean;
|
|
|
58
56
|
editable: boolean;
|
|
59
57
|
executorLabel: string;
|
|
60
58
|
width: string | number;
|
|
61
|
-
visible: boolean;
|
|
62
59
|
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
63
60
|
|
|
64
61
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
@@ -120,6 +117,7 @@ declare function close_2(): void;
|
|
|
120
117
|
declare const _default: DefineComponent<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
|
|
121
118
|
pistonUrl: string;
|
|
122
119
|
modelValue: string;
|
|
120
|
+
code: string;
|
|
123
121
|
language: string;
|
|
124
122
|
theme: string;
|
|
125
123
|
themeColor: string;
|
|
@@ -133,9 +131,11 @@ executorLabel: string;
|
|
|
133
131
|
"execute-end": (result: ExecuteResult) => void;
|
|
134
132
|
"language-change": (language: string, code: string) => void;
|
|
135
133
|
"update:language": (language: string) => void;
|
|
134
|
+
"update:code": (code: string) => void;
|
|
136
135
|
}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
|
|
137
136
|
pistonUrl: string;
|
|
138
137
|
modelValue: string;
|
|
138
|
+
code: string;
|
|
139
139
|
language: string;
|
|
140
140
|
theme: string;
|
|
141
141
|
themeColor: string;
|
|
@@ -149,7 +149,9 @@ executorLabel: string;
|
|
|
149
149
|
"onExecute-end"?: ((result: ExecuteResult) => any) | undefined;
|
|
150
150
|
"onLanguage-change"?: ((language: string, code: string) => any) | undefined;
|
|
151
151
|
"onUpdate:language"?: ((language: string) => any) | undefined;
|
|
152
|
+
"onUpdate:code"?: ((code: string) => any) | undefined;
|
|
152
153
|
}>, {
|
|
154
|
+
code: string;
|
|
153
155
|
modelValue: string;
|
|
154
156
|
language: string;
|
|
155
157
|
theme: "light" | "dark";
|
|
@@ -177,6 +179,7 @@ declare function open_2(): void;
|
|
|
177
179
|
declare interface Props {
|
|
178
180
|
pistonUrl?: string;
|
|
179
181
|
modelValue?: string;
|
|
182
|
+
code?: string;
|
|
180
183
|
language?: string;
|
|
181
184
|
theme?: "light" | "dark";
|
|
182
185
|
themeColor?: string;
|
|
@@ -187,7 +190,6 @@ declare interface Props {
|
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
declare interface Props_2 {
|
|
190
|
-
visible?: boolean;
|
|
191
193
|
title?: string;
|
|
192
194
|
width?: string | number;
|
|
193
195
|
pistonUrl?: string;
|