@pie-element/explicit-constructed-response 3.13.0 → 3.13.3

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.
@@ -1,6 +1,6 @@
1
- import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_lodash, _dll_material_ui__icons, _dll_react_dom, _dll_debug} from "../../../@pie-lib/shared-module@^1.4.13/module/index.js";
2
- import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.5.0/module/index.js";
3
- import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.2.0/module/index.js";
1
+ import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_classnames, _dll_material_ui__core_styles, _dll_lodash, _dll_material_ui__icons, _dll_react_dom, _dll_debug} from "../../../@pie-lib/shared-module@^1.4.19/module/index.js";
2
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.5.6/module/index.js";
3
+ import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.3.1/module/index.js";
4
4
  function getDefaultExportFromCjs(x) {
5
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6
6
  }
@@ -384,6 +384,7 @@ const require$$8 = _dll_react;
384
384
  const require$$9$3 = _dll_prop_types;
385
385
  const require$$10$4 = _dll_material_ui__core_styles;
386
386
  const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
387
+ const require$$12$4 = _dll_classnames;
387
388
  (function (exports) {
388
389
  var _interopRequireDefault = interopRequireDefault.exports;
389
390
  Object.defineProperty(exports, "__esModule", {
@@ -401,6 +402,7 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
401
402
  var _propTypes = _interopRequireDefault(require$$9$3);
402
403
  var _styles = require$$10$4;
403
404
  var _OutlinedInput = _interopRequireDefault(require$$11$4);
405
+ _interopRequireDefault(require$$12$4);
404
406
  function ownKeys(object, enumerableOnly) {
405
407
  var keys = Object.keys(object);
406
408
  if (Object.getOwnPropertySymbols) {
@@ -509,7 +511,8 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
509
511
  }, {
510
512
  key: "render",
511
513
  value: function render() {
512
- var classes = this.props.classes;
514
+ var _this$props3 = this.props, classes = _this$props3.classes;
515
+ _this$props3.error;
513
516
  var _this$state = this.state, markup = _this$state.markup, toolbarStyle = _this$state.toolbarStyle;
514
517
  return _react["default"].createElement("div", {
515
518
  style: _objectSpread(_objectSpread({}, toolbarStyle), {}, {
@@ -554,6 +557,9 @@ const {OutlinedInput: require$$11$4} = _dll_material_ui__core;
554
557
  input: {
555
558
  backgroundColor: '#fff',
556
559
  padding: '10px 20px 10px 10px'
560
+ },
561
+ errorInput: {
562
+ border: '2px solid red'
557
563
  }
558
564
  })(ECRToolbar);
559
565
  var _default = StyledECRToolbar;
@@ -622,7 +628,7 @@ const require$$9$2 = _dll_react;
622
628
  const require$$10$3 = _dll_prop_types;
623
629
  const {debounce: require$$11$3} = _dll_lodash;
624
630
  const {isEqual: require$$12$3} = _dll_lodash;
625
- const {max: require$$21} = _dll_lodash;
631
+ const {max: require$$21$1} = _dll_lodash;
626
632
  const {OutlinedInput: require$$13$3} = _dll_material_ui__core;
627
633
  const {Button: require$$14$2} = _dll_material_ui__core;
628
634
  const {IconButton: require$$16$1} = _dll_material_ui__core;
@@ -630,7 +636,8 @@ const {MenuItem: require$$17$1} = _dll_material_ui__core;
630
636
  const {Select: require$$18$1} = _dll_material_ui__core;
631
637
  const {TextField: require$$19$1} = _dll_material_ui__core;
632
638
  const {Delete: require$$15$1} = _dll_material_ui__icons;
633
- const require$$20 = _dll_material_ui__core_styles;
639
+ const require$$20$1 = _dll_material_ui__core_styles;
640
+ const require$$22 = _dll_classnames;
634
641
  (function (exports) {
635
642
  var _interopRequireDefault = interopRequireDefault.exports;
636
643
  Object.defineProperty(exports, "__esModule", {
@@ -656,8 +663,9 @@ const require$$20 = _dll_material_ui__core_styles;
656
663
  var _MenuItem = _interopRequireDefault(require$$17$1);
657
664
  var _Select = _interopRequireDefault(require$$18$1);
658
665
  var _TextField = _interopRequireDefault(require$$19$1);
659
- var _styles = require$$20;
660
- var _max = _interopRequireDefault(require$$21);
666
+ var _styles = require$$20$1;
667
+ var _max = _interopRequireDefault(require$$21$1);
668
+ var _classnames = _interopRequireDefault(require$$22);
661
669
  var _markupUtils = markupUtils;
662
670
  function ownKeys(object, enumerableOnly) {
663
671
  var keys = Object.keys(object);
@@ -736,6 +744,15 @@ const require$$20 = _dll_material_ui__core_styles;
736
744
  lengthField: {
737
745
  width: '230px',
738
746
  marginRight: '20px'
747
+ },
748
+ errorText: {
749
+ fontSize: '12px',
750
+ color: 'red',
751
+ paddingTop: '5px'
752
+ },
753
+ inputError: {
754
+ border: '2px solid red',
755
+ borderRadius: '6px'
739
756
  }
740
757
  };
741
758
  };
@@ -775,15 +792,15 @@ const require$$20 = _dll_material_ui__core_styles;
775
792
  key: "render",
776
793
  value: function render() {
777
794
  var value = this.state.value;
778
- var _this$props = this.props, classes = _this$props.classes, onDelete = _this$props.onDelete, spellCheck = _this$props.spellCheck;
779
- return _react["default"].createElement("div", {
795
+ var _this$props = this.props, classes = _this$props.classes, onDelete = _this$props.onDelete, spellCheck = _this$props.spellCheck, error = _this$props.error;
796
+ return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement("div", {
780
797
  style: {
781
798
  alignItems: 'center',
782
799
  display: 'flex',
783
800
  justifyContent: 'space-between'
784
801
  }
785
802
  }, _react["default"].createElement(_OutlinedInput["default"], {
786
- className: classes.choice,
803
+ className: (0, _classnames["default"])(classes.choice, error && classes.inputError),
787
804
  value: value,
788
805
  onChange: this.onChange,
789
806
  labelWidth: 0,
@@ -793,7 +810,9 @@ const require$$20 = _dll_material_ui__core_styles;
793
810
  "aria-label": "delete",
794
811
  className: classes.deleteBtn,
795
812
  onClick: onDelete
796
- }, _react["default"].createElement(_Delete["default"], null)));
813
+ }, _react["default"].createElement(_Delete["default"], null))), error && _react["default"].createElement("div", {
814
+ className: classes.errorText
815
+ }, error));
797
816
  }
798
817
  }]);
799
818
  return Choice;
@@ -899,7 +918,7 @@ const require$$20 = _dll_material_ui__core_styles;
899
918
  key: "render",
900
919
  value: function render() {
901
920
  var _this3 = this;
902
- var _this$props2 = this.props, classes = _this$props2.classes, selectChoices = _this$props2.selectChoices, maxLength = _this$props2.maxLength, showMaxLength = _this$props2.showMaxLength, value = _this$props2.value, spellCheck = _this$props2.spellCheck;
921
+ var _this$props2 = this.props, classes = _this$props2.classes, selectChoices = _this$props2.selectChoices, maxLength = _this$props2.maxLength, showMaxLength = _this$props2.showMaxLength, value = _this$props2.value, spellCheck = _this$props2.spellCheck, errors = _this$props2.errors;
903
922
  var choices = this.state.choices;
904
923
  var minLength = this.getChoicesMaxLength();
905
924
  return _react["default"].createElement("div", {
@@ -936,7 +955,9 @@ const require$$20 = _dll_material_ui__core_styles;
936
955
  variant: "contained",
937
956
  color: "primary",
938
957
  onClick: this.onAddChoice
939
- }, "Add"))), _react["default"].createElement("div", {
958
+ }, "Add"))), errors && errors[0] && _react["default"].createElement("div", {
959
+ className: classes.errorText
960
+ }, errors[0]), _react["default"].createElement("div", {
940
961
  className: classes.altChoices
941
962
  }, choices && choices.map(function (c, index) {
942
963
  return index > 0 && _react["default"].createElement(Choice, {
@@ -949,7 +970,8 @@ const require$$20 = _dll_material_ui__core_styles;
949
970
  onDelete: function onDelete() {
950
971
  return _this3.onRemoveChoice(c);
951
972
  },
952
- spellCheck: spellCheck
973
+ spellCheck: spellCheck,
974
+ error: errors && errors[index]
953
975
  });
954
976
  })));
955
977
  }
@@ -1157,13 +1179,14 @@ const {cloneDeep: require$$14$1} = _dll_lodash;
1157
1179
  value: function render() {
1158
1180
  var _this2 = this;
1159
1181
  var choices = this.state.choices;
1160
- var _this$props2 = this.props, _this$props2$model = _this$props2.model, maxLengthPerChoice = _this$props2$model.maxLengthPerChoice, maxLengthPerChoiceEnabled = _this$props2$model.maxLengthPerChoiceEnabled, spellCheck = _this$props2.spellCheck;
1182
+ var _this$props2 = this.props, _this$props2$model = _this$props2.model, maxLengthPerChoice = _this$props2$model.maxLengthPerChoice, maxLengthPerChoiceEnabled = _this$props2$model.maxLengthPerChoiceEnabled, spellCheck = _this$props2.spellCheck, choicesErrors = _this$props2.choicesErrors;
1161
1183
  return _react["default"].createElement("div", null, (0, _map["default"])(choices, function (c, key) {
1162
1184
  if (c && (maxLengthPerChoiceEnabled || c.length > 1)) {
1163
1185
  var selected = _this2.state.values[key];
1164
1186
  return _react["default"].createElement(_alternateSection["default"], {
1165
1187
  key: key,
1166
1188
  value: selected && selected.value,
1189
+ errors: choicesErrors && choicesErrors[key],
1167
1190
  onSelect: function onSelect(choice) {
1168
1191
  return _this2.onSectionSelect(choice, key);
1169
1192
  },
@@ -1212,6 +1235,17 @@ const {cloneDeep: require$$14$1} = _dll_lodash;
1212
1235
  exports["default"] = _default;
1213
1236
  })(alternateResponses);
1214
1237
  getDefaultExportFromCjs(alternateResponses);
1238
+ var utils = {};
1239
+ Object.defineProperty(utils, "__esModule", {
1240
+ value: true
1241
+ });
1242
+ utils.generateValidationMessage = void 0;
1243
+ var generateValidationMessage = function generateValidationMessage(config) {
1244
+ var maxResponseAreas = config.maxResponseAreas;
1245
+ var responseAreasMessage = '\nThe response area content should ' + 'not be empty and should be unique.\nThere should be at least 1 ' + (maxResponseAreas ? ("and at most ").concat(maxResponseAreas, " ") : '') + 'response area' + (maxResponseAreas ? 's' : '') + ' defined.';
1246
+ return 'Validation requirements:' + responseAreasMessage;
1247
+ };
1248
+ utils.generateValidationMessage = generateValidationMessage;
1215
1249
  const require$$10$1 = _dll_react;
1216
1250
  const require$$11$1 = _dll_prop_types;
1217
1251
  const {cloneDeep: require$$12$1} = _dll_lodash;
@@ -1220,6 +1254,8 @@ const {pick: require$$14} = _dll_lodash;
1220
1254
  const {throttle: require$$15} = _dll_lodash;
1221
1255
  const require$$18 = _dll_material_ui__core_styles;
1222
1256
  const {Typography: require$$19} = _dll_material_ui__core;
1257
+ const {Tooltip: require$$21} = _dll_material_ui__core;
1258
+ const {Info: require$$20} = _dll_material_ui__icons;
1223
1259
  const require$$16 = _dll_pie_lib__editable_html;
1224
1260
  const require$$17 = _dll_pie_lib__config_ui;
1225
1261
  (function (exports) {
@@ -1247,9 +1283,12 @@ const require$$17 = _dll_pie_lib__config_ui;
1247
1283
  var _configUi = require$$17;
1248
1284
  var _styles = require$$18;
1249
1285
  var _Typography = _interopRequireDefault(require$$19);
1286
+ var _Info = _interopRequireDefault(require$$20);
1287
+ var _Tooltip = _interopRequireDefault(require$$21);
1250
1288
  var _ecrToolbar = _interopRequireDefault(ecrToolbar);
1251
1289
  var _alternateResponses = _interopRequireDefault(alternateResponses);
1252
1290
  var _markupUtils = markupUtils;
1291
+ var _utils = utils;
1253
1292
  function _getRequireWildcardCache(nodeInterop) {
1254
1293
  if (typeof WeakMap !== "function") return null;
1255
1294
  var cacheBabelInterop = new WeakMap();
@@ -1374,6 +1413,20 @@ const require$$17 = _dll_pie_lib__config_ui;
1374
1413
  fontSize: '16px',
1375
1414
  lineHeight: '19px',
1376
1415
  marginTop: theme.spacing.unit * 4
1416
+ },
1417
+ tooltip: {
1418
+ fontSize: '12px',
1419
+ whiteSpace: 'pre',
1420
+ maxWidth: '500px'
1421
+ },
1422
+ errorText: {
1423
+ fontSize: '12px',
1424
+ color: 'red',
1425
+ padding: '5px 0'
1426
+ },
1427
+ flexContainer: {
1428
+ display: 'flex',
1429
+ alignItems: 'end'
1377
1430
  }
1378
1431
  };
1379
1432
  };
@@ -1543,9 +1596,11 @@ const require$$17 = _dll_pie_lib__config_ui;
1543
1596
  value: function render() {
1544
1597
  var _this2 = this;
1545
1598
  var _this$props7 = this.props, classes = _this$props7.classes, model = _this$props7.model, configuration = _this$props7.configuration, onConfigurationChanged = _this$props7.onConfigurationChanged, imageSupport = _this$props7.imageSupport;
1546
- var _ref = configuration || ({}), _ref$prompt = _ref.prompt, prompt = _ref$prompt === void 0 ? {} : _ref$prompt, _ref$partialScoring = _ref.partialScoring, partialScoring = _ref$partialScoring === void 0 ? {} : _ref$partialScoring, _ref$rationale = _ref.rationale, rationale = _ref$rationale === void 0 ? {} : _ref$rationale, _ref$teacherInstructi = _ref.teacherInstructions, teacherInstructions = _ref$teacherInstructi === void 0 ? {} : _ref$teacherInstructi, _ref$maxLengthPerChoi = _ref.maxLengthPerChoice, maxLengthPerChoice = _ref$maxLengthPerChoi === void 0 ? {} : _ref$maxLengthPerChoi, _ref$spellCheck = _ref.spellCheck, spellCheck = _ref$spellCheck === void 0 ? {} : _ref$spellCheck, _ref$playerSpellCheck = _ref.playerSpellCheck, playerSpellCheck = _ref$playerSpellCheck === void 0 ? {} : _ref$playerSpellCheck;
1547
- var _ref2 = model || ({}), teacherInstructionsEnabled = _ref2.teacherInstructionsEnabled, promptEnabled = _ref2.promptEnabled, rationaleEnabled = _ref2.rationaleEnabled, maxLengthPerChoiceEnabled = _ref2.maxLengthPerChoiceEnabled, spellCheckEnabled = _ref2.spellCheckEnabled;
1599
+ var _ref = configuration || ({}), _ref$prompt = _ref.prompt, prompt = _ref$prompt === void 0 ? {} : _ref$prompt, _ref$partialScoring = _ref.partialScoring, partialScoring = _ref$partialScoring === void 0 ? {} : _ref$partialScoring, _ref$rationale = _ref.rationale, rationale = _ref$rationale === void 0 ? {} : _ref$rationale, _ref$teacherInstructi = _ref.teacherInstructions, teacherInstructions = _ref$teacherInstructi === void 0 ? {} : _ref$teacherInstructi, _ref$maxLengthPerChoi = _ref.maxLengthPerChoice, maxLengthPerChoice = _ref$maxLengthPerChoi === void 0 ? {} : _ref$maxLengthPerChoi, _ref$spellCheck = _ref.spellCheck, spellCheck = _ref$spellCheck === void 0 ? {} : _ref$spellCheck, _ref$playerSpellCheck = _ref.playerSpellCheck, playerSpellCheck = _ref$playerSpellCheck === void 0 ? {} : _ref$playerSpellCheck, maxResponseAreas = _ref.maxResponseAreas;
1600
+ var _ref2 = model || ({}), teacherInstructionsEnabled = _ref2.teacherInstructionsEnabled, promptEnabled = _ref2.promptEnabled, rationaleEnabled = _ref2.rationaleEnabled, maxLengthPerChoiceEnabled = _ref2.maxLengthPerChoiceEnabled, spellCheckEnabled = _ref2.spellCheckEnabled, errors = _ref2.errors;
1548
1601
  var toolbarOpts = {};
1602
+ var _ref3 = errors || ({}), responseAreasError = _ref3.responseAreasError, _ref3$choicesErrors = _ref3.choicesErrors, choicesErrors = _ref3$choicesErrors === void 0 ? {} : _ref3$choicesErrors;
1603
+ var validationMessage = (0, _utils.generateValidationMessage)(configuration);
1549
1604
  switch (model.toolbarEditorPosition) {
1550
1605
  case 'top':
1551
1606
  toolbarOpts.position = 'top';
@@ -1603,9 +1658,27 @@ const require$$17 = _dll_pie_lib__config_ui;
1603
1658
  disableUnderline: true,
1604
1659
  toolbarOpts: toolbarOpts,
1605
1660
  spellCheck: spellCheckEnabled
1606
- })), _react["default"].createElement(_Typography["default"], {
1661
+ })), _react["default"].createElement("div", {
1662
+ className: classes.flexContainer
1663
+ }, _react["default"].createElement(_Typography["default"], {
1607
1664
  className: classes.text
1608
- }, "Define Template, Choices, and Correct Responses"), _react["default"].createElement(_editableHtml["default"], {
1665
+ }, "Define Template, Choices, and Correct Responses"), _react["default"].createElement(_Tooltip["default"], {
1666
+ classes: {
1667
+ tooltip: classes.tooltip
1668
+ },
1669
+ disableFocusListener: true,
1670
+ disableTouchListener: true,
1671
+ placement: 'right',
1672
+ title: validationMessage
1673
+ }, _react["default"].createElement(_Info["default"], {
1674
+ fontSize: 'small',
1675
+ color: 'primary',
1676
+ style: {
1677
+ marginLeft: '5px'
1678
+ }
1679
+ }))), responseAreasError && _react["default"].createElement("div", {
1680
+ className: classes.errorText
1681
+ }, responseAreasError), _react["default"].createElement(_editableHtml["default"], {
1609
1682
  activePlugins: _editableHtml.ALL_PLUGINS,
1610
1683
  toolbarOpts: {
1611
1684
  position: 'top'
@@ -1616,6 +1689,7 @@ const require$$17 = _dll_pie_lib__config_ui;
1616
1689
  options: {
1617
1690
  duplicates: true
1618
1691
  },
1692
+ maxResponseAreas: maxResponseAreas,
1619
1693
  respAreaToolbar: function respAreaToolbar(node, value, onToolbarDone) {
1620
1694
  var model = _this2.props.model;
1621
1695
  var correctChoice = (model.choices[node.data.get('index')] || [])[0];
@@ -1631,6 +1705,9 @@ const require$$17 = _dll_pie_lib__config_ui;
1631
1705
  });
1632
1706
  };
1633
1707
  },
1708
+ error: function error() {
1709
+ return choicesErrors;
1710
+ },
1634
1711
  onHandleAreaChange: this.onHandleAreaChange
1635
1712
  },
1636
1713
  className: classes.markup,
@@ -1639,7 +1716,8 @@ const require$$17 = _dll_pie_lib__config_ui;
1639
1716
  imageSupport: imageSupport,
1640
1717
  onBlur: this.onBlur,
1641
1718
  disabled: false,
1642
- highlightShape: false
1719
+ highlightShape: false,
1720
+ error: responseAreasError
1643
1721
  }), !(0, _isEmpty["default"])(model.choices) && _react["default"].createElement(_Typography["default"], {
1644
1722
  className: classes.text
1645
1723
  }, ("Define Alternates ").concat(maxLengthPerChoiceEnabled ? 'and Character Limits' : '')), _react["default"].createElement(_alternateResponses["default"], {
@@ -1647,7 +1725,8 @@ const require$$17 = _dll_pie_lib__config_ui;
1647
1725
  onChange: this.onResponsesChanged,
1648
1726
  onLengthChange: this.onLengthChanged,
1649
1727
  maxLengthPerChoiceEnabled: maxLengthPerChoiceEnabled,
1650
- spellCheck: spellCheckEnabled
1728
+ spellCheck: spellCheckEnabled,
1729
+ choicesErrors: choicesErrors
1651
1730
  }), rationaleEnabled && _react["default"].createElement(_configUi.InputContainer, {
1652
1731
  label: rationale.label,
1653
1732
  className: classes.promptHolder
@@ -1767,7 +1846,8 @@ var defaults = {};
1767
1846
  maxLengthPerChoice: {
1768
1847
  settings: true,
1769
1848
  label: 'Maximum Length Per Choice'
1770
- }
1849
+ },
1850
+ maxResponseAreas: 10
1771
1851
  }
1772
1852
  };
1773
1853
  exports["default"] = _default;
@@ -21343,4 +21343,48 @@ const createCorrectResponseSession = (question, env) => {
21343
21343
  });
