@pie-element/match-list 7.2.2-beta.6 → 7.2.2-beta.7
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/CHANGELOG.md +4 -0
- package/controller/CHANGELOG.md +4 -0
- package/controller/lib/defaults.js +15 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +246 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/package.json +1 -1
- package/lib/answer-area.js +168 -0
- package/lib/answer-area.js.map +1 -0
- package/lib/answer.js +267 -0
- package/lib/answer.js.map +1 -0
- package/lib/arrow.js +57 -0
- package/lib/arrow.js.map +1 -0
- package/lib/choices-list.js +60 -0
- package/lib/choices-list.js.map +1 -0
- package/lib/droppable-placeholder.js +60 -0
- package/lib/droppable-placeholder.js.map +1 -0
- package/lib/index.js +87 -0
- package/lib/index.js.map +1 -0
- package/lib/main.js +220 -0
- package/lib/main.js.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [7.2.2-beta.7](https://github.com/pie-framework/pie-elements/compare/@pie-element/match-list@7.2.2-beta.6...@pie-element/match-list@7.2.2-beta.7) (2026-09-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @pie-element/match-list
|
|
9
|
+
|
|
6
10
|
## [7.2.2-beta.6](https://github.com/pie-framework/pie-elements/compare/@pie-element/match-list@7.2.2-beta.5...@pie-element/match-list@7.2.2-beta.6) (2026-09-24)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @pie-element/match-list
|
package/controller/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.4.0-beta.13](https://github.com/pie-framework/pie-elements/compare/@pie-element/match-list-controller@6.4.0-beta.12...@pie-element/match-list-controller@6.4.0-beta.13) (2026-09-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @pie-element/match-list-controller
|
|
9
|
+
|
|
6
10
|
# [6.4.0-beta.12](https://github.com/pie-framework/pie-elements/compare/@pie-element/match-list-controller@6.4.0-beta.11...@pie-element/match-list-controller@6.4.0-beta.12) (2026-09-24)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @pie-element/match-list-controller
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
config: {
|
|
9
|
+
answers: [],
|
|
10
|
+
prompt: '',
|
|
11
|
+
prompts: [],
|
|
12
|
+
shuffled: false
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","names":["config","answers","prompt","prompts","shuffled"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n config: {\n answers: [],\n prompt: '',\n prompts: [],\n shuffled: false,\n },\n};\n"],"mappings":";;;;;;iCAAe;EACbA,MAAM,EAAE;IACNC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAE,EAAE;IACVC,OAAO,EAAE,EAAE;IACXC,QAAQ,EAAE;EACZ;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createCorrectResponseSession = void 0;
|
|
8
|
+
exports.createDefaultModel = createDefaultModel;
|
|
9
|
+
exports.getLogTrace = void 0;
|
|
10
|
+
exports.model = model;
|
|
11
|
+
exports.outcome = exports.normalize = void 0;
|
|
12
|
+
var _lodashEs = require("lodash-es");
|
|
13
|
+
var _feedback = require("@pie-lib/feedback");
|
|
14
|
+
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
15
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
16
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
17
|
+
const log = (0, _debug.default)('@pie-element:match-list:controller');
|
|
18
|
+
const getResponseCorrectness = (model, answers, env) => {
|
|
19
|
+
const isPartialScoring = _controllerUtils.partialScoring.enabled(model, env);
|
|
20
|
+
const prompts = model.prompts;
|
|
21
|
+
if (!answers || Object.keys(answers).length === 0) {
|
|
22
|
+
return 'unanswered';
|
|
23
|
+
}
|
|
24
|
+
const totalCorrectAnswers = getTotalCorrect(model);
|
|
25
|
+
const correctAnswers = getCorrectSelected(prompts, answers);
|
|
26
|
+
if (totalCorrectAnswers === correctAnswers) {
|
|
27
|
+
return 'correct';
|
|
28
|
+
} else if (correctAnswers === 0) {
|
|
29
|
+
return 'incorrect';
|
|
30
|
+
} else if (isPartialScoring) {
|
|
31
|
+
return 'partial';
|
|
32
|
+
}
|
|
33
|
+
return 'incorrect';
|
|
34
|
+
};
|
|
35
|
+
const getCorrectness = (question, env, answers) => {
|
|
36
|
+
if (env.mode === 'evaluate') {
|
|
37
|
+
return getResponseCorrectness(question, answers, env);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getCorrectSelected = (prompts = [], answers) => {
|
|
41
|
+
let correctAnswers = 0;
|
|
42
|
+
prompts.forEach(p => {
|
|
43
|
+
if (p.relatedAnswer === answers[p.id]) {
|
|
44
|
+
correctAnswers += 1;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return correctAnswers;
|
|
48
|
+
};
|
|
49
|
+
const getTotalCorrect = question => {
|
|
50
|
+
return question && question.prompts ? question.prompts.length : 0;
|
|
51
|
+
};
|
|
52
|
+
const getPartialScore = (question, answers) => {
|
|
53
|
+
const count = getCorrectSelected(question && question.prompts, answers);
|
|
54
|
+
const totalCorrect = getTotalCorrect(question);
|
|
55
|
+
return parseFloat((count / totalCorrect).toFixed(2));
|
|
56
|
+
};
|
|
57
|
+
const getOutComeScore = (question, env, answers) => {
|
|
58
|
+
const correctness = getCorrectness(question, env, answers);
|
|
59
|
+
return correctness === 'correct' ? 1 : correctness === 'partial' && true ? getPartialScore(question, answers) : 0;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Generates detailed trace log for match-list scoring evaluation
|
|
64
|
+
* @param {Object} question
|
|
65
|
+
* @param {Object} session
|
|
66
|
+
* @param {Object} env
|
|
67
|
+
* @returns {Array<string>} traceLog
|
|
68
|
+
*/
|
|
69
|
+
const getLogTrace = (question, session, env) => {
|
|
70
|
+
const traceLog = [];
|
|
71
|
+
const prompts = question?.prompts || [];
|
|
72
|
+
const answers = session?.value || {};
|
|
73
|
+
if (!answers || Object.keys(answers).length === 0) {
|
|
74
|
+
traceLog.push('Student did not provide any answer.');
|
|
75
|
+
return traceLog;
|
|
76
|
+
}
|
|
77
|
+
const totalPrompts = prompts.length;
|
|
78
|
+
traceLog.push(`Match-list item contains ${totalPrompts} question(s).`);
|
|
79
|
+
let correctCount = 0;
|
|
80
|
+
let answeredCount = 0;
|
|
81
|
+
prompts.forEach(prompt => {
|
|
82
|
+
const expectedAnswer = prompt.relatedAnswer;
|
|
83
|
+
const studentAnswer = answers[prompt.id];
|
|
84
|
+
if (studentAnswer !== undefined) {
|
|
85
|
+
answeredCount += 1;
|
|
86
|
+
if (studentAnswer === expectedAnswer) {
|
|
87
|
+
correctCount += 1;
|
|
88
|
+
traceLog.push(`Question ${prompt.id}: correctly matched.`);
|
|
89
|
+
} else {
|
|
90
|
+
traceLog.push(`Question ${prompt.id}: incorrectly matched (selected '${studentAnswer}', expected '${expectedAnswer}').`);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
traceLog.push(`Question ${prompt.id}: no answer provided.`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
traceLog.push(`Student correctly matched ${correctCount} out of ${totalPrompts} question(s).`);
|
|
97
|
+
const partialScoringEnabled = _controllerUtils.partialScoring.enabled(question, env);
|
|
98
|
+
if (partialScoringEnabled) {
|
|
99
|
+
traceLog.push('Score calculated using partial scoring.');
|
|
100
|
+
traceLog.push('Score is the number of correct matches divided by the total number of questions.');
|
|
101
|
+
} else {
|
|
102
|
+
traceLog.push('Score calculated using all-or-nothing scoring.');
|
|
103
|
+
traceLog.push('Student must match all questions correctly to receive full credit.');
|
|
104
|
+
}
|
|
105
|
+
const rawScore = getOutComeScore(question, env, answers);
|
|
106
|
+
const finalScore = partialScoringEnabled ? rawScore : rawScore === 1 ? 1 : 0;
|
|
107
|
+
traceLog.push(`Final score: ${finalScore}.`);
|
|
108
|
+
return traceLog;
|
|
109
|
+
};
|
|
110
|
+
exports.getLogTrace = getLogTrace;
|
|
111
|
+
const outcome = (question, session, env) => {
|
|
112
|
+
return new Promise(resolve => {
|
|
113
|
+
if (env.mode !== 'evaluate') {
|
|
114
|
+
resolve({
|
|
115
|
+
score: undefined,
|
|
116
|
+
completed: undefined,
|
|
117
|
+
logTrace: []
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
121
|
+
resolve({
|
|
122
|
+
score: 0,
|
|
123
|
+
empty: true,
|
|
124
|
+
logTrace: ['Student did not provide any answer.']
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
const out = {
|
|
128
|
+
score: getOutComeScore(question, env, session.value),
|
|
129
|
+
empty: false,
|
|
130
|
+
logTrace: getLogTrace(question, session, env)
|
|
131
|
+
};
|
|
132
|
+
resolve(out);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
exports.outcome = outcome;
|
|
138
|
+
function createDefaultModel(model = {}) {
|
|
139
|
+
return new Promise(resolve => {
|
|
140
|
+
resolve({
|
|
141
|
+
..._defaults.default,
|
|
142
|
+
...model
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const normalize = model => ({
|
|
147
|
+
..._defaults.default,
|
|
148
|
+
...model
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
* @param {*} question
|
|
154
|
+
* @param {*} session
|
|
155
|
+
* @param {*} env
|
|
156
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
157
|
+
*/
|
|
158
|
+
exports.normalize = normalize;
|
|
159
|
+
async function model(question, session, env, updateSession) {
|
|
160
|
+
question = normalize(question);
|
|
161
|
+
const correctness = getCorrectness(question, env, session && session.value);
|
|
162
|
+
const correctResponse = {};
|
|
163
|
+
const score = `${getOutComeScore(question, env, session && session.value) * 100}%`;
|
|
164
|
+
const correctInfo = {
|
|
165
|
+
score,
|
|
166
|
+
correctness
|
|
167
|
+
};
|
|
168
|
+
const shuffledValues = {};
|
|
169
|
+
let prompts = question.prompts;
|
|
170
|
+
let answers = question.answers;
|
|
171
|
+
const us = part => (id, element, update) => {
|
|
172
|
+
return new Promise(resolve => {
|
|
173
|
+
shuffledValues[part] = update.shuffledValues;
|
|
174
|
+
resolve();
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
const lockChoiceOrder = (0, _controllerUtils.lockChoices)(question, session, env);
|
|
178
|
+
if (!lockChoiceOrder) {
|
|
179
|
+
prompts = await (0, _controllerUtils.getShuffledChoices)(prompts, {
|
|
180
|
+
shuffledValues: (session && session.shuffledValues || {}).prompts
|
|
181
|
+
}, us('prompts'), 'id');
|
|
182
|
+
answers = await (0, _controllerUtils.getShuffledChoices)(answers, {
|
|
183
|
+
shuffledValues: (session && session.shuffledValues || {}).answers
|
|
184
|
+
}, us('answers'), 'id');
|
|
185
|
+
}
|
|
186
|
+
if (!(0, _lodashEs.isEmpty)(shuffledValues)) {
|
|
187
|
+
if (updateSession && typeof updateSession === 'function') {
|
|
188
|
+
updateSession(session.id, session.element, {
|
|
189
|
+
shuffledValues
|
|
190
|
+
}).catch(e => {
|
|
191
|
+
// eslint-disable-next-line no-console
|
|
192
|
+
console.error('update session failed', e);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (question && prompts) {
|
|
197
|
+
prompts.forEach(prompt => {
|
|
198
|
+
correctResponse[prompt.id] = prompt.relatedAnswer;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const feedback = env.mode === 'evaluate' ? await (0, _feedback.getFeedbackForCorrectness)(correctInfo.correctness, question.feedback) : undefined;
|
|
202
|
+
const base = {
|
|
203
|
+
config: {
|
|
204
|
+
...question,
|
|
205
|
+
prompts,
|
|
206
|
+
answers
|
|
207
|
+
},
|
|
208
|
+
correctness: correctInfo,
|
|
209
|
+
feedback,
|
|
210
|
+
mode: env.mode
|
|
211
|
+
};
|
|
212
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
213
|
+
base.rationale = question.rationale;
|
|
214
|
+
} else {
|
|
215
|
+
base.rationale = null;
|
|
216
|
+
}
|
|
217
|
+
const out = Object.assign(base, {
|
|
218
|
+
correctResponse
|
|
219
|
+
});
|
|
220
|
+
log('out: ', out);
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
const createCorrectResponseSession = (question, env) => {
|
|
224
|
+
return new Promise(resolve => {
|
|
225
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
226
|
+
const {
|
|
227
|
+
prompts,
|
|
228
|
+
answers
|
|
229
|
+
} = question;
|
|
230
|
+
const value = {};
|
|
231
|
+
prompts.forEach(p => {
|
|
232
|
+
if (answers.filter(a => a.id === p.relatedAnswer).length) {
|
|
233
|
+
value[p.id] = p.relatedAnswer;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
resolve({
|
|
237
|
+
value,
|
|
238
|
+
id: '1'
|
|
239
|
+
});
|
|
240
|
+
} else {
|
|
241
|
+
resolve(null);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
246
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_lodashEs","require","_feedback","_controllerUtils","_debug","_interopRequireDefault","_defaults","log","debug","getResponseCorrectness","model","answers","env","isPartialScoring","partialScoring","enabled","prompts","Object","keys","length","totalCorrectAnswers","getTotalCorrect","correctAnswers","getCorrectSelected","getCorrectness","question","mode","forEach","p","relatedAnswer","id","getPartialScore","count","totalCorrect","parseFloat","toFixed","getOutComeScore","correctness","getLogTrace","session","traceLog","value","push","totalPrompts","correctCount","answeredCount","prompt","expectedAnswer","studentAnswer","undefined","partialScoringEnabled","rawScore","finalScore","exports","outcome","Promise","resolve","score","completed","logTrace","isEmpty","empty","out","createDefaultModel","defaults","normalize","updateSession","correctResponse","correctInfo","shuffledValues","us","part","element","update","lockChoiceOrder","lockChoices","getShuffledChoices","catch","e","console","error","feedback","getFeedbackForCorrectness","base","config","role","rationale","assign","createCorrectResponseSession","filter","a"],"sources":["../src/index.js"],"sourcesContent":["import { isEmpty } from 'lodash-es';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nconst log = debug('@pie-element:match-list:controller');\n\nimport defaults from './defaults';\n\nconst getResponseCorrectness = (model, answers, env) => {\n const isPartialScoring = partialScoring.enabled(model, env);\n const prompts = model.prompts;\n\n if (!answers || Object.keys(answers).length === 0) {\n return 'unanswered';\n }\n\n const totalCorrectAnswers = getTotalCorrect(model);\n const correctAnswers = getCorrectSelected(prompts, answers);\n\n if (totalCorrectAnswers === correctAnswers) {\n return 'correct';\n } else if (correctAnswers === 0) {\n return 'incorrect';\n } else if (isPartialScoring) {\n return 'partial';\n }\n\n return 'incorrect';\n};\n\nconst getCorrectness = (question, env, answers) => {\n if (env.mode === 'evaluate') {\n return getResponseCorrectness(question, answers, env);\n }\n};\n\nconst getCorrectSelected = (prompts = [], answers) => {\n let correctAnswers = 0;\n\n prompts.forEach((p) => {\n if (p.relatedAnswer === answers[p.id]) {\n correctAnswers += 1;\n }\n });\n\n return correctAnswers;\n};\n\nconst getTotalCorrect = (question) => {\n return question && question.prompts ? question.prompts.length : 0;\n};\n\nconst getPartialScore = (question, answers) => {\n const count = getCorrectSelected(question && question.prompts, answers);\n const totalCorrect = getTotalCorrect(question);\n\n return parseFloat((count / totalCorrect).toFixed(2));\n};\n\nconst getOutComeScore = (question, env, answers) => {\n const correctness = getCorrectness(question, env, answers);\n\n return correctness === 'correct' ? 1 : correctness === 'partial' && true ? getPartialScore(question, answers) : 0;\n};\n\n/**\n * Generates detailed trace log for match-list scoring evaluation\n * @param {Object} question\n * @param {Object} session\n * @param {Object} env\n * @returns {Array<string>} traceLog\n */\nexport const getLogTrace = (question, session, env) => {\n const traceLog = [];\n\n const prompts = question?.prompts || [];\n const answers = session?.value || {};\n\n if (!answers || Object.keys(answers).length === 0) {\n traceLog.push('Student did not provide any answer.');\n return traceLog;\n }\n\n const totalPrompts = prompts.length;\n traceLog.push(`Match-list item contains ${totalPrompts} question(s).`);\n\n let correctCount = 0;\n let answeredCount = 0;\n\n prompts.forEach((prompt) => {\n const expectedAnswer = prompt.relatedAnswer;\n const studentAnswer = answers[prompt.id];\n\n if (studentAnswer !== undefined) {\n answeredCount += 1;\n\n if (studentAnswer === expectedAnswer) {\n correctCount += 1;\n traceLog.push(`Question ${prompt.id}: correctly matched.`);\n } else {\n traceLog.push(\n `Question ${prompt.id}: incorrectly matched (selected '${studentAnswer}', expected '${expectedAnswer}').`,\n );\n }\n } else {\n traceLog.push(`Question ${prompt.id}: no answer provided.`);\n }\n });\n\n traceLog.push(\n `Student correctly matched ${correctCount} out of ${totalPrompts} question(s).`,\n );\n\n const partialScoringEnabled = partialScoring.enabled(question, env);\n\n if (partialScoringEnabled) {\n traceLog.push('Score calculated using partial scoring.');\n traceLog.push(\n 'Score is the number of correct matches divided by the total number of questions.',\n );\n } else {\n traceLog.push('Score calculated using all-or-nothing scoring.');\n traceLog.push(\n 'Student must match all questions correctly to receive full credit.',\n );\n }\n\n const rawScore = getOutComeScore(question, env, answers);\n const finalScore = partialScoringEnabled ? rawScore : rawScore === 1 ? 1 : 0;\n\n traceLog.push(`Final score: ${finalScore}.`);\n\n return traceLog;\n};\n\nexport const outcome = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined, logTrace: [] });\n } else {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true, logTrace: ['Student did not provide any answer.'] });\n } else {\n const out = {\n score: getOutComeScore(question, env, session.value),\n empty: false,\n logTrace: getLogTrace(question, session, env),\n };\n\n resolve(out);\n }\n }\n });\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n}\n\nexport const normalize = (model) => ({ ...defaults, ...model });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n question = normalize(question);\n const correctness = getCorrectness(question, env, session && session.value);\n const correctResponse = {};\n const score = `${getOutComeScore(question, env, session && session.value) * 100}%`;\n const correctInfo = {\n score,\n correctness,\n };\n\n const shuffledValues = {};\n let prompts = question.prompts;\n let answers = question.answers;\n\n const us = (part) => (id, element, update) => {\n return new Promise((resolve) => {\n shuffledValues[part] = update.shuffledValues;\n resolve();\n });\n };\n\n const lockChoiceOrder = lockChoices(question, session, env);\n\n if (!lockChoiceOrder) {\n prompts = await getShuffledChoices(\n prompts,\n { shuffledValues: ((session && session.shuffledValues) || {}).prompts },\n us('prompts'),\n 'id',\n );\n answers = await getShuffledChoices(\n answers,\n { shuffledValues: ((session && session.shuffledValues) || {}).answers },\n us('answers'),\n 'id',\n );\n }\n\n if (!isEmpty(shuffledValues)) {\n if (updateSession && typeof updateSession === 'function') {\n updateSession(session.id, session.element, {\n shuffledValues,\n }).catch((e) => {\n // eslint-disable-next-line no-console\n console.error('update session failed', e);\n });\n }\n }\n\n if (question && prompts) {\n prompts.forEach((prompt) => {\n correctResponse[prompt.id] = prompt.relatedAnswer;\n });\n }\n\n const feedback =\n env.mode === 'evaluate'\n ? await getFeedbackForCorrectness(correctInfo.correctness, question.feedback)\n : undefined;\n\n const base = {\n config: {\n ...question,\n prompts,\n answers,\n },\n correctness: correctInfo,\n feedback,\n mode: env.mode,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n base.rationale = question.rationale;\n } else {\n base.rationale = null;\n }\n\n const out = Object.assign(base, {\n correctResponse,\n });\n\n log('out: ', out);\n return out;\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { prompts, answers } = question;\n const value = {};\n\n prompts.forEach((p) => {\n if (answers.filter((a) => a.id === p.relatedAnswer).length) {\n value[p.id] = p.relatedAnswer;\n }\n });\n\n resolve({\n value,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAIA,IAAAK,SAAA,GAAAD,sBAAA,CAAAJ,OAAA;AAFA,MAAMM,GAAG,GAAG,IAAAC,cAAK,EAAC,oCAAoC,CAAC;AAIvD,MAAMC,sBAAsB,GAAGA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,IAAId,GAAG,CAACc,IAAI,KAAK,UAAU,CAAC,EAAE;IACjFyD,IAAI,CAACG,SAAS,GAAG7D,QAAQ,CAAC6D,SAAS;EACrC,CAAC,MAAM;IACLH,IAAI,CAACG,SAAS,GAAG,IAAI;EACvB;EAEA,MAAMxB,GAAG,GAAG7C,MAAM,CAACsE,MAAM,CAACJ,IAAI,EAAE;IAC9BhB;EACF,CAAC,CAAC;EAEF5D,GAAG,CAAC,OAAO,EAAEuD,GAAG,CAAC;EACjB,OAAOA,GAAG;AACZ;AAEO,MAAM0B,4BAA4B,GAAGA,CAAC/D,QAAQ,EAAEb,GAAG,KAAK;EAC7D,OAAO,IAAI2C,OAAO,CAAEC,OAAO,IAAK;IAC9B,IAAI5C,GAAG,CAACc,IAAI,KAAK,UAAU,IAAId,GAAG,CAACyE,IAAI,KAAK,YAAY,EAAE;MACxD,MAAM;QAAErE,OAAO;QAAEL;MAAQ,CAAC,GAAGc,QAAQ;MACrC,MAAMgB,KAAK,GAAG,CAAC,CAAC;MAEhBzB,OAAO,CAACW,OAAO,CAAEC,CAAC,IAAK;QACrB,IAAIjB,OAAO,CAAC8E,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAAC5D,EAAE,KAAKF,CAAC,CAACC,aAAa,CAAC,CAACV,MAAM,EAAE;UAC1DsB,KAAK,CAACb,CAAC,CAACE,EAAE,CAAC,GAAGF,CAAC,CAACC,aAAa;QAC/B;MACF,CAAC,CAAC;MAEF2B,OAAO,CAAC;QACNf,KAAK;QACLX,EAAE,EAAE;MACN,CAAC,CAAC;IACJ,CAAC,MAAM;MACL0B,OAAO,CAAC,IAAI,CAAC;IACf;EACF,CAAC,CAAC;AACJ,CAAC;AAACH,OAAA,CAAAmC,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
package/controller/package.json
CHANGED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.AnswerArea = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _styles = require("@mui/material/styles");
|
|
12
|
+
var _lodashEs = require("lodash-es");
|
|
13
|
+
var _arrow = _interopRequireDefault(require("./arrow"));
|
|
14
|
+
var _answer = _interopRequireDefault(require("./answer"));
|
|
15
|
+
const ArrowEntry = (0, _styles.styled)('div')({
|
|
16
|
+
alignItems: 'normal',
|
|
17
|
+
display: 'flex',
|
|
18
|
+
height: 40,
|
|
19
|
+
margin: '10px 20px'
|
|
20
|
+
});
|
|
21
|
+
const ItemList = (0, _styles.styled)('div')(({
|
|
22
|
+
theme
|
|
23
|
+
}) => ({
|
|
24
|
+
alignItems: 'flex-start',
|
|
25
|
+
display: 'flex',
|
|
26
|
+
flex: 1,
|
|
27
|
+
flexDirection: 'column',
|
|
28
|
+
justifyContent: 'space-between',
|
|
29
|
+
marginTop: theme.spacing(2),
|
|
30
|
+
marginBottom: theme.spacing(2)
|
|
31
|
+
}));
|
|
32
|
+
const PromptEntry = (0, _styles.styled)('div')(({
|
|
33
|
+
theme
|
|
34
|
+
}) => ({
|
|
35
|
+
border: `1px solid ${theme.palette.grey[400]}`,
|
|
36
|
+
boxSizing: 'border-box',
|
|
37
|
+
flex: 1,
|
|
38
|
+
margin: '10px 0',
|
|
39
|
+
minHeight: 40,
|
|
40
|
+
overflow: 'hidden',
|
|
41
|
+
padding: 10,
|
|
42
|
+
textAlign: 'center',
|
|
43
|
+
width: '100%',
|
|
44
|
+
wordBreak: 'break-word'
|
|
45
|
+
}));
|
|
46
|
+
const Row = (0, _styles.styled)('div')({
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
display: 'flex',
|
|
49
|
+
justifyContent: 'space-between',
|
|
50
|
+
width: '100%'
|
|
51
|
+
});
|
|
52
|
+
class AnswerArea extends _react.default.Component {
|
|
53
|
+
constructor(...args) {
|
|
54
|
+
super(...args);
|
|
55
|
+
(0, _defineProperty2.default)(this, "getAnswerFromSession", promptId => {
|
|
56
|
+
const {
|
|
57
|
+
model,
|
|
58
|
+
session,
|
|
59
|
+
showCorrect
|
|
60
|
+
} = this.props;
|
|
61
|
+
const {
|
|
62
|
+
config
|
|
63
|
+
} = model;
|
|
64
|
+
const answerId = showCorrect ? config.prompts.find(p => p.id === promptId).relatedAnswer : session.value && session.value[promptId];
|
|
65
|
+
const answer = config.answers.find(answer => answer.id === answerId);
|
|
66
|
+
return answer || {};
|
|
67
|
+
});
|
|
68
|
+
(0, _defineProperty2.default)(this, "getCorrectOrIncorrectMap", () => {
|
|
69
|
+
const {
|
|
70
|
+
model,
|
|
71
|
+
session,
|
|
72
|
+
showCorrect
|
|
73
|
+
} = this.props;
|
|
74
|
+
const {
|
|
75
|
+
config
|
|
76
|
+
} = model;
|
|
77
|
+
const sessionValue = session.value || config.prompts.reduce((obj, prompt) => {
|
|
78
|
+
obj[prompt.id] = undefined;
|
|
79
|
+
return obj;
|
|
80
|
+
}, {});
|
|
81
|
+
if (model.mode !== 'evaluate') {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
if (showCorrect) {
|
|
85
|
+
return config.prompts.reduce((obj, prompt) => {
|
|
86
|
+
obj[prompt.id] = true;
|
|
87
|
+
return obj;
|
|
88
|
+
}, {});
|
|
89
|
+
}
|
|
90
|
+
const correctPromptMap = config.prompts.reduce((obj, prompt) => {
|
|
91
|
+
if (!(0, _lodashEs.isUndefined)(prompt.relatedAnswer)) {
|
|
92
|
+
obj[prompt.id] = prompt.relatedAnswer;
|
|
93
|
+
}
|
|
94
|
+
return obj;
|
|
95
|
+
}, {});
|
|
96
|
+
return (0, _lodashEs.reduce)(sessionValue, (obj, val, key) => {
|
|
97
|
+
obj[key] = correctPromptMap[key] === sessionValue[key];
|
|
98
|
+
return obj;
|
|
99
|
+
}, {});
|
|
100
|
+
});
|
|
101
|
+
(0, _defineProperty2.default)(this, "buildRows", () => {
|
|
102
|
+
const {
|
|
103
|
+
model
|
|
104
|
+
} = this.props;
|
|
105
|
+
const {
|
|
106
|
+
config
|
|
107
|
+
} = model;
|
|
108
|
+
const prompts = config.prompts || [];
|
|
109
|
+
return prompts.map(prompt => {
|
|
110
|
+
const sessionAnswer = this.getAnswerFromSession(prompt.id);
|
|
111
|
+
return {
|
|
112
|
+
...prompt,
|
|
113
|
+
sessionAnswer
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
render() {
|
|
119
|
+
const {
|
|
120
|
+
disabled,
|
|
121
|
+
instanceId,
|
|
122
|
+
onRemoveAnswer
|
|
123
|
+
} = this.props;
|
|
124
|
+
const rows = this.buildRows();
|
|
125
|
+
const correctnessMap = this.getCorrectOrIncorrectMap();
|
|
126
|
+
return /*#__PURE__*/_react.default.createElement(ItemList, null, rows.map(({
|
|
127
|
+
sessionAnswer,
|
|
128
|
+
title,
|
|
129
|
+
id
|
|
130
|
+
}, index) => {
|
|
131
|
+
return /*#__PURE__*/_react.default.createElement(Row, {
|
|
132
|
+
key: index
|
|
133
|
+
}, /*#__PURE__*/_react.default.createElement(PromptEntry, {
|
|
134
|
+
dangerouslySetInnerHTML: {
|
|
135
|
+
__html: title
|
|
136
|
+
}
|
|
137
|
+
}), /*#__PURE__*/_react.default.createElement(ArrowEntry, null, /*#__PURE__*/_react.default.createElement(_arrow.default, {
|
|
138
|
+
direction: "left"
|
|
139
|
+
}), /*#__PURE__*/_react.default.createElement(_arrow.default, null)), /*#__PURE__*/_react.default.createElement(_answer.default, {
|
|
140
|
+
key: index,
|
|
141
|
+
className: "answer",
|
|
142
|
+
index: index,
|
|
143
|
+
promptId: id,
|
|
144
|
+
correct: correctnessMap[id],
|
|
145
|
+
draggable: !(0, _lodashEs.isEmpty)(sessionAnswer),
|
|
146
|
+
disabled: disabled,
|
|
147
|
+
instanceId: instanceId,
|
|
148
|
+
id: sessionAnswer.id,
|
|
149
|
+
title: sessionAnswer.title,
|
|
150
|
+
type: 'target',
|
|
151
|
+
onRemoveChoice: () => onRemoveAnswer(id)
|
|
152
|
+
}));
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.AnswerArea = AnswerArea;
|
|
157
|
+
(0, _defineProperty2.default)(AnswerArea, "propTypes", {
|
|
158
|
+
session: _propTypes.default.object.isRequired,
|
|
159
|
+
showCorrect: _propTypes.default.bool.isRequired,
|
|
160
|
+
disabled: _propTypes.default.bool.isRequired,
|
|
161
|
+
onSessionChange: _propTypes.default.func,
|
|
162
|
+
onRemoveAnswer: _propTypes.default.func,
|
|
163
|
+
instanceId: _propTypes.default.string.isRequired,
|
|
164
|
+
model: _propTypes.default.object.isRequired,
|
|
165
|
+
prompt: _propTypes.default.string
|
|
166
|
+
});
|
|
167
|
+
var _default = exports.default = AnswerArea;
|
|
168
|
+
//# sourceMappingURL=answer-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answer-area.js","names":["_react","_interopRequireDefault","require","_propTypes","_styles","_lodashEs","_arrow","_answer","ArrowEntry","styled","alignItems","display","height","margin","ItemList","theme","flex","flexDirection","justifyContent","marginTop","spacing","marginBottom","PromptEntry","border","palette","grey","boxSizing","minHeight","overflow","padding","textAlign","width","wordBreak","Row","AnswerArea","React","Component","constructor","args","_defineProperty2","default","promptId","model","session","showCorrect","props","config","answerId","prompts","find","p","id","relatedAnswer","value","answer","answers","sessionValue","reduce","obj","prompt","undefined","mode","correctPromptMap","isUndefined","val","key","map","sessionAnswer","getAnswerFromSession","render","disabled","instanceId","onRemoveAnswer","rows","buildRows","correctnessMap","getCorrectOrIncorrectMap","createElement","title","index","dangerouslySetInnerHTML","__html","direction","className","correct","draggable","isEmpty","type","onRemoveChoice","exports","PropTypes","object","isRequired","bool","onSessionChange","func","string","_default"],"sources":["../src/answer-area.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { styled } from '@mui/material/styles';\nimport { isEmpty, isUndefined, reduce } from 'lodash-es';\n\nimport Arrow from './arrow';\nimport DragAndDropAnswer from './answer';\n\nconst ArrowEntry = styled('div')({\n alignItems: 'normal',\n display: 'flex',\n height: 40,\n margin: '10px 20px',\n});\n\nconst ItemList = styled('div')(({ theme }) => ({\n alignItems: 'flex-start',\n display: 'flex',\n flex: 1,\n flexDirection: 'column',\n justifyContent: 'space-between',\n marginTop: theme.spacing(2),\n marginBottom: theme.spacing(2),\n}));\n\nconst PromptEntry = styled('div')(({ theme }) => ({\n border: `1px solid ${theme.palette.grey[400]}`,\n boxSizing: 'border-box',\n flex: 1,\n margin: '10px 0',\n minHeight: 40,\n overflow: 'hidden',\n padding: 10,\n textAlign: 'center',\n width: '100%',\n wordBreak: 'break-word',\n}));\n\nconst Row = styled('div')({\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n});\n\nexport class AnswerArea extends React.Component {\n static propTypes = {\n session: PropTypes.object.isRequired,\n showCorrect: PropTypes.bool.isRequired,\n disabled: PropTypes.bool.isRequired,\n onSessionChange: PropTypes.func,\n onRemoveAnswer: PropTypes.func,\n instanceId: PropTypes.string.isRequired,\n model: PropTypes.object.isRequired,\n prompt: PropTypes.string,\n };\n\n getAnswerFromSession = (promptId) => {\n const { model, session, showCorrect } = this.props;\n const { config } = model;\n const answerId = showCorrect\n ? config.prompts.find((p) => p.id === promptId).relatedAnswer\n : session.value && session.value[promptId];\n const answer = config.answers.find((answer) => answer.id === answerId);\n\n return answer || {};\n };\n\n getCorrectOrIncorrectMap = () => {\n const { model, session, showCorrect } = this.props;\n const { config } = model;\n const sessionValue =\n session.value ||\n config.prompts.reduce((obj, prompt) => {\n obj[prompt.id] = undefined;\n return obj;\n }, {});\n\n if (model.mode !== 'evaluate') {\n return {};\n }\n\n if (showCorrect) {\n return config.prompts.reduce((obj, prompt) => {\n obj[prompt.id] = true;\n\n return obj;\n }, {});\n }\n\n const correctPromptMap = config.prompts.reduce((obj, prompt) => {\n if (!isUndefined(prompt.relatedAnswer)) {\n obj[prompt.id] = prompt.relatedAnswer;\n }\n\n return obj;\n }, {});\n\n return reduce(\n sessionValue,\n (obj, val, key) => {\n obj[key] = correctPromptMap[key] === sessionValue[key];\n\n return obj;\n },\n {},\n );\n };\n\n buildRows = () => {\n const { model } = this.props;\n const { config } = model;\n const prompts = config.prompts || [];\n\n return prompts.map((prompt) => {\n const sessionAnswer = this.getAnswerFromSession(prompt.id);\n\n return {\n ...prompt,\n sessionAnswer,\n };\n });\n };\n\n render() {\n const { disabled, instanceId, onRemoveAnswer } = this.props;\n const rows = this.buildRows();\n const correctnessMap = this.getCorrectOrIncorrectMap();\n\n return (\n <ItemList>\n {rows.map(({ sessionAnswer, title, id }, index) => {\n return (\n <Row key={index}>\n <PromptEntry dangerouslySetInnerHTML={{ __html: title }} />\n\n <ArrowEntry>\n <Arrow direction=\"left\" />\n <Arrow />\n </ArrowEntry>\n\n <DragAndDropAnswer\n key={index}\n className=\"answer\"\n index={index}\n promptId={id}\n correct={correctnessMap[id]}\n draggable={!isEmpty(sessionAnswer)}\n disabled={disabled}\n instanceId={instanceId}\n id={sessionAnswer.id}\n title={sessionAnswer.title}\n type={'target'}\n onRemoveChoice={() => onRemoveAnswer(id)}\n />\n </Row>\n );\n })}\n </ItemList>\n );\n }\n}\n\nexport default AnswerArea;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CA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