@pie-element/placement-ordering 7.5.0 → 7.5.3-next.1014

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.
@@ -5,12 +5,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = void 0;
8
+ exports["default"] = exports.InfoDialog = void 0;
9
9
 
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
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,44 @@ 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 _Dialog = _interopRequireDefault(require("@material-ui/core/Dialog"));
49
+
50
+ var _DialogTitle = _interopRequireDefault(require("@material-ui/core/DialogTitle"));
51
+
52
+ var _DialogActions = _interopRequireDefault(require("@material-ui/core/DialogActions"));
53
+
40
54
  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
55
 
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; } }
56
+ 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
57
 
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; }
58
+ 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
59
 
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; }
60
+ 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; }
61
+
62
+ var InfoDialog = function InfoDialog(_ref) {
63
+ var title = _ref.title,
64
+ open = _ref.open,
65
+ onOk = _ref.onOk;
66
+ return /*#__PURE__*/_react["default"].createElement(_Dialog["default"], {
67
+ open: open
68
+ }, /*#__PURE__*/_react["default"].createElement(_DialogTitle["default"], null, title), /*#__PURE__*/_react["default"].createElement(_DialogActions["default"], null, onOk && /*#__PURE__*/_react["default"].createElement(_Button["default"], {
69
+ onClick: onOk,
70
+ color: "primary"
71
+ }, "OK")));
72
+ };
73
+
74
+ exports.InfoDialog = InfoDialog;
75
+ InfoDialog.propTypes = {
76
+ title: _propTypes["default"].string,
77
+ open: _propTypes["default"].bool,
78
+ onOk: _propTypes["default"].func
79
+ };
47
80
 
