@pie-element/multiple-choice 6.1.7 → 6.1.11

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,6 +1,6 @@
1
- import {_dll_react, _dll_prop_types, _dll_material_ui__core_styles, _dll_material_ui__core, _dll_lodash, _dll_pie_lib__render_ui, _dll_debug, _dll_react_dom} from "../../../@pie-lib/shared-module@^1.2.14/module/index.js";
2
- import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.0.15/module/index.js";
3
- import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.15/module/index.js";
1
+ import {_dll_react, _dll_prop_types, _dll_material_ui__core_styles, _dll_material_ui__core, _dll_lodash, _dll_pie_lib__render_ui, _dll_debug, _dll_react_dom} from "../../../@pie-lib/shared-module@^1.2.16/module/index.js";
2
+ import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.0.17/module/index.js";
3
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.17/module/index.js";
4
4
  var lib = {};
5
5
  Object.defineProperty(lib, "__esModule", {
6
6
  value: true
@@ -52,6 +52,9 @@ const {color: color} = _dll_pie_lib__render_ui;
52
52
  const {withStyles: withStyles} = _dll_material_ui__core_styles;
53
53
  const {Button: Button} = _dll_material_ui__core;
54
54
  const {Tooltip: Tooltip} = _dll_material_ui__core;
55
+ const {Dialog: Dialog} = _dll_material_ui__core;
56
+ const {DialogTitle: DialogTitle} = _dll_material_ui__core;
57
+ const {DialogActions: DialogActions} = _dll_material_ui__core;
55
58
  const {merge: merge} = _dll_lodash;
56
59
  const EditableHtml = _dll_pie_lib__editable_html;
57
60
  const {InputContainer: InputContainer} = _dll_pie_lib__config_ui;
@@ -118,8 +121,9 @@ const styles = theme => ({
118
121
  });
119
122
  const Design = withStyles(styles)(props => {
120
123
  const {classes, model, configuration, onPromptChanged, onChoiceChanged, onRemoveChoice, onAddChoice, imageSupport, onChangeModel, onConfigurationChanged, onTeacherInstructionsChanged} = props;
121
- const {prompt = {}, addChoiceButton = {}, limitChoicesNumber = {}, feedback = {}, deleteChoice = {}, choiceMode = {}, choicePrefix = {}, partialScoring = {}, lockChoiceOrder = {}, teacherInstructions = {}, studentInstructions = {}, rationale = {}, accessibility = {}, scoringType = {}, sequentialChoiceLabels = {}, settingsPanelDisabled, choicesLayout, gridColumns} = configuration || ({});
122
- const {limitChoicesNumber: limitChoicesNumberModel, teacherInstructionsEnabled, rationaleEnabled, accessibilityLabelsEnabled, feedbackEnabled, promptEnabled, choices} = model || ({});
124
+ const {prompt = {}, addChoiceButton = {}, feedback = {}, deleteChoice = {}, choiceMode = {}, choicePrefix = {}, partialScoring = {}, lockChoiceOrder = {}, teacherInstructions = {}, studentInstructions = {}, rationale = {}, accessibility = {}, scoringType = {}, sequentialChoiceLabels = {}, settingsPanelDisabled, choicesLayout, gridColumns} = configuration || ({});
125
+ let {maxAnswerChoices} = configuration || ({});
126
+ const {limitChoicesNumber, teacherInstructionsEnabled, rationaleEnabled, accessibilityLabelsEnabled, feedbackEnabled, promptEnabled, choices} = model || ({});
123
127
  const nrOfColumnsAvailable = choices && choices.length ? Array.from({
124
128
  length: choices.length
125
129
  }, (_, i) => `${i + 1}`) : [];
@@ -140,11 +144,14 @@ const Design = withStyles(styles)(props => {
140
144
  toolbarOpts.position = 'bottom';
141
145
  break;
142
146
  }
147
+ if (limitChoicesNumber) {
148
+ maxAnswerChoices = MAX_CHOICES;
149
+ }
143
150
  const Content = React$1.createElement('div', {
144
151
  __self: undefined,
145
152
  __source: {
146
153
  fileName: _jsxFileName,
147
- lineNumber: 141
154
+ lineNumber: 149
148
155
  }
149
156
  }, teacherInstructionsEnabled && React$1.createElement(InputContainer, {
150
157
  label: teacherInstructions.label,
@@ -152,7 +159,7 @@ const Design = withStyles(styles)(props => {
152
159
  __self: undefined,
153
160
  __source: {
154
161
  fileName: _jsxFileName,
155
- lineNumber: 143
162
+ lineNumber: 151
156
163
  }
157
164
  }, React$1.createElement(EditableHtml, {
158
165
  className: classes.prompt,
@@ -164,7 +171,7 @@ const Design = withStyles(styles)(props => {
164
171
  __self: undefined,
165
172
  __source: {
166
173
  fileName: _jsxFileName,
167
- lineNumber: 147
174
+ lineNumber: 155
168
175
  }
169
176
  })), promptEnabled && React$1.createElement(InputContainer, {
170
177
  label: prompt.label,
@@ -172,7 +179,7 @@ const Design = withStyles(styles)(props => {
172
179
  __self: undefined,
173
180
  __source: {
174
181
  fileName: _jsxFileName,
175
- lineNumber: 159
182
+ lineNumber: 167
176
183
  }
177
184
  }, React$1.createElement(EditableHtml, {
178
185
  className: classes.prompt,
@@ -185,7 +192,7 @@ const Design = withStyles(styles)(props => {
185
192
  __self: undefined,
186
193
  __source: {
187
194
  fileName: _jsxFileName,
188
- lineNumber: 160
195
+ lineNumber: 168
189
196
  }
190
197
  })), model.choices.map((choice, index) => React$1.createElement('div', {
191
198
  key: `choice-${index}`,
@@ -193,7 +200,7 @@ const Design = withStyles(styles)(props => {
193
200
  __self: undefined,
194
201
  __source: {
195
202
  fileName: _jsxFileName,
196
- lineNumber: 172
203
+ lineNumber: 180
197
204
  }
198
205
  }, React$1.createElement(ChoiceConfiguration, {
199
206
  key: index,
@@ -213,7 +220,7 @@ const Design = withStyles(styles)(props => {
213
220
  __self: undefined,
214
221
  __source: {
215
222
  fileName: _jsxFileName,
216
- lineNumber: 176
223
+ lineNumber: 184
217
224
  }
218
225
  }), rationaleEnabled && React$1.createElement(InputContainer, {
219
226
  key: `rationale-${index}`,
@@ -222,7 +229,7 @@ const Design = withStyles(styles)(props => {
222
229
  __self: undefined,
223
230
  __source: {
224
231
  fileName: _jsxFileName,
225
- lineNumber: 193
232
+ lineNumber: 201
226
233
  }
227
234
  }, React$1.createElement(EditableHtml, {
228
235
  className: classes.rationale,
@@ -237,7 +244,7 @@ const Design = withStyles(styles)(props => {
237
244
  __self: undefined,
238
245
  __source: {
239
246
  fileName: _jsxFileName,
240
- lineNumber: 198
247
+ lineNumber: 206
241
248
  }
242
249
  })), accessibilityLabelsEnabled && React$1.createElement(InputContainer, {
243
250
  key: `accessibility-${index}`,
@@ -246,7 +253,7 @@ const Design = withStyles(styles)(props => {
246
253
  __self: undefined,
247
254
  __source: {
248
255
  fileName: _jsxFileName,
249
- lineNumber: 214
256
+ lineNumber: 222
250
257
  }
251
258
  }, React$1.createElement(EditableHtml, {
252
259
  className: classes.accessibility,
@@ -260,27 +267,27 @@ const Design = withStyles(styles)(props => {
260
267
  __self: undefined,
261
268
  __source: {
262
269
  fileName: _jsxFileName,
263
- lineNumber: 219
270
+ lineNumber: 227
264
271
  }
265
272
  })))), React$1.createElement('br', {
266
273
  __self: undefined,
267
274
  __source: {
268
275
  fileName: _jsxFileName,
269
- lineNumber: 235
276
+ lineNumber: 243
270
277
  }
271
278
  }), addChoiceButton.settings && React$1.createElement(Tooltip, {
272
- title: limitChoicesNumberModel && model.choices.length >= MAX_CHOICES ? `Only ${MAX_CHOICES} allowed maximum` : '',
279
+ title: maxAnswerChoices && model.choices.length >= maxAnswerChoices ? `Only ${maxAnswerChoices} allowed maximum` : '',
273
280
  classes: {
274
281
  tooltip: classes.tooltip
275
282
  },
276
283
  __self: undefined,
277
284
  __source: {
278
285
  fileName: _jsxFileName,
279
- lineNumber: 237
286
+ lineNumber: 245
280
287
  }
281
288
  }, React$1.createElement(Button, {
282
289
  classes: {
283
- root: limitChoicesNumberModel && model.choices.length >= MAX_CHOICES ? classes.disableButton : undefined
290
+ root: maxAnswerChoices && model.choices.length >= maxAnswerChoices ? classes.disableButton : undefined
284
291
  },
285
292
  className: classes.addButton,
286
293
  variant: "contained",
@@ -289,7 +296,7 @@ const Design = withStyles(styles)(props => {
289
296
  __self: undefined,
290
297
  __source: {
291
298
  fileName: _jsxFileName,
292
- lineNumber: 238
299
+ lineNumber: 246
293
300
  }
294
301
  }, addChoiceButton.label)));
295
302
  const settingsInPanel = {
@@ -297,7 +304,6 @@ const Design = withStyles(styles)(props => {
297
304
  'sequentialChoiceLabels.enabled': sequentialChoiceLabels.settings && toggle(sequentialChoiceLabels.label, true),
298
305
  choicePrefix: choicePrefix.settings && radio(choicePrefix.label, ['numbers', 'letters']),
299
306
  partialScoring: partialScoring.settings && toggle(partialScoring.label),
300
- limitChoicesNumber: limitChoicesNumber.settings && toggle(limitChoicesNumber.label),
301
307
  lockChoiceOrder: lockChoiceOrder.settings && toggle(lockChoiceOrder.label),
302
308
  feedbackEnabled: feedback.settings && toggle(feedback.label),
303
309
  choicesLayout: choicesLayout.settings && dropdown(choicesLayout.label, ['vertical', 'grid', 'horizontal']),
@@ -308,7 +314,7 @@ const Design = withStyles(styles)(props => {
308
314
  __self: undefined,
309
315
  __source: {
310
316
  fileName: _jsxFileName,
311
- lineNumber: 278
317
+ lineNumber: 284
312
318
  }
313
319
  }, settingsPanelDisabled ? Content : React$1.createElement(layout.ConfigLayout, {
314
320
  settings: React$1.createElement(Panel, {
@@ -330,16 +336,58 @@ const Design = withStyles(styles)(props => {
330
336
  __self: undefined,
331
337
  __source: {
332
338
  fileName: _jsxFileName,
333
- lineNumber: 284
339
+ lineNumber: 290
334
340
  }
335
341
  }),
336
342
  __self: undefined,
337
343
  __source: {
338
344
  fileName: _jsxFileName,
339
- lineNumber: 282
345
+ lineNumber: 288
340
346
  }
341
347
  }, Content));
342
348
  });
349
+ const InfoDialog = ({open, onCancel, onOk, title}) => React$1.createElement(Dialog, {
350
+ open: open,
351
+ __self: undefined,
352
+ __source: {
353
+ fileName: _jsxFileName,
354
+ lineNumber: 325
355
+ }
356
+ }, React$1.createElement(DialogTitle, {
357
+ __self: undefined,
358
+ __source: {
359
+ fileName: _jsxFileName,
360
+ lineNumber: 326
361
+ }
362
+ }, title), React$1.createElement(DialogActions, {
363
+ __self: undefined,
364
+ __source: {
365
+ fileName: _jsxFileName,
366
+ lineNumber: 327
367
+ }
368
+ }, onOk && React$1.createElement(Button, {
369
+ onClick: onOk,
370
+ color: "primary",
371
+ __self: undefined,
372
+ __source: {
373
+ fileName: _jsxFileName,
374
+ lineNumber: 329
375
+ }
376
+ }, "OK"), onCancel && React$1.createElement(Button, {
377
+ onClick: onCancel,
378
+ color: "primary",
379
+ __self: undefined,
380
+ __source: {
381
+ fileName: _jsxFileName,
382
+ lineNumber: 334
383
+ }
384
+ }, "Cancel")));
385
+ InfoDialog.propTypes = {
386
+ open: PropTypes.bool,
387
+ onCancel: PropTypes.func,
388
+ onOk: PropTypes.func,
389
+ title: PropTypes.string
390
+ };
343
391
  class Main extends React$1.Component {
344
392
  constructor(...args) {
345
393
  super(...args);
@@ -349,10 +397,12 @@ class Main extends React$1.Component {
349
397
  Main.prototype.__init4.call(this);
350
398
  Main.prototype.__init5.call(this);
351
399
  Main.prototype.__init6.call(this);
400
+ Main.prototype.__init7.call(this);
352
401
  }
353
402
  static __initStatic() {
354
403
  this.propTypes = {
355
404
  model: PropTypes.object.isRequired,
405
+ configuration: PropTypes.object.isRequired,
356
406
  disableSidePanel: PropTypes.bool,
357
407
  onModelChanged: PropTypes.func.isRequired,
358
408
  onConfigurationChanged: PropTypes.func.isRequired,
@@ -364,16 +414,69 @@ class Main extends React$1.Component {
364
414
  };
365
415
  }
366
416
  __init() {
367
- this.onRemoveChoice = index => {
368
- const {model} = this.props;
369
- model.choices.splice(index, 1);
370
- this.props.onModelChanged(model);
417
+ this.state = {
418
+ dialog: {
419
+ open: false
420
+ }
371
421
  };
372
422
  }
373
423
  __init2() {
424
+ this.onRemoveChoice = index => {
425
+ const {model, configuration} = this.props;
426
+ const {minAnswerChoices} = configuration || ({});
427
+ if (minAnswerChoices && model.choices.length === minAnswerChoices) {
428
+ this.setState({
429
+ dialog: {
430
+ open: true,
431
+ message: `There can't be less than ${minAnswerChoices} choices.`,
432
+ onOk: () => {
433
+ this.setState({
434
+ dialog: {
435
+ open: false
436
+ }
437
+ });
438
+ },
439
+ onCancel: () => this.setState({
440
+ dialog: {
441
+ open: false
442
+ }
443
+ })
444
+ }
445
+ });
446
+ } else {
447
+ model.choices.splice(index, 1);
448
+ this.props.onModelChanged(model);
449
+ }
450
+ };
451
+ }
452
+ __init3() {
374
453
  this.onAddChoice = () => {
375
- const {model} = this.props;
376
- if (!model.limitChoicesNumber || model.limitChoicesNumber && model.choices.length < MAX_CHOICES) {
454
+ const {model, configuration} = this.props;
455
+ let {maxAnswerChoices} = configuration || ({});
456
+ const {limitChoicesNumber} = model || ({});
457
+ if (limitChoicesNumber) {
458
+ maxAnswerChoices = MAX_CHOICES;
459
+ }
460
+ if (maxAnswerChoices && model.choices.length === maxAnswerChoices) {
461
+ this.setState({
462
+ dialog: {
463
+ open: true,
464
+ message: `There can't be more than ${maxAnswerChoices} choices.`,
465
+ onOk: () => {
466
+ this.setState({
467
+ dialog: {
468
+ open: false
469
+ }
470
+ });
471
+ },
472
+ onCancel: () => this.setState({
473
+ dialog: {
474
+ open: false
475
+ }
476
+ })
477
+ }
478
+ });
479
+ } else {
377
480
  model.choices.push({
378
481
  label: '',
379
482
  value: utils$1.firstAvailableIndex(model.choices.map(c => c.value), 0),
@@ -385,7 +488,7 @@ class Main extends React$1.Component {
385
488
  }
386
489
  };
387
490
  }
388
- __init3() {
491
+ __init4() {
389
492
  this.onChoiceChanged = (index, choice) => {
390
493
  const {model} = this.props;
391
494
  if (choice.correct && model.choiceMode === 'radio') {
@@ -399,7 +502,7 @@ class Main extends React$1.Component {
399
502
  this.props.onModelChanged(model);
400
503
  };
401
504
  }
402
- __init4() {
505
+ __init5() {
403
506
  this.onPromptChanged = prompt => {
404
507
  this.props.onModelChanged({
405
508
  ...this.props.model,
@@ -407,7 +510,7 @@ class Main extends React$1.Component {
407
510
  });
408
511
  };
409
512
  }
410
- __init5() {
513
+ __init6() {
411
514
  this.onTeacherInstructionsChanged = teacherInstructions => {
412
515
  this.props.onModelChanged({
413
516
  ...this.props.model,
@@ -415,7 +518,7 @@ class Main extends React$1.Component {
415
518
  });
416
519
  };
417
520
  }
418
- __init6() {
521
+ __init7() {
419
522
  this.onModelChanged = (model, key) => {
420
523
  const {onModelChanged} = this.props;
421
524
  switch (key) {
@@ -445,7 +548,18 @@ class Main extends React$1.Component {
445
548
  };
446
549
  }
447
550
  render() {
448
- return React$1.createElement(Design, {
551
+ const {dialog} = this.state;
552
+ return React$1.createElement(React$1.Fragment, null, React$1.createElement(InfoDialog, {
553
+ open: dialog.open,
554
+ title: dialog.message,
555
+ onCancel: dialog.onCancel,
556
+ onOk: dialog.onOk,
557
+ __self: this,
558
+ __source: {
559
+ fileName: _jsxFileName,
560
+ lineNumber: 511
561
+ }
562
+ }), React$1.createElement(Design, {
449
563
  ...this.props,
450
564
  onChangeModel: this.onModelChanged,
451
565
  onRemoveChoice: this.onRemoveChoice,
@@ -456,9 +570,9 @@ class Main extends React$1.Component {
456
570
  __self: this,
457
571
  __source: {
458
572
  fileName: _jsxFileName,
459
- lineNumber: 414
573
+ lineNumber: 517
460
574
  }
461
- });
575
+ }));
462
576
  }
463
577
  }
464
578
  Main.__initStatic();
@@ -475,7 +589,6 @@ var sensibleDefaults = {
475
589
  feedbackEnabled: true,
476
590
  promptEnabled: true,
477
591
  rationaleEnabled: true,
478
- limitChoicesNumber: true,
479
592
  teacherInstructionsEnabled: true,
480
593
  studentInstructionsEnabled: true,
481
594
  toolbarEditorPosition: 'bottom',
@@ -495,10 +608,6 @@ var sensibleDefaults = {
495
608
  settings: true,
496
609
  label: 'Add a Choice'
497
610
  },
498
- limitChoicesNumber: {
499
- settings: true,
500
- label: 'Limit choices to 9'
501
- },
502
611
  choiceMode: {
503
612
  settings: true,
504
613
  label: 'Response Type'
@@ -549,7 +658,9 @@ var sensibleDefaults = {
549
658
  toolbarEditorPosition: {
550
659
  settings: false,
551
660
  label: 'Toolbar Editor Position'
552
- }
661
+ },
662
+ minAnswerChoices: 2,
663
+ maxAnswerChoices: 5
553
664
  }
554
665
  };
555
666
  const React = _dll_react;