@pie-element/categorize 8.21.3-next.0 → 8.21.3-next.4

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.
@@ -35,6 +35,8 @@ var _categorize = require("@pie-lib/pie-toolbox/categorize");
35
35
 
36
36
  var _RowLabel = require("./RowLabel");
37
37
 
38
+ var _utils = require("../../utils");
39
+
38
40
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
39
41
 
40
42
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -88,6 +90,8 @@ var AlternateResponses = /*#__PURE__*/function (_React$Component) {
88
90
  _this$props$model = _this$props.model,
89
91
  correctResponse = _this$props$model.correctResponse,
90
92
  choices = _this$props$model.choices,
93
+ _this$props$model$max = _this$props$model.maxChoicesPerCategory,
94
+ maxChoicesPerCategory = _this$props$model$max === void 0 ? 0 : _this$props$model$max,
91
95
  onModelChanged = _this$props.onModelChanged;
92
96
  var choice = choices.find(function (c) {
93
97
  return c.id === addedChoice.id;
@@ -132,8 +136,11 @@ var AlternateResponses = /*#__PURE__*/function (_React$Component) {
132
136
 
133
137
  return a;
134
138
  });
139
+ var maxCategoryChoices = (0, _utils.getMaxCategoryChoices)(_this.props.model); // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
140
+
135
141
  onModelChanged({
136
- correctResponse: correctResponse
142
+ correctResponse: correctResponse,
143
+ maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
137
144
  });
138
145
  });
139
146
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moveChoice", function (choiceId, from, to, choiceIndex, alternateIndex) {
@@ -144,32 +151,27 @@ var AlternateResponses = /*#__PURE__*/function (_React$Component) {
144
151
  var _ref = model || {},
145
152
  choices = _ref.choices,
146
153
  _ref$correctResponse = _ref.correctResponse,
147
- correctResponse = _ref$correctResponse === void 0 ? [] : _ref$correctResponse;
154
+ correctResponse = _ref$correctResponse === void 0 ? [] : _ref$correctResponse,
155
+ _ref$maxChoicesPerCat = _ref.maxChoicesPerCategory,
156
+ maxChoicesPerCategory = _ref$maxChoicesPerCat === void 0 ? 0 : _ref$maxChoicesPerCat;
148
157
 
149
158
  var choice = (choices || []).find(function (choice) {
150
159
  return choice.id === choiceId;
151
160
  });
152
161
  correctResponse = (0, _categorize.moveChoiceToAlternate)(choiceId, from, to, choiceIndex, correctResponse, alternateIndex, choice === null || choice === void 0 ? void 0 : choice.categoryCount);
162
+ var maxCategoryChoices = (0, _utils.getMaxCategoryChoices)(_this.props.model); // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
163
+
153
164
  onModelChanged({
154
- correctResponse: correctResponse
165
+ correctResponse: correctResponse,
166
+ maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
155
167
  });
156
168
  });
157
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoiceFromCategory", function (category, choice) {
169
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoiceFromCategory", function (category, choice, choiceIndex) {
158
170
  var _this$props3 = _this.props,
171
+ model = _this$props3.model,
159
172
  altIndex = _this$props3.altIndex,
160
- correctResponse = _this$props3.model.correctResponse,
161
173
  onModelChanged = _this$props3.onModelChanged;