48
81
  function findFreeChoiceSlot(choices) {
49
82
  var slot = 1;
@@ -60,26 +93,70 @@ function findFreeChoiceSlot(choices) {
60
93
 
61
94
  var log = (0, _debug["default"])('@pie-element:placement-ordering:configure:choice-editor');
62
95
 
63
- function updateResponse(response, from, to) {
64
- var update = (0, _cloneDeep["default"])(response);
65
- var fromType = from.type;
96
+ function updateResponseOrChoices(response, choices, from, to) {
97
+ var fromType = from.type,
98
+ fromIndex = from.index;
66
99
  var toType = to.type,
67
100
  placeAtIndex = to.index;
68
101
 
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;
102
+ if (fromType === 'target' && toType === 'target') {
103
+ var updatedResponse = (0, _cloneDeep["default"])(response) || [];
104
+
105
+ var _updatedResponse$redu = updatedResponse.reduce(function (acc, item, index) {
106
+ if (index === fromIndex) {
107
+ acc.movedItem = item;
108
+ } else {
109
+ acc.remainingItems.push(item);
110
+ }
111
+
112
+ return acc;
113
+ }, {
114
+ movedItem: null,
115
+ remainingItems: []
116
+ }),
117
+ movedItem = _updatedResponse$redu.movedItem,
118
+ remainingItems = _updatedResponse$redu.remainingItems;
119
+
120
+ return {
121
+ response: [].concat((0, _toConsumableArray2["default"])(remainingItems.slice(0, placeAtIndex)), [movedItem], (0, _toConsumableArray2["default"])(remainingItems.slice(placeAtIndex))),
122
+ choices: choices
123
+ };
124
+ }
125
+
126
+ if (fromType === 'choice' && toType === 'choice') {
127
+ var updatedChoices = (0, _cloneDeep["default"])(choices) || [];
128
+
129
+ var _updatedChoices$reduc = updatedChoices.reduce(function (acc, item, index) {
130
+ if (item.id === from.id) {
131
+ acc.movedItem = item;
132
+ } else {
133
+ acc.remainingItems.push(item);
134
+ }
135
+
136
+ if (item.id === to.id) {
137
+ acc.toIndex = index;
138
+ }
139
+
140
+ return acc;
141
+ }, {
142
+ movedItem: null,
143
+ remainingItems: [],
144
+ toIndex: null
145
+ }),
146
+ _movedItem = _updatedChoices$reduc.movedItem,
147
+ _remainingItems = _updatedChoices$reduc.remainingItems,
148
+ toIndex = _updatedChoices$reduc.toIndex;
149
+
150
+ return {
151
+ response: response,
152
+ choices: [].concat((0, _toConsumableArray2["default"])(_remainingItems.slice(0, toIndex)), [_movedItem], (0, _toConsumableArray2["default"])(_remainingItems.slice(toIndex)))
153
+ };
80
154
  }
81
155
 
82
- return response;
156
+ return {
157
+ response: response,
158
+ choices: choices
159
+ };
83
160
  }
84
161
 
85
162
  function buildTiles(choices, response, instanceId) {
@@ -119,13 +196,19 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
119
196
 
120
197
  (0, _classCallCheck2["default"])(this, ChoiceEditor);
121
198
  _this = _super.call(this, props);
199
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
200
+ dialog: {
201
+ open: false
202
+ }
203
+ });
122
204
  _this.instanceId = (0, _uniqueId["default"])();
123
205
 
124
206
  _this.onChoiceChange = function (choice) {
125
207
  var _this$props = _this.props,
126
208
  choices = _this$props.choices,
127
209
  onChange = _this$props.onChange,
128
- correctResponse = _this$props.correctResponse;
210
+ correctResponse = _this$props.correctResponse,
211
+ toolbarOpts = _this$props.toolbarOpts;
129
212
  var index = choices.findIndex(function (c) {
130
213
  return c.id === choice.id;
131
214
  });
@@ -139,51 +222,111 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
139
222
  var _this$props2 = _this.props,
140
223
  choices = _this$props2.choices,
141
224
  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);
225
+ correctResponse = _this$props2.correctResponse,
226
+ choicesLabel = _this$props2.choicesLabel;
227
+
228
+ if (choices && choices.length === 3) {
229
+ _this.setState({
230
+ dialog: {
231
+ open: true,
232
+ message: "There have to be at least 3 ".concat(choicesLabel, "."),
233
+ onOk: function onOk() {
234
+ _this.setState({
235
+ dialog: {
236
+ open: false
237
+ }
238
+ });
239
+ }
240
+ }
241
+ });
242
+ } else {
243
+ var updatedChoices = choices.filter(function (c) {
244
+ return c.id !== choice.id;
245
+ });
246
+ var updatedCorrectResponse = correctResponse.filter(function (v) {
247
+ return v.id !== choice.id;
248
+ });
249
+ onChange(updatedChoices, updatedCorrectResponse);
250
+ }
150
251
  };
151
252
 
152
253
  _this.addChoice = function () {
153
254
  var _this$props3 = _this.props,
154
255
  choices = _this$props3.choices,
155
256
  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);
257
+ onChange = _this$props3.onChange,
258
+ choicesLabel = _this$props3.choicesLabel;
259
+
260
+ if (choices && choices.length === 10) {
261
+ _this.setState({
262
+ dialog: {
263
+ open: true,
264
+ message: "There can be maximum 10 ".concat(choicesLabel, "."),
265
+ onOk: function onOk() {
266
+ _this.setState({
267
+ dialog: {
268
+ open: false
269
+ }
270
+ });
271
+ }
272
+ }
273
+ });
274
+ } else {
275
+ var freeId = findFreeChoiceSlot(choices);
276
+ var id = "c".concat(freeId);
277
+ var newChoice = {
278
+ id: id,
279
+ label: ''
280
+ };
281
+ var newCorrectResponse = {
282
+ id: id,
283
+
284
+ /**
285
+ * Note: weights are not configurable in the existing component
286
+ * so we'll want do disable this in the controller and ignore it for now.
287
+ */
288
+ weight: 0
289
+ };
290
+ var updatedChoices = choices.concat([newChoice]);
291
+ var updatedCorrectResponse = correctResponse.concat([newCorrectResponse]);
292
+ onChange(updatedChoices, updatedCorrectResponse);
293
+ }
175
294
  };
176
295
 
