@pie-element/categorize 6.9.8 → 6.9.10-beta.1443

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/configure/CHANGELOG.md +385 -0
  3. package/configure/lib/defaults.js +50 -3
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/design/builder.js +8 -5
  6. package/configure/lib/design/builder.js.map +1 -1
  7. package/configure/lib/design/buttons.js +5 -3
  8. package/configure/lib/design/buttons.js.map +1 -1
  9. package/configure/lib/design/categories/RowLabel.js +68 -0
  10. package/configure/lib/design/categories/RowLabel.js.map +1 -0
  11. package/configure/lib/design/categories/alternateResponses.js +121 -17
  12. package/configure/lib/design/categories/alternateResponses.js.map +1 -1
  13. package/configure/lib/design/categories/category.js +50 -6
  14. package/configure/lib/design/categories/category.js.map +1 -1
  15. package/configure/lib/design/categories/choice-preview.js +17 -4
  16. package/configure/lib/design/categories/choice-preview.js.map +1 -1
  17. package/configure/lib/design/categories/droppable-placeholder.js +23 -3
  18. package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
  19. package/configure/lib/design/categories/index.js +165 -72
  20. package/configure/lib/design/categories/index.js.map +1 -1
  21. package/configure/lib/design/choices/choice.js +80 -13
  22. package/configure/lib/design/choices/choice.js.map +1 -1
  23. package/configure/lib/design/choices/config.js +8 -113
  24. package/configure/lib/design/choices/config.js.map +1 -1
  25. package/configure/lib/design/choices/index.js +83 -10
  26. package/configure/lib/design/choices/index.js.map +1 -1
  27. package/configure/lib/design/header.js +17 -5
  28. package/configure/lib/design/header.js.map +1 -1
  29. package/configure/lib/design/index.js +158 -61
  30. package/configure/lib/design/index.js.map +1 -1
  31. package/configure/lib/design/input-header.js +57 -11
  32. package/configure/lib/design/input-header.js.map +1 -1
  33. package/configure/lib/index.js +17 -3
  34. package/configure/lib/index.js.map +1 -1
  35. package/configure/lib/main.js +3 -1
  36. package/configure/lib/main.js.map +1 -1
  37. package/configure/lib/utils.js +27 -0
  38. package/configure/lib/utils.js.map +1 -0
  39. package/configure/package.json +9 -9
  40. package/controller/CHANGELOG.md +89 -0
  41. package/controller/lib/defaults.js +18 -0
  42. package/controller/lib/defaults.js.map +1 -1
  43. package/controller/lib/index.js +160 -24
  44. package/controller/lib/index.js.map +1 -1
  45. package/controller/lib/utils.js +60 -0
  46. package/controller/lib/utils.js.map +1 -0
  47. package/controller/package.json +4 -4
  48. package/docs/config-schema.json +181 -0
  49. package/docs/config-schema.json.md +141 -1
  50. package/docs/demo/config.js +2 -2
  51. package/docs/demo/generate.js +3 -3
  52. package/docs/demo/index.html +1 -1
  53. package/docs/pie-schema.json +48 -5
  54. package/docs/pie-schema.json.md +36 -5
  55. package/lib/categorize/categories.js +14 -4
  56. package/lib/categorize/categories.js.map +1 -1
  57. package/lib/categorize/category.js +3 -3
  58. package/lib/categorize/category.js.map +1 -1
  59. package/lib/categorize/choice.js +3 -3
  60. package/lib/categorize/choice.js.map +1 -1
  61. package/lib/categorize/choices.js +16 -7
  62. package/lib/categorize/choices.js.map +1 -1
  63. package/lib/categorize/droppable-placeholder.js +5 -3
  64. package/lib/categorize/droppable-placeholder.js.map +1 -1
  65. package/lib/categorize/grid-content.js +2 -2
  66. package/lib/categorize/grid-content.js.map +1 -1
  67. package/lib/categorize/index.js +36 -17
  68. package/lib/categorize/index.js.map +1 -1
  69. package/lib/index.js +3 -0
  70. package/lib/index.js.map +1 -1
  71. package/package.json +8 -8
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = exports.spec = exports.DroppablePlaceHolder = void 0;
8
+ exports.spec = exports["default"] = exports.DroppablePlaceHolder = void 0;
9
9
 
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
 
@@ -59,12 +59,17 @@ var Helper = (0, _styles.withStyles)(function () {
59
59
  });
60
60
 
