@pie-element/categorize 6.9.9 → 6.9.10-beta.1445

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 (71) hide show
  1. package/CHANGELOG.md +394 -0
  2. package/configure/CHANGELOG.md +377 -0
  3. package/configure/lib/defaults.js +50 -3
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/design/builder.js +8 -5
  6. package/configure/lib/design/builder.js.map +1 -1
  7. package/configure/lib/design/buttons.js +5 -3
  8. package/configure/lib/design/buttons.js.map +1 -1
  9. package/configure/lib/design/categories/RowLabel.js +68 -0
  10. package/configure/lib/design/categories/RowLabel.js.map +1 -0
  11. package/configure/lib/design/categories/alternateResponses.js +121 -17
  12. package/configure/lib/design/categories/alternateResponses.js.map +1 -1
  13. package/configure/lib/design/categories/category.js +50 -6
  14. package/configure/lib/design/categories/category.js.map +1 -1
  15. package/configure/lib/design/categories/choice-preview.js +17 -4
  16. package/configure/lib/design/categories/choice-preview.js.map +1 -1
  17. package/configure/lib/design/categories/droppable-placeholder.js +23 -3
  18. package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
  19. package/configure/lib/design/categories/index.js +165 -72
  20. package/configure/lib/design/categories/index.js.map +1 -1
  21. package/configure/lib/design/choices/choice.js +80 -13
  22. package/configure/lib/design/choices/choice.js.map +1 -1
  23. package/configure/lib/design/choices/config.js +8 -113
  24. package/configure/lib/design/choices/config.js.map +1 -1
  25. package/configure/lib/design/choices/index.js +83 -10
  26. package/configure/lib/design/choices/index.js.map +1 -1
  27. package/configure/lib/design/header.js +17 -5
  28. package/configure/lib/design/header.js.map +1 -1
  29. package/configure/lib/design/index.js +158 -61
  30. package/configure/lib/design/index.js.map +1 -1
  31. package/configure/lib/design/input-header.js +57 -11
  32. package/configure/lib/design/input-header.js.map +1 -1
  33. package/configure/lib/index.js +17 -3
  34. package/configure/lib/index.js.map +1 -1
  35. package/configure/lib/main.js +3 -1
  36. package/configure/lib/main.js.map +1 -1
  37. package/configure/lib/utils.js +27 -0
  38. package/configure/lib/utils.js.map +1 -0
  39. package/configure/package.json +9 -9
  40. package/controller/CHANGELOG.md +89 -0
  41. package/controller/lib/defaults.js +18 -0
  42. package/controller/lib/defaults.js.map +1 -1
  43. package/controller/lib/index.js +160 -24
  44. package/controller/lib/index.js.map +1 -1
  45. package/controller/lib/utils.js +60 -0
  46. package/controller/lib/utils.js.map +1 -0
  47. package/controller/package.json +4 -4
  48. package/docs/config-schema.json +181 -0
  49. package/docs/config-schema.json.md +141 -1
  50. package/docs/demo/config.js +2 -2
  51. package/docs/demo/generate.js +3 -3
  52. package/docs/demo/index.html +1 -1
  53. package/docs/pie-schema.json +48 -5
  54. package/docs/pie-schema.json.md +36 -5
  55. package/lib/categorize/categories.js +14 -4
  56. package/lib/categorize/categories.js.map +1 -1
  57. package/lib/categorize/category.js +3 -3
  58. package/lib/categorize/category.js.map +1 -1
  59. package/lib/categorize/choice.js +3 -3
  60. package/lib/categorize/choice.js.map +1 -1
  61. package/lib/categorize/choices.js +16 -7
  62. package/lib/categorize/choices.js.map +1 -1
  63. package/lib/categorize/droppable-placeholder.js +5 -3
  64. package/lib/categorize/droppable-placeholder.js.map +1 -1
  65. package/lib/categorize/grid-content.js +2 -2
  66. package/lib/categorize/grid-content.js.map +1 -1
  67. package/lib/categorize/index.js +36 -17
  68. package/lib/categorize/index.js.map +1 -1
  69. package/lib/index.js +3 -0
  70. package/lib/index.js.map +1 -1
  71. package/package.json +9 -8
@@ -5,16 +5,19 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.outcome = exports.normalize = exports.model = exports.getTotalScore = exports.getPartialScore = exports.getCorrectness = exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
8
9
  Object.defineProperty(exports, "score", {
9
10
  enumerable: true,
10
11
  get: function get() {
11
12
  return _categorize.score;
12
13
  }
13
14
  });
14
- exports.createCorrectResponseSession = exports.outcome = exports.model = exports.normalize = exports.createDefaultModel = exports.getCorrectness = exports.getTotalScore = exports.getPartialScore = void 0;
15
+ exports.validate = void 0;
15
16
 
16
17
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
17
18
 
19
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
+
18
21
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
19
22
 
20
23
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -25,13 +28,15 @@ var _categorize = require("@pie-lib/categorize");
25
28
 
26
29
  var _feedback = require("@pie-lib/feedback");
27
30
 
31
+ var _utils = require("./utils");
32
+
28
33
  var _controllerUtils = require("@pie-lib/controller-utils");
29
34
 
30
35
  var _defaults = _interopRequireDefault(require("./defaults"));
31
36
 
32
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
37
+ 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; }
33
38
 
34
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
39
+ 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; }
35
40
 