177
- _this.onDropChoice = function (ordering, target, source) {
296
+ _this.shuffleChoices = function () {
178
297
  var _this$props4 = _this.props,
179
298
  onChange = _this$props4.onChange,
180
- choices = _this$props4.choices;
299
+ choices = _this$props4.choices,
300
+ correctResponse = _this$props4.correctResponse,
301
+ placementArea = _this$props4.placementArea;
302
+ var shuffled = (0, _shuffle["default"])(choices); // if placementArea is disabled, make sure we don't shuffle choices in the correct order
303
+
304
+ var shuffledCorrect = !placementArea && (0, _isEqual["default"])(shuffled.map(function (item) {
305
+ return item.id;
306
+ }), correctResponse.map(function (item) {
307
+ return item.id;
308
+ }));
309
+
310
+ if (shuffledCorrect) {
311
+ var shuffledTwice = (0, _shuffle["default"])(shuffled);
312
+ onChange(shuffledTwice, correctResponse);
313
+ } else {
314
+ onChange(shuffled, correctResponse);
315
+ }
316
+ };
317
+
318
+ _this.onDropChoice = function (ordering, target, source) {
319
+ var onChange = _this.props.onChange;
181
320
  var from = ordering.tiles.find(function (t) {
182
321
  return t.id === source.id && t.type === source.type;
183
322
  });
184
323
  var to = target;
185
324
  log('[onDropChoice] ', from, to);
186
- var response = updateResponse(ordering.response, from, to);
325
+
326
+ var _updateResponseOrChoi = updateResponseOrChoices(ordering.response, ordering.choices, from, to),
327
+ response = _updateResponseOrChoi.response,
328
+ choices = _updateResponseOrChoi.choices;
329
+
187
330
  onChange(choices, response);
188
331
  };
189
332
 
@@ -200,7 +343,15 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
200
343
  correctResponse = _this$props5.correctResponse,
201
344
  choices = _this$props5.choices,
202
345
  imageSupport = _this$props5.imageSupport,
203
- disableImages = _this$props5.disableImages;
346
+ disableImages = _this$props5.disableImages,
347
+ toolbarOpts = _this$props5.toolbarOpts,
348
+ singularChoiceLabel = _this$props5.singularChoiceLabel,
349
+ pluralChoiceLabel = _this$props5.pluralChoiceLabel,
350
+ choicesLabel = _this$props5.choicesLabel,
351
+ spellCheck = _this$props5.spellCheck,
352
+ maxImageWidth = _this$props5.maxImageWidth,
353
+ maxImageHeight = _this$props5.maxImageHeight;
354
+ var dialog = this.state.dialog;
204
355
  var ordering = {
205
356
  choices: choices,
206
357
  response: !correctResponse || (0, _isEmpty["default"])(correctResponse) ? new Array(choices.length) : correctResponse,
@@ -226,11 +377,26 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
226
377
  onDropChoice: function onDropChoice(source, index) {
227
378
  return _this2.onDropChoice(ordering, c, source, index);
228
379
  },
229
- disableImages: disableImages
380
+ disableImages: disableImages,
381
+ toolbarOpts: toolbarOpts,
382
+ choices: choices,
383
+ choicesLabel: choicesLabel,
384
+ spellCheck: spellCheck,
385
+ maxImageWidth: maxImageWidth,
386
+ maxImageHeight: maxImageHeight
230
387
  });
231
388
  })), /*#__PURE__*/_react["default"].createElement("div", {
232
389
  className: classes.controls
233
390
  }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
391
+ onClick: this.shuffleChoices,
392
+ size: "small",
393
+ variant: "contained",
394
+ color: "default",
395
+ classes: {
396
+ root: classes.addButtonRoot,
397
+ label: classes.addButtonLabel
398
+ }
399
+ }, "SHUFFLE ".concat(pluralChoiceLabel).toUpperCase()), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
234
400
  onClick: this.addChoice,
235
401
  size: "small",
236
402
  variant: "contained",
@@ -239,7 +405,11 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
239
405
  root: classes.addButtonRoot,
240
406
  label: classes.addButtonLabel
241
407
  }
242
- }, "ADD CHOICE")));
408
+ }, "ADD ".concat(singularChoiceLabel).toUpperCase())), /*#__PURE__*/_react["default"].createElement(InfoDialog, {
409
+ title: dialog.message,
410
+ open: dialog.open,
411
+ onOk: dialog.onOk
412
+ }));
243
413
  }
244
414
  }]);
245
415
  return ChoiceEditor;
@@ -254,7 +424,12 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
254
424
  add: _propTypes["default"].func.isRequired,
255
425
  "delete": _propTypes["default"].func.isRequired
256
426
  }),
257
- disableImages: _propTypes["default"].bool
427
+ disableImages: _propTypes["default"].bool,
428
+ toolbarOpts: _propTypes["default"].object,
429
+ placementArea: _propTypes["default"].bool,
430
+ singularChoiceLabel: _propTypes["default"].string,
431
+ pluralChoiceLabel: _propTypes["default"].string,
432
+ choicesLabel: _propTypes["default"].string
258
433
  });
