@pie-element/multiple-choice 7.6.1-beta.2 → 7.6.1-beta.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.
Files changed (40) hide show
  1. package/configure/package.json +3 -3
  2. package/package.json +3 -3
  3. package/configure/lib/__tests__/root.test.js +0 -271
  4. package/configure/lib/defaults.js +0 -120
  5. package/configure/lib/defaults.js.map +0 -1
  6. package/configure/lib/index.js +0 -212
  7. package/configure/lib/index.js.map +0 -1
  8. package/configure/lib/main.js +0 -604
  9. package/configure/lib/main.js.map +0 -1
  10. package/configure/lib/utils.js +0 -18
  11. package/configure/lib/utils.js.map +0 -1
  12. package/controller/lib/__tests__/index.test.js +0 -864
  13. package/controller/lib/__tests__/utils.test.js +0 -8
  14. package/controller/lib/defaults.js +0 -18
  15. package/controller/lib/defaults.js.map +0 -1
  16. package/controller/lib/index.js +0 -305
  17. package/controller/lib/index.js.map +0 -1
  18. package/controller/lib/utils.js +0 -36
  19. package/controller/lib/utils.js.map +0 -1
  20. package/docs/demo/pie.manifest.json +0 -11
  21. package/lib/__tests__/choice-input-test.js +0 -124
  22. package/lib/__tests__/index-test.js +0 -22
  23. package/lib/__tests__/multiple-choice-test.js +0 -237
  24. package/lib/__tests__/session-updater-test.js +0 -72
  25. package/lib/choice-input.js +0 -298
  26. package/lib/choice-input.js.map +0 -1
  27. package/lib/choice.js +0 -157
  28. package/lib/choice.js.map +0 -1
  29. package/lib/feedback-tick.js +0 -174
  30. package/lib/feedback-tick.js.map +0 -1
  31. package/lib/index.js +0 -151
  32. package/lib/index.js.map +0 -1
  33. package/lib/main.js +0 -100
  34. package/lib/main.js.map +0 -1
  35. package/lib/multiple-choice.js +0 -263
  36. package/lib/multiple-choice.js.map +0 -1
  37. package/lib/print.js +0 -129
  38. package/lib/print.js.map +0 -1
  39. package/lib/session-updater.js +0 -35
  40. package/lib/session-updater.js.map +0 -1
