@pie-element/explicit-constructed-response 9.3.4-next.3 → 10.0.0-beta.0

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.
Files changed (47) hide show
  1. package/configure/lib/alternateResponses.js +139 -184
  2. package/configure/lib/alternateResponses.js.map +1 -1
  3. package/configure/lib/alternateSection.js +272 -369
  4. package/configure/lib/alternateSection.js.map +1 -1
  5. package/configure/lib/defaults.js +2 -3
  6. package/configure/lib/defaults.js.map +1 -1
  7. package/configure/lib/ecr-toolbar.js +124 -186
  8. package/configure/lib/ecr-toolbar.js.map +1 -1
  9. package/configure/lib/index.js +126 -203
  10. package/configure/lib/index.js.map +1 -1
  11. package/configure/lib/main.js +434 -550
  12. package/configure/lib/main.js.map +1 -1
  13. package/configure/lib/markupUtils.js +26 -49
  14. package/configure/lib/markupUtils.js.map +1 -1
  15. package/configure/lib/utils.js +5 -5
  16. package/configure/lib/utils.js.map +1 -1
  17. package/configure/package.json +9 -7
  18. package/controller/lib/defaults.js +2 -3
  19. package/controller/lib/defaults.js.map +1 -1
  20. package/controller/lib/index.js +169 -260
  21. package/controller/lib/index.js.map +1 -1
  22. package/controller/package.json +3 -3
  23. package/lib/index.js +71 -115
  24. package/lib/index.js.map +1 -1
  25. package/lib/main.js +174 -248
  26. package/lib/main.js.map +1 -1
  27. package/lib/print.js +39 -83
  28. package/lib/print.js.map +1 -1
  29. package/package.json +14 -19
  30. package/esm/configure.js +0 -33096
  31. package/esm/configure.js.map +0 -1
  32. package/esm/controller.js +0 -5144
  33. package/esm/controller.js.map +0 -1
  34. package/esm/element.js +0 -11518
  35. package/esm/element.js.map +0 -1
  36. package/esm/package.json +0 -3
  37. package/esm/print.js +0 -12202
  38. package/esm/print.js.map +0 -1
  39. package/module/configure.js +0 -1
  40. package/module/controller.js +0 -7460
  41. package/module/demo.js +0 -45
  42. package/module/element.js +0 -1
  43. package/module/index.html +0 -21
  44. package/module/manifest.json +0 -22
  45. package/module/print-demo.js +0 -83
  46. package/module/print.html +0 -18
  47. package/module/print.js +0 -1
@@ -1,422 +1,325 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports["default"] = exports.Choice = exports.AlternateSection = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
7
+ exports.default = exports.Choice = exports.AlternateSection = void 0;
12
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
-
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
-
24
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
-
26
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
-
28
10
  var _react = _interopRequireDefault(require("react"));
29
-
30
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
31
-
32
12
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
33
-
34
13
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
35
-
36
- var _OutlinedInput = _interopRequireDefault(require("@material-ui/core/OutlinedInput"));
37
-
38
- var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
39
-
40
- var _Delete = _interopRequireDefault(require("@material-ui/icons/Delete"));
41
-
42
- var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
43
-
44
- var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
45
-
46
- var _Select = _interopRequireDefault(require("@material-ui/core/Select"));
47
-
48
- var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
49
-
50
- var _styles = require("@material-ui/core/styles");
51
-
14
+ var _Button = _interopRequireDefault(require("@mui/material/Button"));
15
+ var _Delete = _interopRequireDefault(require("@mui/icons-material/Delete"));
16
+ var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
17
+ var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
18
+ var _Select = _interopRequireDefault(require("@mui/material/Select"));
19
+ var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
20
+ var _styles = require("@mui/material/styles");
52
21
  var _max = _interopRequireDefault(require("lodash/max"));
53
-
54
- var _classnames = _interopRequireDefault(require("classnames"));
55
-
56
22
  var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
57
-
58
23
  var _markupUtils = require("./markupUtils");
