@pie-element/drag-in-the-blank 4.13.3-next.9 → 4.13.4-next.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
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
+ ## [4.13.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/drag-in-the-blank@4.13.2...@pie-element/drag-in-the-blank@4.13.3) (2023-08-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * update pie-libs PD-3049, PD-2916, PD-2059 ([0e800b5](https://github.com/pie-framework/pie-elements/commit/0e800b54b852304d222a292400362e0870f0cc9a))
12
+ * updated pie-lib to fix PD-2802 ([eab79f7](https://github.com/pie-framework/pie-elements/commit/eab79f70ad4488207a5b9b401679eb096feba247))
13
+ * updated pie-lib to fix PD-2802, PD-3050, PD-3051 ([34b4dd7](https://github.com/pie-framework/pie-elements/commit/34b4dd7ba18f4c18589975921cc9d127926f8294))
14
+ * updated pie-libs Pd-1163 ([300c1db](https://github.com/pie-framework/pie-elements/commit/300c1db1658ce85ca58f3cc2981b604aefbf9f01))
15
+ * **drag-in-the-blank:** remove the new blank tokens and improve tokens update flow PD-2920 ([232ea24](https://github.com/pie-framework/pie-elements/commit/232ea2419080fb7f303536d1ce7f00167e7f64d6))
16
+
17
+
18
+
19
+
20
+
6
21
  ## [4.13.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/drag-in-the-blank@4.13.1...@pie-element/drag-in-the-blank@4.13.2) (2023-07-24)
7
22
 
8
23
 
@@ -3,6 +3,20 @@
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
+ ## [4.10.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/drag-in-the-blank-configure@4.10.2...@pie-element/drag-in-the-blank-configure@4.10.3) (2023-08-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * update pie-libs PD-3049, PD-2916, PD-2059 ([0e800b5](https://github.com/pie-framework/pie-elements/commit/0e800b54b852304d222a292400362e0870f0cc9a))
12
+ * updated pie-lib to fix PD-2802, PD-3050, PD-3051 ([34b4dd7](https://github.com/pie-framework/pie-elements/commit/34b4dd7ba18f4c18589975921cc9d127926f8294))
13
+ * updated pie-libs Pd-1163 ([300c1db](https://github.com/pie-framework/pie-elements/commit/300c1db1658ce85ca58f3cc2981b604aefbf9f01))
14
+ * **drag-in-the-blank:** remove the new blank tokens and improve tokens update flow PD-2920 ([232ea24](https://github.com/pie-framework/pie-elements/commit/232ea2419080fb7f303536d1ce7f00167e7f64d6))
15
+
16
+
17
+
18
+
19
+
6
20
  ## [4.10.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/drag-in-the-blank-configure@4.10.1...@pie-element/drag-in-the-blank-configure@4.10.2) (2023-07-24)
7
21
 
8
22
 
@@ -97,7 +97,9 @@ var Choices = /*#__PURE__*/function (_React$Component) {
97
97
 
98
98
  _this = _super.call.apply(_super, [this].concat(args));
99
99
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
100
- showWarning: false
100
+ warning: {
101
+ open: false
102
+ }
101
103
  });
102
104
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "preventDone", false);
103
105
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "rerenderMath", function () {
@@ -128,7 +130,10 @@ var Choices = /*#__PURE__*/function (_React$Component) {
128
130
  }
129
131
 
130
132
  _this.setState({
131
- showWarning: true
133
+ warning: {
134
+ open: true,
135
+ text: 'Identical answer choices are not allowed and the changes will be discarded.'
136
+ }
132
137
  });
133
138
 
134
139
  return;
@@ -140,46 +145,54 @@ var Choices = /*#__PURE__*/function (_React$Component) {
140
145
  }) : choice;
141
146
  })) || [];
142
147
 
143
- if ((0, _markupUtils.choiceIsEmpty)({
148
+ if (!(0, _markupUtils.choiceIsEmpty)({
144
149
  value: val
145
150
  })) {
146
- // if the edited content is empty, its usage has to be searched in the correct response definitions
147
- var usedForResponse = false;
151
+ onChange(newChoices);
152
+ return;
153
+ } // if the edited content is empty, its usage has to be searched in the correct response definitions
148
154
 
149
- if (correctResponse) {
150
- Object.keys(correctResponse).forEach(function (responseKey) {
151
- if (correctResponse[responseKey] === key) {
152
- usedForResponse = true;
153
- }
154
- });
155
- }
156
155
 
157
- if (alternateResponses) {
158
- Object.values(alternateResponses).forEach(function (alternate) {
159
- if (alternate.indexOf(key) >= 0) {
160
- usedForResponse = true;
161
- }
162
- });
163
- }
156
+ var usedForResponse = false;
164
157
 
165
- if (usedForResponse) {
166
- alert('Answer choices cannot be blank.');
167
- } else {
168
- if (!(0, _markupUtils.choiceIsEmpty)({
169
- value: prevValue
170
- })) {
171
- // if the previous value was not empty, it means that the choice can be deleted
172
- var newChoicesWithoutTheEmptyOne = newChoices.filter(function (choice) {
173
- return choice.id !== key;
174
- });
175
- onChange(newChoicesWithoutTheEmptyOne);
176
- } else {
177
- onChange(newChoices);
158
+ if (correctResponse) {
159
+ Object.keys(correctResponse).forEach(function (responseKey) {
160
+ if (correctResponse[responseKey] === key) {
161
+ usedForResponse = true;
178
162
  }
179
- }
180
- } else {
181
- onChange(newChoices);
163
+ });
164
+ }
165
+
166
+ if (alternateResponses && !usedForResponse) {
167
+ Object.values(alternateResponses).forEach(function (alternate) {
168
+ if (alternate.indexOf(key) >= 0) {
169
+ usedForResponse = true;
170
+ }
171
+ });
182
172
  }
173
+
174
+ if (usedForResponse) {
175
+ _this.setState({
176
+ warning: {
177
+ open: true,
178
+ text: 'Answer choices cannot be blank and the changes will be discarded.'
179
+ }
180
+ });
181
+
182
+ return;
183
+ }
184
+
185
+ var newChoicesWithoutTheEmptyOne = newChoices.filter(function (choice) {
186
+ return choice.id !== key;
187
+ });
188
+ onChange(newChoicesWithoutTheEmptyOne);
189
+
190
+ _this.setState({
191
+ warning: {
192
+ open: true,
193
+ text: 'Answer choices cannot be blank.'
194
+ }
195
+ });
183
196
  });
184
197
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChoiceFocus", function (id) {
185
198
  return _this.setState({
@@ -255,17 +268,17 @@ var Choices = /*#__PURE__*/function (_React$Component) {
255
268
 
256
269
  var _this$state = this.state,
257
270
  focusedEl = _this$state.focusedEl,
258
- showWarning = _this$state.showWarning;
271
+ warning = _this$state.warning;
259
272
  var _this$props5 = this.props,
260
273
  classes = _this$props5.classes,
261
274
  duplicates = _this$props5.duplicates,
262
275
  error = _this$props5.error,
276
+ _this$props5$mathMlOp = _this$props5.mathMlOptions,
277
+ mathMlOptions = _this$props5$mathMlOp === void 0 ? {} : _this$props5$mathMlOp,
263
278
  maxChoices = _this$props5.maxChoices,
264
279
  choices = _this$props5.model.choices,
265
280
  toolbarOpts = _this$props5.toolbarOpts,
266
- uploadSoundSupport = _this$props5.uploadSoundSupport,
267
- _this$props5$mathMlOp = _this$props5.mathMlOptions,
268
- mathMlOptions = _this$props5$mathMlOp === void 0 ? {} : _this$props5$mathMlOp;
281
+ uploadSoundSupport = _this$props5.uploadSoundSupport;
269
282
  var visibleChoices = this.getVisibleChoices() || [];
270
283
  return /*#__PURE__*/_react["default"].createElement("div", {
271
284
  className: classes.design
@@ -343,12 +356,14 @@ var Choices = /*#__PURE__*/function (_React$Component) {
343
356
  })), error && /*#__PURE__*/_react["default"].createElement("div", {
344
357
  className: classes.errorText
345
358
  }, error), /*#__PURE__*/_react["default"].createElement(_configUi.AlertDialog, {
346
- open: showWarning,
359
+ open: warning.open,
347
360
  title: "Warning",
348
- text: "Identical answer choices are not allowed and the changes will be discarded.",
361
+ text: warning.text,
349
362
  onConfirm: function onConfirm() {
350
363
  return _this2.setState({
351
- showWarning: false
364
+ warning: {
365
+ open: false
366
+ }
352
367
  });
353
368
  }
354
369
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/choices.jsx"],"names":["styles","theme","design","display","flexDirection","marginBottom","spacing","unit","addButton","marginLeft","altChoices","alignItems","flexWrap","justifyContent","marginTop","margin","errorText","fontSize","typography","color","palette","error","main","paddingBottom","Choices","showWarning","domNode","ReactDOM","findDOMNode","prevValue","val","key","props","onChange","model","choices","correctResponse","alternateResponses","duplicatedValue","find","c","value","id","newChoices","filter","setState","map","choice","usedForResponse","Object","keys","forEach","responseKey","values","alternate","indexOf","alert","newChoicesWithoutTheEmptyOne","focusedEl","oldChoices","length","duplicates","v","rerenderMath","focusedNodeRef","focus","state","classes","maxChoices","toolbarOpts","uploadSoundSupport","mathMlOptions","visibleChoices","getVisibleChoices","onAddChoice","index","minWidth","zIndex","ref","prompt","video","disabled","audio","language","preventDone","onChoiceChanged","undefined","e","inInInsertCharacter","relatedTarget","closest","onChoiceFocus","onChoiceRemove","React","Component","PropTypes","bool","string","object","isRequired","func","number","Styled"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,MAAM,EAAE;AACNC,MAAAA,OAAO,EAAE,MADH;AAENC,MAAAA,aAAa,EAAE,QAFT;AAGNC,MAAAA,YAAY,EAAEJ,KAAK,CAACK,OAAN,CAAcC,IAAd,GAAqB;AAH7B,KADiB;AAMzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,UAAU,EAAE;AADH,KANc;AASzBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,UAAU,EAAE,YADF;AAEVR,MAAAA,OAAO,EAAE,MAFC;AAGVS,MAAAA,QAAQ,EAAE,MAHA;AAIVC,MAAAA,cAAc,EAAE,cAJN;AAKVC,MAAAA,SAAS,EAAEb,KAAK,CAACK,OAAN,CAAcC,IALf;AAOV,eAAS;AACPQ,QAAAA,MAAM,EAAEd,KAAK,CAACK,OAAN,CAAcC;AADf;AAP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V,CAAiBC,UAHP;AAIjBlE,EAAAA,QAAQ,EAAE8D,sBAAUK,IAAV,CAAeD,UAJR;AAKjBhC,EAAAA,OAAO,EAAE4B,sBAAUG,MAAV,CAAiBC,UALT;AAMjB9B,EAAAA,WAAW,EAAE0B,sBAAUG,MANN;AAOjB9B,EAAAA,UAAU,EAAE2B,sBAAUM,MAPL;AAQjB/B,EAAAA,kBAAkB,EAAEyB,sBAAUG;AARb,C;AAwPrB,IAAMI,MAAM,GAAG,wBAAWtG,MAAX,EAAmBwB,OAAnB,CAAf;eAEe8E,M","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport EditableHtml from '@pie-lib/editable-html';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport find from 'lodash/find';\nimport Button from '@material-ui/core/Button';\nimport Choice from './choice';\nimport { choiceIsEmpty } from './markupUtils';\nimport { withStyles } from '@material-ui/core/styles';\nimport { AlertDialog } from '@pie-lib/config-ui';\n\nconst styles = (theme) => ({\n design: {\n display: 'flex',\n flexDirection: 'column',\n marginBottom: theme.spacing.unit * 1.5,\n },\n addButton: {\n marginLeft: 'auto',\n },\n altChoices: {\n alignItems: 'flex-start',\n display: 'flex',\n flexWrap: 'wrap',\n justifyContent: 'space-evenly',\n marginTop: theme.spacing.unit,\n\n '& > *': {\n margin: theme.spacing.unit,\n },\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingBottom: theme.spacing.unit * 2,\n },\n});\n\nexport class Choices extends React.Component {\n static propTypes = {\n duplicates: PropTypes.bool,\n error: PropTypes.string,\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n classes: PropTypes.object.isRequired,\n toolbarOpts: PropTypes.object,\n maxChoices: PropTypes.number,\n uploadSoundSupport: PropTypes.object,\n };\n\n state = { showWarning: false };\n preventDone = false;\n\n componentDidMount() {\n this.rerenderMath();\n }\n\n componentDidUpdate() {\n this.rerenderMath();\n\n if (this.focusedNodeRef) {\n this.focusedNodeRef.focus('end');\n }\n }\n\n rerenderMath = () => {\n //eslint-disable-next-line\n const domNode = ReactDOM.findDOMNode(this);\n\n renderMath(domNode);\n };\n\n onChoiceChanged = (prevValue, val, key) => {\n const { onChange, model } = this.props;\n const { choices, correctResponse, alternateResponses } = model;\n const duplicatedValue = (choices || []).find((c) => c.value === val && c.id !== key);\n\n // discard the new added choice or the changes if the choice would be a duplicate to one that already exists\n if (duplicatedValue) {\n if (prevValue === '') {\n // remove the new added choice from choices\n const newChoices = (choices || []).filter((c) => c.id !== key);\n\n onChange(newChoices);\n }\n\n this.setState({ showWarning: true });\n\n return;\n }\n\n const newChoices = choices?.map((choice) => (choice.id === key ? { ...choice, value: val } : choice)) || [];\n\n if (choiceIsEmpty({ value: val })) {\n // if the edited content is empty, its usage has to be searched in the correct response definitions\n let usedForResponse = false;\n\n if (correctResponse) {\n Object.keys(correctResponse).forEach((responseKey) => {\n if (correctResponse[responseKey] === key) {\n usedForResponse = true;\n }\n });\n }\n\n if (alternateResponses) {\n Object.values(alternateResponses).forEach((alternate) => {\n if (alternate.indexOf(key) >= 0) {\n usedForResponse = true;\n }\n });\n }\n\n if (usedForResponse) {\n alert('Answer choices cannot be blank.');\n } else {\n if (!choiceIsEmpty({ value: prevValue })) {\n // if the previous value was not empty, it means that the choice can be deleted\n const newChoicesWithoutTheEmptyOne = newChoices.filter((choice) => choice.id !== key);\n\n onChange(newChoicesWithoutTheEmptyOne);\n } else {\n onChange(newChoices);\n }\n }\n } else {\n onChange(newChoices);\n }\n };\n\n onChoiceFocus = (id) =>\n this.setState({\n focusedEl: id,\n });\n\n onAddChoice = () => {\n const {\n model: { choices: oldChoices },\n onChange,\n } = this.props;\n\n this.setState(\n {\n focusedEl: `${oldChoices.length}`,\n },\n () => {\n onChange([\n ...oldChoices,\n {\n id: `${oldChoices.length}`,\n value: '',\n },\n ]);\n },\n );\n };\n\n onChoiceRemove = (id) => {\n const {\n onChange,\n model: { choices },\n } = this.props;\n const newChoices = (choices || []).filter((choice) => choice.id !== id);\n\n onChange(newChoices);\n };\n\n getVisibleChoices = () => {\n const {\n duplicates,\n model: { choices, correctResponse },\n } = this.props;\n\n if (!choices) {\n return [];\n }\n\n if (duplicates) {\n return choices;\n }\n\n // if duplicates not allowed, remove the choices that are used to define the correct response\n return choices.filter((choice) => !find(correctResponse, (v) => v === choice.id));\n };\n\n render() {\n const { focusedEl, showWarning } = this.state;\n const {\n classes,\n duplicates,\n error,\n maxChoices,\n model: { choices },\n toolbarOpts,\n uploadSoundSupport,\n mathMlOptions = {}\n } = this.props;\n const visibleChoices = this.getVisibleChoices() || [];\n\n return (\n <div className={classes.design}>\n <Button\n className={classes.addButton}\n variant=\"contained\"\n color=\"primary\"\n onClick={this.onAddChoice}\n disabled={maxChoices && choices && maxChoices === choices.length}\n >\n Add Choice\n </Button>\n\n <div className={classes.altChoices}>\n {visibleChoices.map((choice, index) =>\n focusedEl === choice.id ? (\n <div\n key={index}\n style={{\n minWidth: '100%',\n zIndex: '100',\n }}\n >\n <EditableHtml\n ref={(ref) => (this.focusedNodeRef = ref)}\n className={classes.prompt}\n markup={choice.value}\n pluginProps={{\n video: {\n disabled: true,\n },\n audio: {\n disabled: true,\n },\n }}\n languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}\n onChange={(val) => {\n if (this.preventDone) {\n return;\n }\n\n this.onChoiceChanged(choice.value, val, choice.id);\n }}\n onDone={() => {\n if (this.preventDone) {\n return;\n }\n\n this.setState({\n focusedEl: undefined,\n });\n }}\n onBlur={(e) => {\n const inInInsertCharacter = e.relatedTarget && e.relatedTarget.closest('.insert-character-dialog');\n\n this.preventDone = inInInsertCharacter;\n }}\n disableUnderline\n toolbarOpts={toolbarOpts}\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n />\n </div>\n ) : (\n <Choice\n key={index}\n duplicates={duplicates}\n targetId=\"0\"\n choice={choice}\n error={error}\n onClick={() => this.onChoiceFocus(choice.id)}\n onRemoveChoice={() => this.onChoiceRemove(choice.id)}\n />\n ),\n )}\n </div>\n {error && <div className={classes.errorText}>{error}</div>}\n\n <AlertDialog\n open={showWarning}\n title=\"Warning\"\n text=\"Identical answer choices are not allowed and the changes will be discarded.\"\n onConfirm={() => this.setState({ showWarning: false })}\n />\n </div>\n );\n }\n}\n\nconst Styled = withStyles(styles)(Choices);\n\nexport default Styled;\n"],"file":"choices.js"}
1
+ {"version":3,"sources":["../src/choices.jsx"],"names":["styles","theme","design","display","flexDirection","marginBottom","spacing","unit","addButton","marginLeft","altChoices","alignItems","flexWrap","justifyContent","marginTop","margin","errorText","fontSize","typography","color","palette","error","main","paddingBottom","Choices","warning","open","domNode","ReactDOM","findDOMNode","prevValue","val","key","props","onChange","model","choices","correctResponse","alternateResponses","duplicatedValue","find","c","value","id","newChoices","filter","setState","text","map","choice","usedForResponse","Object","keys","forEach","responseKey","values","alternate","indexOf","newChoicesWithoutTheEmptyOne","focusedEl","oldChoices","length","duplicates","v","rerenderMath","focusedNodeRef","focus","state","classes","mathMlOptions","maxChoices","toolbarOpts","uploadSoundSupport","visibleChoices","getVisibleChoices","onAddChoice","index","minWidth","zIndex","ref","prompt","video","disabled","audio","language","preventDone","onChoiceChanged","undefined","e","inInInsertCharacter","relatedTarget","closest","onChoiceFocus","onChoiceRemove","React","Component","PropTypes","bool","string","object","isRequired","func","number","Styled"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,MAAM,EAAE;AACNC,MAAAA,OAAO,EAAE,MADH;AAENC,MAAAA,aAAa,EAAE,QAFT;AAGNC,MAAAA,YAAY,EAAEJ,KAAK,CAACK,OAAN,CAAcC,IAAd,GAAqB;AAH7B,KADiB;AAMzBC,IAAAA,SAAS,EAAE;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AAI;AAAK,QAAA,SAAS,EAAE+C,OAAO,CAACpD;AAAxB,SAAoCK,KAApC,CA1EZ,eA4EE,gCAAC,qBAAD;AACE,QAAA,IAAI,EAAEI,OAAO,CAACC,IADhB;AAEE,QAAA,KAAK,EAAC,SAFR;AAGE,QAAA,IAAI,EAAED,OAAO,CAACsB,IAHhB;AAIE,QAAA,SAAS,EAAE;AAAA,iBAAM,MAAI,CAACD,QAAL,CAAc;AAAErB,YAAAA,OAAO,EAAE;AAAEC,cAAAA,IAAI,EAAE;AAAR;AAAX,WAAd,CAAN;AAAA;AAJb,QA5EF,CADF;AAqFD;;;EAtQ0BoE,kBAAMC,S;;;iCAAtBvE,O,eACQ;AACjBsC,EAAAA,UAAU,EAAEkC,sBAAUC,IADL;AAEjB5E,EAAAA,KAAK,EAAE2E,sBAAUE,MAFA;AAGjB/D,EAAAA,KAAK,EAAE6D,sBAAUG,MAAV,CAAiBC,UAHP;AAIjBlE,EAAAA,QAAQ,EAAE8D,sBAAUK,IAAV,CAAeD,UAJR;AAKjBhC,EAAAA,OAAO,EAAE4B,sBAAUG,MAAV,CAAiBC,UALT;AAMjB7B,EAAAA,WAAW,EAAEyB,sBAAUG,MANN;AAOjB7B,EAAAA,UAAU,EAAE0B,sBAAUM,MAPL;AAQjB9B,EAAAA,kBAAkB,EAAEwB,sBAAUG;AARb,C;AAwQrB,IAAMI,MAAM,GAAG,wBAAWvG,MAAX,EAAmBwB,OAAnB,CAAf;eAEe+E,M","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport EditableHtml from '@pie-lib/editable-html';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport find from 'lodash/find';\nimport Button from '@material-ui/core/Button';\nimport Choice from './choice';\nimport { choiceIsEmpty } from './markupUtils';\nimport { withStyles } from '@material-ui/core/styles';\nimport { AlertDialog } from '@pie-lib/config-ui';\n\nconst styles = (theme) => ({\n design: {\n display: 'flex',\n flexDirection: 'column',\n marginBottom: theme.spacing.unit * 1.5,\n },\n addButton: {\n marginLeft: 'auto',\n },\n altChoices: {\n alignItems: 'flex-start',\n display: 'flex',\n flexWrap: 'wrap',\n justifyContent: 'space-evenly',\n marginTop: theme.spacing.unit,\n\n '& > *': {\n margin: theme.spacing.unit,\n },\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingBottom: theme.spacing.unit * 2,\n },\n});\n\nexport class Choices extends React.Component {\n static propTypes = {\n duplicates: PropTypes.bool,\n error: PropTypes.string,\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n classes: PropTypes.object.isRequired,\n toolbarOpts: PropTypes.object,\n maxChoices: PropTypes.number,\n uploadSoundSupport: PropTypes.object,\n };\n\n state = { warning: { open: false } };\n preventDone = false;\n\n componentDidMount() {\n this.rerenderMath();\n }\n\n componentDidUpdate() {\n this.rerenderMath();\n\n if (this.focusedNodeRef) {\n this.focusedNodeRef.focus('end');\n }\n }\n\n rerenderMath = () => {\n //eslint-disable-next-line\n const domNode = ReactDOM.findDOMNode(this);\n\n renderMath(domNode);\n };\n\n onChoiceChanged = (prevValue, val, key) => {\n const { onChange, model } = this.props;\n const { choices, correctResponse, alternateResponses } = model;\n const duplicatedValue = (choices || []).find((c) => c.value === val && c.id !== key);\n\n // discard the new added choice or the changes if the choice would be a duplicate to one that already exists\n if (duplicatedValue) {\n if (prevValue === '') {\n // remove the new added choice from choices\n const newChoices = (choices || []).filter((c) => c.id !== key);\n\n onChange(newChoices);\n }\n\n this.setState({\n warning: {\n open: true,\n text: 'Identical answer choices are not allowed and the changes will be discarded.',\n },\n });\n\n return;\n }\n\n const newChoices = choices?.map((choice) => (choice.id === key ? { ...choice, value: val } : choice)) || [];\n\n if (!choiceIsEmpty({ value: val })) {\n onChange(newChoices);\n\n return;\n }\n\n // if the edited content is empty, its usage has to be searched in the correct response definitions\n let usedForResponse = false;\n\n if (correctResponse) {\n Object.keys(correctResponse).forEach((responseKey) => {\n if (correctResponse[responseKey] === key) {\n usedForResponse = true;\n }\n });\n }\n\n if (alternateResponses && !usedForResponse) {\n Object.values(alternateResponses).forEach((alternate) => {\n if (alternate.indexOf(key) >= 0) {\n usedForResponse = true;\n }\n });\n }\n\n if (usedForResponse) {\n this.setState({\n warning: {\n open: true,\n text: 'Answer choices cannot be blank and the changes will be discarded.',\n },\n });\n\n return;\n }\n\n const newChoicesWithoutTheEmptyOne = newChoices.filter((choice) => choice.id !== key);\n\n onChange(newChoicesWithoutTheEmptyOne);\n\n this.setState({\n warning: {\n open: true,\n text: 'Answer choices cannot be blank.',\n },\n });\n };\n\n onChoiceFocus = (id) =>\n this.setState({\n focusedEl: id,\n });\n\n onAddChoice = () => {\n const {\n model: { choices: oldChoices },\n onChange,\n } = this.props;\n\n this.setState(\n {\n focusedEl: `${oldChoices.length}`,\n },\n () => {\n onChange([\n ...oldChoices,\n {\n id: `${oldChoices.length}`,\n value: '',\n },\n ]);\n },\n );\n };\n\n onChoiceRemove = (id) => {\n const {\n onChange,\n model: { choices },\n } = this.props;\n const newChoices = (choices || []).filter((choice) => choice.id !== id);\n\n onChange(newChoices);\n };\n\n getVisibleChoices = () => {\n const {\n duplicates,\n model: { choices, correctResponse },\n } = this.props;\n\n if (!choices) {\n return [];\n }\n\n if (duplicates) {\n return choices;\n }\n\n // if duplicates not allowed, remove the choices that are used to define the correct response\n return choices.filter((choice) => !find(correctResponse, (v) => v === choice.id));\n };\n\n render() {\n const { focusedEl, warning } = this.state;\n const {\n classes,\n duplicates,\n error,\n mathMlOptions = {},\n maxChoices,\n model: { choices },\n toolbarOpts,\n uploadSoundSupport,\n } = this.props;\n const visibleChoices = this.getVisibleChoices() || [];\n\n return (\n <div className={classes.design}>\n <Button\n className={classes.addButton}\n variant=\"contained\"\n color=\"primary\"\n onClick={this.onAddChoice}\n disabled={maxChoices && choices && maxChoices === choices.length}\n >\n Add Choice\n </Button>\n\n <div className={classes.altChoices}>\n {visibleChoices.map((choice, index) =>\n focusedEl === choice.id ? (\n <div\n key={index}\n style={{\n minWidth: '100%',\n zIndex: '100',\n }}\n >\n <EditableHtml\n ref={(ref) => (this.focusedNodeRef = ref)}\n className={classes.prompt}\n markup={choice.value}\n pluginProps={{\n video: {\n disabled: true,\n },\n audio: {\n disabled: true,\n },\n }}\n languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}\n onChange={(val) => {\n if (this.preventDone) {\n return;\n }\n\n this.onChoiceChanged(choice.value, val, choice.id);\n }}\n onDone={() => {\n if (this.preventDone) {\n return;\n }\n\n this.setState({\n focusedEl: undefined,\n });\n }}\n onBlur={(e) => {\n const inInInsertCharacter = e.relatedTarget && e.relatedTarget.closest('.insert-character-dialog');\n\n this.preventDone = inInInsertCharacter;\n }}\n disableUnderline\n toolbarOpts={toolbarOpts}\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n />\n </div>\n ) : (\n <Choice\n key={index}\n duplicates={duplicates}\n targetId=\"0\"\n choice={choice}\n error={error}\n onClick={() => this.onChoiceFocus(choice.id)}\n onRemoveChoice={() => this.onChoiceRemove(choice.id)}\n />\n ),\n )}\n </div>\n {error && <div className={classes.errorText}>{error}</div>}\n\n <AlertDialog\n open={warning.open}\n title=\"Warning\"\n text={warning.text}\n onConfirm={() => this.setState({ warning: { open: false } })}\n />\n </div>\n );\n }\n}\n\nconst Styled = withStyles(styles)(Choices);\n\nexport default Styled;\n"],"file":"choices.js"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/drag-in-the-blank-configure",
3
- "version": "4.10.2",
3
+ "version": "4.10.3",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -8,9 +8,9 @@
8
8
  "@material-ui/core": "^3.9.2",
9
9
  "@material-ui/icons": "^3.0.1",
10
10
  "@pie-framework/pie-configure-events": "^1.3.0",
11
- "@pie-lib/config-ui": "^11.8.6",
12
- "@pie-lib/drag": "^2.2.2",
13
- "@pie-lib/editable-html": "^9.7.3",
11
+ "@pie-lib/config-ui": "^11.9.2",
12
+ "@pie-lib/drag": "^2.2.4",
13
+ "@pie-lib/editable-html": "^9.7.6",
14
14
  "@pie-lib/math-rendering": "^2.5.17",
15
15
  "debug": "^3.1.0",
16
16
  "lodash": "^4.17.15",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "repository": "pie-framework/pie-elements",
7
- "version": "4.13.3-next.9+dcee1f0b6",
7
+ "version": "4.13.4-next.3+6928cab54",
8
8
  "description": "",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -13,10 +13,10 @@
13
13
  "dependencies": {
14
14
  "@material-ui/core": "^3.9.2",
15
15
  "@pie-framework/pie-player-events": "^0.1.0",
16
- "@pie-lib/correct-answer-toggle": "^2.3.79",
17
- "@pie-lib/mask-markup": "^1.13.33",
16
+ "@pie-lib/correct-answer-toggle": "^2.5.1",
17
+ "@pie-lib/mask-markup": "^1.13.36",
18
18
  "@pie-lib/math-rendering": "^2.5.17",
19
- "@pie-lib/render-ui": "^4.14.29",
19
+ "@pie-lib/render-ui": "^4.15.0",
20
20
  "classnames": "^2.2.5",
21
21
  "lodash": "^4.17.10",
22
22
  "prop-types": "^15.6.1",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "author": "",
27
27
  "license": "ISC",
28
- "gitHead": "dcee1f0b6df57d63e74fd7b088ad69afa4792ae7",
28
+ "gitHead": "6928cab54c01003f8dd8c40b393512116cc3b3f6",
29
29
  "main": "lib/index.js",
30
30
  "module": "src/index.js"
31
31
  }