@thanh01.pmt/interactive-quiz-kit 1.0.12 → 1.0.15
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/HEADLESS.md +126 -213
- package/README.md +83 -95
- package/dist/ai.cjs +1449 -0
- package/dist/ai.js +1438 -0
- package/dist/authoring.cjs +9447 -0
- package/dist/authoring.js +9379 -0
- package/dist/index.cjs +2458 -0
- package/dist/index.js +2440 -0
- package/dist/player.cjs +2942 -0
- package/dist/player.js +2906 -0
- package/dist/react-ui.cjs +9584 -0
- package/dist/react-ui.js +9505 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Interactive Quiz Kit
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@thanh01.pmt/interactive-quiz-kit)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
6
|
**Interactive Quiz Kit** is a comprehensive TypeScript library built with React, designed to effortlessly create, manage, play, and distribute interactive quizzes. It provides a robust core logic (`QuizEngine`), reusable React UI components, and support for a wide variety of question types.
|
|
@@ -9,43 +9,51 @@ The library is architected for easy extension and integration, featuring a power
|
|
|
9
9
|
|
|
10
10
|
## ✨ Features
|
|
11
11
|
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
* **Robust Core Engine**: Handles state management, navigation, automatic grading, and time tracking.
|
|
13
|
+
* **Rich Question Support**: Includes 12+ question types, from Multiple Choice to complex ones like Blockly/Scratch Programming and Hotspot.
|
|
14
|
+
* **Modular React UI Kit**: A full suite of components to build quiz players and authoring tools, organized into logical entry points.
|
|
15
|
+
* **Headless Mode**: Use all core logic, services, and AI flows independently of the React UI. Ideal for backend integrations, custom frontends, or automation scripts.
|
|
16
|
+
* **Advanced AI Capabilities**:
|
|
17
|
+
* **Single Question Generation**: Create individual questions based on topic, context, and difficulty.
|
|
18
|
+
* **Full Quiz Generation**: Generate entire, well-structured quizzes using a two-stage planning process.
|
|
19
|
+
* **AI-Powered Practice Mode**: Generate personalized 10-question quizzes on-the-fly from a user-provided curriculum.
|
|
20
|
+
* **Flexible Content Import**: Import curriculum data and learning objectives from TSV files to power the AI Practice Mode.
|
|
21
|
+
* **SCORM & Webhook Integration**:
|
|
22
|
+
* Package quizzes as SCORM 1.2 compliant ZIP files.
|
|
23
|
+
* Send detailed quiz results to a specified webhook URL.
|
|
24
24
|
|
|
25
25
|
## 🚀 Installation
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npm install @
|
|
28
|
+
npm install @thanh01.pmt/interactive-quiz-kit
|
|
29
29
|
# or
|
|
30
|
-
yarn add @
|
|
30
|
+
yarn add @thanh01.pmt/interactive-quiz-kit
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
**Peer Dependencies:** This library requires `react` and `react-dom` as peer dependencies. Ensure they are installed in your project.
|
|
34
34
|
|
|
35
35
|
## 📚 Usage
|
|
36
36
|
|
|
37
|
-
This library
|
|
37
|
+
This library is modular, allowing you to import only the parts you need.
|
|
38
38
|
|
|
39
|
-
###
|
|
39
|
+
### Understanding the Entry Points
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
The package is split into several entry points for optimized usage:
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
* `@thanh01.pmt/interactive-quiz-kit`: The core "headless" library. Contains all types, services (`QuizEngine`, `QuizEditorService`), and utilities. Use this for backend logic or custom UIs.
|
|
44
|
+
* `@thanh01.pmt/interactive-quiz-kit/react-ui`: General-purpose UI components like `<QuizPlayer>` and `<QuizResult>`.
|
|
45
|
+
* `@thanh01.pmt/interactive-quiz-kit/authoring`: The complete UI suite for creating and editing quizzes, centered around the `<QuizAuthoringTool>` component.
|
|
46
|
+
* `@thanh01.pmt/interactive-quiz-kit/ai`: The headless functions for AI-powered content generation.
|
|
47
|
+
* `@thanh01.pmt/interactive-quiz-kit/player`: A dedicated entry point for the player bundle, useful for SCORM packaging.
|
|
48
|
+
|
|
49
|
+
### 1. Displaying a Quiz (Player Mode)
|
|
50
|
+
|
|
51
|
+
Use the `<QuizPlayer>` component for the test-taker's experience.
|
|
44
52
|
|
|
45
53
|
```tsx
|
|
46
|
-
import React
|
|
47
|
-
import { QuizPlayer } from '@
|
|
48
|
-
import type { QuizConfig,
|
|
54
|
+
import React from 'react';
|
|
55
|
+
import { QuizPlayer } from '@thanh01.pmt/interactive-quiz-kit/react-ui';
|
|
56
|
+
import type { QuizConfig, QuizResultType } from '@thanh01.pmt/interactive-quiz-kit';
|
|
49
57
|
|
|
50
58
|
// 1. Define or load your quiz configuration
|
|
51
59
|
const myQuiz: QuizConfig = {
|
|
@@ -59,7 +67,7 @@ const myQuiz: QuizConfig = {
|
|
|
59
67
|
};
|
|
60
68
|
|
|
61
69
|
const MyQuizPage = () => {
|
|
62
|
-
const handleQuizComplete = (result:
|
|
70
|
+
const handleQuizComplete = (result: QuizResultType) => {
|
|
63
71
|
console.log("Quiz Complete!", result);
|
|
64
72
|
// Send result to your backend, or display a summary
|
|
65
73
|
};
|
|
@@ -75,14 +83,15 @@ const MyQuizPage = () => {
|
|
|
75
83
|
};
|
|
76
84
|
```
|
|
77
85
|
|
|
78
|
-
|
|
86
|
+
### 2. Creating Quizzes (Authoring Mode)
|
|
79
87
|
|
|
80
|
-
|
|
88
|
+
Use the `<QuizAuthoringTool>` for a complete content creation interface.
|
|
81
89
|
|
|
82
90
|
```tsx
|
|
83
91
|
import React from 'react';
|
|
84
|
-
import { QuizAuthoringTool
|
|
85
|
-
import
|
|
92
|
+
import { QuizAuthoringTool } from '@thanh01.pmt/interactive-quiz-kit/authoring';
|
|
93
|
+
import { emptyQuiz } from '@thanh01.pmt/interactive-quiz-kit';
|
|
94
|
+
import type { QuizConfig } from '@thanh01.pmt/interactive-quiz-kit';
|
|
86
95
|
|
|
87
96
|
const MyAuthoringPage = () => {
|
|
88
97
|
const handleSave = (quiz: QuizConfig) => {
|
|
@@ -100,80 +109,59 @@ const MyAuthoringPage = () => {
|
|
|
100
109
|
};
|
|
101
110
|
```
|
|
102
111
|
|
|
103
|
-
###
|
|
112
|
+
### 3. Using the "Practice with AI" Feature
|
|
104
113
|
|
|
105
|
-
|
|
114
|
+
The library includes a complete application flow for AI-powered practice sessions.
|
|
106
115
|
|
|
107
|
-
|
|
116
|
+
```tsx
|
|
117
|
+
import React from 'react';
|
|
118
|
+
// AppController is a conceptual component you would build
|
|
119
|
+
// using the blocks provided by the library.
|
|
120
|
+
import { AppController } from './components/AppController';
|
|
121
|
+
|
|
122
|
+
// This component would render the main menu, allowing users to switch
|
|
123
|
+
// between Authoring, Practice Mode, and Managing Topics.
|
|
124
|
+
const FullApplication = () => {
|
|
125
|
+
return <AppController />;
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 4. Headless Mode (Core Logic Only)
|
|
130
|
+
|
|
131
|
+
Use the library's services in any JavaScript/TypeScript environment.
|
|
108
132
|
|
|
109
|
-
|
|
133
|
+
> For detailed examples and a full component list, see [**HEADLESS.md**](./HEADLESS.md).
|
|
110
134
|
|
|
111
|
-
|
|
135
|
+
#### Example: Creating a Quiz Programmatically
|
|
112
136
|
|
|
113
137
|
```typescript
|
|
114
|
-
import { QuizEditorService, emptyQuiz } from '@
|
|
115
|
-
import type { MultipleChoiceQuestion } from '@
|
|
138
|
+
import { QuizEditorService, emptyQuiz } from '@thanh01.pmt/interactive-quiz-kit';
|
|
139
|
+
import type { MultipleChoiceQuestion } from '@thanh01.pmt/interactive-quiz-kit';
|
|
116
140
|
|
|
117
141
|
// Start with an empty quiz config
|
|
118
142
|
const editor = new QuizEditorService(emptyQuiz);
|
|
119
143
|
|
|
120
|
-
// Create a question
|
|
144
|
+
// Create and populate a question
|
|
121
145
|
const mcqTemplate = QuizEditorService.createNewQuestionTemplate('multiple_choice') as MultipleChoiceQuestion;
|
|
122
|
-
|
|
123
|
-
// Populate the question details
|
|
124
146
|
mcqTemplate.prompt = "What is the capital of France?";
|
|
125
147
|
mcqTemplate.options = [
|
|
126
148
|
{ id: 'opt1', text: 'Berlin' },
|
|
127
149
|
{ id: 'opt2', text: 'Paris' },
|
|
128
|
-
{ id: 'opt3', text: 'Madrid' },
|
|
129
150
|
];
|
|
130
151
|
mcqTemplate.correctAnswerId = 'opt2';
|
|
131
152
|
|
|
132
|
-
// Add the question to the quiz
|
|
133
153
|
editor.addQuestion(mcqTemplate);
|
|
134
|
-
|
|
135
|
-
// Get the final, updated quiz configuration
|
|
136
154
|
const finalQuizConfig = editor.getQuiz();
|
|
137
155
|
|
|
138
|
-
// Now you can save `finalQuizConfig` to your database
|
|
139
156
|
console.log(finalQuizConfig);
|
|
140
157
|
```
|
|
141
158
|
|
|
142
|
-
#### Example: Running a Quiz Session with `QuizEngine`
|
|
143
|
-
|
|
144
|
-
This is useful for backend-driven quizzes or for running simulations.
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
import { QuizEngine } from '@thanh01pmt/interactive-quiz-kit';
|
|
148
|
-
import type { QuizConfig, QuizResult } from '@thanh01pmt/interactive-quiz-kit';
|
|
149
|
-
|
|
150
|
-
const myQuizConfig: QuizConfig = /* ... load your quiz config ... */;
|
|
151
|
-
|
|
152
|
-
const engine = new QuizEngine({
|
|
153
|
-
config: myQuizConfig,
|
|
154
|
-
callbacks: {
|
|
155
|
-
onQuizFinish: (result: QuizResult) => {
|
|
156
|
-
console.log(`Quiz finished! Final score: ${result.score}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Simulate answering the first question
|
|
162
|
-
const firstQuestion = engine.getCurrentQuestion();
|
|
163
|
-
if (firstQuestion) {
|
|
164
|
-
engine.submitAnswer(firstQuestion.id, 'id_of_the_user_answer');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Finalize the quiz
|
|
168
|
-
engine.calculateResults();
|
|
169
|
-
```
|
|
170
|
-
|
|
171
159
|
#### Example: Generating a Question with AI
|
|
172
160
|
|
|
173
|
-
|
|
161
|
+
*Requires Genkit environment setup.*
|
|
174
162
|
|
|
175
163
|
```typescript
|
|
176
|
-
import { generateTrueFalseQuestion } from '@
|
|
164
|
+
import { generateTrueFalseQuestion } from '@thanh01.pmt/interactive-quiz-kit/ai';
|
|
177
165
|
|
|
178
166
|
async function createNewQuestion() {
|
|
179
167
|
try {
|
|
@@ -184,7 +172,6 @@ async function createNewQuestion() {
|
|
|
184
172
|
|
|
185
173
|
if (question) {
|
|
186
174
|
console.log("AI-generated question:", question);
|
|
187
|
-
// Save to your database
|
|
188
175
|
}
|
|
189
176
|
} catch (error) {
|
|
190
177
|
console.error("Failed to generate question:", error);
|
|
@@ -195,35 +182,36 @@ async function createNewQuestion() {
|
|
|
195
182
|
## Supported Question Types
|
|
196
183
|
|
|
197
184
|
The library supports a wide array of 12+ question types, including:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
185
|
+
|
|
186
|
+
* `multiple_choice`
|
|
187
|
+
* `multiple_response`
|
|
188
|
+
* `true_false`
|
|
189
|
+
* `short_answer`
|
|
190
|
+
* `numeric`
|
|
191
|
+
* `fill_in_the_blanks`
|
|
192
|
+
* `sequence`
|
|
193
|
+
* `matching`
|
|
194
|
+
* `drag_and_drop`
|
|
195
|
+
* `hotspot`
|
|
196
|
+
* `blockly_programming`
|
|
197
|
+
* `scratch_programming`
|
|
210
198
|
|
|
211
199
|
## Known Issues
|
|
212
200
|
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
201
|
+
* **Asset Integration for Programming Questions**: Using `Blockly` or `Scratch` questions requires manually copying assets (`js`, `css`, `media`) from their respective `node_modules` folders into your project's `public` directory for the UI components to render correctly.
|
|
202
|
+
* **SCORM Packaging**: The SCORM export function relies on fetching the player assets (`player.js`, `styles.css`) from your `public` folder at the time of packaging. Ensure these files are present and accessible.
|
|
203
|
+
* **AI Generation Limits**: AI generation is not yet supported for visually complex types like `Drag and Drop`, `Hotspot`, `Blockly`, or `Scratch`.
|
|
216
204
|
|
|
217
205
|
## 🤝 Contributing
|
|
218
206
|
|
|
219
207
|
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have ideas for improvements or find a bug.
|
|
220
208
|
|
|
221
|
-
1.
|
|
222
|
-
2.
|
|
223
|
-
3.
|
|
224
|
-
4.
|
|
225
|
-
5.
|
|
209
|
+
1. Fork the repository.
|
|
210
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`).
|
|
211
|
+
3. Commit your changes (`git commit -m 'feat: Add some AmazingFeature'`).
|
|
212
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`).
|
|
213
|
+
5. Open a Pull Request.
|
|
226
214
|
|
|
227
215
|
## 📄 License
|
|
228
216
|
|
|
229
|
-
This project is licensed under the MIT License
|
|
217
|
+
This project is licensed under the MIT License.
|