@pie-element/explicit-constructed-response 9.3.4-next.3 → 10.0.0-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.
Files changed (50) hide show
  1. package/CHANGELOG.md +0 -11
  2. package/configure/CHANGELOG.md +0 -11
  3. package/configure/lib/alternateResponses.js +139 -184
  4. package/configure/lib/alternateResponses.js.map +1 -1
  5. package/configure/lib/alternateSection.js +279 -370
  6. package/configure/lib/alternateSection.js.map +1 -1
  7. package/configure/lib/defaults.js +2 -3
  8. package/configure/lib/defaults.js.map +1 -1
  9. package/configure/lib/ecr-toolbar.js +127 -191
  10. package/configure/lib/ecr-toolbar.js.map +1 -1
  11. package/configure/lib/index.js +126 -203
  12. package/configure/lib/index.js.map +1 -1
  13. package/configure/lib/main.js +436 -552
  14. package/configure/lib/main.js.map +1 -1
  15. package/configure/lib/markupUtils.js +26 -49
  16. package/configure/lib/markupUtils.js.map +1 -1
  17. package/configure/lib/utils.js +5 -5
  18. package/configure/lib/utils.js.map +1 -1
  19. package/configure/package.json +9 -7
  20. package/controller/CHANGELOG.md +0 -11
  21. package/controller/lib/defaults.js +2 -3
  22. package/controller/lib/defaults.js.map +1 -1
  23. package/controller/lib/index.js +172 -260
  24. package/controller/lib/index.js.map +1 -1
  25. package/controller/package.json +3 -3
  26. package/lib/index.js +71 -115
  27. package/lib/index.js.map +1 -1
  28. package/lib/main.js +174 -248
  29. package/lib/main.js.map +1 -1
  30. package/lib/print.js +39 -83
  31. package/lib/print.js.map +1 -1
  32. package/package.json +14 -19
  33. package/esm/configure.js +0 -33096
  34. package/esm/configure.js.map +0 -1
  35. package/esm/controller.js +0 -5144
  36. package/esm/controller.js.map +0 -1
  37. package/esm/element.js +0 -11518
  38. package/esm/element.js.map +0 -1
  39. package/esm/package.json +0 -3
  40. package/esm/print.js +0 -12202
  41. package/esm/print.js.map +0 -1
  42. package/module/configure.js +0 -1
  43. package/module/controller.js +0 -7460
  44. package/module/demo.js +0 -45
  45. package/module/element.js +0 -1
  46. package/module/index.html +0 -21
  47. package/module/manifest.json +0 -22
  48. package/module/print-demo.js +0 -83
  49. package/module/print.html +0 -18
  50. package/module/print.js +0 -1
@@ -1,422 +1,331 @@
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
- var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
57
-
22
+ var _editableHtmlTipTap = _interopRequireDefault(require("@pie-lib/editable-html-tip-tap"));
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)(_editableHtmlTipTap.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
- }
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
- });
110
+ (0, _defineProperty2.default)(this, "onKeyDown", event => {
111
+ if (event.key === 'Enter') {
112
+ return true;
154
113
  }
114
+ });
115
+ }
116
+ UNSAFE_componentWillReceiveProps(nextProps) {
117
+ if (nextProps.markup) {
118
+ this.setState({
119
+ value: nextProps.markup
120
+ });
155
121
  }
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));
201
- }
202
- }]);
203
- return Choice;
204
- }(_react["default"].Component);
205
-
122
+ }
123
+ render() {
124
+ const {
125
+ value
126
+ } = this.state;
127
+ const {
128
+ onDelete,
129
+ spellCheck,
130
+ error,
131
+ showMaxLength,
132
+ pluginProps
133
+ } = this.props;
134
+ const inputProps = showMaxLength ? {} : {
135
+ maxLength: 25
136
+ };
137
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ChoiceWrapper, null, /*#__PURE__*/_react.default.createElement(StyledEditableHtml, (0, _extends2.default)({
138
+ hasError: !!error,
139
+ disableUnderline: true,
140
+ onChange: this.onChange,
141
+ onKeyDown: this.onKeyDown,
142
+ markup: value || '',
143
+ activePlugins: ['languageCharacters'],
144
+ pluginProps: pluginProps,
145
+ languageCharactersProps: [{
146
+ language: 'spanish'
147
+ }],
148
+ spellCheck: spellCheck,
149
+ autoWidthToolbar: true,
150
+ toolbarOpts: {
151
+ minWidth: 'auto',
152
+ isHidden: !!pluginProps?.characters?.disabled
153
+ }
154
+ }, inputProps)), /*#__PURE__*/_react.default.createElement(StyledDeleteButton, {
155
+ "aria-label": "delete",
156
+ onClick: onDelete,
157
+ size: "large"
158
+ }, /*#__PURE__*/_react.default.createElement(_Delete.default, null))), error && /*#__PURE__*/_react.default.createElement(ErrorText, null, error));
159
+ }
160
+ }
206
161
  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