162
- correctResponse.forEach(function (a) {
163
- if (a.category === category.id) {
164
- if (a.alternateResponses[altIndex]) {
165
- a.alternateResponses[altIndex] = a.alternateResponses[altIndex].filter(function (altId) {
166
- return altId !== choice.id;
167
- });
168
- }
169
- }
170
-
171
- return a;
172
- });
174
+ var correctResponse = (0, _categorize.removeChoiceFromAlternate)(choice.id, category.id, choiceIndex, altIndex, model.correctResponse);
173
175
  onModelChanged({
174
176
  correctResponse: correctResponse
175
177
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/design/categories/alternateResponses.jsx"],"names":["styles","theme","categories","marginBottom","spacing","unit","categoriesHolder","display","gridRowGap","gridColumnGap","row","gridTemplateColumns","alignItems","width","marginTop","rowLabel","gridColumn","rowLabelHolder","AlternateResponses","addedChoice","categoryId","props","altIndex","model","correctResponse","choices","onModelChanged","choice","find","c","id","forEach","a","category","alternateResponses","push","categoryCount","reduce","acc","currentValue","foundIndex","findIndex","filter","choiceId","from","to","choiceIndex","alternateIndex","altId","configuration","classes","className","imageSupport","spellCheck","uploadSoundSupport","toolbarOpts","defaultImageMaxHeight","defaultImageMaxWidth","mathMlOptions","categoriesPerRow","errors","rowLabels","duplicateAlternate","maxImageWidth","maxImageHeight","holderStyle","isDuplicated","index","map","hasRowLabel","rowIndex","val","changeRowLabel","addChoiceToCategory","deleteChoiceFromCategory","moveChoice","React","Component","PropTypes","number","isRequired","object","shape","add","func","string","array","bool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB;AADzB,KADa;AAIzBC,IAAAA,gBAAgB,EAAE;AAChBC,MAAAA,OAAO,EAAE,MADO;AAEhBC,MAAAA,UAAU,YAAKP,KAAK,CAACG,OAAN,CAAcC,IAAnB,O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AAA,qBAAqB,EAAEsB,sBAAUC,MAVhB;AAWjBtB,EAAAA,oBAAoB,EAAEqB,sBAAUC,MAXf;AAYjBrD,EAAAA,cAAc,EAAEoD,sBAAUM,IAZT;AAajB7D,EAAAA,KAAK,EAAEuD,sBAAUG,MAAV,CAAiBD,UAbP;AAcjB1B,EAAAA,kBAAkB,EAAEwB,sBAAUI,KAAV,CAAgB;AAClCC,IAAAA,GAAG,EAAEL,sBAAUM,IAAV,CAAeJ,UADc;AAElC,cAAQF,sBAAUM,IAAV,CAAeJ;AAFW,GAAhB,CAdH;AAkBjBzB,EAAAA,WAAW,EAAEuB,sBAAUG,MAlBN;AAmBjB5B,EAAAA,UAAU,EAAEyB,sBAAUS;AAnBL,C;;eAuLN,wBAAWvF,MAAX,EAAmBkB,kBAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport Category from './category';\nimport { moveChoiceToAlternate } from '@pie-lib/pie-toolbox/categorize';\nimport { RowLabel } from './RowLabel';\n\nconst styles = (theme) => ({\n categories: {\n marginBottom: theme.spacing.unit * 2.5,\n },\n categoriesHolder: {\n display: 'grid',\n gridRowGap: `${theme.spacing.unit}px`,\n gridColumnGap: `${theme.spacing.unit}px`,\n },\n row: {\n display: 'grid',\n gridTemplateColumns: 'repeat(2, 1fr)',\n gridColumnGap: `${theme.spacing.unit}px`,\n alignItems: 'baseline',\n width: '100%',\n marginTop: theme.spacing.unit,\n marginBottom: 2 * theme.spacing.unit,\n },\n rowLabel: {\n gridColumn: '1/3',\n },\n rowLabelHolder: {\n width: '100%',\n },\n});\n\nexport class AlternateResponses extends React.Component {\n static propTypes = {\n altIndex: PropTypes.number.isRequired,\n configuration: PropTypes.object,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n categories: PropTypes.array,\n defaultImageMaxHeight: PropTypes.number,\n defaultImageMaxWidth: PropTypes.number,\n onModelChanged: PropTypes.func,\n model: PropTypes.object.isRequired,\n uploadSoundSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n toolbarOpts: PropTypes.object,\n spellCheck: PropTypes.bool,\n };\n\n addChoiceToCategory = (addedChoice, categoryId) => {\n const {\n altIndex,\n model: { correctResponse, choices },\n onModelChanged,\n } = this.props;\n\n const choice = choices.find((c) => c.id === addedChoice.id);\n\n correctResponse.forEach((a) => {\n if (a.category === categoryId) {\n a.alternateResponses = a.alternateResponses || [];\n\n if (!a.alternateResponses[altIndex]) {\n a.alternateResponses[altIndex] = [];\n }\n\n a.alternateResponses[altIndex].push(addedChoice.id);\n if (choice.categoryCount && choice.categoryCount !== 0) {\n a.alternateResponses[altIndex] = a.alternateResponses[altIndex].reduce((acc, currentValue) => {\n if (currentValue === choice.id) {\n const foundIndex = acc.findIndex((c) => c === choice.id);\n if (foundIndex === -1) {\n acc.push(currentValue);\n }\n } else {\n acc.push(currentValue);\n }\n\n return acc;\n }, []);\n }\n\n return a;\n } else {\n if (a.alternateResponses[altIndex] && choice.categoryCount !== 0) {\n a.alternateResponses[altIndex] = a.alternateResponses[altIndex].filter((c) => c !== addedChoice.id);\n return a;\n }\n }\n\n return a;\n });\n\n onModelChanged({ correctResponse });\n };\n\n moveChoice = (choiceId, from, to, choiceIndex, alternateIndex) => {\n const { model, onModelChanged } = this.props;\n let { choices, correctResponse = [] } = model || {};\n const choice = (choices || []).find((choice) => choice.id === choiceId);\n correctResponse = moveChoiceToAlternate(\n choiceId,\n from,\n to,\n choiceIndex,\n correctResponse,\n alternateIndex,\n choice?.categoryCount,\n );\n\n onModelChanged({ correctResponse });\n };\n\n deleteChoiceFromCategory = (category, choice) => {\n const {\n altIndex,\n model: { correctResponse },\n onModelChanged,\n } = this.props;\n\n correctResponse.forEach((a) => {\n if (a.category === category.id) {\n if (a.alternateResponses[altIndex]) {\n a.alternateResponses[altIndex] = a.alternateResponses[altIndex].filter((altId) => altId !== choice.id);\n }\n }\n\n return a;\n });\n\n onModelChanged({ correctResponse });\n };\n\n render() {\n const {\n altIndex,\n model,\n configuration,\n classes,\n className,\n categories,\n imageSupport,\n spellCheck,\n uploadSoundSupport,\n toolbarOpts,\n defaultImageMaxHeight,\n defaultImageMaxWidth,\n mathMlOptions = {},\n } = this.props;\n const { categoriesPerRow, errors, rowLabels } = model;\n const { duplicateAlternate } = errors || {};\n const { maxImageWidth = {}, maxImageHeight = {} } = configuration || {};\n\n const holderStyle = {\n gridTemplateColumns: `repeat(${categoriesPerRow}, 1fr)`,\n };\n const isDuplicated = duplicateAlternate ? duplicateAlternate.index === altIndex : false;\n\n return (\n <div className={classNames(classes.categories, className)}>\n <div className={classes.categoriesHolder} style={holderStyle}>\n {categories.map((category, index) => {\n const hasRowLabel = index % categoriesPerRow === 0;\n const rowIndex = index / categoriesPerRow;\n\n return (\n <React.Fragment key={index}>\n {hasRowLabel && (\n <RowLabel\n categoriesPerRow={categoriesPerRow}\n disabled={true}\n rowIndex={rowIndex}\n markup={rowLabels[rowIndex] || ''}\n onChange={(val) => this.changeRowLabel(val, rowIndex)}\n imageSupport={imageSupport}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n maxImageWidth={(maxImageWidth && maxImageWidth.rowLabel) || defaultImageMaxWidth}\n maxImageHeight={(maxImageHeight && maxImageHeight.rowLabel) || defaultImageMaxHeight}\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n configuration={configuration}\n />\n )}\n\n <Category\n key={index}\n alternateResponseIndex={altIndex}\n imageSupport={imageSupport}\n isDuplicated={isDuplicated && duplicateAlternate.category === category.id}\n category={category}\n spellCheck={spellCheck}\n onAddChoice={this.addChoiceToCategory}\n onDeleteChoice={(choice, choiceIndex) => this.deleteChoiceFromCategory(category, choice, choiceIndex)}\n onMoveChoice={(choiceId, from, to, choiceIndex, alternateIndex) =>\n this.moveChoice(choiceId, from, to, choiceIndex, alternateIndex)\n }\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n configuration={configuration}\n />\n </React.Fragment>\n );\n })}\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(AlternateResponses);\n"],"file":"alternateResponses.js"}
1
+ {"version":3,"sources":["../../../src/design/categories/alternateResponses.jsx"],"names":["styles","theme","categories","marginBottom","spacing","unit","categoriesHolder","display","gridRowGap","gridColumnGap","row","gridTemplateColumns","alignItems","width","marginTop","rowLabel","gridColumn","rowLabelHolder","AlternateResponses","addedChoice","categoryId","props","altIndex","model","correctResponse","choices","maxChoicesPerCategory","onModelChanged","choice","find","c","id","forEach","a","category","alternateResponses","push","categoryCount","reduce","acc","currentValue","foundIndex","findIndex","filter","maxCategoryChoices","choiceId","from","to","choiceIndex","alternateIndex","configuration","classes","className","imageSupport","spellCheck","uploadSoundSupport","toolbarOpts","defaultImageMaxHeight","defaultImageMaxWidth","mathMlOptions","categoriesPerRow","errors","rowLabels","duplicateAlternate","maxImageWidth","maxImageHeight","holderStyle","isDuplicated","index","map","hasRowLabel","rowIndex","val","changeRowLabel","addChoiceToCategory","deleteChoiceFromCategory","moveChoice","React","Component","PropTypes","number","isRequired","object","shape","add","func","string","array","bool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB;AADzB,KADa;AAIzBC,IAAAA,gBAAgB,EAAE;AAChBC,MAAAA,OAAO,EAAE,MADO;AAEhBC,MAAAA,UAAU,YAAKP,KAAK,CAACG,OAAN,CAAcC,IAAnB,OAFM;AAGhBI,MAAAA,aAAa,YAAKR,KAAK,CAACG,OAAN,CAAcC,IAAnB;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B,cAAQF,sBAAUM,IAAV,CAAeJ;AAFK,GAAhB,CAHG;AAOjB9B,EAAAA,OAAO,EAAE4B,sBAAUG,MAAV,CAAiBD,UAPT;AAQjB7B,EAAAA,SAAS,EAAE2B,sBAAUO,MARJ;AASjBpF,EAAAA,UAAU,EAAE6E,sBAAUQ,KATL;AAUjB9B,EAAAA,qBAAqB,EAAEsB,sBAAUC,MAVhB;AAWjBtB,EAAAA,oBAAoB,EAAEqB,sBAAUC,MAXf;AAYjBrD,EAAAA,cAAc,EAAEoD,sBAAUM,IAZT;AAajB9D,EAAAA,KAAK,EAAEwD,sBAAUG,MAAV,CAAiBD,UAbP;AAcjB1B,EAAAA,kBAAkB,EAAEwB,sBAAUI,KAAV,CAAgB;AAClCC,IAAAA,GAAG,EAAEL,sBAAUM,IAAV,CAAeJ,UADc;AAElC,cAAQF,sBAAUM,IAAV,CAAeJ;AAFW,GAAhB,CAdH;AAkBjBzB,EAAAA,WAAW,EAAEuB,sBAAUG,MAlBN;AAmBjB5B,EAAAA,UAAU,EAAEyB,sBAAUS;AAnBL,C;;eAiMN,wBAAWxF,MAAX,EAAmBkB,kBAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport Category from './category';\nimport { moveChoiceToAlternate, removeChoiceFromAlternate } from '@pie-lib/pie-toolbox/categorize';\nimport { RowLabel } from './RowLabel';\nimport { getMaxCategoryChoices } from '../../utils';\n\nconst styles = (theme) => ({\n categories: {\n marginBottom: theme.spacing.unit * 2.5,\n },\n categoriesHolder: {\n display: 'grid',\n gridRowGap: `${theme.spacing.unit}px`,\n gridColumnGap: `${theme.spacing.unit}px`,\n },\n row: {\n display: 'grid',\n gridTemplateColumns: 'repeat(2, 1fr)',\n gridColumnGap: `${theme.spacing.unit}px`,\n alignItems: 'baseline',\n width: '100%',\n marginTop: theme.spacing.unit,\n marginBottom: 2 * theme.spacing.unit,\n },\n rowLabel: {\n gridColumn: '1/3',\n },\n rowLabelHolder: {\n width: '100%',\n },\n});\n\nexport class AlternateResponses extends React.Component {\n static propTypes = {\n altIndex: PropTypes.number.isRequired,\n configuration: PropTypes.object,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n categories: PropTypes.array,\n defaultImageMaxHeight: PropTypes.number,\n defaultImageMaxWidth: PropTypes.number,\n onModelChanged: PropTypes.func,\n model: PropTypes.object.isRequired,\n uploadSoundSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n toolbarOpts: PropTypes.object,\n spellCheck: PropTypes.bool,\n };\n\n addChoiceToCategory = (addedChoice, categoryId) => {\n const {\n altIndex,\n model: { correctResponse, choices, maxChoicesPerCategory = 0 },\n onModelChanged,\n } = this.props;\n\n const choice = choices.find((c) => c.id === addedChoice.id);\n\n correctResponse.forEach((a) => {\n if (a.category === categoryId) {\n a.alternateResponses = a.alternateResponses || [];\n\n if (!a.alternateResponses[altIndex]) {\n a.alternateResponses[altIndex] = [];\n }\n\n a.alternateResponses[altIndex].push(addedChoice.id);\n if (choice.categoryCount && choice.categoryCount !== 0) {\n a.alternateResponses[altIndex] = a.alternateResponses[altIndex].reduce((acc, currentValue) => {\n if (currentValue === choice.id) {\n const foundIndex = acc.findIndex((c) => c === choice.id);\n if (foundIndex === -1) {\n acc.push(currentValue);\n }\n } else {\n acc.push(currentValue);\n }\n\n return acc;\n }, []);\n }\n\n return a;\n } else {\n if (a.alternateResponses[altIndex] && choice.categoryCount !== 0) {\n a.alternateResponses[altIndex] = a.alternateResponses[altIndex].filter((c) => c !== addedChoice.id);\n return a;\n }\n }\n\n return a;\n });\n\n const maxCategoryChoices = getMaxCategoryChoices(this.props.model);\n // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated\n onModelChanged({\n correctResponse,\n maxChoicesPerCategory:\n maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices\n ? maxChoicesPerCategory + 1\n : maxChoicesPerCategory,\n });\n };\n\n moveChoice = (choiceId, from, to, choiceIndex, alternateIndex) => {\n const { model, onModelChanged } = this.props;\n let { choices, correctResponse = [], maxChoicesPerCategory = 0 } = model || {};\n const choice = (choices || []).find((choice) => choice.id === choiceId);\n correctResponse = moveChoiceToAlternate(\n choiceId,\n from,\n to,\n choiceIndex,\n correctResponse,\n alternateIndex,\n choice?.categoryCount,\n );\n\n const maxCategoryChoices = getMaxCategoryChoices(this.props.model);\n // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated\n onModelChanged({\n correctResponse,\n maxChoicesPerCategory:\n maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices\n ? maxChoicesPerCategory + 1\n : maxChoicesPerCategory,\n });\n };\n\n deleteChoiceFromCategory = (category, choice, choiceIndex) => {\n const { model, altIndex, onModelChanged } = this.props;\n\n const correctResponse = removeChoiceFromAlternate(\n choice.id,\n category.id,\n choiceIndex,\n altIndex,\n model.correctResponse,\n );\n\n onModelChanged({ correctResponse });\n };\n\n render() {\n const {\n altIndex,\n model,\n configuration,\n classes,\n className,\n categories,\n imageSupport,\n spellCheck,\n uploadSoundSupport,\n toolbarOpts,\n defaultImageMaxHeight,\n defaultImageMaxWidth,\n mathMlOptions = {},\n } = this.props;\n const { categoriesPerRow, errors, rowLabels } = model;\n const { duplicateAlternate } = errors || {};\n const { maxImageWidth = {}, maxImageHeight = {} } = configuration || {};\n\n const holderStyle = {\n gridTemplateColumns: `repeat(${categoriesPerRow}, 1fr)`,\n };\n const isDuplicated = duplicateAlternate ? duplicateAlternate.index === altIndex : false;\n\n return (\n <div className={classNames(classes.categories, className)}>\n <div className={classes.categoriesHolder} style={holderStyle}>\n {categories.map((category, index) => {\n const hasRowLabel = index % categoriesPerRow === 0;\n const rowIndex = index / categoriesPerRow;\n\n return (\n <React.Fragment key={index}>\n {hasRowLabel && (\n <RowLabel\n categoriesPerRow={categoriesPerRow}\n disabled={true}\n rowIndex={rowIndex}\n markup={rowLabels[rowIndex] || ''}\n onChange={(val) => this.changeRowLabel(val, rowIndex)}\n imageSupport={imageSupport}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n maxImageWidth={(maxImageWidth && maxImageWidth.rowLabel) || defaultImageMaxWidth}\n maxImageHeight={(maxImageHeight && maxImageHeight.rowLabel) || defaultImageMaxHeight}\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n configuration={configuration}\n />\n )}\n\n <Category\n key={index}\n alternateResponseIndex={altIndex}\n imageSupport={imageSupport}\n isDuplicated={isDuplicated && duplicateAlternate.category === category.id}\n category={category}\n spellCheck={spellCheck}\n onAddChoice={this.addChoiceToCategory}\n onDeleteChoice={(choice, choiceIndex) => this.deleteChoiceFromCategory(category, choice, choiceIndex)}\n onMoveChoice={(choiceId, from, to, choiceIndex, alternateIndex) =>\n this.moveChoice(choiceId, from, to, choiceIndex, alternateIndex)\n }\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n configuration={configuration}\n />\n </React.Fragment>\n );\n })}\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(AlternateResponses);\n"],"file":"alternateResponses.js"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.multiplePlacements = exports.getMaxCategoryChoices = exports.generateValidationMessage = void 0;
6
+ exports.multiplePlacements = exports.maxLength = exports.getMaxCategoryChoices = exports.generateValidationMessage = void 0;
7
7
 
8
8
  var generateValidationMessage = function generateValidationMessage(config) {
9
9
  var _ref = config || {},
@@ -22,17 +22,30 @@ var multiplePlacements = {
22
22
  enabled: 'Yes',
23
23
  disabled: 'No',
24
24
  perChoice: 'Set Per Choice'
25
- };
25
+ }; // Find the length of the largest array from an array
26
+
26
27
  exports.multiplePlacements = multiplePlacements;
27
28
 
29
+ var maxLength = function maxLength(array) {
30
+ return (array || []).reduce(function (max, arr) {
31
+ return Math.max(max, arr.length);
32
+ }, 0);
33
+ };
34
+
35
+ exports.maxLength = maxLength;
36
+
28
37
  var getMaxCategoryChoices = function getMaxCategoryChoices(model) {
29
38
  var _ref2 = model || {},
30
39
  _ref2$correctResponse = _ref2.correctResponse,
31
40
  correctResponse = _ref2$correctResponse === void 0 ? [] : _ref2$correctResponse;
32
41
 
33
42
  return correctResponse.reduce(function (max, correctRes) {
34
- var choicesLength = correctRes.choices.length;
35
- return choicesLength > max ? choicesLength : max;
43
+ var _correctRes$choices;
44
+
45
+ var correctRespLength = (correctRes === null || correctRes === void 0 ? void 0 : (_correctRes$choices = correctRes.choices) === null || _correctRes$choices === void 0 ? void 0 : _correctRes$choices.length) || 0;
46
+ var alternates = (correctRes === null || correctRes === void 0 ? void 0 : correctRes.alternateResponses) || [];
47
+ var maxChoices = Math.max(correctRespLength, maxLength(alternates));
48
+ return maxChoices > max ? maxChoices : max;
36
49
  }, 0);
37
50
  };
38
51
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["generateValidationMessage","config","minChoices","maxChoices","maxCategories","validationMessage","multiplePlacements","enabled","disabled","perChoice","getMaxCategoryChoices","model","correctResponse","reduce","max","correctRes","choicesLength","choices","length"],"mappings":";;;;;;;AAAO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,CAACC,MAAD,EAAY;AACnD,aAAgDA,MAAM,IAAI,EAA1D;AAAA,MAAMC,UAAN,QAAMA,UAAN;AAAA,MAAkBC,UAAlB,QAAkBA,UAAlB;AAAA,MAA8BC,aAA9B,QAA8BA,aAA9B;;AACAF,EAAAA,UAAU,GAAGA,UAAU,IAAI,CAA3B;AAEA,MAAMG,iBAAiB,GACrB,kCACA,iEADA,IAECD,aAAa,yBAAkBA,aAAlB,SAAqC,EAFnD,IAGA,UAHA,IAICA,aAAa,GAAG,GAAH,GAAS,EAJvB,IAKA,WALA,IAMCF,UAAU,wCAAiCA,UAAjC,yBAAiE,EAN5E,KAOCC,UAAU,4BAAqBA,UAArB,mCAA+D,EAP1E,IAQA,mEATF;AAWA,SAAO,6BAA6BE,iBAApC;AACD,CAhBM,C,CAkBP;;;;AACO,IAAMC,kBAAkB,GAAG;AAAEC,EAAAA,OAAO,EAAE,KAAX;AAAkBC,EAAAA,QAAQ,EAAE,IAA5B;AAAkCC,EAAAA,SAAS,EAAE;AAA7C,CAA3B;;;AAEA,IAAOC,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,KAAD,EAAW;AAC/C,cAAiCA,KAAK,IAAI,EAA1C;AAAA,oCAAQC,eAAR;AAAA,MAAQA,eAAR,sCAA0B,EAA1B;;AACA,SAAOA,eAAe,CAACC,MAAhB,CAAuB,UAACC,GAAD,EAAMC,UAAN,EAAqB;AACjD,QAAMC,aAAa,GAAGD,UAAU,CAACE,OAAX,CAAmBC,MAAzC;AACA,WAAOF,aAAa,GAAGF,GAAhB,GAAsBE,aAAtB,GAAsCF,GAA7C;AACD,GAHM,EAGJ,CAHI,CAAP;AAID,CANM","sourcesContent":["export const generateValidationMessage = (config) => {\n let { minChoices, maxChoices, maxCategories } = config || {};\n minChoices = minChoices || 1;\n\n const validationMessage =\n '\\nThe choices content should ' +\n 'not be empty and should be unique.\\nThere should be at least 1 ' +\n (maxCategories ? `and at most ${maxCategories} ` : '') +\n 'category' +\n (maxCategories ? 's' : '') +\n ' defined.' +\n (minChoices ? `\\nThere should be at least ${minChoices} choices defined.` : '') +\n (maxChoices ? `\\nNo more than ${maxChoices} choices should be defined.` : '') +\n '\\nAt least one token should be assigned to at least one category.';\n\n return 'Validation requirements:' + validationMessage;\n};\n\n// used in controller too, for consistency modify it there too\nexport const multiplePlacements = { enabled: 'Yes', disabled: 'No', perChoice: 'Set Per Choice' };\n\nexport const getMaxCategoryChoices = (model) => {\n const { correctResponse = [] } = model || {};\n return correctResponse.reduce((max, correctRes) => {\n const choicesLength = correctRes.choices.length;\n return choicesLength > max ? choicesLength : max;\n }, 0);\n};\n"],"file":"utils.js"}
1
+ {"version":3,"sources":["../src/utils.js"],"names":["generateValidationMessage","config","minChoices","maxChoices","maxCategories","validationMessage","multiplePlacements","enabled","disabled","perChoice","maxLength","array","reduce","max","arr","Math","length","getMaxCategoryChoices","model","correctResponse","correctRes","correctRespLength","choices","alternates","alternateResponses"],"mappings":";;;;;;;AAAO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,CAACC,MAAD,EAAY;AACnD,aAAgDA,MAAM,IAAI,EAA1D;AAAA,MAAMC,UAAN,QAAMA,UAAN;AAAA,MAAkBC,UAAlB,QAAkBA,UAAlB;AAAA,MAA8BC,aAA9B,QAA8BA,aAA9B;;AACAF,EAAAA,UAAU,GAAGA,UAAU,IAAI,CAA3B;AAEA,MAAMG,iBAAiB,GACrB,kCACA,iEADA,IAECD,aAAa,yBAAkBA,aAAlB,SAAqC,EAFnD,IAGA,UAHA,IAICA,aAAa,GAAG,GAAH,GAAS,EAJvB,IAKA,WALA,IAMCF,UAAU,wCAAiCA,UAAjC,yBAAiE,EAN5E,KAOCC,UAAU,4BAAqBA,UAArB,mCAA+D,EAP1E,IAQA,mEATF;AAWA,SAAO,6BAA6BE,iBAApC;AACD,CAhBM,C,CAkBP;;;;AACO,IAAMC,kBAAkB,GAAG;AAAEC,EAAAA,OAAO,EAAE,KAAX;AAAkBC,EAAAA,QAAQ,EAAE,IAA5B;AAAkCC,EAAAA,SAAS,EAAE;AAA7C,CAA3B,C,CAEP;;;;AACO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,KAAD;AAAA,SACvB,CAACA,KAAK,IAAI,EAAV,EAAcC,MAAd,CAAqB,UAACC,GAAD,EAAMC,GAAN,EAAc;AACjC,WAAOC,IAAI,CAACF,GAAL,CAASA,GAAT,EAAcC,GAAG,CAACE,MAAlB,CAAP;AACD,GAFD,EAEG,CAFH,CADuB;AAAA,CAAlB;;;;AAKA,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,KAAD,EAAW;AAC9C,cAAiCA,KAAK,IAAI,EAA1C;AAAA,oCAAQC,eAAR;AAAA,MAAQA,eAAR,sCAA0B,EAA1B;;AACA,SAAOA,eAAe,CAACP,MAAhB,CAAuB,UAACC,GAAD,EAAMO,UAAN,EAAqB;AAAA;;AACjD,QAAMC,iBAAiB,GAAG,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,mCAAAA,UAAU,CAAEE,OAAZ,4EAAqBN,MAArB,KAA+B,CAAzD;AACA,QAAMO,UAAU,GAAG,CAAAH,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEI,kBAAZ,KAAkC,EAArD;AACA,QAAMrB,UAAU,GAAGY,IAAI,CAACF,GAAL,CAASQ,iBAAT,EAA4BX,SAAS,CAACa,UAAD,CAArC,CAAnB;AACA,WAAOpB,UAAU,GAAGU,GAAb,GAAmBV,UAAnB,GAAgCU,GAAvC;AACD,GALM,EAKJ,CALI,CAAP;AAMD,CARM","sourcesContent":["export const generateValidationMessage = (config) => {\n let { minChoices, maxChoices, maxCategories } = config || {};\n minChoices = minChoices || 1;\n\n const validationMessage =\n '\\nThe choices content should ' +\n 'not be empty and should be unique.\\nThere should be at least 1 ' +\n (maxCategories ? `and at most ${maxCategories} ` : '') +\n 'category' +\n (maxCategories ? 's' : '') +\n ' defined.' +\n (minChoices ? `\\nThere should be at least ${minChoices} choices defined.` : '') +\n (maxChoices ? `\\nNo more than ${maxChoices} choices should be defined.` : '') +\n '\\nAt least one token should be assigned to at least one category.';\n\n return 'Validation requirements:' + validationMessage;\n};\n\n// used in controller too, for consistency modify it there too\nexport const multiplePlacements = { enabled: 'Yes', disabled: 'No', perChoice: 'Set Per Choice' };\n\n// Find the length of the largest array from an array\nexport const maxLength = (array) =>\n (array || []).reduce((max, arr) => {\n return Math.max(max, arr.length);\n }, 0);\n\nexport const getMaxCategoryChoices = (model) => {\n const { correctResponse = [] } = model || {};\n return correctResponse.reduce((max, correctRes) => {\n const correctRespLength = correctRes?.choices?.length || 0;\n const alternates = correctRes?.alternateResponses || [];\n const maxChoices = Math.max(correctRespLength, maxLength(alternates));\n return maxChoices > max ? maxChoices : max;\n }, 0);\n};\n"],"file":"utils.js"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "8.21.3-next.0+30959513b",
7
+ "version": "8.21.3-next.4+61cea0f0c",
8
8
  "description": "",
9
9
  "author": "pie framework developers",
10
10
  "license": "ISC",
@@ -20,7 +20,7 @@
20
20
  "react-dnd": "^14.0.5",
21
21
  "react-dom": "^16.8.1"
22
22
  },
23
- "gitHead": "30959513b59815fbed1cef5d3eb1a38c86b94a67",
23
+ "gitHead": "61cea0f0c870813833468c68cdb3d26c56969264",
24
24
  "scripts": {
25
25
  "postpublish": "../../scripts/postpublish"
26
26
  },