@pie-element/categorize 8.15.1-next.1 → 8.15.1-next.10
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/configure/lib/defaults.js +207 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/design/builder.js +74 -0
- package/configure/lib/design/builder.js.map +1 -0
- package/configure/lib/design/buttons.js +127 -0
- package/configure/lib/design/buttons.js.map +1 -0
- package/configure/lib/design/categories/RowLabel.js +78 -0
- package/configure/lib/design/categories/RowLabel.js.map +1 -0
- package/configure/lib/design/categories/alternateResponses.js +293 -0
- package/configure/lib/design/categories/alternateResponses.js.map +1 -0
- package/configure/lib/design/categories/category.js +219 -0
- package/configure/lib/design/categories/category.js.map +1 -0
- package/configure/lib/design/categories/choice-preview.js +136 -0
- package/configure/lib/design/categories/choice-preview.js.map +1 -0
- package/configure/lib/design/categories/droppable-placeholder.js +187 -0
- package/configure/lib/design/categories/droppable-placeholder.js.map +1 -0
- package/configure/lib/design/categories/index.js +408 -0
- package/configure/lib/design/categories/index.js.map +1 -0
- package/configure/lib/design/choices/choice.js +297 -0
- package/configure/lib/design/choices/choice.js.map +1 -0
- package/configure/lib/design/choices/config.js +114 -0
- package/configure/lib/design/choices/config.js.map +1 -0
- package/configure/lib/design/choices/index.js +276 -0
- package/configure/lib/design/choices/index.js.map +1 -0
- package/configure/lib/design/header.js +107 -0
- package/configure/lib/design/header.js.map +1 -0
- package/configure/lib/design/index.js +538 -0
- package/configure/lib/design/index.js.map +1 -0
- package/configure/lib/design/input-header.js +166 -0
- package/configure/lib/design/input-header.js.map +1 -0
- package/configure/lib/design/utils.js +23 -0
- package/configure/lib/design/utils.js.map +1 -0
- package/configure/lib/index.js +196 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/main.js +88 -0
- package/configure/lib/main.js.map +1 -0
- package/configure/lib/utils.js +40 -0
- package/configure/lib/utils.js.map +1 -0
- package/controller/lib/defaults.js +31 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +484 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +60 -0
- package/controller/lib/utils.js.map +1 -0
- package/lib/categorize/categories.js +193 -0
- package/lib/categorize/categories.js.map +1 -0
- package/lib/categorize/category.js +135 -0
- package/lib/categorize/category.js.map +1 -0
- package/lib/categorize/choice.js +228 -0
- package/lib/categorize/choice.js.map +1 -0
- package/lib/categorize/choices.js +162 -0
- package/lib/categorize/choices.js.map +1 -0
- package/lib/categorize/droppable-placeholder.js +111 -0
- package/lib/categorize/droppable-placeholder.js.map +1 -0
- package/lib/categorize/grid-content.js +103 -0
- package/lib/categorize/grid-content.js.map +1 -0
- package/lib/categorize/index.js +368 -0
- package/lib/categorize/index.js.map +1 -0
- package/lib/index.js +137 -0
- package/lib/index.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = 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
|
+
|
|
24
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
+
|
|
26
|
+
var _react = _interopRequireDefault(require("react"));
|
|
27
|
+
|
|
28
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
29
|
+
|
|
30
|
+
var _styles = require("@material-ui/core/styles");
|
|
31
|
+
|
|
32
|
+
var _configUi = require("@pie-lib/pie-toolbox/config-ui");
|
|
33
|
+
|
|
34
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
35
|
+
|
|
36
|
+
var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
|
|
37
|
+
|
|
38
|
+
var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
|
|
39
|
+
|
|
40
|
+
var _categorize = require("@pie-lib/pie-toolbox/categorize");
|
|
41
|
+
|
|
42
|
+
var _category = _interopRequireDefault(require("./category"));
|
|
43
|
+
|
|
44
|
+
var _header = _interopRequireDefault(require("../header"));
|
|
45
|
+
|
|
46
|
+
var _utils = require("../../utils");
|
|
47
|
+
|
|
48
|
+
var _RowLabel = require("./RowLabel");
|
|
49
|
+
|
|
50
|
+
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); }; }
|
|
51
|
+
|
|
52
|
+
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; } }
|
|
53
|
+
|
|
54
|
+
var styles = function styles(theme) {
|
|
55
|
+
return {
|
|
56
|
+
categories: {
|
|
57
|
+
marginBottom: theme.spacing.unit * 3
|
|
58
|
+
},
|
|
59
|
+
categoriesHolder: {
|
|
60
|
+
display: 'grid',
|
|
61
|
+
gridRowGap: "".concat(theme.spacing.unit, "px"),
|
|
62
|
+
gridColumnGap: "".concat(theme.spacing.unit, "px")
|
|
63
|
+
},
|
|
64
|
+
row: {
|
|
65
|
+
display: 'grid',
|
|
66
|
+
gridTemplateColumns: 'repeat(2, 1fr)',
|
|
67
|
+
gridColumnGap: "".concat(theme.spacing.unit, "px"),
|
|
68
|
+
alignItems: 'baseline',
|
|
69
|
+
width: '100%',
|
|
70
|
+
marginTop: theme.spacing.unit,
|
|
71
|
+
marginBottom: 2 * theme.spacing.unit
|
|
72
|
+
},
|
|
73
|
+
rowLabel: {
|
|
74
|
+
gridColumn: '1/3'
|
|
75
|
+
},
|
|
76
|
+
rowLabelHolder: {
|
|
77
|
+
width: '100%'
|
|
78
|
+
},
|
|
79
|
+
tooltip: {
|
|
80
|
+
fontSize: theme.typography.fontSize - 2,
|
|
81
|
+
whiteSpace: 'pre',
|
|
82
|
+
maxWidth: '500px'
|
|
83
|
+
},
|
|
84
|
+
errorText: {
|
|
85
|
+
fontSize: theme.typography.fontSize - 2,
|
|
86
|
+
color: theme.palette.error.main,
|
|
87
|
+
paddingTop: theme.spacing.unit / 2
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var Categories = /*#__PURE__*/function (_React$Component) {
|
|
93
|
+
(0, _inherits2["default"])(Categories, _React$Component);
|
|
94
|
+
|
|
95
|
+
var _super = _createSuper(Categories);
|
|
96
|
+
|
|
97
|
+
function Categories() {
|
|
98
|
+
var _this;
|
|
99
|
+
|
|
100
|
+
(0, _classCallCheck2["default"])(this, Categories);
|
|
101
|
+
|
|
102
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
103
|
+
args[_key] = arguments[_key];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
107
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
|
|
108
|
+
focusedEl: null
|
|
109
|
+
});
|
|
110
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "add", function () {
|
|
111
|
+
var _this$props = _this.props,
|
|
112
|
+
model = _this$props.model,
|
|
113
|
+
oldCategories = _this$props.categories;
|
|
114
|
+
var categoriesPerRow = model.categoriesPerRow;
|
|
115
|
+
|
|
116
|
+
var id = _configUi.choiceUtils.firstAvailableIndex(model.categories.map(function (a) {
|
|
117
|
+
return a.id;
|
|
118
|
+
}), 0);
|
|
119
|
+
|
|
120
|
+
var data = {
|
|
121
|
+
id: id,
|
|
122
|
+
label: 'Category ' + id
|
|
123
|
+
};
|
|
124
|
+
var addRowLabel = model.categories.length % categoriesPerRow === 0;
|
|
125
|
+
var rowLabels = (0, _toConsumableArray2["default"])(model.rowLabels);
|
|
126
|
+
|
|
127
|
+
if (addRowLabel) {
|
|
128
|
+
rowLabels.push('');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_this.setState({
|
|
132
|
+
focusedEl: oldCategories.length
|
|
133
|
+
}, function () {
|
|
134
|
+
_this.props.onModelChanged({
|
|
135
|
+
rowLabels: rowLabels,
|
|
136
|
+
categories: model.categories.concat([data])
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteFocusedEl", function () {
|
|
141
|
+
_this.setState({
|
|
142
|
+
focusedEl: null
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "delete", function (category) {
|
|
146
|
+
var _this$props2 = _this.props,
|
|
147
|
+
model = _this$props2.model,
|
|
148
|
+
onModelChanged = _this$props2.onModelChanged;
|
|
149
|
+
var index = model.categories.findIndex(function (a) {
|
|
150
|
+
return a.id === category.id;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (index !== -1) {
|
|
154
|
+
model.categories.splice(index, 1);
|
|
155
|
+
model.correctResponse = (0, _categorize.removeCategory)(category.id, model.correctResponse);
|
|
156
|
+
onModelChanged(model);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "change", function (c) {
|
|
160
|
+
var categories = _this.props.categories;
|
|
161
|
+
var index = categories.findIndex(function (a) {
|
|
162
|
+
return a.id === c.id;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (index !== -1) {
|
|
166
|
+
categories.splice(index, 1, c);
|
|
167
|
+
|
|
168
|
+
_this.props.onModelChanged({
|
|
169
|
+
categories: categories
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addChoiceToCategory", function (addedChoice, categoryId) {
|
|
174
|
+
var _this$props3 = _this.props,
|
|
175
|
+
model = _this$props3.model,
|
|
176
|
+
onModelChanged = _this$props3.onModelChanged;
|
|
177
|
+
|
|
178
|
+
var _ref = model || {},
|
|
179
|
+
_ref$choices = _ref.choices,
|
|
180
|
+
choices = _ref$choices === void 0 ? [] : _ref$choices,
|
|
181
|
+
_ref$correctResponse = _ref.correctResponse,
|
|
182
|
+
correctResponse = _ref$correctResponse === void 0 ? [] : _ref$correctResponse,
|
|
183
|
+
_ref$maxChoicesPerCat = _ref.maxChoicesPerCategory,
|
|
184
|
+
maxChoicesPerCategory = _ref$maxChoicesPerCat === void 0 ? 0 : _ref$maxChoicesPerCat;
|
|
185
|
+
|
|
186
|
+
var choice = (choices || []).find(function (choice) {
|
|
187
|
+
return choice.id === addedChoice.id;
|
|
188
|
+
});
|
|
189
|
+
correctResponse = (0, _categorize.moveChoiceToCategory)(addedChoice.id, undefined, categoryId, 0, model.correctResponse); // if multiplePlacements not allowed, ensure the consistency in the other categories
|
|
190
|
+
|
|
191
|
+
if (choice.categoryCount !== 0) {
|
|
192
|
+
correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(addedChoice, categoryId, correctResponse);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
var maxCategoryChoices = (0, _utils.getMaxCategoryChoices)(model); // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
|
|
196
|
+
|
|
197
|
+
onModelChanged({
|
|
198
|
+
correctResponse: correctResponse,
|
|
199
|
+
maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoiceFromCategory", function (category, choice, choiceIndex) {
|
|
203
|
+
var _this$props4 = _this.props,
|
|
204
|
+
model = _this$props4.model,
|
|
205
|
+
onModelChanged = _this$props4.onModelChanged;
|
|
206
|
+
var correctResponse = (0, _categorize.removeChoiceFromCategory)(choice.id, category.id, choiceIndex, model.correctResponse);
|
|
207
|
+
onModelChanged({
|
|
208
|
+
correctResponse: correctResponse
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moveChoice", function (choiceId, from, to, choiceIndex) {
|
|
212
|
+
var _this$props5 = _this.props,
|
|
213
|
+
model = _this$props5.model,
|
|
214
|
+
onModelChanged = _this$props5.onModelChanged;
|
|
215
|
+
|
|
216
|
+
var _ref2 = model || {},
|
|
217
|
+
choices = _ref2.choices,
|
|
218
|
+
_ref2$correctResponse = _ref2.correctResponse,
|
|
219
|
+
correctResponse = _ref2$correctResponse === void 0 ? [] : _ref2$correctResponse,
|
|
220
|
+
_ref2$maxChoicesPerCa = _ref2.maxChoicesPerCategory,
|
|
221
|
+
maxChoicesPerCategory = _ref2$maxChoicesPerCa === void 0 ? 0 : _ref2$maxChoicesPerCa;
|
|
222
|
+
|
|
223
|
+
var choice = (choices || []).find(function (choice) {
|
|
224
|
+
return choice.id === choiceId;
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (to === from || !choice) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (choice.categoryCount !== 0) {
|
|
232
|
+
correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, from, to, choiceIndex, correctResponse);
|
|
233
|
+
correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(choice, to, correctResponse);
|
|
234
|
+
} else if (choice.categoryCount === 0) {
|
|
235
|
+
correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, to, 0, correctResponse);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
var maxCategoryChoices = (0, _utils.getMaxCategoryChoices)(model); // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
|
|
239
|
+
|
|
240
|
+
onModelChanged({
|
|
241
|
+
correctResponse: correctResponse,
|
|
242
|
+
maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeRowLabel", function (val, index) {
|
|
246
|
+
var model = _this.props.model;
|
|
247
|
+
var rowLabels = model.rowLabels;
|
|
248
|
+
var newRowLabels = (0, _toConsumableArray2["default"])(rowLabels);
|
|
249
|
+
|
|
250
|
+
if (newRowLabels.length < index) {
|
|
251
|
+
newRowLabels.push(val);
|
|
252
|
+
} else {
|
|
253
|
+
newRowLabels[index] = val;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
_this.props.onModelChanged({
|
|
257
|
+
rowLabels: newRowLabels
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
return _this;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
(0, _createClass2["default"])(Categories, [{
|
|
264
|
+
key: "render",
|
|
265
|
+
value: function render() {
|
|
266
|
+
var _this2 = this;
|
|
267
|
+
|
|
268
|
+
var _this$props6 = this.props,
|
|
269
|
+
model = _this$props6.model,
|
|
270
|
+
classes = _this$props6.classes,
|
|
271
|
+
className = _this$props6.className,
|
|
272
|
+
categories = _this$props6.categories,
|
|
273
|
+
imageSupport = _this$props6.imageSupport,
|
|
274
|
+
uploadSoundSupport = _this$props6.uploadSoundSupport,
|
|
275
|
+
toolbarOpts = _this$props6.toolbarOpts,
|
|
276
|
+
spellCheck = _this$props6.spellCheck,
|
|
277
|
+
configuration = _this$props6.configuration,
|
|
278
|
+
defaultImageMaxHeight = _this$props6.defaultImageMaxHeight,
|
|
279
|
+
defaultImageMaxWidth = _this$props6.defaultImageMaxWidth,
|
|
280
|
+
_this$props6$mathMlOp = _this$props6.mathMlOptions,
|
|
281
|
+
mathMlOptions = _this$props6$mathMlOp === void 0 ? {} : _this$props6$mathMlOp;
|
|
282
|
+
var categoriesPerRow = model.categoriesPerRow,
|
|
283
|
+
rowLabels = model.rowLabels,
|
|
284
|
+
errors = model.errors;
|
|
285
|
+
|
|
286
|
+
var _ref3 = errors || {},
|
|
287
|
+
associationError = _ref3.associationError,
|
|
288
|
+
categoriesError = _ref3.categoriesError,
|
|
289
|
+
categoriesErrors = _ref3.categoriesErrors;
|
|
290
|
+
|
|
291
|
+
var _ref4 = configuration || {},
|
|
292
|
+
maxCategories = _ref4.maxCategories,
|
|
293
|
+
_ref4$maxImageWidth = _ref4.maxImageWidth,
|
|
294
|
+
maxImageWidth = _ref4$maxImageWidth === void 0 ? {} : _ref4$maxImageWidth,
|
|
295
|
+
_ref4$maxImageHeight = _ref4.maxImageHeight,
|
|
296
|
+
maxImageHeight = _ref4$maxImageHeight === void 0 ? {} : _ref4$maxImageHeight;
|
|
297
|
+
|
|
298
|
+
var holderStyle = {
|
|
299
|
+
gridTemplateColumns: "repeat(".concat(categoriesPerRow, ", 1fr)")
|
|
300
|
+
};
|
|
301
|
+
var validationMessage = (0, _utils.generateValidationMessage)(configuration);
|
|
302
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
303
|
+
className: (0, _classnames["default"])(classes.categories, className)
|
|
304
|
+
}, /*#__PURE__*/_react["default"].createElement(_header["default"], {
|
|
305
|
+
label: "Categories",
|
|
306
|
+
buttonLabel: "ADD A CATEGORY",
|
|
307
|
+
onAdd: this.add,
|
|
308
|
+
info: /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
|
|
309
|
+
classes: {
|
|
310
|
+
tooltip: classes.tooltip
|
|
311
|
+
},
|
|
312
|
+
disableFocusListener: true,
|
|
313
|
+
disableTouchListener: true,
|
|
314
|
+
placement: 'right',
|
|
315
|
+
title: validationMessage
|
|
316
|
+
}, /*#__PURE__*/_react["default"].createElement(_Info["default"], {
|
|
317
|
+
fontSize: 'small',
|
|
318
|
+
color: 'primary',
|
|
319
|
+
style: {
|
|
320
|
+
marginLeft: '5px'
|
|
321
|
+
}
|
|
322
|
+
})),
|
|
323
|
+
buttonDisabled: maxCategories && categories && maxCategories === categories.length
|
|
324
|
+
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
325
|
+
className: classes.categoriesHolder,
|
|
326
|
+
style: holderStyle
|
|
327
|
+
}, categories.map(function (category, index) {
|
|
328
|
+
var hasRowLabel = index % categoriesPerRow === 0;
|
|
329
|
+
var rowIndex = index / categoriesPerRow;
|
|
330
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
|
|
331
|
+
key: index
|
|
332
|
+
}, hasRowLabel && /*#__PURE__*/_react["default"].createElement(_RowLabel.RowLabel, {
|
|
333
|
+
categoriesPerRow: categoriesPerRow,
|
|
334
|
+
disabled: false,
|
|
335
|
+
rowIndex: rowIndex,
|
|
336
|
+
markup: rowLabels[rowIndex] || '',
|
|
337
|
+
onChange: function onChange(val) {
|
|
338
|
+
return _this2.changeRowLabel(val, rowIndex);
|
|
339
|
+
},
|
|
340
|
+
imageSupport: imageSupport,
|
|
341
|
+
toolbarOpts: toolbarOpts,
|
|
342
|
+
spellCheck: spellCheck,
|
|
343
|
+
maxImageWidth: maxImageWidth && maxImageWidth.rowLabel || defaultImageMaxWidth,
|
|
344
|
+
maxImageHeight: maxImageHeight && maxImageHeight.rowLabel || defaultImageMaxHeight,
|
|
345
|
+
uploadSoundSupport: uploadSoundSupport,
|
|
346
|
+
mathMlOptions: mathMlOptions,
|
|
347
|
+
configuration: configuration
|
|
348
|
+
}), /*#__PURE__*/_react["default"].createElement(_category["default"], {
|
|
349
|
+
imageSupport: imageSupport,
|
|
350
|
+
focusedEl: _this2.state.focusedEl,
|
|
351
|
+
deleteFocusedEl: _this2.deleteFocusedEl,
|
|
352
|
+
index: index,
|
|
353
|
+
category: category,
|
|
354
|
+
error: categoriesErrors && categoriesErrors[category.id],
|
|
355
|
+
onChange: _this2.change,
|
|
356
|
+
onDelete: function onDelete() {
|
|
357
|
+
return _this2["delete"](category);
|
|
358
|
+
},
|
|
359
|
+
onAddChoice: _this2.addChoiceToCategory,
|
|
360
|
+
onMoveChoice: function onMoveChoice(choiceId, from, to, choiceIndex) {
|
|
361
|
+
return _this2.moveChoice(choiceId, from, to, choiceIndex);
|
|
362
|
+
},
|
|
363
|
+
toolbarOpts: toolbarOpts,
|
|
364
|
+
spellCheck: spellCheck,
|
|
365
|
+
onDeleteChoice: function onDeleteChoice(choice, choiceIndex) {
|
|
366
|
+
return _this2.deleteChoiceFromCategory(category, choice, choiceIndex);
|
|
367
|
+
},
|
|
368
|
+
maxImageWidth: maxImageWidth && maxImageWidth.categoryLabel || defaultImageMaxWidth,
|
|
369
|
+
maxImageHeight: maxImageHeight && maxImageHeight.categoryLabel || defaultImageMaxHeight,
|
|
370
|
+
uploadSoundSupport: uploadSoundSupport,
|
|
371
|
+
configuration: configuration
|
|
372
|
+
}));
|
|
373
|
+
})), associationError && /*#__PURE__*/_react["default"].createElement("div", {
|
|
374
|
+
className: classes.errorText
|
|
375
|
+
}, associationError), categoriesError && /*#__PURE__*/_react["default"].createElement("div", {
|
|
376
|
+
className: classes.errorText
|
|
377
|
+
}, categoriesError));
|
|
378
|
+
}
|
|
379
|
+
}]);
|
|
380
|
+
return Categories;
|
|
381
|
+
}(_react["default"].Component);
|
|
382
|
+
|
|
383
|
+
exports.Categories = Categories;
|
|
384
|
+
(0, _defineProperty2["default"])(Categories, "propTypes", {
|
|
385
|
+
defaultImageMaxHeight: _propTypes["default"].number,
|
|
386
|
+
defaultImageMaxWidth: _propTypes["default"].number,
|
|
387
|
+
imageSupport: _propTypes["default"].shape({
|
|
388
|
+
add: _propTypes["default"].func.isRequired,
|
|
389
|
+
"delete": _propTypes["default"].func.isRequired
|
|
390
|
+
}),
|
|
391
|
+
uploadSoundSupport: _propTypes["default"].shape({
|
|
392
|
+
add: _propTypes["default"].func.isRequired,
|
|
393
|
+
"delete": _propTypes["default"].func.isRequired
|
|
394
|
+
}),
|
|
395
|
+
classes: _propTypes["default"].object.isRequired,
|
|
396
|
+
className: _propTypes["default"].string,
|
|
397
|
+
categories: _propTypes["default"].array,
|
|
398
|
+
onModelChanged: _propTypes["default"].func,
|
|
399
|
+
model: _propTypes["default"].object.isRequired,
|
|
400
|
+
configuration: _propTypes["default"].object.isRequired,
|
|
401
|
+
toolbarOpts: _propTypes["default"].object,
|
|
402
|
+
spellCheck: _propTypes["default"].bool
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
var _default = (0, _styles.withStyles)(styles)(Categories);
|
|
406
|
+
|
|
407
|
+
exports["default"] = _default;
|
|
408
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/design/categories/index.jsx"],"names":["styles","theme","categories","marginBottom","spacing","unit","categoriesHolder","display","gridRowGap","gridColumnGap","row","gridTemplateColumns","alignItems","width","marginTop","rowLabel","gridColumn","rowLabelHolder","tooltip","fontSize","typography","whiteSpace","maxWidth","errorText","color","palette","error","main","paddingTop","Categories","focusedEl","props","model","oldCategories","categoriesPerRow","id","utils","firstAvailableIndex","map","a","data","label","addRowLabel","length","rowLabels","push","setState","onModelChanged","concat","category","index","findIndex","splice","correctResponse","c","addedChoice","categoryId","choices","maxChoicesPerCategory","choice","find","undefined","categoryCount","maxCategoryChoices","choiceIndex","choiceId","from","to","val","newRowLabels","classes","className","imageSupport","uploadSoundSupport","toolbarOpts","spellCheck","configuration","defaultImageMaxHeight","defaultImageMaxWidth","mathMlOptions","errors","associationError","categoriesError","categoriesErrors","maxCategories","maxImageWidth","maxImageHeight","holderStyle","validationMessage","add","marginLeft","hasRowLabel","rowIndex","changeRowLabel","state","deleteFocusedEl","change","addChoiceToCategory","moveChoice","deleteChoiceFromCategory","categoryLabel","React","Component","PropTypes","number","shape","func","isRequired","object","string","array","bool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB;AADzB,KADa;AAIzBC,IAAAA,gBAAgB,EAAE;AAChBC,MAAAA,OAAO,EAAE,MADO;AAEhBC,MAAAA,UAAU,YAAKP,KAAK,CAACG,OAAN,CAAcC,IAAnB,OAFM;AAGhBI,MAAAA,aAAa,YAAKR,KAAK,CAACG,OAAN,CAAcC,IAAnB;AAHG,KAJO;AASzBK,IAAAA,GAAG,EAAE;AACHH,MAAAA,OAAO,EAAE,MADN;AAEHI,MAAAA,mBAAmB,EAAE,gBAFlB;AAGHF,MAAAA,aAAa,YAAKR,KAAK,CAACG,OAAN,CAAcC,IAAnB,OAHV;AAIHO,MAAAA,UA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UAhBf;AAiBjBjC,EAAAA,WAAW,EAAE6B,sBAAUK,MAjBN;AAkBjBjC,EAAAA,UAAU,EAAE4B,sBAAUQ;AAlBL,C;;eAwPN,wBAAW/G,MAAX,EAAmB6B,UAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { choiceUtils as utils } from '@pie-lib/pie-toolbox/config-ui';\nimport classNames from 'classnames';\nimport Info from '@material-ui/icons/Info';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport {\n moveChoiceToCategory,\n removeCategory,\n removeChoiceFromCategory,\n verifyAllowMultiplePlacements,\n} from '@pie-lib/pie-toolbox/categorize';\n\nimport Category from './category';\nimport Header from '../header';\nimport { generateValidationMessage, getMaxCategoryChoices } from '../../utils';\nimport { RowLabel } from './RowLabel';\n\nconst styles = (theme) => ({\n categories: {\n marginBottom: theme.spacing.unit * 3,\n },\n categoriesHolder: {\n display: 'grid',\n gridRowGap: `${theme.spacing.unit}px`,\n gridColumnGap: `${theme.spacing.unit}px`,\n },\n row: {\n display: 'grid',\n gridTemplateColumns: 'repeat(2, 1fr)',\n gridColumnGap: `${theme.spacing.unit}px`,\n alignItems: 'baseline',\n width: '100%',\n marginTop: theme.spacing.unit,\n marginBottom: 2 * theme.spacing.unit,\n },\n rowLabel: {\n gridColumn: '1/3',\n },\n rowLabelHolder: {\n width: '100%',\n },\n tooltip: {\n fontSize: theme.typography.fontSize - 2,\n whiteSpace: 'pre',\n maxWidth: '500px',\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit / 2,\n },\n});\n\nexport class Categories extends React.Component {\n static propTypes = {\n defaultImageMaxHeight: PropTypes.number,\n defaultImageMaxWidth: PropTypes.number,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n uploadSoundSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n categories: PropTypes.array,\n onModelChanged: PropTypes.func,\n model: PropTypes.object.isRequired,\n configuration: PropTypes.object.isRequired,\n toolbarOpts: PropTypes.object,\n spellCheck: PropTypes.bool,\n };\n\n state = {\n focusedEl: null,\n };\n\n add = () => {\n const { model, categories: oldCategories } = this.props;\n const { categoriesPerRow } = model;\n const id = utils.firstAvailableIndex(\n model.categories.map((a) => a.id),\n 0,\n );\n const data = { id, label: 'Category ' + id };\n const addRowLabel = model.categories.length % categoriesPerRow === 0;\n const rowLabels = [...model.rowLabels];\n\n if (addRowLabel) {\n rowLabels.push('');\n }\n\n this.setState(\n {\n focusedEl: oldCategories.length,\n },\n () => {\n this.props.onModelChanged({\n rowLabels,\n categories: model.categories.concat([data]),\n });\n },\n );\n };\n\n deleteFocusedEl = () => {\n this.setState({\n focusedEl: null,\n });\n };\n\n delete = (category) => {\n const { model, onModelChanged } = this.props;\n const index = model.categories.findIndex((a) => a.id === category.id);\n\n if (index !== -1) {\n model.categories.splice(index, 1);\n model.correctResponse = removeCategory(category.id, model.correctResponse);\n onModelChanged(model);\n }\n };\n\n change = (c) => {\n const { categories } = this.props;\n const index = categories.findIndex((a) => a.id === c.id);\n\n if (index !== -1) {\n categories.splice(index, 1, c);\n this.props.onModelChanged({ categories });\n }\n };\n\n addChoiceToCategory = (addedChoice, categoryId) => {\n const { model, onModelChanged } = this.props;\n let { choices = [], correctResponse = [], maxChoicesPerCategory = 0 } = model || {};\n const choice = (choices || []).find((choice) => choice.id === addedChoice.id);\n correctResponse = moveChoiceToCategory(addedChoice.id, undefined, categoryId, 0, model.correctResponse);\n // if multiplePlacements not allowed, ensure the consistency in the other categories\n if (choice.categoryCount !== 0) {\n correctResponse = verifyAllowMultiplePlacements(addedChoice, categoryId, correctResponse);\n }\n const maxCategoryChoices = getMaxCategoryChoices(model);\n // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated\n onModelChanged({\n correctResponse,\n maxChoicesPerCategory:\n maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices\n ? maxChoicesPerCategory + 1\n : maxChoicesPerCategory,\n });\n };\n\n deleteChoiceFromCategory = (category, choice, choiceIndex) => {\n const { model, onModelChanged } = this.props;\n const correctResponse = removeChoiceFromCategory(choice.id, category.id, choiceIndex, model.correctResponse);\n\n onModelChanged({ correctResponse });\n };\n\n moveChoice = (choiceId, from, to, choiceIndex) => {\n const { model, onModelChanged } = this.props;\n let { choices, correctResponse = [], maxChoicesPerCategory = 0 } = model || {};\n const choice = (choices || []).find((choice) => choice.id === choiceId);\n if (to === from || !choice) {\n return;\n }\n if (choice.categoryCount !== 0) {\n correctResponse = moveChoiceToCategory(choice.id, from, to, choiceIndex, correctResponse);\n correctResponse = verifyAllowMultiplePlacements(choice, to, correctResponse);\n } else if (choice.categoryCount === 0) {\n correctResponse = moveChoiceToCategory(choice.id, undefined, to, 0, correctResponse);\n }\n const maxCategoryChoices = getMaxCategoryChoices(model);\n // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated\n onModelChanged({\n correctResponse,\n maxChoicesPerCategory:\n maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices\n ? maxChoicesPerCategory + 1\n : maxChoicesPerCategory,\n });\n };\n\n changeRowLabel = (val, index) => {\n const { model } = this.props;\n const { rowLabels } = model;\n const newRowLabels = [...rowLabels];\n\n if (newRowLabels.length < index) {\n newRowLabels.push(val);\n } else {\n newRowLabels[index] = val;\n }\n\n this.props.onModelChanged({\n rowLabels: newRowLabels,\n });\n };\n\n render() {\n const {\n model,\n classes,\n className,\n categories,\n imageSupport,\n uploadSoundSupport,\n toolbarOpts,\n spellCheck,\n configuration,\n defaultImageMaxHeight,\n defaultImageMaxWidth,\n mathMlOptions = {},\n } = this.props;\n\n const { categoriesPerRow, rowLabels, errors } = model;\n const { associationError, categoriesError, categoriesErrors } = errors || {};\n const { maxCategories, maxImageWidth = {}, maxImageHeight = {} } = configuration || {};\n const holderStyle = {\n gridTemplateColumns: `repeat(${categoriesPerRow}, 1fr)`,\n };\n\n const validationMessage = generateValidationMessage(configuration);\n\n return (\n <div className={classNames(classes.categories, className)}>\n <Header\n label=\"Categories\"\n buttonLabel=\"ADD A CATEGORY\"\n onAdd={this.add}\n info={\n <Tooltip\n classes={{ tooltip: classes.tooltip }}\n disableFocusListener\n disableTouchListener\n placement={'right'}\n title={validationMessage}\n >\n <Info fontSize={'small'} color={'primary'} style={{ marginLeft: '5px' }} />\n </Tooltip>\n }\n buttonDisabled={maxCategories && categories && maxCategories === categories.length}\n />\n\n <div className={classes.categoriesHolder} style={holderStyle}>\n {categories.map((category, index) => {\n const hasRowLabel = index % categoriesPerRow === 0;\n const rowIndex = index / categoriesPerRow;\n\n return (\n <React.Fragment key={index}>\n {hasRowLabel && (\n <RowLabel\n categoriesPerRow={categoriesPerRow}\n disabled={false}\n rowIndex={rowIndex}\n markup={rowLabels[rowIndex] || ''}\n onChange={(val) => this.changeRowLabel(val, rowIndex)}\n imageSupport={imageSupport}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n maxImageWidth={(maxImageWidth && maxImageWidth.rowLabel) || defaultImageMaxWidth}\n maxImageHeight={(maxImageHeight && maxImageHeight.rowLabel) || defaultImageMaxHeight}\n uploadSoundSupport={uploadSoundSupport}\n mathMlOptions={mathMlOptions}\n configuration={configuration}\n />\n )}\n\n <Category\n imageSupport={imageSupport}\n focusedEl={this.state.focusedEl}\n deleteFocusedEl={this.deleteFocusedEl}\n index={index}\n category={category}\n error={categoriesErrors && categoriesErrors[category.id]}\n onChange={this.change}\n onDelete={() => this.delete(category)}\n onAddChoice={this.addChoiceToCategory}\n onMoveChoice={(choiceId, from, to, choiceIndex) => this.moveChoice(choiceId, from, to, choiceIndex)}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n onDeleteChoice={(choice, choiceIndex) => this.deleteChoiceFromCategory(category, choice, choiceIndex)}\n maxImageWidth={(maxImageWidth && maxImageWidth.categoryLabel) || defaultImageMaxWidth}\n maxImageHeight={(maxImageHeight && maxImageHeight.categoryLabel) || defaultImageMaxHeight}\n uploadSoundSupport={uploadSoundSupport}\n configuration={configuration}\n />\n </React.Fragment>\n );\n })}\n </div>\n\n {associationError && <div className={classes.errorText}>{associationError}</div>}\n {categoriesError && <div className={classes.errorText}>{categoriesError}</div>}\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(Categories);\n"],"file":"index.js"}
|