@pie-element/explicit-constructed-response 9.3.4-next.0 → 10.0.0-beta.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 (38) hide show
  1. package/configure/lib/alternateResponses.js +139 -184
  2. package/configure/lib/alternateResponses.js.map +1 -1
  3. package/configure/lib/alternateSection.js +272 -369
  4. package/configure/lib/alternateSection.js.map +1 -1
  5. package/configure/lib/defaults.js +2 -3
  6. package/configure/lib/defaults.js.map +1 -1
  7. package/configure/lib/ecr-toolbar.js +124 -186
  8. package/configure/lib/ecr-toolbar.js.map +1 -1
  9. package/configure/lib/index.js +126 -203
  10. package/configure/lib/index.js.map +1 -1
  11. package/configure/lib/main.js +434 -550
  12. package/configure/lib/main.js.map +1 -1
  13. package/configure/lib/markupUtils.js +26 -49
  14. package/configure/lib/markupUtils.js.map +1 -1
  15. package/configure/lib/utils.js +5 -5
  16. package/configure/lib/utils.js.map +1 -1
  17. package/configure/package.json +9 -7
  18. package/controller/lib/defaults.js +2 -3
  19. package/controller/lib/defaults.js.map +1 -1
  20. package/controller/lib/index.js +169 -260
  21. package/controller/lib/index.js.map +1 -1
  22. package/controller/package.json +3 -3
  23. package/lib/index.js +71 -115
  24. package/lib/index.js.map +1 -1
  25. package/lib/main.js +174 -248
  26. package/lib/main.js.map +1 -1
  27. package/lib/print.js +39 -83
  28. package/lib/print.js.map +1 -1
  29. package/package.json +14 -15
  30. package/module/configure.js +0 -1
  31. package/module/controller.js +0 -7460
  32. package/module/demo.js +0 -45
  33. package/module/element.js +0 -1
  34. package/module/index.html +0 -21
  35. package/module/manifest.json +0 -22
  36. package/module/print-demo.js +0 -83
  37. package/module/print.html +0 -18
  38. package/module/print.js +0 -1
@@ -1,7 +1,6 @@
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
  });
@@ -10,248 +9,181 @@ exports.model = model;
10
9
  exports.normalize = void 0;
11
10
  exports.outcome = outcome;
12
11
  exports.validate = exports.prepareVal = exports.prepareChoice = void 0;
13
-
14
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
15
-
16
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
-
18
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
19
-
20
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
21
-
22
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
-
24
12
  var _debug = _interopRequireDefault(require("debug"));
25
-
26
13
  var _map = _interopRequireDefault(require("lodash/map"));
27
-
28
14
  var _reduce = _interopRequireDefault(require("lodash/reduce"));
29
-
30
15
  var _find = _interopRequireDefault(require("lodash/find"));
31
-
32
16
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
33
-
34
17
  var _he = require("he");
35
-
36
18
  var _controllerUtils = require("@pie-lib/controller-utils");
37
-
38
19
  var _translator = _interopRequireDefault(require("@pie-lib/translator"));
39
-
40
20
  var _defaults = _interopRequireDefault(require("./defaults"));