59
-
60
- 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; }
61
-
62
- 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; }
63
-
64
- 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); }; }
65
-
66
- 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; } }
67
-
68
- var styles = function styles(theme) {
69
- return {
70
- design: {
71
- marginBottom: theme.spacing.unit / 2
72
- },
73
- altChoices: {
74
- alignItems: 'flex-start',
75
- flexDirection: 'column',
76
- display: 'flex',
77
- paddingTop: theme.spacing.unit * 2.5,
78
- '& > *': {
79
- marginBottom: theme.spacing.unit * 2.5,
80
- width: '100%'
81
- }
82
- },
83
- choice: {
84
- flex: '1',
85
- marginRight: theme.spacing.unit * 2.5
86
- },
87
- deleteBtn: {
88
- fill: theme.palette.grey[600]
89
- },
90
- selectContainer: {
91
- alignItems: 'flex-end',
92
- display: 'flex',
93
- justifyContent: 'space-between',
94
- width: '100%'
95
- },
96
- rightContainer: {
97
- alignItems: 'center',
98
- display: 'flex'
99
- },
100
- lengthField: {
101
- width: '230px',
102
- marginRight: theme.spacing.unit * 2.5
103
- },
104
- errorText: {
105
- fontSize: theme.typography.fontSize - 2,
106
- color: theme.palette.error.main,
107
- paddingTop: theme.spacing.unit / 2
108
- },
109
- inputError: {
110
- border: "2px solid ".concat(theme.palette.error.main),
111
- borderRadius: '6px'
112
- }
113
- };
114
- };
115
-
116
- var Choice = /*#__PURE__*/function (_React$Component) {
117
- (0, _inherits2["default"])(Choice, _React$Component);
118
-
119
- var _super = _createSuper(Choice);
120
-
121
- function Choice() {
122
- var _this;
123
-
124
- (0, _classCallCheck2["default"])(this, Choice);
125
-
126
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
127
- args[_key] = arguments[_key];
128
- }
129
-
130
- _this = _super.call.apply(_super, [this].concat(args));
131
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
132
- value: _this.props.markup
24
+ const DesignContainer = (0, _styles.styled)('div')(({
25
+ theme
26
+ }) => ({
27
+ marginBottom: theme.spacing(0.5)
28
+ }));
29
+ const AltChoices = (0, _styles.styled)('div')(({
30
+ theme
31
+ }) => ({
32
+ alignItems: 'flex-start',
33
+ flexDirection: 'column',
34
+ display: 'flex',
35
+ paddingTop: theme.spacing(2.5),
36
+ '& > *': {
37
+ marginBottom: theme.spacing(2.5),
38
+ width: '100%'
39
+ }
40
+ }));
41
+ const StyledEditableHtml = (0, _styles.styled)(_editableHtml.default)(({
42
+ theme,
43
+ hasError
44
+ }) => ({
45
+ flex: '1',
46
+ marginRight: theme.spacing(2.5),
47
+ ...(hasError && {
48
+ border: `2px solid ${theme.palette.error.main}`,
49
+ borderRadius: '6px'
50
+ })
51
+ }));
52
+ const StyledDeleteButton = (0, _styles.styled)(_IconButton.default)(({
53
+ theme
54
+ }) => ({
55
+ '& svg': {
56
+ fill: theme.palette.grey[600]
57
+ }
58
+ }));
59
+ const SelectContainer = (0, _styles.styled)('div')({
60
+ alignItems: 'flex-end',
61
+ display: 'flex',
62
+ justifyContent: 'space-between',
63
+ width: '100%'
64
+ });
65
+ const RightContainer = (0, _styles.styled)('div')({
66
+ alignItems: 'center',
67
+ display: 'flex'
68
+ });
69
+ const LengthField = (0, _styles.styled)(_TextField.default)(({
70
+ theme
71
+ }) => ({
72
+ width: '230px',
73
+ marginRight: theme.spacing(2.5),
74
+ '& .MuiInput-underline:before': {
75
+ borderBottomColor: theme.palette.divider
76
+ },
77
+ '& .MuiInput-underline:hover:not(.Mui-disabled):before': {
78
+ borderBottomColor: theme.palette.text.primary
79
+ },
80
+ '& .MuiInput-underline:after': {
81
+ borderBottomColor: theme.palette.primary.main
82
+ }
83
+ }));
84
+ const ErrorText = (0, _styles.styled)('div')(({
85
+ theme
86
+ }) => ({
87
+ fontSize: theme.typography.fontSize - 2,
88
+ color: theme.palette.error.main,
89
+ paddingTop: theme.spacing(0.5)
90
+ }));
91
+ const ChoiceWrapper = (0, _styles.styled)('div')({
92
+ alignItems: 'center',
93
+ display: 'flex',
94
+ justifyContent: 'space-between'
95
+ });
96
+ class Choice extends _react.default.Component {
97
+ constructor(...args) {
98
+ super(...args);
99
+ (0, _defineProperty2.default)(this, "state", {
100
+ value: this.props.markup
133
101
  });
134
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateText", (0, _debounce["default"])(_this.props.onChange, 300));
135
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (e) {
136
- var strippedValue = (0, _markupUtils.stripHtmlTags)(e);
137
-
138
- _this.setState({
102
+ (0, _defineProperty2.default)(this, "updateText", (0, _debounce.default)(this.props.onChange, 300));
103
+ (0, _defineProperty2.default)(this, "onChange", e => {
104
+ const strippedValue = (0, _markupUtils.stripHtmlTags)(e);
105
+ this.setState({
139
106
  value: strippedValue
140
107
  });
141
-
142
- _this.updateText(strippedValue);
108
+ this.updateText(strippedValue);
143
109
  });
144
- return _this;
145
110
  }
146
-
147
- (0, _createClass2["default"])(Choice, [{
148
- key: "UNSAFE_componentWillReceiveProps",
149
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
150
- if (nextProps.markup) {
151
- this.setState({
152
- value: nextProps.markup
153
- });
154
- }
155
- }
156
- }, {
157
- key: "render",
158
- value: function render() {
159
- var _pluginProps$characte;
160
-
161
- var value = this.state.value;
162
- var _this$props = this.props,
163
- classes = _this$props.classes,
164
- onDelete = _this$props.onDelete,
165
- spellCheck = _this$props.spellCheck,
166
- error = _this$props.error,
167
- showMaxLength = _this$props.showMaxLength,
168
- pluginProps = _this$props.pluginProps;
169
- var inputProps = showMaxLength ? {} : {
170
- maxLength: 25
171
- };
172
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
173
- style: {
174
- alignItems: 'center',
175
- display: 'flex',
176
- justifyContent: 'space-between'
177
- }
178
- }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], (0, _extends2["default"])({
179
- className: (0, _classnames["default"])(classes.choice, error && classes.inputError),
180
- disableUnderline: true,
181
- onChange: this.onChange,
182
- markup: value || '',
183
- activePlugins: ['languageCharacters'],
184
- pluginProps: pluginProps,
185
- languageCharactersProps: [{
186
- language: 'spanish'
187
- }],
188
- spellCheck: spellCheck,
189
- autoWidthToolbar: true,
190
- toolbarOpts: {
191
- minWidth: 'auto',
192
- isHidden: !!(pluginProps !== null && pluginProps !== void 0 && (_pluginProps$characte = pluginProps.characters) !== null && _pluginProps$characte !== void 0 && _pluginProps$characte.disabled)
193
- }
194
- }, inputProps)), /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
195
- "aria-label": "delete",
196
- className: classes.deleteBtn,
197
- onClick: onDelete
198
- }, /*#__PURE__*/_react["default"].createElement(_Delete["default"], null))), error && /*#__PURE__*/_react["default"].createElement("div", {
199
- className: classes.errorText
200
- }, error));
111
+ UNSAFE_componentWillReceiveProps(nextProps) {
112
+ if (nextProps.markup) {
113
+ this.setState({
114
+ value: nextProps.markup
115
+ });
201
116
  }
202
- }]);
203
- return Choice;
204
- }(_react["default"].Component);
205
-
117
+ }
118
+ render() {
119
+ const {
120
+ value
121
+ } = this.state;
122
+ const {
123
+ onDelete,
124
+ spellCheck,
125
+ error,
126
+ showMaxLength,
127
+ pluginProps
128
+ } = this.props;
129
+ const inputProps = showMaxLength ? {} : {
130
+ maxLength: 25
131
+ };
132
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ChoiceWrapper, null, /*#__PURE__*/_react.default.createElement(StyledEditableHtml, (0, _extends2.default)({
133
+ hasError: !!error,
134
+ disableUnderline: true,
135
+ onChange: this.onChange,
136
+ markup: value || '',
137
+ activePlugins: ['languageCharacters'],
138
+ pluginProps: pluginProps,
139
+ languageCharactersProps: [{
140
+ language: 'spanish'
141
+ }],
142
+ spellCheck: spellCheck,
143
+ autoWidthToolbar: true,
144
+ toolbarOpts: {
145
+ minWidth: 'auto',
146
+ isHidden: !!pluginProps?.characters?.disabled
147
+ }
148
+ }, inputProps)), /*#__PURE__*/_react.default.createElement(StyledDeleteButton, {
149
+ "aria-label": "delete",
150
+ onClick: onDelete,
151
+ size: "large"
152
+ }, /*#__PURE__*/_react.default.createElement(_Delete.default, null))), error && /*#__PURE__*/_react.default.createElement(ErrorText, null, error));
153
+ }
154
+ }
206
155
  exports.Choice = Choice;
