@pie-element/explicit-constructed-response 4.6.0 → 4.6.1-beta.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.
@@ -1,20 +1,38 @@
1
1
  {
2
2
  "name": "@pie-element/explicit-constructed-response-configure",
3
- "version": "4.4.0",
3
+ "version": "4.4.1-beta.0",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "modue": "src/index.js",
7
7
  "dependencies": {
8
+ "@emotion/css": "^11.10.0",
8
9
  "@material-ui/core": "^3.9.2",
9
10
  "@material-ui/icons": "^3.0.1",
10
11
  "@pie-framework/pie-configure-events": "^1.3.0",
11
- "@pie-lib/config-ui": "^11.3.0",
12
- "@pie-lib/editable-html": "^9.5.0",
12
+ "@pie-lib/config-ui": "12.0.0-beta.4",
13
+ "@pie-lib/editable-html": "10.0.0-beta.5",
14
+ "@types/is-hotkey": "^0.1.1",
15
+ "@types/lodash": "^4.14.149",
13
16
  "classnames": "^2.2.6",
14
17
  "debug": "^3.1.0",
18
+ "direction": "^1.0.3",
19
+ "is-hotkey": "^0.2.0",
20
+ "is-plain-object": "^5.0.0",
15
21
  "lodash": "^4.17.15",
16
22
  "prop-types": "^15.6.2",
17
23
  "react": "^16.8.1",
18
- "react-dom": "^16.8.1"
24
+ "react-dom": "^16.8.1",
25
+ "scroll-into-view-if-needed": "^2.2.20",
26
+ "slate": "^0.82.1",
27
+ "slate-dev-environment": "^0.2.5",
28
+ "slate-edit-list": "^0.12.1",
29
+ "slate-edit-table": "^0.18.0",
30
+ "slate-history": "^0.66.0",
31
+ "slate-html-serializer": "^0.8.13",
32
+ "slate-hyperscript": "^0.77.0",
33
+ "slate-plain-serializer": "^0.7.13",
34
+ "slate-prop-types": "^0.5.44",
35
+ "slate-react": "0.92.0",
36
+ "tiny-invariant": "1.0.6"
19
37
  }
20
38
  }
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@pie-element/explicit-constructed-response-controller",
3
3
  "private": true,
4
- "version": "3.5.0",
4
+ "version": "3.5.1-beta.0",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "@pie-lib/controller-utils": "^0.2.27",
11
+ "@pie-lib/controller-utils": "^0.2.42",
12
12
  "debug": "^3.1.0",
13
13
  "lodash": "^4.17.15",
14
14
  "type-of": "^2.0.1"
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "repository": "pie-framework/pie-elements",
7
- "version": "4.6.0",
7
+ "version": "4.6.1-beta.1+73223f303",
8
8
  "description": "",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -13,19 +13,21 @@
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.47",
17
- "@pie-lib/mask-markup": "^1.13.0",
18
- "@pie-lib/math-rendering": "^2.5.1",
19
- "@pie-lib/render-ui": "^4.13.7",
16
+ "@pie-lib/correct-answer-toggle": "^2.3.62",
17
+ "@pie-lib/mask-markup": "2.0.0-beta.1",
18
+ "@pie-lib/math-rendering": "^2.5.12",
19
+ "@pie-lib/render-ui": "^4.14.12",
20
20
  "classnames": "^2.2.5",
21
+ "is-plain-object": "^5.0.0",
21
22
  "lodash": "^4.17.10",
22
23
  "prop-types": "^15.6.1",
23
24
  "react": "^16.8.1",
24
- "react-dom": "^16.8.1"
25
+ "react-dom": "^16.8.1",
26
+ "slate-react": "0.92.0"
25
27
  },
26
28
  "author": "",
27
29
  "license": "ISC",
28
- "gitHead": "7fcbba0ed99ce1db1e66598ea6865b4a2425d0a4",
30
+ "gitHead": "73223f303ea31ca510b096d77e6fb06382b0f0c6",
29
31
  "main": "lib/index.js",
30
32
  "module": "src/index.js",
