cloudlab-ui 0.0.7 → 0.0.9

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/lib/index.d.ts ADDED
@@ -0,0 +1,446 @@
1
+ /**
2
+ * cloudlab-ui 组件库类型声明文件
3
+ *
4
+ * 本文件提供所有导出组件、hooks、工具函数和类型的 TypeScript 声明
5
+ */
6
+
7
+ import * as React from 'react';
8
+
9
+ // ==================== 类型定义 ====================
10
+
11
+ export type Scenario = 'exam' | 'response' | 'reanswer' | 'editor' | 'write';
12
+
13
+ export type QuestionType = 'radio' | 'checkbox' | 'answer' | 'completion' | 'ccm';
14
+
15
+ export interface Style {
16
+ className?: string;
17
+ style?: React.CSSProperties;
18
+ }
19
+
20
+ // 单选题数据结构
21
+ export interface RadioQuestionData {
22
+ type: 'radio';
23
+ text: string;
24
+ options: Array<{ title: string; value: string }>;
25
+ answer: string;
26
+ score?: number;
27
+ analysis?: string;
28
+ validated?: boolean;
29
+ validateMessage?: string;
30
+ }
31
+
32
+ // 多选题数据结构
33
+ export interface MultipleQuestionData {
34
+ type: 'checkbox';
35
+ text: string;
36
+ options: Array<{ title: string; value: string }>;
37
+ answer: Array<string>;
38
+ score?: number;
39
+ analysis?: string;
40
+ validated?: boolean;
41
+ validateMessage?: string;
42
+ }
43
+
44
+ // 问答题数据结构
45
+ export interface AnswerQuestionData {
46
+ type: 'answer';
47
+ text: string;
48
+ answer: string;
49
+ score?: number;
50
+ analysis?: string;
51
+ validated?: boolean;
52
+ validateMessage?: string;
53
+ }
54
+
55
+ // 填空题数据结构
56
+ export interface CompletionQuestionData {
57
+ type: 'completion';
58
+ text: string;
59
+ inputList: Array<{
60
+ id: string;
61
+ answer: string;
62
+ userAnswer?: string;
63
+ }>;
64
+ answerList: Array<string>;
65
+ score?: number;
66
+ validated?: boolean;
67
+ validateMessage?: string;
68
+ }
69
+
70
+ // 编码测验题数据结构
71
+ export interface CcmQuestionData {
72
+ type: string;
73
+ form: string;
74
+ topic: string;
75
+ text: string;
76
+ codeText: {
77
+ lang: string;
78
+ value: string;
79
+ };
80
+ example: Array<{ input: string[]; output: string }>;
81
+ test: Array<{ input: string[]; output: string }>;
82
+ score?: number;
83
+ validated?: boolean;
84
+ validateMessage?: string;
85
+ }
86
+
87
+ // 代码块数据结构
88
+ export interface CodeBlockData {
89
+ type: 'codeBlock';
90
+ text: string;
91
+ lang: string;
92
+ langList: Array<string>;
93
+ meta?: string;
94
+ }
95
+
96
+ // 自动判分请求参数
97
+ export interface AutoScoreParams {
98
+ id?: string;
99
+ type: string;
100
+ title: string;
101
+ content: string;
102
+ score: number;
103
+ require: string;
104
+ answer: string;
105
+ commit: string;
106
+ }
107
+
108
+ // 判分反馈信息
109
+ export interface ReasonsParams {
110
+ item?: string;
111
+ reason: string;
112
+ score: number;
113
+ }
114
+
115
+ // 自动判分响应
116
+ export interface AutoScoreResponse {
117
+ userScore: number;
118
+ reasons: ReasonsParams[];
119
+ answer?: string;
120
+ comment?: string;
121
+ [key: string]: unknown;
122
+ }
123
+
124
+ // 基础题目 JSON 结构(新格式)
125
+ export interface BaseQuestionJson {
126
+ type: string;
127
+ topic?: string;
128
+ content?: string | null;
129
+ difficulty?: string;
130
+ score?: number;
131
+ option?: Array<{ key: string; value: string }>;
132
+ answer?: unknown;
133
+ description?: string;
134
+ validated?: boolean;
135
+ message?: string;
136
+ [key: string]: unknown;
137
+ }
138
+
139
+ // ==================== 组件 Props ====================
140
+
141
+ export interface QuestionRadioProps {
142
+ scenario?: Scenario;
143
+ content: string | RadioQuestionData | BaseQuestionJson;
144
+ index?: number;
145
+ elements?: React.ReactNode[];
146
+ className?: string;
147
+ disabled?: boolean;
148
+ scoreDisabled?: boolean;
149
+ showScore?: boolean;
150
+ elementCheckbox?: React.ReactNode;
151
+ elementLabel?: React.ReactNode;
152
+ requestId?: string;
153
+ onAnswer?: (answer: string) => void;
154
+ onScore?: (score: number) => void;
155
+ returnContent?: (content: RadioQuestionData) => void;
156
+ }
157
+
158
+ export interface QuestionMultipleProps {
159
+ content: string | MultipleQuestionData | BaseQuestionJson;
160
+ index?: number;
161
+ elements?: React.ReactNode[];
162
+ className?: string;
163
+ disabled?: boolean;
164
+ scoreDisabled?: boolean;
165
+ showScore?: boolean;
166
+ elementCheckbox?: React.ReactNode;
167
+ elementLabel?: React.ReactNode;
168
+ onAnswer?: (answer: string[]) => void;
169
+ onScore?: (score: number) => void;
170
+ returnContent?: (content: MultipleQuestionData) => void;
171
+ scenario?: Scenario;
172
+ requestId?: string;
173
+ onAutoScore?: (result: {
174
+ success: boolean;
175
+ score?: number;
176
+ reasons?: Array<{ item?: string; reason: string; score: number }>;
177
+ }) => void;
178
+ }
179
+
180
+ export interface QuestionAnswerProps {
181
+ scenario?: Scenario;
182
+ content: string | AnswerQuestionData | BaseQuestionJson;
183
+ index?: number;
184
+ elements?: React.ReactNode[];
185
+ className?: string;
186
+ disabled?: boolean;
187
+ scoreDisabled?: boolean;
188
+ showScore?: boolean;
189
+ elementCheckbox?: React.ReactNode;
190
+ elementLabel?: React.ReactNode;
191
+ requestId?: string;
192
+ onAnswer?: (answer: string) => void;
193
+ onScore?: (score: number) => void;
194
+ returnContent?: (content: AnswerQuestionData) => void;
195
+ }
196
+
197
+ export interface QuestionCompletionProps {
198
+ scenario?: Scenario;
199
+ content?: string | CompletionQuestionData | BaseQuestionJson;
200
+ index?: number;
201
+ elements?: React.ReactNode;
202
+ className?: string;
203
+ disabled?: boolean;
204
+ scoreDisabled?: boolean;
205
+ showScore?: boolean;
206
+ requestId?: string;
207
+ onAnswer?: (answer: string) => void;
208
+ onScore?: (score: number, isCorrect: boolean) => void;
209
+ returnContent?: (content: string) => void;
210
+ }
211
+
212
+ export interface QuestionCcmProps {
213
+ content: string | CcmQuestionData | BaseQuestionJson;
214
+ index?: number;
215
+ elements?: React.ReactNode[];
216
+ className?: string;
217
+ disabled?: boolean;
218
+ scoreDisabled?: boolean;
219
+ showScore?: boolean;
220
+ elementCheckbox?: React.ReactNode;
221
+ elementLabel?: React.ReactNode;
222
+ onAnswer?: (answer: string) => void;
223
+ onScore?: (score: number) => void;
224
+ onGoAnswer?: (content: CcmQuestionData) => void;
225
+ returnContent?: (content: CcmQuestionData) => void;
226
+ }
227
+
228
+ export interface CodeBlockProps {
229
+ content: string;
230
+ enviroment?: string[];
231
+ env?: string;
232
+ elements?: React.ReactNode[];
233
+ assistantElements?: React.ReactNode[];
234
+ assistantShow?: boolean;
235
+ token?: string;
236
+ onCodeChange?: (code: string) => void;
237
+ onLanguageChange?: (lang: string) => void;
238
+ onEnvChange?: (env: string) => void;
239
+ returnContent?: (content: CodeBlockData) => void;
240
+ onExecuteCode?: (content: CodeBlockData) => void;
241
+ executeResult?: { success?: boolean; output?: string; error?: string } | null;
242
+ returnAssistantShow?: (show: boolean) => void;
243
+ }
244
+
245
+ // ==================== Hooks 返回类型 ====================
246
+
247
+ export interface UseRadioQuestionReturn {
248
+ data: RadioQuestionData | undefined;
249
+ parse: (raw: string | BaseQuestionJson | undefined | null) => void;
250
+ toString: () => string;
251
+ ask: () => void;
252
+ updateScore: (score: number | '') => void;
253
+ value: string;
254
+ onChange: (e: any) => void;
255
+ submitted: boolean;
256
+ analysisSentence: string;
257
+ tipType: 'correct' | 'incorrect' | 'warning' | 'reanswerIncorrect' | '';
258
+ isSubmitting: boolean;
259
+ submitForAutoScore: () => Promise<void>;
260
+ isExpanded: boolean;
261
+ setIsExpanded: (expanded: boolean) => void;
262
+ onChangeSubmit: () => void;
263
+ }
264
+
265
+ export interface UseMultipleQuestionReturn {
266
+ data: MultipleQuestionData | undefined;
267
+ parse: (raw: string | BaseQuestionJson | undefined | null) => void;
268
+ toString: () => string;
269
+ ask: () => void;
270
+ updateScore: (score: number | '') => void;
271
+ selectedValues: string[];
272
+ handleMultipleChange: (values: string[]) => void;
273
+ submitForAutoScore: () => Promise<void>;
274
+ isSubmitting: boolean;
275
+ scenario: Scenario;
276
+ submitted: boolean;
277
+ isExpanded: boolean;
278
+ analysisSentence: string;
279
+ setIsExpanded: (expanded: boolean) => void;
280
+ tipType: 'correct' | 'incorrect' | 'warning' | 'reanswerIncorrect' | '' | null;
281
+ onChangeSubmit: () => void;
282
+ }
283
+
284
+ export interface UseAnswerQuestionReturn {
285
+ data: AnswerQuestionData | undefined;
286
+ parse: (raw: string | BaseQuestionJson | undefined | null) => void;
287
+ toString: () => string;
288
+ ask: () => void;
289
+ updateScore: (score: number | '') => void;
290
+ userAnswer: string;
291
+ updateUserAnswer: (answer: string) => void;
292
+ submitted: boolean;
293
+ analysisSentence: string;
294
+ tipType: 'correct' | 'incorrect' | 'warning' | 'reanswerIncorrect' | '';
295
+ isSubmitting: boolean;
296
+ submitForAutoScore: () => Promise<void>;
297
+ isExpanded: boolean;
298
+ setIsExpanded: (expanded: boolean) => void;
299
+ onChangeSubmit: () => void;
300
+ }
301
+
302
+ export interface UseCompletionQuestionReturn {
303
+ data: CompletionQuestionData | undefined;
304
+ parse: (raw: string | BaseQuestionJson | undefined | null) => void;
305
+ toString: () => string;
306
+ updateScore: (score: number | '') => void;
307
+ updateAnswer: (blankId: string, answer: string) => void;
308
+ submitForAutoScore: () => Promise<void>;
309
+ isSubmitting: boolean;
310
+ submitted: boolean;
311
+ isExpanded: boolean;
312
+ analysisSentence: string;
313
+ setIsExpanded: (expanded: boolean) => void;
314
+ tipType: 'correct' | 'incorrect' | 'warning' | 'reanswerIncorrect' | '' | null;
315
+ onChangeSubmit: () => void;
316
+ elementLabel: React.ReactNode | null;
317
+ }
318
+
319
+ export interface UseCcmQuestionReturn {
320
+ data: CcmQuestionData | undefined;
321
+ parse: (raw: string | BaseQuestionJson | undefined | null) => void;
322
+ toString: () => string;
323
+ ask: () => void;
324
+ updateScore: (score: number | '') => void;
325
+ }
326
+
327
+ export interface UseCodeBlockReturn {
328
+ data: CodeBlockData | undefined;
329
+ parse: (content: string) => void;
330
+ toString: () => string;
331
+ height: number;
332
+ isExecuting: boolean;
333
+ executeResult: { success?: boolean; output?: string; error?: string } | null;
334
+ updateCode: (newCode: string) => void;
335
+ updateLanguage: (newLanguage: string) => void;
336
+ executeCode: () => Promise<void>;
337
+ clearResult: () => void;
338
+ resetCode: () => void;
339
+ setHeight: (height: number) => void;
340
+ wsHandler: (
341
+ runResult: { status?: string; success?: boolean; log?: string; error?: string },
342
+ finish?: boolean,
343
+ type?: string
344
+ ) => void;
345
+ }
346
+
347
+ // ==================== 组件导出 ====================
348
+
349
+ export const QuestionRadio: React.FC<QuestionRadioProps>;
350
+ export const QuestionMultiple: React.FC<QuestionMultipleProps>;
351
+ export const QuestionAnswer: React.FC<QuestionAnswerProps>;
352
+ export const QuestionCompletion: React.FC<QuestionCompletionProps>;
353
+ export const QuestionCcm: React.FC<QuestionCcmProps>;
354
+ export const CodeBlock: React.FC<CodeBlockProps>;
355
+
356
+ // ==================== Hooks 导出 ====================
357
+
358
+ export function useRadioQuestion(
359
+ scenario: Scenario,
360
+ requestId?: string,
361
+ onScore?: (score: number) => void
362
+ ): UseRadioQuestionReturn;
363
+
364
+ export function useMultipleQuestion(props?: {
365
+ content?: string;
366
+ scenario?: Scenario;
367
+ requestId?: string;
368
+ onAutoScore?: (result: {
369
+ success: boolean;
370
+ score?: number;
371
+ reasons?: Array<{ item?: string; reason: string; score: number }>;
372
+ }) => void;
373
+ }): UseMultipleQuestionReturn;
374
+
375
+ export function useAnswerQuestion(
376
+ scenario: Scenario,
377
+ requestId?: string,
378
+ onScore?: (score: number) => void
379
+ ): UseAnswerQuestionReturn;
380
+
381
+ export function useCompletionQuestion(props?: {
382
+ content?: string;
383
+ disabled?: boolean;
384
+ scoreDisabled?: boolean;
385
+ requestId?: string;
386
+ onAnswer?: (answer: string) => void;
387
+ onScore?: (score: number, isCorrect: boolean) => void;
388
+ returnContent?: (content: string) => void;
389
+ }): UseCompletionQuestionReturn;
390
+
391
+ export function useCcmQuestion(): UseCcmQuestionReturn;
392
+
393
+ export function useCodeBlock(props?: {
394
+ content?: string;
395
+ disabled?: boolean;
396
+ onCodeChange?: (code: string) => void;
397
+ onLanguageChange?: (language: string) => void;
398
+ }): UseCodeBlockReturn;
399
+
400
+ // ==================== 工具函数导出 ====================
401
+
402
+ // 解析函数
403
+ export function parseRadioQuestion(content: string): RadioQuestionData;
404
+ export function parseMultipleQuestion(content: string): MultipleQuestionData;
405
+ export function parseAnswerQuestion(content: string): AnswerQuestionData;
406
+ export function parseCompletionQuestion(content: string): CompletionQuestionData;
407
+ export function parseCcmQuestion(content: string): CcmQuestionData;
408
+
409
+ // 转换函数
410
+ export function toRadioQuestion(data: RadioQuestionData): string;
411
+ export function toMultipleQuestion(data: MultipleQuestionData): string;
412
+ export function toAnswerQuestion(data: AnswerQuestionData): string;
413
+ export function toCompletionQuestion(data: CompletionQuestionData): string;
414
+ export function toCcmQuestion(data: CcmQuestionData): string;
415
+
416
+ // 新格式解析函数
417
+ export function parseQuestionsXml(content: string): BaseQuestionJson[];
418
+ export function parseQuestionsPaper(
419
+ content: string
420
+ ): { title?: string; questions: BaseQuestionJson[] };
421
+
422
+ // JSON 格式转换函数
423
+ export function fromJsonRadioQuestion(json: BaseQuestionJson): RadioQuestionData;
424
+ export function fromJsonMultipleQuestion(json: BaseQuestionJson): MultipleQuestionData;
425
+ export function fromJsonCompletionQuestion(json: BaseQuestionJson): CompletionQuestionData;
426
+ export function fromJsonAnswerQuestion(json: BaseQuestionJson): AnswerQuestionData;
427
+ export function fromJsonCcmQuestion(json: BaseQuestionJson): CcmQuestionData;
428
+
429
+ // CodeBlock 工具函数
430
+ export function copy(text: string): void;
431
+
432
+ // ==================== API 函数 ====================
433
+
434
+ export function sendAutoScoreRequest(params: AutoScoreParams): Promise<AutoScoreResponse>;
435
+
436
+ // ==================== 常量导出 ====================
437
+
438
+ export const QuestionTypeList: string[];
439
+ export const QuestionType: {
440
+ RADIO: 'radio';
441
+ CHECKBOX: 'checkbox';
442
+ ANSWER: 'answer';
443
+ COMPLETION: 'completion';
444
+ CCM: 'ccm';
445
+ };
446
+
@@ -1,4 +1,4 @@
1
- import { conf as t, language as e } from "./typescript-Ybmmps0S.js";
1
+ import { conf as t, language as e } from "./typescript-Dvrjb3qe.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as Et } from "./index-gOJ0Yx75.js";
1
+ import { m as Et } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as l } from "./index-gOJ0Yx75.js";
1
+ import { m as l } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as s } from "./index-gOJ0Yx75.js";
1
+ import { m as s } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as o } from "./index-gOJ0Yx75.js";
1
+ import { m as o } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m } from "./index-gOJ0Yx75.js";
1
+ import { m } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { t as O, m as I } from "./index-gOJ0Yx75.js";
1
+ import { t as O, m as I } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as s } from "./index-gOJ0Yx75.js";
1
+ import { m as s } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as r } from "./index-gOJ0Yx75.js";
1
+ import { m as r } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
@@ -1,4 +1,4 @@
1
- import { m as l } from "./index-gOJ0Yx75.js";
1
+ import { m as l } from "./index-DLAagtyg.js";
2
2
  /*!-----------------------------------------------------------------------------
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudlab-ui",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"
@@ -10,6 +10,7 @@
10
10
  "types": "./lib/index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./lib/index.d.ts",
13
14
  "import": "./lib/cloudlab-ui.js",
14
15
  "require": "./lib/cloudlab-ui.umd.cjs"
15
16
  },
@@ -19,7 +20,7 @@
19
20
  "scripts": {
20
21
  "start": "vite --open",
21
22
  "dev": "vite",
22
- "build": "tsc && vite build",
23
+ "build": "tsc && vite build && cp src/index.d.ts lib/index.d.ts",
23
24
  "lint": "eslint .",
24
25
  "preview": "vite preview",
25
26
  "typecheck": "tsc --noEmit"