61
61
  var Previews = function Previews(_ref2) {
62
- var choices = _ref2.choices,
62
+ var alternateResponseIndex = _ref2.alternateResponseIndex,
63
+ category = _ref2.category,
64
+ choices = _ref2.choices,
63
65
  onDeleteChoice = _ref2.onDeleteChoice;
64
66
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, choices.map(function (c, index) {
65
67
  return c && /*#__PURE__*/_react["default"].createElement(_choicePreview["default"], {
68
+ alternateResponseIndex: alternateResponseIndex,
69
+ category: category,
66
70
  choice: c,
67
71
  key: index,
72
+ choiceIndex: index,
68
73
  onDelete: function onDelete(choice) {
69
74
  return onDeleteChoice(choice, index);
70
75
  }
@@ -73,6 +78,8 @@ var Previews = function Previews(_ref2) {
73
78
  };
74
79
 
75
80
  Previews.propTypes = {
81
+ alternateResponseIndex: _propTypes["default"].number,
82
+ category: _propTypes["default"].object,
76
83
  choices: _propTypes["default"].array,
77
84
  onDeleteChoice: _propTypes["default"].func
78
85
  };
@@ -91,7 +98,9 @@ var DroppablePlaceHolder = /*#__PURE__*/function (_React$Component) {
91
98
  key: "render",
92
99
  value: function render() {
93
100
  var _this$props = this.props,
101
+ alternateResponseIndex = _this$props.alternateResponseIndex,
94
102
  isOver = _this$props.isOver,
103
+ category = _this$props.category,
95
104
  choices = _this$props.choices,
96
105
  classes = _this$props.classes,
97
106
  className = _this$props.className,
@@ -103,6 +112,8 @@ var DroppablePlaceHolder = /*#__PURE__*/function (_React$Component) {
103
112
  isOver: isOver,
104
113
  className: classes.placeHolder
105
114
  }, (choices || []).length === 0 ? /*#__PURE__*/_react["default"].createElement(Helper, null) : /*#__PURE__*/_react["default"].createElement(Previews, {
115
+ alternateResponseIndex: alternateResponseIndex,
116
+ category: category,
106
117
  choices: choices,
107
118
  onDeleteChoice: onDeleteChoice
108
119
  }))));
@@ -113,11 +124,14 @@ var DroppablePlaceHolder = /*#__PURE__*/function (_React$Component) {
113
124
 
114
125
  exports.DroppablePlaceHolder = DroppablePlaceHolder;
115
126
  (0, _defineProperty2["default"])(DroppablePlaceHolder, "propTypes", {
127
+ alternateResponseIndex: _propTypes["default"].number,
128
+ category: _propTypes["default"].object,
116
129
  classes: _propTypes["default"].object.isRequired,
117
130
  className: _propTypes["default"].string,
118
131
  connectDropTarget: _propTypes["default"].func.isRequired,
119
132
  choices: _propTypes["default"].array,
120
133
  onDropChoice: _propTypes["default"].func.isRequired,
134
+ onMoveChoice: _propTypes["default"].func,
121
135
  isOver: _propTypes["default"].bool,
122
136
  onDeleteChoice: _propTypes["default"].func,
123
137
  categoryId: _propTypes["default"].string.isRequired
@@ -142,7 +156,13 @@ var spec = {
142
156
  drop: function drop(props, monitor) {
143
157
  log('[drop] props: ', props);
144
158
  var item = monitor.getItem();
145
- props.onDropChoice(item, props.categoryId);
159
+
160
+ if (item.from && item.alternateResponseIndex === props.alternateResponseIndex) {
161
+ props.onMoveChoice(item.choiceId, item.from, props.categoryId, item.choiceIndex, item.alternateResponseIndex);
162
+ } else if (!item.from) {
163
+ // avoid dropping choice when user tries to move it to an alternate with other index
164
+ props.onDropChoice(item, props.categoryId);
165
+ }
146
166
  },
147
167
  canDrop: function canDrop(props
148
168
  /*, monitor*/
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/design/categories/droppable-placeholder.jsx"],"names":["log","Helper","helper","display","alignItems","fontSize","color","width","height","classes","Previews","choices","onDeleteChoice","map","c","index","choice","propTypes","PropTypes","array","func","DroppablePlaceHolder","props","isOver","className","connectDropTarget","droppablePlaceholder","placeHolder","length","React","Component","object","isRequired","string","onDropChoice","bool","categoryId","styles","minHeight","Styled","spec","drop","monitor","item","getItem","canDrop","disabled","WithTarget","uid","connect","dropTarget","withUid"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,mCAAN,CAAZ;AAEA,IAAMC,MAAM,GAAG,wBAAW;AAA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AAE,cAACnB,KAAD,EAAQoB,OAAR,EAAoB;AACxB1C,IAAAA,GAAG,CAAC,gBAAD,EAAmBsB,KAAnB,CAAH;AACA,QAAMqB,IAAI,GAAGD,OAAO,CAACE,OAAR,EAAb;AACAtB,IAAAA,KAAK,CAACY,YAAN,CAAmBS,IAAnB,EAAyBrB,KAAK,CAACc,UAA/B;AACD,GALiB;AAMlBS,EAAAA,OAAO,EAAE,iBAACvB;AAAM;AAAP,IAAyB;AAChC,WAAO,CAACA,KAAK,CAACwB,QAAd;AACD;AARiB,CAAb;;AAWP,IAAMC,UAAU,GAAG,0BAAW;AAAA,MAAGC,GAAH,SAAGA,GAAH;AAAA,SAAaA,GAAb;AAAA,CAAX,EAA6BR,IAA7B,EAAmC,UAACS,OAAD,EAAUP,OAAV;AAAA,SAAuB;AAC3EjB,IAAAA,iBAAiB,EAAEwB,OAAO,CAACC,UAAR,EADwD;AAE3E3B,IAAAA,MAAM,EAAEmB,OAAO,CAACnB,MAAR;AAFmE,GAAvB;AAAA,CAAnC,EAGfgB,MAHe,CAAnB;;eAKeS,UAAIG,OAAJ,CAAYJ,UAAZ,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport ChoicePreview from './choice-preview';\nimport { DropTarget } from 'react-dnd';\nimport { uid, PlaceHolder } from '@pie-lib/drag';\nimport debug from 'debug';\n\nconst log = debug('@pie-element:categorize:configure');\n\nconst Helper = withStyles(() => ({\n helper: {\n display: 'flex',\n alignItems: 'center',\n fontSize: '12px',\n color: 'rgba(0,0,0,0.4)',\n width: '100%',\n height: '100%'\n }\n}))(({ classes }) => (\n <div className={classes.helper}>Drag your correct answers here</div>\n));\n\nconst Previews = ({ choices, onDeleteChoice }) => (\n <React.Fragment>\n {choices.map((c, index) =>\n c && <ChoicePreview\n choice={c}\n key={index}\n onDelete={choice => onDeleteChoice(choice, index)}\n />\n )}\n </React.Fragment>\n);\n\nPreviews.propTypes = {\n choices: PropTypes.array,\n onDeleteChoice: PropTypes.func\n};\n\nexport class DroppablePlaceHolder extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n connectDropTarget: PropTypes.func.isRequired,\n choices: PropTypes.array,\n onDropChoice: PropTypes.func.isRequired,\n isOver: PropTypes.bool,\n onDeleteChoice: PropTypes.func,\n categoryId: PropTypes.string.isRequired\n };\n\n static defaultProps = {};\n render() {\n const {\n isOver,\n choices,\n classes,\n className,\n connectDropTarget,\n onDeleteChoice\n } = this.props;\n\n return connectDropTarget(\n <div className={classNames(classes.droppablePlaceholder, className)}>\n <PlaceHolder isOver={isOver} className={classes.placeHolder}>\n {(choices || []).length === 0 ? (\n <Helper />\n ) : (\n <Previews choices={choices} onDeleteChoice={onDeleteChoice} />\n )}\n </PlaceHolder>\n </div>\n );\n }\n}\nconst styles = () => ({\n droppablePlaceholder: {\n minHeight: '100px'\n },\n placeHolder: {\n width: '100%',\n minHeight: '100px',\n height: 'auto'\n }\n});\n\nconst Styled = withStyles(styles)(DroppablePlaceHolder);\n\nexport const spec = {\n drop: (props, monitor) => {\n log('[drop] props: ', props);\n const item = monitor.getItem();\n props.onDropChoice(item, props.categoryId);\n },\n canDrop: (props /*, monitor*/) => {\n return !props.disabled;\n }\n};\n\nconst WithTarget = DropTarget(({ uid }) => uid, spec, (connect, monitor) => ({\n connectDropTarget: connect.dropTarget(),\n isOver: monitor.isOver()\n}))(Styled);\n\nexport default uid.withUid(WithTarget);\n"],"file":"droppable-placeholder.js"}
1
+ {"version":3,"sources":["../../../src/design/categories/droppable-placeholder.jsx"],"names":["log","Helper","helper","display","alignItems","fontSize","color","width","height","classes","Previews","alternateResponseIndex","category","choices","onDeleteChoice","map","c","index","choice","propTypes","PropTypes","number","object","array","func","DroppablePlaceHolder","props","isOver","className","connectDropTarget","droppablePlaceholder","placeHolder","length","React","Component","isRequired","string","onDropChoice","onMoveChoice","bool","categoryId","styles","minHeight","Styled","spec","drop","monitor","item","getItem","from","choiceId","choiceIndex","canDrop","disabled","WithTarget","uid","connect","dropTarget","withUid"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,mCAAN,CAAZ;AAEA,IAAMC,MAAM,GAAG,wBAAW;AAAA,SAAO;AAC/BC,IAAAA,MAAM,EAAE;AACNC,MAAAA,OAAO,EAAE,MADH;AAENC,MAAAA,UAAU,EAAE,QAFN;AAGNC,MAAAA,QAAQ,EAAE,MAHJ;AAINC,MAAAA,KAAK,EAAE,iBAJD;AAKNC,MAAAA,KAAK,EAAE,MALD;AAMNC,MAAAA,MAAM,EAAE;AANF;AADuB,GAAP;AAAA,CAAX,EASX;AAAA,MAAGC,OAAH,QAAGA,OAAH;AAAA,sBAAiB;AAAK,IAAA,SAAS,EAAEA,OAAO,CAACP;AAAxB,sCAAjB;AAAA,CATW,CAAf;;AAWA,IAAMQ,QAAQ,GAAG,SAAXA,QAAW;AAAA,MAAGC,sBAAH,SAAGA,sBAAH;AAAA,MAA2BC,QAA3B,SAA2BA,QAA3B;AAAA,MAAqCC,OAArC,SAAqCA,OAArC;AAAA,MAA8CC,cAA9C,SAA8CA,cAA9C;AAAA,sBACf,gCAAC,iBAAD,CAAO,QAAP,QACGD,OAAO,CAACE,GAAR,CACC,UAACC,CAAD,EAAIC,KAAJ;AAAA,WACED,CAAC,iBACC,gCAAC,yBAAD;AACE,MAAA,sBAAsB,EAAEL,sBAD1B;AAEE,MAAA,QAAQ,EAAEC,QAFZ;AAGE,MAAA,MAAM,EAAEI,CAHV;AAIE,MAAA,GAAG,EAAEC,KAJP;AAKE,MAAA,WAAW,EAAEA,KALf;AAME,MAAA,QAAQ,EAAE,kBAACC,MAAD;AAAA,eAAYJ,cAAc,CAACI,MAAD,EAASD,KAAT,CAA1B;AAAA;AANZ,MAFJ;AAAA,GADD,CADH,CADe;AAAA,CAAjB;;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;AACD,KAFD,MAEO,IAAI,CAACoC,IAAI,CAACE,IAAV,EAAe;AACpB;AACAvB,MAAAA,KAAK,CAACW,YAAN,CAAmBU,IAAnB,EAAyBrB,KAAK,CAACc,UAA/B;AACD;AACF,GAXiB;AAYlBY,EAAAA,OAAO,EAAE,iBAAC1B;AAAM;AAAP,IAAyB;AAChC,WAAO,CAACA,KAAK,CAAC2B,QAAd;AACD;AAdiB,CAAb;;AAiBP,IAAMC,UAAU,GAAG,0BACjB;AAAA,MAAGC,GAAH,SAAGA,GAAH;AAAA,SAAaA,GAAb;AAAA,CADiB,EAEjBX,IAFiB,EAGjB,UAACY,OAAD,EAAUV,OAAV;AAAA,SAAuB;AACrBjB,IAAAA,iBAAiB,EAAE2B,OAAO,CAACC,UAAR,EADE;AAErB9B,IAAAA,MAAM,EAAEmB,OAAO,CAACnB,MAAR;AAFa,GAAvB;AAAA,CAHiB,EAOjBgB,MAPiB,CAAnB;;eASeY,UAAIG,OAAJ,CAAYJ,UAAZ,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport ChoicePreview from './choice-preview';\nimport { DropTarget } from 'react-dnd';\nimport { uid, PlaceHolder } from '@pie-lib/drag';\nimport debug from 'debug';\n\nconst log = debug('@pie-element:categorize:configure');\n\nconst Helper = withStyles(() => ({\n helper: {\n display: 'flex',\n alignItems: 'center',\n fontSize: '12px',\n color: 'rgba(0,0,0,0.4)',\n width: '100%',\n height: '100%',\n },\n}))(({ classes }) => <div className={classes.helper}>Drag your correct answers here</div>);\n\nconst Previews = ({ alternateResponseIndex, category, choices, onDeleteChoice }) => (\n <React.Fragment>\n {choices.map(\n (c, index) =>\n c && (\n <ChoicePreview\n alternateResponseIndex={alternateResponseIndex}\n category={category}\n choice={c}\n key={index}\n choiceIndex={index}\n onDelete={(choice) => onDeleteChoice(choice, index)}\n />\n ),\n )}\n </React.Fragment>\n);\n\nPreviews.propTypes = {\n alternateResponseIndex: PropTypes.number,\n category: PropTypes.object,\n choices: PropTypes.array,\n onDeleteChoice: PropTypes.func,\n};\n\nexport class DroppablePlaceHolder extends React.Component {\n static propTypes = {\n alternateResponseIndex: PropTypes.number,\n category: PropTypes.object,\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n connectDropTarget: PropTypes.func.isRequired,\n choices: PropTypes.array,\n onDropChoice: PropTypes.func.isRequired,\n onMoveChoice: PropTypes.func,\n isOver: PropTypes.bool,\n onDeleteChoice: PropTypes.func,\n categoryId: PropTypes.string.isRequired,\n };\n\n static defaultProps = {};\n render() {\n const { alternateResponseIndex, isOver, category, choices, classes, className, connectDropTarget, onDeleteChoice } =\n this.props;\n\n return connectDropTarget(\n <div className={classNames(classes.droppablePlaceholder, className)}>\n <PlaceHolder isOver={isOver} className={classes.placeHolder}>\n {(choices || []).length === 0 ? (\n <Helper />\n ) : (\n <Previews\n alternateResponseIndex={alternateResponseIndex}\n category={category}\n choices={choices}\n onDeleteChoice={onDeleteChoice}\n />\n )}\n </PlaceHolder>\n </div>,\n );\n }\n}\nconst styles = () => ({\n droppablePlaceholder: {\n minHeight: '100px',\n },\n placeHolder: {\n width: '100%',\n minHeight: '100px',\n height: 'auto',\n },\n});\n\nconst Styled = withStyles(styles)(DroppablePlaceHolder);\n\nexport const spec = {\n drop: (props, monitor) => {\n log('[drop] props: ', props);\n const item = monitor.getItem();\n\n if (item.from && item.alternateResponseIndex === props.alternateResponseIndex) {\n props.onMoveChoice(item.choiceId, item.from, props.categoryId, item.choiceIndex, item.alternateResponseIndex);\n } else if (!item.from){\n // avoid dropping choice when user tries to move it to an alternate with other index\n props.onDropChoice(item, props.categoryId);\n }\n },\n canDrop: (props /*, monitor*/) => {\n return !props.disabled;\n },\n};\n\nconst WithTarget = DropTarget(\n ({ uid }) => uid,\n spec,\n (connect, monitor) => ({\n connectDropTarget: connect.dropTarget(),\n isOver: monitor.isOver(),\n }),\n)(Styled);\n\nexport default uid.withUid(WithTarget);\n"],"file":"droppable-placeholder.js"}
@@ -39,11 +39,19 @@ var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
39
39
 
40
40
  var _classnames = _interopRequireDefault(require("classnames"));
41
41
 
42
+ var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
43
+
44
+ var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
45
+
46
+ var _categorize = require("@pie-lib/categorize");
47
+
42
48
  var _category = _interopRequireDefault(require("./category"));
43
49
 
44
50
  var _header = _interopRequireDefault(require("../header"));
45
51
 
46
- var _categorize = require("@pie-lib/categorize");
52
+ var _utils = require("../../utils");
53
+
54
+ var _RowLabel = require("./RowLabel");
47
55
 
48
56
  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); }; }
49
57
 
@@ -73,34 +81,20 @@ var styles = function styles(theme) {
73
81
  },
74
82
  rowLabelHolder: {
75
83
  width: '100%'
84
+ },
85
+ tooltip: {
86
+ fontSize: '12px',
87
+ whiteSpace: 'pre',
88
+ maxWidth: '500px'
89
+ },
90
+ errorText: {
91
+ fontSize: '12px',
92
+ color: 'red',
93
+ padding: '5px 0'
76
94
  }
77
95
  };
78
96
  };
79
97
 
80
- var RowLabel = (0, _styles.withStyles)(styles)(function (_ref) {
81
- var categoriesPerRow = _ref.categoriesPerRow,
82
- classes = _ref.classes,
83
- markup = _ref.markup,
84
- imageSupport = _ref.imageSupport,
85
- onChange = _ref.onChange,
86
- toolbarOpts = _ref.toolbarOpts;
87
- return /*#__PURE__*/_react["default"].createElement("div", {
88
- style: {
89
- gridColumn: "1/".concat(categoriesPerRow + 1),
90
- width: '100%'
91
- }
92
- }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
93
- className: classes.text
94
- }, "Row Label"), /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
95
- className: classes.rowLabelHolder,
96
- markup: markup,
97
- onChange: onChange,
98
- imageSupport: imageSupport,
99
- nonEmpty: false,
100
- toolbarOpts: toolbarOpts
101
- }));
102
- });
103
-
104
98
  var Categories = /*#__PURE__*/function (_React$Component) {
105
99
  (0, _inherits2["default"])(Categories, _React$Component);
106
100
 
@@ -116,17 +110,13 @@ var Categories = /*#__PURE__*/function (_React$Component) {
116
110
  }
117
111
 
118
112
  _this = _super.call.apply(_super, [this].concat(args));
119
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeCategoryColumns", function (event) {
120
- var numberValue = parseInt(event.target.value, 10);
121
-
122
- if (numberValue && numberValue >= 1 && numberValue <= 4) {
123
- _this.props.onModelChanged({
124
- categoriesPerRow: numberValue
125
- });
126
- }
113
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
114
+ focusedEl: null
127
115
  });
128
116
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "add", function () {
129
- var model = _this.props.model;
117
+ var _this$props = _this.props,
118
+ model = _this$props.model,
119
+ oldCategories = _this$props.categories;
130
120
  var categoriesPerRow = model.categoriesPerRow;
131
121
 
132
122
  var id = _configUi.choiceUtils.firstAvailableIndex(model.categories.map(function (a) {
@@ -144,15 +134,24 @@ var Categories = /*#__PURE__*/function (_React$Component) {
144
134
  rowLabels.push('');
145
135
  }
146
136
 
147
- _this.props.onModelChanged({
148
- rowLabels: rowLabels,
149
- categories: model.categories.concat([data])
137
+ _this.setState({
138
+ focusedEl: oldCategories.length
139
+ }, function () {
140
+ _this.props.onModelChanged({
141
+ rowLabels: rowLabels,
142
+ categories: model.categories.concat([data])
143
+ });
144
+ });
145
+ });
146
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteFocusedEl", function () {
147
+ _this.setState({
148
+ focusedEl: null
150
149
  });
151
150
  });
152
151
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "delete", function (category) {
153
- var _this$props = _this.props,
154
- model = _this$props.model,
155
- onModelChanged = _this$props.onModelChanged;
152
+ var _this$props2 = _this.props,
153
+ model = _this$props2.model,
154
+ onModelChanged = _this$props2.onModelChanged;
156
155
  var index = model.categories.findIndex(function (a) {
157
156
  return a.id === category.id;
158
157
  });
@@ -177,24 +176,68 @@ var Categories = /*#__PURE__*/function (_React$Component) {
177
176
  });
178
177
  }
179
178
  });
180
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addChoiceToCategory", function (choice, categoryId) {
181
- var _this$props2 = _this.props,
182
- model = _this$props2.model,
183
- onModelChanged = _this$props2.onModelChanged;
184
- var correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, categoryId, 0, model.correctResponse);
179
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addChoiceToCategory", function (addedChoice, categoryId) {
180
+ var _this$props3 = _this.props,
181
+ model = _this$props3.model,
182
+ onModelChanged = _this$props3.onModelChanged;
183
+
184
+ var _ref = model || {},
185
+ _ref$choices = _ref.choices,
186
+ choices = _ref$choices === void 0 ? [] : _ref$choices,
187
+ _ref$correctResponse = _ref.correctResponse,
188
+ correctResponse = _ref$correctResponse === void 0 ? [] : _ref$correctResponse;
189
+
190
+ var choice = (choices || []).find(function (choice) {
191
+ return choice.id === addedChoice.id;
192
+ });
193
+ correctResponse = (0, _categorize.moveChoiceToCategory)(addedChoice.id, undefined, categoryId, 0, model.correctResponse); // if multiplePlacements not allowed, ensure the consistency in the other categories
194
+
195
+ if (choice.categoryCount !== 0) {
196
+ correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(addedChoice, categoryId, correctResponse);
197
+ }
198
+
185
199
  onModelChanged({
186
200
  correctResponse: correctResponse
187
201
  });