31
33
  "exports": {
@@ -1,241 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = exports.AlternateResponses = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
-
20
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
-
22
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
-
24
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
- var _react = _interopRequireDefault(require("react"));
27
-
28
- var _propTypes = _interopRequireDefault(require("prop-types"));
29
-
30
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
31
-
32
- var _map = _interopRequireDefault(require("lodash/map"));
33
-
34
- var _reduce = _interopRequireDefault(require("lodash/reduce"));
35
-
36
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
37
-
38
- var _alternateSection = _interopRequireDefault(require("./alternateSection"));
39
-
40
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
41
-
42
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
43
-
44
- 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); }; }
45
-
46
- 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; } }
47
-
48
- var AlternateResponses = /*#__PURE__*/function (_React$Component) {
49
- (0, _inherits2["default"])(AlternateResponses, _React$Component);
50
-
51
- var _super = _createSuper(AlternateResponses);
52
-
53
- function AlternateResponses() {
54
- var _this;
55
-
56
- (0, _classCallCheck2["default"])(this, AlternateResponses);
57
-
58
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
59
- args[_key] = arguments[_key];
60
- }
61
-
62
- _this = _super.call.apply(_super, [this].concat(args));
63
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
64
- maxLengthPerChoice: (0, _cloneDeep["default"])(_this.props.model.maxLengthPerChoice)
65
- });
66
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateChoicesIfNeeded", function (props) {
67
- if (!_this.state.choices || !(0, _isEqual["default"])(_this.state.choices, props.model.choices) || !(0, _isEqual["default"])(props.model.choices, _this.props.model.choices) || _this.state.values && Object.keys(_this.state.values).length !== Object.keys(_this.props.model.choices).length || props.maxLengthPerChoiceEnabled !== _this.props.maxLengthPerChoiceEnabled) {
68
- var _props$model = props.model,
69
- choices = _props$model.choices,
70
- maxLengthPerChoice = _props$model.maxLengthPerChoice;
71
- var selectedValues = (0, _reduce["default"])(choices, function (obj, c, key) {
72
- // if maxLengthPerChoiceEnabled is true, we display all the choices
73
- if (c && (props.maxLengthPerChoiceEnabled || c.length > 1)) {
74
- obj[key] = c[0];
75
- }
76
-
77
- return obj;
78
- }, {});
79
-
80
- _this.setState({
81
- choices: props.model.choices,
82
- values: selectedValues,
83
- maxLengthPerChoice: (0, _cloneDeep["default"])(maxLengthPerChoice)
84
- });
85
- }
86
- });
87
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getRemainingChoices", function (valueKey) {
88
- var choices = _this.state.choices;
89
- return (0, _reduce["default"])(choices, function (arr, c, key) {
90
- if (c && c.length === 1 && !valueKey) {
91
- arr.push({
92
- label: c[0].label,
93
- value: key
94
- });
95
- }
96
-
97
- return arr;
98
- }, []);
99
- });
100
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChoiceChanged", function (choice, key) {
101
- var onChange = _this.props.onChange;
102
- var choices = _this.state.choices;
103
- var sectionChoices = choices[key] || [];
104
- var isNew = !sectionChoices.find(function (c) {
105
- return c.value === choice.value;
106
- });
107
- var newChoices = sectionChoices.reduce(function (arr, c) {
108
- var newVal = c.value === choice.value ? choice : c;
109
- arr.push(newVal);
110
- return arr;
111
- }, []);
112
-
113
- if (isNew) {
114
- newChoices.push(choice);
115
- }
116
-
117
- onChange(_objectSpread(_objectSpread({}, choices), {}, (0, _defineProperty2["default"])({}, key, newChoices)));
118
- });
119
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChoiceRemoved", function (value, section) {
120
- var onChange = _this.props.onChange;
121
- var choices = _this.state.choices;
122
- var sectionChoices = choices[section] || [];
123
- var newChoices = sectionChoices.reduce(function (arr, c) {
124
- if (c.value === value) {
125
- return arr;
126
- }
127
-
128
- arr.push(c);
129
- return arr;
130
- }, []);
131
- onChange(_objectSpread(_objectSpread({}, choices), {}, (0, _defineProperty2["default"])({}, section, newChoices)));
132
- });
133
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSectionSelect", function (choice, key) {
134
- var onChange = _this.props.onChange;
135
- var _this$state = _this.state,
136
- choices = _this$state.choices,
137
- values = _this$state.values;
138
-
139
- if (choices[key] && choices[key].length > 1) {
140
- if (!choice) {
141
- onChange(_objectSpread(_objectSpread({}, choices), {}, (0, _defineProperty2["default"])({}, key, [choices[key][0]])));
142
- }
143
- } else {
144
- _this.setState({
145
- choices: _objectSpread(_objectSpread({}, choices), {}, (0, _defineProperty2["default"])({}, key, [].concat((0, _toConsumableArray2["default"])(choices[key]), [{
146
- label: '',
147
- value: '1'
148
- }]))),
149
- values: _objectSpread(_objectSpread({}, values), {}, (0, _defineProperty2["default"])({}, key, choices[key][0]))
150
- });
151
- }
152
- });
153
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onLengthChanged", function (value, key) {
154
- var _this$props = _this.props,
155
- model = _this$props.model,
156
- onLengthChange = _this$props.onLengthChange;
157
- var maxLengthPerChoice = model.maxLengthPerChoice;
158
- maxLengthPerChoice[key] = value;
159
- onLengthChange(maxLengthPerChoice);
160
- });
161
- return _this;
162
- }
163
-
164
- (0, _createClass2["default"])(AlternateResponses, [{
165
- key: "UNSAFE_componentWillReceiveProps",
166
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
167
- this.updateChoicesIfNeeded(nextProps);
168
- }
169
- }, {
170
- key: "componentDidMount",
171
- value: function componentDidMount() {
172
- this.updateChoicesIfNeeded(this.props);
173
- }
174
- }, {
175
- key: "render",
176
- value: function render() {
177
- var _this2 = this;
178
-
179
- var choices = this.state.choices;
180
- var _this$props2 = this.props,
181
- _this$props2$model = _this$props2.model,
182
- maxLengthPerChoice = _this$props2$model.maxLengthPerChoice,
183
- maxLengthPerChoiceEnabled = _this$props2$model.maxLengthPerChoiceEnabled,
184
- spellCheck = _this$props2.spellCheck,
185
- choicesErrors = _this$props2.choicesErrors;
186
- return /*#__PURE__*/_react["default"].createElement("div", null, (0, _map["default"])(choices, function (c, key) {
187
- // if maxLengthPerChoiceEnabled is true, we display all the choices
188
- if (c && (maxLengthPerChoiceEnabled || c.length > 1)) {
189
- var selected = _this2.state.values[key];
190
- return /*#__PURE__*/_react["default"].createElement(_alternateSection["default"], {
191
- key: key,
192
- value: selected && selected.value,
193
- errors: choicesErrors && choicesErrors[key],
194
- onSelect: function onSelect(choice) {
195
- return _this2.onSectionSelect(choice, key);
196
- },
197
- choiceChanged: function choiceChanged(choice) {
198
- return _this2.onChoiceChanged(choice, key);
199
- },
200
- choiceRemoved: function choiceRemoved(value) {
201
- return _this2.onChoiceRemoved(value, key);
202
- },
203
- lengthChanged: function lengthChanged(value) {
204
- return _this2.onLengthChanged(value, key);
205
- },
206
- selectChoices: [selected],
207
- choices: c,
208
- maxLength: maxLengthPerChoice[key],
209
- showMaxLength: maxLengthPerChoiceEnabled,
210
- spellCheck: spellCheck
211
- });
212
- }
213
- }), choices && Object.keys(this.state.values).length !== Object.keys(choices).length && /*#__PURE__*/_react["default"].createElement(_alternateSection["default"], {
214
- value: "",
215
- onSelect: function onSelect(choice) {
216
- return _this2.onSectionSelect(choice, choice.value);
217
- },
218
- choiceChanged: function choiceChanged(choice) {
219
- return _this2.onChoiceChanged(choice);
220
- },
221
- choiceRemoved: function choiceRemoved(value) {
222
- return _this2.onChoiceRemoved(value);
223
- },
224
- selectChoices: this.getRemainingChoices(),
225
- spellCheck: spellCheck
226
- }));
227
- }
228
- }]);
229
- return AlternateResponses;
230
- }(_react["default"].Component);
231
-
232
- exports.AlternateResponses = AlternateResponses;
233
- (0, _defineProperty2["default"])(AlternateResponses, "propTypes", {
234
- model: _propTypes["default"].object.isRequired,
235
- onChange: _propTypes["default"].func.isRequired,
236
- onLengthChange: _propTypes["default"].func.isRequired,
237
- maxLengthPerChoiceEnabled: _propTypes["default"].bool.isRequired
238
- });
239
- var _default = AlternateResponses;
240
- exports["default"] = _default;
241
- //# sourceMappingURL=alternateResponses.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/alternateResponses.jsx"],"names":["AlternateResponses","maxLengthPerChoice","props","model","state","choices","values","Object","keys","length","maxLengthPerChoiceEnabled","selectedValues","obj","c","key","setState","valueKey","arr","push","label","value","choice","onChange","sectionChoices","isNew","find","newChoices","reduce","newVal","section","onLengthChange","nextProps","updateChoicesIfNeeded","spellCheck","choicesErrors","selected","onSectionSelect","onChoiceChanged","onChoiceRemoved","onLengthChanged","getRemainingChoices","React","Component","PropTypes","object","isRequired","func","bool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;IAEaA,kB;;;;;;;;;;;;;;;8FAQH;AAAEC,MAAAA,kBAAkB,EAAE,2BAAU,MAAKC,KAAL,CAAWC,KAAX,CAAiBF,kBAA3B;AAAtB,K;8GAUgB,UAACC,KAAD,EAAW;AACjC,UACE,CAAC,MAAKE,KAAL,CAAWC,OAAZ,IACA,CAAC,yBAAQ,MAAKD,KAAL,CAAWC,OAAnB,EAA4BH,KAAK,CAACC,KAAN,CAAYE,OAAxC,CADD,IAEA,CAAC,yBAAQH,KAAK,CAACC,KAAN,CAAYE,OAApB,EAA6B,MAAKH,KAAL,CAAWC,KAAX,CAAiBE,OAA9C,CAFD,IAGC,MAAKD,KAAL,CAAWE,MAAX,IAAqBC,MAAM,CAACC,IAAP,CAAY,MAAKJ,KAAL,CAAWE,MAAvB,EAA+BG,MAA/B,KAA0CF,MAAM,CAACC,IAAP,CAAY,MAAKN,KAAL,CAAWC,KAAX,CAAiBE,OAA7B,EAAsCI,MAHtG,IAIAP,KAAK,CAACQ,yBAAN,KAAoC,MAAKR,KAAL,CAAWQ,yBALjD,EAME;AACA,2BAAwCR,KAAK,CAACC,KAA9C;AAAA,YAAQE,OAAR,gBAAQA,OAAR;AAAA,YAAiBJ,kBAAjB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,CADH,EAwBG5B,OAAO,IAAIE,MAAM,CAACC,IAAP,CAAY,KAAKJ,KAAL,CAAWE,MAAvB,EAA+BG,MAA/B,KAA0CF,MAAM,CAACC,IAAP,CAAYH,OAAZ,EAAqBI,MAA1E,iBACC,gCAAC,4BAAD;AACE,QAAA,KAAK,EAAC,EADR;AAEE,QAAA,QAAQ,EAAE,kBAACY,MAAD;AAAA,iBAAY,MAAI,CAACe,eAAL,CAAqBf,MAArB,EAA6BA,MAAM,CAACD,KAApC,CAAZ;AAAA,SAFZ;AAGE,QAAA,aAAa,EAAE,uBAACC,MAAD;AAAA,iBAAY,MAAI,CAACgB,eAAL,CAAqBhB,MAArB,CAAZ;AAAA,SAHjB;AAIE,QAAA,aAAa,EAAE,uBAACD,KAAD;AAAA,iBAAW,MAAI,CAACkB,eAAL,CAAqBlB,KAArB,CAAX;AAAA,SAJjB;AAKE,QAAA,aAAa,EAAE,KAAKoB,mBAAL,EALjB;AAME,QAAA,UAAU,EAAEP;AANd,QAzBJ,CADF;AAqCD;;;EAtMqCQ,kBAAMC,S;;;iCAAjC1C,kB,eACQ;AACjBG,EAAAA,KAAK,EAAEwC,sBAAUC,MAAV,CAAiBC,UADP;AAEjBvB,EAAAA,QAAQ,EAAEqB,sBAAUG,IAAV,CAAeD,UAFR;AAGjBf,EAAAA,cAAc,EAAEa,sBAAUG,IAAV,CAAeD,UAHd;AAIjBnC,EAAAA,yBAAyB,EAAEiC,sBAAUI,IAAV,CAAeF;AAJzB,C;eAwMN7C,kB","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport isEqual from 'lodash/isEqual';\nimport map from 'lodash/map';\nimport reduce from 'lodash/reduce';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport AlternateSection from './alternateSection';\n\nexport class AlternateResponses extends React.Component {\n static propTypes = {\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n onLengthChange: PropTypes.func.isRequired,\n maxLengthPerChoiceEnabled: PropTypes.bool.isRequired,\n };\n\n state = { maxLengthPerChoice: cloneDeep(this.props.model.maxLengthPerChoice) };\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n this.updateChoicesIfNeeded(nextProps);\n }\n\n componentDidMount() {\n this.updateChoicesIfNeeded(this.props);\n }\n\n updateChoicesIfNeeded = (props) => {\n if (\n !this.state.choices ||\n !isEqual(this.state.choices, props.model.choices) ||\n !isEqual(props.model.choices, this.props.model.choices) ||\n (this.state.values && Object.keys(this.state.values).length !== Object.keys(this.props.model.choices).length) ||\n props.maxLengthPerChoiceEnabled !== this.props.maxLengthPerChoiceEnabled\n ) {\n const { choices, maxLengthPerChoice } = props.model;\n\n const selectedValues = reduce(\n choices,\n (obj, c, key) => {\n // if maxLengthPerChoiceEnabled is true, we display all the choices\n if (c && (props.maxLengthPerChoiceEnabled || c.length > 1)) {\n obj[key] = c[0];\n }\n\n return obj;\n },\n {},\n );\n\n this.setState({\n choices: props.model.choices,\n values: selectedValues,\n maxLengthPerChoice: cloneDeep(maxLengthPerChoice),\n });\n }\n };\n\n getRemainingChoices = (valueKey) => {\n const { choices } = this.state;\n\n return reduce(\n choices,\n (arr, c, key) => {\n if (c && c.length === 1 && !valueKey) {\n arr.push({\n label: c[0].label,\n value: key,\n });\n }\n\n return arr;\n },\n [],\n );\n };\n\n onChoiceChanged = (choice, key) => {\n const { onChange } = this.props;\n const { choices } = this.state;\n const sectionChoices = choices[key] || [];\n\n const isNew = !sectionChoices.find((c) => c.value === choice.value);\n\n const newChoices = sectionChoices.reduce((arr, c) => {\n const newVal = c.value === choice.value ? choice : c;\n\n arr.push(newVal);\n\n return arr;\n }, []);\n\n if (isNew) {\n newChoices.push(choice);\n }\n\n onChange({\n ...choices,\n [key]: newChoices,\n });\n };\n\n onChoiceRemoved = (value, section) => {\n const { onChange } = this.props;\n const { choices } = this.state;\n const sectionChoices = choices[section] || [];\n\n const newChoices = sectionChoices.reduce((arr, c) => {\n if (c.value === value) {\n return arr;\n }\n\n arr.push(c);\n\n return arr;\n }, []);\n\n onChange({\n ...choices,\n [section]: newChoices,\n });\n };\n\n onSectionSelect = (choice, key) => {\n const { onChange } = this.props;\n const { choices, values } = this.state;\n\n if (choices[key] && choices[key].length > 1) {\n if (!choice) {\n onChange({\n ...choices,\n [key]: [choices[key][0]],\n });\n }\n } else {\n this.setState({\n choices: {\n ...choices,\n [key]: [\n ...choices[key],\n {\n label: '',\n value: '1',\n },\n ],\n },\n values: {\n ...values,\n [key]: choices[key][0],\n },\n });\n }\n };\n\n onLengthChanged = (value, key) => {\n const { model, onLengthChange } = this.props;\n const { maxLengthPerChoice } = model;\n\n maxLengthPerChoice[key] = value;\n onLengthChange(maxLengthPerChoice);\n };\n\n render() {\n const { choices } = this.state;\n const {\n model: { maxLengthPerChoice, maxLengthPerChoiceEnabled },\n spellCheck,\n choicesErrors,\n } = this.props;\n\n return (\n <div>\n {map(choices, (c, key) => {\n // if maxLengthPerChoiceEnabled is true, we display all the choices\n if (c && (maxLengthPerChoiceEnabled || c.length > 1)) {\n const selected = this.state.values[key];\n\n return (\n <AlternateSection\n key={key}\n value={selected && selected.value}\n errors={choicesErrors && choicesErrors[key]}\n onSelect={(choice) => this.onSectionSelect(choice, key)}\n choiceChanged={(choice) => this.onChoiceChanged(choice, key)}\n choiceRemoved={(value) => this.onChoiceRemoved(value, key)}\n lengthChanged={(value) => this.onLengthChanged(value, key)}\n selectChoices={[selected]}\n choices={c}\n maxLength={maxLengthPerChoice[key]}\n showMaxLength={maxLengthPerChoiceEnabled}\n spellCheck={spellCheck}\n />\n );\n }\n })}\n {choices && Object.keys(this.state.values).length !== Object.keys(choices).length && (\n <AlternateSection\n value=\"\"\n onSelect={(choice) => this.onSectionSelect(choice, choice.value)}\n choiceChanged={(choice) => this.onChoiceChanged(choice)}\n choiceRemoved={(value) => this.onChoiceRemoved(value)}\n selectChoices={this.getRemainingChoices()}\n spellCheck={spellCheck}\n />\n )}\n </div>\n );\n }\n}\n\nexport default AlternateResponses;\n"],"file":"alternateResponses.js"}