@pie-element/categorize 7.4.1-next.3 → 7.4.1-next.42
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 +0 -1
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/design/categories/alternateResponses.js +38 -14
- package/configure/lib/design/categories/alternateResponses.js.map +1 -1
- package/configure/lib/design/categories/category.js +16 -0
- package/configure/lib/design/categories/category.js.map +1 -1
- package/configure/lib/design/categories/choice-preview.js +15 -2
- package/configure/lib/design/categories/choice-preview.js.map +1 -1
- package/configure/lib/design/categories/droppable-placeholder.js +21 -2
- package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
- package/configure/lib/design/categories/index.js +83 -35
- package/configure/lib/design/categories/index.js.map +1 -1
- package/configure/lib/design/choices/choice.js +9 -0
- package/configure/lib/design/choices/choice.js.map +1 -1
- package/configure/lib/design/choices/index.js +21 -3
- package/configure/lib/design/choices/index.js.map +1 -1
- package/configure/lib/design/index.js.map +1 -1
- package/configure/lib/design/input-header.js +38 -15
- package/configure/lib/design/input-header.js.map +1 -1
- package/controller/lib/defaults.js +0 -1
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +2 -3
- package/controller/lib/index.js.map +1 -1
- package/docs/config-schema.json.md +1 -1
- package/docs/pie-schema.json +0 -5
- package/docs/pie-schema.json.md +1 -6
- package/package.json +2 -2
|
@@ -145,8 +145,13 @@ var Categories = /*#__PURE__*/function (_React$Component) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
148
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
|
|
149
|
+
focusedEl: null
|
|
150
|
+
});
|
|
148
151
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "add", function () {
|
|
149
|
-
var
|
|
152
|
+
var _this$props = _this.props,
|
|
153
|
+
model = _this$props.model,
|
|
154
|
+
oldCategories = _this$props.categories;
|
|
150
155
|
var categoriesPerRow = model.categoriesPerRow;
|
|
151
156
|
|
|
152
157
|
var id = _configUi.choiceUtils.firstAvailableIndex(model.categories.map(function (a) {
|
|
@@ -164,15 +169,24 @@ var Categories = /*#__PURE__*/function (_React$Component) {
|
|
|
164
169
|
rowLabels.push('');
|
|
165
170
|
}
|
|
166
171
|
|
|
167
|
-
_this.
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
_this.setState({
|
|
173
|
+
focusedEl: oldCategories.length
|
|
174
|
+
}, function () {
|
|
175
|
+
_this.props.onModelChanged({
|
|
176
|
+
rowLabels: rowLabels,
|
|
177
|
+
categories: model.categories.concat([data])
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteFocusedEl", function () {
|
|
182
|
+
_this.setState({
|
|
183
|
+
focusedEl: null
|
|
170
184
|
});
|
|
171
185
|
});
|
|
172
186
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "delete", function (category) {
|
|
173
|
-
var _this$
|
|
174
|
-
model = _this$
|
|
175
|
-
onModelChanged = _this$
|
|
187
|
+
var _this$props2 = _this.props,
|
|
188
|
+
model = _this$props2.model,
|
|
189
|
+
onModelChanged = _this$props2.onModelChanged;
|
|
176
190
|
var index = model.categories.findIndex(function (a) {
|
|
177
191
|
return a.id === category.id;
|
|
178
192
|
});
|
|
@@ -198,23 +212,51 @@ var Categories = /*#__PURE__*/function (_React$Component) {
|
|
|
198
212
|
}
|
|
199
213
|
});
|
|
200
214
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addChoiceToCategory", function (choice, categoryId) {
|
|
201
|
-
var _this$
|
|
202
|
-
model = _this$
|
|
203
|
-
onModelChanged = _this$
|
|
215
|
+
var _this$props3 = _this.props,
|
|
216
|
+
model = _this$props3.model,
|
|
217
|
+
onModelChanged = _this$props3.onModelChanged;
|
|
204
218
|
var correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, categoryId, 0, model.correctResponse);
|
|
205
219
|
onModelChanged({
|
|
206
220
|
correctResponse: correctResponse
|
|
207
221
|
});
|
|
208
222
|
});
|
|
209
223
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoiceFromCategory", function (category, choice, choiceIndex) {
|
|
210
|
-
var _this$
|
|
211
|
-
model = _this$
|
|
212
|
-
onModelChanged = _this$
|
|
224
|
+
var _this$props4 = _this.props,
|
|
225
|
+
model = _this$props4.model,
|
|
226
|
+
onModelChanged = _this$props4.onModelChanged;
|
|
213
227
|
var correctResponse = (0, _categorize.removeChoiceFromCategory)(choice.id, category.id, choiceIndex, model.correctResponse);
|
|
214
228
|
onModelChanged({
|
|
215
229
|
correctResponse: correctResponse
|
|
216
230
|
});
|
|
217
231
|
});
|
|
232
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moveChoice", function (choiceId, from, to, choiceIndex) {
|
|
233
|
+
var _this$props5 = _this.props,
|
|
234
|
+
model = _this$props5.model,
|
|
235
|
+
onModelChanged = _this$props5.onModelChanged;
|
|
236
|
+
|
|
237
|
+
var _ref2 = model || {},
|
|
238
|
+
choices = _ref2.choices,
|
|
239
|
+
_ref2$correctResponse = _ref2.correctResponse,
|
|
240
|
+
correctResponse = _ref2$correctResponse === void 0 ? [] : _ref2$correctResponse;
|
|
241
|
+
|
|
242
|
+
var choice = (choices || []).find(function (choice) {
|
|
243
|
+
return choice.id === choiceId;
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (to === from || !choice) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (choice.categoryCount !== 0) {
|
|
251
|
+
correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, from, to, choiceIndex, correctResponse);
|
|
252
|
+
} else if (choice.categoryCount === 0) {
|
|
253
|
+
correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, to, 0, correctResponse);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
onModelChanged({
|
|
257
|
+
correctResponse: correctResponse
|
|
258
|
+
});
|
|
259
|
+
});
|
|
218
260
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeRowLabel", function (val, index) {
|
|
219
261
|
var model = _this.props.model;
|
|
220
262
|
var rowLabels = model.rowLabels;
|
|
@@ -238,33 +280,33 @@ var Categories = /*#__PURE__*/function (_React$Component) {
|
|
|
238
280
|
value: function render() {
|
|
239
281
|
var _this2 = this;
|
|
240
282
|
|
|
241
|
-
var _this$
|
|
242
|
-
model = _this$
|
|
243
|
-
classes = _this$
|
|
244
|
-
className = _this$
|
|
245
|
-
categories = _this$
|
|
246
|
-
imageSupport = _this$
|
|
247
|
-
uploadSoundSupport = _this$
|
|
248
|
-
toolbarOpts = _this$
|
|
249
|
-
spellCheck = _this$
|
|
250
|
-
configuration = _this$
|
|
251
|
-
defaultImageMaxHeight = _this$
|
|
252
|
-
defaultImageMaxWidth = _this$
|
|
283
|
+
var _this$props6 = this.props,
|
|
284
|
+
model = _this$props6.model,
|
|
285
|
+
classes = _this$props6.classes,
|
|
286
|
+
className = _this$props6.className,
|
|
287
|
+
categories = _this$props6.categories,
|
|
288
|
+
imageSupport = _this$props6.imageSupport,
|
|
289
|
+
uploadSoundSupport = _this$props6.uploadSoundSupport,
|
|
290
|
+
toolbarOpts = _this$props6.toolbarOpts,
|
|
291
|
+
spellCheck = _this$props6.spellCheck,
|
|
292
|
+
configuration = _this$props6.configuration,
|
|
293
|
+
defaultImageMaxHeight = _this$props6.defaultImageMaxHeight,
|
|
294
|
+
defaultImageMaxWidth = _this$props6.defaultImageMaxWidth;
|
|
253
295
|
var categoriesPerRow = model.categoriesPerRow,
|
|
254
296
|
rowLabels = model.rowLabels,
|
|
255
297
|
errors = model.errors;
|
|
256
298
|
|
|
257
|
-
var
|
|
258
|
-
associationError =
|
|
259
|
-
categoriesError =
|
|
260
|
-
categoriesErrors =
|
|
299
|
+
var _ref3 = errors || {},
|
|
300
|
+
associationError = _ref3.associationError,
|
|
301
|
+
categoriesError = _ref3.categoriesError,
|
|
302
|
+
categoriesErrors = _ref3.categoriesErrors;
|
|
261
303
|
|
|
262
|
-
var
|
|
263
|
-
maxCategories =
|
|
264
|
-
|
|
265
|
-
maxImageWidth =
|
|
266
|
-
|
|
267
|
-
maxImageHeight =
|
|
304
|
+
var _ref4 = configuration || {},
|
|
305
|
+
maxCategories = _ref4.maxCategories,
|
|
306
|
+
_ref4$maxImageWidth = _ref4.maxImageWidth,
|
|
307
|
+
maxImageWidth = _ref4$maxImageWidth === void 0 ? {} : _ref4$maxImageWidth,
|
|
308
|
+
_ref4$maxImageHeight = _ref4.maxImageHeight,
|
|
309
|
+
maxImageHeight = _ref4$maxImageHeight === void 0 ? {} : _ref4$maxImageHeight;
|
|
268
310
|
|
|
269
311
|
var holderStyle = {
|
|
270
312
|
gridTemplateColumns: "repeat(".concat(categoriesPerRow, ", 1fr)")
|
|
@@ -319,6 +361,9 @@ var Categories = /*#__PURE__*/function (_React$Component) {
|
|
|
319
361
|
uploadSoundSupport: uploadSoundSupport
|
|
320
362
|
}), /*#__PURE__*/_react["default"].createElement(_category["default"], {
|
|
321
363
|
imageSupport: imageSupport,
|
|
364
|
+
focusedEl: _this2.state.focusedEl,
|
|
365
|
+
deleteFocusedEl: _this2.deleteFocusedEl,
|
|
366
|
+
index: index,
|
|
322
367
|
category: category,
|
|
323
368
|
error: categoriesErrors && categoriesErrors[category.id],
|
|
324
369
|
onChange: _this2.change,
|
|
@@ -326,6 +371,9 @@ var Categories = /*#__PURE__*/function (_React$Component) {
|
|
|
326
371
|
return _this2["delete"](category);
|
|
327
372
|
},
|
|
328
373
|
onAddChoice: _this2.addChoiceToCategory,
|
|
374
|
+
onMoveChoice: function onMoveChoice(choiceId, from, to, choiceIndex) {
|
|
375
|
+
return _this2.moveChoice(choiceId, from, to, choiceIndex);
|
|
376
|
+
},
|
|
329
377
|
toolbarOpts: toolbarOpts,
|
|
330
378
|
spellCheck: spellCheck,
|
|
331
379
|
onDeleteChoice: function onDeleteChoice(choice, choiceIndex) {
|
|
@@ -1 +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","whiteSpace","maxWidth","errorText","color","padding","RowLabel","categoriesPerRow","classes","markup","imageSupport","onChange","toolbarOpts","spellCheck","maxImageWidth","maxImageHeight","uploadSoundSupport","text","language","Categories","model","props","id","utils","firstAvailableIndex","map","a","data","label","addRowLabel","length","rowLabels","push","onModelChanged","concat","category","index","findIndex","splice","correctResponse","c","choice","categoryId","undefined","choiceIndex","val","newRowLabels","className","configuration","defaultImageMaxHeight","defaultImageMaxWidth","errors","associationError","categoriesError","categoriesErrors","maxCategories","holderStyle","validationMessage","add","marginLeft","hasRowLabel","rowIndex","changeRowLabel","change","addChoiceToCategory","deleteChoiceFromCategory","categoryLabel","React","Component","PropTypes","shape","func","isRequired","object","string","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC;AADlB,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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BZ,IAAAA,GAAG,EAAEW,sBAAUE,IAAV,CAAeC,UADQ;AAE5B,cAAQH,sBAAUE,IAAV,CAAeC;AAFK,GAAhB,CADG;AAKjBxD,EAAAA,kBAAkB,EAAEqD,sBAAUC,KAAV,CAAgB;AAClCZ,IAAAA,GAAG,EAAEW,sBAAUE,IAAV,CAAeC,UADc;AAElC,cAAQH,sBAAUE,IAAV,CAAeC;AAFW,GAAhB,CALH;AASjBhE,EAAAA,OAAO,EAAE6D,sBAAUI,MAAV,CAAiBD,UATT;AAUjBzB,EAAAA,SAAS,EAAEsB,sBAAUK,MAVJ;AAWjB3F,EAAAA,UAAU,EAAEsF,sBAAUM,KAXL;AAYjB1C,EAAAA,cAAc,EAAEoC,sBAAUE,IAZT;AAajBnD,EAAAA,KAAK,EAAEiD,sBAAUI,MAAV,CAAiBD,UAbP;AAcjBxB,EAAAA,aAAa,EAAEqB,sBAAUI,MAAV,CAAiBD,UAdf;AAejB5D,EAAAA,WAAW,EAAEyD,sBAAUI;AAfN,C;;eAuLN,wBAAW5F,MAAX,EAAmBsC,UAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport TextField from '@material-ui/core/TextField';\nimport Typography from '@material-ui/core/Typography';\nimport { choiceUtils as utils } from '@pie-lib/config-ui';\nimport EditableHtml from '@pie-lib/editable-html';\nimport classNames from 'classnames';\nimport Info from '@material-ui/icons/Info';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { moveChoiceToCategory, removeCategory, removeChoiceFromCategory } from '@pie-lib/categorize';\n\nimport Category from './category';\nimport Header from '../header';\nimport { generateValidationMessage } from '../../utils';\n\nconst styles = (theme) => ({\n categories: {\n marginBottom: theme.spacing.unit,\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: '12px',\n whiteSpace: 'pre',\n maxWidth: '500px',\n },\n errorText: {\n fontSize: '12px',\n color: 'red',\n padding: '5px 0',\n },\n});\n\nconst RowLabel = withStyles(styles)(\n ({\n categoriesPerRow,\n classes,\n markup,\n imageSupport,\n onChange,\n toolbarOpts,\n spellCheck,\n maxImageWidth,\n maxImageHeight,\n uploadSoundSupport,\n }) => {\n return (\n <div\n style={{\n gridColumn: `1/${categoriesPerRow + 1}`,\n width: '100%',\n }}\n >\n <Typography className={classes.text}>Row Label</Typography>\n <EditableHtml\n className={classes.rowLabelHolder}\n markup={markup}\n onChange={onChange}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n uploadSoundSupport={uploadSoundSupport}\n languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}\n />\n </div>\n );\n },\n);\n\nexport class Categories extends React.Component {\n static propTypes = {\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 };\n\n add = () => {\n const { model } = 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.props.onModelChanged({\n rowLabels,\n categories: model.categories.concat([data]),\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 = (choice, categoryId) => {\n const { model, onModelChanged } = this.props;\n const correctResponse = moveChoiceToCategory(choice.id, undefined, categoryId, 0, model.correctResponse);\n\n onModelChanged({ correctResponse });\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 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 } = this.props;\n\n const { categoriesPerRow, rowLabels, errors } = model;\n const { associationError, categoriesError, categoriesErrors } = errors || {};\n const {\n maxCategories,\n maxImageWidth = {},\n maxImageHeight = {},\n } = 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 {associationError && <div className={classes.errorText}>{associationError}</div>}\n {categoriesError && <div className={classes.errorText}>{categoriesError}</div>}\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 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 />\n )}\n <Category\n imageSupport={imageSupport}\n category={category}\n error={categoriesErrors && categoriesErrors[category.id]}\n onChange={this.change}\n onDelete={() => this.delete(category)}\n onAddChoice={this.addChoiceToCategory}\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 />\n </React.Fragment>\n );\n })}\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(Categories);\n"],"file":"index.js"}
|
|
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","whiteSpace","maxWidth","errorText","color","padding","RowLabel","categoriesPerRow","classes","markup","imageSupport","onChange","toolbarOpts","spellCheck","maxImageWidth","maxImageHeight","uploadSoundSupport","text","language","Categories","focusedEl","props","model","oldCategories","id","utils","firstAvailableIndex","map","a","data","label","addRowLabel","length","rowLabels","push","setState","onModelChanged","concat","category","index","findIndex","splice","correctResponse","c","choice","categoryId","undefined","choiceIndex","choiceId","from","to","choices","find","categoryCount","val","newRowLabels","className","configuration","defaultImageMaxHeight","defaultImageMaxWidth","errors","associationError","categoriesError","categoriesErrors","maxCategories","holderStyle","validationMessage","add","marginLeft","hasRowLabel","rowIndex","changeRowLabel","state","deleteFocusedEl","change","addChoiceToCategory","moveChoice","deleteChoiceFromCategory","categoryLabel","React","Component","PropTypes","shape","func","isRequired","object","string","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC;AADlB,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,C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CAAC+D,aAAlC,IAAoDpB,qBAftE;AAgBE,UAAA,kBAAkB,EAAE1C;AAhBtB,UAfF,CADF;AAoCD,OAxCA,CADH,CApBF,CADF;AAkED;;;EArN6B+D,kBAAMC,S;;;iCAAzB7D,U,eACQ;AACjBT,EAAAA,YAAY,EAAEuE,sBAAUC,KAAV,CAAgB;AAC5Bf,IAAAA,GAAG,EAAEc,sBAAUE,IAAV,CAAeC,UADQ;AAE5B,cAAQH,sBAAUE,IAAV,CAAeC;AAFK,GAAhB,CADG;AAKjBpE,EAAAA,kBAAkB,EAAEiE,sBAAUC,KAAV,CAAgB;AAClCf,IAAAA,GAAG,EAAEc,sBAAUE,IAAV,CAAeC,UADc;AAElC,cAAQH,sBAAUE,IAAV,CAAeC;AAFW,GAAhB,CALH;AASjB5E,EAAAA,OAAO,EAAEyE,sBAAUI,MAAV,CAAiBD,UATT;AAUjB5B,EAAAA,SAAS,EAAEyB,sBAAUK,MAVJ;AAWjBvG,EAAAA,UAAU,EAAEkG,sBAAUM,KAXL;AAYjBnD,EAAAA,cAAc,EAAE6C,sBAAUE,IAZT;AAajB7D,EAAAA,KAAK,EAAE2D,sBAAUI,MAAV,CAAiBD,UAbP;AAcjB3B,EAAAA,aAAa,EAAEwB,sBAAUI,MAAV,CAAiBD,UAdf;AAejBxE,EAAAA,WAAW,EAAEqE,sBAAUI;AAfN,C;;eAuNN,wBAAWxG,MAAX,EAAmBsC,UAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport TextField from '@material-ui/core/TextField';\nimport Typography from '@material-ui/core/Typography';\nimport { choiceUtils as utils } from '@pie-lib/config-ui';\nimport EditableHtml from '@pie-lib/editable-html';\nimport classNames from 'classnames';\nimport Info from '@material-ui/icons/Info';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport {\n moveChoiceToAlternate,\n moveChoiceToCategory,\n removeCategory,\n removeChoiceFromCategory,\n} from '@pie-lib/categorize';\n\nimport Category from './category';\nimport Header from '../header';\nimport { generateValidationMessage } from '../../utils';\n\nconst styles = (theme) => ({\n categories: {\n marginBottom: theme.spacing.unit,\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: '12px',\n whiteSpace: 'pre',\n maxWidth: '500px',\n },\n errorText: {\n fontSize: '12px',\n color: 'red',\n padding: '5px 0',\n },\n});\n\nconst RowLabel = withStyles(styles)(\n ({\n categoriesPerRow,\n classes,\n markup,\n imageSupport,\n onChange,\n toolbarOpts,\n spellCheck,\n maxImageWidth,\n maxImageHeight,\n uploadSoundSupport,\n }) => {\n return (\n <div\n style={{\n gridColumn: `1/${categoriesPerRow + 1}`,\n width: '100%',\n }}\n >\n <Typography className={classes.text}>Row Label</Typography>\n <EditableHtml\n className={classes.rowLabelHolder}\n markup={markup}\n onChange={onChange}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n uploadSoundSupport={uploadSoundSupport}\n languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}\n />\n </div>\n );\n },\n);\n\nexport class Categories extends React.Component {\n static propTypes = {\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 };\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 = (choice, categoryId) => {\n const { model, onModelChanged } = this.props;\n const correctResponse = moveChoiceToCategory(choice.id, undefined, categoryId, 0, model.correctResponse);\n\n onModelChanged({ correctResponse });\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 = [] } = 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 } else if (choice.categoryCount === 0) {\n correctResponse = moveChoiceToCategory(choice.id, undefined, to, 0, correctResponse);\n }\n onModelChanged({ correctResponse });\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 } = 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 {associationError && <div className={classes.errorText}>{associationError}</div>}\n {categoriesError && <div className={classes.errorText}>{categoriesError}</div>}\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 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 />\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 />\n </React.Fragment>\n );\n })}\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(Categories);\n"],"file":"index.js"}
|
|
@@ -114,6 +114,9 @@ var Choice = /*#__PURE__*/function (_React$Component) {
|
|
|
114
114
|
classes = _this$props3.classes,
|
|
115
115
|
className = _this$props3.className,
|
|
116
116
|
choice = _this$props3.choice,
|
|
117
|
+
deleteFocusedEl = _this$props3.deleteFocusedEl,
|
|
118
|
+
focusedEl = _this$props3.focusedEl,
|
|
119
|
+
index = _this$props3.index,
|
|
117
120
|
onDelete = _this$props3.onDelete,
|
|
118
121
|
connectDragSource = _this$props3.connectDragSource,
|
|
119
122
|
connectDragPreview = _this$props3.connectDragPreview,
|
|
@@ -136,6 +139,9 @@ var Choice = /*#__PURE__*/function (_React$Component) {
|
|
|
136
139
|
color: draggable ? 'primary' : 'disabled'
|
|
137
140
|
})))), connectDragPreview( /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_inputHeader["default"], {
|
|
138
141
|
imageSupport: imageSupport,
|
|
142
|
+
focusedEl: focusedEl,
|
|
143
|
+
deleteFocusedEl: deleteFocusedEl,
|
|
144
|
+
index: index,
|
|
139
145
|
label: choice.content,
|
|
140
146
|
onChange: this.changeContent,
|
|
141
147
|
onDelete: onDelete,
|
|
@@ -169,6 +175,9 @@ exports.Choice = Choice;
|
|
|
169
175
|
classes: _propTypes["default"].object.isRequired,
|
|
170
176
|
className: _propTypes["default"].string,
|
|
171
177
|
choice: _propTypes["default"].object.isRequired,
|
|
178
|
+
deleteFocusedEl: _propTypes["default"].func,
|
|
179
|
+
focusedEl: _propTypes["default"].number,
|
|
180
|
+
index: _propTypes["default"].number,
|
|
172
181
|
onChange: _propTypes["default"].func.isRequired,
|
|
173
182
|
onDelete: _propTypes["default"].func.isRequired,
|
|
174
183
|
connectDragSource: _propTypes["default"].func.isRequired,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/design/choices/choice.jsx"],"names":["log","canDrag","props","count","choice","categoryCount","correctResponseCount","Choice","content","onChange","allowMultiplePlacements","multiplePlacements","perChoice","classes","className","onDelete","connectDragSource","connectDragPreview","imageSupport","spellCheck","toolbarOpts","error","maxImageWidth","maxImageHeight","uploadSoundSupport","draggable","showRemoveAfterPlacing","isCheckboxShown","actions","dragHandle","dragDisabled","changeContent","errorText","changeCategoryCount","React","Component","PropTypes","string","object","isRequired","func","number","shape","add","styles","theme","padding","justifyContent","spacing","unit","overflow","cursor","fontSize","color","paddingBottom","StyledChoice","spec","beginDrag","out","id","endDrag","monitor","didDrop","item","getItem","categoryId","onRemoveChoice","DraggableChoice","uid","connect","dragSource","dragPreview","isDragging","withUid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAA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AAID,IAAI,CAACE,UAAT,EAAqB;AACnBjE,QAAAA,GAAG,CAAC,8BAAD,CAAH;AACAE,QAAAA,KAAK,CAACgE,cAAN,CAAqBH,IAArB;AACD;AACF;AACF;AAjBiB,CAAb;;AAoBP,IAAMI,eAAe,GAAG,0BACtB;AAAA,MAAGC,GAAH,QAAGA,GAAH;AAAA,SAAaA,GAAb;AAAA,CADsB,EAEtBZ,IAFsB,EAGtB,UAACa,OAAD,EAAUR,OAAV;AAAA,SAAuB;AACrB7C,IAAAA,iBAAiB,EAAEqD,OAAO,CAACC,UAAR,EADE;AAErBrD,IAAAA,kBAAkB,EAAEoD,OAAO,CAACE,WAAR,EAFC;AAGrBC,IAAAA,UAAU,EAAEX,OAAO,CAACW,UAAR;AAHS,GAAvB;AAAA,CAHsB,EAQtBjB,YARsB,CAAxB;;eAUea,UAAIK,OAAJ,CAAYN,eAAZ,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport Card from '@material-ui/core/Card';\nimport CardActions from '@material-ui/core/CardActions';\nimport InputHeader from '../input-header';\nimport { Checkbox } from '@pie-lib/config-ui';\nimport { DeleteButton } from '../buttons';\nimport DragHandle from '@material-ui/icons/DragHandle';\nimport { DragSource } from 'react-dnd';\nimport debug from 'debug';\nimport { uid } from '@pie-lib/drag';\nimport { multiplePlacements } from '../../utils';\n\nconst log = debug('@pie-element:categorize:configure:choice');\n\nconst canDrag = (props) => {\n const count = props.choice.categoryCount || 0;\n if (count === 0) {\n return true;\n } else {\n return props.correctResponseCount < count;\n }\n};\n\nexport class Choice extends React.Component {\n static propTypes = {\n allowMultiplePlacements: PropTypes.string,\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n choice: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n onDelete: PropTypes.func.isRequired,\n connectDragSource: PropTypes.func.isRequired,\n connectDragPreview: PropTypes.func.isRequired,\n correctResponseCount: PropTypes.number.isRequired,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n toolbarOpts: PropTypes.object,\n error: PropTypes.string,\n uploadSoundSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n };\n\n static defaultProps = {};\n\n changeContent = (content) => {\n const { onChange, choice } = this.props;\n choice.content = content;\n onChange(choice);\n };\n\n changeCategoryCount = () => {\n const { onChange, choice } = this.props;\n if (choice.categoryCount === 1) {\n choice.categoryCount = 0;\n } else {\n choice.categoryCount = 1;\n }\n onChange(choice);\n };\n\n isCheckboxShown = (allowMultiplePlacements) => allowMultiplePlacements === multiplePlacements.perChoice;\n\n render() {\n const {\n allowMultiplePlacements,\n classes,\n className,\n choice,\n onDelete,\n connectDragSource,\n connectDragPreview,\n imageSupport,\n spellCheck,\n toolbarOpts,\n error,\n maxImageWidth,\n maxImageHeight,\n uploadSoundSupport,\n } = this.props;\n\n const draggable = canDrag(this.props);\n\n const showRemoveAfterPlacing = this.isCheckboxShown(allowMultiplePlacements);\n\n return (\n <Card className={classNames(classes.choice, className)}>\n <CardActions className={classes.actions}>\n {connectDragSource(\n <span className={classNames(classes.dragHandle, draggable === false && classes.dragDisabled)}>\n <DragHandle color={draggable ? 'primary' : 'disabled'} />\n </span>,\n )}\n </CardActions>\n {connectDragPreview(\n <span>\n <InputHeader\n imageSupport={imageSupport}\n label={choice.content}\n onChange={this.changeContent}\n onDelete={onDelete}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n error={error}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n uploadSoundSupport={uploadSoundSupport}\n />\n {error && <div className={classes.errorText}>{error}</div>}\n </span>,\n )}\n\n <CardActions className={classes.actions}>\n <DeleteButton label={'delete'} onClick={onDelete} />\n {showRemoveAfterPlacing && (\n <Checkbox\n mini\n label={'Remove after placing'}\n checked={choice.categoryCount === 1}\n onChange={this.changeCategoryCount}\n />\n )}\n </CardActions>\n </Card>\n );\n }\n}\nconst styles = (theme) => ({\n actions: {\n padding: 0,\n justifyContent: 'space-between',\n },\n choice: {\n padding: theme.spacing.unit,\n overflow: 'visible',\n },\n dragHandle: {\n cursor: 'move',\n },\n dragDisabled: {\n cursor: 'inherit',\n },\n errorText: {\n fontSize: '11px',\n color: 'red',\n paddingBottom: '5px',\n },\n});\n\nconst StyledChoice = withStyles(styles)(Choice);\n\nexport const spec = {\n canDrag,\n beginDrag: (props) => {\n const out = {\n id: props.choice.id,\n };\n log('[beginDrag] out:', out);\n return out;\n },\n endDrag: (props, monitor) => {\n if (!monitor.didDrop()) {\n const item = monitor.getItem();\n if (item.categoryId) {\n log('wasnt droppped - what to do?');\n props.onRemoveChoice(item);\n }\n }\n },\n};\n\nconst DraggableChoice = DragSource(\n ({ uid }) => uid,\n spec,\n (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n connectDragPreview: connect.dragPreview(),\n isDragging: monitor.isDragging(),\n }),\n)(StyledChoice);\n\nexport default uid.withUid(DraggableChoice);\n"],"file":"choice.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/design/choices/choice.jsx"],"names":["log","canDrag","props","count","choice","categoryCount","correctResponseCount","Choice","content","onChange","allowMultiplePlacements","multiplePlacements","perChoice","classes","className","deleteFocusedEl","focusedEl","index","onDelete","connectDragSource","connectDragPreview","imageSupport","spellCheck","toolbarOpts","error","maxImageWidth","maxImageHeight","uploadSoundSupport","draggable","showRemoveAfterPlacing","isCheckboxShown","actions","dragHandle","dragDisabled","changeContent","errorText","changeCategoryCount","React","Component","PropTypes","string","object","isRequired","func","number","shape","add","styles","theme","padding","justifyContent","spacing","unit","overflow","cursor","fontSize","color","paddingBottom","StyledChoice","spec","beginDrag","out","id","endDrag","monitor","didDrop","item","getItem","categoryId","onRemoveChoice","DraggableChoice","uid","connect","dragSource","dragPreview","isDragging","withUid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;A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oD,IAAI,GAAG;AAClB1D,EAAAA,OAAO,EAAPA,OADkB;AAElB2D,EAAAA,SAAS,EAAE,mBAAC1D,KAAD,EAAW;AACpB,QAAM2D,GAAG,GAAG;AACVC,MAAAA,EAAE,EAAE5D,KAAK,CAACE,MAAN,CAAa0D;AADP,KAAZ;AAGA9D,IAAAA,GAAG,CAAC,kBAAD,EAAqB6D,GAArB,CAAH;AACA,WAAOA,GAAP;AACD,GARiB;AASlBE,EAAAA,OAAO,EAAE,iBAAC7D,KAAD,EAAQ8D,OAAR,EAAoB;AAC3B,QAAI,CAACA,OAAO,CAACC,OAAR,EAAL,EAAwB;AACtB,UAAMC,IAAI,GAAGF,OAAO,CAACG,OAAR,EAAb;;AACA,UAAID,IAAI,CAACE,UAAT,EAAqB;AACnBpE,QAAAA,GAAG,CAAC,8BAAD,CAAH;AACAE,QAAAA,KAAK,CAACmE,cAAN,CAAqBH,IAArB;AACD;AACF;AACF;AAjBiB,CAAb;;AAoBP,IAAMI,eAAe,GAAG,0BACtB;AAAA,MAAGC,GAAH,QAAGA,GAAH;AAAA,SAAaA,GAAb;AAAA,CADsB,EAEtBZ,IAFsB,EAGtB,UAACa,OAAD,EAAUR,OAAV;AAAA,SAAuB;AACrB7C,IAAAA,iBAAiB,EAAEqD,OAAO,CAACC,UAAR,EADE;AAErBrD,IAAAA,kBAAkB,EAAEoD,OAAO,CAACE,WAAR,EAFC;AAGrBC,IAAAA,UAAU,EAAEX,OAAO,CAACW,UAAR;AAHS,GAAvB;AAAA,CAHsB,EAQtBjB,YARsB,CAAxB;;eAUea,UAAIK,OAAJ,CAAYN,eAAZ,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport Card from '@material-ui/core/Card';\nimport CardActions from '@material-ui/core/CardActions';\nimport InputHeader from '../input-header';\nimport { Checkbox } from '@pie-lib/config-ui';\nimport { DeleteButton } from '../buttons';\nimport DragHandle from '@material-ui/icons/DragHandle';\nimport { DragSource } from 'react-dnd';\nimport debug from 'debug';\nimport { uid } from '@pie-lib/drag';\nimport { multiplePlacements } from '../../utils';\n\nconst log = debug('@pie-element:categorize:configure:choice');\n\nconst canDrag = (props) => {\n const count = props.choice.categoryCount || 0;\n if (count === 0) {\n return true;\n } else {\n return props.correctResponseCount < count;\n }\n};\n\nexport class Choice extends React.Component {\n static propTypes = {\n allowMultiplePlacements: PropTypes.string,\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n choice: PropTypes.object.isRequired,\n deleteFocusedEl: PropTypes.func,\n focusedEl: PropTypes.number,\n index: PropTypes.number,\n onChange: PropTypes.func.isRequired,\n onDelete: PropTypes.func.isRequired,\n connectDragSource: PropTypes.func.isRequired,\n connectDragPreview: PropTypes.func.isRequired,\n correctResponseCount: PropTypes.number.isRequired,\n imageSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n toolbarOpts: PropTypes.object,\n error: PropTypes.string,\n uploadSoundSupport: PropTypes.shape({\n add: PropTypes.func.isRequired,\n delete: PropTypes.func.isRequired,\n }),\n };\n\n static defaultProps = {};\n\n changeContent = (content) => {\n const { onChange, choice } = this.props;\n choice.content = content;\n onChange(choice);\n };\n\n changeCategoryCount = () => {\n const { onChange, choice } = this.props;\n if (choice.categoryCount === 1) {\n choice.categoryCount = 0;\n } else {\n choice.categoryCount = 1;\n }\n onChange(choice);\n };\n\n isCheckboxShown = (allowMultiplePlacements) => allowMultiplePlacements === multiplePlacements.perChoice;\n\n render() {\n const {\n allowMultiplePlacements,\n classes,\n className,\n choice,\n deleteFocusedEl,\n focusedEl,\n index,\n onDelete,\n connectDragSource,\n connectDragPreview,\n imageSupport,\n spellCheck,\n toolbarOpts,\n error,\n maxImageWidth,\n maxImageHeight,\n uploadSoundSupport,\n } = this.props;\n\n const draggable = canDrag(this.props);\n\n const showRemoveAfterPlacing = this.isCheckboxShown(allowMultiplePlacements);\n\n return (\n <Card className={classNames(classes.choice, className)}>\n <CardActions className={classes.actions}>\n {connectDragSource(\n <span className={classNames(classes.dragHandle, draggable === false && classes.dragDisabled)}>\n <DragHandle color={draggable ? 'primary' : 'disabled'} />\n </span>,\n )}\n </CardActions>\n {connectDragPreview(\n <span>\n <InputHeader\n imageSupport={imageSupport}\n focusedEl={focusedEl}\n deleteFocusedEl={deleteFocusedEl}\n index={index}\n label={choice.content}\n onChange={this.changeContent}\n onDelete={onDelete}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n error={error}\n maxImageWidth={maxImageWidth}\n maxImageHeight={maxImageHeight}\n uploadSoundSupport={uploadSoundSupport}\n />\n {error && <div className={classes.errorText}>{error}</div>}\n </span>,\n )}\n\n <CardActions className={classes.actions}>\n <DeleteButton label={'delete'} onClick={onDelete} />\n {showRemoveAfterPlacing && (\n <Checkbox\n mini\n label={'Remove after placing'}\n checked={choice.categoryCount === 1}\n onChange={this.changeCategoryCount}\n />\n )}\n </CardActions>\n </Card>\n );\n }\n}\nconst styles = (theme) => ({\n actions: {\n padding: 0,\n justifyContent: 'space-between',\n },\n choice: {\n padding: theme.spacing.unit,\n overflow: 'visible',\n },\n dragHandle: {\n cursor: 'move',\n },\n dragDisabled: {\n cursor: 'inherit',\n },\n errorText: {\n fontSize: '11px',\n color: 'red',\n paddingBottom: '5px',\n },\n});\n\nconst StyledChoice = withStyles(styles)(Choice);\n\nexport const spec = {\n canDrag,\n beginDrag: (props) => {\n const out = {\n id: props.choice.id,\n };\n log('[beginDrag] out:', out);\n return out;\n },\n endDrag: (props, monitor) => {\n if (!monitor.didDrop()) {\n const item = monitor.getItem();\n if (item.categoryId) {\n log('wasnt droppped - what to do?');\n props.onRemoveChoice(item);\n }\n }\n },\n};\n\nconst DraggableChoice = DragSource(\n ({ uid }) => uid,\n spec,\n (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n connectDragPreview: connect.dragPreview(),\n isDragging: monitor.isDragging(),\n }),\n)(StyledChoice);\n\nexport default uid.withUid(DraggableChoice);\n"],"file":"choice.js"}
|
|
@@ -62,6 +62,9 @@ var Choices = /*#__PURE__*/function (_React$Component) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
65
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
|
|
66
|
+
focusedEl: null
|
|
67
|
+
});
|
|
65
68
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeChoice", function (choice) {
|
|
66
69
|
var _this$props = _this.props,
|
|
67
70
|
choices = _this$props.choices,
|
|
@@ -86,7 +89,8 @@ var Choices = /*#__PURE__*/function (_React$Component) {
|
|
|
86
89
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addChoice", function () {
|
|
87
90
|
var _this$props2 = _this.props,
|
|
88
91
|
onModelChanged = _this$props2.onModelChanged,
|
|
89
|
-
model = _this$props2.model
|
|
92
|
+
model = _this$props2.model,
|
|
93
|
+
oldChoices = _this$props2.choices;
|
|
90
94
|
|
|
91
95
|
var id = _configUi.choiceUtils.firstAvailableIndex(model.choices.map(function (a) {
|
|
92
96
|
return a.id;
|
|
@@ -96,8 +100,18 @@ var Choices = /*#__PURE__*/function (_React$Component) {
|
|
|
96
100
|
id: id,
|
|
97
101
|
content: 'Choice ' + id
|
|
98
102
|
};
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
|
|
104
|
+
_this.setState({
|
|
105
|
+
focusedEl: oldChoices.length
|
|
106
|
+
}, function () {
|
|
107
|
+
onModelChanged({
|
|
108
|
+
choices: model.choices.concat([data])
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteFocusedEl", function () {
|
|
113
|
+
_this.setState({
|
|
114
|
+
focusedEl: null
|
|
101
115
|
});
|
|
102
116
|
});
|
|
103
117
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoice", function (choice) {
|
|
@@ -122,6 +136,7 @@ var Choices = /*#__PURE__*/function (_React$Component) {
|
|
|
122
136
|
value: function render() {
|
|
123
137
|
var _this2 = this;
|
|
124
138
|
|
|
139
|
+
var focusedEl = this.state.focusedEl;
|
|
125
140
|
var _this$props4 = this.props,
|
|
126
141
|
classes = _this$props4.classes,
|
|
127
142
|
className = _this$props4.className,
|
|
@@ -172,8 +187,11 @@ var Choices = /*#__PURE__*/function (_React$Component) {
|
|
|
172
187
|
}, choices.map(function (h, index) {
|
|
173
188
|
return /*#__PURE__*/_react["default"].createElement(_choice["default"], {
|
|
174
189
|
choice: h,
|
|
190
|
+
focusedEl: focusedEl,
|
|
191
|
+
deleteFocusedEl: _this2.deleteFocusedEl,
|
|
175
192
|
correctResponseCount: h.correctResponseCount,
|
|
176
193
|
allowMultiplePlacements: allowMultiplePlacementsEnabled,
|
|
194
|
+
index: index,
|
|
177
195
|
key: index,
|
|
178
196
|
imageSupport: imageSupport,
|
|
179
197
|
onChange: _this2.changeChoice,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/design/choices/index.jsx"],"names":["Choices","choice","props","choices","onModelChanged","index","findIndex","h","id","splice","count","c","categoryCount","model","utils","firstAvailableIndex","map","a","data","content","concat","correctResponse","classes","className","imageSupport","uploadSoundSupport","spellCheck","toolbarOpts","configuration","defaultImageMaxWidth","defaultImageMaxHeight","errors","allowMultiplePlacementsEnabled","choicesError","choicesErrors","maxChoices","maxImageWidth","maxImageHeight","categoryCountIsOne","allChoicesHaveCount","choiceHolderStyle","gridTemplateColumns","categoriesPerRow","addChoice","length","errorText","choiceHolder","correctResponseCount","changeChoice","deleteChoice","React","Component","PropTypes","object","isRequired","string","array","func","shape","add","styles","theme","paddingTop","spacing","unit","paddingBottom","display","gridRowGap","gridColumnGap","label","fontSize","color","padding"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;A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B,EAAAA,WAAW,EAAEyB,sBAAUC;AAfN,C;iCADRrD,O,kBAmBW,E;;AAoGxB,IAAM4D,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBf,IAAAA,YAAY,EAAE;AACZgB,MAAAA,UAAU,EAAED,KAAK,CAACE,OAAN,CAAcC,IADd;AAEZC,MAAAA,aAAa,EAAEJ,KAAK,CAACE,OAAN,CAAcC,IAFjB;AAGZE,MAAAA,OAAO,EAAE,MAHG;AAIZC,MAAAA,UAAU,YAAKN,KAAK,CAACE,OAAN,CAAcC,IAAnB,OAJE;AAKZI,MAAAA,aAAa,YAAKP,KAAK,CAACE,OAAN,CAAcC,IAAnB;AALD,KADW;AAQzB7D,IAAAA,OAAO,EAAE;AACP2D,MAAAA,UAAU,EAAED,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB,CAD1B;AAEPC,MAAAA,aAAa,EAAEJ,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB;AAF7B,KARgB;AAYzBK,IAAAA,KAAK,EAAE,EAZkB;AAazBxB,IAAAA,SAAS,EAAE;AACTyB,MAAAA,QAAQ,EAAE,MADD;AAETC,MAAAA,KAAK,EAAE,KAFE;AAGTC,MAAAA,OAAO,EAAE;AAHA;AAbc,GAAZ;AAAA,CAAf;;eAmBe,wBAAWZ,MAAX,EAAmB5D,OAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { Divider } from '../buttons';\nimport classNames from 'classnames';\nimport Choice from './choice';\nimport Header from '../header';\nimport every from 'lodash/every';\nimport Config from './config';\nimport { choiceUtils as utils } from '@pie-lib/config-ui';\nimport { removeAllChoices } from '@pie-lib/categorize';\n\nexport class Choices extends React.Component {\n static propTypes = {\n model: PropTypes.object.isRequired,\n configuration: PropTypes.object.isRequired,\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n choices: PropTypes.array.isRequired,\n onModelChanged: PropTypes.func.isRequired,\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 toolbarOpts: PropTypes.object,\n };\n\n static defaultProps = {};\n\n changeChoice = (choice) => {\n const { choices, onModelChanged } = this.props;\n const index = choices.findIndex((h) => h.id === choice.id);\n if (index !== -1) {\n choices.splice(index, 1, choice);\n onModelChanged({ choices });\n }\n };\n\n allChoicesHaveCount = (count) => {\n const { choices } = this.props;\n return every(choices, (c) => c.categoryCount === count);\n };\n\n addChoice = () => {\n const { onModelChanged, model } = this.props;\n\n const id = utils.firstAvailableIndex(\n model.choices.map((a) => a.id),\n 0,\n );\n const data = { id, content: 'Choice ' + id };\n\n onModelChanged({ choices: model.choices.concat([data]) });\n };\n\n deleteChoice = (choice) => {\n const { model, onModelChanged } = this.props;\n const index = model.choices.findIndex((a) => a.id === choice.id);\n if (index !== -1) {\n model.choices.splice(index, 1);\n model.correctResponse = removeAllChoices(choice.id, model.correctResponse);\n onModelChanged(model);\n }\n };\n\n render() {\n const {\n classes,\n className,\n choices,\n model,\n imageSupport,\n uploadSoundSupport,\n onModelChanged,\n spellCheck,\n toolbarOpts,\n configuration,\n defaultImageMaxWidth,\n defaultImageMaxHeight,\n } = this.props;\n const { errors, allowMultiplePlacementsEnabled } = model;\n const { choicesError, choicesErrors } = errors || {};\n const { maxChoices, maxImageWidth = {}, maxImageHeight = {} } = configuration || {};\n\n const categoryCountIsOne = this.allChoicesHaveCount(1);\n const choiceHolderStyle = {\n gridTemplateColumns: `repeat(${model.categoriesPerRow}, 1fr)`,\n };\n\n return (\n <div className={classNames(classes.choices, className)}>\n <Header\n label=\"Choices\"\n buttonLabel=\"ADD A CHOICE\"\n onAdd={this.addChoice}\n buttonDisabled={maxChoices && choices && maxChoices === choices.length}\n />\n {choicesError && <div className={classes.errorText}>{choicesError}</div>}\n <Config\n config={model}\n onModelChanged={onModelChanged}\n spellCheck={spellCheck}\n />\n <div className={classes.choiceHolder} style={choiceHolderStyle}>\n {choices.map((h, index) => (\n <Choice\n choice={h}\n correctResponseCount={h.correctResponseCount}\n allowMultiplePlacements={allowMultiplePlacementsEnabled}\n key={index}\n imageSupport={imageSupport}\n onChange={this.changeChoice}\n onDelete={() => this.deleteChoice(h)}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n error={choicesErrors && choicesErrors[h.id]}\n maxImageWidth={(maxImageWidth && maxImageWidth.choice) || defaultImageMaxWidth}\n maxImageHeight={(maxImageHeight && maxImageHeight.choice) || defaultImageMaxHeight}\n uploadSoundSupport={uploadSoundSupport}\n />\n ))}\n </div>\n <Divider />\n </div>\n );\n }\n}\nconst styles = (theme) => ({\n choiceHolder: {\n paddingTop: theme.spacing.unit,\n paddingBottom: theme.spacing.unit,\n display: 'grid',\n gridRowGap: `${theme.spacing.unit}px`,\n gridColumnGap: `${theme.spacing.unit}px`,\n },\n choices: {\n paddingTop: theme.spacing.unit * 2,\n paddingBottom: theme.spacing.unit * 2,\n },\n label: {},\n errorText: {\n fontSize: '12px',\n color: 'red',\n padding: '5px 0',\n },\n});\nexport default withStyles(styles)(Choices);\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/design/choices/index.jsx"],"names":["Choices","focusedEl","choice","props","choices","onModelChanged","index","findIndex","h","id","splice","count","c","categoryCount","model","oldChoices","utils","firstAvailableIndex","map","a","data","content","setState","length","concat","correctResponse","state","classes","className","imageSupport","uploadSoundSupport","spellCheck","toolbarOpts","configuration","defaultImageMaxWidth","defaultImageMaxHeight","errors","allowMultiplePlacementsEnabled","choicesError","choicesErrors","maxChoices","maxImageWidth","maxImageHeight","categoryCountIsOne","allChoicesHaveCount","choiceHolderStyle","gridTemplateColumns","categoriesPerRow","addChoice","errorText","choiceHolder","deleteFocusedEl","correctResponseCount","changeChoice","deleteChoice","React","Component","PropTypes","object","isRequired","string","array","func","shape","add","styles","theme","paddingTop","spacing","unit","paddingBottom","display","gridRowGap","gridColumnGap","label","fontSize","color","padding"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;IAEaA,O;;;;;;;;;;;;;;;8FAqBH;AACNC,MAAAA,SAAS,EAAE;AADL,K;qGAIO,UAACC,MAAD,EAAY;AACzB,wBAAoC,MAAKC,KAAzC;AAAA,UAAQC,OAAR,eAAQA,OAAR;AAAA,UAAiBC,cAAjB,eAAiBA,cAAjB;AACA,UAAMC,KAAK,GAAGF,OAAO,CAACG,SAAR,CAAkB,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACC,EAAF,KAASP,MAAM,CAACO,EAAvB;AAAA,OAAlB,CAAd;;AACA,UAAIH,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChBF,QAAAA,OAAO,CAACM,MAAR,CAAeJ,KAAf,EAAsB,CAAtB,EAAyBJ,MAAzB;AACAG,QAAAA,cAAc,CAAC;AAAED,UAAAA,OAAO,EAAPA;AAAF,SAAD,CAAd;AACD;AACF,K;4GAEqB,UAACO,KAAD,EAAW;AAC/B,UAAQP,OAAR,GAAoB,MAAKD,KAAzB,CAAQC,OAAR;AACA,aAAO,uBAAMA,OAAN,EAAe,UAACQ,CAAD;AAAA,eAAOA,CAAC,CAACC,aAAF,KAAoBF,KAA3B;AAAA,OAAf,CAAP;AACD,K;kGAEW,YAAM;AAChB,yBAAuD,MAAKR,KAA5D;AAAA,UAAQE,cAAR,gBAAQA,cAAR;AAAA,UAAwBS,KAAxB,gBAAwBA,KAAxB;AAAA,UAAwCC,UAAxC,gBAA+BX,OAA/B;;AAEA,UAAMK,EAAE,GAAGO,sBAAMC,mBAAN,CACTH,KAAK,CAACV,OAAN,CAAcc,GAAd,CAAkB,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACV,EAAT;AAAA,OAAlB,CADS,EAET,CAFS,CAAX;;AAIA,UAAMW,IAA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AS,EAAE;AACT0B,MAAAA,QAAQ,EAAE,MADD;AAETC,MAAAA,KAAK,EAAE,KAFE;AAGTC,MAAAA,OAAO,EAAE;AAHA;AAbc,GAAZ;AAAA,CAAf;;eAmBe,wBAAWZ,MAAX,EAAmBjE,OAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { Divider } from '../buttons';\nimport classNames from 'classnames';\nimport Choice from './choice';\nimport Header from '../header';\nimport every from 'lodash/every';\nimport Config from './config';\nimport { choiceUtils as utils } from '@pie-lib/config-ui';\nimport { removeAllChoices } from '@pie-lib/categorize';\n\nexport class Choices extends React.Component {\n static propTypes = {\n model: PropTypes.object.isRequired,\n configuration: PropTypes.object.isRequired,\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n choices: PropTypes.array.isRequired,\n onModelChanged: PropTypes.func.isRequired,\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 toolbarOpts: PropTypes.object,\n };\n\n static defaultProps = {};\n\n state = {\n focusedEl: null,\n };\n\n changeChoice = (choice) => {\n const { choices, onModelChanged } = this.props;\n const index = choices.findIndex((h) => h.id === choice.id);\n if (index !== -1) {\n choices.splice(index, 1, choice);\n onModelChanged({ choices });\n }\n };\n\n allChoicesHaveCount = (count) => {\n const { choices } = this.props;\n return every(choices, (c) => c.categoryCount === count);\n };\n\n addChoice = () => {\n const { onModelChanged, model, choices: oldChoices } = this.props;\n\n const id = utils.firstAvailableIndex(\n model.choices.map((a) => a.id),\n 0,\n );\n const data = { id, content: 'Choice ' + id };\n\n this.setState(\n {\n focusedEl: oldChoices.length,\n },\n () => {\n onModelChanged({ choices: model.choices.concat([data]) });\n }\n );\n };\n\n deleteFocusedEl = () => {\n this.setState({\n focusedEl: null,\n });\n };\n\n deleteChoice = (choice) => {\n const { model, onModelChanged } = this.props;\n const index = model.choices.findIndex((a) => a.id === choice.id);\n if (index !== -1) {\n model.choices.splice(index, 1);\n model.correctResponse = removeAllChoices(choice.id, model.correctResponse);\n onModelChanged(model);\n }\n };\n\n render() {\n const { focusedEl } = this.state;\n const {\n classes,\n className,\n choices,\n model,\n imageSupport,\n uploadSoundSupport,\n onModelChanged,\n spellCheck,\n toolbarOpts,\n configuration,\n defaultImageMaxWidth,\n defaultImageMaxHeight,\n } = this.props;\n const { errors, allowMultiplePlacementsEnabled } = model;\n const { choicesError, choicesErrors } = errors || {};\n const { maxChoices, maxImageWidth = {}, maxImageHeight = {} } = configuration || {};\n\n const categoryCountIsOne = this.allChoicesHaveCount(1);\n const choiceHolderStyle = {\n gridTemplateColumns: `repeat(${model.categoriesPerRow}, 1fr)`,\n };\n\n return (\n <div className={classNames(classes.choices, className)}>\n <Header\n label=\"Choices\"\n buttonLabel=\"ADD A CHOICE\"\n onAdd={this.addChoice}\n buttonDisabled={maxChoices && choices && maxChoices === choices.length}\n />\n {choicesError && <div className={classes.errorText}>{choicesError}</div>}\n <Config\n config={model}\n onModelChanged={onModelChanged}\n spellCheck={spellCheck}\n />\n <div className={classes.choiceHolder} style={choiceHolderStyle}>\n {choices.map((h, index) => {\n return (\n <Choice\n choice={h}\n focusedEl={focusedEl}\n deleteFocusedEl={this.deleteFocusedEl}\n correctResponseCount={h.correctResponseCount}\n allowMultiplePlacements={allowMultiplePlacementsEnabled}\n index={index}\n key={index}\n imageSupport={imageSupport}\n onChange={this.changeChoice}\n onDelete={() => this.deleteChoice(h)}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheck}\n error={choicesErrors && choicesErrors[h.id]}\n maxImageWidth={\n (maxImageWidth && maxImageWidth.choice) ||\n defaultImageMaxWidth\n }\n maxImageHeight={\n (maxImageHeight && maxImageHeight.choice) ||\n defaultImageMaxHeight\n }\n uploadSoundSupport={uploadSoundSupport}\n />\n );\n })}\n </div>\n <Divider />\n </div>\n );\n }\n}\nconst styles = (theme) => ({\n choiceHolder: {\n paddingTop: theme.spacing.unit,\n paddingBottom: theme.spacing.unit,\n display: 'grid',\n gridRowGap: `${theme.spacing.unit}px`,\n gridColumnGap: `${theme.spacing.unit}px`,\n },\n choices: {\n paddingTop: theme.spacing.unit * 2,\n paddingBottom: theme.spacing.unit * 2,\n },\n label: {},\n errorText: {\n fontSize: '12px',\n color: 'red',\n padding: '5px 0',\n },\n});\nexport default withStyles(styles)(Choices);\n"],"file":"index.js"}
|