259
434
 
260
435
  var styles = function styles(theme) {
@@ -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,CAElC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e,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":["InfoDialog","title","open","onOk","propTypes","PropTypes","string","bool","func","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","dialog","onChoiceChange","onChange","correctResponse","toolbarOpts","findIndex","splice","label","onDelete","choicesLabel","length","setState","message","filter","updatedCorrectResponse","v","addChoice","freeId","newChoice","newCorrectResponse","weight","shuffleChoices","placementArea","shuffled","shuffledCorrect","shuffledTwice","onDropChoice","ordering","target","source","tiles","t","classes","imageSupport","disableImages","singularChoiceLabel","pluralChoiceLabel","spellCheck","maxImageWidth","maxImageHeight","state","Array","style","gridTemplateColumns","gridTemplateRows","choiceEditor","vtiler","bind","controls","root","addButtonRoot","addButtonLabel","toUpperCase","React","Component","object","isRequired","array","shape","add","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;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEO,IAAMA,UAAU,GAAG,SAAbA,UAAa;AAAA,MAAGC,KAAH,QAAGA,KAAH;AAAA,MAAUC,IAAV,QAAUA,IAAV;AAAA,MAAgBC,IAAhB,QAAgBA,IAAhB;AAAA,sBACxB,gCAAC,kBAAD;AAAQ,IAAA,IAAI,EAAED;AAAd,kBACE,gCAAC,uBAAD,QAAcD,KAAd,CADF,eAEE,gCAAC,yBAAD,QACGE,IAAI,iBACH,gCAAC,kBAAD;AAAQ,IAAA,OAAO,EAAEA,IAAjB;AAAuB,IAAA,KAAK,EAAC;AAA7B,UAFJ,CAFF,CADwB;AAAA,CAAnB;;;AAaPH,UAAU,CAACI,SAAX,GAAuB;AACrBH,EAAAA,KAAK,EAAEI,sBAAUC,MADI;AAErBJ,EAAAA,IAAI,EAAEG,sBAAUE,IAFK;AAGrBJ,EAAAA,IAAI,EAAEE,sBAAUG;AAHK,CAAvB;;AAMA,SAASC,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,uBAAT,CAAiCC,QAAjC,EAA2CT,OAA3C,EAAoDU,IAApD,EAA0DC,EAA1D,EAA8D;AAC5D,MAAcC,QAAd,GAA6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Y,EAAE;AACZkB,MAAAA,SAAS,EAAE;AADC,KAFS;AAKvBf,IAAAA,QAAQ,EAAE;AACRgB,MAAAA,OAAO,EAAE,MADD;AAERC,MAAAA,UAAU,EAAE,QAFJ;AAGRC,MAAAA,cAAc,EAAE;AAHR,KALa;AAUvBjB,IAAAA,IAAI,EAAE;AACJkB,MAAAA,KAAK,EAAE,MADH;AAEJC,MAAAA,MAAM,EAAE,MAFJ;AAGJC,MAAAA,IAAI,EAAER,KAAK,CAACS,OAAN,CAAcC,OAAd,CAAsB,GAAtB;AAHF,KAViB;AAevBrB,IAAAA,aAAa,EAAE;AACba,MAAAA,SAAS,EAAE,MADE;AAEbS,MAAAA,iBAAiB,EAAE;AAFN,KAfQ;AAmBvBrB,IAAAA,cAAc,EAAE;AACdsB,MAAAA,UAAU,EAAE,sBADE;AAEd,iBAAW;AACTC,QAAAA,OAAO,EAAE;AADA;AAFG,KAnBO;AAyBvB5B,IAAAA,MAAM,EAAE;AACN6B,MAAAA,YAAY,EAAE,QADR;AAENX,MAAAA,OAAO,EAAE,MAFH;AAGNY,MAAAA,OAAO,EAAE;AAHH;AAzBe,GAAL;AAAA,CAApB;;eAgCe,wBAAWhB,MAAX,EAAmB9D,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 Dialog from '@material-ui/core/Dialog';\nimport DialogTitle from '@material-ui/core/DialogTitle';\nimport DialogActions from '@material-ui/core/DialogActions';\n\nexport const InfoDialog = ({ title, open, onOk }) => (\n <Dialog open={open}>\n <DialogTitle>{title}</DialogTitle>\n <DialogActions>\n {onOk && (\n <Button onClick={onOk} color=\"primary\">\n OK\n </Button>\n )}\n </DialogActions>\n </Dialog>\n);\n\nInfoDialog.propTypes = {\n title: PropTypes.string,\n open: PropTypes.bool,\n onOk: PropTypes.func,\n};\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 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: [\n ...remainingItems.slice(0, placeAtIndex),\n movedItem,\n ...remainingItems.slice(placeAtIndex)\n ],\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: [\n ...remainingItems.slice(0, toIndex),\n movedItem,\n ...remainingItems.slice(toIndex)\n ]\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\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 };\n\n state = {\n dialog: {\n open: false\n }\n };\n\n constructor(props) {\n super(props);\n\n this.instanceId = uniqueId();\n\n this.onChoiceChange = choice => {\n const { choices, onChange, correctResponse, toolbarOpts } = 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 dialog: {\n open: true,\n message: `There have to be at least 3 ${choicesLabel}.`,\n onOk: () => {\n this.setState(\n {\n dialog: {\n open: false,\n }\n }\n );\n }\n }\n });\n }\n else {\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\n this.addChoice = () => {\n const { choices, correctResponse, onChange, choicesLabel } = this.props;\n\n if (choices && choices.length === 10) {\n this.setState({\n dialog: {\n open: true,\n message: `There can be maximum 10 ${choicesLabel}.`,\n onOk: () => {\n this.setState(\n {\n dialog: {\n open: false,\n }\n }\n );\n }\n }\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([\n newCorrectResponse\n ]);\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 = !placementArea && isEqual(shuffled.map(item => item.id), correctResponse.map(item => item.id));\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(\n t => t.id === source.id && t.type === source.type\n );\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 } = this.props;\n const { dialog } = this.state;\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 toolbarOpts={toolbarOpts}\n choices={choices}\n choicesLabel={choicesLabel}\n spellCheck={spellCheck}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n />\n ))}\n </div>\n <div className={classes.controls}>\n <Button\n onClick={this.shuffleChoices}\n size=\"small\"\n variant=\"contained\"\n color=\"default\"\n classes={{\n root: classes.addButtonRoot,\n label: classes.addButtonLabel\n }}\n >\n {`SHUFFLE ${pluralChoiceLabel}`.toUpperCase()}\n </Button>\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 ${singularChoiceLabel}`.toUpperCase()}\n </Button>\n </div>\n <InfoDialog\n title={dialog.message}\n open={dialog.open}\n onOk={dialog.onOk}\n />\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);\n"],"file":"choice-editor.js"}
@@ -2,6 +2,8 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
@@ -21,7 +23,7 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
21
23
 
22
24
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
25
 
24
- var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
26
+ var _editableHtml = _interopRequireWildcard(require("@pie-lib/editable-html"));
25
27
 
26
28
  var _CardActions = _interopRequireDefault(require("@material-ui/core/CardActions"));
27
29
 
@@ -43,9 +45,15 @@ var _debug = _interopRequireDefault(require("debug"));
43
45
 
44
46
  var _styles = require("@material-ui/core/styles");
45
47
 
48
+ var _choiceEditor = require("./choice-editor");
49
+
50
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
51
+
52
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
53
+
46
54
  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); }; }