41
-
42
- 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; }
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"])('explicit-constructed-response:controller');
48
-
49
- var prepareChoice = function prepareChoice(mode, defaultFeedback) {
50
- return function (choice) {
51
- var out = {
52
- label: choice.label,
53
- value: choice.value
54
- };
55
-
56
- if (mode === 'evaluate') {
57
- out.correct = true;
58
- var feedbackType = choice.feedback && choice.feedback.type || 'none';
59
-
60
- if (feedbackType === 'default') {
61
- out.feedback = defaultFeedback['correct'];
62
- } else if (feedbackType === 'custom') {
63
- out.feedback = choice.feedback.value;
64
- }
65
- }
66
-
67
- return out;
21
+ const {
22
+ translator
23
+ } = _translator.default;
24
+ const log = (0, _debug.default)('explicit-constructed-response:controller');
25
+ const prepareChoice = (mode, defaultFeedback) => choice => {
26
+ const out = {
27
+ label: choice.label,
28
+ value: choice.value
68
29
  };
30
+ if (mode === 'evaluate') {
31
+ out.correct = true;
32
+ const feedbackType = choice.feedback && choice.feedback.type || 'none';
33
+ if (feedbackType === 'default') {
34
+ out.feedback = defaultFeedback['correct'];
35
+ } else if (feedbackType === 'custom') {
36
+ out.feedback = choice.feedback.value;
37
+ }
38
+ }
39
+ return out;
69
40
  };
70
-
71
41
  exports.prepareChoice = prepareChoice;
72
-
73
- var getFeedback = function getFeedback(value) {
42
+ const getFeedback = value => {
74
43
  if (value) {
75
44
  return 'correct';
76
45
  }
77
-
78
46
  return 'incorrect';
79
- }; // also used in configure/src/markupUtils.js
80
-
47
+ };
81
48
 
82
- var getAdjustedLength = function getAdjustedLength(length) {
49
+ // also used in configure/src/markupUtils.js
50
+ const getAdjustedLength = length => {
83
51
  if (length <= 2) {
84
52
  return length + 2;
85
53
  }
86
-
87
54
  if (length <= 4) {
88
55
  return length + 3;
89
56
  }
90
-
91
57
  if (length <= 6) {
92
58
  return length + 4;
93
59
  }
94
-
95
60
  return length + 5;
96
- }; // we can't use the dom parser here because it is not available in the node environment
97
-
61
+ };
98
62
 
99
- var decodeHtmlEntities = function decodeHtmlEntities(str) {
63
+ // we can't use the dom parser here because it is not available in the node environment
64
+ const decodeHtmlEntities = str => {
100
65
  if (!str) return '';
101
66
  return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#x27;|&#39;/g, '\'').replace(/&amp;/g, '&');
102
67
  };
68
+ const normalize = question => ({
69
+ ..._defaults.default,
70
+ ...question
71
+ });
103
72
 
104
- var normalize = function normalize(question) {
105
- return _objectSpread(_objectSpread({}, _defaults["default"]), question);
106
- };
107
73
  /**
108
74
  *
109
75
  * @param {*} question
110
76
  * @param {*} session
111
77
  * @param {*} env
112
78
  */
113
-
114
-
115
79
  exports.normalize = normalize;
116
-
117
- function model(question, session, env) {
118
- return new Promise( /*#__PURE__*/function () {
119
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
120
- var normalizedQuestion, defaultFeedback, prepareChoiceFn, choices, _ref2, _ref2$value, value, feedback, showNote, note, _normalizedQuestion$m, maxLengthPerChoice, maxLengthPerChoiceEnabled, undefinedLengths, out;
121
-
122
- return _regenerator["default"].wrap(function _callee$(_context) {
123
- while (1) {
124
- switch (_context.prev = _context.next) {
125
- case 0:
126
- // this was added to treat an exception, when the model has choices without
127
- // the "value" property like: { label: 'test' }
128
- if (question.choices) {
129
- Object.keys(question.choices).forEach(function (key) {
130
- question.choices[key] = (question.choices[key] || []).map(function (item, index) {
131
- if (!item.value) {
132
- log('Choice does not contain "value" property, which is required.', item);
133
- return _objectSpread({
134
- value: "".concat(index)
135
- }, item);
136
- }
137
-
138
- return item;
139
- });
140
- });
141
- }
142
-
143
- normalizedQuestion = normalize(question);
144
- defaultFeedback = Object.assign({
145
- correct: 'Correct',
146
- incorrect: 'Incorrect'
147
- }, normalizedQuestion.defaultFeedback);
148
- prepareChoiceFn = prepareChoice(env.mode, defaultFeedback);
149
- choices = (0, _reduce["default"])(normalizedQuestion.choices, function (obj, area, key) {
150
- obj[key] = (0, _map["default"])(area, prepareChoiceFn);
151
- return obj;
152
- }, {});
153
- _ref2 = session || {}, _ref2$value = _ref2.value, value = _ref2$value === void 0 ? {} : _ref2$value;
154
- feedback = env.mode === 'evaluate' ? (0, _reduce["default"])(normalizedQuestion.choices, function (obj, respArea, key) {
155
- var chosenValue = value && value[key];
156
- var val = !(0, _isEmpty["default"])(chosenValue) && (0, _find["default"])(respArea, function (c) {
157
- return prepareVal(c.label) === prepareVal(chosenValue);
158
- });
159
- obj[key] = getFeedback(val);
160
- return obj;
161
- }, {}) : {}; // check if at least one choice has an alternate
162
-
163
- showNote = Object.values(choices).some(function (choice) {
164
- return (choice === null || choice === void 0 ? void 0 : choice.length) > 1;
165
- });
166
- note = normalizedQuestion.note || translator.t('common:commonCorrectAnswerWithAlternates', {
167
- lng: normalizedQuestion.language
168
- });
169
- _normalizedQuestion$m = normalizedQuestion.maxLengthPerChoice, maxLengthPerChoice = _normalizedQuestion$m === void 0 ? [] : _normalizedQuestion$m, maxLengthPerChoiceEnabled = normalizedQuestion.maxLengthPerChoiceEnabled;
170
- undefinedLengths = !maxLengthPerChoice.length; // calculate maxLengthPerChoice array if it is not defined or defined incorrectly
171
-
172
- Object.values(choices).forEach(function (choice, index) {
173
- var labelLengthsArr = (choice || []).map(function (choice) {
174
- return decodeHtmlEntities(choice.label || '').length;
175
- });
176
- var length = Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
177
-
178
- if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length || maxLengthPerChoice[index] > length + 10) {
179
- maxLengthPerChoice[index] = getAdjustedLength(length);
180
- }
181
- });
182
- out = {
183
- choices: choices,
184
- disabled: env.mode !== 'gather',
185
- displayType: normalizedQuestion.displayType,
186
- mode: env.mode,
187
- role: env.role,
188
- feedback: feedback,
189
- language: normalizedQuestion.language,
190
- markup: normalizedQuestion.markup,
191
- maxLengthPerChoice: maxLengthPerChoice,
192
- maxLengthPerChoiceEnabled: maxLengthPerChoiceEnabled,
193
- note: note,
194
- playerSpellCheckEnabled: normalizedQuestion.playerSpellCheckEnabled,
195
- prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : _defaults["default"].prompt,
196
- rationale: _defaults["default"].rationale,
197
- responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,
198
- showNote: showNote,
199
- teacherInstructions: _defaults["default"].teacherInstructions,
200
- responseAreaInputConfiguration: normalizedQuestion.responseAreaInputConfiguration,
201
- extraCSSRules: normalizedQuestion.extraCSSRules
202
- };
203
-
204
- if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
205
- out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : _defaults["default"].rationale;
206
- out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : _defaults["default"].teacherInstructions;
207
- }
208
-
209
- resolve(out);
210
-
211
- case 15:
212
- case "end":
213
- return _context.stop();
214
- }
80
+ async function model(question, session, env) {
81
+ // this was added to treat an exception, when the model has choices without
82
+ // the "value" property like: { label: 'test' }
83
+ if (question.choices) {
84
+ Object.keys(question.choices).forEach(key => {
85
+ question.choices[key] = (question.choices[key] || []).map((item, index) => {
86
+ if (!item.value) {
87
+ log('Choice does not contain "value" property, which is required.', item);
88
+ return {
89
+ value: `${index}`,
90
+ ...item
91
+ };
215
92
  }
216
- }, _callee);
217
- }));
218
-
219
- return function (_x) {
220
- return _ref.apply(this, arguments);
221
- };
222
- }());
93
+ return item;
94
+ });
95
+ });
96
+ }
97
+ const normalizedQuestion = normalize(question);
98
+ const defaultFeedback = Object.assign({
99
+ correct: 'Correct',
100
+ incorrect: 'Incorrect'
101
+ }, normalizedQuestion.defaultFeedback);
102
+ const prepareChoiceFn = prepareChoice(env.mode, defaultFeedback);
103
+ const choices = (0, _reduce.default)(normalizedQuestion.choices, (obj, area, key) => {
104
+ obj[key] = (0, _map.default)(area, prepareChoiceFn);
105
+ return obj;
106
+ }, {});
107
+ const {
108
+ value = {}
109
+ } = session || {};
110
+ const feedback = env.mode === 'evaluate' ? (0, _reduce.default)(normalizedQuestion.choices, (obj, respArea, key) => {
111
+ const chosenValue = value && value[key];
112
+ const val = !(0, _isEmpty.default)(chosenValue) && (0, _find.default)(respArea, c => prepareVal(c.label) === prepareVal(chosenValue));
113
+ obj[key] = getFeedback(val);
114
+ return obj;
115
+ }, {}) : {};
116
+
117
+ // check if at least one choice has an alternate
118
+ const showNote = Object.values(choices).some(choice => choice?.length > 1);
119
+ const note = normalizedQuestion.note || translator.t('common:commonCorrectAnswerWithAlternates', {
120
+ lng: normalizedQuestion.language
121
+ });
122
+ const {
123
+ maxLengthPerChoice = [],
124
+ maxLengthPerChoiceEnabled
125
+ } = normalizedQuestion;
126
+ const undefinedLengths = !maxLengthPerChoice.length;
127
+
128
+ // calculate maxLengthPerChoice array if it is not defined or defined incorrectly
129
+ Object.values(choices).forEach((choice, index) => {
130
+ const labelLengthsArr = (choice || []).map(choice => decodeHtmlEntities(choice.label || '').length);
131
+ const length = Math.max(...labelLengthsArr);
132
+ if (undefinedLengths || !maxLengthPerChoice[index] || maxLengthPerChoice[index] < length || maxLengthPerChoice[index] > length + 10) {
133
+ maxLengthPerChoice[index] = getAdjustedLength(length);
134
+ }
135
+ });
136
+ const out = {
137
+ choices,
138
+ disabled: env.mode !== 'gather',
139
+ displayType: normalizedQuestion.displayType,
140
+ mode: env.mode,
141
+ role: env.role,
142
+ feedback,
143
+ language: normalizedQuestion.language,
144
+ markup: normalizedQuestion.markup,
145
+ maxLengthPerChoice,
146
+ maxLengthPerChoiceEnabled,
147
+ note,
148
+ playerSpellCheckEnabled: normalizedQuestion.playerSpellCheckEnabled,
149
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : _defaults.default.prompt,
150
+ rationale: _defaults.default.rationale,
151
+ responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,
152
+ showNote,
153
+ teacherInstructions: _defaults.default.teacherInstructions,
154
+ responseAreaInputConfiguration: normalizedQuestion.responseAreaInputConfiguration,
155
+ extraCSSRules: normalizedQuestion.extraCSSRules
156
+ };
157
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
158
+ out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : _defaults.default.rationale;
159
+ out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : _defaults.default.teacherInstructions;
160
+ }
161
+ return out;
223
162
  }