188
202
  });
189
203
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteChoiceFromCategory", function (category, choice, choiceIndex) {
190
- var _this$props3 = _this.props,
191
- model = _this$props3.model,
192
- onModelChanged = _this$props3.onModelChanged;
204
+ var _this$props4 = _this.props,
205
+ model = _this$props4.model,
206
+ onModelChanged = _this$props4.onModelChanged;
193
207
  var correctResponse = (0, _categorize.removeChoiceFromCategory)(choice.id, category.id, choiceIndex, model.correctResponse);
194
208
  onModelChanged({
195
209
  correctResponse: correctResponse
196
210
  });
197
211
  });
212
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moveChoice", function (choiceId, from, to, choiceIndex) {
213
+ var _this$props5 = _this.props,
214
+ model = _this$props5.model,
215
+ onModelChanged = _this$props5.onModelChanged;
216
+
217
+ var _ref2 = model || {},
218
+ choices = _ref2.choices,
219
+ _ref2$correctResponse = _ref2.correctResponse,
220
+ correctResponse = _ref2$correctResponse === void 0 ? [] : _ref2$correctResponse;
221
+
222
+ var choice = (choices || []).find(function (choice) {
223
+ return choice.id === choiceId;
224
+ });
225
+
226
+ if (to === from || !choice) {
227
+ return;
228
+ }
229
+
230
+ if (choice.categoryCount !== 0) {
231
+ correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, from, to, choiceIndex, correctResponse);
232
+ correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(choice, to, correctResponse);
233
+ } else if (choice.categoryCount === 0) {
234
+ correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, to, 0, correctResponse);
235
+ }
236
+
237
+ onModelChanged({
238
+ correctResponse: correctResponse
239
+ });
240
+ });
198
241
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeRowLabel", function (val, index) {
199
242
  var model = _this.props.model;