47
55
 
48
- 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; } }
56
+ 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; } }
49
57
 
50
58
  var log = (0, _debug["default"])('@pie-element:placement-ordering:configure:choice-tile');
51
59
 
@@ -64,12 +72,43 @@ var ChoiceTile = /*#__PURE__*/function (_React$Component) {
64
72
  }
65
73
 
66
74
  _this = _super.call.apply(_super, [this].concat(args));
75
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
76
+ dialog: {
77
+ open: false
78
+ }
79
+ });
67
80
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onLabelChange", function (label) {
68
81
  var _this$props = _this.props,
69
82
  choice = _this$props.choice,
70
- onChoiceChange = _this$props.onChoiceChange;
71
- choice.label = label;
72
- onChoiceChange(choice);
83
+ onChoiceChange = _this$props.onChoiceChange,
84
+ choices = _this$props.choices,
85
+ choicesLabel = _this$props.choicesLabel;
86
+ var currentValue = choice.label;
87
+ var sameValue = choices.filter(function (choice) {
88
+ var wasChanged = currentValue !== label && "<div>".concat(currentValue, "</div>") !== label;
89
+ var sameValueEntered = choice.label === label || "<div>".concat(choice.label, "</div>") === label;
90
+ return wasChanged && sameValueEntered;
91
+ });
92
+ var empty = label === '<div></div>';
93
+
94
+ if (sameValue.length || empty) {
95
+ _this.setState({
96
+ dialog: {
97
+ open: true,
98
+ message: "Each of the ".concat(choicesLabel, " must be non-empty and unique."),
99
+ onOk: function onOk() {
100
+ _this.setState({
101
+ dialog: {
102
+ open: false
103
+ }
104
+ });
105
+ }
106
+ }
107
+ });
108
+ } else {
109
+ choice.label = label;
110
+ onChoiceChange(choice);
111
+ }
73
112
  });
