@pie-element/placement-ordering 7.4.0 → 7.4.1-beta.587

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 (46) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/README.md +1 -1
  3. package/configure/CHANGELOG.md +486 -0
  4. package/configure/lib/choice-editor.js +239 -62
  5. package/configure/lib/choice-editor.js.map +1 -1
  6. package/configure/lib/choice-tile.js +71 -14
  7. package/configure/lib/choice-tile.js.map +1 -1
  8. package/configure/lib/defaults.js +29 -5
  9. package/configure/lib/defaults.js.map +1 -1
  10. package/configure/lib/design.js +230 -78
  11. package/configure/lib/design.js.map +1 -1
  12. package/configure/lib/help.js.map +1 -1
  13. package/configure/lib/index.js +17 -3
  14. package/configure/lib/index.js.map +1 -1
  15. package/configure/lib/utils.js +14 -0
  16. package/configure/lib/utils.js.map +1 -0
  17. package/configure/package.json +7 -6
  18. package/controller/CHANGELOG.md +126 -0
  19. package/controller/lib/defaults.js +4 -2
  20. package/controller/lib/defaults.js.map +1 -1
  21. package/controller/lib/index.js +79 -20
  22. package/controller/lib/index.js.map +1 -1
  23. package/controller/lib/scoring.js +11 -4
  24. package/controller/lib/scoring.js.map +1 -1
  25. package/controller/package.json +3 -3
  26. package/docs/config-schema.json +142 -23
  27. package/docs/config-schema.json.md +106 -16
  28. package/docs/demo/config.js +2 -2
  29. package/docs/demo/generate.js +10 -9
  30. package/docs/demo/index.html +1 -2
  31. package/docs/demo/session.js +1 -1
  32. package/docs/pie-schema.json +96 -42
  33. package/docs/pie-schema.json.md +67 -37
  34. package/lib/index.js +5 -2
  35. package/lib/index.js.map +1 -1
  36. package/lib/main.js +1 -1
  37. package/lib/main.js.map +1 -1
  38. package/lib/ordering.js +2 -1
  39. package/lib/ordering.js.map +1 -1
  40. package/lib/placement-ordering.js +131 -53
  41. package/lib/placement-ordering.js.map +1 -1
  42. package/lib/tile.js +1 -1
  43. package/lib/tile.js.map +1 -1
  44. package/lib/tiler.js +7 -5
  45. package/lib/tiler.js.map +1 -1
  46. package/package.json +8 -7
@@ -11,6 +11,8 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
11
11
 
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
 
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
14
16
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
17
 
16
18
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
@@ -19,6 +21,8 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
19
21
 
20
22
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
21
23
 
24
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
25
+
22
26
  var _choiceTile = _interopRequireDefault(require("./choice-tile"));
23
27
 
24
28
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -35,15 +39,23 @@ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
35
39
 
36
40
  var _uniqueId = _interopRequireDefault(require("lodash/uniqueId"));
37
41
 
42
+ var _shuffle = _interopRequireDefault(require("lodash/shuffle"));
43
+
44
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
45
+
38
46
  var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
39
47
 
48
+ var _renderUi = require("@pie-lib/render-ui");
49
+
50
+ var _configUi = require("@pie-lib/config-ui");
51
+
40
52
  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); }; }
41
53
 
42
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
54
+ 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; } }
43
55
 
44
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
56
+ 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; }
45
57
 
46
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
58
+ 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; }
47
59
 
