@pie-element/categorize 11.3.4-next.0 → 12.0.0-beta.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.
Files changed (63) hide show
  1. package/configure/lib/defaults.js +2 -5
  2. package/configure/lib/defaults.js.map +1 -1
  3. package/configure/lib/design/builder.js +15 -33
  4. package/configure/lib/design/builder.js.map +1 -1
  5. package/configure/lib/design/buttons.js +41 -95
  6. package/configure/lib/design/buttons.js.map +1 -1
  7. package/configure/lib/design/categories/RowLabel.js +32 -45
  8. package/configure/lib/design/categories/RowLabel.js.map +1 -1
  9. package/configure/lib/design/categories/alternateResponses.js +96 -251
  10. package/configure/lib/design/categories/alternateResponses.js.map +1 -1
  11. package/configure/lib/design/categories/category.js +135 -208
  12. package/configure/lib/design/categories/category.js.map +1 -1
  13. package/configure/lib/design/categories/choice-preview.js +61 -126
  14. package/configure/lib/design/categories/choice-preview.js.map +1 -1
  15. package/configure/lib/design/categories/droppable-placeholder.js +73 -165
  16. package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
  17. package/configure/lib/design/categories/index.js +195 -384
  18. package/configure/lib/design/categories/index.js.map +1 -1
  19. package/configure/lib/design/choices/choice.js +155 -264
  20. package/configure/lib/design/choices/choice.js.map +1 -1
  21. package/configure/lib/design/choices/config.js +42 -98
  22. package/configure/lib/design/choices/config.js.map +1 -1
  23. package/configure/lib/design/choices/index.js +148 -236
  24. package/configure/lib/design/choices/index.js.map +1 -1
  25. package/configure/lib/design/header.js +57 -111
  26. package/configure/lib/design/header.js.map +1 -1
  27. package/configure/lib/design/index.js +631 -476
  28. package/configure/lib/design/index.js.map +1 -1
  29. package/configure/lib/design/input-header.js +93 -149
  30. package/configure/lib/design/input-header.js.map +1 -1
  31. package/configure/lib/design/utils.js +4 -15
  32. package/configure/lib/design/utils.js.map +1 -1
  33. package/configure/lib/index.js +120 -183
  34. package/configure/lib/index.js.map +1 -1
  35. package/configure/lib/main.js +30 -74
  36. package/configure/lib/main.js.map +1 -1
  37. package/configure/lib/utils.js +22 -32
  38. package/configure/lib/utils.js.map +1 -1
  39. package/configure/package.json +15 -15
  40. package/controller/lib/defaults.js +2 -5
  41. package/controller/lib/defaults.js.map +1 -1
  42. package/controller/lib/index.js +237 -318
  43. package/controller/lib/index.js.map +1 -1
  44. package/controller/lib/utils.js +28 -65
  45. package/controller/lib/utils.js.map +1 -1
  46. package/controller/package.json +5 -5
  47. package/lib/categorize/categories.js +106 -164
  48. package/lib/categorize/categories.js.map +1 -1
  49. package/lib/categorize/category.js +73 -123
  50. package/lib/categorize/category.js.map +1 -1
  51. package/lib/categorize/choice.js +118 -245
  52. package/lib/categorize/choice.js.map +1 -1
  53. package/lib/categorize/choices.js +66 -131
  54. package/lib/categorize/choices.js.map +1 -1
  55. package/lib/categorize/droppable-placeholder.js +46 -103
  56. package/lib/categorize/droppable-placeholder.js.map +1 -1
  57. package/lib/categorize/grid-content.js +39 -87
  58. package/lib/categorize/grid-content.js.map +1 -1
  59. package/lib/categorize/index.js +341 -317
  60. package/lib/categorize/index.js.map +1 -1
  61. package/lib/index.js +285 -306
  62. package/lib/index.js.map +1 -1
  63. package/package.json +16 -14
@@ -1,445 +1,256 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports["default"] = exports.Categories = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
-
20
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
-
22
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
-
7
+ exports.default = exports.Categories = void 0;
24
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
9
  var _react = _interopRequireDefault(require("react"));
27
-
28
- var _reactDom = _interopRequireDefault(require("react-dom"));
29
-
30
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
31
-
32
- var _styles = require("@material-ui/core/styles");
33
-
11
+ var _styles = require("@mui/material/styles");
34
12
  var _configUi = require("@pie-lib/config-ui");
