@pie-element/placement-ordering 9.12.1-next.1 → 9.12.1-next.2

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.
@@ -0,0 +1,477 @@
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"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
+
24
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
25
+
26
+ var _choiceTile = _interopRequireDefault(require("./choice-tile"));
27
+
28
+ var _propTypes = _interopRequireDefault(require("prop-types"));
29
+
30
+ var _react = _interopRequireDefault(require("react"));
31
+
32
+ var _debug = _interopRequireDefault(require("debug"));
33
+
34
+ var _styles = require("@material-ui/core/styles");
35
+
36
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
37
+
38
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
39
+
40
+ var _uniqueId = _interopRequireDefault(require("lodash/uniqueId"));
41
+
42
+ var _shuffle = _interopRequireDefault(require("lodash/shuffle"));
43
+
44
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
45
+
46
+ var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
47
+
48
+ var _renderUi = require("@pie-lib/pie-toolbox/render-ui");
49
+
50
+ var _configUi = require("@pie-lib/pie-toolbox/config-ui");
51
+
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); }; }
53
+
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; } }
55
+
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; }
57
+
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; }
59
+
60
+ function findFreeChoiceSlot(choices) {
61
+ var slot = 1;
62
+ var ids = choices.map(function (c) {
63
+ return c.id;
64
+ });
65
+
66
+ while (ids.includes("c".concat(slot))) {
67
+ slot++;
68
+ }
69
+
70
+ return slot;
71
+ }
72
+
73
+ var log = (0, _debug["default"])('@pie-element:placement-ordering:configure:choice-editor');
74
+
75
+ function updateResponseOrChoices(response, choices, from, to) {
76
+ var fromType = from.type,
77
+ fromIndex = from.index;
78
+ var toType = to.type,
79
+ placeAtIndex = to.index;
80
+
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
+ };
133
+ }
134
+
135
+ return {
136
+ response: response,
137
+ choices: choices
138
+ };
139
+ }
140
+
141
+ function buildTiles(choices, response, instanceId) {
142
+ var targets = response.map(function (r, index) {
143
+ var respId = r && r.id;
144
+ var choice = choices.find(function (c) {
145
+ return respId !== undefined && respId !== null && c.id === respId;
146
+ });
147
+ return _objectSpread(_objectSpread({
148
+ type: 'target',
149
+ instanceId: instanceId
150
+ }, choice), {}, {
151
+ draggable: true,
152
+ index: index,
153
+ editable: false
154
+ });
155
+ });
156
+ var processedChoices = choices.map(function (m) {
157
+ return Object.assign({}, m, {
158
+ type: 'choice',
159
+ droppable: false,
160
+ draggable: true,
161
+ instanceId: instanceId,
162
+ editable: true
163
+ });
164
+ });
165
+ return processedChoices.concat(targets);
166
+ }
167
+
168
+ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
169
+ (0, _inherits2["default"])(ChoiceEditor, _React$Component);
170
+
171
+ var _super = _createSuper(ChoiceEditor);
172
+
173
+ function ChoiceEditor(props) {
174
+ var _this;
175
+
176
+ (0, _classCallCheck2["default"])(this, ChoiceEditor);
177
+ _this = _super.call(this, props);
178
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
179
+ warning: {
180
+ open: false
181
+ }
182
+ });
183
+ _this.instanceId = (0, _uniqueId["default"])();
184
+
185
+ _this.onChoiceChange = function (choice) {
186
+ var _this$props = _this.props,
187
+ choices = _this$props.choices,
188
+ onChange = _this$props.onChange,
189
+ correctResponse = _this$props.correctResponse;
190
+ var index = choices.findIndex(function (c) {
191
+ return c.id === choice.id;
192
+ });
193
+ choices.splice(index, 1, _objectSpread(_objectSpread({}, choices[index]), {}, {
194
+ label: choice.label
195
+ }));
196
+ onChange(choices, correctResponse);
197
+ };
198
+
199
+ _this.onDelete = function (choice) {
200
+ var _this$props2 = _this.props,
201
+ choices = _this$props2.choices,
202
+ onChange = _this$props2.onChange,
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
+ }
222
+ };
223
+
224
+ _this.addChoice = function () {
225
+ var _this$props3 = _this.props,
226
+ choices = _this$props3.choices,
227
+ correctResponse = _this$props3.correctResponse,
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
+ }
258
+ };
259
+
260
+ _this.shuffleChoices = function () {
261
+ var _this$props4 = _this.props,
262
+ onChange = _this$props4.onChange,
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;
284
+ var from = ordering.tiles.find(function (t) {
285
+ return t.id === source.id && t.type === source.type;
286
+ });
287
+ var to = target;
288
+ log('[onDropChoice] ', from, to);
289
+
290
+ var _updateResponseOrChoi = updateResponseOrChoices(ordering.response, ordering.choices, from, to),
291
+ response = _updateResponseOrChoi.response,
292
+ choices = _updateResponseOrChoi.choices;
293
+
294
+ onChange(choices, response);
295
+ };
296
+
297
+ return _this;
298
+ }
299
+
300
+ (0, _createClass2["default"])(ChoiceEditor, [{
301
+ key: "render",
302
+ value: function render() {
303
+ var _this2 = this;
304
+
305
+ var _this$props5 = this.props,
306
+ classes = _this$props5.classes,
307
+ correctResponse = _this$props5.correctResponse,
308
+ choices = _this$props5.choices,
309
+ imageSupport = _this$props5.imageSupport,
310
+ toolbarOpts = _this$props5.toolbarOpts,
311
+ pluginProps = _this$props5.pluginProps,
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
+ _this$props5$mathMlOp = _this$props5.mathMlOptions,
320
+ mathMlOptions = _this$props5$mathMlOp === void 0 ? {} : _this$props5$mathMlOp;
321
+ var warning = this.state.warning;
322
+
323
+ var _ref = errors || {},
324
+ choicesErrors = _ref.choicesErrors,
325
+ orderError = _ref.orderError;
326
+
327
+ var ordering = {
328
+ choices: choices,
329
+ response: !correctResponse || (0, _isEmpty["default"])(correctResponse) ? new Array(choices.length) : correctResponse,
330
+ tiles: buildTiles(choices, correctResponse, this.instanceId)
331
+ };
332
+ var vTilerStyle = {
333
+ gridTemplateColumns: 'repeat(2, 1fr)',
334
+ gridTemplateRows: "repeat(".concat(choices.length, ", 1fr)")
335
+ };
336
+ return /*#__PURE__*/_react["default"].createElement("div", {
337
+ className: classes.choiceEditor
338
+ }, /*#__PURE__*/_react["default"].createElement("div", {
339
+ className: classes.vtiler,
340
+ style: {
341
+ gridTemplateColumns: 'repeat(2, 1fr)'
342
+ }
343
+ }, /*#__PURE__*/_react["default"].createElement(_renderUi.InputContainer, {
344
+ label: "Student ".concat(choicesLabel || 'Choices'),
345
+ className: classes.columnLabel
346
+ }), /*#__PURE__*/_react["default"].createElement(_renderUi.InputContainer, {
347
+ label: "Correct Order",
348
+ className: classes.columnLabel
349
+ })), /*#__PURE__*/_react["default"].createElement("div", {
350
+ className: classes.vtiler,
351
+ style: vTilerStyle
352
+ }, ordering.tiles.map(function (choice, index) {
353
+ return /*#__PURE__*/_react["default"].createElement(_choiceTile["default"], {
354
+ choice: choice,
355
+ index: index,
356
+ key: index,
357
+ imageSupport: imageSupport,
358
+ onDelete: _this2.onDelete.bind(_this2, choice),
359
+ onChoiceChange: _this2.onChoiceChange,
360
+ onDropChoice: function onDropChoice(source, index) {
361
+ return _this2.onDropChoice(ordering, choice, source, index);
362
+ },
363
+ toolbarOpts: toolbarOpts,
364
+ pluginProps: pluginProps,
365
+ choices: choices,
366
+ choicesLabel: choicesLabel,
367
+ spellCheck: spellCheck,
368
+ maxImageWidth: maxImageWidth,
369
+ maxImageHeight: maxImageHeight,
370
+ error: (choicesErrors === null || choicesErrors === void 0 ? void 0 : choicesErrors[choice.id]) || orderError && ' ' || null,
371
+ mathMlOptions: mathMlOptions
372
+ });
373
+ })), orderError && /*#__PURE__*/_react["default"].createElement("div", {
374
+ className: classes.errorText
375
+ }, orderError), /*#__PURE__*/_react["default"].createElement("div", {
376
+ className: classes.controls
377
+ }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
378
+ onClick: this.shuffleChoices,
379
+ size: "small",
380
+ variant: "contained",
381
+ color: "default",
382
+ classes: {
383
+ root: classes.addButtonRoot,
384
+ label: classes.addButtonLabel
385
+ }
386
+ }, "SHUFFLE ".concat(pluralChoiceLabel).toUpperCase()), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
387
+ onClick: this.addChoice,
388
+ size: "small",
389
+ variant: "contained",
390
+ color: "default",
391
+ classes: {
392
+ root: classes.addButtonRoot,
393
+ label: classes.addButtonLabel
394
+ }
395
+ }, "ADD ".concat(singularChoiceLabel).toUpperCase())), /*#__PURE__*/_react["default"].createElement(_configUi.AlertDialog, {
396
+ open: warning.open,
397
+ title: "Warning",
398
+ text: warning.text,
399
+ onConfirm: function onConfirm() {
400
+ return _this2.setState({
401
+ warning: {
402
+ open: false
403
+ }
404
+ });
405
+ }
406
+ }));
407
+ }
408
+ }]);
409
+ return ChoiceEditor;
410
+ }(_react["default"].Component);
411
+
412
+ (0, _defineProperty2["default"])(ChoiceEditor, "propTypes", {
413
+ classes: _propTypes["default"].object.isRequired,
414
+ correctResponse: _propTypes["default"].array.isRequired,
415
+ choices: _propTypes["default"].array.isRequired,
416
+ onChange: _propTypes["default"].func.isRequired,
417
+ imageSupport: _propTypes["default"].shape({
418
+ add: _propTypes["default"].func.isRequired,
419
+ "delete": _propTypes["default"].func.isRequired
420
+ }),
421
+ maxImageHeight: _propTypes["default"].object,
422
+ maxImageWidth: _propTypes["default"].object,
423
+ toolbarOpts: _propTypes["default"].object,
424
+ pluginProps: _propTypes["default"].object,
425
+ placementArea: _propTypes["default"].bool,
426
+ singularChoiceLabel: _propTypes["default"].string,
427
+ pluralChoiceLabel: _propTypes["default"].string,
428
+ choicesLabel: _propTypes["default"].string,
429
+ errors: _propTypes["default"].object,
430
+ spellCheck: _propTypes["default"].bool
431
+ });
432
+
433
+ var styles = function styles(theme) {
434
+ return {
435
+ allToggle: {},
436
+ choiceEditor: {},
437
+ controls: {
438
+ display: 'flex',
439
+ alignItems: 'center',
440
+ justifyContent: 'space-between'
441
+ },
442
+ root: {
443
+ width: '30px',
444
+ height: '30px',
445
+ fill: theme.palette.primary[500]
446
+ },
447
+ addButtonRoot: {
448
+ marginTop: theme.spacing.unit * 2.5,
449
+ paddingHorizontal: theme.spacing.unit * 1.5
450
+ },
451
+ addButtonLabel: {
452
+ transition: 'opacity 200ms linear',
453
+ '&:hover': {
454
+ opacity: 0.3
455
+ }
456
+ },
457
+ vtiler: {
458
+ gridAutoFlow: 'column',
459
+ display: 'grid',
460
+ gridGap: '10px'
461
+ },
462
+ columnLabel: {
463
+ width: '100%',
464
+ paddingTop: theme.spacing.unit * 2
465
+ },
466
+ errorText: {
467
+ fontSize: theme.typography.fontSize - 2,
468
+ color: theme.palette.error.main,
469
+ paddingTop: theme.spacing.unit
470
+ }
471
+ };
472
+ };
473
+
474
+ var _default = (0, _styles.withStyles)(styles)(ChoiceEditor);
475
+
476
+ exports["default"] = _default;
477
+ //# sourceMappingURL=choice-editor.js.map
@@ -0,0 +1 @@
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","toolbarOpts","pluginProps","singularChoiceLabel","pluralChoiceLabel","spellCheck","maxImageWidth","maxImageHeight","errors","mathMlOptions","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","display","alignItems","justifyContent","width","height","fill","palette","primary","marginTop","spacing","unit","paddingHorizontal","transition","opacity","gridAutoFlow","gridGap","paddingTop","fontSize","typography","color","error","main"],"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,IAAjB,EAAP,EAAiC;AAC/BA,IAAAA,IAAI;AACL;;AAED,SAAOA,IAAP;AACD;;AAED,IAAMM,GAAG,GAAG,uBAAM,yDAAN,CAAZ;;AAEA,SAASC,uBAAT,CAAiCC,QAAjC,EAA2CT,OAA3C,EAAoDU,IAApD,EAA0DC,EAA1D,EAA8D;AAC5D,MAAcC,QAAd,GAA6CF,IAA7C,CAAQG,IAAR;AAAA,MAA+BC,SAA/B,GAA6CJ,IAA7C,CAAwBK,KAAxB;AACA,MAAcC,MAAd,GAA8CL,EAA9C,CAAQE,IAAR;AAAA,MAA6BI,YAA7B,GAA8CN,EAA9C,CAAsBI,KAAtB;;AAEA,MAAIH,QAAQ,KAAK,QAAb,IAAyBI,MAAM,KAAK,QAAxC,EAAkD;AAChD,QAAME,eAAe,GAAG,2BAAUT,QAAV,KAAuB,EAA/C;;AAEA,gCAAsCS,eAAe,CAACC,MAAhB,CACpC,UAACC,GAAD,EAAMC,IAAN,EAAYN,KAAZ,EAAsB;AACpB,UAAIA,KAAK,KAAKD,SAAd,EAAyB;AACvBM,QAAAA,GAAG,CAACE,SAAJ,GAAgBD,IAAhB;AACD,OAFD,MAEO;AACLD,QAAAA,GAAG,CAACG,cAAJ,CA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SAAS,EAAE;AACTqC,MAAAA,QAAQ,EAAEnB,KAAK,CAACoB,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;AAETE,MAAAA,KAAK,EAAErB,KAAK,CAACQ,OAAN,CAAcc,KAAd,CAAoBC,IAFlB;AAGTL,MAAAA,UAAU,EAAElB,KAAK,CAACW,OAAN,CAAcC;AAHjB;AAhCc,GAAZ;AAAA,CAAf;;eAuCe,wBAAWb,MAAX,EAAmBzE,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/pie-toolbox/render-ui';\nimport { AlertDialog } from '@pie-lib/pie-toolbox/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 maxImageHeight: PropTypes.object,\n maxImageWidth: PropTypes.object,\n toolbarOpts: PropTypes.object,\n pluginProps: PropTypes.object,\n placementArea: PropTypes.bool,\n singularChoiceLabel: PropTypes.string,\n pluralChoiceLabel: PropTypes.string,\n choicesLabel: PropTypes.string,\n errors: PropTypes.object,\n spellCheck: PropTypes.bool,\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 toolbarOpts,\n pluginProps,\n singularChoiceLabel,\n pluralChoiceLabel,\n choicesLabel,\n spellCheck,\n maxImageWidth,\n maxImageHeight,\n errors,\n mathMlOptions = {},\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 toolbarOpts={toolbarOpts}\n pluginProps={pluginProps}\n choices={choices}\n choicesLabel={choicesLabel}\n spellCheck={spellCheck}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n error={choicesErrors?.[choice.id] || (orderError && ' ') || null}\n mathMlOptions={mathMlOptions}\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 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 * 2.5,\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 * 2,\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n});\n\nexport default withStyles(styles)(ChoiceEditor);\n"],"file":"choice-editor.js"}