48
60
  function findFreeChoiceSlot(choices) {
49
61
  var slot = 1;
@@ -60,26 +72,70 @@ function findFreeChoiceSlot(choices) {
60
72
 
61
73
  var log = (0, _debug["default"])('@pie-element:placement-ordering:configure:choice-editor');
62
74
 
63
- function updateResponse(response, from, to) {
64
- var update = (0, _cloneDeep["default"])(response);
65
- var fromType = from.type;
75
+ function updateResponseOrChoices(response, choices, from, to) {
76
+ var fromType = from.type,
77
+ fromIndex = from.index;
66
78
  var toType = to.type,
67
79
  placeAtIndex = to.index;
68
80
 
69
- if (fromType === 'choice' && toType === 'target' || fromType === 'target' && toType === 'target') {
70
- var optionToSwitch = update[placeAtIndex];
71
- var currentPositionOfOption = update.findIndex(function (up) {
72
- return up.id === from.id;
73
- });
74
- var option = update.find(function (up) {
75
- return up.id === from.id;
76
- });
77
- update[placeAtIndex] = option;
78
- update[currentPositionOfOption] = optionToSwitch;
79
- return update;
81
+ if (fromType === 'target' && toType === 'target') {
82
+ var updatedResponse = (0, _cloneDeep["default"])(response) || [];
83
+
84
+ var _updatedResponse$redu = updatedResponse.reduce(function (acc, item, index) {
85
+ if (index === fromIndex) {
86
+ acc.movedItem = item;
87
+ } else {
88
+ acc.remainingItems.push(item);
89
+ }
90
+
91
+ return acc;
92
+ }, {
93
+ movedItem: null,
94
+ remainingItems: []
95
+ }),
96
+ movedItem = _updatedResponse$redu.movedItem,
97
+ remainingItems = _updatedResponse$redu.remainingItems;
98
+
99
+ return {
100
+ response: [].concat((0, _toConsumableArray2["default"])(remainingItems.slice(0, placeAtIndex)), [movedItem], (0, _toConsumableArray2["default"])(remainingItems.slice(placeAtIndex))),
101
+ choices: choices
102
+ };
103
+ }
104
+
105
+ if (fromType === 'choice' && toType === 'choice') {
106
+ var updatedChoices = (0, _cloneDeep["default"])(choices) || [];
107
+
108
+ var _updatedChoices$reduc = updatedChoices.reduce(function (acc, item, index) {
109
+ if (item.id === from.id) {
110
+ acc.movedItem = item;
111
+ } else {
112
+ acc.remainingItems.push(item);
113
+ }
114
+
115
+ if (item.id === to.id) {
116
+ acc.toIndex = index;
117
+ }
118
+
119
+ return acc;
120
+ }, {
121
+ movedItem: null,
122
+ remainingItems: [],
123
+ toIndex: null
124
+ }),
125
+ _movedItem = _updatedChoices$reduc.movedItem,
126
+ _remainingItems = _updatedChoices$reduc.remainingItems,
127
+ toIndex = _updatedChoices$reduc.toIndex;
128
+
129
+ return {
130
+ response: response,
131
+ choices: [].concat((0, _toConsumableArray2["default"])(_remainingItems.slice(0, toIndex)), [_movedItem], (0, _toConsumableArray2["default"])(_remainingItems.slice(toIndex)))
132
+ };
80
133
  }
81
134
 
82
- return response;
135
+ return {
136
+ response: response,
137
+ choices: choices
138
+ };
83
139
  }
84
140
 
85
141
  function buildTiles(choices, response, instanceId) {
@@ -119,6 +175,11 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
119
175
 
120
176
  (0, _classCallCheck2["default"])(this, ChoiceEditor);
121
177
  _this = _super.call(this, props);
178
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
179
+ warning: {
180
+ open: false
181
+ }
182
+ });
122
183
  _this.instanceId = (0, _uniqueId["default"])();
123
184
 
124
185
  _this.onChoiceChange = function (choice) {
@@ -139,51 +200,97 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
139
200
  var _this$props2 = _this.props,
140
201
  choices = _this$props2.choices,
141
202
  onChange = _this$props2.onChange,
142
- correctResponse = _this$props2.correctResponse;
143
- var updatedChoices = choices.filter(function (c) {
144
- return c.id !== choice.id;
145
- });
146
- var updatedCorrectResponse = correctResponse.filter(function (v) {
147
- return v.id !== choice.id;
148
- });
149
- onChange(updatedChoices, updatedCorrectResponse);
203
+ correctResponse = _this$props2.correctResponse,
204
+ choicesLabel = _this$props2.choicesLabel;
205
+
206
+ if (choices && choices.length === 3) {
207
+ _this.setState({
208
+ warning: {
209
+ open: true,
210
+ text: "There have to be at least 3 ".concat(choicesLabel, ".")
211
+ }
212
+ });
213
+ } else {
214
+ var updatedChoices = choices.filter(function (c) {
215
+ return c.id !== choice.id;
216
+ });
217
+ var updatedCorrectResponse = correctResponse.filter(function (v) {
218
+ return v.id !== choice.id;
219
+ });
220
+ onChange(updatedChoices, updatedCorrectResponse);
221
+ }
150
222
  };
151
223
 
152
224
  _this.addChoice = function () {
153
225
  var _this$props3 = _this.props,
154
226
  choices = _this$props3.choices,
155
227
  correctResponse = _this$props3.correctResponse,
156
- onChange = _this$props3.onChange;
157
- var freeId = findFreeChoiceSlot(choices);
158
- var id = "c".concat(freeId);
159
- var newChoice = {
160
- id: id,
161
- label: ''
162
- };
163
- var newCorrectResponse = {
164
- id: id,
165
-
166
- /**
167
- * Note: weights are not configurable in the existing component
168
- * so we'll want do disable this in the controller and ignore it for now.
169
- */
170
- weight: 0
171
- };
172
- var updatedChoices = choices.concat([newChoice]);
173
- var updatedCorrectResponse = correctResponse.concat([newCorrectResponse]);
174
- onChange(updatedChoices, updatedCorrectResponse);
228
+ onChange = _this$props3.onChange,
229
+ choicesLabel = _this$props3.choicesLabel;
230
+
231
+ if (choices && choices.length === 10) {
232
+ _this.setState({
233
+ warning: {
234
+ open: true,
235
+ text: "There can be maximum 10 ".concat(choicesLabel, ".")
236
+ }
237
+ });
238
+ } else {
239
+ var freeId = findFreeChoiceSlot(choices);
240
+ var id = "c".concat(freeId);
241
+ var newChoice = {
242
+ id: id,
243
+ label: ''
244
+ };
245
+ var newCorrectResponse = {
246
+ id: id,
247
+
248
+ /**
249
+ * Note: weights are not configurable in the existing component
250
+ * so we'll want do disable this in the controller and ignore it for now.
251
+ */
252
+ weight: 0
253
+ };
254
+ var updatedChoices = choices.concat([newChoice]);
255
+ var updatedCorrectResponse = correctResponse.concat([newCorrectResponse]);
256
+ onChange(updatedChoices, updatedCorrectResponse);
257
+ }
175
258
  };
176
259
 
177
- _this.onDropChoice = function (ordering, target, source) {
260
+ _this.shuffleChoices = function () {
178
261
  var _this$props4 = _this.props,
179
262
  onChange = _this$props4.onChange,
180
- choices = _this$props4.choices;
263
+ choices = _this$props4.choices,
264
+ correctResponse = _this$props4.correctResponse,
265
+ placementArea = _this$props4.placementArea;
266
+ var shuffled = (0, _shuffle["default"])(choices); // if placementArea is disabled, make sure we don't shuffle choices in the correct order
267
+
268
+ var shuffledCorrect = !placementArea && (0, _isEqual["default"])(shuffled.map(function (item) {
269
+ return item.id;
270
+ }), correctResponse.map(function (item) {
271
+ return item.id;
272
+ }));
273
+
274
+ if (shuffledCorrect) {
275
+ var shuffledTwice = (0, _shuffle["default"])(shuffled);
276
+ onChange(shuffledTwice, correctResponse);
277
+ } else {
278
+ onChange(shuffled, correctResponse);
279
+ }
280
+ };
281
+
282
+ _this.onDropChoice = function (ordering, target, source) {
283
+ var onChange = _this.props.onChange;
181
284
  var from = ordering.tiles.find(function (t) {
182
285
  return t.id === source.id && t.type === source.type;
183
286
  });
184
287
  var to = target;
185
288
  log('[onDropChoice] ', from, to);
186
- var response = updateResponse(ordering.response, from, to);
289
+
290
+ var _updateResponseOrChoi = updateResponseOrChoices(ordering.response, ordering.choices, from, to),
291
+ response = _updateResponseOrChoi.response,
292
+ choices = _updateResponseOrChoi.choices;
293
+
187
294
  onChange(choices, response);
188
295
  };
189
296
 
@@ -200,13 +307,27 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
200
307
  correctResponse = _this$props5.correctResponse,
201
308
  choices = _this$props5.choices,
202
309
  imageSupport = _this$props5.imageSupport,
203
- disableImages = _this$props5.disableImages;
310
+ disableImages = _this$props5.disableImages,
311
+ toolbarOpts = _this$props5.toolbarOpts,
312
+ singularChoiceLabel = _this$props5.singularChoiceLabel,
313
+ pluralChoiceLabel = _this$props5.pluralChoiceLabel,
314
+ choicesLabel = _this$props5.choicesLabel,
315
+ spellCheck = _this$props5.spellCheck,
316
+ maxImageWidth = _this$props5.maxImageWidth,
317
+ maxImageHeight = _this$props5.maxImageHeight,
318
+ errors = _this$props5.errors;
319
+ var warning = this.state.warning;
320
+
321
+ var _ref = errors || {},
322
+ choicesErrors = _ref.choicesErrors,
323
+ orderError = _ref.orderError;
324
+
204
325
  var ordering = {
205
326
  choices: choices,
206
327
  response: !correctResponse || (0, _isEmpty["default"])(correctResponse) ? new Array(choices.length) : correctResponse,
207
328
  tiles: buildTiles(choices, correctResponse, this.instanceId)
208
329
  };
209
- var style = {
330
+ var vTilerStyle = {
210
331
  gridTemplateColumns: 'repeat(2, 1fr)',
211
332
  gridTemplateRows: "repeat(".concat(choices.length, ", 1fr)")
212
333
  };
@@ -214,23 +335,52 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
214
335
  className: classes.choiceEditor
215
336
  }, /*#__PURE__*/_react["default"].createElement("div", {
216
337
  className: classes.vtiler,
217
- style: style
218
- }, ordering.tiles.map(function (c, index) {
338
+ style: {
339
+ gridTemplateColumns: 'repeat(2, 1fr)'
340
+ }
341
+ }, /*#__PURE__*/_react["default"].createElement(_renderUi.InputContainer, {
342
+ label: "Student ".concat(choicesLabel || 'Choices'),
343
+ className: classes.columnLabel
344
+ }), /*#__PURE__*/_react["default"].createElement(_renderUi.InputContainer, {
345
+ label: "Correct Order",
346
+ className: classes.columnLabel
347
+ })), /*#__PURE__*/_react["default"].createElement("div", {
348
+ className: classes.vtiler,
349
+ style: vTilerStyle
350
+ }, ordering.tiles.map(function (choice, index) {
219
351
  return /*#__PURE__*/_react["default"].createElement(_choiceTile["default"], {
220
- choice: c,
352
+ choice: choice,
221
353
  index: index,
222
354
  key: index,
223
355
  imageSupport: imageSupport,
224
- onDelete: _this2.onDelete.bind(_this2, c),
356
+ onDelete: _this2.onDelete.bind(_this2, choice),
225
357
  onChoiceChange: _this2.onChoiceChange,
226
358
  onDropChoice: function onDropChoice(source, index) {
227
- return _this2.onDropChoice(ordering, c, source, index);
359
+ return _this2.onDropChoice(ordering, choice, source, index);
228
360
  },
229
- disableImages: disableImages
361
+ disableImages: disableImages,
362
+ toolbarOpts: toolbarOpts,
363
+ choices: choices,
364
+ choicesLabel: choicesLabel,
365
+ spellCheck: spellCheck,
366
+ maxImageWidth: maxImageWidth,
367
+ maxImageHeight: maxImageHeight,
368
+ error: (choicesErrors === null || choicesErrors === void 0 ? void 0 : choicesErrors[choice.id]) || orderError && ' ' || null
230
369
  });
231
- })), /*#__PURE__*/_react["default"].createElement("div", {
370
+ })), orderError && /*#__PURE__*/_react["default"].createElement("div", {
371
+ className: classes.errorText
372
+ }, orderError), /*#__PURE__*/_react["default"].createElement("div", {
232
373
  className: classes.controls
233
374
  }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
375
+ onClick: this.shuffleChoices,
376
+ size: "small",
377
+ variant: "contained",
378
+ color: "default",
379
+ classes: {
380
+ root: classes.addButtonRoot,
381
+ label: classes.addButtonLabel
382
+ }
383
+ }, "SHUFFLE ".concat(pluralChoiceLabel).toUpperCase()), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
234
384
  onClick: this.addChoice,
235
385
  size: "small",
236
386
  variant: "contained",
@@ -239,7 +389,18 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
239
389
  root: classes.addButtonRoot,
240
390
  label: classes.addButtonLabel
241
391
  }
242
- }, "ADD CHOICE")));
392
+ }, "ADD ".concat(singularChoiceLabel).toUpperCase())), /*#__PURE__*/_react["default"].createElement(_configUi.AlertDialog, {
393
+ open: warning.open,
394
+ title: "Warning",
395
+ text: warning.text,
396
+ onConfirm: function onConfirm() {
397
+ return _this2.setState({
398
+ warning: {
399
+ open: false
400
+ }
401
+ });
402
+ }
403
+ }));
243
404
  }