162
+ (0, _defineProperty2.default)(Choice, "propTypes", {
163
+ error: _propTypes.default.string,
164
+ markup: _propTypes.default.string,
165
+ onChange: _propTypes.default.func.isRequired,
166
+ onDelete: _propTypes.default.func.isRequired,
167
+ value: _propTypes.default.string,
168
+ spellCheck: _propTypes.default.bool,
169
+ showMaxLength: _propTypes.default.bool,
170
+ pluginProps: _propTypes.default.object
217
171
  });
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({
172
+ class AlternateSection extends _react.default.Component {
173
+ constructor(...args) {
174
+ super(...args);
175
+ (0, _defineProperty2.default)(this, "state", {});
176
+ (0, _defineProperty2.default)(this, "updateChoicesIfNeeded", props => {
177
+ if (!this.state.choices || !(0, _isEqual.default)(props.choices, this.state.choices) || !(0, _isEqual.default)(props.choices, this.props.choices)) {
178
+ this.setState({
238
179
  choices: props.choices
239
180
  });
240
181
  }
241
182
  });
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
- }));
183
+ (0, _defineProperty2.default)(this, "handleSelect", e => {
184
+ const {
185
+ onSelect,
186
+ selectChoices
187
+ } = this.props;
188
+ const {
189
+ value
190
+ } = e.target;
191
+ onSelect(selectChoices.find(c => c.value === value));
250
192
  });
251
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onAddChoice", function () {
252
- var choices = _this2.state.choices;
253
-
193
+ (0, _defineProperty2.default)(this, "onAddChoice", () => {
194
+ const {
195
+ choices
196
+ } = this.state;
254
197
  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),
198
+ const value = (0, _max.default)(choices.map(c => parseInt(c.value)).filter(id => !isNaN(id))) || 0;
199
+ this.setState({
200
+ choices: [...choices, {
201
+ value: `${value + 1}`,
264
202
  label: ''
265
- }])
203
+ }]
266
204
  });
267
205
  }
268
206
  });
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
- });
207
+ (0, _defineProperty2.default)(this, "onChoiceChanged", (choice, value, index) => {
208
+ const {
209
+ choiceChanged,
210
+ lengthChanged,
211
+ maxLength,
212
+ choices
213
+ } = this.props;
214
+ const labelLengthsArr = choices.map(choice => (0, _markupUtils.decodeHTML)(choice.label || '').length);
278
215
  labelLengthsArr[index] = (0, _markupUtils.decodeHTML)(value).length;
279
- var newLength = Math.max.apply(Math, (0, _toConsumableArray2["default"])(labelLengthsArr));
280
- choiceChanged(_objectSpread(_objectSpread({}, choice), {}, {
216
+ const newLength = Math.max(...labelLengthsArr);
217
+ choiceChanged({
218
+ ...choice,
281
219
  label: value
282
- }));
283
-
220
+ });
284
221
  if (newLength > maxLength || newLength + 10 <= maxLength) {
285
222
  lengthChanged((0, _markupUtils.getAdjustedLength)(newLength));
286
223
  }
287
224
  });
288
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onRemoveChoice", function (choice) {
289
- var choiceRemoved = _this2.props.choiceRemoved;
225
+ (0, _defineProperty2.default)(this, "onRemoveChoice", choice => {
226
+ const {
227
+ choiceRemoved
228
+ } = this.props;
290
229
  choiceRemoved(choice.value);
291
230
  });