36
41
  var getPartialScore = function getPartialScore(correctResponse, builtCategories) {
37
42
  // in the resulted best scenario we make a sum with all the correct responses
@@ -152,13 +157,7 @@ var createDefaultModel = function createDefaultModel() {
152
157
  exports.createDefaultModel = createDefaultModel;
153
158
 
154
159
  var normalize = function normalize(question) {
155
- return _objectSpread({
156
- feedbackEnabled: true,
157
- rationaleEnabled: true,
158
- promptEnabled: true,
159
- teacherInstructionsEnabled: true,
160
- studentInstructionsEnabled: true
161
- }, question);
160
+ return _objectSpread(_objectSpread({}, _defaults["default"]), question);
162
161
  };
163
162
  /**
164
163
  *
@@ -174,7 +173,7 @@ exports.normalize = normalize;
174
173
  var model = function model(question, session, env, updateSession) {
175
174
  return new Promise( /*#__PURE__*/function () {
176
175
  var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
177
- var normalizedQuestion, answerCorrectness, _ref7, mode, role, categories, categoriesPerRow, choicesLabel, choicesPosition, correctResponse, feedback, feedbackEnabled, promptEnabled, prompt, removeTilesAfterPlacing, rowLabels, rationaleEnabled, rationale, note, teacherInstructionsEnabled, teacherInstructions, choices, fb, lockChoiceOrder, alternates, out;
176
+ var normalizedQuestion, answerCorrectness, _ref7, mode, role, categories, categoriesPerRow, choicesLabel, choicesPosition, correctResponse, feedback, feedbackEnabled, promptEnabled, prompt, rowLabels, rationaleEnabled, rationale, note, teacherInstructionsEnabled, teacherInstructions, choices, fb, lockChoiceOrder, filteredCorrectResponse, alternates, out;
178
177
 
179
178
  return _regenerator["default"].wrap(function _callee$(_context) {
180
179
  while (1) {
@@ -187,35 +186,43 @@ var model = function model(question, session, env, updateSession) {
187
186
  case 3:
188
187
  answerCorrectness = _context.sent;
189
188
  _ref7 = env || {}, mode = _ref7.mode, role = _ref7.role;
190
- 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, removeTilesAfterPlacing = normalizedQuestion.removeTilesAfterPlacing, rowLabels = normalizedQuestion.rowLabels, rationaleEnabled = normalizedQuestion.rationaleEnabled, rationale = normalizedQuestion.rationale, note = normalizedQuestion.note, teacherInstructionsEnabled = normalizedQuestion.teacherInstructionsEnabled, teacherInstructions = normalizedQuestion.teacherInstructions;
189
+ 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, note = normalizedQuestion.note, teacherInstructionsEnabled = normalizedQuestion.teacherInstructionsEnabled, teacherInstructions = normalizedQuestion.teacherInstructions;
191
190
  choices = normalizedQuestion.choices;
192
191
  lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
192
+ filteredCorrectResponse = correctResponse.map(function (response) {
193
+ var filteredChoices = (response.choices || []).filter(function (choice) {
194
+ return choice !== 'null';
195
+ });
196
+ return _objectSpread(_objectSpread({}, response), {}, {
197
+ choices: filteredChoices
198
+ });
199
+ });
193
200
 
194
201
  if (!(mode === 'evaluate' && feedbackEnabled)) {
195
- _context.next = 12;
202
+ _context.next = 13;
196
203
  break;
197
204
  }
198
205
 
199
- _context.next = 11;
206
+ _context.next = 12;
200
207
  return (0, _feedback.getFeedbackForCorrectness)(answerCorrectness, feedback);
201
208
 
202
- case 11:
209
+ case 12:
203
210
  fb = _context.sent;
204
211
 
205
- case 12:
212
+ case 13:
206
213
  if (lockChoiceOrder) {
207
- _context.next = 16;
214
+ _context.next = 17;
208
215
  break;
209
216
  }
210
217
 
211
- _context.next = 15;
218
+ _context.next = 16;
212
219
  return (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'id');
213
220
 
214
- case 15:
221
+ case 16:
215
222
  choices = _context.sent;
216
223
 
217
- case 16:
218
- alternates = getAlternates(correctResponse);
224
+ case 17:
225
+ alternates = getAlternates(filteredCorrectResponse);
219
226
  out = {
220
227
  categories: categories || [],
221
228
  categoriesPerRow: categoriesPerRow || 2,
@@ -227,12 +234,11 @@ var model = function model(question, session, env, updateSession) {
227
234
  feedback: fb,
228
235
  lockChoiceOrder: lockChoiceOrder,
229
236
  prompt: promptEnabled ? prompt : null,
230
- removeTilesAfterPlacing: removeTilesAfterPlacing,
231
237
  rowLabels: rowLabels,
232
238
  note: note,
233
239
  env: env,
234
240
  showNote: alternates && alternates.length > 0,
235
- correctResponse: mode === 'evaluate' ? correctResponse : undefined
241
+ correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined
236
242
  };
237
243
 
238
244
  if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
@@ -245,7 +251,7 @@ var model = function model(question, session, env, updateSession) {
245
251
 
246
252
  resolve(out);
247
253
 
248
- case 20:
254
+ case 21:
249
255
  case "end":
250
256
  return _context.stop();
251
257
  }
@@ -295,4 +301,134 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
295
301
  };
296
302
 
297
303
  exports.createCorrectResponseSession = createCorrectResponseSession;
304
+
305
+ var validate = function validate() {
306
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
307
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
308
+ var categories = model.categories,
309
+ choices = model.choices,
310
+ correctResponse = model.correctResponse;
311
+ var _config$minChoices = config.minChoices,
312
+ minChoices = _config$minChoices === void 0 ? 1 : _config$minChoices,
313
+ _config$maxChoices = config.maxChoices,
314
+ maxChoices = _config$maxChoices === void 0 ? 15 : _config$maxChoices,
315
+ _config$minCategories = config.minCategories,
316
+ minCategories = _config$minCategories === void 0 ? 1 : _config$minCategories,
317
+ _config$maxCategories = config.maxCategories,
318
+ maxCategories = _config$maxCategories === void 0 ? 12 : _config$maxCategories,
319
+ _config$maxLengthPerC = config.maxLengthPerChoice,
320
+ maxLengthPerChoice = _config$maxLengthPerC === void 0 ? 300 : _config$maxLengthPerC,
321
+ _config$maxLengthPerC2 = config.maxLengthPerCategory,
322
+ maxLengthPerCategory = _config$maxLengthPerC2 === void 0 ? 150 : _config$maxLengthPerC2;
323
+ var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
324
+ var errors = {};
325
+ var choicesErrors = {};
326
+ var categoriesErrors = {};
327
+ (categories || []).forEach(function (category) {
328
+ var id = category.id,
329
+ label = category.label;
330
+ var parsedLabel = label.replace(/<(?:.|\n)*?>/gm, '');
331
+
332
+ if (parsedLabel.length > maxLengthPerCategory) {
333
+ categoriesErrors[id] = "Category labels should be no more than ".concat(maxLengthPerCategory, " characters long.");
334
+ }
335
+ });
336
+ (reversedChoices || []).forEach(function (choice, index) {
337
+ var id = choice.id,
338
+ content = choice.content;
339
+ var parsedContent = content.replace(/<(?:.|\n)*?>/gm, '');
340
+
341
+ if (parsedContent.length > maxLengthPerChoice) {
342
+ choicesErrors[id] = "Tokens should be no more than ".concat(maxLengthPerChoice, " characters long.");
343
+ }
344
+
345
+ if (content === '' || content === '<div></div>') {
346
+ choicesErrors[id] = 'Tokens should not be empty.';
347
+ } else {
348
+ var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
349
+ return c.content === content;
350
+ });
351
+
352
+ if (identicalAnswer) {
353
+ choicesErrors[id] = 'Tokens content should be unique.';
354
+ }
355
+ }
356
+ });
357
+ var nbOfCategories = (categories || []).length;
358
+ var nbOfChoices = (choices || []).length;
359
+
360
+ if (nbOfCategories > maxCategories) {
361
+ errors.categoriesError = "No more than ".concat(maxCategories, " categories should be defined.");
362
+ } else if (nbOfCategories < minCategories) {
363
+ errors.categoriesError = "There should be at least ".concat(minCategories, " category defined.");
364
+ }
365
+
366
+ if (nbOfChoices < minChoices) {
367
+ errors.choicesError = "There should be at least ".concat(minChoices, " choices defined.");
368
+ } else if (nbOfChoices > maxChoices) {
369
+ errors.choicesError = "No more than ".concat(maxChoices, " choices should be defined.");
370
+ }
371
+
372
+ if (nbOfChoices && nbOfCategories) {
373
+ var hasAssociations = false;
374
+ (correctResponse || []).forEach(function (response) {
375
+ var _response$choices = response.choices,
376
+ choices = _response$choices === void 0 ? [] : _response$choices,
377
+ _response$alternateRe = response.alternateResponses,
378
+ alternateResponses = _response$alternateRe === void 0 ? [] : _response$alternateRe;
379
+
380
+ if (choices.length) {
381
+ hasAssociations = true;
382
+ } else {
383
+ alternateResponses.forEach(function (alternate) {
384
+ if ((alternate || []).length) {
385
+ hasAssociations = true;
386
+ }
387
+ });
388
+ }
389
+ });
390
+ var duplicateAlternateIndex = -1;
391
+ var duplicateCategory = '';
392
+ (correctResponse || []).forEach(function (response) {
393
+ var _response$choices2 = response.choices,
394
+ choices = _response$choices2 === void 0 ? [] : _response$choices2,
395
+ _response$alternateRe2 = response.alternateResponses,
396
+ alternateResponses = _response$alternateRe2 === void 0 ? [] : _response$alternateRe2,
397
+ category = response.category;
398
+
399
+ if (duplicateAlternateIndex === -1) {
400
+ duplicateAlternateIndex = (0, _utils.isCorrectResponseDuplicated)(choices, alternateResponses);
401
+
402
+ if (duplicateAlternateIndex === -1) {
403
+ duplicateAlternateIndex = (0, _utils.isAlternateDuplicated)(alternateResponses);
404
+ }
405
+
406
+ duplicateCategory = category;
407
+ }
408
+ });
409
+
410
+ if (duplicateAlternateIndex > -1) {
411
+ errors.duplicateAlternate = {
412
+ index: duplicateAlternateIndex,
413
+ category: duplicateCategory
414
+ };
415
+ }
416
+
417
+ if (!hasAssociations) {
418
+ errors.associationError = 'At least one token should be assigned to at least one category.';
419
+ }
420
+ }
421
+
422
+ if (!(0, _isEmpty["default"])(choicesErrors)) {
423
+ errors.choicesErrors = choicesErrors;
424
+ }
425
+
426
+ if (!(0, _isEmpty["default"])(categoriesErrors)) {
427
+ errors.categoriesErrors = categoriesErrors;
428
+ }
429
+
430
+ return errors;
431
+ };
432
+
433
+ exports.validate = validate;
298
434
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["getPartialScore","correctResponse","builtCategories","reduce","acc","choices","placements","length","score","filter","ch","correct","maxScore","extraPlacements","totalScore","parseFloat","toFixed","getAlternates","map","c","alternateResponses","alternate","getTotalScore","question","session","env","Object","keys","categories","answers","alternates","enabled","partialScoring","getCorrectness","Promise","resolve","mode","undefined","createDefaultModel","model","defaults","normalize","feedbackEnabled","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","updateSession","normalizedQuestion","answerCorrectness","role","categoriesPerRow","choicesLabel","choicesPosition","feedback","prompt","removeTilesAfterPlacing","rowLabels","rationale","note","teacherInstructions","lockChoiceOrder","fb","out","correctness","disabled","showNote","outcome","reject","Error","empty","createCorrectResponseSession","id"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAKA;;;;;;AAMO,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAACC,eAAD,EAAkBC,eAAlB,EAAsC;AACnE;AACA;AACA,8BAA8BA,eAAe,CAACC,MAAhB,CAC5B,UAACC,GAAD;AAAA,4BAAQC,OAAR;AAAA,QAAQA,OAAR,6BAAkB,EAAlB;AAAA,WAA4B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,eAAR;AAEAkC,MAAAA,OAAO,CAAC;AAAEN,QAAAA,OAAO,EAAE5B,eAAX;AAA4BuE,QAAAA,EAAE,EAAE;AAAhC,OAAD,CAAP;AACD,KAJD,MAIO;AACL,aAAOrC,OAAO,CAAC,IAAD,CAAd;AACD;AACF,GAVM,CAAP;AAWD,CAZM","sourcesContent":["import isEmpty from 'lodash/isEmpty';\nimport { buildState, score } from '@pie-lib/categorize';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport {\n lockChoices,\n getShuffledChoices,\n partialScoring,\n} from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\n// eslint-disable-next-line no-console\n\nexport { score };\n\nexport const getPartialScore = (correctResponse, builtCategories) => {\n // in the resulted best scenario we make a sum with all the correct responses\n // and all the placements\n const { placements, score } = builtCategories.reduce(\n (acc, { choices = [] }) => ({\n placements: acc.placements + choices.length,\n score: acc.score + choices.filter((ch) => ch.correct).length,\n }),\n { placements: 0, score: 0 }\n );\n\n // in the correct response, we make a sum of the max possible score\n const { maxScore } = correctResponse.reduce(\n (acc, { choices }) => ({\n maxScore: acc.maxScore + choices.length,\n }),\n { maxScore: 0 }\n );\n\n // if there are any extra placements, we subtract from the obtained score\n const extraPlacements = placements > maxScore ? placements - maxScore : 0;\n const totalScore = (score - extraPlacements) / maxScore;\n\n return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));\n};\n\nconst getAlternates = correctResponse => correctResponse\n .map((c) => c.alternateResponses)\n .filter((alternate) => alternate);\n\nexport const getTotalScore = (question, session, env) => {\n if (!session) {\n return 0;\n }\n\n if (Object.keys(session).length === 0) {\n return 0;\n }\n const { categories, choices } = question || {};\n let { correctResponse } = question || {};\n let { answers } = session || {};\n answers = answers || [];\n correctResponse = correctResponse || [];\n\n // this function is used in pie-ui/categorize as well, in order to get the best scenario\n // so we get the best scenario and calculate the score\n const { categories: builtCategories, correct } = buildState(\n categories,\n choices,\n answers,\n correctResponse\n );\n\n const alternates = getAlternates(correctResponse);\n const enabled = partialScoring.enabled(question, env);\n\n // if there are any alternates, there will be no partial scoring!\n if (enabled && !alternates.length) {\n // we apply partial scoring\n return getPartialScore(correctResponse, builtCategories);\n }\n\n // else we apply dichotomous\n return correct ? 1 : 0;\n};\n\nexport const getCorrectness = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode === 'evaluate') {\n const score = getTotalScore(question, session, env);\n if (score === 1) {\n resolve('correct');\n } else if (score === 0) {\n resolve('incorrect');\n } else {\n resolve('partially-correct');\n }\n } else {\n resolve(undefined);\n }\n });\n};\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nexport const normalize = (question) => ({\n feedbackEnabled: true,\n rationaleEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport const model = (question, session, env, updateSession) =>\n new Promise(async (resolve) => {\n const normalizedQuestion = normalize(question);\n const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);\n\n const { mode, role } = env || {};\n\n const {\n categories,\n categoriesPerRow,\n choicesLabel,\n choicesPosition,\n correctResponse,\n feedback,\n feedbackEnabled,\n promptEnabled,\n prompt,\n removeTilesAfterPlacing,\n rowLabels,\n rationaleEnabled,\n rationale,\n note,\n teacherInstructionsEnabled,\n teacherInstructions,\n } = normalizedQuestion;\n let { choices } = normalizedQuestion;\n let fb;\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (mode === 'evaluate' && feedbackEnabled) {\n fb = await getFeedbackForCorrectness(\n answerCorrectness,\n feedback\n );\n }\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n const alternates = getAlternates(correctResponse);\n const out = {\n categories: categories || [],\n categoriesPerRow: categoriesPerRow || 2,\n correctness: answerCorrectness,\n choices: choices || [],\n choicesLabel: choicesLabel || '',\n choicesPosition,\n disabled: mode !== 'gather',\n feedback: fb,\n lockChoiceOrder,\n prompt: promptEnabled ? prompt : null,\n removeTilesAfterPlacing,\n rowLabels,\n note,\n env,\n showNote: alternates && alternates.length > 0,\n correctResponse: mode === 'evaluate' ? correctResponse : undefined,\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = rationaleEnabled ? rationale : null;\n out.teacherInstructions = teacherInstructionsEnabled\n ? teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n\nexport const outcome = (question, session, env) => {\n if (env.mode !== 'evaluate') {\n return Promise.reject(\n new Error('Can not call outcome when mode is not evaluate')\n );\n } else {\n return new Promise((resolve) => {\n resolve({\n score: getTotalScore(question, session, env),\n empty: !session || isEmpty(session),\n });\n });\n }\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n const { mode, role } = env || {};\n\n if (mode !== 'evaluate' && role === 'instructor') {\n const { correctResponse } = question;\n\n resolve({ answers: correctResponse, id: 1 });\n } else {\n return resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["getPartialScore","correctResponse","builtCategories","reduce","acc","choices","placements","length","score","filter","ch","correct","maxScore","extraPlacements","totalScore","parseFloat","toFixed","getAlternates","map","c","alternateResponses","alternate","getTotalScore","question","session","env","Object","keys","categories","answers","alternates","enabled","partialScoring","getCorrectness","Promise","resolve","mode","undefined","createDefaultModel","model","defaults","normalize","updateSession","normalizedQuestion","answerCorrectness","role","categoriesPerRow","choicesLabel","choicesPosition","feedback","feedbackEnabled","promptEnabled","prompt","rowLabels","rationaleEnabled","rationale","note","teacherInstructionsEnabled","teacherInstructions","lockChoiceOrder","filteredCorrectResponse","response","filteredChoices","choice","fb","out","correctness","disabled","showNote","outcome","reject","Error","empty","createCorrectResponseSession","id","validate","config","minChoices","maxChoices","minCategories","maxCategories","maxLengthPerChoice","maxLengthPerCategory","reversedChoices","reverse","errors","choicesErrors","categoriesErrors","forEach","category","label","parsedLabel","replace","index","content","parsedContent","identicalAnswer","slice","some","nbOfCategories","nbOfChoices","categoriesError","choicesError","hasAssociations","duplicateAlternateIndex","duplicateCategory","duplicateAlternate","associationError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAMO,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAACC,eAAD,EAAkBC,eAAlB,EAAsC;AACnE;AACA;AACA,8BAA8BA,eAAe,CAACC,MAAhB,CAC5B,UAACC,GAAD;AAAA,4BAAQC,OAAR;AAAA,QAAQA,OAAR,6BAAkB,EAAlB;AAAA,WAA4B;AAC1BC,MAAAA,UAAU,EAAEF,GAAG,CAACE,UAAJ,GAAiBD,OAAO,CAACE,MADX;AAE1BC,MAAAA,KAAK,EAAEJ,GAAG,CAACI,KAAJ,GAAYH,OAAO,CAACI,MAAR,CAAe,UAACC,EAAD;AAAA,eAAQA,EAAE,CAACC,OAAX;AAAA,OAAf,EAAmCJ;AAF5B,KAA5B;AAAA,GAD4B,EAK5B;AAAED,IAAAA,UAAU,EAAE,CAAd;AAAiBE,IAAAA,KAAK,EAAE;AAAxB,GAL4B,CAA9B;AAAA,MAAQF,UAAR,yBAAQA,UAAR;AAAA,MAAoBE,KAApB,yBAAoBA,KAApB,CAHmE,CAWnE;;;AACA,8BAAqBP,eAAe,CAACE,MAAhB,CACnB,UAACC,GAAD;AAAA,QAAQC,OAAR,SAAQA,OAAR;AAAA,WAAuB;AACrBO,MAAAA,QAAQ,EAAER,GAAG,CAACQ,QAAJ,GAAeP,OAAO,CAACE;AADZ,KAAvB;AAAA,GADmB,EAInB;AAAEK,IAAAA,QAAQ,EAAE;AAAZ,GAJmB,CAArB;AAAA,MAAQA,QAAR,yBAAQA,QAAR,CAZmE,CAmBnE;;;AACA,MAAMC,eAAe,G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AED,MAAI,CAAC,yBAAQrB,aAAR,CAAL,EAA6B;AAC3BD,IAAAA,MAAM,CAACC,aAAP,GAAuBA,aAAvB;AACD;;AAED,MAAI,CAAC,yBAAQC,gBAAR,CAAL,EAAgC;AAC9BF,IAAAA,MAAM,CAACE,gBAAP,GAA0BA,gBAA1B;AACD;;AACD,SAAOF,MAAP;AACD,CA/FM","sourcesContent":["import isEmpty from 'lodash/isEmpty';\nimport { buildState, score } from '@pie-lib/categorize';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { isAlternateDuplicated, isCorrectResponseDuplicated } from './utils';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\n// eslint-disable-next-line no-console\n\nexport { score };\n\nexport const getPartialScore = (correctResponse, builtCategories) => {\n // in the resulted best scenario we make a sum with all the correct responses\n // and all the placements\n const { placements, score } = builtCategories.reduce(\n (acc, { choices = [] }) => ({\n placements: acc.placements + choices.length,\n score: acc.score + choices.filter((ch) => ch.correct).length,\n }),\n { placements: 0, score: 0 },\n );\n\n // in the correct response, we make a sum of the max possible score\n const { maxScore } = correctResponse.reduce(\n (acc, { choices }) => ({\n maxScore: acc.maxScore + choices.length,\n }),\n { maxScore: 0 },\n );\n\n // if there are any extra placements, we subtract from the obtained score\n const extraPlacements = placements > maxScore ? placements - maxScore : 0;\n const totalScore = (score - extraPlacements) / maxScore;\n\n return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));\n};\n\nconst getAlternates = (correctResponse) =>\n correctResponse.map((c) => c.alternateResponses).filter((alternate) => alternate);\n\nexport const getTotalScore = (question, session, env) => {\n if (!session) {\n return 0;\n }\n\n if (Object.keys(session).length === 0) {\n return 0;\n }\n const { categories, choices } = question || {};\n let { correctResponse } = question || {};\n let { answers } = session || {};\n answers = answers || [];\n correctResponse = correctResponse || [];\n\n // this function is used in pie-ui/categorize as well, in order to get the best scenario\n // so we get the best scenario and calculate the score\n const { categories: builtCategories, correct } = buildState(categories, choices, answers, correctResponse);\n\n const alternates = getAlternates(correctResponse);\n const enabled = partialScoring.enabled(question, env);\n\n // if there are any alternates, there will be no partial scoring!\n if (enabled && !alternates.length) {\n // we apply partial scoring\n return getPartialScore(correctResponse, builtCategories);\n }\n\n // else we apply dichotomous\n return correct ? 1 : 0;\n};\n\nexport const getCorrectness = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode === 'evaluate') {\n const score = getTotalScore(question, session, env);\n if (score === 1) {\n resolve('correct');\n } else if (score === 0) {\n resolve('incorrect');\n } else {\n resolve('partially-correct');\n }\n } else {\n resolve(undefined);\n }\n });\n};\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nexport const normalize = (question) => ({\n ...defaults,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport const model = (question, session, env, updateSession) =>\n new Promise(async (resolve) => {\n const normalizedQuestion = normalize(question);\n const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);\n\n const { mode, role } = env || {};\n\n const {\n categories,\n categoriesPerRow,\n choicesLabel,\n choicesPosition,\n correctResponse,\n feedback,\n feedbackEnabled,\n promptEnabled,\n prompt,\n rowLabels,\n rationaleEnabled,\n rationale,\n note,\n teacherInstructionsEnabled,\n teacherInstructions,\n } = normalizedQuestion;\n let { choices } = normalizedQuestion;\n let fb;\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n const filteredCorrectResponse = correctResponse.map((response) => {\n const filteredChoices = (response.choices || []).filter((choice) => choice !== 'null');\n return { ...response, choices: filteredChoices };\n });\n\n if (mode === 'evaluate' && feedbackEnabled) {\n fb = await getFeedbackForCorrectness(answerCorrectness, feedback);\n }\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n const alternates = getAlternates(filteredCorrectResponse);\n const out = {\n categories: categories || [],\n categoriesPerRow: categoriesPerRow || 2,\n correctness: answerCorrectness,\n choices: choices || [],\n choicesLabel: choicesLabel || '',\n choicesPosition,\n disabled: mode !== 'gather',\n feedback: fb,\n lockChoiceOrder,\n prompt: promptEnabled ? prompt : null,\n rowLabels,\n note,\n env,\n showNote: alternates && alternates.length > 0,\n correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = rationaleEnabled ? rationale : null;\n out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n\nexport const outcome = (question, session, env) => {\n if (env.mode !== 'evaluate') {\n return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));\n } else {\n return new Promise((resolve) => {\n resolve({\n score: getTotalScore(question, session, env),\n empty: !session || isEmpty(session),\n });\n });\n }\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n const { mode, role } = env || {};\n\n if (mode !== 'evaluate' && role === 'instructor') {\n const { correctResponse } = question;\n\n resolve({ answers: correctResponse, id: 1 });\n } else {\n return resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { categories, choices, correctResponse } = model;\n const { minChoices = 1, maxChoices = 15, minCategories = 1, maxCategories = 12, maxLengthPerChoice = 300, maxLengthPerCategory = 150 } = config;\n const reversedChoices = [ ...choices || []].reverse();\n const errors = {};\n const choicesErrors = {};\n const categoriesErrors = {};\n\n (categories || []).forEach((category) => {\n const {id, label} = category;\n const parsedLabel = label.replace(/<(?:.|\\n)*?>/gm, '');\n if (parsedLabel.length > maxLengthPerCategory){\n categoriesErrors[id] = `Category labels should be no more than ${maxLengthPerCategory} characters long.`;\n }\n });\n\n (reversedChoices || []).forEach((choice, index) => {\n const { id, content } = choice;\n const parsedContent = content.replace(/<(?:.|\\n)*?>/gm, '');\n if (parsedContent.length > maxLengthPerChoice){\n choicesErrors[id] = `Tokens should be no more than ${maxLengthPerChoice} characters long.`;\n }\n if (content === '' || content === '<div></div>') {\n choicesErrors[id] = 'Tokens should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.content === content);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Tokens content should be unique.';\n }\n }\n });\n\n const nbOfCategories = (categories || []).length;\n const nbOfChoices = (choices || []).length;\n\n if (nbOfCategories > maxCategories) {\n errors.categoriesError = `No more than ${maxCategories} categories should be defined.`;\n } else if (nbOfCategories < minCategories) {\n errors.categoriesError = `There should be at least ${minCategories} category defined.`;\n }\n\n if (nbOfChoices < minChoices) {\n errors.choicesError = `There should be at least ${minChoices} choices defined.`;\n } else if (nbOfChoices > maxChoices) {\n errors.choicesError = `No more than ${maxChoices} choices should be defined.`;\n }\n\n if (nbOfChoices && nbOfCategories) {\n let hasAssociations = false;\n\n (correctResponse || []).forEach(response => {\n const { choices = [], alternateResponses = [] } = response;\n\n if (choices.length) {\n hasAssociations = true;\n } else {\n alternateResponses.forEach(alternate => {\n if ((alternate || []).length) {\n hasAssociations = true;\n }\n });\n }\n });\n\n let duplicateAlternateIndex = -1;\n let duplicateCategory = '';\n (correctResponse || []).forEach(response => {\n const { choices = [], alternateResponses = [], category } = response;\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isCorrectResponseDuplicated(choices,alternateResponses);\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isAlternateDuplicated(alternateResponses);\n }\n duplicateCategory = category;\n }\n });\n\n if (duplicateAlternateIndex > -1) {\n errors.duplicateAlternate = {index:duplicateAlternateIndex, category:duplicateCategory};\n }\n\n if (!hasAssociations) {\n errors.associationError = 'At least one token should be assigned to at least one category.';\n }\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n if (!isEmpty(categoriesErrors)) {\n errors.categoriesErrors = categoriesErrors;\n }\n return errors;\n};\n"],"file":"index.js"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.multiplePlacements = exports.isCorrectResponseDuplicated = exports.isAlternateDuplicated = void 0;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ // used in configure too, for consistency modify it there too
13
+ var multiplePlacements = {
14
+ enabled: 'Yes',
15
+ disabled: 'No',
16
+ perChoice: 'Set Per Choice'
17
+ }; // used to validate the config
18
+
19
+ exports.multiplePlacements = multiplePlacements;
20
+
21
+ var isCorrectResponseDuplicated = function isCorrectResponseDuplicated(choices, alternate) {
22
+ if (choices.length < 1 || alternate.length < 1) {
23
+ return -1;
24
+ }
25
+
26
+ var stringChoices = JSON.stringify(choices.sort());
27
+ var stringAlternate = alternate.reduce(function (total, current) {
28
+ return current.length > 0 ? [].concat((0, _toConsumableArray2["default"])(total), [JSON.stringify(current.sort())]) : total;
29
+ }, []);
30
+ var foundIndexDuplicate = stringAlternate.findIndex(function (alternate) {
31
+ return alternate.length && alternate === stringChoices;
32
+ });
33
+ return foundIndexDuplicate;
34
+ };
35
+
36
+ exports.isCorrectResponseDuplicated = isCorrectResponseDuplicated;
37
+
38
+ var isAlternateDuplicated = function isAlternateDuplicated(alternate) {
39
+ if (alternate.length <= 1) {
40
+ return -1;
41
+ }
42
+
43
+ var elementSet = new Set();
44
+ var stringAlternate = alternate.reduce(function (total, current) {
45
+ return current.length > 0 ? [].concat((0, _toConsumableArray2["default"])(total), [JSON.stringify(current.sort())]) : total;
46
+ }, []);
47
+
48
+ for (var i = 0; i < stringAlternate.length; i++) {
49
+ if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {
50
+ return i;
51
+ }
52
+
53
+ elementSet.add(stringAlternate[i]);
54
+ }
55
+
56
+ return -1;
57
+ };
58
+
59
+ exports.isAlternateDuplicated = isAlternateDuplicated;
60
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.js"],"names":["multiplePlacements","enabled","disabled","perChoice","isCorrectResponseDuplicated","choices","alternate","length","stringChoices","JSON","stringify","sort","stringAlternate","reduce","total","current","foundIndexDuplicate","findIndex","isAlternateDuplicated","elementSet","Set","i","has","add"],"mappings":";;;;;;;;;;;AAAA;AACO,IAAMA,kBAAkB,GAAG;AAAEC,EAAAA,OAAO,EAAE,KAAX;AAAkBC,EAAAA,QAAQ,EAAE,IAA5B;AAAkCC,EAAAA,SAAS,EAAE;AAA7C,CAA3B,C,CAEP;;;;AACO,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA8B,CAACC,OAAD,EAASC,SAAT,EAAuB;AAC9D,MAAID,OAAO,CAACE,MAAR,GAAiB,CAAjB,IAAsBD,SAAS,CAACC,MAAV,GAAmB,CAA7C,EAA+C;AAC3C,WAAO,CAAC,CAAR;AACH;;AACD,MAAMC,aAAa,GAAIC,IAAI,CAACC,SAAL,CAAeL,OAAO,CAACM,IAAR,EAAf,CAAvB;AACA,MAAMC,eAAe,GAAGN,SAAS,CAACO,MAAV,CAAiB,UAACC,KAAD,EAAQC,OAAR;AAAA,WAAoBA,OAAO,CAACR,MAAR,GAAiB,CAAjB,iDAAyBO,KAAzB,IAAgCL,IAAI,CAACC,SAAL,CAAeK,OAAO,CAACJ,IAAR,EAAf,CAAhC,KAAkEG,KAAtF;AAAA,GAAjB,EAA8G,EAA9G,CAAxB;AACA,MAAME,mBAAmB,GAAGJ,eAAe,CAACK,SAAhB,CAA0B,UAAAX,SAAS;AAAA,WAAIA,SAAS,CAACC,MAAV,IAAqBD,SAAS,KAAKE,aAAvC;AAAA,GAAnC,CAA5B;AACA,SAAOQ,mBAAP;AACH,CARM;;;;AAUA,IAAME,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACZ,SAAD,EAAe;AAChD,MAAIA,SAAS,CAACC,MAAV,IAAoB,CAAxB,EAA0B;AACtB,WAAO,CAAC,CAAR;AACH;;AACD,MAAMY,UAAU,GAAG,IAAIC,GAAJ,EAAnB;AACA,MAAMR,eAAe,GAAGN,SAAS,CAACO,MAAV,CAAiB,UAACC,KAAD,EAAQC,OAAR;AAAA,WAAoBA,OAAO,CAACR,MAAR,GAAiB,CAAjB,iDAAyBO,KAAzB,IAAgCL,IAAI,CAACC,SAAL,CAAeK,OAAO,CAACJ,IAAR,EAAf,CAAhC,KAAkEG,KAAtF;AAAA,GAAjB,EAA8G,EAA9G,CAAxB;;AACA,OAAK,IAAIO,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGT,eAAe,CAACL,MAApC,EAA4Cc,CAAC,EAA7C,EAAiD;AAC7C,QAAIF,UAAU,CAACG,GAAX,CAAeV,eAAe,CAACS,CAAD,CAA9B,KAAsCT,eAAe,CAACS,CAAD,CAAzD,EAA8D;AAC1D,aAAOA,CAAP;AACH;;AACDF,IAAAA,UAAU,CAACI,GAAX,CAAeX,eAAe,CAACS,CAAD,CAA9B;AACH;;AAED,SAAO,CAAC,CAAR;AACH,CAdM","sourcesContent":["// used in configure too, for consistency modify it there too\nexport const multiplePlacements = { enabled: 'Yes', disabled: 'No', perChoice: 'Set Per Choice' };\n\n// used to validate the config\nexport const isCorrectResponseDuplicated = (choices,alternate) => {\n if (choices.length < 1 || alternate.length < 1){\n return -1;\n }\n const stringChoices = JSON.stringify(choices.sort());\n const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);\n const foundIndexDuplicate = stringAlternate.findIndex(alternate => alternate.length && alternate === stringChoices);\n return foundIndexDuplicate;\n};\n\nexport const isAlternateDuplicated = (alternate) => {\n if (alternate.length <= 1){\n return -1;\n }\n const elementSet = new Set();\n const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);\n for (let i = 0; i < stringAlternate.length; i++) {\n if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {\n return i;\n }\n elementSet.add(stringAlternate[i]);\n }\n\n return -1;\n};\n"],"file":"utils.js"}
@@ -2,12 +2,12 @@
2
2
  "name": "@pie-element/categorize-controller",
3
3
  "private": true,
4
4
  "dependencies": {
5
- "@pie-lib/categorize": "^0.6.24",
6
- "@pie-lib/controller-utils": "^0.2.26",
7
- "@pie-lib/feedback": "^0.4.27",
5
+ "@pie-lib/categorize": "^0.8.12",
6
+ "@pie-lib/controller-utils": "^0.2.42",
7
+ "@pie-lib/feedback": "^0.4.42",
8
8
  "lodash": "^4.17.15"
9
9
  },
10
- "version": "5.2.7",
10
+ "version": "5.7.0",
11
11
  "description": "",
12
12
  "scripts": {},
13
13
  "main": "lib/index.js",
@@ -35,6 +35,22 @@
35
35
  }
36
36
  }
37
37
  },
38
+ "spellCheck": {
39
+ "title": "ConfigureProp",
40
+ "type": "object",
41
+ "properties": {
42
+ "settings": {
43
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
44
+ "type": "boolean",
45
+ "title": "settings"
46
+ },
47
+ "label": {
48
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
49
+ "type": "string",
50
+ "title": "label"
51
+ }
52
+ }
53
+ },
38
54
  "scoringType": {
39
55
  "title": "ConfigureProp",
40
56
  "type": "object",
@@ -51,6 +67,11 @@
51
67
  }
52
68
  }
53
69
  },
70
+ "settingsPanelDisabled": {
71
+ "description": "Indicates if the settings panel is not available",
72
+ "type": "boolean",
73
+ "title": "settingsPanelDisabled"
74
+ },
54
75
  "studentInstructions": {
55
76
  "title": "ConfigureProp",
56
77
  "type": "object",
@@ -83,6 +104,130 @@
83
104
  }
84
105
  }
