@pie-element/categorize 11.1.0 → 11.2.0-mui-update.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/configure/CHANGELOG.md +66 -0
  3. package/configure/lib/defaults.js +2 -5
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/design/builder.js +15 -33
  6. package/configure/lib/design/builder.js.map +1 -1
  7. package/configure/lib/design/buttons.js +44 -95
  8. package/configure/lib/design/buttons.js.map +1 -1
  9. package/configure/lib/design/categories/RowLabel.js +32 -45
  10. package/configure/lib/design/categories/RowLabel.js.map +1 -1
  11. package/configure/lib/design/categories/alternateResponses.js +102 -251
  12. package/configure/lib/design/categories/alternateResponses.js.map +1 -1
  13. package/configure/lib/design/categories/category.js +138 -208
  14. package/configure/lib/design/categories/category.js.map +1 -1
  15. package/configure/lib/design/categories/choice-preview.js +59 -126
  16. package/configure/lib/design/categories/choice-preview.js.map +1 -1
  17. package/configure/lib/design/categories/droppable-placeholder.js +76 -165
  18. package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
  19. package/configure/lib/design/categories/index.js +199 -384
  20. package/configure/lib/design/categories/index.js.map +1 -1
  21. package/configure/lib/design/choices/choice.js +160 -263
  22. package/configure/lib/design/choices/choice.js.map +1 -1
  23. package/configure/lib/design/choices/config.js +46 -98
  24. package/configure/lib/design/choices/config.js.map +1 -1
  25. package/configure/lib/design/choices/index.js +152 -236
  26. package/configure/lib/design/choices/index.js.map +1 -1
  27. package/configure/lib/design/header.js +62 -111
  28. package/configure/lib/design/header.js.map +1 -1
  29. package/configure/lib/design/index.js +632 -476
  30. package/configure/lib/design/index.js.map +1 -1
  31. package/configure/lib/design/input-header.js +97 -149
  32. package/configure/lib/design/input-header.js.map +1 -1
  33. package/configure/lib/design/utils.js +4 -15
  34. package/configure/lib/design/utils.js.map +1 -1
  35. package/configure/lib/index.js +120 -183
  36. package/configure/lib/index.js.map +1 -1
  37. package/configure/lib/main.js +31 -74
  38. package/configure/lib/main.js.map +1 -1
  39. package/configure/lib/utils.js +22 -32
  40. package/configure/lib/utils.js.map +1 -1
  41. package/configure/package.json +15 -14
  42. package/controller/CHANGELOG.md +54 -0
  43. package/controller/lib/defaults.js +2 -5
  44. package/controller/lib/defaults.js.map +1 -1
  45. package/controller/lib/index.js +238 -315
  46. package/controller/lib/index.js.map +1 -1
  47. package/controller/lib/utils.js +40 -31
  48. package/controller/lib/utils.js.map +1 -1
  49. package/controller/package.json +5 -5
  50. package/lib/categorize/categories.js +110 -164
  51. package/lib/categorize/categories.js.map +1 -1
  52. package/lib/categorize/category.js +72 -122
  53. package/lib/categorize/category.js.map +1 -1
  54. package/lib/categorize/choice.js +116 -245
  55. package/lib/categorize/choice.js.map +1 -1
  56. package/lib/categorize/choices.js +66 -131
  57. package/lib/categorize/choices.js.map +1 -1
  58. package/lib/categorize/droppable-placeholder.js +49 -103
  59. package/lib/categorize/droppable-placeholder.js.map +1 -1
  60. package/lib/categorize/grid-content.js +39 -87
  61. package/lib/categorize/grid-content.js.map +1 -1
  62. package/lib/categorize/index.js +341 -316
  63. package/lib/categorize/index.js.map +1 -1
  64. package/lib/index.js +286 -271
  65. package/lib/index.js.map +1 -1
  66. package/package.json +16 -13
  67. package/LICENSE.md +0 -5