21344
21344
  };
21345
21345
 
21346
- export { createCorrectResponseSession, getScore, model, normalize, outcome, prepareChoice, prepareVal };
21346
+ const validate = (model = {}, config = {}) => {
21347
+ const { choices, markup } = model;
21348
+ const { maxResponseAreas } = config;
21349
+ const allChoicesErrors = {};
21350
+
21351
+ Object.entries(choices || {}).forEach(([key, values]) => {
21352
+ const reversedChoices = [...values || []].reverse();
21353
+ const choicesErrors = {};
21354
+
21355
+ reversedChoices.forEach((choice, index) => {
21356
+ const { value, label } = choice;
21357
+
21358
+ if (label === '' || label === '<div></div>') {
21359
+ choicesErrors[value] = 'Content should not be empty.';
21360
+ } else {
21361
+ const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);
21362
+
21363
+ if (identicalAnswer) {
21364
+ choicesErrors[value] = 'Content should be unique.';
21365
+ }
21366
+ }
21367
+ });
21368
+
21369
+ if (!isEmpty_1(choicesErrors)) {
21370
+ allChoicesErrors[key] = choicesErrors;
21371
+ }
21372
+ });
21373
+
21374
+ const errors = {};
21375
+ const nbOfResponseAreas = (markup.match(/\{\{(\d+)\}\}/g) || []).length;
21376
+
21377
+ if (nbOfResponseAreas > maxResponseAreas) {
21378
+ errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;
21379
+ } else if (nbOfResponseAreas < 1) {
21380
+ errors.responseAreasError = 'There should be at least 1 response area defined.';
21381
+ }
21382
+
21383
+ if (!isEmpty_1(allChoicesErrors)) {
21384
+ errors.choicesErrors = allChoicesErrors;
21385
+ }
21386
+
21387
+ return errors;
21388
+ };
21389
+
21390
+ export { createCorrectResponseSession, getScore, model, normalize, outcome, prepareChoice, prepareVal, validate };