@pie-element/math-inline 11.0.5-esm.0 → 11.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/configure/CHANGELOG.md +69 -0
- package/configure/lib/configure.js +162 -240
- package/configure/lib/configure.js.map +1 -1
- package/configure/lib/defaults.js +8 -8
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/general-config-block.js +447 -564
- package/configure/lib/general-config-block.js.map +1 -1
- package/configure/lib/index.js +111 -176
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/response.js +330 -388
- package/configure/lib/response.js.map +1 -1
- package/configure/lib/utils.js +15 -30
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +14 -12
- package/controller/CHANGELOG.md +49 -0
- package/controller/lib/defaults.js +5 -8
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +189 -278
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +1 -2
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +7 -7
- package/lib/index.js +72 -125
- package/lib/index.js.map +1 -1
- package/lib/main.js +784 -889
- package/lib/main.js.map +1 -1
- package/lib/print.js +43 -84
- package/lib/print.js.map +1 -1
- package/lib/simple-question-block.js +125 -162
- package/lib/simple-question-block.js.map +1 -1
- package/lib/utils.js +1 -2
- package/lib/utils.js.map +1 -1
- package/module/configure.js +1 -1
- package/module/controller.js +2319 -2930
- package/module/element.js +1 -1
- package/module/index.html +1 -1
- package/module/manifest.json +7 -3
- package/module/print.html +1 -1
- package/module/print.js +1 -1
- package/package.json +21 -33
- package/esm/configure.css +0 -847
- package/esm/configure.js +0 -1769
- package/esm/configure.js.map +0 -1
- package/esm/controller.css +0 -847
- package/esm/controller.js +0 -416
- package/esm/controller.js.map +0 -1
- package/esm/element.css +0 -847
- package/esm/element.js +0 -1476
- package/esm/element.js.map +0 -1
- package/esm/print.css +0 -847
- package/esm/print.js +0 -1288
- package/esm/print.js.map +0 -1
package/controller/lib/index.js
CHANGED
|
@@ -1,55 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
4
|
Object.defineProperty(exports, "__esModule", {
|
|
8
5
|
value: true
|
|
9
6
|
});
|
|
10
7
|
exports.createCorrectResponseSession = void 0;
|
|
11
8
|
exports.createDefaultModel = createDefaultModel;
|
|
12
9
|
exports.validate = exports.outcome = exports.normalize = exports.model = void 0;
|
|
13
|
-
|
|
14
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
-
|
|
16
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
|
-
|
|
18
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
19
|
-
|
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
23
|
-
|
|
24
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
25
|
-
|
|
11
|
+
var _lodashEs = require("lodash-es");
|
|
26
12
|
var _feedback = require("@pie-lib/feedback");
|
|
27
|
-
|
|
28
13
|
var _utils = require("./utils");
|
|
29
|
-
|
|
30
14
|
var _translator = _interopRequireDefault(require("@pie-lib/translator"));
|
|
31
|
-
|
|
32
15
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
33
|
-
|
|
34
16
|
var mv = _interopRequireWildcard(require("@pie-framework/math-validation"));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
45
|
-
|
|
46
|
-
var translator = _translator["default"].translator;
|
|
47
|
-
var log = (0, _debug["default"])('@pie-element:math-inline:controller');
|
|
48
|
-
|
|
49
|
-
var getResponseCorrectness = function getResponseCorrectness(model, answerItem, isOutcome) {
|
|
50
|
-
var correctResponses = model.responses;
|
|
51
|
-
var isAdvanced = model.responseType === _utils.ResponseTypes.advanced;
|
|
52
|
-
|
|
17
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
18
|
+
const {
|
|
19
|
+
translator
|
|
20
|
+
} = _translator.default;
|
|
21
|
+
const log = (0, _debug.default)('@pie-element:math-inline:controller');
|
|
22
|
+
const getResponseCorrectness = (model, answerItem, isOutcome) => {
|
|
23
|
+
const correctResponses = model.responses;
|
|
24
|
+
const isAdvanced = model.responseType === _utils.ResponseTypes.advanced;
|
|
53
25
|
if (!answerItem) {
|
|
54
26
|
return {
|
|
55
27
|
correctness: 'unanswered',
|
|
@@ -57,43 +29,34 @@ var getResponseCorrectness = function getResponseCorrectness(model, answerItem,
|
|
|
57
29
|
correct: false
|
|
58
30
|
};
|
|
59
31
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var correctnessObject = {
|
|
32
|
+
const isAnswerCorrect = getIsAnswerCorrect(isAdvanced ? correctResponses : correctResponses.slice(0, 1), answerItem);
|
|
33
|
+
const correctnessObject = {
|
|
63
34
|
correctness: 'incorrect',
|
|
64
35
|
score: isOutcome ? 0 : '0%',
|
|
65
36
|
correct: false
|
|
66
37
|
};
|
|
67
|
-
|
|
68
38
|
if (isAnswerCorrect) {
|
|
69
39
|
correctnessObject.correctness = 'correct';
|
|
70
40
|
correctnessObject.score = isOutcome ? 1 : '100%';
|
|
71
41
|
correctnessObject.correct = true;
|
|
72
42
|
}
|
|
73
|
-
|
|
74
43
|
return correctnessObject;
|
|
75
44
|
};
|
|
76
|
-
|
|
77
45
|
function getIsAnswerCorrect(correctResponseItems, answerItem) {
|
|
78
|
-
|
|
79
|
-
(correctResponseItems || []).forEach(
|
|
46
|
+
let answerCorrect = false;
|
|
47
|
+
(correctResponseItems || []).forEach(correctResponse => {
|
|
80
48
|
if (answerCorrect) return;
|
|
81
|
-
|
|
82
|
-
mode: correctResponse.validation || _defaults
|
|
49
|
+
const opts = {
|
|
50
|
+
mode: correctResponse.validation || _defaults.default.validationDefault
|
|
83
51
|
};
|
|
84
|
-
|
|
85
52
|
if (opts.mode === 'literal') {
|
|
86
53
|
opts.literal = {
|
|
87
54
|
allowTrailingZeros: correctResponse.allowTrailingZeros || false,
|
|
88
55
|
ignoreOrder: correctResponse.ignoreOrder || false
|
|
89
56
|
};
|
|
90
57
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return correctResponse.alternates[alternateId];
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
for (var i = 0; i < acceptedValues.length; i++) {
|
|
58
|
+
const acceptedValues = [correctResponse.answer].concat(Object.keys(correctResponse.alternates || {}).map(alternateId => correctResponse.alternates[alternateId]));
|
|
59
|
+
for (let i = 0; i < acceptedValues.length; i++) {
|
|
97
60
|
try {
|
|
98
61
|
if (mv.latexEqual(answerItem, acceptedValues[i], opts)) {
|
|
99
62
|
answerCorrect = true;
|
|
@@ -107,39 +70,37 @@ function getIsAnswerCorrect(correctResponseItems, answerItem) {
|
|
|
107
70
|
});
|
|
108
71
|
return answerCorrect;
|
|
109
72
|
}
|
|
110
|
-
|
|
111
|
-
var getCorrectness = function getCorrectness(question, env, session, isOutcome) {
|
|
73
|
+
const getCorrectness = (question, env, session, isOutcome) => {
|
|
112
74
|
if (env.mode === 'evaluate') {
|
|
113
75
|
return getResponseCorrectness(question, question.responseType === _utils.ResponseTypes.advanced ? session && session.completeAnswer || '' : session && session.response, isOutcome);
|
|
114
76
|
}
|
|
115
|
-
|
|
116
77
|
return undefined;
|
|
117
78
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
121
|
-
return new Promise(function (resolve) {
|
|
79
|
+
function createDefaultModel(model = {}) {
|
|
80
|
+
return new Promise(resolve => {
|
|
122
81
|
resolve({
|
|
123
|
-
config:
|
|
82
|
+
config: {
|
|
83
|
+
..._defaults.default,
|
|
84
|
+
...model
|
|
85
|
+
}
|
|
124
86
|
});
|
|
125
87
|
});
|
|
126
88
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return new Promise(function (resolve) {
|
|
89
|
+
const outcome = (question, session, env) => {
|
|
90
|
+
return new Promise(resolve => {
|
|
130
91
|
if (env.mode !== 'evaluate') {
|
|
131
92
|
resolve({
|
|
132
93
|
score: undefined,
|
|
133
94
|
completed: undefined
|
|
134
95
|
});
|
|
135
96
|
} else {
|
|
136
|
-
if (!session || (0,
|
|
97
|
+
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
137
98
|
resolve({
|
|
138
99
|
score: 0,
|
|
139
100
|
empty: true
|
|
140
101
|
});
|
|
141
102
|
} else {
|
|
142
|
-
|
|
103
|
+
const correctness = getCorrectness(question, env, session, true);
|
|
143
104
|
resolve({
|
|
144
105
|
score: correctness.score
|
|
145
106
|
});
|
|
@@ -147,270 +108,220 @@ var outcome = function outcome(question, session, env) {
|
|
|
147
108
|
}
|
|
148
109
|
});
|
|
149
110
|
};
|
|
150
|
-
|
|
151
111
|
exports.outcome = outcome;
|
|
152
|
-
|
|
153
|
-
var normalize = function normalize(question) {
|
|
112
|
+
const normalize = question => {
|
|
154
113
|
// making sure that defaults are set
|
|
155
|
-
if (!(0,
|
|
156
|
-
question.responses = question.responses.map(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
114
|
+
if (!(0, _lodashEs.isEmpty)(question.responses)) {
|
|
115
|
+
question.responses = question.responses.map(correctResponse => ({
|
|
116
|
+
...correctResponse,
|
|
117
|
+
validation: correctResponse.validation || question.validationDefault,
|
|
118
|
+
allowTrailingZeros: correctResponse.allowTrailingZeros || question.allowTrailingZerosDefault,
|
|
119
|
+
ignoreOrder: correctResponse.ignoreOrder || question.ignoreOrderDefault
|
|
120
|
+
}));
|
|
163
121
|
}
|
|
164
|
-
|
|
165
|
-
|
|
122
|
+
return {
|
|
123
|
+
..._defaults.default,
|
|
124
|
+
...question
|
|
125
|
+
};
|
|
166
126
|
};
|
|
167
|
-
|
|
168
127
|
exports.normalize = normalize;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
var note = normalizedQuestion.note || translator.t('mathInline.primaryCorrectWithAlternates', {
|
|
191
|
-
lng: language
|
|
192
|
-
});
|
|
193
|
-
var showNote = (config === null || config === void 0 ? void 0 : (_config$responses = config.responses) === null || _config$responses === void 0 ? void 0 : _config$responses.length) > 1 || ((config === null || config === void 0 ? void 0 : config.responses) || []).some(function (response) {
|
|
194
|
-
return response.validation === 'symbolic' || Object.keys(response.alternates || {}).length > 0;
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
if (env.mode === 'evaluate') {
|
|
198
|
-
out.correctResponse = {};
|
|
199
|
-
out.config.showNote = showNote;
|
|
200
|
-
out.config.note = note;
|
|
201
|
-
} else {
|
|
202
|
-
out.config.responses = [];
|
|
203
|
-
out.config.showNote = false;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
207
|
-
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
208
|
-
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
209
|
-
} else {
|
|
210
|
-
out.rationale = null;
|
|
211
|
-
out.teacherInstructions = null;
|
|
212
|
-
out.config.rationale = null;
|
|
213
|
-
out.config.teacherInstructions = null;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
out.config.env = env;
|
|
217
|
-
out.config.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
|
|
218
|
-
out.language = language;
|
|
219
|
-
log('out: ', out);
|
|
220
|
-
resolve(out);
|
|
128
|
+
const model = (question, session, env) => new Promise(resolve => {
|
|
129
|
+
const normalizedQuestion = normalize(question);
|
|
130
|
+
const correctness = getCorrectness(normalizedQuestion, env, session);
|
|
131
|
+
const {
|
|
132
|
+
extraCSSRules,
|
|
133
|
+
responses,
|
|
134
|
+
language,
|
|
135
|
+
...config
|
|
136
|
+
} = normalizedQuestion;
|
|
137
|
+
config.responses = config.responseType === _utils.ResponseTypes.simple ? responses.slice(0, 1) : responses;
|
|
138
|
+
const feedback = env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled ? (0, _feedback.getActualFeedbackForCorrectness)(correctness?.correctness, normalizedQuestion.feedback) : undefined;
|
|
139
|
+
const out = {
|
|
140
|
+
extraCSSRules,
|
|
141
|
+
config,
|
|
142
|
+
correctness,
|
|
143
|
+
feedback,
|
|
144
|
+
disabled: env.mode !== 'gather',
|
|
145
|
+
view: env.mode === 'view'
|
|
146
|
+
};
|
|
147
|
+
const note = normalizedQuestion.note || translator.t('mathInline.primaryCorrectWithAlternates', {
|
|
148
|
+
lng: language
|
|
221
149
|
});
|
|
222
|
-
};
|
|
223
|
-
|
|
150
|
+
const showNote = config?.responses?.length > 1 || (config?.responses || []).some(response => response.validation === 'symbolic' || Object.keys(response.alternates || {}).length > 0);
|
|
151
|
+
if (env.mode === 'evaluate') {
|
|
152
|
+
out.correctResponse = {};
|
|
153
|
+
out.config.showNote = showNote;
|
|
154
|
+
out.config.note = note;
|
|
155
|
+
} else {
|
|
156
|
+
out.config.responses = [];
|
|
157
|
+
out.config.showNote = false;
|
|
158
|
+
}
|
|
159
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
160
|
+
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
161
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
162
|
+
} else {
|
|
163
|
+
out.rationale = null;
|
|
164
|
+
out.teacherInstructions = null;
|
|
165
|
+
out.config.rationale = null;
|
|
166
|
+
out.config.teacherInstructions = null;
|
|
167
|
+
}
|
|
168
|
+
out.config.env = env;
|
|
169
|
+
out.config.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
|
|
170
|
+
out.language = language;
|
|
171
|
+
log('out: ', out);
|
|
172
|
+
resolve(out);
|
|
173
|
+
});
|
|
224
174
|
exports.model = model;
|
|
175
|
+
const escape = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
176
|
+
|
|
177
|
+
const simpleSessionResponse = question => new Promise(resolve => {
|
|
178
|
+
const {
|
|
179
|
+
responses,
|
|
180
|
+
id
|
|
181
|
+
} = question;
|
|
182
|
+
const {
|
|
183
|
+
answer
|
|
184
|
+
} = responses && responses.length ? responses[0] : {};
|
|
185
|
+
resolve({
|
|
186
|
+
id,
|
|
187
|
+
response: answer || '',
|
|
188
|
+
completeAnswer: answer || ''
|
|
189
|
+
});
|
|
190
|
+
});
|
|
225
191
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
answer = _ref.answer;
|
|
238
|
-
|
|
192
|
+
// use this for items like E672793
|
|
193
|
+
const removeTrailingEscape = str => str.endsWith('\\') ? str.slice(0, -1) : str;
|
|
194
|
+
const advancedSessionResponse = question => new Promise(resolve => {
|
|
195
|
+
const {
|
|
196
|
+
responses,
|
|
197
|
+
id
|
|
198
|
+
} = question;
|
|
199
|
+
const {
|
|
200
|
+
answer
|
|
201
|
+
} = responses && responses.length ? responses[0] : {};
|
|
202
|
+
if (!answer) {
|
|
239
203
|
resolve({
|
|
240
|
-
id
|
|
241
|
-
|
|
242
|
-
completeAnswer:
|
|
204
|
+
id,
|
|
205
|
+
answers: {},
|
|
206
|
+
completeAnswer: ''
|
|
243
207
|
});
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
id = question.id;
|
|
256
|
-
|
|
257
|
-
var _ref2 = responses && responses.length ? responses[0] : {},
|
|
258
|
-
answer = _ref2.answer;
|
|
259
|
-
|
|
260
|
-
if (!answer) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const e = question.expression;
|
|
212
|
+
const RESPONSE_TOKEN = /\\{\\{\s*response\s*\\}\\}/g;
|
|
213
|
+
const o = escape(e).split(RESPONSE_TOKEN);
|
|
214
|
+
const to = o.map(t => t === '' ? t : t.replace(/\s+/g, () => '\\s*'));
|
|
215
|
+
const tt = to.join('(.*)');
|
|
216
|
+
const m = answer.match(new RegExp(tt));
|
|
217
|
+
const count = o.length - 1;
|
|
218
|
+
if (!m) {
|
|
261
219
|
resolve({
|
|
262
|
-
id
|
|
220
|
+
id,
|
|
263
221
|
answers: {},
|
|
264
|
-
completeAnswer: ''
|
|
265
|
-
});
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
try {
|
|
270
|
-
var e = question.expression;
|
|
271
|
-
var RESPONSE_TOKEN = /\\{\\{\s*response\s*\\}\\}/g;
|
|
272
|
-
var o = escape(e).split(RESPONSE_TOKEN);
|
|
273
|
-
var to = o.map(function (t) {
|
|
274
|
-
return t === '' ? t : t.replace(/\s+/g, function () {
|
|
275
|
-
return '\\s*';
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
var tt = to.join('(.*)');
|
|
279
|
-
var m = answer.match(new RegExp(tt));
|
|
280
|
-
var count = o.length - 1;
|
|
281
|
-
|
|
282
|
-
if (!m) {
|
|
283
|
-
resolve({
|
|
284
|
-
id: id,
|
|
285
|
-
answers: {},
|
|
286
|
-
completeAnswer: answer
|
|
287
|
-
}); // eslint-disable-next-line no-console
|
|
288
|
-
|
|
289
|
-
console.log("can not find match: ".concat(o, " in ").concat(answer));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
m.shift();
|
|
294
|
-
var answers = {};
|
|
295
|
-
|
|
296
|
-
for (var i = 0; i < count; i++) {
|
|
297
|
-
answers["r".concat(i + 1)] = {
|
|
298
|
-
value: removeTrailingEscape(m[i].trim())
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
resolve({
|
|
303
|
-
id: id,
|
|
304
|
-
answers: answers,
|
|
305
222
|
completeAnswer: answer
|
|
306
223
|
});
|
|
307
|
-
} catch (e) {
|
|
308
|
-
resolve({
|
|
309
|
-
id: id,
|
|
310
|
-
answers: {},
|
|
311
|
-
completeAnswer: answer
|
|
312
|
-
}); // eslint-disable-next-line no-console
|
|
313
224
|
|
|
314
|
-
console
|
|
225
|
+
// eslint-disable-next-line no-console
|
|
226
|
+
console.log(`can not find match: ${o} in ${answer}`);
|
|
227
|
+
return;
|
|
315
228
|
}
|
|
316
|
-
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
|
|
229
|
+
m.shift();
|
|
230
|
+
const answers = {};
|
|
231
|
+
for (var i = 0; i < count; i++) {
|
|
232
|
+
answers[`r${i + 1}`] = {
|
|
233
|
+
value: removeTrailingEscape(m[i].trim())
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
resolve({
|
|
237
|
+
id,
|
|
238
|
+
answers,
|
|
239
|
+
completeAnswer: answer
|
|
240
|
+
});
|
|
241
|
+
} catch (e) {
|
|
242
|
+
resolve({
|
|
243
|
+
id,
|
|
244
|
+
answers: {},
|
|
245
|
+
completeAnswer: answer
|
|
246
|
+
});
|
|
247
|
+
// eslint-disable-next-line no-console
|
|
248
|
+
console.error(e.toString());
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
const createCorrectResponseSession = (question, env) => {
|
|
320
252
|
if (env.mode === 'evaluate' || env.role !== 'instructor') {
|
|
321
253
|
// eslint-disable-next-line no-console
|
|
322
254
|
console.error('can not create correct response session if mode is evaluate or role is not instructor');
|
|
323
255
|
return Promise.resolve(null);
|
|
324
256
|
}
|
|
325
|
-
|
|
326
257
|
if ((question.responseType || '').toLowerCase() === 'simple') {
|
|
327
258
|
return simpleSessionResponse(question, env);
|
|
328
259
|
} else {
|
|
329
260
|
return advancedSessionResponse(question, env);
|
|
330
261
|
}
|
|
331
|
-
}; // remove all html tags
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
335
|
-
|
|
336
|
-
var getInnerText = function getInnerText(html) {
|
|
337
|
-
return (html || '').replaceAll(/<[^>]*>/g, '');
|
|
338
|
-
}; // remove all html tags except img, iframe and source tag for audio
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
var getContent = function getContent(html) {
|
|
342
|
-
return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
343
262
|
};
|
|
344
263
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
264
|
+
// remove all html tags
|
|
265
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
266
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
267
|
+
|
|
268
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
269
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
270
|
+
const validate = (model = {}, config = {}) => {
|
|
271
|
+
const {
|
|
272
|
+
expression = '',
|
|
273
|
+
responses,
|
|
274
|
+
responseType
|
|
275
|
+
} = model;
|
|
276
|
+
const {
|
|
277
|
+
maxResponseAreas
|
|
278
|
+
} = config;
|
|
279
|
+
const responsesErrors = {};
|
|
280
|
+
const errors = {};
|
|
281
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
|
|
282
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
359
283
|
errors[field] = 'This field is required.';
|
|
360
284
|
}
|
|
361
285
|
});
|
|
362
|
-
(responses || []).forEach(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
286
|
+
(responses || []).forEach((response, index) => {
|
|
287
|
+
const {
|
|
288
|
+
answer
|
|
289
|
+
} = response;
|
|
290
|
+
const reversedAlternates = [...Object.entries(response.alternates || {})].reverse();
|
|
291
|
+
const alternatesErrors = {};
|
|
292
|
+
const responseError = {};
|
|
368
293
|
if (answer === '') {
|
|
369
294
|
responseError.answer = 'Content should not be empty.';
|
|
370
295
|
}
|
|
371
|
-
|
|
372
|
-
reversedAlternates.forEach(function (_ref3, index) {
|
|
373
|
-
var _ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
|
|
374
|
-
key = _ref4[0],
|
|
375
|
-
value = _ref4[1];
|
|
376
|
-
|
|
296
|
+
reversedAlternates.forEach(([key, value], index) => {
|
|
377
297
|
if (value === '') {
|
|
378
298
|
alternatesErrors[key] = 'Content should not be empty.';
|
|
379
299
|
} else {
|
|
380
|
-
|
|
381
|
-
var _ref6 = (0, _slicedToArray2["default"])(_ref5, 2),
|
|
382
|
-
val = _ref6[1];
|
|
383
|
-
|
|
384
|
-
return val === value;
|
|
385
|
-
});
|
|
386
|
-
|
|
300
|
+
const identicalAnswer = answer === value || reversedAlternates.slice(index + 1).some(([, val]) => val === value);
|
|
387
301
|
if (identicalAnswer) {
|
|
388
302
|
alternatesErrors[key] = 'Content should be unique.';
|
|
389
303
|
}
|
|
390
304
|
}
|
|
391
305
|
});
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
306
|
+
if (!(0, _lodashEs.isEmpty)(responseError) || !(0, _lodashEs.isEmpty)(alternatesErrors)) {
|
|
307
|
+
responsesErrors[index] = {
|
|
308
|
+
...responseError,
|
|
309
|
+
...alternatesErrors
|
|
310
|
+
};
|
|
395
311
|
}
|
|
396
312
|
});
|
|
397
|
-
|
|
398
313
|
if (responseType === 'Advanced Multi') {
|
|
399
|
-
|
|
400
|
-
|
|
314
|
+
const nbOfResponseAreas = (expression.match(/\{\{response\}\}/g) || []).length;
|
|
401
315
|
if (nbOfResponseAreas > maxResponseAreas) {
|
|
402
|
-
errors.responseAreasError =
|
|
316
|
+
errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;
|
|
403
317
|
} else if (nbOfResponseAreas < 1) {
|
|
404
318
|
errors.responseAreasError = 'There should be at least 1 response area defined.';
|
|
405
319
|
}
|
|
406
320
|
}
|
|
407
|
-
|
|
408
|
-
if (!(0, _isEmpty["default"])(responsesErrors)) {
|
|
321
|
+
if (!(0, _lodashEs.isEmpty)(responsesErrors)) {
|
|
409
322
|
errors.responsesErrors = responsesErrors;
|
|
410
323
|
}
|
|
411
|
-
|
|
412
324
|
return errors;
|
|
413
325
|
};
|
|
414
|
-
|
|
415
326
|
exports.validate = validate;
|
|
416
327
|
//# sourceMappingURL=index.js.map
|