74
113
  return _this;
75
114
  }
@@ -87,7 +126,12 @@ var ChoiceTile = /*#__PURE__*/function (_React$Component) {
87
126
  classes = _this$props2.classes,
88
127
  onDelete = _this$props2.onDelete,
89
128
  imageSupport = _this$props2.imageSupport,
90
- disableImages = _this$props2.disableImages;
129
+ disableImages = _this$props2.disableImages,
130
+ spellCheck = _this$props2.spellCheck,
131
+ toolbarOpts = _this$props2.toolbarOpts,
132
+ maxImageWidth = _this$props2.maxImageWidth,
133
+ maxImageHeight = _this$props2.maxImageHeight;
134
+ var dialog = this.state.dialog;
91
135
  var dragSourceOpts = {}; //dropEffect: moveOnDrag ? 'move' : 'copy'};
92
136
 
93
137
  var choicePlugins = {
@@ -101,6 +145,9 @@ var ChoiceTile = /*#__PURE__*/function (_React$Component) {
101
145
  disabled: true
102
146
  }
103
147
  };
148
+ var filteredDefaultPlugins = (_editableHtml.DEFAULT_PLUGINS || []).filter(function (p) {
149
+ return p !== 'bulleted-list' && p !== 'numbered-list';
150
+ });
104
151
  var opacity = isDragging ? 0 : 1;
105
152
 
106
153
  var markup = /*#__PURE__*/_react["default"].createElement("div", {
@@ -120,7 +167,13 @@ var ChoiceTile = /*#__PURE__*/function (_React$Component) {
120
167
  markup: label,
121
168
  imageSupport: imageSupport || undefined,
122
169
  onChange: this.onLabelChange,
123
- pluginProps: choicePlugins
170
+ pluginProps: choicePlugins,
171
+ toolbarOpts: toolbarOpts,
172
+ activePlugins: filteredDefaultPlugins,
173
+ spellCheck: spellCheck,
174
+ allowValidation: true,
175
+ maxImageWidth: maxImageWidth,
176
+ maxImageHeight: maxImageHeight
124
177
  }), editable && /*#__PURE__*/_react["default"].createElement("div", {
125
178
  className: classes.controls
126
179
  }, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
@@ -130,7 +183,11 @@ var ChoiceTile = /*#__PURE__*/function (_React$Component) {
130
183
  classes: {
131
184
  root: classes.removeCircle
132
185
  }
133
- }))));
186
+ }))), /*#__PURE__*/_react["default"].createElement(_choiceEditor.InfoDialog, {
187
+ title: dialog.message,
188
+ open: dialog.open,
189
+ onOk: dialog.onOk
190
+ }));
134
191
 
135
192
  return connectDragSource(connectDropTarget( /*#__PURE__*/_react["default"].createElement("div", null, markup)), dragSourceOpts);
136
193
  }
@@ -157,9 +214,12 @@ exports.ChoiceTile = ChoiceTile;
157
214
  "delete": _propTypes["default"].func.isRequired
158
215
  }),
159
216
  choice: _propTypes["default"].object,
217
+ choices: _propTypes["default"].array.isRequired,
160
218
  onChoiceChange: _propTypes["default"].func.isRequired,
161
219
  onDelete: _propTypes["default"].func.isRequired,
162
- disableImages: _propTypes["default"].bool
220
+ disableImages: _propTypes["default"].bool,
221
+ toolbarOpts: _propTypes["default"].object,
222
+ choicesLabel: _propTypes["default"].string
163
223
  });
164
224
  var Styled = (0, _styles.withStyles)(function (theme) {
165
225
  return {