@@ -1,144 +1,110 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.outcome = exports.normalize = exports.model = exports.getTotalScore = exports.getPartialScore = exports.getCorrectness = exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
9
8
  Object.defineProperty(exports, "score", {
10
9
  enumerable: true,
11
- get: function get() {
10
+ get: function () {
12
11
  return _categorize.score;
13
12
  }
14
13
  });
15
14
  exports.validate = void 0;
16
-
17
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
18
-
19
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
22
-
23
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
-
25
15
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
26
-
27
16
  var _categorize = require("@pie-lib/categorize");
28
-
29
17
  var _feedback = require("@pie-lib/feedback");
30
-
31
18
  var _controllerUtils = require("@pie-lib/controller-utils");
32
-
33
19
  var _translator = _interopRequireDefault(require("@pie-lib/translator"));
34
-
35
20
  var _defaults = _interopRequireDefault(require("./defaults"));
36
-
37
21
  var _utils = require("./utils");
22
+ const {
23
+ translator
24
+ } = _translator.default;
38
25
 
39
- 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; }
40
-
41
- 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; }
42
-
43
- var translator = _translator["default"].translator;
26
+ // eslint-disable-next-line no-console
44
27
 
45
- var getPartialScore = function getPartialScore(correctResponse, builtCategories) {
28
+ const getPartialScore = (correctResponse, builtCategories) => {
46
29
  // in the resulted best scenario we make a sum with all the correct responses
47
30
  // and all the placements
48
- var _builtCategories$redu = builtCategories.reduce(function (acc, _ref) {
49
- var _ref$choices = _ref.choices,
50
- choices = _ref$choices === void 0 ? [] : _ref$choices;
51
- return {
52
- placements: acc.placements + choices.length,
53
- score: acc.score + choices.filter(function (ch) {
54
- return ch.correct;
55
- }).length
56
- };
57
- }, {
31
+ const {
32
+ placements,
33
+ score
34
+ } = builtCategories.reduce((acc, {
35
+ choices = []
36
+ }) => ({
37
+ placements: acc.placements + choices.length,
38
+ score: acc.score + choices.filter(ch => ch.correct).length
39
+ }), {
58
40
  placements: 0,
59
41
  score: 0
60
- }),
61
- placements = _builtCategories$redu.placements,
62
- score = _builtCategories$redu.score; // in the correct response, we make a sum of the max possible score
63
-
42
+ });
64
43
 
65
- var _correctResponse$redu = correctResponse.reduce(function (acc, _ref2) {
66
- var choices = _ref2.choices;
67
- return {
68
- maxScore: acc.maxScore + choices.length
69
- };
70
- }, {
44
+ // in the correct response, we make a sum of the max possible score
45
+ const {
46
+ maxScore
47
+ } = correctResponse.reduce((acc, {
48
+ choices
49
+ }) => ({
50
+ maxScore: acc.maxScore + choices.length
51
+ }), {
71
52
  maxScore: 0
72
- }),
73
- maxScore = _correctResponse$redu.maxScore; // if there are any extra placements, we subtract from the obtained score
74
-
53
+ });
75
54
 
76
- var extraPlacements = placements > maxScore ? placements - maxScore : 0;
77
- var totalScore = (score - extraPlacements) / maxScore;
55
+ // if there are any extra placements, we subtract from the obtained score
56
+ const extraPlacements = placements > maxScore ? placements - maxScore : 0;
57
+ const totalScore = (score - extraPlacements) / maxScore;
78
58
  return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));
79
59
  };
80
-
81
60
  exports.getPartialScore = getPartialScore;