85
106
  },
107
+ "minChoices": {
108
+ "description": "Minimum number of choices",
109
+ "type": "number",
110
+ "title": "minChoices"
111
+ },
112
+ "maxChoices": {
113
+ "description": "Maximum number of choices",
114
+ "type": "number",
115
+ "title": "maxChoices"
116
+ },
117
+ "choicesPosition": {
118
+ "title": "ConfigureProp",
119
+ "type": "object",
120
+ "properties": {
121
+ "settings": {
122
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
123
+ "type": "boolean",
124
+ "title": "settings"
125
+ },
126
+ "label": {
127
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
128
+ "type": "string",
129
+ "title": "label"
130
+ }
131
+ }
132
+ },
133
+ "maxCategories": {
134
+ "description": "Maximum number of categories",
135
+ "type": "number",
136
+ "title": "maxCategories"
137
+ },
138
+ "minCategoriesPerRow": {
139
+ "description": "Minimum value of categories per row",
140
+ "type": "number",
141
+ "title": "minCategoriesPerRow"
142
+ },
143
+ "maxImageWidth": {
144
+ "title": "ConfigureMaxImageDimensionsProp",
145
+ "type": "object",
146
+ "properties": {
147
+ "teacherInstructions": {
148
+ "description": "Indicates the max dimension for images in teacher instructions",
149
+ "type": "number",
150
+ "title": "teacherInstructions"
151
+ },
152
+ "prompt": {
153
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
154
+ "type": "number",
155
+ "title": "prompt"
156
+ },
157
+ "rationale": {
158
+ "description": "Indicates the max dimension for images in rationale",
159
+ "type": "number",
160
+ "title": "rationale"
161
+ },
162
+ "choices": {
163
+ "description": "Indicates the max dimension for images in choices",
164
+ "type": "number",
165
+ "title": "choices"
166
+ },
167
+ "rowLabel": {
168
+ "description": "Indicates the max dimension for images in row labels",
169
+ "type": "number",
170
+ "title": "rowLabel"
171
+ },
172
+ "categoryLabel": {
173
+ "description": "Indicates the max dimension for images in category labels",
174
+ "type": "number",
175
+ "title": "categoryLabel"
176
+ }
177
+ }
178
+ },
179
+ "maxImageHeight": {
180
+ "title": "ConfigureMaxImageDimensionsProp",
181
+ "type": "object",
182
+ "properties": {
183
+ "teacherInstructions": {
184
+ "description": "Indicates the max dimension for images in teacher instructions",
185
+ "type": "number",
186
+ "title": "teacherInstructions"
187
+ },
188
+ "prompt": {
189
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
190
+ "type": "number",
191
+ "title": "prompt"
192
+ },
193
+ "rationale": {
194
+ "description": "Indicates the max dimension for images in rationale",
195
+ "type": "number",
196
+ "title": "rationale"
197
+ },
198
+ "choices": {
199
+ "description": "Indicates the max dimension for images in choices",
200
+ "type": "number",
201
+ "title": "choices"
202
+ },
203
+ "rowLabel": {
204
+ "description": "Indicates the max dimension for images in row labels",
205
+ "type": "number",
206
+ "title": "rowLabel"
207
+ },
208
+ "categoryLabel": {
209
+ "description": "Indicates the max dimension for images in category labels",
210
+ "type": "number",
211
+ "title": "categoryLabel"
212
+ }
213
+ }
214
+ },
215
+ "withRubric": {
216
+ "title": "ConfigureProp",
217
+ "type": "object",
218
+ "properties": {
219
+ "settings": {
220
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
221
+ "type": "boolean",
222
+ "title": "settings"
223
+ },
224
+ "label": {
225
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
226
+ "type": "string",
227
+ "title": "label"
228
+ }
229
+ }
230
+ },
86
231
  "showPrompt": {
87
232
  "description": "Determines whether prompt field will be displayed or not",
88
233
  "default": true,
@@ -118,6 +263,42 @@
118
263
  "title": "label"
119
264
  }