207
- (0, _defineProperty2["default"])(Choice, "propTypes", {
208
- classes: _propTypes["default"].object,
209
- error: _propTypes["default"].string,
210
- markup: _propTypes["default"].string,
211
- onChange: _propTypes["default"].func.isRequired,
212
- onDelete: _propTypes["default"].func.isRequired,
213
- value: _propTypes["default"].string,
214
- spellCheck: _propTypes["default"].bool,
215
- showMaxLength: _propTypes["default"].bool,
216
- pluginProps: _propTypes["default"].object
156
+ (0, _defineProperty2.default)(Choice, "propTypes", {
157
+ error: _propTypes.default.string,
158
+ markup: _propTypes.default.string,
159
+ onChange: _propTypes.default.func.isRequired,
160
+ onDelete: _propTypes.default.func.isRequired,
161
+ value: _propTypes.default.string,
162
+ spellCheck: _propTypes.default.bool,
163
+ showMaxLength: _propTypes.default.bool,
164
+ pluginProps: _propTypes.default.object
217
165
  });
218
-
219
- var AlternateSection = /*#__PURE__*/function (_React$Component2) {
220
- (0, _inherits2["default"])(AlternateSection, _React$Component2);
221
-
222
- var _super2 = _createSuper(AlternateSection);
223
-
224
- function AlternateSection() {
225
- var _this2;
226
-
227
- (0, _classCallCheck2["default"])(this, AlternateSection);
228
-
229
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
230
- args[_key2] = arguments[_key2];
231
- }
232
-
233
- _this2 = _super2.call.apply(_super2, [this].concat(args));
234
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "state", {});
235
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "updateChoicesIfNeeded", function (props) {
236
- if (!_this2.state.choices || !(0, _isEqual["default"])(props.choices, _this2.state.choices) || !(0, _isEqual["default"])(props.choices, _this2.props.choices)) {
237
- _this2.setState({
166
+ class AlternateSection extends _react.default.Component {
167
+ constructor(...args) {
168
+ super(...args);
169
+ (0, _defineProperty2.default)(this, "state", {});
170
+ (0, _defineProperty2.default)(this, "updateChoicesIfNeeded", props => {
171
+ if (!this.state.choices || !(0, _isEqual.default)(props.choices, this.state.choices) || !(0, _isEqual.default)(props.choices, this.props.choices)) {
172
+ this.setState({
238
173
  choices: props.choices
239
174
  });
240
175
  }
241
176
  });
242
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "handleSelect", function (e) {
243
- var _this2$props = _this2.props,
244
- onSelect = _this2$props.onSelect,
245
- selectChoices = _this2$props.selectChoices;
246
- var value = e.target.value;
247
- onSelect(selectChoices.find(function (c) {
248
- return c.value === value;
249
- }));
177
+ (0, _defineProperty2.default)(this, "handleSelect", e => {
178
+ const {
179
+ onSelect,
180
+ selectChoices
181
+ } = this.props;
182
+ const {
183
+ value
184
+ } = e.target;
185
+ onSelect(selectChoices.find(c => c.value === value));
250
186
  });
251
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onAddChoice", function () {
252
- var choices = _this2.state.choices;
253
-
187
+ (0, _defineProperty2.default)(this, "onAddChoice", () => {
188
+ const {
189
+ choices
190
+ } = this.state;
254
191
  if (choices.length && choices[choices.length - 1].label !== '') {
255
- var value = (0, _max["default"])(choices.map(function (c) {
256
- return parseInt(c.value);
257
- }).filter(function (id) {
258
- return !isNaN(id);
259
- })) || 0;
260
-
261
- _this2.setState({
262
- choices: [].concat((0, _toConsumableArray2["default"])(choices), [{
263
- value: "".concat(value + 1),
192
+ const value = (0, _max.default)(choices.map(c => parseInt(c.value)).filter(id => !isNaN(id))) || 0;
193
+ this.setState({
194
+ choices: [...choices, {
195
+ value: `${value + 1}`,
264
196
  label: ''
265
- }])
197
+ }]
266
198
  });
267
199
  }
268
200
  });
269
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onChoiceChanged", function (choice, value, index) {
270
- var _this2$props2 = _this2.props,
271
- choiceChanged = _this2$props2.choiceChanged,
272
- lengthChanged = _this2$props2.lengthChanged,
273
- maxLength = _this2$props2.maxLength,
274
- choices = _this2$props2.choices;
275
- var labelLengthsArr = choices.map(function (choice) {
276
- return (0, _markupUtils.decodeHTML)(choice.label || '').length;
277
- });
201
+ (0, _defineProperty2.default)(this, "onChoiceChanged", (choice, value, index) => {
202
+ const {
203
+ choiceChanged,
204
+ lengthChanged,
205
+ maxLength,
206
+ choices
207
+ } = this.props;
208
+ const labelLengthsArr = choices.map(choice => (0, _markupUtils.decodeHTML)(choice.label || '').length);
278
209
  labelLengthsArr[index] = (0, _markupUtils.decodeHTML)(value).length;
279
- var newLength = Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
280
- choiceChanged(_objectSpread(_objectSpread({}, choice), {}, {
210
+ const newLength = Math.max(...labelLengthsArr);
211
+ choiceChanged({
212
+ ...choice,
281
213
  label: value
282
- }));
283
-
214
+ });
284
215
  if (newLength > maxLength || newLength + 10 <= maxLength) {
285
216
  lengthChanged((0, _markupUtils.getAdjustedLength)(newLength));
286
217
  }
287
218
  });
288
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onRemoveChoice", function (choice) {
289
- var choiceRemoved = _this2.props.choiceRemoved;
219
+ (0, _defineProperty2.default)(this, "onRemoveChoice", choice => {
220
+ const {
221
+ choiceRemoved
222
+ } = this.props;
290
223
  choiceRemoved(choice.value);
291
224
  });
292
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "getChoicesMaxLength", function () {
293
- var choices = _this2.state.choices;
294
-
225
+ (0, _defineProperty2.default)(this, "getChoicesMaxLength", () => {
226
+ const {
227
+ choices
228
+ } = this.state;
295
229
  if (!choices) {
296
230
  return 1;
297
231
  }
298
-
299
- var labelLengthsArr = choices.map(function (choice) {
300
- return (0, _markupUtils.decodeHTML)(choice.label || '').length;
301
- });
302
- return Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
232
+ const labelLengthsArr = choices.map(choice => (0, _markupUtils.decodeHTML)(choice.label || '').length);
233
+ return Math.max(...labelLengthsArr);
303
234
  });
304
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "changeLength", function (event) {
305
- var lengthChanged = _this2.props.lengthChanged;
306
- var numberValue = parseInt(event.target.value, 10);
307
-
308
- var minLength = _this2.getChoicesMaxLength();
309
-
235
+ (0, _defineProperty2.default)(this, "changeLength", event => {
236
+ const {
237
+ lengthChanged
238
+ } = this.props;
239
+ const numberValue = parseInt(event.target.value, 10);
240
+ const minLength = this.getChoicesMaxLength();
310
241
  if (numberValue && numberValue >= minLength && numberValue <= minLength + 10) {
311
242
  lengthChanged(numberValue);
312
243
  }
313
244
  });
314
- return _this2;
315
245
  }
316
-
317
- (0, _createClass2["default"])(AlternateSection, [{
318
- key: "UNSAFE_componentWillReceiveProps",
319
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
320
- this.updateChoicesIfNeeded(nextProps);
321
- }
322
- }, {
323
- key: "componentDidMount",
324
- value: function componentDidMount() {
325
- this.updateChoicesIfNeeded(this.props);
326
- }
327
- }, {
328
- key: "render",
329
- value: function render() {
330
- var _this3 = this;
331
-
332
- var _this$props2 = this.props,
333
- classes = _this$props2.classes,
334
- selectChoices = _this$props2.selectChoices,
335
- maxLength = _this$props2.maxLength,
336
- showMaxLength = _this$props2.showMaxLength,
337
- value = _this$props2.value,
338
- spellCheck = _this$props2.spellCheck,
339
- errors = _this$props2.errors,
340
- pluginProps = _this$props2.pluginProps;
341
- var choices = this.state.choices;
342
- var minLength = this.getChoicesMaxLength();
343
- return /*#__PURE__*/_react["default"].createElement("div", {
344
- className: classes.design
345
- }, /*#__PURE__*/_react["default"].createElement("div", {
346
- className: classes.selectContainer
347
- }, /*#__PURE__*/_react["default"].createElement(_Select["default"], {
348
- className: classes.select,
349
- displayEmpty: true,
350
- onChange: this.handleSelect,
351
- value: value || '',
352
- readOnly: showMaxLength
353
- }, /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
354
- value: ""
355
- }, /*#__PURE__*/_react["default"].createElement("em", null, value ? 'Remove selection' : 'Select a response')), selectChoices.map(function (c, index) {
356
- return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
357
- key: index,
358
- value: c === null || c === void 0 ? void 0 : c.value
359
- }, (0, _markupUtils.decodeHTML)(c === null || c === void 0 ? void 0 : c.label));
360
- })), choices && choices.length > 0 && /*#__PURE__*/_react["default"].createElement("div", {
361
- className: classes.rightContainer
362
- }, maxLength && showMaxLength && /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
363
- className: classes.lengthField,
364
- label: "Maximum length (characters)",
365
- type: "number",
366
- inputProps: {
367
- min: minLength,
368
- max: minLength + 10
369
- },
370
- value: maxLength,
371
- onChange: this.changeLength
372
- }), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
373
- className: classes.addButton,
374
- variant: "contained",
375
- color: "primary",
376
- onClick: this.onAddChoice
377
- }, "Add"))), errors && errors[0] && /*#__PURE__*/_react["default"].createElement("div", {
378
- className: classes.errorText
379
- }, errors[0]), /*#__PURE__*/_react["default"].createElement("div", {
380
- className: classes.altChoices
381
- }, choices && choices.map(function (c, index) {
382
- return index > 0 && /*#__PURE__*/_react["default"].createElement(Choice, {
383
- key: index,
384
- classes: classes,
385
- markup: c.label,
386
- onChange: function onChange(val) {
387
- return _this3.onChoiceChanged(c, val, index);
388
- },
389
- onDelete: function onDelete() {
390
- return _this3.onRemoveChoice(c);
391
- },
392
- spellCheck: spellCheck,
393
- error: errors && errors[index],
394
- showMaxLength: showMaxLength,
395
- pluginProps: pluginProps
396
- });
397
- })));
398
- }
399
- }]);
400
- return AlternateSection;
401
- }(_react["default"].Component);
402
-
246
+ UNSAFE_componentWillReceiveProps(nextProps) {
247
+ this.updateChoicesIfNeeded(nextProps);
248
+ }
249
+ componentDidMount() {
250
+ this.updateChoicesIfNeeded(this.props);
251
+ }
252
+ render() {
253
+ const {
254
+ selectChoices,
255
+ maxLength,
256
+ showMaxLength,
257
+ value,
258
+ spellCheck,
259
+ errors,
260
+ pluginProps
261
+ } = this.props;
262
+ const {
263
+ choices
264
+ } = this.state;
265
+ const minLength = this.getChoicesMaxLength();
266
+ return /*#__PURE__*/_react.default.createElement(DesignContainer, null, /*#__PURE__*/_react.default.createElement(SelectContainer, null, /*#__PURE__*/_react.default.createElement(_Select.default, {
267
+ variant: "standard",
268
+ displayEmpty: true,
269
+ onChange: this.handleSelect,
270
+ value: value || '',
271
+ readOnly: showMaxLength,
272
+ MenuProps: {
273
+ transitionDuration: {
274
+ enter: 225,
275
+ exit: 195
276
+ }
277
+ }
278
+ }, /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
279
+ value: ""
280
+ }, /*#__PURE__*/_react.default.createElement("em", null, value ? 'Remove selection' : 'Select a response')), selectChoices.map((c, index) => /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
281
+ key: index,
282
+ value: c?.value
283
+ }, (0, _markupUtils.decodeHTML)(c?.label)))), choices && choices.length > 0 && /*#__PURE__*/_react.default.createElement(RightContainer, null, maxLength && showMaxLength && /*#__PURE__*/_react.default.createElement(LengthField, {
284
+ variant: "standard",
285
+ label: "Maximum length (characters)",
286
+ type: "number",
287
+ inputProps: {
288
+ min: minLength,
289
+ max: minLength + 10
290
+ },
291
+ value: maxLength,
292
+ onChange: this.changeLength
293
+ }), /*#__PURE__*/_react.default.createElement(_Button.default, {
294
+ variant: "contained",
295
+ color: "primary",
296
+ onClick: this.onAddChoice
297
+ }, "Add"))), errors && errors[0] && /*#__PURE__*/_react.default.createElement(ErrorText, null, errors[0]), /*#__PURE__*/_react.default.createElement(AltChoices, null, choices && choices.map((c, index) => index > 0 && /*#__PURE__*/_react.default.createElement(Choice, {
298
+ key: index,
299
+ markup: c.label,
300
+ onChange: val => this.onChoiceChanged(c, val, index),
301
+ onDelete: () => this.onRemoveChoice(c),
302
+ spellCheck: spellCheck,
303
+ error: errors && errors[index],
304
+ showMaxLength: showMaxLength,
305
+ pluginProps: pluginProps
306
+ }))));
307
+ }
308
+ }
403
309
  exports.AlternateSection = AlternateSection;
