@pie-element/placement-ordering 7.6.1 → 7.7.1-next.0

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.
package/CHANGELOG.md CHANGED
@@ -3,9 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [7.6.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering@7.6.0...@pie-element/placement-ordering@7.6.1) (2021-09-01)
6
+ # [7.7.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering@7.5.2...@pie-element/placement-ordering@7.7.0) (2021-11-11)
7
7
 
8
- **Note:** Version bump only for package @pie-element/placement-ordering
8
+
9
+ ### Bug Fixes
10
+
11
+ * **placement-ordering:** fix create correct session for IBX browse items PD-1349 ([e84c30d](https://github.com/pie-framework/pie-elements/commit/e84c30dd075085ef5d917f2893568bca2003d225))
12
+ * **placement-ordering:** fix issues with dragging answer choices in authoring PD-1329 ([286a495](https://github.com/pie-framework/pie-elements/commit/286a495e313cb33227a8672f38331b283c283583))
13
+ * pie-lib updates ([e521c2f](https://github.com/pie-framework/pie-elements/commit/e521c2f1a44aa7f3e14f82a1cee05ceb484ed0a6))
14
+ * Updated pie-lib versions ([2fe4c5d](https://github.com/pie-framework/pie-elements/commit/2fe4c5d0be2d40f5fdb34815855695a7f1087f56))
15
+ * Updated pie-lib versions ([1c23830](https://github.com/pie-framework/pie-elements/commit/1c23830fc75d1de5f7bb3bb16de3c665ae5fa350))
16
+ * **placement-ordering:** Updated documentation PD-305 ([ff31ac5](https://github.com/pie-framework/pie-elements/commit/ff31ac57139f59413748e88f152ef7629ae6e5be))
17
+
18
+
19
+ ### Features
20
+
21
+ * **placement-ordering:** add baseline validation for authoring PD-600, PD-1334 ([2350279](https://github.com/pie-framework/pie-elements/commit/23502790000e3c4f14e4dae6744519b004eb1172))
22
+ * **placement-ordering:** add shuffle button to UI for authoring PD-1300 ([734fcda](https://github.com/pie-framework/pie-elements/commit/734fcda4b50b50cb54d66789b854f270818ba6fc))
23
+ * **placement-ordering:** added option to set toolbar editor position ([9b1b291](https://github.com/pie-framework/pie-elements/commit/9b1b2916f2c34297f3d4b239e393376f87be3826))
24
+ * **placement-ordering:** remove list buttons from choice labels PD-1337 ([1f1f927](https://github.com/pie-framework/pie-elements/commit/1f1f9276a29d84b551a3eaa93e15738ef1e22681))
9
25
 
10
26
 
11
27
 
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.5.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-configure@5.3.2...@pie-element/placement-ordering-configure@5.5.0) (2021-11-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **placement-ordering:** fix issues with dragging answer choices in authoring PD-1329 ([286a495](https://github.com/pie-framework/pie-elements/commit/286a495e313cb33227a8672f38331b283c283583))
12
+ * pie-lib updates ([e521c2f](https://github.com/pie-framework/pie-elements/commit/e521c2f1a44aa7f3e14f82a1cee05ceb484ed0a6))
13
+ * Updated pie-lib versions ([2fe4c5d](https://github.com/pie-framework/pie-elements/commit/2fe4c5d0be2d40f5fdb34815855695a7f1087f56))
14
+ * Updated pie-lib versions ([1c23830](https://github.com/pie-framework/pie-elements/commit/1c23830fc75d1de5f7bb3bb16de3c665ae5fa350))
15
+
16
+
17
+ ### Features
18
+
19
+ * **placement-ordering:** add baseline validation for authoring PD-600, PD-1334 ([2350279](https://github.com/pie-framework/pie-elements/commit/23502790000e3c4f14e4dae6744519b004eb1172))
20
+ * **placement-ordering:** add shuffle button to UI for authoring PD-1300 ([734fcda](https://github.com/pie-framework/pie-elements/commit/734fcda4b50b50cb54d66789b854f270818ba6fc))
21
+ * **placement-ordering:** added option to set toolbar editor position ([9b1b291](https://github.com/pie-framework/pie-elements/commit/9b1b2916f2c34297f3d4b239e393376f87be3826))
22
+ * **placement-ordering:** remove list buttons from choice labels PD-1337 ([1f1f927](https://github.com/pie-framework/pie-elements/commit/1f1f9276a29d84b551a3eaa93e15738ef1e22681))
23
+
24
+
25
+
26
+
27
+
6
28
  # [5.4.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-configure@5.3.2...@pie-element/placement-ordering-configure@5.4.0) (2021-08-05)
7
29
 
8
30
 
@@ -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,16 +39,45 @@ 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); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
45
59
 
46
60
  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; }
47
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
+ };
80
+
48
81
  function findFreeChoiceSlot(choices) {
49
82
  var slot = 1;
50
83
  var ids = choices.map(function (c) {
@@ -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,6 +196,11 @@ 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) {
@@ -140,51 +222,111 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
140
222
  var _this$props2 = _this.props,
141
223
  choices = _this$props2.choices,
142
224
  onChange = _this$props2.onChange,
143
- correctResponse = _this$props2.correctResponse;
144
- var updatedChoices = choices.filter(function (c) {
145
- return c.id !== choice.id;
146
- });
147
- var updatedCorrectResponse = correctResponse.filter(function (v) {
148
- return v.id !== choice.id;
149
- });
150
- 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
+ }
151
251
  };
152
252
 
153
253
  _this.addChoice = function () {
154
254
  var _this$props3 = _this.props,
155
255
  choices = _this$props3.choices,
156
256
  correctResponse = _this$props3.correctResponse,
157
- onChange = _this$props3.onChange;
158
- var freeId = findFreeChoiceSlot(choices);
159
- var id = "c".concat(freeId);
160
- var newChoice = {
161
- id: id,
162
- label: ''
163
- };
164
- var newCorrectResponse = {
165
- id: id,
166
-
167
- /**
168
- * Note: weights are not configurable in the existing component
169
- * so we'll want do disable this in the controller and ignore it for now.
170
- */
171
- weight: 0
172
- };
173
- var updatedChoices = choices.concat([newChoice]);
174
- var updatedCorrectResponse = correctResponse.concat([newCorrectResponse]);
175
- 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
+ }
176
294
  };
177
295
 
178
- _this.onDropChoice = function (ordering, target, source) {
296
+ _this.shuffleChoices = function () {
179
297
  var _this$props4 = _this.props,
180
298
  onChange = _this$props4.onChange,
181
- 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;
182
320
  var from = ordering.tiles.find(function (t) {
183
321
  return t.id === source.id && t.type === source.type;
184
322
  });
185
323
  var to = target;
186
324
  log('[onDropChoice] ', from, to);
187
- 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
+
188
330
  onChange(choices, response);
189
331
  };
190
332
 
@@ -202,7 +344,11 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
202
344
  choices = _this$props5.choices,
203
345
  imageSupport = _this$props5.imageSupport,
204
346
  disableImages = _this$props5.disableImages,
205
- toolbarOpts = _this$props5.toolbarOpts;
347
+ toolbarOpts = _this$props5.toolbarOpts,
348
+ singularChoiceLabel = _this$props5.singularChoiceLabel,
349
+ pluralChoiceLabel = _this$props5.pluralChoiceLabel,
350
+ choicesLabel = _this$props5.choicesLabel;
351
+ var dialog = this.state.dialog;
206
352
  var ordering = {
207
353
  choices: choices,
208
354
  response: !correctResponse || (0, _isEmpty["default"])(correctResponse) ? new Array(choices.length) : correctResponse,
@@ -229,11 +375,22 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
229
375
  return _this2.onDropChoice(ordering, c, source, index);
230
376
  },
231
377
  disableImages: disableImages,
232
- toolbarOpts: toolbarOpts
378
+ toolbarOpts: toolbarOpts,
379
+ choices: choices,
380
+ choicesLabel: choicesLabel
233
381
  });
234
382
  })), /*#__PURE__*/_react["default"].createElement("div", {
235
383
  className: classes.controls
236
384
  }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
385
+ onClick: this.shuffleChoices,
386
+ size: "small",
387
+ variant: "contained",
388
+ color: "default",
389
+ classes: {
390
+ root: classes.addButtonRoot,
391
+ label: classes.addButtonLabel
392
+ }
393
+ }, "SHUFFLE ".concat(pluralChoiceLabel).toUpperCase()), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
237
394
  onClick: this.addChoice,
238
395
  size: "small",
239
396
  variant: "contained",
@@ -242,7 +399,11 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
242
399
  root: classes.addButtonRoot,
243
400
  label: classes.addButtonLabel
244
401
  }
245
- }, "ADD CHOICE")));
402
+ }, "ADD ".concat(singularChoiceLabel).toUpperCase())), /*#__PURE__*/_react["default"].createElement(InfoDialog, {
403
+ title: dialog.message,
404
+ open: dialog.open,
405
+ onOk: dialog.onOk
406
+ }));
246
407
  }
247
408
  }]);
248
409
  return ChoiceEditor;
@@ -258,7 +419,11 @@ var ChoiceEditor = /*#__PURE__*/function (_React$Component) {
258
419
  "delete": _propTypes["default"].func.isRequired
259
420
  }),
260
421
  disableImages: _propTypes["default"].bool,
261
- toolbarOpts: _propTypes["default"].object
422
+ toolbarOpts: _propTypes["default"].object,
423
+ placementArea: _propTypes["default"].bool,
424
+ singularChoiceLabel: _propTypes["default"].string,
425
+ pluralChoiceLabel: _propTypes["default"].string,
426
+ choicesLabel: _propTypes["default"].string
262
427
  });
263
428
 
264
429
  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","toolbarOpts","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,IAAP,CAAY,UAAAF,EAAE;AAAA,aAAIA,EAAE,CAAChB,EAAH,K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MO,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;AAAA,SAAK;AACvBC,IAAAA,SAAS,EAAE,EADY;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,EAAmBjD,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 toolbarOpts: PropTypes.object\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 } = 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, toolbarOpts } = 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 toolbarOpts={toolbarOpts}\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);\n"],"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","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,sB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,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,EAAmB3D,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 } = 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 />\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"}