200
243
  var rowLabels = model.rowLabels;
@@ -218,36 +261,65 @@ var Categories = /*#__PURE__*/function (_React$Component) {
218
261
  value: function render() {
219
262
  var _this2 = this;
220
263
 
221
- var _this$props4 = this.props,
222
- model = _this$props4.model,
223
- classes = _this$props4.classes,
224
- className = _this$props4.className,
225
- categories = _this$props4.categories,
226
- imageSupport = _this$props4.imageSupport,
227
- toolbarOpts = _this$props4.toolbarOpts;
264
+ var _this$props6 = this.props,
265
+ model = _this$props6.model,
266
+ classes = _this$props6.classes,
267
+ className = _this$props6.className,
268
+ categories = _this$props6.categories,
269
+ imageSupport = _this$props6.imageSupport,
270
+ uploadSoundSupport = _this$props6.uploadSoundSupport,
271
+ toolbarOpts = _this$props6.toolbarOpts,
272
+ spellCheck = _this$props6.spellCheck,
273
+ configuration = _this$props6.configuration,
274
+ defaultImageMaxHeight = _this$props6.defaultImageMaxHeight,
275
+ defaultImageMaxWidth = _this$props6.defaultImageMaxWidth;
228
276
  var categoriesPerRow = model.categoriesPerRow,
229
- rowLabels = model.rowLabels;
277
+ rowLabels = model.rowLabels,
278
+ errors = model.errors;
279
+
280
+ var _ref3 = errors || {},
281
+ associationError = _ref3.associationError,
282
+ categoriesError = _ref3.categoriesError,
283
+ categoriesErrors = _ref3.categoriesErrors;
284
+
285
+ var _ref4 = configuration || {},
286
+ maxCategories = _ref4.maxCategories,
287
+ _ref4$maxImageWidth = _ref4.maxImageWidth,
288
+ maxImageWidth = _ref4$maxImageWidth === void 0 ? {} : _ref4$maxImageWidth,
289
+ _ref4$maxImageHeight = _ref4.maxImageHeight,
290
+ maxImageHeight = _ref4$maxImageHeight === void 0 ? {} : _ref4$maxImageHeight;
291
+
230
292
  var holderStyle = {
231
293
  gridTemplateColumns: "repeat(".concat(categoriesPerRow, ", 1fr)")
232
294
  };
295
+ var validationMessage = (0, _utils.generateValidationMessage)(configuration);
233
296
  return /*#__PURE__*/_react["default"].createElement("div", {
234
297
  className: (0, _classnames["default"])(classes.categories, className)
235
298
  }, /*#__PURE__*/_react["default"].createElement(_header["default"], {
236
299
  label: "Categories",
237
300
  buttonLabel: "ADD A CATEGORY",
238
- onAdd: this.add
239
- }), /*#__PURE__*/_react["default"].createElement("div", {
240
- className: classes.row
241
- }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
242
- label: "Categories per row",
243
- type: "number",
244
- inputProps: {
245
- min: 1,
246
- max: 4
247
- },
248
- value: categoriesPerRow,
249
- onChange: this.changeCategoryColumns
250
- })), /*#__PURE__*/_react["default"].createElement("div", {
301
+ onAdd: this.add,
302
+ info: /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
303
+ classes: {
304
+ tooltip: classes.tooltip
305
+ },
306
+ disableFocusListener: true,
307
+ disableTouchListener: true,
308
+ placement: 'right',
309
+ title: validationMessage
310
+ }, /*#__PURE__*/_react["default"].createElement(_Info["default"], {
311
+ fontSize: 'small',
312
+ color: 'primary',
313
+ style: {
314
+ marginLeft: '5px'
315
+ }
316
+ })),
317
+ buttonDisabled: maxCategories && categories && maxCategories === categories.length
318
+ }), associationError && /*#__PURE__*/_react["default"].createElement("div", {
319
+ className: classes.errorText
320
+ }, associationError), categoriesError && /*#__PURE__*/_react["default"].createElement("div", {
321
+ className: classes.errorText
322
+ }, categoriesError), /*#__PURE__*/_react["default"].createElement("div", {
251
323
  className: classes.categoriesHolder,
252
324
  style: holderStyle
253
325
  }, categories.map(function (category, index) {
@@ -255,27 +327,43 @@ var Categories = /*#__PURE__*/function (_React$Component) {
255
327
  var rowIndex = index / categoriesPerRow;
256
328
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
257
329
  key: index
258
- }, hasRowLabel && /*#__PURE__*/_react["default"].createElement(RowLabel, {
330
+ }, hasRowLabel && /*#__PURE__*/_react["default"].createElement(_RowLabel.RowLabel, {
259
331
  categoriesPerRow: categoriesPerRow,
332
+ disabled: false,
260
333
  rowIndex: rowIndex,
261
334
  markup: rowLabels[rowIndex] || '',
262
335
  onChange: function onChange(val) {
263
336
  return _this2.changeRowLabel(val, rowIndex);
264
337
  },
265
338
  imageSupport: imageSupport,
266
- toolbarOpts: toolbarOpts
339
+ toolbarOpts: toolbarOpts,
340
+ spellCheck: spellCheck,
341
+ maxImageWidth: maxImageWidth && maxImageWidth.rowLabel || defaultImageMaxWidth,
342
+ maxImageHeight: maxImageHeight && maxImageHeight.rowLabel || defaultImageMaxHeight,
343
+ uploadSoundSupport: uploadSoundSupport
267
344
  }), /*#__PURE__*/_react["default"].createElement(_category["default"], {
268
345
  imageSupport: imageSupport,
346
+ focusedEl: _this2.state.focusedEl,
347
+ deleteFocusedEl: _this2.deleteFocusedEl,
348
+ index: index,
269
349
  category: category,
350
+ error: categoriesErrors && categoriesErrors[category.id],
270
351
  onChange: _this2.change,
271
352
  onDelete: function onDelete() {
272
353
  return _this2["delete"](category);
273
354
  },
274
355
  onAddChoice: _this2.addChoiceToCategory,
356
+ onMoveChoice: function onMoveChoice(choiceId, from, to, choiceIndex) {
357
+ return _this2.moveChoice(choiceId, from, to, choiceIndex);
358
+ },
275
359
  toolbarOpts: toolbarOpts,
360
+ spellCheck: spellCheck,
276
361
  onDeleteChoice: function onDeleteChoice(choice, choiceIndex) {
277
362
  return _this2.deleteChoiceFromCategory(category, choice, choiceIndex);
278
- }
363
+ },
364
+ maxImageWidth: maxImageWidth && maxImageWidth.categoryLabel || defaultImageMaxWidth,
365
+ maxImageHeight: maxImageHeight && maxImageHeight.categoryLabel || defaultImageMaxHeight,
366
+ uploadSoundSupport: uploadSoundSupport
279
367
  }));
280
368
  })));