120
265
  }
266
+ },
267
+ "ConfigureMaxImageDimensionsProp": {
268
+ "title": "ConfigureMaxImageDimensionsProp",
269
+ "type": "object",
270
+ "properties": {
271
+ "teacherInstructions": {
272
+ "description": "Indicates the max dimension for images in teacher instructions",
273
+ "type": "number",
274
+ "title": "teacherInstructions"
275
+ },
276
+ "prompt": {
277
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
278
+ "type": "number",
279
+ "title": "prompt"
280
+ },
281
+ "rationale": {
282
+ "description": "Indicates the max dimension for images in rationale",
283
+ "type": "number",
284
+ "title": "rationale"
285
+ },
286
+ "choices": {
287
+ "description": "Indicates the max dimension for images in choices",
288
+ "type": "number",
289
+ "title": "choices"
290
+ },
291
+ "rowLabel": {
292
+ "description": "Indicates the max dimension for images in row labels",
293
+ "type": "number",
294
+ "title": "rowLabel"
295
+ },
296
+ "categoryLabel": {
297
+ "description": "Indicates the max dimension for images in category labels",
298
+ "type": "number",
299
+ "title": "categoryLabel"
300
+ }
301
+ }
121
302
  }
122
303
  },
123
304
  "$schema": "http://json-schema.org/draft-07/schema#"