@@ -1,604 +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.Main = void 0;
9
-
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
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 _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
31
-
32
- var _configUi = require("@pie-lib/config-ui");
33
-
34
- var _renderUi = require("@pie-lib/render-ui");
35
-
36
- var _styles = require("@material-ui/core/styles");
37
-
38
- var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
39
-
40
- var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
41
-
42
- var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
43
-
44
- var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
45
-
46
- var _merge = _interopRequireDefault(require("lodash/merge"));
47
-
48
- var _utils = require("./utils");
49
-
50
- 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); }; }
51
-
52
- 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; } }
53
-
54
- 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; }
55
-
56
- 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; }
57
-
58
- var Panel = _configUi.settings.Panel,
59
- toggle = _configUi.settings.toggle,
60
- radio = _configUi.settings.radio,
61
- dropdown = _configUi.settings.dropdown;
62
- var MAX_CHOICES = 9;
63
-
64
- var styles = function styles(theme) {
65
- return {
66
- promptHolder: {
67
- width: '100%',
68
- paddingBottom: theme.spacing.unit * 2,
69
- marginBottom: theme.spacing.unit * 2
70
- },
71
- prompt: {
72
- paddingTop: theme.spacing.unit * 2,
73
- width: '100%'
74
- },
75
- rationaleHolder: {
76
- width: '70%'
77
- },
78
- accessibilityHolder: {
79
- width: '70%'
80
- },
81
- rationale: {
82
- paddingTop: theme.spacing.unit * 2
83
- },
84
- accessibility: {
85
- paddingTop: theme.spacing.unit * 2
86
- },
87
- choiceConfigurationHolder: {
88
- display: 'flex',
89
- flexDirection: 'column',
90
- alignItems: 'center'
91
- },
92
- choiceConfiguration: {
93
- width: '100%',
94
- paddingTop: theme.spacing.unit * 2,
95
- paddingBottom: theme.spacing.unit * 2
96
- },
97
- switchElement: {
98
- justifyContent: 'space-between',
99
- margin: 0
100
- },
101
- addButton: {
102
- marginTop: theme.spacing.unit * 3,
103
- "float": 'right'
104
- },
105
- disableButton: {
106
- cursor: 'not-allowed',
107
- pointerEvents: 'all',
108
- backgroundColor: _renderUi.color.disabled(),
109
- '&:hover': {
110
- backgroundColor: _renderUi.color.disabled()
111
- },
112
- '&:focus': {
113
- backgroundColor: _renderUi.color.disabled()
114
- }
115
- },
116
- flexContainer: {
117
- display: 'flex',
118
- alignItems: 'center',
119
- marginBottom: theme.spacing.unit
120
- },
121
- titleText: {
122
- fontFamily: 'Cerebri Sans',
123
- fontSize: theme.typography.fontSize + 2,
124
- lineHeight: '19px',
125
- color: '#495B8F',
126
- marginRight: theme.spacing.unit
127
- },
128
- tooltip: {
129
- fontSize: theme.typography.fontSize - 2,
130
- whiteSpace: 'pre',
131
- maxWidth: '500px'
132
- },
133
- errorText: {
134
- fontSize: theme.typography.fontSize - 2,
135
- color: 'red',
136
- paddingTop: theme.spacing.unit
137
- }
138
- };
139
- };
140
-
141
- var Design = (0, _styles.withStyles)(styles)(function (props) {
142
- var classes = props.classes,
143
- model = props.model,
144
- configuration = props.configuration,
145
- onPromptChanged = props.onPromptChanged,
146
- onChoiceChanged = props.onChoiceChanged,
147
- onRemoveChoice = props.onRemoveChoice,
148
- onAddChoice = props.onAddChoice,
149
- imageSupport = props.imageSupport,
150
- uploadSoundSupport = props.uploadSoundSupport,
151
- onChangeModel = props.onChangeModel,
152
- onConfigurationChanged = props.onConfigurationChanged,
153
- onTeacherInstructionsChanged = props.onTeacherInstructionsChanged;
154
-
155
- var _ref = configuration || {},
156
- _ref$prompt = _ref.prompt,
157
- prompt = _ref$prompt === void 0 ? {} : _ref$prompt,
158
- _ref$addChoiceButton = _ref.addChoiceButton,
159
- addChoiceButton = _ref$addChoiceButton === void 0 ? {} : _ref$addChoiceButton,
160
- _ref$feedback = _ref.feedback,
161
- feedback = _ref$feedback === void 0 ? {} : _ref$feedback,
162
- _ref$deleteChoice = _ref.deleteChoice,
163
- deleteChoice = _ref$deleteChoice === void 0 ? {} : _ref$deleteChoice,
164
- _ref$choiceMode = _ref.choiceMode,
165
- choiceMode = _ref$choiceMode === void 0 ? {} : _ref$choiceMode,
166
- _ref$choicePrefix = _ref.choicePrefix,
167
- choicePrefix = _ref$choicePrefix === void 0 ? {} : _ref$choicePrefix,
168
- _ref$partialScoring = _ref.partialScoring,
169
- partialScoring = _ref$partialScoring === void 0 ? {} : _ref$partialScoring,
170
- _ref$lockChoiceOrder = _ref.lockChoiceOrder,
171
- lockChoiceOrder = _ref$lockChoiceOrder === void 0 ? {} : _ref$lockChoiceOrder,
172
- _ref$teacherInstructi = _ref.teacherInstructions,
173
- teacherInstructions = _ref$teacherInstructi === void 0 ? {} : _ref$teacherInstructi,
174
- _ref$studentInstructi = _ref.studentInstructions,
175
- studentInstructions = _ref$studentInstructi === void 0 ? {} : _ref$studentInstructi,
176
- _ref$rationale = _ref.rationale,
177
- rationale = _ref$rationale === void 0 ? {} : _ref$rationale,
178
- _ref$accessibility = _ref.accessibility,
179
- accessibility = _ref$accessibility === void 0 ? {} : _ref$accessibility,
180
- _ref$scoringType = _ref.scoringType,
181
- scoringType = _ref$scoringType === void 0 ? {} : _ref$scoringType,
182
- _ref$sequentialChoice = _ref.sequentialChoiceLabels,
183
- sequentialChoiceLabels = _ref$sequentialChoice === void 0 ? {} : _ref$sequentialChoice,
184
- settingsPanelDisabled = _ref.settingsPanelDisabled,
185
- choicesLayout = _ref.choicesLayout,
186
- _ref$spellCheck = _ref.spellCheck,
187
- spellCheck = _ref$spellCheck === void 0 ? {} : _ref$spellCheck,
188
- gridColumns = _ref.gridColumns,
189
- _ref$maxImageWidth = _ref.maxImageWidth,
190
- maxImageWidth = _ref$maxImageWidth === void 0 ? {} : _ref$maxImageWidth,
191
- _ref$maxImageHeight = _ref.maxImageHeight,
192
- maxImageHeight = _ref$maxImageHeight === void 0 ? {} : _ref$maxImageHeight,
193
- _ref$withRubric = _ref.withRubric,
194
- withRubric = _ref$withRubric === void 0 ? {} : _ref$withRubric;
195
-
196
- var _ref2 = configuration || {},
197
- maxAnswerChoices = _ref2.maxAnswerChoices;
198
-
199
- var _ref3 = model || {},
200
- limitChoicesNumber = _ref3.limitChoicesNumber,
201
- teacherInstructionsEnabled = _ref3.teacherInstructionsEnabled,
202
- rationaleEnabled = _ref3.rationaleEnabled,
203
- accessibilityLabelsEnabled = _ref3.accessibilityLabelsEnabled,
204
- feedbackEnabled = _ref3.feedbackEnabled,
205
- promptEnabled = _ref3.promptEnabled,
206
- spellCheckEnabled = _ref3.spellCheckEnabled,
207
- choices = _ref3.choices,
208
- errors = _ref3.errors,
209
- toolbarEditorPosition = _ref3.toolbarEditorPosition;
210
-
211
- var _ref4 = errors || {},
212
- choicesErrors = _ref4.choicesErrors,
213
- correctResponseError = _ref4.correctResponseError,
214
- answerChoicesError = _ref4.answerChoicesError;
215
-
216
- var nrOfColumnsAvailable = choices !== null && choices !== void 0 && choices.length ? Array.from({
217
- length: choices.length
218
- }, function (_, i) {
219
- return "".concat(i + 1);
220
- }) : [];
221
- var labelPlugins = {
222
- audio: {
223
- disabled: true
224
- },
225
- video: {
226
- disabled: true
227
- }
228
- };
229
- var toolbarOpts = {
230
- position: toolbarEditorPosition === 'top' ? 'top' : 'bottom'
231
- }; // if old property is used, set maxAnswerChoices to 9
232
-
233
- if (limitChoicesNumber) {
234
- maxAnswerChoices = MAX_CHOICES;
235
- }
236
-
237
- var validationMessage = (0, _utils.generateValidationMessage)(configuration);
238
- var defaultImageMaxWidth = maxImageWidth && maxImageWidth.prompt;
239
- var defaultImageMaxHeight = maxImageHeight && maxImageHeight.prompt;
240
- var addChoiceButtonTooltip = maxAnswerChoices && (choices === null || choices === void 0 ? void 0 : choices.length) >= maxAnswerChoices ? "Only ".concat(maxAnswerChoices, " allowed maximum") : '';
241
- var panelSettings = {
242
- choiceMode: choiceMode.settings && radio(choiceMode.label, ['checkbox', 'radio']),
243
- 'sequentialChoiceLabels.enabled': sequentialChoiceLabels.settings && toggle(sequentialChoiceLabels.label, true),
244
- choicePrefix: choicePrefix.settings && radio(choicePrefix.label, ['numbers', 'letters']),
245
- partialScoring: partialScoring.settings && toggle(partialScoring.label),
246
- lockChoiceOrder: lockChoiceOrder.settings && toggle(lockChoiceOrder.label),
247
- feedbackEnabled: feedback.settings && toggle(feedback.label),
248
- choicesLayout: choicesLayout.settings && dropdown(choicesLayout.label, ['vertical', 'grid', 'horizontal']),
249
- gridColumns: choicesLayout.settings && model.choicesLayout === 'grid' && nrOfColumnsAvailable.length > 0 && dropdown(gridColumns.label, nrOfColumnsAvailable)
250
- };
251
- var panelProperties = {
252
- teacherInstructionsEnabled: teacherInstructions.settings && toggle(teacherInstructions.label),
253
- studentInstructionsEnabled: studentInstructions.settings && toggle(studentInstructions.label),
254
- promptEnabled: prompt.settings && toggle(prompt.label),
255
- rationaleEnabled: rationale.settings && toggle(rationale.label),
256
- spellCheckEnabled: spellCheck.settings && toggle(spellCheck.label),
257
- accessibilityLabelsEnabled: accessibility.settings && toggle(accessibility.label),
258
- scoringType: scoringType.settings && radio(scoringType.label, ['auto', 'rubric']),
259
- rubricEnabled: (withRubric === null || withRubric === void 0 ? void 0 : withRubric.settings) && toggle(withRubric === null || withRubric === void 0 ? void 0 : withRubric.label)
260
- };
261
- return /*#__PURE__*/_react["default"].createElement(_configUi.layout.ConfigLayout, {
262
- hideSettings: settingsPanelDisabled,
263
- settings: /*#__PURE__*/_react["default"].createElement(Panel, {
264
- model: model,
265
- onChangeModel: onChangeModel,
266
- configuration: configuration,
267
- onChangeConfiguration: onConfigurationChanged,
268
- groups: {
269
- Settings: panelSettings,
270
- Properties: panelProperties
271
- }
272
- })
273
- }, /*#__PURE__*/_react["default"].createElement("div", null, teacherInstructionsEnabled && /*#__PURE__*/_react["default"].createElement(_configUi.InputContainer, {
274
- label: teacherInstructions.label,
275
- className: classes.promptHolder
276
- }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
277
- className: classes.prompt,
278
- markup: model.teacherInstructions || '',
279
- onChange: onTeacherInstructionsChanged,
280
- imageSupport: imageSupport,
281
- nonEmpty: false,
282
- toolbarOpts: toolbarOpts,
283
- spellCheck: spellCheckEnabled,
284
- maxImageWidth: maxImageWidth && maxImageWidth.teacherInstructions || defaultImageMaxWidth,
285
- maxImageHeight: maxImageHeight && maxImageHeight.teacherInstructions || defaultImageMaxHeight,
286
- uploadSoundSupport: uploadSoundSupport,
287
- languageCharactersProps: [{
288
- language: 'spanish'
289
- }, {
290
- language: 'special'
291
- }]
292
- })), promptEnabled && /*#__PURE__*/_react["default"].createElement(_configUi.InputContainer, {
293
- label: prompt.label,
294
- className: classes.promptHolder
295
- }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
296
- className: classes.prompt,
297
- markup: model.prompt,
298
- onChange: onPromptChanged,
299
- imageSupport: imageSupport,
300
- nonEmpty: false,
301
- disableUnderline: true,
302
- toolbarOpts: toolbarOpts,
303
- spellCheck: spellCheckEnabled,
304
- maxImageWidth: maxImageWidth && maxImageWidth.prompt,
305
- maxImageHeight: maxImageHeight && maxImageHeight.prompt,
306
- uploadSoundSupport: uploadSoundSupport,
307
- languageCharactersProps: [{
308
- language: 'spanish'
309
- }, {
310
- language: 'special'
311
- }]
312
- })), /*#__PURE__*/_react["default"].createElement("div", {
313
- className: classes.flexContainer
314
- }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
315
- className: classes.titleText
316
- }, "Choices"), /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
317
- classes: {
318
- tooltip: classes.tooltip
319
- },
320
- disableFocusListener: true,
321
- disableTouchListener: true,
322
- placement: 'right',
323
- title: validationMessage
324
- }, /*#__PURE__*/_react["default"].createElement(_Info["default"], {
325
- fontSize: 'small',
326
- color: 'primary'
327
- }))), choices.map(function (choice, index) {
328
- return /*#__PURE__*/_react["default"].createElement("div", {
329
- key: "choice-".concat(index),
330
- className: classes.choiceConfigurationHolder
331
- }, /*#__PURE__*/_react["default"].createElement(_configUi.ChoiceConfiguration, {
332
- key: index,
333
- index: index + 1,
334
- useLetterOrdering: model.choicePrefix === 'letters',
335
- className: classes.choiceConfiguration,
336
- mode: model.choiceMode,
337
- data: choice,
338
- defaultFeedback: {},
339
- imageSupport: imageSupport,
340
- disableImageAlignmentButtons: true,
341
- onDelete: function onDelete() {
342
- return onRemoveChoice(index);
343
- },
344
- onChange: function onChange(c) {
345
- return onChoiceChanged(index, c);
346
- },
347
- allowFeedBack: feedbackEnabled,
348
- allowDelete: deleteChoice.settings,
349
- noLabels: true,
350
- toolbarOpts: toolbarOpts,
351
- spellCheck: spellCheckEnabled,
352
- error: (choicesErrors === null || choicesErrors === void 0 ? void 0 : choicesErrors[choice.value]) || null,
353
- noCorrectAnswerError: correctResponseError,
354
- maxImageWidth: maxImageWidth && maxImageWidth.choices || defaultImageMaxWidth,
355
- maxImageHeight: maxImageHeight && maxImageHeight.choices || defaultImageMaxHeight,
356
- uploadSoundSupport: uploadSoundSupport
357
- }), rationaleEnabled && /*#__PURE__*/_react["default"].createElement(_configUi.InputContainer, {
358
- key: "rationale-".concat(index),
359
- label: rationale.label,
360
- className: classes.rationaleHolder
361
- }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
362
- className: classes.rationale,
363
- markup: choice.rationale || '',
364
- onChange: function onChange(c) {
365
- return onChoiceChanged(index, _objectSpread(_objectSpread({}, choice), {}, {
366
- rationale: c
367
- }));
368
- },
369
- imageSupport: imageSupport,
370
- toolbarOpts: toolbarOpts,
371
- pluginProps: labelPlugins,
372
- spellCheck: spellCheckEnabled,
373
- maxImageWidth: maxImageWidth && maxImageWidth.rationale || defaultImageMaxWidth,
374
- maxImageHeight: maxImageHeight && maxImageHeight.rationale || defaultImageMaxHeight,
375
- uploadSoundSupport: uploadSoundSupport,
376
- languageCharactersProps: [{
377
- language: 'spanish'
378
- }, {
379
- language: 'special'
380
- }]
381
- })), accessibilityLabelsEnabled && /*#__PURE__*/_react["default"].createElement(_configUi.InputContainer, {
382
- key: "accessibility-".concat(index),
383
- label: accessibility.label,
384
- className: classes.accessibilityHolder
385
- }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
386
- className: classes.accessibility,
387
- markup: choice.accessibility || '',
388
- onChange: function onChange(c) {
389
- return onChoiceChanged(index, _objectSpread(_objectSpread({}, choice), {}, {
390
- accessibility: c
391
- }));
392
- },
393
- imageSupport: imageSupport,
394
- pluginProps: labelPlugins,
395
- spellCheck: spellCheckEnabled,
396
- maxImageWidth: maxImageWidth && maxImageWidth.choices || defaultImageMaxWidth,
397
- maxImageHeight: maxImageHeight && maxImageHeight.choices || defaultImageMaxHeight,
398
- uploadSoundSupport: uploadSoundSupport,
399
- languageCharactersProps: [{
400
- language: 'spanish'
401
- }, {
402
- language: 'special'
403
- }]
404
- })));
405
- }), correctResponseError && /*#__PURE__*/_react["default"].createElement("div", {
406
- className: classes.errorText
407
- }, correctResponseError), answerChoicesError && /*#__PURE__*/_react["default"].createElement("div", {
408
- className: classes.errorText
409
- }, answerChoicesError), addChoiceButton.settings && /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
410
- title: addChoiceButtonTooltip,
411
- classes: {
412
- tooltip: classes.tooltip
413
- }
414
- }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
415
- classes: {
416
- root: maxAnswerChoices && (choices === null || choices === void 0 ? void 0 : choices.length) >= maxAnswerChoices && classes.disableButton
417
- },
418
- className: classes.addButton,
419
- variant: "contained",
420
- color: "primary",
421
- onClick: onAddChoice
422
- }, addChoiceButton.label))));
423
- });
424
-
425
- var Main = /*#__PURE__*/function (_React$Component) {
426
- (0, _inherits2["default"])(Main, _React$Component);
427
-
428
- var _super = _createSuper(Main);
429
-
430
- function Main() {
431
- var _this;
432
-
433
- (0, _classCallCheck2["default"])(this, Main);
434
-
435
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
436
- args[_key] = arguments[_key];
437
- }
438
-
439
- _this = _super.call.apply(_super, [this].concat(args));
440
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
441
- showWarning: false
442
- });
443
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onRemoveChoice", function (index) {
444
- var _this$props = _this.props,
445
- model = _this$props.model,
446
- configuration = _this$props.configuration,
447
- onModelChanged = _this$props.onModelChanged;
448
-
449
- var _ref5 = configuration || {},
450
- minAnswerChoices = _ref5.minAnswerChoices;
451
-
452
- if (minAnswerChoices && model.choices.length === minAnswerChoices) {
453
- _this.setState({
454
- showWarning: true
455
- });
456
-
457
- return;
458
- }
459
-
460
- model.choices.splice(index, 1);
461
- onModelChanged(model);
462
- });
463
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onAddChoice", function () {
464
- var _this$props2 = _this.props,
465
- model = _this$props2.model,
466
- configuration = _this$props2.configuration,
467
- onModelChanged = _this$props2.onModelChanged;
468
-
469
- var _ref6 = configuration || {},
470
- maxAnswerChoices = _ref6.maxAnswerChoices;
471
-
472
- var _ref7 = model || {},
473
- limitChoicesNumber = _ref7.limitChoicesNumber; // if old property is used, set maxAnswerChoices to 9
474
-
475
-
476
- if (limitChoicesNumber) {
477
- maxAnswerChoices = MAX_CHOICES;
478
- }
479
-
480
- if (maxAnswerChoices && model.choices.length >= maxAnswerChoices) {
481
- return;
482
- }
483
-
484
- model.choices.push({
485
- label: '',
486
- value: _configUi.choiceUtils.firstAvailableIndex(model.choices.map(function (c) {
487
- return c.value;
488
- }), 0),
489
- feedback: {
490
- type: 'none'
491
- }
492
- });
493
- onModelChanged(model);
494
- });
495
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChoiceChanged", function (index, choice) {
496
- var _this$props3 = _this.props,
497
- model = _this$props3.model,
498
- onModelChanged = _this$props3.onModelChanged;
499
-
500
- if (choice.correct && model.choiceMode === 'radio') {
501
- model.choices = model.choices.map(function (c) {
502
- return (0, _merge["default"])({}, c, {
503
- correct: false
504
- });
505
- });
506
- }
507
-
508
- model.choices.splice(index, 1, choice);
509
- onModelChanged(model);
510
- });
511
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPromptChanged", function (prompt) {
512
- _this.props.onModelChanged(_objectSpread(_objectSpread({}, _this.props.model), {}, {
513
- prompt: prompt
514
- }));
515
- });
516
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onTeacherInstructionsChanged", function (teacherInstructions) {
517
- _this.props.onModelChanged(_objectSpread(_objectSpread({}, _this.props.model), {}, {
518
- teacherInstructions: teacherInstructions
519
- }));
520
- });
521
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onModelChanged", function (model, key) {
522
- var onModelChanged = _this.props.onModelChanged;
523
-
524
- switch (key) {
525
- case 'choiceMode':
526
- {
527
- var value = model.choiceMode;
528
-
529
- if (value === 'radio') {
530
- var correctFound = false;
531
- model.choices = model.choices.map(function (c) {
532
- if (correctFound) {
533
- c.correct = false;
534
- return c;
535
- }
536
-
537
- if (c.correct) {
538
- correctFound = true;
539
- }
540
-
541
- return c;
542
- });
543
- }
544
-
545
- onModelChanged(model, true);
546
- break;
547
- }
548
-
549
- default:
550
- onModelChanged(model);
551
- break;
552
- }
553
- });
554
- return _this;
555
- }
556
-
557
- (0, _createClass2["default"])(Main, [{
558
- key: "render",
559
- value: function render() {
560
- var _this2 = this;
561
-
562
- var _this$props$configura = this.props.configuration;
563
- _this$props$configura = _this$props$configura === void 0 ? {} : _this$props$configura;
564
- var minAnswerChoices = _this$props$configura.minAnswerChoices;
565
- var showWarning = this.state.showWarning;
566
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_configUi.AlertDialog, {
567
- open: showWarning,
568
- title: "Warning",
569
- text: "There can't be less than ".concat(minAnswerChoices || 0, " choices."),
570
- onConfirm: function onConfirm() {
571
- return _this2.setState({
572
- showWarning: false
573
- });
574
- }
575
- }), /*#__PURE__*/_react["default"].createElement(Design, (0, _extends2["default"])({}, this.props, {
576
- onChangeModel: this.onModelChanged,
577
- onRemoveChoice: this.onRemoveChoice,
578
- onChoiceChanged: this.onChoiceChanged,
579
- onAddChoice: this.onAddChoice,
580
- onPromptChanged: this.onPromptChanged,
581
- onTeacherInstructionsChanged: this.onTeacherInstructionsChanged
582
- })));
583
- }
584
- }]);
585
- return Main;
586
- }(_react["default"].Component);
587
-
588
- exports.Main = Main;
589
- (0, _defineProperty2["default"])(Main, "propTypes", {
590
- model: _propTypes["default"].object.isRequired,
591
- configuration: _propTypes["default"].object.isRequired,
592
- disableSidePanel: _propTypes["default"].bool,
593
- onModelChanged: _propTypes["default"].func.isRequired,
594
- onConfigurationChanged: _propTypes["default"].func.isRequired,
595
- classes: _propTypes["default"].object.isRequired,
596
- imageSupport: _propTypes["default"].shape({
597
- add: _propTypes["default"].func.isRequired,
598
- "delete": _propTypes["default"].func.isRequired
599
- })
600
- });
601
- var Styled = (0, _styles.withStyles)(styles)(Main);
602
- var _default = Styled;
603
- exports["default"] = _default;
604
- //# sourceMappingURL=main.js.map