244
405
  }]);
245
406
  return ChoiceEditor;
@@ -254,14 +415,20 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
254
415
  add: _propTypes["default"].func.isRequired,
255
416
  "delete": _propTypes["default"].func.isRequired
256
417
  }),
257
- disableImages: _propTypes["default"].bool
418
+ disableImages: _propTypes["default"].bool,
419
+ toolbarOpts: _propTypes["default"].object,
420
+ placementArea: _propTypes["default"].bool,
421
+ singularChoiceLabel: _propTypes["default"].string,
422
+ pluralChoiceLabel: _propTypes["default"].string,
423
+ choicesLabel: _propTypes["default"].string,
424
+ errors: _propTypes["default"].object
258
425
  });
259
426
 
260
427
  var styles = function styles(theme) {
261
428
  return {
262
429
  allToggle: {},
263
430
  choiceEditor: {
264
- marginTop: '10px'
431
+ marginTop: theme.spacing.unit
265
432
  },
266
433
  controls: {
267
434
  display: 'flex',
@@ -274,8 +441,8 @@ var styles = function styles(theme) {
274
441
  fill: theme.palette.primary[500]
275
442
  },
276
443
  addButtonRoot: {
277
- marginTop: '24px',
278
- paddingHorizontal: '12px'
444
+ marginTop: theme.spacing.unit * 3,
445
+ paddingHorizontal: theme.spacing.unit * 1.5
279
446
  },
280
447
  addButtonLabel: {
281
448
  transition: 'opacity 200ms linear',
@@ -287,6 +454,16 @@ var styles = function styles(theme) {
287
454
  gridAutoFlow: 'column',
288
455
  display: 'grid',
289
456
  gridGap: '10px'
457
+ },
458
+ columnLabel: {
459
+ width: '100%',
460
+ paddingTop: theme.spacing.unit * 3,
461
+ marginTop: theme.spacing.unit * 2
462
+ },
463
+ errorText: {
464
+ fontSize: theme.typography.fontSize - 2,
465
+ color: 'red',
466
+ paddingTop: theme.spacing.unit
290
467
  }
291
468
  };
292
469
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/choice-editor.jsx"],"names":["findFreeChoiceSlot","choices","slot","ids","map","c","id","includes","log","updateResponse","response","from","to","update","fromType","type","toType","placeAtIndex","index","optionToSwitch","currentPositionOfOption","findIndex","up","option","find","buildTiles","instanceId","targets","r","respId","choice","undefined","draggable","editable","processedChoices","m","Object","assign","droppable","concat","ChoiceEditor","props","onChoiceChange","onChange","correctResponse","splice","label","onDelete","updatedChoices","filter","updatedCorrectResponse","v","addChoice","freeId","newChoice","newCorrectResponse","weight","onDropChoice","ordering","target","source","tiles","t","classes","imageSupport","disableImages","Array","length","style","gridTemplateColumns","gridTemplateRows","choiceEditor","vtiler","bind","controls","root","addButtonRoot","addButtonLabel","React","Component","PropTypes","object","isRequired","array","func","shape","add","bool","styles","theme","allToggle","marginTop","display","alignItems","justifyContent","width","height","fill","palette","primary","paddingHorizontal","transition","opacity","gridAutoFlow","gridGap"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,SAASA,kBAAT,CAA4BC,OAA5B,EAAqC;AACnC,MAAIC,IAAI,GAAG,CAAX;AACA,MAAMC,GAAG,GAAGF,OAAO,CAACG,GAAR,CAAY,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,EAAN;AAAA,GAAb,CAAZ;;AACA,SAAOH,GAAG,CAACI,QAAJ,YAAiBL,IAAjB,EAAP,EAAiC;AAC/BA,IAAAA,IAAI;AACL;;AACD,SAAOA,IAAP;AACD;;AAED,IAAMM,GAAG,GAAG,uBAAM,yDAAN,CAAZ;;AAEA,SAASC,cAAT,CAAwBC,QAAxB,EAAkCC,IAAlC,EAAwCC,EAAxC,EAA4C;AAC1C,MAAMC,MAAM,GAAG,2BAAUH,QAAV,CAAf;AAD0C,MAE5BI,QAF4B,GAEfH,IAFe,CAElCI,IAFkC;AAAA,MAG5BC,MAH4B,GAGIJ,EAHJ,CAGlCG,IAHkC;AAAA,MAGbE,YAHa,GAGIL,EAHJ,CAGpBM,KAHoB;;AAK1C,MAAKJ,QAAQ,KAAK,QAAb,IAAyBE,MAAM,KAAK,QAArC,IAAmDF,QAAQ,KAAK,QAAb,IAAyBE,MAAM,KAAK,QAA3F,EAAsG;AACpG,QAAMG,cAAc,GAAGN,MAAM,CAACI,YAAD,CAA7B;AAEA,QAAMG,uBAAuB,GAAGP,MAAM,CAACQ,SAAP,CAAiB,UAAAC,EAAE;AAAA,aAAIA,EAAE,CAAChB,EAAH,KAAUK,IAAI,CAACL,EAAnB;AAAA,KAAnB,CAAhC;AACA,QAAMiB,MAAM,GAAGV,MAAM,CAACW,IA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ADY;AAEvBnB,IAAAA,YAAY,EAAE;AACZoB,MAAAA,SAAS,EAAE;AADC,KAFS;AAKvBjB,IAAAA,QAAQ,EAAE;AACRkB,MAAAA,OAAO,EAAE,MADD;AAERC,MAAAA,UAAU,EAAE,QAFJ;AAGRC,MAAAA,cAAc,EAAE;AAHR,KALa;AAUvBnB,IAAAA,IAAI,EAAE;AACJoB,MAAAA,KAAK,EAAE,MADH;AAEJC,MAAAA,MAAM,EAAE,MAFJ;AAGJC,MAAAA,IAAI,EAAER,KAAK,CAACS,OAAN,CAAcC,OAAd,CAAsB,GAAtB;AAHF,KAViB;AAevBvB,IAAAA,aAAa,EAAE;AACbe,MAAAA,SAAS,EAAE,MADE;AAEbS,MAAAA,iBAAiB,EAAE;AAFN,KAfQ;AAmBvBvB,IAAAA,cAAc,EAAE;AACdwB,MAAAA,UAAU,EAAE,sBADE;AAEd,iBAAW;AACTC,QAAAA,OAAO,EAAE;AADA;AAFG,KAnBO;AAyBvB9B,IAAAA,MAAM,EAAE;AACN+B,MAAAA,YAAY,EAAE,QADR;AAENX,MAAAA,OAAO,EAAE,MAFH;AAGNY,MAAAA,OAAO,EAAE;AAHH;AAzBe,GAAL;AAAA,CAApB;;eAgCe,wBAAWhB,MAAX,EAAmBhD,YAAnB,C","sourcesContent":["import ChoiceTile from './choice-tile';\nimport PropTypes from 'prop-types';\nimport React from 'react';\nimport debug from 'debug';\nimport { withStyles } from '@material-ui/core/styles';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\nimport uniqueId from 'lodash/uniqueId';\nimport Button from '@material-ui/core/Button';\n\nfunction findFreeChoiceSlot(choices) {\n let slot = 1;\n const ids = choices.map(c => c.id);\n while (ids.includes(`c${slot}`)) {\n slot++;\n }\n return slot;\n}\n\nconst log = debug('@pie-element:placement-ordering:configure:choice-editor');\n\nfunction updateResponse(response, from, to) {\n const update = cloneDeep(response);\n const { type: fromType } = from;\n const { type: toType, index: placeAtIndex } = to;\n\n if ((fromType === 'choice' && toType === 'target') || (fromType === 'target' && toType === 'target')) {\n const optionToSwitch = update[placeAtIndex];\n\n const currentPositionOfOption = update.findIndex(up => up.id === from.id);\n const option = update.find(up => up.id === from.id);\n\n update[placeAtIndex] = option;\n update[currentPositionOfOption] = optionToSwitch;\n\n return update;\n }\n\n return response;\n}\n\nfunction buildTiles(choices, response, instanceId) {\n const targets = response.map((r, index) => {\n const respId = r && r.id;\n\n const choice = choices.find(c => respId !== undefined && respId !== null && c.id === respId);\n\n return {\n type: 'target',\n instanceId,\n ...choice,\n draggable: true,\n index,\n editable: false\n };\n });\n\n const processedChoices = choices.map(m => {\n return Object.assign({}, m, {\n type: 'choice',\n droppable: false,\n draggable: true,\n instanceId,\n editable: true\n });\n });\n\n return processedChoices.concat(targets);\n}\n\nclass ChoiceEditor extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n correctResponse: PropTypes.array.isRequired,\n choices: PropTypes.array.isRequired,\n onChange: PropTypes.func.isRequired,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired\n }),\n disableImages: PropTypes.bool,\n };\n\n constructor(props) {\n super(props);\n\n this.instanceId = uniqueId();\n\n this.onChoiceChange = choice => {\n const { choices, onChange, correctResponse } = this.props;\n const index = choices.findIndex(c => c.id === choice.id);\n\n choices.splice(index, 1, { ...choices[index], label: choice.label });\n onChange(choices, correctResponse);\n };\n\n this.onDelete = choice => {\n const { choices, onChange, correctResponse } = this.props;\n const updatedChoices = choices.filter(c => c.id !== choice.id);\n const updatedCorrectResponse = correctResponse.filter(\n v => v.id !== choice.id\n );\n onChange(updatedChoices, updatedCorrectResponse);\n };\n\n this.addChoice = () => {\n const { choices, correctResponse, onChange } = this.props;\n const freeId = findFreeChoiceSlot(choices);\n const id = `c${freeId}`;\n const newChoice = { id, label: '' };\n\n const newCorrectResponse = {\n id,\n /**\n * Note: weights are not configurable in the existing component\n * so we'll want do disable this in the controller and ignore it for now.\n */\n weight: 0\n };\n\n const updatedChoices = choices.concat([newChoice]);\n const updatedCorrectResponse = correctResponse.concat([\n newCorrectResponse\n ]);\n\n onChange(updatedChoices, updatedCorrectResponse);\n };\n\n this.onDropChoice = (ordering, target, source) => {\n const { onChange, choices } = this.props;\n const from = ordering.tiles.find(\n t => t.id === source.id && t.type === source.type\n );\n const to = target;\n log('[onDropChoice] ', from, to);\n const response = updateResponse(ordering.response, from, to);\n\n onChange(choices, response);\n };\n }\n\n render() {\n const { classes, correctResponse, choices, imageSupport, disableImages } = this.props;\n\n const ordering = {\n choices,\n response: !correctResponse || isEmpty(correctResponse) ? new Array(choices.length) : correctResponse,\n tiles: buildTiles(choices, correctResponse, this.instanceId),\n };\n\n const style = {\n gridTemplateColumns: 'repeat(2, 1fr)',\n gridTemplateRows: `repeat(${choices.length}, 1fr)`\n };\n\n return (\n <div className={classes.choiceEditor}>\n <div className={classes.vtiler} style={style}>\n\n {ordering.tiles.map((c, index) => (\n <ChoiceTile\n choice={c}\n index={index}\n key={index}\n imageSupport={imageSupport}\n onDelete={this.onDelete.bind(this, c)}\n onChoiceChange={this.onChoiceChange}\n onDropChoice={(source, index) => this.onDropChoice(ordering, c, source, index)}\n disableImages={disableImages}\n />\n ))}\n </div>\n <div className={classes.controls}>\n <Button\n onClick={this.addChoice}\n size=\"small\"\n variant=\"contained\"\n color=\"default\"\n classes={{\n root: classes.addButtonRoot,\n label: classes.addButtonLabel\n }}\n >\n ADD CHOICE\n </Button>\n </div>\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n allToggle: {},\n choiceEditor: {\n marginTop: '10px'\n },\n controls: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between'\n },\n root: {\n width: '30px',\n height: '30px',\n fill: theme.palette.primary[500]\n },\n addButtonRoot: {\n marginTop: '24px',\n paddingHorizontal: '12px'\n },\n addButtonLabel: {\n transition: 'opacity 200ms linear',\n '&:hover': {\n opacity: 0.3\n }\n },\n vtiler: {\n gridAutoFlow: 'column',\n display: 'grid',\n gridGap: '10px'\n }\n});\n\nexport default withStyles(styles)(ChoiceEditor);"],"file":"choice-editor.js"}
1
+ {"version":3,"sources":["../src/choice-editor.jsx"],"names":["findFreeChoiceSlot","choices","slot","ids","map","c","id","includes","log","updateResponseOrChoices","response","from","to","fromType","type","fromIndex","index","toType","placeAtIndex","updatedResponse","reduce","acc","item","movedItem","remainingItems","push","slice","updatedChoices","toIndex","buildTiles","instanceId","targets","r","respId","choice","find","undefined","draggable","editable","processedChoices","m","Object","assign","droppable","concat","ChoiceEditor","props","warning","open","onChoiceChange","onChange","correctResponse","findIndex","splice","label","onDelete","choicesLabel","length","setState","text","filter","updatedCorrectResponse","v","addChoice","freeId","newChoice","newCorrectResponse","weight","shuffleChoices","placementArea","shuffled","shuffledCorrect","shuffledTwice","onDropChoice","ordering","target","source","tiles","t","classes","imageSupport","disableImages","toolbarOpts","singularChoiceLabel","pluralChoiceLabel","spellCheck","maxImageWidth","maxImageHeight","errors","state","choicesErrors","orderError","Array","vTilerStyle","gridTemplateColumns","gridTemplateRows","choiceEditor","vtiler","columnLabel","bind","errorText","controls","root","addButtonRoot","addButtonLabel","toUpperCase","React","Component","PropTypes","object","isRequired","array","func","shape","add","bool","string","styles","theme","allToggle","marginTop","spacing","unit","display","alignItems","justifyContent","width","height","fill","palette","primary","paddingHorizontal","transition","opacity","gridAutoFlow","gridGap","paddingTop","fontSize","typography","color"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,SAASA,kBAAT,CAA4BC,OAA5B,EAAqC;AACnC,MAAIC,IAAI,GAAG,CAAX;AACA,MAAMC,GAAG,GAAGF,OAAO,CAACG,GAAR,CAAY,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,EAAT;AAAA,GAAZ,CAAZ;;AAEA,SAAOH,GAAG,CAACI,QAAJ,YAAiBL,IAA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,IAAAA,aAAa,EAAE;AACbiB,MAAAA,SAAS,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CADnB;AAEbS,MAAAA,iBAAiB,EAAEb,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB;AAF3B,KAfU;AAmBzBlB,IAAAA,cAAc,EAAE;AACd4B,MAAAA,UAAU,EAAE,sBADE;AAEd,iBAAW;AACTC,QAAAA,OAAO,EAAE;AADA;AAFG,KAnBS;AAyBzBpC,IAAAA,MAAM,EAAE;AACNqC,MAAAA,YAAY,EAAE,QADR;AAENX,MAAAA,OAAO,EAAE,MAFH;AAGNY,MAAAA,OAAO,EAAE;AAHH,KAzBiB;AA8BzBrC,IAAAA,WAAW,EAAE;AACX4B,MAAAA,KAAK,EAAE,MADI;AAEXU,MAAAA,UAAU,EAAElB,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAFtB;AAGXF,MAAAA,SAAS,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB;AAHrB,KA9BY;AAmCzBtB,IAAAA,SAAS,EAAE;AACTqC,MAAAA,QAAQ,EAAEnB,KAAK,CAACoB,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;AAETE,MAAAA,KAAK,EAAE,KAFE;AAGTH,MAAAA,UAAU,EAAElB,KAAK,CAACG,OAAN,CAAcC;AAHjB;AAnCc,GAAZ;AAAA,CAAf;;eA0Ce,wBAAWL,MAAX,EAAmBxE,YAAnB,C","sourcesContent":["import ChoiceTile from './choice-tile';\nimport PropTypes from 'prop-types';\nimport React from 'react';\nimport debug from 'debug';\nimport { withStyles } from '@material-ui/core/styles';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\nimport uniqueId from 'lodash/uniqueId';\nimport shuffle from 'lodash/shuffle';\nimport isEqual from 'lodash/isEqual';\nimport Button from '@material-ui/core/Button';\nimport { InputContainer } from '@pie-lib/render-ui';\nimport { AlertDialog } from '@pie-lib/config-ui';\n\nfunction findFreeChoiceSlot(choices) {\n let slot = 1;\n const ids = choices.map((c) => c.id);\n\n while (ids.includes(`c${slot}`)) {\n slot++;\n }\n\n return slot;\n}\n\nconst log = debug('@pie-element:placement-ordering:configure:choice-editor');\n\nfunction updateResponseOrChoices(response, choices, from, to) {\n const { type: fromType, index: fromIndex } = from;\n const { type: toType, index: placeAtIndex } = to;\n\n if (fromType === 'target' && toType === 'target') {\n const updatedResponse = cloneDeep(response) || [];\n\n const { movedItem, remainingItems } = updatedResponse.reduce(\n (acc, item, index) => {\n if (index === fromIndex) {\n acc.movedItem = item;\n } else {\n acc.remainingItems.push(item);\n }\n\n return acc;\n },\n { movedItem: null, remainingItems: [] },\n );\n\n return {\n response: [...remainingItems.slice(0, placeAtIndex), movedItem, ...remainingItems.slice(placeAtIndex)],\n choices,\n };\n }\n\n if (fromType === 'choice' && toType === 'choice') {\n const updatedChoices = cloneDeep(choices) || [];\n\n const { movedItem, remainingItems, toIndex } = updatedChoices.reduce(\n (acc, item, index) => {\n if (item.id === from.id) {\n acc.movedItem = item;\n } else {\n acc.remainingItems.push(item);\n }\n\n if (item.id === to.id) {\n acc.toIndex = index;\n }\n\n return acc;\n },\n { movedItem: null, remainingItems: [], toIndex: null },\n );\n\n return {\n response,\n choices: [...remainingItems.slice(0, toIndex), movedItem, ...remainingItems.slice(toIndex)],\n };\n }\n\n return { response, choices };\n}\n\nfunction buildTiles(choices, response, instanceId) {\n const targets = response.map((r, index) => {\n const respId = r && r.id;\n const choice = choices.find((c) => respId !== undefined && respId !== null && c.id === respId);\n\n return {\n type: 'target',\n instanceId,\n ...choice,\n draggable: true,\n index,\n editable: false,\n };\n });\n\n const processedChoices = choices.map((m) => {\n return Object.assign({}, m, {\n type: 'choice',\n droppable: false,\n draggable: true,\n instanceId,\n editable: true,\n });\n });\n\n return processedChoices.concat(targets);\n}\n\nclass ChoiceEditor extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n correctResponse: PropTypes.array.isRequired,\n choices: PropTypes.array.isRequired,\n onChange: PropTypes.func.isRequired,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n disableImages: PropTypes.bool,\n toolbarOpts: PropTypes.object,\n placementArea: PropTypes.bool,\n singularChoiceLabel: PropTypes.string,\n pluralChoiceLabel: PropTypes.string,\n choicesLabel: PropTypes.string,\n errors: PropTypes.object,\n };\n\n state = { warning: { open: false } };\n\n constructor(props) {\n super(props);\n\n this.instanceId = uniqueId();\n\n this.onChoiceChange = (choice) => {\n const { choices, onChange, correctResponse } = this.props;\n const index = choices.findIndex((c) => c.id === choice.id);\n\n choices.splice(index, 1, { ...choices[index], label: choice.label });\n onChange(choices, correctResponse);\n };\n\n this.onDelete = (choice) => {\n const { choices, onChange, correctResponse, choicesLabel } = this.props;\n\n if (choices && choices.length === 3) {\n this.setState({\n warning: {\n open: true,\n text: `There have to be at least 3 ${choicesLabel}.`,\n },\n });\n } else {\n const updatedChoices = choices.filter((c) => c.id !== choice.id);\n const updatedCorrectResponse = correctResponse.filter((v) => v.id !== choice.id);\n\n onChange(updatedChoices, updatedCorrectResponse);\n }\n };\n\n this.addChoice = () => {\n const { choices, correctResponse, onChange, choicesLabel } = this.props;\n\n if (choices && choices.length === 10) {\n this.setState({\n warning: {\n open: true,\n text: `There can be maximum 10 ${choicesLabel}.`,\n },\n });\n } else {\n const freeId = findFreeChoiceSlot(choices);\n const id = `c${freeId}`;\n const newChoice = { id, label: '' };\n\n const newCorrectResponse = {\n id,\n /**\n * Note: weights are not configurable in the existing component\n * so we'll want do disable this in the controller and ignore it for now.\n */\n weight: 0,\n };\n\n const updatedChoices = choices.concat([newChoice]);\n const updatedCorrectResponse = correctResponse.concat([newCorrectResponse]);\n\n onChange(updatedChoices, updatedCorrectResponse);\n }\n };\n\n this.shuffleChoices = () => {\n const { onChange, choices, correctResponse, placementArea } = this.props;\n let shuffled = shuffle(choices);\n\n // if placementArea is disabled, make sure we don't shuffle choices in the correct order\n const shuffledCorrect =\n !placementArea &&\n isEqual(\n shuffled.map((item) => item.id),\n correctResponse.map((item) => item.id),\n );\n\n if (shuffledCorrect) {\n const shuffledTwice = shuffle(shuffled);\n\n onChange(shuffledTwice, correctResponse);\n } else {\n onChange(shuffled, correctResponse);\n }\n };\n\n this.onDropChoice = (ordering, target, source) => {\n const { onChange } = this.props;\n const from = ordering.tiles.find((t) => t.id === source.id && t.type === source.type);\n const to = target;\n log('[onDropChoice] ', from, to);\n const { response, choices } = updateResponseOrChoices(ordering.response, ordering.choices, from, to);\n\n onChange(choices, response);\n };\n }\n\n render() {\n const {\n classes,\n correctResponse,\n choices,\n imageSupport,\n disableImages,\n toolbarOpts,\n singularChoiceLabel,\n pluralChoiceLabel,\n choicesLabel,\n spellCheck,\n maxImageWidth,\n maxImageHeight,\n errors,\n } = this.props;\n const { warning } = this.state;\n const { choicesErrors, orderError } = errors || {};\n\n const ordering = {\n choices,\n response: !correctResponse || isEmpty(correctResponse) ? new Array(choices.length) : correctResponse,\n tiles: buildTiles(choices, correctResponse, this.instanceId),\n };\n\n const vTilerStyle = {\n gridTemplateColumns: 'repeat(2, 1fr)',\n gridTemplateRows: `repeat(${choices.length}, 1fr)`,\n };\n\n return (\n <div className={classes.choiceEditor}>\n <div className={classes.vtiler} style={{ gridTemplateColumns: 'repeat(2, 1fr)' }}>\n <InputContainer label={`Student ${choicesLabel || 'Choices'}`} className={classes.columnLabel} />\n <InputContainer label=\"Correct Order\" className={classes.columnLabel} />\n </div>\n\n <div className={classes.vtiler} style={vTilerStyle}>\n {ordering.tiles.map((choice, index) => (\n <ChoiceTile\n choice={choice}\n index={index}\n key={index}\n imageSupport={imageSupport}\n onDelete={this.onDelete.bind(this, choice)}\n onChoiceChange={this.onChoiceChange}\n onDropChoice={(source, index) => this.onDropChoice(ordering, choice, source, index)}\n disableImages={disableImages}\n toolbarOpts={toolbarOpts}\n choices={choices}\n choicesLabel={choicesLabel}\n spellCheck={spellCheck}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n error={choicesErrors?.[choice.id] || (orderError && ' ') || null}\n />\n ))}\n </div>\n\n {orderError && <div className={classes.errorText}>{orderError}</div>}\n\n <div className={classes.controls}>\n <Button\n onClick={this.shuffleChoices}\n size=\"small\"\n variant=\"contained\"\n color=\"default\"\n classes={{ root: classes.addButtonRoot, label: classes.addButtonLabel }}\n >\n {`SHUFFLE ${pluralChoiceLabel}`.toUpperCase()}\n </Button>\n\n <Button\n onClick={this.addChoice}\n size=\"small\"\n variant=\"contained\"\n color=\"default\"\n classes={{ root: classes.addButtonRoot, label: classes.addButtonLabel }}\n >\n {`ADD ${singularChoiceLabel}`.toUpperCase()}\n </Button>\n </div>\n\n <AlertDialog\n open={warning.open}\n title=\"Warning\"\n text={warning.text}\n onConfirm={() => this.setState({ warning: { open: false } })}\n />\n </div>\n );\n }\n}\n\nconst styles = (theme) => ({\n allToggle: {},\n choiceEditor: {\n marginTop: theme.spacing.unit,\n },\n controls: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n },\n root: {\n width: '30px',\n height: '30px',\n fill: theme.palette.primary[500],\n },\n addButtonRoot: {\n marginTop: theme.spacing.unit * 3,\n paddingHorizontal: theme.spacing.unit * 1.5,\n },\n addButtonLabel: {\n transition: 'opacity 200ms linear',\n '&:hover': {\n opacity: 0.3,\n },\n },\n vtiler: {\n gridAutoFlow: 'column',\n display: 'grid',\n gridGap: '10px',\n },\n columnLabel: {\n width: '100%',\n paddingTop: theme.spacing.unit * 3,\n marginTop: theme.spacing.unit * 2,\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: 'red',\n paddingTop: theme.spacing.unit,\n },\n});\n\nexport default withStyles(styles)(ChoiceEditor);\n"],"file":"choice-editor.js"}