82
-
83
- var getAlternates = function getAlternates(correctResponse) {
84
- return correctResponse.map(function (c) {
85
- return c.alternateResponses;
86
- }).filter(function (alternate) {
87
- return alternate;
88
- });
89
- };
90
-
91
- var getTotalScore = function getTotalScore(question, session, env) {
61
+ const getAlternates = correctResponse => correctResponse.map(c => c.alternateResponses).filter(alternate => alternate);
62
+ const getTotalScore = (question, session, env) => {
92
63
  if (!session) {
93
64
  return 0;
94
65
  }
95
-
96
66
  if (Object.keys(session).length === 0) {
97
67
  return 0;
98
68
  }
99
-
100
- var _ref3 = question || {},
101
- categories = _ref3.categories,
102
- choices = _ref3.choices;
103
-
104
- var _ref4 = question || {},
105
- correctResponse = _ref4.correctResponse;
106
-
107
- var _ref5 = session || {},
108
- answers = _ref5.answers;
109
-
69
+ const {
70
+ categories,
71
+ choices
72
+ } = question || {};
73
+ let {
74
+ correctResponse
75
+ } = question || {};
76
+ let {
77
+ answers
78
+ } = session || {};
110
79
  answers = answers || [];
111
- correctResponse = correctResponse || []; // this function is used in pie-ui/categorize as well, in order to get the best scenario
112
- // so we get the best scenario and calculate the score
113
-
114
- var _buildState = (0, _categorize.buildState)(categories, choices, answers, correctResponse),
115
- builtCategories = _buildState.categories,
116
- correct = _buildState.correct;
117
-
118
- var alternates = getAlternates(correctResponse);
119
-
120
- var enabled = _controllerUtils.partialScoring.enabled(question, env); // if there are any alternates, there will be no partial scoring!
121
-
80
+ correctResponse = correctResponse || [];
122
81
 
82
+ // this function is used in pie-ui/categorize as well, in order to get the best scenario
83
+ // so we get the best scenario and calculate the score
84
+ const {
85
+ categories: builtCategories,
86
+ correct
87
+ } = (0, _categorize.buildState)(categories, choices, answers, correctResponse);
88
+ const alternates = getAlternates(correctResponse);
89
+ const enabled = _controllerUtils.partialScoring.enabled(question, env);
90
+
91
+ // if there are any alternates, there will be no partial scoring!
123
92
  if (enabled && !alternates.length) {
124
93
  // we apply partial scoring
125
94
  return getPartialScore(correctResponse, builtCategories);
126
- } // else we apply dichotomous
127
-
95
+ }
128
96
 
97
+ // else we apply dichotomous
129
98
  return correct ? 1 : 0;
130
99
  };
131
-
132
100
  exports.getTotalScore = getTotalScore;