35
-
36
- var _classnames = _interopRequireDefault(require("classnames"));
37
-
38
- var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
39
-
40
- var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
41
-
13
+ var _Info = _interopRequireDefault(require("@mui/icons-material/Info"));
14
+ var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
42
15
  var _categorize = require("@pie-lib/categorize");
43
-
44
16
  var _category = _interopRequireDefault(require("./category"));
45
-
46
17
  var _header = _interopRequireDefault(require("../header"));
47
-
48
18
  var _utils = require("../../utils");
49
-
50
19
  var _RowLabel = require("./RowLabel");
51
-
52
- var _mathRendering = require("@pie-lib/math-rendering");
53
-
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); }; }
55
-
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; } }
57
-
58
- var styles = function styles(theme) {
59
- return {
60
- categories: {
61
- marginBottom: theme.spacing.unit * 3
62
- },
63
- categoriesHolder: {
64
- display: 'grid',
65
- gridRowGap: "".concat(theme.spacing.unit, "px"),
66
- gridColumnGap: "".concat(theme.spacing.unit, "px")
67
- },
68
- row: {
69
- display: 'grid',
70
- gridTemplateColumns: 'repeat(2, 1fr)',
71
- gridColumnGap: "".concat(theme.spacing.unit, "px"),
72
- alignItems: 'baseline',
73
- width: '100%',
74
- marginTop: theme.spacing.unit,
75
- marginBottom: 2 * theme.spacing.unit
76
- },
77
- rowLabel: {
78
- gridColumn: '1/3'
79
- },
80
- rowLabelHolder: {
81
- width: '100%'
82
- },
83
- tooltip: {
84
- fontSize: theme.typography.fontSize - 2,
85
- whiteSpace: 'pre',
86
- maxWidth: '500px'
87
- },
88
- errorText: {
89
- fontSize: theme.typography.fontSize - 2,
90
- color: theme.palette.error.main,
91
- paddingTop: theme.spacing.unit / 2
92
- }
93
- };
94
- };
95
-
96
- var Categories = /*#__PURE__*/function (_React$Component) {
97
- (0, _inherits2["default"])(Categories, _React$Component);
98
-
99
- var _super = _createSuper(Categories);
100
-
101
- function Categories() {
102
- var _this;
103
-
104
- (0, _classCallCheck2["default"])(this, Categories);
105
-
106
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
107
- args[_key] = arguments[_key];
108
- }
109
-
110
- _this = _super.call.apply(_super, [this].concat(args));
111
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
20
+ const CategoriesContainer = (0, _styles.styled)('div')(({
21
+ theme
22
+ }) => ({
23
+ marginBottom: theme.spacing(3)
24
+ }));
25
+ const CategoriesHolder = (0, _styles.styled)('div')(({
26
+ theme
27
+ }) => ({
28
+ display: 'grid',
29
+ gridRowGap: `${theme.spacing(1)}px`,
30
+ gridColumnGap: `${theme.spacing(1)}px`
31
+ }));
32
+ const StyledTooltip = (0, _styles.styled)(_Tooltip.default)(({
33
+ theme
34
+ }) => ({
35
+ '& .MuiTooltip-tooltip': {
36
+ fontSize: theme.typography.fontSize - 2,
37
+ whiteSpace: 'pre',
38
+ maxWidth: '500px'
39
+ }
40
+ }));
41
+ const ErrorText = (0, _styles.styled)('div')(({
42
+ theme
43
+ }) => ({
44
+ fontSize: theme.typography.fontSize - 2,
45
+ color: theme.palette.error.main,
46
+ paddingTop: theme.spacing(0.5)
47
+ }));
48
+ class Categories extends _react.default.Component {
49
+ constructor(...args) {
50
+ super(...args);
51
+ (0, _defineProperty2.default)(this, "state", {
112
52
  focusedEl: null
113
53
  });
114
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "add", function () {
115
- var _this$props = _this.props,
116
- model = _this$props.model,
117
- oldCategories = _this$props.categories;
118
- var categoriesPerRow = model.categoriesPerRow,
119
- correctResponse = model.correctResponse,
120
- allowAlternateEnabled = model.allowAlternateEnabled;
121
-
122
- var id = _configUi.choiceUtils.firstAvailableIndex(model.categories.map(function (a) {
123
- return a.id;
124
- }), 1);
125
-
126
- var data = {
127
- id: id,
54
+ (0, _defineProperty2.default)(this, "add", () => {
55
+ const {
56
+ model,
57
+ categories: oldCategories
58
+ } = this.props;
59
+ const {
60
+ categoriesPerRow,
61
+ correctResponse,
62
+ allowAlternateEnabled
63
+ } = model;
64
+ const id = _configUi.choiceUtils.firstAvailableIndex(model.categories.map(a => a.id), 1);
65
+ const data = {
66
+ id,
128
67
  label: 'Category ' + id
129
68
  };
130
- var addRowLabel = model.categories.length % categoriesPerRow === 0;
131
- var rowLabels = (0, _toConsumableArray2["default"])(model.rowLabels);
132
-
69
+ const addRowLabel = model.categories.length % categoriesPerRow === 0;
70
+ const rowLabels = [...model.rowLabels];
133
71
  if (addRowLabel) {
134
72
  rowLabels.push('');
135
73
  }
136
-
137
- _this.setState({
74
+ this.setState({
138
75
  focusedEl: oldCategories.length
139
- }, function () {
140
- _this.props.onModelChanged({
141
- rowLabels: rowLabels,
76
+ }, () => {
77
+ this.props.onModelChanged({
78
+ rowLabels,
142
79
  categories: model.categories.concat([data]),
143
- correctResponse: allowAlternateEnabled ? [].concat((0, _toConsumableArray2["default"])(correctResponse), [{
80
+ correctResponse: allowAlternateEnabled ? [...correctResponse, {
144
81
  category: id,
145
82
  choices: [],
146
83
  alternateResponses: []
147
- }]) : correctResponse
84
+ }] : correctResponse
148
85
  });
149
86
  });
150
87
  });
151
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteFocusedEl", function () {
152
- _this.setState({
88
+ (0, _defineProperty2.default)(this, "deleteFocusedEl", () => {
89
+ this.setState({
153
90
  focusedEl: null
154
91
  });
155
92
  });
156
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "delete", function (category) {
157
- var _this$props2 = _this.props,
158
- model = _this$props2.model,
159
- onModelChanged = _this$props2.onModelChanged;
160
- var index = model.categories.findIndex(function (a) {
161
- return a.id === category.id;
162
- });
163
-
93
+ (0, _defineProperty2.default)(this, "delete", category => {
94
+ const {
95
+ model,
96
+ onModelChanged
97
+ } = this.props;
98
+ const index = model.categories.findIndex(a => a.id === category.id);
164
99
  if (index !== -1) {
165
100
  model.categories.splice(index, 1);
166
101
  model.correctResponse = (0, _categorize.removeCategory)(category.id, model.correctResponse);
167
102
  onModelChanged(model);
168
103
  }
169
104
  });
170
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "change", function (c) {
171
- var categories = _this.props.categories;
172
- var index = categories.findIndex(function (a) {
173
- return a.id === c.id;
174
- });
175
-
105
+ (0, _defineProperty2.default)(this, "change", c => {
106
+ const {
107
+ categories
108
+ } = this.props;
109
+ const index = categories.findIndex(a => a.id === c.id);
176
110
  if (index !== -1) {
177
111
  categories.splice(index, 1, c);
178
-
179
- _this.props.onModelChanged({
180
- categories: categories
112
+ this.props.onModelChanged({
113
+ categories
181
114
  });
182
115
  }
183
116
  });
184
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addChoiceToCategory", function (addedChoice, categoryId) {
185
- var _this$props3 = _this.props,
186
- model = _this$props3.model,
187
- onModelChanged = _this$props3.onModelChanged;
188
-
189
- var _ref = model || {},
190
- _ref$choices = _ref.choices,
191
- choices = _ref$choices === void 0 ? [] : _ref$choices,
192
- _ref$correctResponse = _ref.correctResponse,
193
- correctResponse = _ref$correctResponse === void 0 ? [] : _ref$correctResponse,
194
- _ref$maxChoicesPerCat = _ref.maxChoicesPerCategory,
195
- maxChoicesPerCategory = _ref$maxChoicesPerCat === void 0 ? 0 : _ref$maxChoicesPerCat;
196
-
197
- var choice = (choices || []).find(function (choice) {
198
- return choice.id === addedChoice.id;
199
- });
200
- correctResponse = (0, _categorize.moveChoiceToCategory)(addedChoice.id, undefined, categoryId, 0, model.correctResponse); // if multiplePlacements not allowed, ensure the consistency in the other categories
201
-
202
- if (choice.categoryCount !== 0) {
203
- correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(addedChoice, categoryId, correctResponse);
204
- }
205
-
206
- var maxCategoryChoices = (0, _utils.getMaxCategoryChoices)(model); // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
207
-
208
- onModelChanged({
209
- correctResponse: correctResponse,
210
- maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
211
- });
212
- });
213
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoiceFromCategory", function (category, choice, choiceIndex) {
214
- var _this$props4 = _this.props,
215
- model = _this$props4.model,
216
- onModelChanged = _this$props4.onModelChanged;
217
- var correctResponse = (0, _categorize.removeChoiceFromCategory)(choice.id, category.id, choiceIndex, model.correctResponse);
218
- onModelChanged({
219
- correctResponse: correctResponse
220
- });
221
- });
222
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moveChoice", function (choiceId, from, to, choiceIndex) {
223
- var _this$props5 = _this.props,
224
- model = _this$props5.model,
225
- onModelChanged = _this$props5.onModelChanged;
226
-
227
- var _ref2 = model || {},
228
- choices = _ref2.choices,
229
- _ref2$correctResponse = _ref2.correctResponse,
230
- correctResponse = _ref2$correctResponse === void 0 ? [] : _ref2$correctResponse,
231
- _ref2$maxChoicesPerCa = _ref2.maxChoicesPerCategory,
232
- maxChoicesPerCategory = _ref2$maxChoicesPerCa === void 0 ? 0 : _ref2$maxChoicesPerCa;
233
-
234
- var choice = (choices || []).find(function (choice) {
235
- return choice.id === choiceId;
236
- });
237
-
238
- if (to === from || !choice) {
239
- return;
240
- }
241
-
242
- if (choice.categoryCount !== 0) {
243
- correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, from, to, choiceIndex, correctResponse);
244
- correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(choice, to, correctResponse);
245
- } else if (choice.categoryCount === 0) {
246
- correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, to, 0, correctResponse);
247
- }
248
-
249
- var maxCategoryChoices = (0, _utils.getMaxCategoryChoices)(model); // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
250
-
117
+ (0, _defineProperty2.default)(this, "deleteChoiceFromCategory", (category, choice, choiceIndex) => {
118
+ const {
119
+ model,
120
+ onModelChanged
121
+ } = this.props;
122
+ const correctResponse = (0, _categorize.removeChoiceFromCategory)(choice.id, category.id, choiceIndex, model.correctResponse);
251
123
  onModelChanged({
252
- correctResponse: correctResponse,
253
- maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
124
+ correctResponse
254
125
  });
255
126
  });
256
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeRowLabel", function (val, index) {
257
- var model = _this.props.model;
258
- var rowLabels = model.rowLabels;
259
- var newRowLabels = (0, _toConsumableArray2["default"])(rowLabels);
260
-
127
+ (0, _defineProperty2.default)(this, "changeRowLabel", (val, index) => {
128
+ const {
129
+ model
130
+ } = this.props;
131
+ const {
132
+ rowLabels
133
+ } = model;
134
+ const newRowLabels = [...rowLabels];
261
135
  if (newRowLabels.length < index) {
262
136
  newRowLabels.push(val);
263
137
  } else {
264
138
  newRowLabels[index] = val;
265
139
  }
266
-
267
- _this.props.onModelChanged({
140
+ this.props.onModelChanged({
268
141
  rowLabels: newRowLabels
269
142
  });
270
143
  });
271
- return _this;
272
144
  }
273
-
274
- (0, _createClass2["default"])(Categories, [{
275
- key: "componentDidMount",
276
- value: function componentDidMount() {
277
- try {
278
- // eslint-disable-next-line react/no-find-dom-node
279
- var domNode = _reactDom["default"].findDOMNode(this);
280
-
281
- (0, _mathRendering.renderMath)(domNode);
282
- } catch (e) {
283
- // Added try-catch block to handle "Unable to find node on an unmounted component" error from tests, thrown because of the usage of shallow
284
- console.error('DOM not mounted');
285
- }
286
- }
287
- }, {
288
- key: "componentDidUpdate",
289
- value: function componentDidUpdate() {
290
- try {
291
- // eslint-disable-next-line react/no-find-dom-node
292
- var domNode = _reactDom["default"].findDOMNode(this);
293
-
294
- (0, _mathRendering.renderMath)(domNode);
295
- } catch (e) {
296
- // Added try-catch block to handle "Unable to find node on an unmounted component" error from tests, thrown because of the usage of shallow
297
- console.error('DOM not mounted');
298
- }
299
- }
300
- }, {
301
- key: "render",
302
- value: function render() {
303
- var _this2 = this;
304
-
305
- var _this$props6 = this.props,
306
- model = _this$props6.model,
307
- classes = _this$props6.classes,
308
- className = _this$props6.className,
309
- categories = _this$props6.categories,
310
- imageSupport = _this$props6.imageSupport,
311
- uploadSoundSupport = _this$props6.uploadSoundSupport,
312
- toolbarOpts = _this$props6.toolbarOpts,
313
- spellCheck = _this$props6.spellCheck,
314
- configuration = _this$props6.configuration,
315
- defaultImageMaxHeight = _this$props6.defaultImageMaxHeight,
316
- defaultImageMaxWidth = _this$props6.defaultImageMaxWidth,
317
- _this$props6$mathMlOp = _this$props6.mathMlOptions,
318
- mathMlOptions = _this$props6$mathMlOp === void 0 ? {} : _this$props6$mathMlOp;
319
- var categoriesPerRow = model.categoriesPerRow,
320
- rowLabels = model.rowLabels,
321
- errors = model.errors;
322
-
323
- var _ref3 = errors || {},
324
- associationError = _ref3.associationError,
325
- categoriesError = _ref3.categoriesError,
326
- categoriesErrors = _ref3.categoriesErrors;
327
-
328
- var _ref4 = configuration || {},
329
- maxCategories = _ref4.maxCategories,
330
- _ref4$maxImageWidth = _ref4.maxImageWidth,
331
- maxImageWidth = _ref4$maxImageWidth === void 0 ? {} : _ref4$maxImageWidth,
332
- _ref4$maxImageHeight = _ref4.maxImageHeight,
333
- maxImageHeight = _ref4$maxImageHeight === void 0 ? {} : _ref4$maxImageHeight;
334
-
335
- var holderStyle = {
336
- gridTemplateColumns: "repeat(".concat(categoriesPerRow, ", 1fr)")
337
- };
338
- var validationMessage = (0, _utils.generateValidationMessage)(configuration);
339
- return /*#__PURE__*/_react["default"].createElement("div", {
340
- className: (0, _classnames["default"])(classes.categories, className)
341
- }, /*#__PURE__*/_react["default"].createElement(_header["default"], {
342
- label: "Categories",
343
- buttonLabel: "ADD A CATEGORY",
344
- onAdd: this.add,
345
- info: /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
346
- classes: {
347
- tooltip: classes.tooltip
348
- },
349
- disableFocusListener: true,
350
- disableTouchListener: true,
351
- placement: 'right',
352
- title: validationMessage
353
- }, /*#__PURE__*/_react["default"].createElement(_Info["default"], {
354
- fontSize: 'small',
355
- color: 'primary',
356
- style: {
357
- marginLeft: '5px'
358
- }
359
- })),
360
- buttonDisabled: maxCategories && categories && maxCategories === categories.length
361
- }), /*#__PURE__*/_react["default"].createElement("div", {
362
- className: classes.categoriesHolder,
363
- style: holderStyle
364
- }, categories.map(function (category, index) {
365
- var hasRowLabel = index % categoriesPerRow === 0;
366
- var rowIndex = index / categoriesPerRow;
367
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
368
- key: index
369
- }, hasRowLabel && /*#__PURE__*/_react["default"].createElement(_RowLabel.RowLabel, {
370
- categoriesPerRow: categoriesPerRow,
371
- disabled: false,
372
- rowIndex: rowIndex,
373
- markup: rowLabels[rowIndex] || '',
374
- onChange: function onChange(val) {
375
- return _this2.changeRowLabel(val, rowIndex);
376
- },
377
- imageSupport: imageSupport,
378
- toolbarOpts: toolbarOpts,
379
- spellCheck: spellCheck,
380
- maxImageWidth: maxImageWidth && maxImageWidth.rowLabel || defaultImageMaxWidth,
381
- maxImageHeight: maxImageHeight && maxImageHeight.rowLabel || defaultImageMaxHeight,
382
- uploadSoundSupport: uploadSoundSupport,
383
- mathMlOptions: mathMlOptions,
384
- configuration: configuration
385
- }), /*#__PURE__*/_react["default"].createElement(_category["default"], {
386
- imageSupport: imageSupport,
387
- focusedEl: _this2.state.focusedEl,
388
- deleteFocusedEl: _this2.deleteFocusedEl,
389
- index: index,
390
- category: category,
391
- error: categoriesErrors && categoriesErrors[category.id],
392
- onChange: _this2.change,
393
- onDelete: function onDelete() {
394
- return _this2["delete"](category);
395
- },
396
- onAddChoice: _this2.addChoiceToCategory,
397
- onMoveChoice: function onMoveChoice(choiceId, from, to, choiceIndex) {
398
- return _this2.moveChoice(choiceId, from, to, choiceIndex);
399
- },
400
- toolbarOpts: toolbarOpts,
401
- spellCheck: spellCheck,
402
- onDeleteChoice: function onDeleteChoice(choice, choiceIndex) {
403
- return _this2.deleteChoiceFromCategory(category, choice, choiceIndex);
404
- },
405
- maxImageWidth: maxImageWidth && maxImageWidth.categoryLabel || defaultImageMaxWidth,
406
- maxImageHeight: maxImageHeight && maxImageHeight.categoryLabel || defaultImageMaxHeight,
407
- uploadSoundSupport: uploadSoundSupport,
408
- configuration: configuration
409
- }));
410
- })), associationError && /*#__PURE__*/_react["default"].createElement("div", {
411
- className: classes.errorText
412
- }, associationError), categoriesError && /*#__PURE__*/_react["default"].createElement("div", {
413
- className: classes.errorText
414
- }, categoriesError));
415
- }
416
- }]);
417
- return Categories;
418
- }(_react["default"].Component);
419
-
145
+ render() {
146
+ const {
147
+ model,
148
+ categories,
149
+ imageSupport,
150
+ uploadSoundSupport,
151
+ toolbarOpts,
152
+ spellCheck,
153
+ configuration,
154
+ defaultImageMaxHeight,
155
+ defaultImageMaxWidth,
156
+ mathMlOptions = {}
157
+ } = this.props;
158
+ const {
159
+ categoriesPerRow,
160
+ rowLabels,
161
+ errors
162
+ } = model;
163
+ const {
164
+ associationError,
165
+ categoriesError,
166
+ categoriesErrors
167
+ } = errors || {};
168
+ const {
169
+ maxCategories,
170
+ maxImageWidth = {},
171
+ maxImageHeight = {}
172
+ } = configuration || {};
173
+ const holderStyle = {
174
+ gridTemplateColumns: `repeat(${categoriesPerRow}, 1fr)`
175
+ };
176
+ const validationMessage = (0, _utils.generateValidationMessage)(configuration);
177
+ return /*#__PURE__*/_react.default.createElement(CategoriesContainer, null, /*#__PURE__*/_react.default.createElement(_header.default, {
178
+ label: "Categories",
179
+ buttonLabel: "ADD A CATEGORY",
180
+ onAdd: this.add,
181
+ info: /*#__PURE__*/_react.default.createElement(StyledTooltip, {
182
+ disableFocusListener: true,
183
+ disableTouchListener: true,
184
+ placement: 'right',
185
+ title: validationMessage
186
+ }, /*#__PURE__*/_react.default.createElement(_Info.default, {
187
+ fontSize: 'small',
188
+ color: 'primary',
189
+ style: {
190
+ marginLeft: '5px'
191
+ }
192
+ })),
193
+ buttonDisabled: maxCategories && categories && maxCategories === categories.length
194
+ }), /*#__PURE__*/_react.default.createElement(CategoriesHolder, {
195
+ style: holderStyle
196
+ }, categories.map((category, index) => {
197
+ const hasRowLabel = index % categoriesPerRow === 0;
198
+ const rowIndex = index / categoriesPerRow;
199
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
200
+ key: index
201
+ }, hasRowLabel && /*#__PURE__*/_react.default.createElement(_RowLabel.RowLabel, {
202
+ categoriesPerRow: categoriesPerRow,
203
+ disabled: false,
204
+ rowIndex: rowIndex,
205
+ markup: rowLabels[rowIndex] || '',
206
+ onChange: val => this.changeRowLabel(val, rowIndex),
207
+ imageSupport: imageSupport,
208
+ toolbarOpts: toolbarOpts,
209
+ spellCheck: spellCheck,
210
+ maxImageWidth: maxImageWidth && maxImageWidth.rowLabel || defaultImageMaxWidth,
211
+ maxImageHeight: maxImageHeight && maxImageHeight.rowLabel || defaultImageMaxHeight,
212
+ uploadSoundSupport: uploadSoundSupport,
213
+ mathMlOptions: mathMlOptions,
214
+ configuration: configuration
215
+ }), /*#__PURE__*/_react.default.createElement(_category.default, {
216
+ imageSupport: imageSupport,
217
+ focusedEl: this.state.focusedEl,
218
+ deleteFocusedEl: this.deleteFocusedEl,
219
+ index: index,
220
+ category: category,
221
+ error: categoriesErrors && categoriesErrors[category.id],
222
+ onChange: this.change,
223
+ onDelete: () => this.delete(category),
224
+ toolbarOpts: toolbarOpts,
225
+ spellCheck: spellCheck,
226
+ onDeleteChoice: (choice, choiceIndex) => this.deleteChoiceFromCategory(category, choice, choiceIndex),
227
+ maxImageWidth: maxImageWidth && maxImageWidth.categoryLabel || defaultImageMaxWidth,
228
+ maxImageHeight: maxImageHeight && maxImageHeight.categoryLabel || defaultImageMaxHeight,
229
+ uploadSoundSupport: uploadSoundSupport,
230
+ configuration: configuration,
231
+ alternateResponseIndex: undefined
232
+ }));
233
+ })), associationError && /*#__PURE__*/_react.default.createElement(ErrorText, null, associationError), categoriesError && /*#__PURE__*/_react.default.createElement(ErrorText, null, categoriesError));
234
+ }
235
+ }
420
236
  exports.Categories = Categories;
421
- (0, _defineProperty2["default"])(Categories, "propTypes", {
422
- defaultImageMaxHeight: _propTypes["default"].number,
423
- defaultImageMaxWidth: _propTypes["default"].number,
424
- imageSupport: _propTypes["default"].shape({
425
- add: _propTypes["default"].func.isRequired,
426
- "delete": _propTypes["default"].func.isRequired
237
+ (0, _defineProperty2.default)(Categories, "propTypes", {
238
+ defaultImageMaxHeight: _propTypes.default.number,
239
+ defaultImageMaxWidth: _propTypes.default.number,
240
+ imageSupport: _propTypes.default.shape({
241
+ add: _propTypes.default.func.isRequired,
242
+ delete: _propTypes.default.func.isRequired
427
243
  }),
428
- uploadSoundSupport: _propTypes["default"].shape({
429
- add: _propTypes["default"].func.isRequired,
430
- "delete": _propTypes["default"].func.isRequired
244
+ uploadSoundSupport: _propTypes.default.shape({
245
+ add: _propTypes.default.func.isRequired,
246
+ delete: _propTypes.default.func.isRequired
431
247
  }),
432
- classes: _propTypes["default"].object.isRequired,
433
- className: _propTypes["default"].string,
434
- categories: _propTypes["default"].array,
435
- onModelChanged: _propTypes["default"].func,
436
- model: _propTypes["default"].object.isRequired,
437
- configuration: _propTypes["default"].object.isRequired,
438
- toolbarOpts: _propTypes["default"].object,
439
- spellCheck: _propTypes["default"].bool
248
+ categories: _propTypes.default.array,
249
+ onModelChanged: _propTypes.default.func,
250
+ model: _propTypes.default.object.isRequired,
251
+ configuration: _propTypes.default.object.isRequired,
252
+ toolbarOpts: _propTypes.default.object,
253
+ spellCheck: _propTypes.default.bool
440
254
  });
441
-
442
- var _default = (0, _styles.withStyles)(styles)(Categories);
443
-
444
- exports["default"] = _default;
255
+ var _default = exports.default = Categories;
445
256
  //# sourceMappingURL=index.js.map