404
- (0, _defineProperty2["default"])(AlternateSection, "propTypes", {
405
- choices: _propTypes["default"].array,
406
- selectChoices: _propTypes["default"].array.isRequired,
407
- classes: _propTypes["default"].object.isRequired,
408
- errors: _propTypes["default"].object,
409
- onSelect: _propTypes["default"].func.isRequired,
410
- choiceChanged: _propTypes["default"].func.isRequired,
411
- lengthChanged: _propTypes["default"].func,
412
- choiceRemoved: _propTypes["default"].func.isRequired,
413
- value: _propTypes["default"].string,
414
- maxLength: _propTypes["default"].number,
415
- showMaxLength: _propTypes["default"].bool,
416
- spellCheck: _propTypes["default"].bool,
417
- pluginProps: _propTypes["default"].object
310
+ (0, _defineProperty2.default)(AlternateSection, "propTypes", {
311
+ choices: _propTypes.default.array,
312
+ selectChoices: _propTypes.default.array.isRequired,
313
+ errors: _propTypes.default.object,
314
+ onSelect: _propTypes.default.func.isRequired,
315
+ choiceChanged: _propTypes.default.func.isRequired,
316
+ lengthChanged: _propTypes.default.func,
317
+ choiceRemoved: _propTypes.default.func.isRequired,
318
+ value: _propTypes.default.string,
319
+ maxLength: _propTypes.default.number,
320
+ showMaxLength: _propTypes.default.bool,
321
+ spellCheck: _propTypes.default.bool,
322
+ pluginProps: _propTypes.default.object
418
323
  });
419
- var Styled = (0, _styles.withStyles)(styles)(AlternateSection);
420
- var _default = Styled;
421
- exports["default"] = _default;
324
+ var _default = exports.default = AlternateSection;
422
325
  //# sourceMappingURL=alternateSection.js.map