281
369
  }
@@ -289,11 +377,16 @@ exports.Categories = Categories;
289
377
  add: _propTypes["default"].func.isRequired,
290
378
  "delete": _propTypes["default"].func.isRequired
291
379
  }),
380
+ uploadSoundSupport: _propTypes["default"].shape({
381
+ add: _propTypes["default"].func.isRequired,
382
+ "delete": _propTypes["default"].func.isRequired
383
+ }),
292
384
  classes: _propTypes["default"].object.isRequired,
293
385
  className: _propTypes["default"].string,
294
386
  categories: _propTypes["default"].array,
295
387
  onModelChanged: _propTypes["default"].func,
296
388
  model: _propTypes["default"].object.isRequired,
389
+ configuration: _propTypes["default"].object.isRequired,
297
390
  toolbarOpts: _propTypes["default"].object
298
391
  });
299
392
 
@@ -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","RowLabel","categoriesPerRow","classes","markup","imageSupport","onChange","toolbarOpts","text","Categories","event","numberValue","parseInt","target","value","props","onModelChanged","model","id","utils","firstAvailableIndex","map","a","data","label","addRowLabel","length","rowLabels","push","concat","category","index","findIndex","splice","correctResponse","c","choice","categoryId","undefined","choiceIndex","val","newRowLabels","className","holderStyle","add","min","max","changeCategoryColumns","hasRowLabel","rowIndex","changeRowLabel","change","addChoiceToCategory","deleteChoiceFromCategory","React","Component","PropTypes","shape","func","isRequired","object","string","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;AAAA,SAAK;AACvBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC;AADlB,KADW;AAIvBC,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,KAJK;AASvBK,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,UAAU,EAAE,UAJT;AAKHC,MAAAA,KAAK,EAAE,MALJ;AAMHC,MAAAA,SAAS,EAAEb,KAAK,CAACG,OAAN,CAAcC,IANtB;AAOHF,MAAAA,YAAY,EAAE,IAAIF,KAAK,C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ALpB;AAME,UAAA,WAAW,EAAE7C,WANf;AAOE,UAAA,cAAc,EAAE,wBAAC6B,MAAD,EAASG,WAAT;AAAA,mBACd,MAAI,CAACc,wBAAL,CAA8BvB,QAA9B,EAAwCM,MAAxC,EAAgDG,WAAhD,CADc;AAAA;AAPlB,UAbF,CADF;AA2BD,OA/BA,CADH,CAdF,CADF;AAmDD;;;EA3K6Be,kBAAMC,S;;;iCAAzB9C,U,eACQ;AACjBJ,EAAAA,YAAY,EAAEmD,sBAAUC,KAAV,CAAgB;AAC5Bb,IAAAA,GAAG,EAAEY,sBAAUE,IAAV,CAAeC,UADQ;AAE5B,cAAQH,sBAAUE,IAAV,CAAeC;AAFK,GAAhB,CADG;AAKjBxD,EAAAA,OAAO,EAAEqD,sBAAUI,MAAV,CAAiBD,UALT;AAMjBjB,EAAAA,SAAS,EAAEc,sBAAUK,MANJ;AAOjB5E,EAAAA,UAAU,EAAEuE,sBAAUM,KAPL;AAQjB9C,EAAAA,cAAc,EAAEwC,sBAAUE,IART;AASjBzC,EAAAA,KAAK,EAAEuC,sBAAUI,MAAV,CAAiBD,UATP;AAUjBpD,EAAAA,WAAW,EAAEiD,sBAAUI;AAVN,C;;eA6KN,wBAAW7E,MAAX,EAAmB0B,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 Category from './category';\nimport Header from '../header';\nimport { moveChoiceToCategory, removeCategory, removeChoiceFromCategory } from '@pie-lib/categorize';\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});\n\nconst RowLabel = withStyles(styles)(({ categoriesPerRow, classes, markup, imageSupport, onChange, toolbarOpts }) => {\n return (\n <div\n style={{\n gridColumn: `1/${categoriesPerRow + 1}`,\n width: '100%'\n }}\n >\n <Typography className={classes.text}>\n Row Label\n </Typography>\n <EditableHtml\n className={classes.rowLabelHolder}\n markup={markup}\n onChange={onChange}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n />\n </div>\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 classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n categories: PropTypes.array,\n onModelChanged: PropTypes.func,\n model: PropTypes.object.isRequired,\n toolbarOpts: PropTypes.object\n };\n\n changeCategoryColumns = event => {\n const numberValue = parseInt(event.target.value, 10);\n\n if (numberValue && numberValue >= 1 && numberValue <= 4) {\n this.props.onModelChanged({ categoriesPerRow: numberValue });\n }\n };\n\n add = () => {\n const { model } = this.props;\n const { categoriesPerRow } = model;\n const id = utils.firstAvailableIndex(model.categories.map(a => a.id), 0);\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(\n category.id,\n model.correctResponse\n );\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(\n choice.id,\n undefined,\n categoryId,\n 0,\n model.correctResponse\n );\n\n onModelChanged({ correctResponse });\n };\n\n deleteChoiceFromCategory = (category, choice, choiceIndex) => {\n const { model, onModelChanged } = this.props;\n const correctResponse = removeChoiceFromCategory(\n choice.id,\n category.id,\n choiceIndex,\n model.correctResponse\n );\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 toolbarOpts\n } = this.props;\n const { categoriesPerRow, rowLabels } = model;\n\n const holderStyle = {\n gridTemplateColumns: `repeat(${categoriesPerRow}, 1fr)`\n };\n\n return (\n <div className={classNames(classes.categories, className)}>\n <Header label=\"Categories\" buttonLabel=\"ADD A CATEGORY\" onAdd={this.add} />\n <div className={classes.row}>\n <TextField\n label=\"Categories per row\"\n type=\"number\"\n inputProps={{\n min: 1,\n max: 4\n }}\n value={categoriesPerRow}\n onChange={this.changeCategoryColumns}\n />\n </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\n key={index}\n >\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 />\n )}\n <Category\n imageSupport={imageSupport}\n category={category}\n onChange={this.change}\n onDelete={() => this.delete(category)}\n onAddChoice={this.addChoiceToCategory}\n toolbarOpts={toolbarOpts}\n onDeleteChoice={(choice, choiceIndex) =>\n this.deleteChoiceFromCategory(category, choice, choiceIndex)\n }\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","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","choice","find","undefined","categoryCount","choiceIndex","choiceId","from","to","val","newRowLabels","classes","className","imageSupport","uploadSoundSupport","toolbarOpts","spellCheck","configuration","defaultImageMaxHeight","defaultImageMaxWidth","errors","associationError","categoriesError","categoriesErrors","maxCategories","maxImageWidth","maxImageHeight","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;;AAQA;;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;AADlB,KADa;AAIzBC,IAAAA,gBAAgB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;;iCAAzBtE,U,eACQ;AACjByC,EAAAA,YAAY,EAAE8B,sBAAUC,KAAV,CAAgB;AAC5Bf,IAAAA,GAAG,EAAEc,sBAAUE,IAAV,CAAeC,UADQ;AAE5B,cAAQH,sBAAUE,IAAV,CAAeC;AAFK,GAAhB,CADG;AAKjBhC,EAAAA,kBAAkB,EAAE6B,sBAAUC,KAAV,CAAgB;AAClCf,IAAAA,GAAG,EAAEc,sBAAUE,IAAV,CAAeC,UADc;AAElC,cAAQH,sBAAUE,IAAV,CAAeC;AAFW,GAAhB,CALH;AASjBnC,EAAAA,OAAO,EAAEgC,sBAAUI,MAAV,CAAiBD,UATT;AAUjBlC,EAAAA,SAAS,EAAE+B,sBAAUK,MAVJ;AAWjBnG,EAAAA,UAAU,EAAE8F,sBAAUM,KAXL;AAYjB3D,EAAAA,cAAc,EAAEqD,sBAAUE,IAZT;AAajBtE,EAAAA,KAAK,EAAEoE,sBAAUI,MAAV,CAAiBD,UAbP;AAcjB7B,EAAAA,aAAa,EAAE0B,sBAAUI,MAAV,CAAiBD,UAdf;AAejB/B,EAAAA,WAAW,EAAE4B,sBAAUI;AAfN,C;;eA8NN,wBAAWpG,MAAX,EAAmByB,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 verifyAllowMultiplePlacements,\n} from '@pie-lib/categorize';\n\nimport Category from './category';\nimport Header from '../header';\nimport { generateValidationMessage } from '../../utils';\nimport { RowLabel } from './RowLabel';\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\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 = (addedChoice, categoryId) => {\n const { model, onModelChanged } = this.props;\n let { choices = [], correctResponse = [] } = 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 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 correctResponse = verifyAllowMultiplePlacements(choice, to, 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 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 />\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"}