@hep-code-runner/react 1.0.0 → 1.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 CHANGED
@@ -107,3 +107,93 @@ function App() {
107
107
  - react: ^16.8.0 || ^17.0.0 || ^18.0.0
108
108
  - react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
109
109
  - prismjs: ^1.30.0
110
+
111
+ ## CodeRunnerDialog 弹窗组件
112
+
113
+ 提供弹窗模式的代码执行器,支持受控和非受控模式。
114
+
115
+ ### 引入
116
+
117
+ ```jsx
118
+ import { CodeRunnerDialog } from "@hep-code-runner/react";
119
+ ```
120
+
121
+ ### 受控模式
122
+
123
+ ```jsx
124
+ import { useState } from "react";
125
+ import { CodeRunnerDialog } from "@hep-code-runner/react";
126
+
127
+ function App() {
128
+ const [visible, setVisible] = useState(false);
129
+
130
+ return (
131
+ <>
132
+ <button onClick={() => setVisible(true)}>打开弹窗</button>
133
+
134
+ <CodeRunnerDialog
135
+ open={visible}
136
+ onClose={() => setVisible(false)}
137
+ title="代码执行器"
138
+ width={800}
139
+ footer={
140
+ <>
141
+ <button onClick={() => setVisible(false)}>取消</button>
142
+ <button onClick={handleSave}>保存</button>
143
+ <button onClick={handleInsert}>插入代码</button>
144
+ </>
145
+ }
146
+ />
147
+ </>
148
+ );
149
+ }
150
+ ```
151
+
152
+ ### 非受控模式
153
+
154
+ ```jsx
155
+ import { useRef } from "react";
156
+ import { CodeRunnerDialog } from "@hep-code-runner/react";
157
+
158
+ function App() {
159
+ const dialogRef = useRef(null);
160
+
161
+ return (
162
+ <>
163
+ <button onClick={() => dialogRef.current?.open()}>打开弹窗</button>
164
+
165
+ <CodeRunnerDialog
166
+ ref={dialogRef}
167
+ title="代码执行器"
168
+ footer={
169
+ <>
170
+ <button onClick={() => dialogRef.current?.close()}>取消</button>
171
+ <button onClick={handleInsert}>插入代码</button>
172
+ </>
173
+ }
174
+ />
175
+ </>
176
+ );
177
+ }
178
+ ```
179
+
180
+ ### Props 属性
181
+
182
+ | 属性 | 类型 | 默认值 | 说明 |
183
+ |------|------|--------|------|
184
+ | open | boolean | - | 控制显示隐藏(受控模式) |
185
+ | defaultOpen | boolean | false | 初始显示状态(非受控模式) |
186
+ | title | string | '代码执行器' | 弹窗标题 |
187
+ | width | string \| number | 800 | 弹窗宽度 |
188
+ | onClose | () => void | - | 关闭回调 |
189
+ | footer | ReactNode | - | 底部自定义内容 |
190
+ | theme | 'light' \| 'dark' | 'light' | 主题 |
191
+
192
+ 其他 Props 会透传给内部 CodeRunner 组件。
193
+
194
+ ### Ref 方法
195
+
196
+ | 方法 | 说明 |
197
+ |------|------|
198
+ | open() | 打开弹窗 |
199
+ | close() | 关闭弹窗 |
package/dist/index.d.ts CHANGED
@@ -1,10 +1,27 @@
1
1
  import { default as default_2 } from 'react';
2
2
  import { ExecuteResult } from '@hep-code-runner/core';
3
+ import { ReactNode } from 'react';
3
4
 
4
5
  declare const CodeRunner: default_2.FC<CodeRunnerProps>;
5
6
  export { CodeRunner }
6
7
  export default CodeRunner;
7
8
 
9
+ export declare const CodeRunnerDialog: default_2.ForwardRefExoticComponent<CodeRunnerDialogProps & default_2.RefAttributes<CodeRunnerDialogRef>>;
10
+
11
+ export declare interface CodeRunnerDialogProps extends Omit<CodeRunnerProps, "theme"> {
12
+ open?: boolean;
13
+ defaultOpen?: boolean;
14
+ title?: string;
15
+ width?: string | number;
16
+ onClose?: () => void;
17
+ footer?: ReactNode;
18
+ theme?: "light" | "dark";
19
+ }
20
+
21
+ export declare interface CodeRunnerDialogRef {
22
+ close: () => void;
23
+ }
24
+
8
25
  export declare interface CodeRunnerProps {
9
26
  pistonUrl?: string;
10
27
  language?: string;