224
-
225
- var prepareVal = function prepareVal(html) {
163
+ const prepareVal = html => {
226
164
  return decodeHTML(getInnerText(html).trim());
227
165
  };
228
-
229
166
  exports.prepareVal = prepareVal;
230
-
231
- var getScore = function getScore(config, session) {
232
- var _ref3 = session || {},
233
- value = _ref3.value;
234
-
235
- if (!session || (0, _isEmpty["default"])(session) || !value) {
167
+ const getScore = (config, session) => {
168
+ const {
169
+ value
170
+ } = session || {};
171
+ if (!session || (0, _isEmpty.default)(session) || !value) {
236
172
  return 0;
237
173
  }
238
-
239
- var responseAreas = config.markup && config.markup.match(/\{\{(.+?)\}\}/g);
240
- var maxScore = responseAreas ? responseAreas.length : 0;
241
- var correctCount = (0, _reduce["default"])(config.choices, function (total, respArea, key) {
242
- var chosenValue = value && value[key];
243
-
244
- if ((0, _isEmpty["default"])(chosenValue) || !(0, _find["default"])(respArea, function (c) {
245
- return prepareVal(c.label) === prepareVal(chosenValue);
246
- })) {
174
+ const responseAreas = config.markup && config.markup.match(/\{\{(.+?)\}\}/g);
175
+ const maxScore = responseAreas ? responseAreas.length : 0;
176
+ const correctCount = (0, _reduce.default)(config.choices, (total, respArea, key) => {
177
+ const chosenValue = value && value[key];
178
+ if ((0, _isEmpty.default)(chosenValue) || !(0, _find.default)(respArea, c => prepareVal(c.label) === prepareVal(chosenValue))) {
247
179
  return total;
248
180
  }
249
-
250
181
  return total + 1;
251
182
  }, 0);
252
- var str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;
183
+ const str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;
253
184
  return parseFloat(str);
254
185
  };
186
+
255
187
  /**
256
188
  * The score is partial by default for checkbox mode, allOrNothing for radio mode.
257
189
  * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =
@@ -263,50 +195,44 @@ var getScore = function getScore(config, session) {
263
195
  * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides
264
196
  * `model.partialScoring`.
265
197
  */
266
-
267
-
268
198
  exports.getScore = getScore;
269
-
270
- function outcome(model, session) {
271
- var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
272
- return new Promise(function (resolve) {
273
- var partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
274
-
275
- var score = getScore(model, session);
199
+ function outcome(model, session, env = {}) {
200
+ return new Promise(resolve => {
201
+ const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
202
+ const score = getScore(model, session);
276
203
  resolve({
277
204
  score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
278
- empty: (0, _isEmpty["default"])(session)
205
+ empty: (0, _isEmpty.default)(session)
279
206
  });
280
207
  });
281
208
  }
282
-
283
- var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
284
- return new Promise(function (resolve) {
209
+ const createCorrectResponseSession = (question, env) => {
210
+ return new Promise(resolve => {
285
211
  if (env.mode !== 'evaluate' && env.role === 'instructor') {
286
- var choices = question.choices;
287
- var value = {};
288
- Object.keys(choices).forEach(function (key, i) {
212
+ const {
213
+ choices
214
+ } = question;
215
+ const value = {};
216
+ Object.keys(choices).forEach((key, i) => {
289
217
  value[i] = choices[key][0].label;
290
218
  });
291
219
  resolve({
292
220
  id: '1',
293
- value: value
221
+ value
294
222
  });
295
223
  } else {
296
224
  resolve(null);
297
225
  }
298
226
  });
299
- }; // remove all html tags
300
- // const getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');
301
-
227
+ };
302
228
 
229
+ // remove all html tags
230
+ // const getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');
303
231
  exports.createCorrectResponseSession = createCorrectResponseSession;
304
-
305
- var getInnerText = function getInnerText(html) {
232
+ const getInnerText = html => {
306
233
  if (typeof html !== 'string') {
307
234
  return '';
308
235
  }
309
-
310
236
  if (typeof html.replaceAll === 'function') {
311
237
  return html.replaceAll(/<[^>]*>/g, '');
312
238
  } else {
@@ -314,73 +240,56 @@ var getInnerText = function getInnerText(html) {
314
240
  return html.replace(/<[^>]*>/g, '');
315
241
  }
316
242
  };
317
-
318
- var decodeHTML = function decodeHTML(html) {
319
- return (0, _he.decode)(html);
320
- }; // remove all html tags except img, iframe and source tag for audio
321
-
322
-
323
- var getContent = function getContent(html) {
324
- return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
325
- };
326
-
327
- var validate = function validate() {
328
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
329
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
330
- var choices = model.choices,
331
- markup = model.markup;
332
- var maxResponseAreas = config.maxResponseAreas;
333
- var allChoicesErrors = {};
334
- var errors = {};
335
- ['teacherInstructions', 'prompt', 'rationale'].forEach(function (field) {
336
- var _config$field;
337
-
338
- if ((_config$field = config[field]) !== null && _config$field !== void 0 && _config$field.required && !getContent(model[field])) {
243
+ const decodeHTML = html => (0, _he.decode)(html);
244
+
245
+ // remove all html tags except img, iframe and source tag for audio
246
+ const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
247
+ const validate = (model = {}, config = {}) => {
248
+ const {
249
+ choices,
250
+ markup
251
+ } = model;
252
+ const {
253
+ maxResponseAreas
254
+ } = config;
255
+ const allChoicesErrors = {};
256
+ const errors = {};
257
+ ['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
258
+ if (config[field]?.required && !getContent(model[field])) {
339
259
  errors[field] = 'This field is required.';
340
260
  }
341
261
  });
342
- Object.entries(choices || {}).forEach(function (_ref4) {
343
- var _ref5 = (0, _slicedToArray2["default"])(_ref4, 2),
344
- key = _ref5[0],
345
- values = _ref5[1];
346
-
347
- var reversedChoices = (0, _toConsumableArray2["default"])(values || []).reverse();
348
- var choicesErrors = {};
349
- reversedChoices.forEach(function (choice, index) {
350
- var value = choice.value,
351
- label = choice.label;
352
-
262
+ Object.entries(choices || {}).forEach(([key, values]) => {
263
+ const reversedChoices = [...(values || [])].reverse();
264
+ const choicesErrors = {};
265
+ reversedChoices.forEach((choice, index) => {
266
+ const {
267
+ value,
268
+ label
269
+ } = choice;
353
270
  if (label === '' || label === '<div></div>') {
354
271
  choicesErrors[value] = 'Content should not be empty.';
355
272
  } else {
356
- var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
357
- return c.label === label;
358
- });
359
-
273
+ const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);
360
274
  if (identicalAnswer) {
361
275
  choicesErrors[value] = 'Content should be unique.';
362
276
  }
363
277
  }
364
278
  });
365
-
366
- if (!(0, _isEmpty["default"])(choicesErrors)) {
279
+ if (!(0, _isEmpty.default)(choicesErrors)) {
367
280
  allChoicesErrors[key] = choicesErrors;
368
281
  }
369
282
  });
370
- var nbOfResponseAreas = (markup.match(/\{\{(\d+)\}\}/g) || []).length;
371
-
283
+ const nbOfResponseAreas = (markup.match(/\{\{(\d+)\}\}/g) || []).length;
372
284
  if (nbOfResponseAreas > maxResponseAreas) {
373
- errors.responseAreas = "No more than ".concat(maxResponseAreas, " response areas should be defined.");
285
+ errors.responseAreas = `No more than ${maxResponseAreas} response areas should be defined.`;
374
286
  } else if (nbOfResponseAreas < 1) {
375
287
  errors.responseAreas = 'There should be at least 1 response area defined.';
376
288
  }
377
-
378
- if (!(0, _isEmpty["default"])(allChoicesErrors)) {
289
+ if (!(0, _isEmpty.default)(allChoicesErrors)) {
379
290
  errors.choices = allChoicesErrors;
380
291
  }
381
-
382
292
  return errors;
383
293
  };
384
-
385
294
  exports.validate = validate;
386
295
  //# sourceMappingURL=index.js.map