@pie-element/math-inline 5.6.4-next.842 → 5.6.4-next.855

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.
@@ -1369,4 +1369,56 @@ const createCorrectResponseSession = (question, env) => {
1369
1369
  }
1370
1370
  };
1371
1371
 
1372
- export { createCorrectResponseSession, createDefaultModel, model, normalize, outcome };
1372
+ const validate = (model = {}, config = {}) => {
1373
+ const { expression = '', responses, responseType } = model;
1374
+ const { maxResponseAreas } = config;
1375
+ const responsesErrors = {};
1376
+
1377
+ (responses || []).forEach((response, index) => {
1378
+ const { answer } = response;
1379
+ const reversedAlternates = [ ...Object.entries(response.alternates || {}) ].reverse();
1380
+ const alternatesErrors = {};
1381
+ const responseError = {};
1382
+
1383
+ if (answer === '') {
1384
+ responseError.answer = 'Content should not be empty.';
1385
+ }
1386
+
1387
+ reversedAlternates.forEach(([key, value], index) => {
1388
+ if (value === '') {
1389
+ alternatesErrors[key] = 'Content should not be empty.';
1390
+ } else {
1391
+ const identicalAnswer = answer === value ||
1392
+ reversedAlternates.slice(index + 1).some(([ , val]) => val === value);
1393
+
1394
+ if (identicalAnswer) {
1395
+ alternatesErrors[key] = 'Content should be unique.';
1396
+ }
1397
+ }
1398
+ });
1399
+
1400
+ if (!isEmpty_1(responseError) || !isEmpty_1(alternatesErrors)) {
1401
+ responsesErrors[index] = { ...responseError, ...alternatesErrors };
1402
+ }
1403
+ });
1404
+
1405
+ const errors = {};
1406
+
1407
+ if (responseType === 'Advanced Multi') {
1408
+ const nbOfResponseAreas = (expression.match(/\{\{response\}\}/g) || []).length;
1409
+
1410
+ if (nbOfResponseAreas > maxResponseAreas) {
1411
+ errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;
1412
+ } else if (nbOfResponseAreas < 1) {
1413
+ errors.responseAreasError = 'There should be at least 1 response area defined.';
1414
+ }
1415
+ }
1416
+
1417
+ if (!isEmpty_1(responsesErrors)) {
1418
+ errors.responsesErrors = responsesErrors;
1419
+ }
1420
+
1421
+ return errors;
1422
+ };
1423
+
1424
+ export { createCorrectResponseSession, createDefaultModel, model, normalize, outcome, validate };
package/module/element.js CHANGED
@@ -1888,12 +1888,25 @@ var utils = {};
1888
1888
  Object.defineProperty(utils, "__esModule", {
1889
1889
  value: true
1890
1890
  });
1891
- utils.ResponseTypes = void 0;
1891
+ utils.generateValidationMessage = utils.ResponseTypes = void 0;
1892
1892
  var ResponseTypes = {
1893
1893
  advanced: 'Advanced Multi',
1894
1894
  simple: 'Simple'
1895
1895
  };
1896
1896
  utils.ResponseTypes = ResponseTypes;
1897
+ var generateValidationMessage = function generateValidationMessage() {
1898
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1899
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1900
+ var maxResponseAreas = config.maxResponseAreas;
1901
+ var responseType = model.responseType;
1902
+ var responseAreasMessage = '';
1903
+ var answersMessage = '\nAll correct answers (the primary and any alternates) should not be empty and should be unique.';
1904
+ if (responseType === 'Advanced Multi') {
1905
+ responseAreasMessage = '\nThere should be at least 1 ' + (maxResponseAreas ? ("and at most ").concat(maxResponseAreas, " ") : '') + 'response area' + (maxResponseAreas ? 's' : '') + ' defined.';
1906
+ }
1907
+ return 'Validation requirements:' + answersMessage + responseAreasMessage;
1908
+ };
1909
+ utils.generateValidationMessage = generateValidationMessage;
1897
1910
  (function (exports) {
1898
1911
  Object.defineProperty(exports, "__esModule", {
1899
1912
  value: true
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "repository": "pie-framework/pie-elements",
7
- "version": "5.6.4-next.842+a9d5044fc",
7
+ "version": "5.6.4-next.855+054ee27e4",
8
8
  "main": "lib/index.js",
9
9
  "description": "",
10
10
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "author": "",
30
30
  "license": "ISC",
31
- "gitHead": "a9d5044fc1311ee582fee19a361859fe84bc6817",
31
+ "gitHead": "054ee27e4b5f49dfeff08e64ab87e5f8221504a0",
32
32
  "module": "src/index.js",
33
33
  "exports": {
34
34
  ".": "./src/index.js",