292
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "getChoicesMaxLength", function () {
293
- var choices = _this2.state.choices;
294
-
231
+ (0, _defineProperty2.default)(this, "getChoicesMaxLength", () => {
232
+ const {
233
+ choices
234
+ } = this.state;
295
235
  if (!choices) {
296
236
  return 1;
297
237
  }
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));
238
+ const labelLengthsArr = choices.map(choice => (0, _markupUtils.decodeHTML)(choice.label || '').length);
239
+ return Math.max(...labelLengthsArr);
303
240
  });
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
-
241
+ (0, _defineProperty2.default)(this, "changeLength", event => {
242
+ const {
243
+ lengthChanged
244
+ } = this.props;
245
+ const numberValue = parseInt(event.target.value, 10);
246
+ const minLength = this.getChoicesMaxLength();
310
247
  if (numberValue && numberValue >= minLength && numberValue <= minLength + 10) {
311
248
  lengthChanged(numberValue);
312
249
  }
313
250
  });
314
- return _this2;
315
251
  }
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
-
252
+ UNSAFE_componentWillReceiveProps(nextProps) {
253
+ this.updateChoicesIfNeeded(nextProps);
254
+ }
255
+ componentDidMount() {
256
+ this.updateChoicesIfNeeded(this.props);
257
+ }
258
+ render() {
259
+ const {
260
+ selectChoices,
261
+ maxLength,
262
+ showMaxLength,
263
+ value,
264
+ spellCheck,
265
+ errors,
266
+ pluginProps
267
+ } = this.props;
268
+ const {
269
+ choices
270
+ } = this.state;
271
+ const minLength = this.getChoicesMaxLength();
272
+ return /*#__PURE__*/_react.default.createElement(DesignContainer, null, /*#__PURE__*/_react.default.createElement(SelectContainer, null, /*#__PURE__*/_react.default.createElement(_Select.default, {
273
+ variant: "standard",
274
+ displayEmpty: true,
275
+ onChange: this.handleSelect,
276
+ value: value || '',
277
+ readOnly: showMaxLength,
278
+ MenuProps: {
279
+ transitionDuration: {
280
+ enter: 225,
281
+ exit: 195
282
+ }
283
+ }
284
+ }, /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
285
+ value: ""
286
+ }, /*#__PURE__*/_react.default.createElement("em", null, value ? 'Remove selection' : 'Select a response')), selectChoices.map((c, index) => /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
287
+ key: index,
288
+ value: c?.value
289
+ }, (0, _markupUtils.decodeHTML)(c?.label)))), choices && choices.length > 0 && /*#__PURE__*/_react.default.createElement(RightContainer, null, maxLength && showMaxLength && /*#__PURE__*/_react.default.createElement(LengthField, {
290
+ variant: "standard",
291
+ label: "Maximum length (characters)",
292
+ type: "number",
293
+ inputProps: {
294
+ min: minLength,
295
+ max: minLength + 10
296
+ },
297
+ value: maxLength,
298
+ onChange: this.changeLength
299
+ }), /*#__PURE__*/_react.default.createElement(_Button.default, {
300
+ variant: "contained",
301
+ color: "primary",
302
+ onClick: this.onAddChoice
303
+ }, "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, {
304
+ key: index,
305
+ markup: c.label,
306
+ onChange: val => this.onChoiceChanged(c, val, index),
307
+ onDelete: () => this.onRemoveChoice(c),
308
+ spellCheck: spellCheck,
309
+ error: errors && errors[index],
310
+ showMaxLength: showMaxLength,
311
+ pluginProps: pluginProps
312
+ }))));
313
+ }
314
+ }
403
315
  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
316
+ (0, _defineProperty2.default)(AlternateSection, "propTypes", {
317
+ choices: _propTypes.default.array,
318
+ selectChoices: _propTypes.default.array.isRequired,
319
+ errors: _propTypes.default.object,
320
+ onSelect: _propTypes.default.func.isRequired,
321
+ choiceChanged: _propTypes.default.func.isRequired,
322
+ lengthChanged: _propTypes.default.func,
323
+ choiceRemoved: _propTypes.default.func.isRequired,
324
+ value: _propTypes.default.string,
325
+ maxLength: _propTypes.default.number,
326
+ showMaxLength: _propTypes.default.bool,
327
+ spellCheck: _propTypes.default.bool,
328
+ pluginProps: _propTypes.default.object
418
329
  });
419
- var Styled = (0, _styles.withStyles)(styles)(AlternateSection);
420
- var _default = Styled;
421
- exports["default"] = _default;
330
+ var _default = exports.default = AlternateSection;
422
331
  //# sourceMappingURL=alternateSection.js.map