@pie-element/drag-in-the-blank 10.1.2-next.2 → 10.1.2
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.json +1042 -0
- package/CHANGELOG.md +2183 -0
- package/LICENSE.md +5 -0
- package/README.md +1 -0
- package/configure/CHANGELOG.json +652 -0
- package/configure/CHANGELOG.md +1883 -0
- package/configure/lib/choice.js +137 -0
- package/configure/lib/choice.js.map +1 -0
- package/configure/lib/choices.js +319 -0
- package/configure/lib/choices.js.map +1 -0
- package/configure/lib/defaults.js +169 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/index.js +144 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/main.js +440 -0
- package/configure/lib/main.js.map +1 -0
- package/configure/lib/markupUtils.js +83 -0
- package/configure/lib/markupUtils.js.map +1 -0
- package/configure/package.json +25 -0
- package/configure/utils.js +17 -0
- package/controller/CHANGELOG.json +457 -0
- package/controller/CHANGELOG.md +1284 -0
- package/controller/lib/defaults.js +24 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +251 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +39 -0
- package/controller/lib/utils.js.map +1 -0
- package/controller/package.json +16 -0
- package/docs/config-schema.json +2580 -0
- package/docs/config-schema.json.md +1905 -0
- package/docs/demo/config.js +8 -0
- package/docs/demo/generate.js +41 -0
- package/docs/demo/index.html +1 -0
- package/docs/demo/session.js +10 -0
- package/docs/pie-schema.json +1181 -0
- package/docs/pie-schema.json.md +853 -0
- package/lib/index.js +206 -0
- package/lib/index.js.map +1 -0
- package/lib/main.js +126 -0
- package/lib/main.js.map +1 -0
- package/package.json +22 -87
- package/configure.js +0 -2
- package/controller.js +0 -1
- package/dist/author/choice.d.ts +0 -22
- package/dist/author/choice.js +0 -88
- package/dist/author/choices.d.ts +0 -41
- package/dist/author/choices.js +0 -172
- package/dist/author/defaults.d.ts +0 -171
- package/dist/author/defaults.js +0 -123
- package/dist/author/index.d.ts +0 -42
- package/dist/author/index.js +0 -92
- package/dist/author/main.d.ts +0 -36
- package/dist/author/main.js +0 -301
- package/dist/author/markupUtils.d.ts +0 -17
- package/dist/author/markupUtils.js +0 -38
- package/dist/author/utils.d.ts +0 -9
- package/dist/author/utils.js +0 -7
- package/dist/browser/author/index.js +0 -39603
- package/dist/browser/author/index.js.map +0 -1
- package/dist/browser/controller/index.js +0 -176
- package/dist/browser/controller/index.js.map +0 -1
- package/dist/browser/delivery/index.js +0 -3414
- package/dist/browser/delivery/index.js.map +0 -1
- package/dist/browser/dist-BkH5WSi5.js +0 -121
- package/dist/browser/dist-BkH5WSi5.js.map +0 -1
- package/dist/browser/drag-in-the-blank.css +0 -2
- package/dist/browser/drag-provider-D0fyq5lq.js +0 -10946
- package/dist/browser/drag-provider-D0fyq5lq.js.map +0 -1
- package/dist/controller/defaults.d.ts +0 -26
- package/dist/controller/defaults.js +0 -20
- package/dist/controller/index.d.ts +0 -41
- package/dist/controller/index.js +0 -104
- package/dist/controller/utils.d.ts +0 -16
- package/dist/controller/utils.js +0 -14
- package/dist/delivery/index.d.ts +0 -21
- package/dist/delivery/index.js +0 -105
- package/dist/delivery/main.d.ts +0 -28
- package/dist/delivery/main.js +0 -83
- package/dist/index.d.ts +0 -1
- package/dist/index.iife.d.ts +0 -8
- package/dist/index.iife.js +0 -152
- package/dist/index.js +0 -2
- package/dist/runtime-support.d.ts +0 -12
- package/dist/runtime-support.js +0 -12
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
choices: [],
|
|
9
|
+
choicesPosition: 'below',
|
|
10
|
+
correctResponse: {},
|
|
11
|
+
disabled: false,
|
|
12
|
+
duplicates: true,
|
|
13
|
+
markup: '',
|
|
14
|
+
mode: 'gather',
|
|
15
|
+
prompt: '',
|
|
16
|
+
promptEnabled: true,
|
|
17
|
+
rationale: '',
|
|
18
|
+
rationaleEnabled: true,
|
|
19
|
+
studentInstructionsEnabled: true,
|
|
20
|
+
teacherInstructions: '',
|
|
21
|
+
teacherInstructionsEnabled: true,
|
|
22
|
+
toolbarEditorPosition: 'bottom'
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","names":["choices","choicesPosition","correctResponse","disabled","duplicates","markup","mode","prompt","promptEnabled","rationale","rationaleEnabled","studentInstructionsEnabled","teacherInstructions","teacherInstructionsEnabled","toolbarEditorPosition"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n choices: [],\n choicesPosition: 'below',\n correctResponse: {},\n disabled: false,\n duplicates: true,\n markup: '',\n mode: 'gather',\n prompt: '',\n promptEnabled: true,\n rationale: '',\n rationaleEnabled: true,\n studentInstructionsEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n};\n"],"mappings":";;;;;;iCAAe;EACbA,OAAO,EAAE,EAAE;EACXC,eAAe,EAAE,OAAO;EACxBC,eAAe,EAAE,CAAC,CAAC;EACnBC,QAAQ,EAAE,KAAK;EACfC,UAAU,EAAE,IAAI;EAChBC,MAAM,EAAE,EAAE;EACVC,IAAI,EAAE,QAAQ;EACdC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,IAAI;EACtBC,0BAA0B,EAAE,IAAI;EAChCC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,qBAAqB,EAAE;AACzB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getScore = exports.getLogTrace = exports.createCorrectResponseSession = void 0;
|
|
8
|
+
exports.model = model;
|
|
9
|
+
exports.normalize = void 0;
|
|
10
|
+
exports.outcome = outcome;
|
|
11
|
+
exports.validate = void 0;
|
|
12
|
+
var _lodashEs = require("lodash-es");
|
|
13
|
+
var _utils = require("./utils");
|
|
14
|
+
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
15
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
16
|
+
const normalize = question => ({
|
|
17
|
+
..._defaults.default,
|
|
18
|
+
...question
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {*} question
|
|
24
|
+
* @param {*} session
|
|
25
|
+
* @param {*} env
|
|
26
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
27
|
+
*/
|
|
28
|
+
exports.normalize = normalize;
|
|
29
|
+
async function model(question, session, env, updateSession) {
|
|
30
|
+
const normalizedQuestion = normalize(question);
|
|
31
|
+
let feedback = {};
|
|
32
|
+
if (env.mode === 'evaluate') {
|
|
33
|
+
const responses = (0, _utils.getAllCorrectResponses)(normalizedQuestion) || {};
|
|
34
|
+
const allCorrectResponses = responses.possibleResponses;
|
|
35
|
+
const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;
|
|
36
|
+
let correctResponses = undefined;
|
|
37
|
+
const {
|
|
38
|
+
value
|
|
39
|
+
} = session || {};
|
|
40
|
+
for (let i = 0; i < numberOfPossibleResponses; i++) {
|
|
41
|
+
const result = Object.keys(allCorrectResponses).reduce((obj, key) => {
|
|
42
|
+
const choices = allCorrectResponses[key];
|
|
43
|
+
const answer = value && value[key] || '';
|
|
44
|
+
obj.feedback[key] = choices[i] === answer;
|
|
45
|
+
if (obj.feedback[key]) {
|
|
46
|
+
obj.correctResponses += 1;
|
|
47
|
+
}
|
|
48
|
+
return obj;
|
|
49
|
+
}, {
|
|
50
|
+
correctResponses: 0,
|
|
51
|
+
feedback: {}
|
|
52
|
+
});
|
|
53
|
+
if (correctResponses === undefined || result.correctResponses > correctResponses) {
|
|
54
|
+
correctResponses = result.correctResponses;
|
|
55
|
+
feedback = result.feedback;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let choices = normalizedQuestion.choices && normalizedQuestion.choices.filter(choice => !(0, _utils.choiceIsEmpty)(choice));
|
|
60
|
+
const lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
|
|
61
|
+
if (!lockChoiceOrder) {
|
|
62
|
+
choices = await (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'id');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// we don't need to check for fewer areas to be filled in the alternateResponses
|
|
66
|
+
// because the alternates are an option in the default correct response (for scoring)
|
|
67
|
+
const responseAreasToBeFilled = Object.values(normalizedQuestion.correctResponse || {}).filter(value => !!value).length;
|
|
68
|
+
const shouldIncludeCorrectResponse = env.mode === 'evaluate';
|
|
69
|
+
const out = {
|
|
70
|
+
...normalizedQuestion,
|
|
71
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
72
|
+
choices,
|
|
73
|
+
feedback,
|
|
74
|
+
mode: env.mode,
|
|
75
|
+
disabled: env.mode !== 'gather',
|
|
76
|
+
responseCorrect: shouldIncludeCorrectResponse ? getScore(normalizedQuestion, session) === 1 : undefined,
|
|
77
|
+
correctResponse: shouldIncludeCorrectResponse ? normalizedQuestion.correctResponse : undefined,
|
|
78
|
+
responseAreasToBeFilled
|
|
79
|
+
};
|
|
80
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
81
|
+
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
82
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
83
|
+
} else {
|
|
84
|
+
out.rationale = null;
|
|
85
|
+
out.teacherInstructions = null;
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
const getScore = (config, session) => {
|
|
90
|
+
const responses = (0, _utils.getAllCorrectResponses)(config);
|
|
91
|
+
const allCorrectResponses = responses.possibleResponses;
|
|
92
|
+
const maxScore = Object.keys(config.correctResponse).length;
|
|
93
|
+
const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;
|
|
94
|
+
let correctCount = 0;
|
|
95
|
+
const {
|
|
96
|
+
value
|
|
97
|
+
} = session || {};
|
|
98
|
+
for (let i = 0; i < numberOfPossibleResponses; i++) {
|
|
99
|
+
const result = Object.keys(allCorrectResponses).reduce((total, key) => {
|
|
100
|
+
const choices = allCorrectResponses[key];
|
|
101
|
+
const answer = value && value[key] || '';
|
|
102
|
+
if (choices[i] === answer) {
|
|
103
|
+
return total;
|
|
104
|
+
}
|
|
105
|
+
return total - 1;
|
|
106
|
+
}, maxScore);
|
|
107
|
+
if (result > correctCount) {
|
|
108
|
+
correctCount = result;
|
|
109
|
+
}
|
|
110
|
+
if (result === maxScore) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;
|
|
115
|
+
return parseFloat(str);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Generates detailed trace log for scoring evaluation
|
|
120
|
+
* @param {Object} model - the question model
|
|
121
|
+
* @param {Object} session - the student session
|
|
122
|
+
* @param {Object} env - the environment
|
|
123
|
+
* @returns {Array} traceLog - array of trace messages
|
|
124
|
+
*/
|
|
125
|
+
exports.getScore = getScore;
|
|
126
|
+
const getLogTrace = (model, session, env) => {
|
|
127
|
+
const traceLog = [];
|
|
128
|
+
const {
|
|
129
|
+
value
|
|
130
|
+
} = session || {};
|
|
131
|
+
const responseAreas = Object.keys(model.correctResponse || {});
|
|
132
|
+
const totalAreas = responseAreas.length;
|
|
133
|
+
traceLog.push(`${totalAreas} response area(s) defined in this question.`);
|
|
134
|
+
if (value && Object.keys(value).length > 0) {
|
|
135
|
+
const filledAreas = Object.entries(value).filter(([key, val]) => val && val.trim()).length;
|
|
136
|
+
traceLog.push(`Student added choices to ${filledAreas} out of ${totalAreas} response area(s).`);
|
|
137
|
+
responseAreas.forEach(areaKey => {
|
|
138
|
+
const studentAnswer = value && value[areaKey] || '';
|
|
139
|
+
const correctAnswer = model.correctResponse[areaKey] || '';
|
|
140
|
+
if (studentAnswer.trim()) {
|
|
141
|
+
traceLog.push(`Response area ${areaKey}: student placed '${studentAnswer}' (correct answer: '${correctAnswer}').`);
|
|
142
|
+
} else {
|
|
143
|
+
traceLog.push(`Response area ${areaKey}: left empty (correct answer: '${correctAnswer}').`);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
traceLog.push('Student did not add any choices to response areas.');
|
|
148
|
+
}
|
|
149
|
+
const responses = (0, _utils.getAllCorrectResponses)(model);
|
|
150
|
+
const allCorrectResponses = responses.possibleResponses;
|
|
151
|
+
const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;
|
|
152
|
+
if (numberOfPossibleResponses > 1) {
|
|
153
|
+
traceLog.push(`${numberOfPossibleResponses} alternate response combinations are accepted for this question.`);
|
|
154
|
+
}
|
|
155
|
+
const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
|
|
156
|
+
const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';
|
|
157
|
+
traceLog.push(`Score calculated using ${scoringMethod}.`);
|
|
158
|
+
const score = getScore(model, session);
|
|
159
|
+
traceLog.push(`Final score: ${score}.`);
|
|
160
|
+
return traceLog;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* The score is partial by default for checkbox mode, allOrNothing for radio mode.
|
|
166
|
+
* To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =
|
|
167
|
+
* false. the value in `env` will override the value in `model`.
|
|
168
|
+
* @param {Object} model - the main model
|
|
169
|
+
* @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)
|
|
170
|
+
* @param {*} session
|
|
171
|
+
* @param {Object} env
|
|
172
|
+
* @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides
|
|
173
|
+
* `model.partialScoring`.
|
|
174
|
+
*/
|
|
175
|
+
exports.getLogTrace = getLogTrace;
|
|
176
|
+
function outcome(model, session, env = {}) {
|
|
177
|
+
return new Promise(resolve => {
|
|
178
|
+
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
179
|
+
resolve({
|
|
180
|
+
score: 0,
|
|
181
|
+
empty: true,
|
|
182
|
+
traceLog: ['Student did not add any choices to response areas. Score is 0.']
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
const traceLog = getLogTrace(model, session, env);
|
|
186
|
+
const score = getScore(model, session);
|
|
187
|
+
const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
|
|
188
|
+
resolve({
|
|
189
|
+
score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
|
|
190
|
+
empty: false,
|
|
191
|
+
traceLog
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const createCorrectResponseSession = (question, env) => {
|
|
197
|
+
return new Promise(resolve => {
|
|
198
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
199
|
+
resolve({
|
|
200
|
+
value: question.correctResponse,
|
|
201
|
+
id: '1'
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
resolve(null);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// remove all html tags
|
|
210
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
211
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
212
|
+
|
|
213
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
214
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
215
|
+
const validate = (model = {}, config = {}) => {
|
|
216
|
+
const {
|
|
217
|
+
choices,
|
|
218
|
+
correctResponse,
|
|
219
|
+
markup
|
|
220
|
+
} = model;
|
|
221
|
+
const {
|
|
222
|
+
minChoices = 2,
|
|
223
|
+
maxChoices,
|
|
224
|
+
maxResponseAreas
|
|
225
|
+
} = config;
|
|
226
|
+
const errors = {};
|
|
227
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
|
|
228
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
229
|
+
errors[field] = 'This field is required.';
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
const nbOfResponseAreas = ((markup || '').match(/\{\{(\d+)\}\}/g) || []).length;
|
|
233
|
+
const nbOfChoices = (choices || []).length;
|
|
234
|
+
const emptyResponseAreas = Object.values(correctResponse)?.filter(response => !response);
|
|
235
|
+
if (emptyResponseAreas.length) {
|
|
236
|
+
errors.correctResponseError = 'There should be a choice defined for each response area.';
|
|
237
|
+
}
|
|
238
|
+
if (nbOfResponseAreas > maxResponseAreas) {
|
|
239
|
+
errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;
|
|
240
|
+
} else if (nbOfResponseAreas < 1) {
|
|
241
|
+
errors.responseAreasError = 'There should be at least 1 response area defined.';
|
|
242
|
+
}
|
|
243
|
+
if (nbOfChoices < minChoices) {
|
|
244
|
+
errors.choicesError = `There should be at least ${minChoices} tokens defined.`;
|
|
245
|
+
} else if (nbOfChoices > maxChoices) {
|
|
246
|
+
errors.choicesError = `No more than ${maxChoices} tokens should be defined.`;
|
|
247
|
+
}
|
|
248
|
+
return errors;
|
|
249
|
+
};
|
|
250
|
+
exports.validate = validate;
|
|
251
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_lodashEs","require","_utils","_controllerUtils","_defaults","_interopRequireDefault","normalize","question","defaults","exports","model","session","env","updateSession","normalizedQuestion","feedback","mode","responses","getAllCorrectResponses","allCorrectResponses","possibleResponses","numberOfPossibleResponses","correctResponses","undefined","value","i","result","Object","keys","reduce","obj","key","choices","answer","filter","choice","choiceIsEmpty","lockChoiceOrder","lockChoices","getShuffledChoices","responseAreasToBeFilled","values","correctResponse","length","shouldIncludeCorrectResponse","out","prompt","promptEnabled","disabled","responseCorrect","getScore","role","rationale","rationaleEnabled","teacherInstructions","teacherInstructionsEnabled","config","maxScore","correctCount","total","str","toFixed","parseFloat","getLogTrace","traceLog","responseAreas","totalAreas","push","filledAreas","entries","val","trim","forEach","areaKey","studentAnswer","correctAnswer","partialScoringEnabled","partialScoring","enabled","scoringMethod","score","outcome","Promise","resolve","isEmpty","empty","createCorrectResponseSession","id","getInnerText","html","replaceAll","getContent","replace","validate","markup","minChoices","maxChoices","maxResponseAreas","errors","field","required","nbOfResponseAreas","match","nbOfChoices","emptyResponseAreas","response","correctResponseError","responseAreasError","choicesError"],"sources":["../src/index.js"],"sourcesContent":["import { isEmpty } from 'lodash-es';\nimport { getAllCorrectResponses, choiceIsEmpty } from './utils';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\nexport const normalize = (question) => ({\n ...defaults,\n ...question,\n});\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 const normalizedQuestion = normalize(question);\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const responses = getAllCorrectResponses(normalizedQuestion) || {};\n const allCorrectResponses = responses.possibleResponses;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n let correctResponses = undefined;\n const { value } = session || {};\n\n for (let i = 0; i < numberOfPossibleResponses; i++) {\n const result = Object.keys(allCorrectResponses).reduce(\n (obj, key) => {\n const choices = allCorrectResponses[key];\n const answer = (value && value[key]) || '';\n\n obj.feedback[key] = choices[i] === answer;\n\n if (obj.feedback[key]) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} },\n );\n\n if (correctResponses === undefined || result.correctResponses > correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n }\n }\n\n let choices = normalizedQuestion.choices && normalizedQuestion.choices.filter((choice) => !choiceIsEmpty(choice));\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n // we don't need to check for fewer areas to be filled in the alternateResponses\n // because the alternates are an option in the default correct response (for scoring)\n const responseAreasToBeFilled = Object.values(normalizedQuestion.correctResponse || {}).filter(\n (value) => !!value,\n ).length;\n\n const shouldIncludeCorrectResponse = env.mode === 'evaluate';\n\n const out = {\n ...normalizedQuestion,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choices,\n feedback,\n mode: env.mode,\n disabled: env.mode !== 'gather',\n responseCorrect: shouldIncludeCorrectResponse ? getScore(normalizedQuestion, session) === 1 : undefined,\n correctResponse: shouldIncludeCorrectResponse ? normalizedQuestion.correctResponse : undefined,\n responseAreasToBeFilled,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\nexport const getScore = (config, session) => {\n const responses = getAllCorrectResponses(config);\n const allCorrectResponses = responses.possibleResponses;\n const maxScore = Object.keys(config.correctResponse).length;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n let correctCount = 0;\n const { value } = session || {};\n\n for (let i = 0; i < numberOfPossibleResponses; i++) {\n const result = Object.keys(allCorrectResponses).reduce((total, key) => {\n const choices = allCorrectResponses[key];\n const answer = (value && value[key]) || '';\n\n if (choices[i] === answer) {\n return total;\n }\n\n return total - 1;\n }, maxScore);\n\n if (result > correctCount) {\n correctCount = result;\n }\n\n if (result === maxScore) {\n break;\n }\n }\n\n const str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;\n\n return parseFloat(str);\n};\n\n/**\n * Generates detailed trace log for scoring evaluation\n * @param {Object} model - the question model\n * @param {Object} session - the student session\n * @param {Object} env - the environment\n * @returns {Array} traceLog - array of trace messages\n */\nexport const getLogTrace = (model, session, env) => {\n const traceLog = [];\n const { value } = session || {};\n \n const responseAreas = Object.keys(model.correctResponse || {});\n const totalAreas = responseAreas.length;\n traceLog.push(`${totalAreas} response area(s) defined in this question.`);\n \n if (value && Object.keys(value).length > 0) {\n const filledAreas = Object.entries(value).filter(([key, val]) => val && val.trim()).length;\n traceLog.push(`Student added choices to ${filledAreas} out of ${totalAreas} response area(s).`);\n \n responseAreas.forEach((areaKey) => {\n const studentAnswer = (value && value[areaKey]) || '';\n const correctAnswer = model.correctResponse[areaKey] || '';\n \n if (studentAnswer.trim()) {\n traceLog.push(`Response area ${areaKey}: student placed '${studentAnswer}' (correct answer: '${correctAnswer}').`);\n } else {\n traceLog.push(`Response area ${areaKey}: left empty (correct answer: '${correctAnswer}').`);\n }\n });\n } else {\n traceLog.push('Student did not add any choices to response areas.');\n }\n\n const responses = getAllCorrectResponses(model);\n const allCorrectResponses = responses.possibleResponses;\n const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;\n \n if (numberOfPossibleResponses > 1) {\n traceLog.push(`${numberOfPossibleResponses} alternate response combinations are accepted for this question.`);\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';\n traceLog.push(`Score calculated using ${scoringMethod}.`);\n\n const score = getScore(model, session);\n traceLog.push(`Final score: ${score}.`);\n\n return traceLog;\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =\n * false. the value in `env` will override the value in `model`.\n * @param {Object} model - the main model\n * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)\n * @param {*} session\n * @param {Object} env\n * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides\n * `model.partialScoring`.\n */\nexport function outcome(model, session, env = {}) {\n return new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ \n score: 0, \n empty: true, \n traceLog: ['Student did not add any choices to response areas. Score is 0.'] \n });\n } else {\n const traceLog = getLogTrace(model, session, env);\n const score = getScore(model, session);\n const partialScoringEnabled = partialScoring.enabled(model, env);\n\n resolve({\n score: partialScoringEnabled ? score : score === 1 ? 1 : 0,\n empty: false,\n traceLog\n });\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n value: question.correctResponse,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse, markup } = model;\n const { minChoices = 2, maxChoices, maxResponseAreas } = config;\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n const nbOfResponseAreas = ((markup || '').match(/\\{\\{(\\d+)\\}\\}/g) || []).length;\n const nbOfChoices = (choices || []).length;\n const emptyResponseAreas = Object.values(correctResponse)?.filter((response) => !response);\n\n if (emptyResponseAreas.length) {\n errors.correctResponseError = 'There should be a choice defined for each response area.';\n }\n\n if (nbOfResponseAreas > maxResponseAreas) {\n errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;\n } else if (nbOfResponseAreas < 1) {\n errors.responseAreasError = 'There should be at least 1 response area defined.';\n }\n\n if (nbOfChoices < minChoices) {\n errors.choicesError = `There should be at least ${minChoices} tokens defined.`;\n } else if (nbOfChoices > maxChoices) {\n errors.choicesError = `No more than ${maxChoices} tokens should be defined.`;\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAEO,MAAMK,SAAS,GAAIC,QAAQ,KAAM;EACtC,GAAGC,iBAAQ;EACX,GAAGD;AACL,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AANAE,OAAA,CAAAH,SAAA,GAAAA,SAAA;AAOO,eAAeI,KAAKA,CAACH,QAAQ,EAAEI,OAAO,EAAEC,GAAG,EAAEC,aAAa,EAAE;EACjE,MAAMC,kBAAkB,GAAGR,SAAS,CAACC,QAAQ,CAAC;EAC9C,IAAIQ,QAAQ,GAAG,CAAC,CAAC;EAEjB,IAAIH,GAAG,CAACI,IAAI,KAAK,UAAU,EAAE;IAC3B,MAAMC,SAAS,GAAG,IAAAC,6BAAsB,EAACJ,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClE,MAAMK,mBAAmB,GAAGF,SAAS,CAACG,iBAAiB;IACvD,MAAMC,yBAAyB,GAAGJ,SAAS,CAACI,yBAAyB,IAAI,CAAC;IAC1E,IAAIC,gBAAgB,GAAGC,SAAS;IAChC,MAAM;MAAEC;IAAM,CAAC,GAAGb,OAAO,IAAI,CAAC,CAAC;IAE/B,KAAK,IAAIc,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|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAllCorrectResponses = exports.choiceIsEmpty = void 0;
|
|
7
|
+
var _lodashEs = require("lodash-es");
|
|
8
|
+
const replaceHtmlRegex = /<(?!img)[^>]*>?/gm;
|
|
9
|
+
const getAllCorrectResponses = ({
|
|
10
|
+
correctResponse,
|
|
11
|
+
alternateResponses
|
|
12
|
+
}) => {
|
|
13
|
+
return (0, _lodashEs.reduce)(correctResponse || {}, (obj, val, key) => {
|
|
14
|
+
obj.possibleResponses[key] = [val];
|
|
15
|
+
if (alternateResponses && alternateResponses[key]) {
|
|
16
|
+
obj.possibleResponses[key] = [...obj.possibleResponses[key], ...(0, _lodashEs.cloneDeep)(alternateResponses[key])];
|
|
17
|
+
}
|
|
18
|
+
if (obj.numberOfPossibleResponses === undefined || obj.numberOfPossibleResponses > obj.possibleResponses[key].length) {
|
|
19
|
+
obj.numberOfPossibleResponses = obj.possibleResponses[key].length;
|
|
20
|
+
}
|
|
21
|
+
return obj;
|
|
22
|
+
}, {
|
|
23
|
+
possibleResponses: {},
|
|
24
|
+
numberOfPossibleResponses: undefined
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.getAllCorrectResponses = getAllCorrectResponses;
|
|
28
|
+
const choiceIsEmpty = choice => {
|
|
29
|
+
if (choice) {
|
|
30
|
+
const {
|
|
31
|
+
value = ''
|
|
32
|
+
} = choice;
|
|
33
|
+
const withoutEmptyTags = value.replace(replaceHtmlRegex, '') || '';
|
|
34
|
+
return withoutEmptyTags.trim() === '';
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
exports.choiceIsEmpty = choiceIsEmpty;
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_lodashEs","require","replaceHtmlRegex","getAllCorrectResponses","correctResponse","alternateResponses","reduce","obj","val","key","possibleResponses","cloneDeep","numberOfPossibleResponses","undefined","length","exports","choiceIsEmpty","choice","value","withoutEmptyTags","replace","trim"],"sources":["../src/utils.js"],"sourcesContent":["import { cloneDeep, reduce } from 'lodash-es';\n\nconst replaceHtmlRegex = /<(?!img)[^>]*>?/gm;\n\nexport const getAllCorrectResponses = ({ correctResponse, alternateResponses }) => {\n return reduce(\n correctResponse || {},\n (obj, val, key) => {\n obj.possibleResponses[key] = [val];\n\n if (alternateResponses && alternateResponses[key]) {\n obj.possibleResponses[key] = [...obj.possibleResponses[key], ...cloneDeep(alternateResponses[key])];\n }\n\n if (\n obj.numberOfPossibleResponses === undefined ||\n obj.numberOfPossibleResponses > obj.possibleResponses[key].length\n ) {\n obj.numberOfPossibleResponses = obj.possibleResponses[key].length;\n }\n\n return obj;\n },\n {\n possibleResponses: {},\n numberOfPossibleResponses: undefined,\n },\n );\n};\n\nexport const choiceIsEmpty = (choice) => {\n if (choice) {\n const { value = '' } = choice;\n const withoutEmptyTags = value.replace(replaceHtmlRegex, '') || '';\n\n return withoutEmptyTags.trim() === '';\n }\n\n return false;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA,MAAMC,gBAAgB,GAAG,mBAAmB;AAErC,MAAMC,sBAAsB,GAAGA,CAAC;EAAEC,eAAe;EAAEC;AAAmB,CAAC,KAAK;EACjF,OAAO,IAAAC,gBAAM,EACXF,eAAe,IAAI,CAAC,CAAC,EACrB,CAACG,GAAG,EAAEC,GAAG,EAAEC,GAAG,KAAK;IACjBF,GAAG,CAACG,iBAAiB,CAACD,GAAG,CAAC,GAAG,CAACD,GAAG,CAAC;IAElC,IAAIH,kBAAkB,IAAIA,kBAAkB,CAACI,GAAG,CAAC,EAAE;MACjDF,GAAG,CAACG,iBAAiB,CAACD,GAAG,CAAC,GAAG,CAAC,GAAGF,GAAG,CAACG,iBAAiB,CAACD,GAAG,CAAC,EAAE,GAAG,IAAAE,mBAAS,EAACN,kBAAkB,CAACI,GAAG,CAAC,CAAC,CAAC;IACrG;IAEA,IACEF,GAAG,CAACK,yBAAyB,KAAKC,SAAS,IAC3CN,GAAG,CAACK,yBAAyB,GAAGL,GAAG,CAACG,iBAAiB,CAACD,GAAG,CAAC,CAACK,MAAM,EACjE;MACAP,GAAG,CAACK,yBAAyB,GAAGL,GAAG,CAACG,iBAAiB,CAACD,GAAG,CAAC,CAACK,MAAM;IACnE;IAEA,OAAOP,GAAG;EACZ,CAAC,EACD;IACEG,iBAAiB,EAAE,CAAC,CAAC;IACrBE,yBAAyB,EAAEC;EAC7B,CACF,CAAC;AACH,CAAC;AAACE,OAAA,CAAAZ,sBAAA,GAAAA,sBAAA;AAEK,MAAMa,aAAa,GAAIC,MAAM,IAAK;EACvC,IAAIA,MAAM,EAAE;IACV,MAAM;MAAEC,KAAK,GAAG;IAAG,CAAC,GAAGD,MAAM;IAC7B,MAAME,gBAAgB,GAAGD,KAAK,CAACE,OAAO,CAAClB,gBAAgB,EAAE,EAAE,CAAC,IAAI,EAAE;IAElE,OAAOiB,gBAAgB,CAACE,IAAI,CAAC,CAAC,KAAK,EAAE;EACvC;EAEA,OAAO,KAAK;AACd,CAAC;AAACN,OAAA,CAAAC,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-element/drag-in-the-blank-controller",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "9.1.1",
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "src/index.js",
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@pie-lib/controller-utils": "2.0.2",
|
|
12
|
+
"debug": "^4.1.1",
|
|
13
|
+
"lodash-es": "^4.17.23",
|
|
14
|
+
"type-of": "^2.0.1"
|
|
15
|
+
}
|
|
16
|
+
}
|