133
-
134
- var getCorrectness = function getCorrectness(question, session, env) {
135
- return new Promise(function (resolve) {
101
+ const getCorrectness = (question, session, env) => {
102
+ return new Promise(resolve => {
136
103
  if (env.mode === 'evaluate') {
137
- var _score = getTotalScore(question, session, env);
138
-
139
- if (_score === 1) {
104
+ const score = getTotalScore(question, session, env);
105
+ if (score === 1) {
140
106
  resolve('correct');
141
- } else if (_score === 0) {
107
+ } else if (score === 0) {
142
108
  resolve('incorrect');
143
109
  } else {
144
110
  resolve('partially-correct');
@@ -148,21 +114,19 @@ var getCorrectness = function getCorrectness(question, session, env) {
148
114
  }
149
115
  });
150
116
  };
151
-
152
117
  exports.getCorrectness = getCorrectness;
153
-
154
- var createDefaultModel = function createDefaultModel() {
155
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
156
- return new Promise(function (resolve) {
157
- resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
118
+ const createDefaultModel = (model = {}) => new Promise(resolve => {
119
+ resolve({
120
+ ..._defaults.default,
121
+ ...model
158
122
  });
159
- };
160
-
123
+ });
161
124
  exports.createDefaultModel = createDefaultModel;
125
+ const normalize = question => ({
126
+ ..._defaults.default,
127
+ ...question
128
+ });
162
129
 
163
- var normalize = function normalize(question) {
164
- return _objectSpread(_objectSpread({}, _defaults["default"]), question);
165
- };
166
130
  /**
167
131
  *
168
132
  * @param {*} question
@@ -170,144 +134,129 @@ var normalize = function normalize(question) {
170
134
  * @param {*} env
171
135
  * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
172
136
  */
173
-
174
-
175
137
  exports.normalize = normalize;
176
-
177
- var model = function model(question, session, env, updateSession) {
178
- return new Promise( /*#__PURE__*/function () {
179
- var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
180
- var normalizedQuestion, answerCorrectness, _ref7, mode, role, categories, categoriesPerRow, choicesLabel, choicesPosition, correctResponse, feedback, feedbackEnabled, promptEnabled, prompt, rowLabels, rationaleEnabled, rationale, teacherInstructionsEnabled, teacherInstructions, language, maxChoicesPerCategory, extraCSSRules, minRowHeight, fontSizeFactor, autoplayAudioEnabled, completeAudioEnabled, customAudioButton, choices, note, fb, lockChoiceOrder, filteredCorrectResponse, alternates, out;
181
-
182
- return _regenerator["default"].wrap(function _callee$(_context) {
183
- while (1) {
184
- switch (_context.prev = _context.next) {
185
- case 0:
186
- normalizedQuestion = normalize(question);
187
- _context.next = 3;
188
- return getCorrectness(normalizedQuestion, session, env);
189
-
190
- case 3:
191
- answerCorrectness = _context.sent;
192
- _ref7 = env || {}, mode = _ref7.mode, role = _ref7.role;
193
- categories = normalizedQuestion.categories, categoriesPerRow = normalizedQuestion.categoriesPerRow, choicesLabel = normalizedQuestion.choicesLabel, choicesPosition = normalizedQuestion.choicesPosition, correctResponse = normalizedQuestion.correctResponse, feedback = normalizedQuestion.feedback, feedbackEnabled = normalizedQuestion.feedbackEnabled, promptEnabled = normalizedQuestion.promptEnabled, prompt = normalizedQuestion.prompt, rowLabels = normalizedQuestion.rowLabels, rationaleEnabled = normalizedQuestion.rationaleEnabled, rationale = normalizedQuestion.rationale, teacherInstructionsEnabled = normalizedQuestion.teacherInstructionsEnabled, teacherInstructions = normalizedQuestion.teacherInstructions, language = normalizedQuestion.language, maxChoicesPerCategory = normalizedQuestion.maxChoicesPerCategory, extraCSSRules = normalizedQuestion.extraCSSRules, minRowHeight = normalizedQuestion.minRowHeight, fontSizeFactor = normalizedQuestion.fontSizeFactor, autoplayAudioEnabled = normalizedQuestion.autoplayAudioEnabled, completeAudioEnabled = normalizedQuestion.completeAudioEnabled, customAudioButton = normalizedQuestion.customAudioButton;
194
- choices = normalizedQuestion.choices, note = normalizedQuestion.note;
195
- lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
196
- filteredCorrectResponse = correctResponse.map(function (response) {
197
- var filteredChoices = (response.choices || []).filter(function (choice) {
198
- return choice !== 'null';
199
- });
200
- return _objectSpread(_objectSpread({}, response), {}, {
201
- choices: filteredChoices
202
- });
203
- });
204
-
205
- if (!(mode === 'evaluate' && feedbackEnabled)) {
206
- _context.next = 13;
207
- break;
208
- }
209
-
210
- _context.next = 12;
211
- return (0, _feedback.getFeedbackForCorrectness)(answerCorrectness, feedback);
212
-
213
- case 12:
214
- fb = _context.sent;
215
-
216
- case 13:
217
- if (lockChoiceOrder) {
218
- _context.next = 17;
219
- break;
220
- }
221
-
222
- _context.next = 16;
223
- return (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'id');
224
-
225
- case 16:
226
- choices = _context.sent;
227
-
228
- case 17:
229
- if (!note) {
230
- note = translator.t('common:commonCorrectAnswerWithAlternates', {
231
- lng: language
232
- });
233
- }
234
-
235
- alternates = getAlternates(filteredCorrectResponse);
236
- out = {
237
- categories: categories || [],
238
- categoriesPerRow: categoriesPerRow || 2,
239
- maxChoicesPerCategory: maxChoicesPerCategory,
240
- correctness: answerCorrectness,
241
- choices: choices || [],
242
- choicesLabel: choicesLabel || '',
243
- choicesPosition: choicesPosition,
244
- disabled: mode !== 'gather',
245
- feedback: fb,
246
- lockChoiceOrder: lockChoiceOrder,
247
- prompt: promptEnabled ? prompt : null,
248
- rowLabels: rowLabels,
249
- note: note,
250
- env: env,
251
- showNote: alternates && alternates.length > 0,
252
- correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,
253
- language: language,
254
- extraCSSRules: extraCSSRules,
255
- fontSizeFactor: fontSizeFactor,
256
- minRowHeight: minRowHeight,
257
- autoplayAudioEnabled: autoplayAudioEnabled,
258
- completeAudioEnabled: completeAudioEnabled,
259
- customAudioButton: customAudioButton
260
- };
261
-
262
- if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
263
- out.rationale = rationaleEnabled ? rationale : null;
264
- out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
265
- } else {
266
- out.rationale = null;
267
- out.teacherInstructions = null;
268
- }
269
-
270
- resolve(out);
271
-
272
- case 22:
273
- case "end":
274
- return _context.stop();
275
- }
276
- }
277
- }, _callee);
278
- }));
279
-
280
- return function (_x) {
281
- return _ref6.apply(this, arguments);
138
+ const model = (question, session, env, updateSession) => new Promise(async resolve => {
139
+ const normalizedQuestion = normalize(question);
140
+ const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);
141
+ const {
142
+ mode,
143
+ role
144
+ } = env || {};
145
+ const {
146
+ categories,
147
+ categoriesPerRow,
148
+ choicesLabel,
149
+ choicesPosition,
150
+ correctResponse,
151
+ feedback,
152
+ feedbackEnabled,
153
+ promptEnabled,
154
+ prompt,
155
+ rowLabels,
156
+ rationaleEnabled,
157
+ rationale,
158
+ teacherInstructionsEnabled,
159
+ teacherInstructions,
160
+ language,
161
+ maxChoicesPerCategory,
162
+ extraCSSRules,
163
+ minRowHeight,
164
+ fontSizeFactor,
165
+ autoplayAudioEnabled,
166
+ completeAudioEnabled,
167
+ customAudioButton
168
+ } = normalizedQuestion;
169
+ let {
170
+ choices,
171
+ note
172
+ } = normalizedQuestion;
173
+ let fb;
174
+ const lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
175
+ const filteredCorrectResponse = correctResponse.map(response => {
176
+ const filteredChoices = (response.choices || []).filter(choice => choice !== 'null');
177
+ return {
178
+ ...response,
179
+ choices: filteredChoices
282
180
  };
283
- }());
284
- };
285
-
181
+ });
182
+ if (mode === 'evaluate' && feedbackEnabled) {
183
+ fb = await (0, _feedback.getFeedbackForCorrectness)(answerCorrectness, feedback);
184
+ }
185
+ if (!lockChoiceOrder) {
186
+ choices = await (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'id');
187
+ }
188
+ if (!note) {
189
+ note = translator.t('common:commonCorrectAnswerWithAlternates', {
190
+ lng: language
191
+ });
192
+ }
193
+ const alternates = getAlternates(filteredCorrectResponse);
194
+ const {
195
+ responseAreasToBeFilled,
196
+ possibleResponses,
197
+ hasUnplacedChoices
198
+ } = (0, _utils.getCompleteResponseDetails)(filteredCorrectResponse, normalizedQuestion.allowAlternateEnabled ? alternates : [], normalizedQuestion.choices);
199
+ const out = {
200
+ categories: categories || [],
201
+ categoriesPerRow: categoriesPerRow || 2,
202
+ maxChoicesPerCategory,
203
+ correctness: answerCorrectness,
204
+ choices: choices || [],
205
+ choicesLabel: choicesLabel || '',
206
+ choicesPosition,
207
+ disabled: mode !== 'gather',
208
+ feedback: fb,
209
+ lockChoiceOrder,
210
+ prompt: promptEnabled ? prompt : null,
211
+ rowLabels,
212
+ note,
213
+ env,
214
+ showNote: alternates && alternates.length > 0,
215
+ correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,
216
+ language,
217
+ extraCSSRules,
218
+ fontSizeFactor,
219
+ minRowHeight: minRowHeight,
220
+ autoplayAudioEnabled,
221
+ completeAudioEnabled,
222
+ customAudioButton,
223
+ possibleResponses,
224
+ responseAreasToBeFilled,
225
+ hasUnplacedChoices
226
+ };
227
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
228
+ out.rationale = rationaleEnabled ? rationale : null;
229
+ out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
230
+ } else {
231
+ out.rationale = null;
232
+ out.teacherInstructions = null;
233
+ }
234
+ resolve(out);
235
+ });
286
236
  exports.model = model;
287
-
288
- var outcome = function outcome(question, session, env) {
237
+ const outcome = (question, session, env) => {
289
238
  if (env.mode !== 'evaluate') {
290
239
  return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));
291
240
  } else {
292
- return new Promise(function (resolve) {
241
+ return new Promise(resolve => {
293
242
  resolve({
294
243
  score: getTotalScore(question, session, env),
295
- empty: !session || (0, _isEmpty["default"])(session)
244
+ empty: !session || (0, _isEmpty.default)(session)
296
245
  });
297
246
  });
298
247
  }
299
248
  };
300
-
301
249
  exports.outcome = outcome;
302
-
303
- var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
304
- return new Promise(function (resolve) {
305
- var _ref8 = env || {},
306
- mode = _ref8.mode,
307
- role = _ref8.role;
308
-
250
+ const createCorrectResponseSession = (question, env) => {
251
+ return new Promise(resolve => {
252
+ const {
253
+ mode,
254
+ role
255
+ } = env || {};
309
256
  if (mode !== 'evaluate' && role === 'instructor') {
310
- var correctResponse = question.correctResponse;
257
+ const {
258
+ correctResponse
259
+ } = question;
311
260
  resolve({
312
261
  answers: correctResponse,
313
262
  id: 1
@@ -316,151 +265,125 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
316
265
  return resolve(null);
317
266
  }
318
267
  });
319
- }; // remove all html tags
320
-
321
-
322
- exports.createCorrectResponseSession = createCorrectResponseSession;
323
-
324
- var getInnerText = function getInnerText(html) {
325
- return (html || '').replaceAll(/<[^>]*>/g, '');
326
- }; // remove all html tags except img, iframe and source tag for audio
327
-
328
-
329
- var getContent = function getContent(html) {
330
- return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
331
268
  };
332
269
 
333
- var validate = function validate() {
334
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
335
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
336
- var categories = model.categories,
337
- choices = model.choices,
338
- correctResponse = model.correctResponse,
339
- maxAnswerChoices = model.maxAnswerChoices;
340
- var _config$minChoices = config.minChoices,
341
- minChoices = _config$minChoices === void 0 ? 1 : _config$minChoices,
342
- _config$minCategories = config.minCategories,
343
- minCategories = _config$minCategories === void 0 ? 1 : _config$minCategories,
344
- _config$maxCategories = config.maxCategories,
345
- maxCategories = _config$maxCategories === void 0 ? 12 : _config$maxCategories,
346
- _config$maxLengthPerC = config.maxLengthPerChoice,
347
- maxLengthPerChoice = _config$maxLengthPerC === void 0 ? 300 : _config$maxLengthPerC,
348
- _config$maxLengthPerC2 = config.maxLengthPerCategory,
349
- maxLengthPerCategory = _config$maxLengthPerC2 === void 0 ? 150 : _config$maxLengthPerC2;
350
- var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
351
- var errors = {};
352
- var choicesErrors = {};
353
- var categoriesErrors = {};
354
- ['teacherInstructions', 'prompt', 'rationale'].forEach(function (field) {
355
- var _config$field;
356
-
357
- if ((_config$field = config[field]) !== null && _config$field !== void 0 && _config$field.required && !getContent(model[field])) {
270
+ // remove all html tags
271
+ exports.createCorrectResponseSession = createCorrectResponseSession;
272
+ const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
273
+
274
+ // remove all html tags except img, iframe and source tag for audio
275
+ const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
276
+ const validate = (model = {}, config = {}) => {
277
+ const {
278
+ categories,
279
+ choices,
280
+ correctResponse,
281
+ maxAnswerChoices
282
+ } = model;
283
+ const {
284
+ minChoices = 1,
285
+ minCategories = 1,
286
+ maxCategories = 12,
287
+ maxLengthPerChoice = 300,
288
+ maxLengthPerCategory = 150
289
+ } = config;
290
+ const reversedChoices = [...(choices || [])].reverse();
291
+ const errors = {};
292
+ const choicesErrors = {};
293
+ const categoriesErrors = {};
294
+ ['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
295
+ if (config[field]?.required && !getContent(model[field])) {
358
296
  errors[field] = 'This field is required.';
359
297
  }
360
298
  });
361
- (categories || []).forEach(function (category) {
362
- var id = category.id,
363
- label = category.label;
364
-
299
+ (categories || []).forEach(category => {
300
+ const {
301
+ id,
302
+ label
303
+ } = category;
365
304
  if (getInnerText(label).length > maxLengthPerCategory) {
366
- categoriesErrors[id] = "Category labels should be no more than ".concat(maxLengthPerCategory, " characters long.");
305
+ categoriesErrors[id] = `Category labels should be no more than ${maxLengthPerCategory} characters long.`;
367
306
  }
368
307
  });
369
- (reversedChoices || []).forEach(function (choice, index) {
370
- var id = choice.id,
371
- content = choice.content;
372
-
308
+ (reversedChoices || []).forEach((choice, index) => {
309
+ const {
310
+ id,
311
+ content
312
+ } = choice;
373
313
  if (getInnerText(content).length > maxLengthPerChoice) {
374
- choicesErrors[id] = "Tokens should be no more than ".concat(maxLengthPerChoice, " characters long.");
314
+ choicesErrors[id] = `Tokens should be no more than ${maxLengthPerChoice} characters long.`;
375
315
  }
376
-
377
316
  if (!getContent(content)) {
378
317
  choicesErrors[id] = 'Tokens should not be empty.';
379
318
  } else {
380
- var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
381
- return c.content === content;
382
- });
383
-
319
+ const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.content === content);
384
320
  if (identicalAnswer) {
385
321
  choicesErrors[id] = 'Tokens content should be unique.';
386
322
  }
387
323
  }
388
324
  });
389
- var nbOfCategories = (categories || []).length;
390
- var nbOfChoices = (choices || []).length;
391
-
325
+ const nbOfCategories = (categories || []).length;
326
+ const nbOfChoices = (choices || []).length;
392
327
  if (nbOfCategories > maxCategories) {
393
- errors.categoriesError = "No more than ".concat(maxCategories, " categories should be defined.");
328
+ errors.categoriesError = `No more than ${maxCategories} categories should be defined.`;
394
329
  } else if (nbOfCategories < minCategories) {
395
- errors.categoriesError = "There should be at least ".concat(minCategories, " category defined.");
330
+ errors.categoriesError = `There should be at least ${minCategories} category defined.`;
396
331
  }
397
-
398
332
  if (nbOfChoices < minChoices) {
399
- errors.choicesError = "There should be at least ".concat(minChoices, " choices defined.");
333
+ errors.choicesError = `There should be at least ${minChoices} choices defined.`;
400
334
  } else if (nbOfChoices > maxAnswerChoices) {
401
- errors.choicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
335
+ errors.choicesError = `No more than ${maxAnswerChoices} choices should be defined.`;
402
336
  }
403
-
404
337
  if (nbOfChoices && nbOfCategories) {
405
- var hasAssociations = false;
406
- (correctResponse || []).forEach(function (response) {
407
- var _response$choices = response.choices,
408
- choices = _response$choices === void 0 ? [] : _response$choices,
409
- _response$alternateRe = response.alternateResponses,
410
- alternateResponses = _response$alternateRe === void 0 ? [] : _response$alternateRe;
411
-
338
+ let hasAssociations = false;
339
+ (correctResponse || []).forEach(response => {
340
+ const {
341
+ choices = [],
342
+ alternateResponses = []
343
+ } = response;
412
344
  if (choices.length) {
413
345
  hasAssociations = true;
414
346
  } else {
415
- alternateResponses.forEach(function (alternate) {
347
+ alternateResponses.forEach(alternate => {
416
348
  if ((alternate || []).length) {
417
349
  hasAssociations = true;
418
350
  }
419
351
  });
420
352
  }
421
353
  });
422
- var duplicateAlternateIndex = -1;
423
- var duplicateCategory = '';
424
- (correctResponse || []).forEach(function (response) {
425
- var _response$choices2 = response.choices,
426
- choices = _response$choices2 === void 0 ? [] : _response$choices2,
427
- _response$alternateRe2 = response.alternateResponses,
428
- alternateResponses = _response$alternateRe2 === void 0 ? [] : _response$alternateRe2,
429
- category = response.category;
430
-
354
+ let duplicateAlternateIndex = -1;
355
+ let duplicateCategory = '';
356
+ (correctResponse || []).forEach(response => {
357
+ const {
358
+ choices = [],
359
+ alternateResponses = [],
360
+ category
361
+ } = response;
431
362
  if (duplicateAlternateIndex === -1) {
432
363
  duplicateAlternateIndex = (0, _utils.isCorrectResponseDuplicated)(choices, alternateResponses);
433
-
434
364
  if (duplicateAlternateIndex === -1) {
435
365
  duplicateAlternateIndex = (0, _utils.isAlternateDuplicated)(alternateResponses);
436
366
  }
437
-
438
367
  duplicateCategory = category;
439
368
  }
440
369
  });
441
-
442
370
  if (duplicateAlternateIndex > -1) {
443
371
  errors.duplicateAlternate = {
444
372
  index: duplicateAlternateIndex,
445
373
  category: duplicateCategory
446
374
  };
447
375
  }
448
-
449
376
  if (!hasAssociations) {
450
377
  errors.associationError = 'At least one token should be assigned to at least one category.';
451
378
  }
452
379
  }
453
-
454
- if (!(0, _isEmpty["default"])(choicesErrors)) {
380
+ if (!(0, _isEmpty.default)(choicesErrors)) {
455
381
  errors.choicesErrors = choicesErrors;
456
382
  }
457
-
458
- if (!(0, _isEmpty["default"])(categoriesErrors)) {
383
+ if (!(0, _isEmpty.default)(categoriesErrors)) {
459
384
  errors.categoriesErrors = categoriesErrors;
460
385
  }
461
-
462
386
  return errors;
463
387
  };
464
-
465
388
  exports.validate = validate;
466
389
  //# sourceMappingURL=index.js.map