@pie-element/charting 7.2.0 → 7.2.1

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.2.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/charting@7.2.0...@pie-element/charting@7.2.1) (2023-12-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **charting:** fix state sync issues in Define Correct Response Chart when Define Chart data is modified or removed PD-3164 ([baa04e6](https://github.com/pie-framework/pie-elements/commit/baa04e6942c1f8e4279f2b83327c142464fde6e5))
12
+
13
+
14
+
15
+
16
+
6
17
  # [7.2.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/charting@7.1.1...@pie-element/charting@7.2.0) (2023-12-19)
7
18
 
8
19
 
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.1.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/charting-configure@7.1.0...@pie-element/charting-configure@7.1.1) (2023-12-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **charting:** fix state sync issues in Define Correct Response Chart when Define Chart data is modified or removed PD-3164 ([baa04e6](https://github.com/pie-framework/pie-elements/commit/baa04e6942c1f8e4279f2b83327c142464fde6e5))
12
+
13
+
14
+
15
+
16
+
6
17
  # [7.1.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/charting-configure@7.0.3...@pie-element/charting-configure@7.1.0) (2023-12-19)
7
18
 
8
19
 
@@ -163,10 +163,16 @@ var getUpdatedCategories = function getUpdatedCategories(nextProps, prevProps, p
163
163
 
164
164
 
165
165
  if (nextData.length < data.length) {
166
- var removedIndex = data.findIndex(function (item, index) {
167
- return item.index !== index;
168
- });
169
- removedIndex = removedIndex === -1 ? nextData.length : removedIndex;
166
+ var removedIndex = nextData.length; // we need to remove the category from the correct answer data and categories, from the same index it was removed from the data
167
+ // index is a property of the nextData category
168
+
169
+ for (var index = 0; index < nextData.length; index++) {
170
+ if (nextData[index].index !== index) {
171
+ removedIndex = index;
172
+ break;
173
+ }
174
+ }
175
+
170
176
  nextCategories = removeCategory(categoriesCopy, nextData, removedIndex);
171
177
  return nextCategories;
172
178
  } // Handle category value or label changes in Define Chart
@@ -174,15 +180,6 @@ var getUpdatedCategories = function getUpdatedCategories(nextProps, prevProps, p
174
180
 
175
181
 
176
182
  nextCategories = updateCorrectResponseData(nextCorrectAnswerDataCopy, nextData);
177
- nextCorrectAnswerDataCopy.forEach(function (answer, currentIndex) {
178
- var dataExists = currentIndex < nextData.length;
179
- nextCorrectAnswerDataCopy[currentIndex] = {
180
- editable: dataExists ? nextData[currentIndex].editable : true,
181
- interactive: dataExists ? nextData[currentIndex].interactive : true,
182
- label: dataExists && nextData[currentIndex].editable ? answer.label : dataExists ? nextData[currentIndex].label : answer.label,
183
- value: dataExists && nextData[currentIndex].interactive ? answer.value : dataExists ? nextData[currentIndex].value : answer.value
184
- };
185
- });
186
183
  return nextCategories;
187
184
  };
188
185
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/correct-response.jsx"],"names":["styles","theme","container","marginBottom","spacing","unit","display","flex","button","marginTop","cursor","background","palette","grey","padding","width","borderRadius","column","chartError","border","error","main","errorText","fontSize","typography","color","paddingTop","title","addCategoryProps","correctAnswer","data","map","correct","index","editable","length","interactive","deletable","updateCorrectResponseData","correctAnswerData","correctResponseDefinition","forEach","category","currentIndex","label","value","missingCategories","slice","concat","insertCategory","positionToInsert","categoryToInsert","splice","removeCategory","positionToRemove","getUpdatedCategories","nextProps","prevProps","prevState","nextData","model","nextCorrectAnswerDataCopy","categoriesCopy","categories","nextCategories","removedIndex","findIndex","item","answer","dataExists","CorrectResponse","props","onChange","keepAttrs","state","initialCategories","setState","changeData","classes","charts","studentNewCategoryDefaultLabel","correctAnswerErrors","mathMlOptions","domain","range","identicalError","categoriesError","name","chartType","graph","addCategoryEnabled","React","Component","PropTypes","object","isRequired","string","func","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,GAD1B;AAETC,MAAAA,OAAO,EAAE,MAFA;AAGTC,MAAAA,IAAI,EAAE;AAHG,KADc;AAMzBC,IAAAA,MAAM,EAAE;AACNC,MAAAA,SAAS,EAAER,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAD1B;AAENK,MAAAA,MAAM,EAAE,SAFF;AAGNC,MAAAA,UAAU,EAAEV,KAAK,CAACW,OAAN,CAAcC,IAAd,CAAmB,GAAnB,CAHN;AAINC,MAAAA,OAAO,EAAEb,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAJxB;AAKNU,MAAAA,KAAK,EAAE,aALD;AAMNC,MAAAA,YAAY,EAAE;AANR,KANiB;AAczBC,IAAAA,MAAM,EAAE;AACNV,MAAAA,IAAI,EAAE;AADA,KAdiB;AAiBzBW,IAAAA,UAAU,EAAE;AACVC,MAAAA,MAAM,sBAAelB,KAAK,CAACW,OAAN,CAAcQ,KAAd,CAAoBC,IAAnC;AADI,KAjBa;AAoBzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEtB,KAAK,CAACuB,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;AAETE,MAAAA,KAAK,EAAExB,KAAK,CAACW,OAAN,CAAcQ,KAAd,CAAoBC,IAFlB;AAGTK,MAAAA,UAAU,EAAEzB,KAAK,CAACG,OAAN,CAAcC;AAHjB,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,KAND;AAOjB9E,EAAAA,KAAK,EAAEyE,sBAAUG;AAPA,C;;eAyGN,wBAAWhG,MAAX,EAAmBsE,eAAnB,C","sourcesContent":["import * as React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { Chart } from '@pie-lib/pie-toolbox/charting';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport Typography from '@material-ui/core/Typography';\n\nconst styles = (theme) => ({\n container: {\n marginBottom: theme.spacing.unit * 2.5,\n display: 'flex',\n flex: 1,\n },\n button: {\n marginTop: theme.spacing.unit * 3,\n cursor: 'pointer',\n background: theme.palette.grey[200],\n padding: theme.spacing.unit * 2,\n width: 'fit-content',\n borderRadius: '4px',\n },\n column: {\n flex: 1,\n },\n chartError: {\n border: `2px solid ${theme.palette.error.main}`,\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n title: {\n marginBottom: theme.spacing.unit,\n },\n});\n\nconst addCategoryProps = (correctAnswer, data) =>\n correctAnswer.map((correct, index) => ({\n ...correct,\n editable: index < data.length ? data[index].editable : true,\n interactive: index < data.length ? data[index].interactive : true,\n deletable: index >= data.length ? true : false,\n }));\n\nconst updateCorrectResponseData = (correctAnswer, data) => {\n if (!correctAnswer) {\n return data;\n }\n\n const correctAnswerData = [...correctAnswer];\n let correctResponseDefinition = [];\n\n (data || []).forEach((category, currentIndex) => {\n const editable = category.editable;\n const interactive = category.interactive;\n const label = editable && correctAnswer[currentIndex]?.label ? correctAnswer[currentIndex].label : category.label;\n const value =\n (interactive && correctAnswer[currentIndex]?.value) || (interactive && correctAnswer[currentIndex]?.value == 0)\n ? correctAnswer[currentIndex].value\n : category.value;\n\n correctResponseDefinition[currentIndex] = {\n label: label,\n value: value,\n editable: category.editable,\n interactive: category.interactive,\n };\n });\n\n if (correctResponseDefinition.length < correctAnswer.length) {\n const missingCategories = (correctAnswerData || []).slice(correctResponseDefinition.length, correctAnswer.length);\n\n return addCategoryProps((correctResponseDefinition || []).concat(missingCategories), data);\n }\n\n return correctResponseDefinition;\n};\n\nconst insertCategory = (correctAnswer, data) => {\n const positionToInsert = data.length - 1;\n // eslint-disable-next-line no-unused-vars\n const { editable, interactive, deletable, ...categoryToInsert } = data[data.length - 1];\n\n (correctAnswer || []).splice(positionToInsert, 0, categoryToInsert);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nconst removeCategory = (correctAnswer, data, positionToRemove) => {\n (correctAnswer || []).splice(positionToRemove, 1);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nexport const getUpdatedCategories = (nextProps, prevProps, prevState) => {\n const nextData = (nextProps && nextProps.model && nextProps.model.data) || [];\n const data = (prevProps && prevProps.model && prevProps.model.data) || [];\n const nextCorrectAnswerDataCopy = cloneDeep((nextProps && nextProps.model && nextProps.model.correctAnswer && nextProps.model.correctAnswer.data) || []);\n\n const categoriesCopy = cloneDeep(prevState ? prevState.categories : []);\n\n let nextCategories = [];\n\n // Handle categories insertion in Define Chart\n if (nextData.length > data.length) {\n nextCategories = insertCategory(nextCorrectAnswerDataCopy, nextData);\n return nextCategories;\n }\n\n // Handle categories removal from Define Chart\n if (nextData.length < data.length) {\n let removedIndex = data.findIndex((item, index) => item.index !== index);\n removedIndex = removedIndex === -1 ? nextData.length : removedIndex;\n\n nextCategories = removeCategory(categoriesCopy, nextData, removedIndex);\n return nextCategories;\n }\n\n // Handle category value or label changes in Define Chart\n // Handle categories update in Define Correct Response Chart\n nextCategories = updateCorrectResponseData(nextCorrectAnswerDataCopy, nextData);\n\n nextCorrectAnswerDataCopy.forEach((answer, currentIndex) => {\n const dataExists = currentIndex < nextData.length;\n nextCorrectAnswerDataCopy[currentIndex] = {\n editable: dataExists ? nextData[currentIndex].editable : true,\n interactive: dataExists ? nextData[currentIndex].interactive : true,\n label:\n dataExists && nextData[currentIndex].editable\n ? answer.label\n : dataExists\n ? nextData[currentIndex].label\n : answer.label,\n value:\n dataExists && nextData[currentIndex].interactive\n ? answer.value\n : dataExists\n ? nextData[currentIndex].value\n : answer.value,\n };\n });\n\n return nextCategories;\n};\n\nexport class CorrectResponse extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n correctAnswerErrors: PropTypes.object,\n studentNewCategoryDefaultLabel: PropTypes.string,\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n charts: PropTypes.array,\n error: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.state = {\n categories: [],\n };\n }\n\n changeData = (data) => {\n const { model, onChange } = this.props;\n const { correctAnswer } = model || {};\n\n onChange({\n ...model,\n correctAnswer: {\n ...correctAnswer,\n // eslint-disable-next-line no-unused-vars\n data: data.map(({ interactive, editable, index, ...keepAttrs }) => keepAttrs),\n },\n });\n };\n\n componentDidMount() {\n const initialCategories = getUpdatedCategories(this.props, this.props, null);\n\n this.setState({\n categories:\n initialCategories || updateCorrectResponseData(this.props.model.correctAnswer.data, this.props.model.data),\n });\n }\n\n componentDidUpdate(prevProps, prevState) {\n const nextCategories = getUpdatedCategories(this.props, prevProps, prevState);\n\n if (nextCategories && !isEqual(nextCategories, this.state.categories)) {\n this.changeData(nextCategories);\n this.setState({ categories: nextCategories });\n }\n }\n\n render() {\n const {\n classes,\n model,\n charts,\n error,\n studentNewCategoryDefaultLabel,\n correctAnswerErrors,\n mathMlOptions = {},\n } = this.props;\n const { categories } = this.state;\n\n const { domain = {}, range = {} } = model || {};\n const { identicalError, categoriesError } = correctAnswerErrors || {};\n\n return (\n <div>\n <div className={classes.title}>Define Correct Response</div>\n <div className={classes.container}>\n <div className={classes.column} key=\"graph\">\n <Typography component=\"div\" type=\"body1\">\n <span>Use the tools below to define the correct answer.</span>\n </Typography>\n\n <div\n key={`correct-response-graph-${model.correctAnswer.name}`}\n className={identicalError || categoriesError ? classes.chartError : ''}\n >\n <Chart\n chartType={model.chartType}\n size={model.graph}\n domain={domain}\n range={range}\n charts={charts}\n data={categories}\n title={model.title}\n onDataChange={this.changeData}\n addCategoryEnabled={model.addCategoryEnabled}\n categoryDefaultLabel={studentNewCategoryDefaultLabel}\n error={error}\n mathMlOptions={mathMlOptions}\n />\n </div>\n\n {(identicalError || categoriesError) && (\n <Typography component=\"div\" type=\"body1\" className={classes.errorText}>\n <span>{identicalError || categoriesError}</span>\n </Typography>\n )}\n </div>\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(CorrectResponse);\n"],"file":"correct-response.js"}
1
+ {"version":3,"sources":["../src/correct-response.jsx"],"names":["styles","theme","container","marginBottom","spacing","unit","display","flex","button","marginTop","cursor","background","palette","grey","padding","width","borderRadius","column","chartError","border","error","main","errorText","fontSize","typography","color","paddingTop","title","addCategoryProps","correctAnswer","data","map","correct","index","editable","length","interactive","deletable","updateCorrectResponseData","correctAnswerData","correctResponseDefinition","forEach","category","currentIndex","label","value","missingCategories","slice","concat","insertCategory","positionToInsert","categoryToInsert","splice","removeCategory","positionToRemove","getUpdatedCategories","nextProps","prevProps","prevState","nextData","model","nextCorrectAnswerDataCopy","categoriesCopy","categories","nextCategories","removedIndex","CorrectResponse","props","onChange","keepAttrs","state","initialCategories","setState","changeData","classes","charts","studentNewCategoryDefaultLabel","correctAnswerErrors","mathMlOptions","domain","range","identicalError","categoriesError","name","chartType","graph","addCategoryEnabled","React","Component","PropTypes","object","isRequired","string","func","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,GAD1B;AAETC,MAAAA,OAAO,EAAE,MAFA;A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eF,UALR;AAMjBhB,EAAAA,MAAM,EAAEc,sBAAUK,KAND;AAOjB1E,EAAAA,KAAK,EAAEqE,sBAAUG;AAPA,C;;eAyGN,wBAAW5F,MAAX,EAAmBkE,eAAnB,C","sourcesContent":["import * as React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { Chart } from '@pie-lib/pie-toolbox/charting';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport Typography from '@material-ui/core/Typography';\n\nconst styles = (theme) => ({\n container: {\n marginBottom: theme.spacing.unit * 2.5,\n display: 'flex',\n flex: 1,\n },\n button: {\n marginTop: theme.spacing.unit * 3,\n cursor: 'pointer',\n background: theme.palette.grey[200],\n padding: theme.spacing.unit * 2,\n width: 'fit-content',\n borderRadius: '4px',\n },\n column: {\n flex: 1,\n },\n chartError: {\n border: `2px solid ${theme.palette.error.main}`,\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n title: {\n marginBottom: theme.spacing.unit,\n },\n});\n\nconst addCategoryProps = (correctAnswer, data) =>\n correctAnswer.map((correct, index) => ({\n ...correct,\n editable: index < data.length ? data[index].editable : true,\n interactive: index < data.length ? data[index].interactive : true,\n deletable: index >= data.length ? true : false,\n }));\n\nconst updateCorrectResponseData = (correctAnswer, data) => {\n if (!correctAnswer) {\n return data;\n }\n\n const correctAnswerData = [...correctAnswer];\n let correctResponseDefinition = [];\n\n (data || []).forEach((category, currentIndex) => {\n const editable = category.editable;\n const interactive = category.interactive;\n const label = editable && correctAnswer[currentIndex]?.label ? correctAnswer[currentIndex].label : category.label;\n const value =\n (interactive && correctAnswer[currentIndex]?.value) || (interactive && correctAnswer[currentIndex]?.value == 0)\n ? correctAnswer[currentIndex].value\n : category.value;\n\n correctResponseDefinition[currentIndex] = {\n label: label,\n value: value,\n editable: category.editable,\n interactive: category.interactive,\n };\n });\n\n if (correctResponseDefinition.length < correctAnswer.length) {\n const missingCategories = (correctAnswerData || []).slice(correctResponseDefinition.length, correctAnswer.length);\n\n return addCategoryProps((correctResponseDefinition || []).concat(missingCategories), data);\n }\n\n return correctResponseDefinition;\n};\n\nconst insertCategory = (correctAnswer, data) => {\n const positionToInsert = data.length - 1;\n // eslint-disable-next-line no-unused-vars\n const { editable, interactive, deletable, ...categoryToInsert } = data[data.length - 1];\n\n (correctAnswer || []).splice(positionToInsert, 0, categoryToInsert);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nconst removeCategory = (correctAnswer, data, positionToRemove) => {\n (correctAnswer || []).splice(positionToRemove, 1);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nexport const getUpdatedCategories = (nextProps, prevProps, prevState) => {\n const nextData = (nextProps && nextProps.model && nextProps.model.data) || [];\n const data = (prevProps && prevProps.model && prevProps.model.data) || [];\n const nextCorrectAnswerDataCopy = cloneDeep((nextProps && nextProps.model && nextProps.model.correctAnswer && nextProps.model.correctAnswer.data) || []);\n\n const categoriesCopy = cloneDeep(prevState ? prevState.categories : []);\n\n let nextCategories = [];\n\n // Handle categories insertion in Define Chart\n if (nextData.length > data.length) {\n nextCategories = insertCategory(nextCorrectAnswerDataCopy, nextData);\n return nextCategories;\n }\n\n // Handle categories removal from Define Chart\n if (nextData.length < data.length) {\n let removedIndex = nextData.length;\n\n // we need to remove the category from the correct answer data and categories, from the same index it was removed from the data\n // index is a property of the nextData category\n for (let index = 0; index < nextData.length; index++) {\n if (nextData[index].index !== index) {\n removedIndex = index;\n break;\n }\n }\n \n nextCategories = removeCategory(categoriesCopy, nextData, removedIndex);\n return nextCategories;\n }\n\n // Handle category value or label changes in Define Chart\n // Handle categories update in Define Correct Response Chart\n nextCategories = updateCorrectResponseData(nextCorrectAnswerDataCopy, nextData);\n\n return nextCategories;\n};\n\nexport class CorrectResponse extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n correctAnswerErrors: PropTypes.object,\n studentNewCategoryDefaultLabel: PropTypes.string,\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n charts: PropTypes.array,\n error: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.state = {\n categories: [],\n };\n }\n\n changeData = (data) => {\n const { model, onChange } = this.props;\n const { correctAnswer } = model || {};\n\n onChange({\n ...model,\n correctAnswer: {\n ...correctAnswer,\n // eslint-disable-next-line no-unused-vars\n data: data.map(({ interactive, editable, index, ...keepAttrs }) => keepAttrs),\n },\n });\n };\n\n componentDidMount() {\n const initialCategories = getUpdatedCategories(this.props, this.props, null);\n\n this.setState({\n categories:\n initialCategories || updateCorrectResponseData(this.props.model.correctAnswer.data, this.props.model.data),\n });\n }\n\n componentDidUpdate(prevProps, prevState) {\n const nextCategories = getUpdatedCategories(this.props, prevProps, prevState);\n\n if (nextCategories && !isEqual(nextCategories, this.state.categories)) {\n this.changeData(nextCategories);\n this.setState({ categories: nextCategories });\n }\n }\n\n render() {\n const {\n classes,\n model,\n charts,\n error,\n studentNewCategoryDefaultLabel,\n correctAnswerErrors,\n mathMlOptions = {},\n } = this.props;\n const { categories } = this.state;\n\n const { domain = {}, range = {} } = model || {};\n const { identicalError, categoriesError } = correctAnswerErrors || {};\n\n return (\n <div>\n <div className={classes.title}>Define Correct Response</div>\n <div className={classes.container}>\n <div className={classes.column} key=\"graph\">\n <Typography component=\"div\" type=\"body1\">\n <span>Use the tools below to define the correct answer.</span>\n </Typography>\n\n <div\n key={`correct-response-graph-${model.correctAnswer.name}`}\n className={identicalError || categoriesError ? classes.chartError : ''}\n >\n <Chart\n chartType={model.chartType}\n size={model.graph}\n domain={domain}\n range={range}\n charts={charts}\n data={categories}\n title={model.title}\n onDataChange={this.changeData}\n addCategoryEnabled={model.addCategoryEnabled}\n categoryDefaultLabel={studentNewCategoryDefaultLabel}\n error={error}\n mathMlOptions={mathMlOptions}\n />\n </div>\n\n {(identicalError || categoriesError) && (\n <Typography component=\"div\" type=\"body1\" className={classes.errorText}>\n <span>{identicalError || categoriesError}</span>\n </Typography>\n )}\n </div>\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(CorrectResponse);\n"],"file":"correct-response.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/charting-configure",
3
3
  "private": true,
4
- "version": "7.1.0",
4
+ "version": "7.1.1",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "repository": "pie-framework/pie-elements",
7
- "version": "7.2.0",
7
+ "version": "7.2.1",
8
8
  "description": "",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "author": "",
24
24
  "license": "ISC",
25
- "gitHead": "8aec9bff2588b2640ca5b4fa74a75333a52a563b",
25
+ "gitHead": "e85047f0961dba0bbb18b630c99d676972c5309f",
26
26
  "main": "lib/index.js",
27
27
  "module": "src/index.js"
28
28
  }