@hep-code-runner/vue3 2.3.3 → 2.3.5

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 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
- <script setup>
31
- import { CodeRunner } from "@hep-code-runner/vue3";
32
- import "@hep-code-runner/vue3/dist/style.css";
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
- 点击组件右上角的月亮/太阳按钮可切换主题。
69
-
70
- ## 自定义主题色
18
+ ---
71
19
 
72
- 支持通过 `themeColor` 属性自定义主题色,组件会自动根据颜色亮度调整文字颜色,确保可读性。
73
-
74
- ```vue
75
- <!-- 浅色主题 -->
76
- <CodeRunner themeColor="#4fc3f7" theme="light" />
77
-
78
- <!-- 深色主题 -->
79
- <CodeRunner themeColor="#9c27b0" theme="dark" />
80
-
81
- <!-- 动态切换主题色 -->
82
- <CodeRunner :themeColor="currentColor" />
83
- ```
20
+ ## CodeRunner
84
21
 
85
- ## 自定义 Piston API
22
+ ### 用法
86
23
 
87
24
  ```vue
88
- <CodeRunner pistonUrl="https://your-piston-api.com/api" />
89
- ```
90
-
91
- ## 示例
92
-
93
- ### 默认配置
25
+ <template>
26
+ <CodeRunner />
27
+ </template>
94
28
 
95
- ```vue
96
- <CodeRunner />
29
+ <script setup>
30
+ import { CodeRunner } from "@hep-code-runner/vue3";
31
+ </script>
97
32
  ```
98
33
 
99
- ### 深色主题
34
+ ### Props
100
35
 
101
- ```vue
102
- <CodeRunner theme="dark" language="python" />
103
- ```
104
-
105
- ### 受控模式(v-model
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 | '运行' | 运行按钮文字 |
106
47
 
107
- 组件完全受控,父组件控制 language 和 code:
48
+ ### 受控模式
108
49
 
109
50
  ```vue
110
- <template>
111
- <CodeRunner
112
- v-model:language="currentLanguage"
113
- v-model="currentCode"
114
- @language-change="onLanguageChange"
115
- />
116
- </template>
117
-
118
51
  <script setup>
119
- import { ref } from 'vue'
120
- const currentLanguage = ref('javascript')
121
- const currentCode = ref('console.log("hello")')
122
- </script>
123
- ```
52
+ import { ref } from "vue";
124
53
 
125
- ### 监听事件
54
+ const currentLanguage = ref("javascript");
55
+ const currentCode = ref('console.log("hello")');
56
+ </script>
126
57
 
127
- ```vue
128
58
  <template>
129
59
  <CodeRunner
130
- @execute-start="handleStart"
131
- @execute-end="handleEnd"
132
- @language-change="handleLanguageChange"
60
+ v-model="currentCode"
61
+ v-model:language="currentLanguage"
133
62
  />
134
63
  </template>
135
-
136
- <script setup>
137
- function handleStart() {
138
- console.log("开始执行");
139
- }
140
-
141
- function handleEnd(result) {
142
- console.log("执行完成", result);
143
- }
144
-
145
- function handleLanguageChange(language, code) {
146
- console.log("语言切换", language);
147
- }
148
- </script>
149
64
  ```
150
65
 
151
- ## 依赖
152
-
153
- - vue: ^3.0.0
154
- - prismjs: ^1.30.0
66
+ ### Events
155
67
 
156
- ## CodeRunnerDialog 弹窗组件
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 | 代码变化(防抖) |
157
76
 
158
- 提供弹窗模式的代码执行器,支持受控和非受控模式。
77
+ ---
159
78
 
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
- ```
79
+ ## CodeRunnerDialog
168
80
 
169
- ### 受控模式
81
+ ### 用法
170
82
 
171
83
  ```vue
172
84
  <template>
173
- <button @click="visible = true">打开弹窗</button>
174
-
175
- <CodeRunnerDialog
176
- v-model="visible"
177
- v-model:language="currentLang"
178
- v-model:code="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 visible = ref(false);
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
- console.log('save:', currentCode.value);
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="dialogRef?.open()">打开弹窗</button>
117
+ <button @click="visible = true">打开</button>
213
118
 
214
119
  <CodeRunnerDialog
215
- ref="dialogRef"
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="handleInsert">插入代码</button>
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 | boolean | false | 控制显示隐藏 |
139
+ | v-model | boolean | false | 控制显隐 |
237
140
  | v-model:language | string | 'javascript' | 当前语言 |
238
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
- 其他属性会透传给内部 CodeRunner 组件。
243
-
244
- ### Slots 插槽
152
+ ### Slots
245
153
 
246
- | 插槽名 | 作用域参数 | 说明 |
247
- |--------|-----------|------|
248
- | footer | { close } | 底部自定义内容,close 为关闭函数 |
154
+ | 插槽名 | 参数 | 说明 |
155
+ |--------|------|------|
156
+ | footer | { close } | 底部自定义内容 |
249
157
 
250
- ### Expose 暴露方法
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
@@ -25,8 +25,8 @@ close: typeof close_2;
25
25
  }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
26
26
  "update:modelValue": (value: boolean) => void;
27
27
  "update:language": (value: string) => void;
28
- close: () => void;
29
28
  "update:code": (value: string) => void;
29
+ close: () => void;
30
30
  }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults_2<__VLS_TypePropsToRuntimeProps_2<Props_2>, {
31
31
  title: string;
32
32
  width: number;
@@ -42,8 +42,8 @@ executorLabel: string;
42
42
  }>>> & Readonly<{
43
43
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
44
44
  "onUpdate:language"?: ((value: string) => any) | undefined;
45
- onClose?: (() => any) | undefined;
46
45
  "onUpdate:code"?: ((value: string) => any) | undefined;
46
+ onClose?: (() => any) | undefined;
47
47
  }>, {
48
48
  code: string;
49
49
  title: string;
@@ -117,6 +117,7 @@ declare function close_2(): void;
117
117
  declare const _default: DefineComponent<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
118
118
  pistonUrl: string;
119
119
  modelValue: string;
120
+ code: string;
120
121
  language: string;
121
122
  theme: string;
122
123
  themeColor: string;
@@ -130,9 +131,11 @@ executorLabel: string;
130
131
  "execute-end": (result: ExecuteResult) => void;
131
132
  "language-change": (language: string, code: string) => void;
132
133
  "update:language": (language: string) => void;
134
+ "update:code": (code: string) => void;
133
135
  }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
134
136
  pistonUrl: string;
135
137
  modelValue: string;
138
+ code: string;
136
139
  language: string;
137
140
  theme: string;
138
141
  themeColor: string;
@@ -146,7 +149,9 @@ executorLabel: string;
146
149
  "onExecute-end"?: ((result: ExecuteResult) => any) | undefined;
147
150
  "onLanguage-change"?: ((language: string, code: string) => any) | undefined;
148
151
  "onUpdate:language"?: ((language: string) => any) | undefined;
152
+ "onUpdate:code"?: ((code: string) => any) | undefined;
149
153
  }>, {
154
+ code: string;
150
155
  modelValue: string;
151
156
  language: string;
152
157
  theme: "light" | "dark";
@@ -174,6 +179,7 @@ declare function open_2(): void;
174
179
  declare interface Props {
175
180
  pistonUrl?: string;
176
181
  modelValue?: string;
182
+ code?: string;
177
183
  language?: string;
178
184
  theme?: "light" | "dark";
179
185
  themeColor?: string;