@pie-element/ebsr 9.0.2-next.13 → 9.0.2-next.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +2478 -0
- package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
- package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
- package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +1949 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +133 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +248 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +610 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +869 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +306 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +36 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +614 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +469 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +53 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +411 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +327 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +332 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +165 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +156 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +96 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +359 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/package.json +31 -0
- package/configure/package.json +2 -2
- package/controller/package.json +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
promptEnabled: true,
|
|
9
|
+
rationaleEnabled: true,
|
|
10
|
+
accessibilityLabelsEnabled: false,
|
|
11
|
+
teacherInstructionsEnabled: true,
|
|
12
|
+
studentInstructionsEnabled: true,
|
|
13
|
+
choicePrefix: 'letters',
|
|
14
|
+
choicesLayout: 'vertical',
|
|
15
|
+
gridColumns: '2'
|
|
16
|
+
};
|
|
17
|
+
exports["default"] = _default;
|
|
18
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/defaults.js"],"names":["promptEnabled","rationaleEnabled","accessibilityLabelsEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","choicePrefix","choicesLayout","gridColumns"],"mappings":";;;;;;eAAe;AACbA,EAAAA,aAAa,EAAE,IADF;AAEbC,EAAAA,gBAAgB,EAAE,IAFL;AAGbC,EAAAA,0BAA0B,EAAE,KAHf;AAIbC,EAAAA,0BAA0B,EAAE,IAJf;AAKbC,EAAAA,0BAA0B,EAAE,IALf;AAMbC,EAAAA,YAAY,EAAE,SAND;AAObC,EAAAA,aAAa,EAAE,UAPF;AAQbC,EAAAA,WAAW,EAAE;AARA,C","sourcesContent":["export default {\n promptEnabled: true,\n rationaleEnabled: true,\n accessibilityLabelsEnabled: false,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n choicePrefix: 'letters',\n choicesLayout: 'vertical',\n gridColumns: '2',\n};\n"],"file":"defaults.js"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createCorrectResponseSession = void 0;
|
|
9
|
+
exports.createDefaultModel = createDefaultModel;
|
|
10
|
+
exports.getScore = void 0;
|
|
11
|
+
exports.model = model;
|
|
12
|
+
exports.normalize = void 0;
|
|
13
|
+
exports.outcome = outcome;
|
|
14
|
+
exports.validate = void 0;
|
|
15
|
+
|
|
16
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
17
|
+
|
|
18
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
19
|
+
|
|
20
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
21
|
+
|
|
22
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
23
|
+
|
|
24
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
+
|
|
26
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
27
|
+
|
|
28
|
+
var _utils = require("./utils");
|
|
29
|
+
|
|
30
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
31
|
+
|
|
32
|
+
var _controllerUtils = require("@pie-lib/pie-toolbox/controller-utils");
|
|
33
|
+
|
|
34
|
+
var _excluded = ["verticalMode", "choicesLayout"];
|
|
35
|
+
|
|
36
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
|
|
41
|
+
return function (choice) {
|
|
42
|
+
var _ref = env || {},
|
|
43
|
+
role = _ref.role,
|
|
44
|
+
mode = _ref.mode;
|
|
45
|
+
|
|
46
|
+
var out = {
|
|
47
|
+
label: choice.label,
|
|
48
|
+
value: choice.value
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (model.accessibilityLabelsEnabled) {
|
|
52
|
+
out.accessibility = (0, _utils.parseHTML)(choice.accessibility).textContent || choice.value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
56
|
+
out.rationale = model.rationaleEnabled ? choice.rationale : null;
|
|
57
|
+
} else {
|
|
58
|
+
out.rationale = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (mode === 'evaluate') {
|
|
62
|
+
out.correct = !!choice.correct;
|
|
63
|
+
|
|
64
|
+
if (model.feedbackEnabled) {
|
|
65
|
+
var feedbackType = choice.feedback && choice.feedback.type || 'none';
|
|
66
|
+
|
|
67
|
+
if (feedbackType === 'default') {
|
|
68
|
+
out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
|
|
69
|
+
} else if (feedbackType === 'custom') {
|
|
70
|
+
out.feedback = choice.feedback.value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return out;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function createDefaultModel() {
|
|
80
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
81
|
+
return new Promise(function (resolve) {
|
|
82
|
+
return resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var normalize = function normalize(question) {
|
|
87
|
+
var _ref2 = question || {},
|
|
88
|
+
verticalMode = _ref2.verticalMode,
|
|
89
|
+
choicesLayout = _ref2.choicesLayout,
|
|
90
|
+
questionProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
91
|
+
|
|
92
|
+
return _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"]), questionProps), {}, {
|
|
93
|
+
// This is used for offering support for old models which have the property verticalMode
|
|
94
|
+
// Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel
|
|
95
|
+
choicesLayout: choicesLayout || verticalMode === false && 'horizontal' || _defaults["default"].choicesLayout
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @param {*} question
|
|
101
|
+
* @param {*} session
|
|
102
|
+
* @param {*} env
|
|
103
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
exports.normalize = normalize;
|
|
108
|
+
|
|
109
|
+
function model(_x, _x2, _x3, _x4) {
|
|
110
|
+
return _model.apply(this, arguments);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function _model() {
|
|
114
|
+
_model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
|
|
115
|
+
var normalizedQuestion, defaultFeedback, choices, lockChoiceOrder, out, _ref4, role, mode;
|
|
116
|
+
|
|
117
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
118
|
+
while (1) {
|
|
119
|
+
switch (_context.prev = _context.next) {
|
|
120
|
+
case 0:
|
|
121
|
+
normalizedQuestion = normalize(question);
|
|
122
|
+
defaultFeedback = Object.assign({
|
|
123
|
+
correct: 'Correct',
|
|
124
|
+
incorrect: 'Incorrect'
|
|
125
|
+
}, normalizedQuestion.defaultFeedback);
|
|
126
|
+
choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));
|
|
127
|
+
lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
|
|
128
|
+
|
|
129
|
+
if (lockChoiceOrder) {
|
|
130
|
+
_context.next = 8;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_context.next = 7;
|
|
135
|
+
return (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'value');
|
|
136
|
+
|
|
137
|
+
case 7:
|
|
138
|
+
choices = _context.sent;
|
|
139
|
+
|
|
140
|
+
case 8:
|
|
141
|
+
out = {
|
|
142
|
+
disabled: env.mode !== 'gather',
|
|
143
|
+
mode: env.mode,
|
|
144
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
145
|
+
choicesLayout: normalizedQuestion.choicesLayout,
|
|
146
|
+
gridColumns: normalizedQuestion.gridColumns,
|
|
147
|
+
choiceMode: normalizedQuestion.choiceMode,
|
|
148
|
+
keyMode: normalizedQuestion.choicePrefix,
|
|
149
|
+
choices: choices,
|
|
150
|
+
responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(normalizedQuestion, session) : undefined,
|
|
151
|
+
language: normalizedQuestion.language
|
|
152
|
+
};
|
|
153
|
+
_ref4 = env || {}, role = _ref4.role, mode = _ref4.mode;
|
|
154
|
+
|
|
155
|
+
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
156
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
157
|
+
} else {
|
|
158
|
+
out.teacherInstructions = null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return _context.abrupt("return", out);
|
|
162
|
+
|
|
163
|
+
case 12:
|
|
164
|
+
case "end":
|
|
165
|
+
return _context.stop();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}, _callee);
|
|
169
|
+
}));
|
|
170
|
+
return _model.apply(this, arguments);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var getScore = function getScore(config, session) {
|
|
174
|
+
if (!session || (0, _isEmpty["default"])(session)) {
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
var selectedChoices = session.value || [];
|
|
179
|
+
var correctChoices = (config.choices || []).filter(function (ch) {
|
|
180
|
+
return ch.correct;
|
|
181
|
+
});
|
|
182
|
+
var score = selectedChoices.reduce(function (acc, selectedChoice) {
|
|
183
|
+
return acc + (correctChoices.find(function (ch) {
|
|
184
|
+
return ch.value === selectedChoice;
|
|
185
|
+
}) ? 1 : 0);
|
|
186
|
+
}, 0);
|
|
187
|
+
|
|
188
|
+
if (correctChoices.length < selectedChoices.length) {
|
|
189
|
+
score -= selectedChoices.length - correctChoices.length;
|
|
190
|
+
|
|
191
|
+
if (score < 0) {
|
|
192
|
+
score = 0;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
var str = correctChoices.length ? score / correctChoices.length : 0;
|
|
197
|
+
return parseFloat(str.toFixed(2));
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
*
|
|
201
|
+
* The score is partial by default for checkbox mode, allOrNothing for radio mode.
|
|
202
|
+
* To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will
|
|
203
|
+
* override the value in `model`.
|
|
204
|
+
* @param {Object} model - the main model
|
|
205
|
+
* @param {*} session
|
|
206
|
+
* @param {Object} env
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
exports.getScore = getScore;
|
|
211
|
+
|
|
212
|
+
function outcome(model, session, env) {
|
|
213
|
+
return new Promise(function (resolve) {
|
|
214
|
+
if (!session || (0, _isEmpty["default"])(session)) {
|
|
215
|
+
resolve({
|
|
216
|
+
score: 0,
|
|
217
|
+
empty: true
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
var partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
|
|
221
|
+
var score = getScore(model, session);
|
|
222
|
+
resolve({
|
|
223
|
+
score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
|
|
224
|
+
empty: false
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
|
|
231
|
+
return new Promise(function (resolve) {
|
|
232
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
233
|
+
var _ref3 = question || {
|
|
234
|
+
choices: []
|
|
235
|
+
},
|
|
236
|
+
choices = _ref3.choices;
|
|
237
|
+
|
|
238
|
+
resolve({
|
|
239
|
+
id: '1',
|
|
240
|
+
value: choices.filter(function (c) {
|
|
241
|
+
return c.correct;
|
|
242
|
+
}).map(function (c) {
|
|
243
|
+
return c.value;
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
resolve(null);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
253
|
+
|
|
254
|
+
var validate = function validate() {
|
|
255
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
256
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
257
|
+
var choices = model.choices;
|
|
258
|
+
var _config$minAnswerChoi = config.minAnswerChoices,
|
|
259
|
+
minAnswerChoices = _config$minAnswerChoi === void 0 ? 2 : _config$minAnswerChoi,
|
|
260
|
+
maxAnswerChoices = config.maxAnswerChoices;
|
|
261
|
+
var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
|
|
262
|
+
var choicesErrors = {};
|
|
263
|
+
var hasCorrectResponse = false;
|
|
264
|
+
reversedChoices.forEach(function (choice, index) {
|
|
265
|
+
var correct = choice.correct,
|
|
266
|
+
value = choice.value,
|
|
267
|
+
label = choice.label;
|
|
268
|
+
|
|
269
|
+
if (correct) {
|
|
270
|
+
hasCorrectResponse = true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (label === '' || label === '<div></div>') {
|
|
274
|
+
choicesErrors[value] = 'Content should not be empty.';
|
|
275
|
+
} else {
|
|
276
|
+
var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
|
|
277
|
+
return c.label === label;
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
if (identicalAnswer) {
|
|
281
|
+
choicesErrors[value] = 'Content should be unique.';
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
var errors = {};
|
|
286
|
+
var nbOfChoices = (choices || []).length;
|
|
287
|
+
|
|
288
|
+
if (nbOfChoices < minAnswerChoices) {
|
|
289
|
+
errors.answerChoicesError = "There should be at least ".concat(minAnswerChoices, " choices defined.");
|
|
290
|
+
} else if (nbOfChoices > maxAnswerChoices) {
|
|
291
|
+
errors.answerChoicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!hasCorrectResponse) {
|
|
295
|
+
errors.correctResponseError = 'No correct response defined.';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (!(0, _isEmpty["default"])(choicesErrors)) {
|
|
299
|
+
errors.choicesErrors = choicesErrors;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return errors;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
exports.validate = validate;
|
|
306
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","accessibilityLabelsEnabled","accessibility","textContent","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","verticalMode","choicesLayout","questionProps","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","undefined","language","teacherInstructions","teacherInstructionsEnabled","getScore","config","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","id","c","validate","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","hasCorrectResponse","forEach","index","identicalAnswer","slice","some","errors","nbOfChoices","answerChoicesError","correctResponseError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAACC,MAAD,EAAY;AACjE,eAAuBF,GAAG,IAAI,EAA9B;AAAA,QAAQG,IAAR,QAAQA,IAAR;AAAA,QAAcC,IAAd,QAAcA,IAAd;;AACA,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KADJ;AAEVC,MAAAA,KAAK,EAAEL,MAAM,CAACK;AAFJ,KAAZ;;AAKA,QAAIR,KAAK,CAACS,0BAAV,EAAsC;AACpCH,MAAAA,GAAG,CAACI,aAAJ,GAAoB,sBAAUP,MAAM,CAACO,aAAjB,EAAgCC,WAAhC,IAA+CR,MAAM,CAACK,KAA1E;AACD;;AAED,QAAIJ,IAAI,KAAK,YAAT,KAA0BC,IAAI,KAAK,MAAT,IAAmBA,IAAI,KA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,CA3CM","sourcesContent":["/* eslint-disable no-console */\nimport isEmpty from 'lodash/isEmpty';\nimport { isResponseCorrect, parseHTML } from './utils';\nimport defaults from './defaults';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-lib/pie-toolbox/controller-utils';\n\nconst prepareChoice = (model, env, defaultFeedback) => (choice) => {\n const { role, mode } = env || {};\n const out = {\n label: choice.label,\n value: choice.value,\n };\n\n if (model.accessibilityLabelsEnabled) {\n out.accessibility = parseHTML(choice.accessibility).textContent || choice.value;\n }\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (mode === 'evaluate') {\n out.correct = !!choice.correct;\n\n if (model.feedbackEnabled) {\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n }\n\n return out;\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = (question) => {\n const { verticalMode, choicesLayout, ...questionProps } = question || {};\n\n return {\n ...defaults,\n ...questionProps,\n // This is used for offering support for old models which have the property verticalMode\n // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel\n choicesLayout: choicesLayout || (verticalMode === false && 'horizontal') || defaults.choicesLayout,\n };\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\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback,\n );\n\n let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'value');\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choicesLayout: normalizedQuestion.choicesLayout,\n gridColumns: normalizedQuestion.gridColumns,\n choiceMode: normalizedQuestion.choiceMode,\n keyMode: normalizedQuestion.choicePrefix,\n choices,\n responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined,\n language: normalizedQuestion.language,\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\nexport const getScore = (config, session) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const selectedChoices = session.value || [];\n const correctChoices = (config.choices || []).filter((ch) => ch.correct);\n\n let score = selectedChoices.reduce(\n (acc, selectedChoice) => acc + (correctChoices.find((ch) => ch.value === selectedChoice) ? 1 : 0),\n 0,\n );\n\n if (correctChoices.length < selectedChoices.length) {\n score -= selectedChoices.length - correctChoices.length;\n\n if (score < 0) {\n score = 0;\n }\n }\n\n const str = correctChoices.length ? score / correctChoices.length : 0;\n\n return parseFloat(str.toFixed(2));\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 = false. the value in `env` will\n * override the value in `model`.\n * @param {Object} model - the main model\n * @param {*} session\n * @param {Object} env\n */\nexport function outcome(model, session, env) {\n return new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question || { choices: [] };\n\n resolve({\n id: '1',\n value: choices.filter((c) => c.correct).map((c) => c.value),\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors = {};\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n });\n\n const errors = {};\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoicesError = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoicesError = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponseError = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.parseHTML = exports.isResponseCorrect = exports.getCorrectResponse = void 0;
|
|
9
|
+
|
|
10
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
11
|
+
|
|
12
|
+
var getCorrectResponse = function getCorrectResponse(choices) {
|
|
13
|
+
return choices.filter(function (c) {
|
|
14
|
+
return c.correct;
|
|
15
|
+
}).map(function (c) {
|
|
16
|
+
return c.value;
|
|
17
|
+
}).sort();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.getCorrectResponse = getCorrectResponse;
|
|
21
|
+
|
|
22
|
+
var isResponseCorrect = function isResponseCorrect(question, session) {
|
|
23
|
+
var correctResponse = getCorrectResponse(question.choices);
|
|
24
|
+
return session && (0, _isEqual["default"])((session.value || []).sort(), correctResponse);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.isResponseCorrect = isResponseCorrect;
|
|
28
|
+
|
|
29
|
+
var parseHTML = function parseHTML(html) {
|
|
30
|
+
var template = document.createElement('template');
|
|
31
|
+
template.innerHTML = html;
|
|
32
|
+
return template.content;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.parseHTML = parseHTML;
|
|
36
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","value","sort","isResponseCorrect","question","session","correctResponse","parseHTML","html","template","document","createElement","innerHTML","content"],"mappings":";;;;;;;;;AAAA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAChCA,OAAO,CACJC,MADH,CACU,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,OAAT;AAAA,GADV,EAEGC,GAFH,CAEO,UAACF,CAAD;AAAA,WAAOA,CAAC,CAACG,KAAT;AAAA,GAFP,EAGGC,IAHH,EADgC;AAAA,CAA3B;;;;AAMA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACtD,MAAIC,eAAe,GAAGX,kBAAkB,CAACS,QAAQ,CAACR,OAAV,CAAxC;AACA,SAAOS,OAAO,IAAI,yBAAQ,CAACA,OAAO,CAACJ,KAAR,IAAiB,EAAlB,EAAsBC,IAAtB,EAAR,EAAsCI,eAAtC,CAAlB;AACD,CAHM;;;;AAKA,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,IAAD,EAAU;AACjC,MAAMC,QAAQ,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAjB;AACAF,EAAAA,QAAQ,CAACG,SAAT,GAAqBJ,IAArB;AACA,SAAOC,QAAQ,CAACI,OAAhB;AACD,CAJM","sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) =>\n choices\n .filter((c) => c.correct)\n .map((c) => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n return session && isEqual((session.value || []).sort(), correctResponse);\n};\n\nexport const parseHTML = (html) => {\n const template = document.createElement('template');\n template.innerHTML = html;\n return template.content;\n};\n"],"file":"utils.js"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-element/multiple-choice-controller",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "4.0.1",
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "src/index.js",
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@pie-lib/pie-toolbox": "1.0.12-next.3",
|
|
12
|
+
"debug": "^3.1.0",
|
|
13
|
+
"lodash": "^4.17.15"
|
|
14
|
+
}
|
|
15
|
+
}
|