@pie-element/graphing 8.3.4-next.3 → 9.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,601 +1,484 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
10
- exports["default"] = exports.Tools = exports.CorrectResponse = void 0;
11
-
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
-
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
-
24
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
-
7
+ exports.default = exports.Tools = exports.CorrectResponse = void 0;
26
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
-
28
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
29
-
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
30
10
  var React = _interopRequireWildcard(require("react"));
31
-
32
11
  var _reactDom = _interopRequireDefault(require("react-dom"));
33
-
34
- var _classnames = _interopRequireDefault(require("classnames"));
35
-
36
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
37
-
38
- var _styles = require("@material-ui/core/styles");
39
-
13
+ var _styles = require("@mui/material/styles");
40
14
  var _graphing = require("@pie-lib/graphing");
41
-
42
15
  var _configUi = require("@pie-lib/config-ui");
43
-
44
16
  var _mathRendering = require("@pie-lib/math-rendering");
45
-
46
- var _Delete = _interopRequireDefault(require("@material-ui/icons/Delete"));
47
-
17
+ var _Delete = _interopRequireDefault(require("@mui/icons-material/Delete"));
48
18
  var _lodash = require("lodash");
49
-
50
- var _core = require("@material-ui/core");
51
-
52
- var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
53
-
54
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
55
-
56
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
57
-
58
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
59
-
60
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
61
-
62
- 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); }; }
63
-
64
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
65
-
66
- var styles = function styles(theme) {
67
- return {
68
- column: {
69
- flex: 1
70
- },
71
- graphingTools: {
72
- color: theme.palette.grey['A200']
73
- },
74
- availableTools: {
75
- marginTop: theme.spacing.unit,
76
- display: 'flex',
77
- flexWrap: 'wrap'
78
- },
79
- availableTool: {
80
- cursor: 'pointer',
81
- margin: theme.spacing.unit,
82
- padding: theme.spacing.unit,
83
- border: "2px solid ".concat(theme.palette.common.white),
84
- textTransform: 'capitalize',
85
- '&:hover': {
86
- color: theme.palette.grey[800]
87
- }
88
- },
89
- selectedTool: {
90
- background: theme.palette.grey['A100'],
91
- border: "2px solid ".concat(theme.palette.grey['A200'])
92
- },
93
- container: {
94
- border: "2px solid ".concat(theme.palette.grey['A200']),
95
- borderRadius: '4px',
96
- padding: "0 ".concat(theme.spacing.unit * 4, "px ").concat(theme.spacing.unit * 2, "px"),
97
- background: theme.palette.grey[50]
98
- },
99
- button: {
100
- margin: "".concat(theme.spacing.unit * 2.5, "px 0"),
101
- cursor: 'pointer',
102
- background: theme.palette.grey[200],
103
- padding: theme.spacing.unit * 1.5,
104
- width: 'fit-content',
105
- borderRadius: '4px',
106
- '&:hover': {
107
- background: theme.palette.grey['A100']
108
- }
109
- },
110
- responseTitle: {
111
- display: 'flex',
112
- alignItems: 'center',
113
- marginTop: theme.spacing.unit * 2.5
114
- },
115
- iconButton: {
116
- marginLeft: '6px',
117
- color: theme.palette.grey[600],
118
- '&:hover': {
119
- cursor: 'pointer',
120
- color: theme.palette.common.black
121
- }
122
- },
123
- name: {
124
- marginBottom: theme.spacing.unit / 2
125
- },
126
- tooltip: {
127
- fontSize: theme.typography.fontSize - 2,
128
- whiteSpace: 'pre',
129
- maxWidth: '500px'
130
- },
131
- subtitleText: {
132
- marginTop: theme.spacing.unit * 1.5,
133
- marginBottom: theme.spacing.unit
134
- },
135
- toolsHeader: {
136
- display: 'flex',
137
- alignItems: 'center',
138
- justifyContent: 'space-between'
139
- },
140
- defaultTool: {
141
- display: 'flex',
142
- alignItems: 'center',
143
- width: '300px'
144
- },
145
- defaultToolSelect: {
146
- marginLeft: theme.spacing.unit,
147
- textTransform: 'uppercase',
148
- color: theme.palette.grey[800]
149
- },
150
- menuItem: {
151
- textTransform: 'uppercase'
152
- },
153
- noDefaultTool: {
154
- padding: theme.spacing.unit / 2
155
- },
156
- error: {
157
- color: theme.palette.error.main
158
- },
159
- errorMessage: {
160
- fontSize: theme.typography.fontSize - 2,
161
- color: theme.palette.error.main,
162
- marginTop: theme.spacing.unit
163
- },
164
- graphError: {
165
- border: "2px solid ".concat(theme.palette.error.main)
166
- }
167
- };
168
- };
169
-
170
- var Tools = function Tools(_ref) {
171
- var classes = _ref.classes,
172
- availableTools = _ref.availableTools,
173
- defaultTool = _ref.defaultTool,
174
- hasErrors = _ref.hasErrors,
175
- toolbarTools = _ref.toolbarTools,
176
- toggleToolBarTool = _ref.toggleToolBarTool,
177
- onDefaultToolChange = _ref.onDefaultToolChange;
178
- var allTools = availableTools || [];
179
- var isLabelAvailable = allTools.includes('label');
180
- var toolbarToolsNoLabel = (toolbarTools || []).filter(function (tool) {
181
- return tool !== 'label';
182
- });
183
-
19
+ var _material = require("@mui/material");
20
+ var _Info = _interopRequireDefault(require("@mui/icons-material/Info"));
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
22
+ // custom grey values close to old v3 accents
23
+ const GREY_A100 = '#D5D5D5';
24
+ const GREY_A200 = '#AAAAAA';
25
+ const GraphingTools = (0, _styles.styled)('div')({
26
+ color: GREY_A200
27
+ });
28
+ const Button = (0, _styles.styled)('div')(({
29
+ theme
30
+ }) => ({
31
+ margin: `${theme.spacing(2.5)} 0`,
32
+ cursor: 'pointer',
33
+ background: theme.palette.grey[200],
34
+ padding: theme.spacing(1.5),
35
+ width: 'fit-content',
36
+ borderRadius: '4px',
37
+ '&:hover': {
38
+ background: GREY_A100
39
+ }
40
+ }));
41
+ const AvailableTools = (0, _styles.styled)('div')(({
42
+ theme
43
+ }) => ({
44
+ marginTop: theme.spacing(1),
45
+ display: 'flex',
46
+ flexWrap: 'wrap'
47
+ }));
48
+ const AvailableTool = (0, _styles.styled)('div')(({
49
+ theme
50
+ }) => ({
51
+ cursor: 'pointer',
52
+ margin: theme.spacing(1),
53
+ padding: theme.spacing(1),
54
+ border: `2px solid ${theme.palette.common.white}`,
55
+ textTransform: 'capitalize',
56
+ '&:hover': {
57
+ color: theme.palette.grey[800]
58
+ }
59
+ }));
60
+ const SelectedTool = (0, _styles.styled)(AvailableTool)({
61
+ background: GREY_A100,
62
+ border: `2px solid ${GREY_A200}`
63
+ });
64
+ const ResponseTitle = (0, _styles.styled)('div')(({
65
+ theme
66
+ }) => ({
67
+ display: 'flex',
68
+ alignItems: 'center',
69
+ marginTop: theme.spacing(2.5)
70
+ }));
71
+ const IconButton = (0, _styles.styled)('div')(({
72
+ theme
73
+ }) => ({
74
+ marginLeft: '6px',
75
+ color: theme.palette.grey[600],
76
+ '&:hover': {
77
+ cursor: 'pointer',
78
+ color: theme.palette.common.black
79
+ }
80
+ }));
81
+ const Name = (0, _styles.styled)('div')(({
82
+ theme
83
+ }) => ({
84
+ marginBottom: theme.spacing(0.5)
85
+ }));
86
+ const StyledTooltip = (0, _styles.styled)(({
87
+ className,
88
+ ...props
89
+ }) => /*#__PURE__*/React.createElement(_material.Tooltip, (0, _extends2.default)({}, props, {
90
+ classes: {
91
+ tooltip: className
92
+ }
93
+ })))(({
94
+ theme
95
+ }) => ({
96
+ '& .MuiTooltip-tooltip': {
97
+ fontSize: theme.typography.fontSize - 2,
98
+ whiteSpace: 'pre',
99
+ maxWidth: '500px'
100
+ }
101
+ }));
102
+ const SubtitleText = (0, _styles.styled)(_material.Typography)(({
103
+ theme
104
+ }) => ({
105
+ marginTop: theme.spacing(1.5),
106
+ marginBottom: theme.spacing(1)
107
+ }));
108
+ const ToolsHeader = (0, _styles.styled)('div')({
109
+ display: 'flex',
110
+ alignItems: 'center',
111
+ justifyContent: 'space-between'
112
+ });
113
+ const DefaultTool = (0, _styles.styled)('div')({
114
+ display: 'flex',
115
+ alignItems: 'center',
116
+ width: '300px'
117
+ });
118
+ const DefaultToolSelect = (0, _styles.styled)(_material.Select)(({
119
+ theme
120
+ }) => ({
121
+ marginLeft: theme.spacing(1),
122
+ textTransform: 'uppercase',
123
+ color: theme.palette.grey[800]
124
+ }));
125
+ const StyledMenuItem = (0, _styles.styled)(_material.MenuItem)({
126
+ textTransform: 'uppercase'
127
+ });
128
+ const ErrorMessage = (0, _styles.styled)('div')(({
129
+ theme
130
+ }) => ({
131
+ fontSize: theme.typography.fontSize - 2,
132
+ color: theme.palette.error.main,
133
+ marginTop: theme.spacing(1)
134
+ }));
135
+ const Tools = ({
136
+ availableTools,
137
+ defaultTool,
138
+ hasErrors,
139
+ toolbarTools,
140
+ toggleToolBarTool,
141
+ onDefaultToolChange
142
+ }) => {
143
+ let allTools = availableTools || [];
144
+ const isLabelAvailable = allTools.includes('label');
145
+ const toolbarToolsNoLabel = (toolbarTools || []).filter(tool => tool !== 'label');
184
146
  if (isLabelAvailable) {
185
147
  // label has to be placed at the end of the list
186
- var allToolsNoLabel = allTools.filter(function (tool) {
187
- return tool !== 'label';
188
- });
189
- allTools = [].concat((0, _toConsumableArray2["default"])(allToolsNoLabel), ['label']);
148
+ const allToolsNoLabel = allTools.filter(tool => tool !== 'label');
149
+ allTools = [...allToolsNoLabel, 'label'];
190
150
  }
191
-
192
- return /*#__PURE__*/React.createElement("div", {
193
- className: classes.graphingTools
194
- }, /*#__PURE__*/React.createElement("div", {
195
- className: classes.toolsHeader
196
- }, /*#__PURE__*/React.createElement("span", null, "GRAPHING TOOLS"), toolbarToolsNoLabel.length > 0 && /*#__PURE__*/React.createElement("div", {
197
- className: classes.defaultTool
198
- }, /*#__PURE__*/React.createElement("span", null, "Default graphing tool:"), /*#__PURE__*/React.createElement(_core.Select, {
199
- className: classes.defaultToolSelect,
151
+ return /*#__PURE__*/React.createElement(GraphingTools, null, /*#__PURE__*/React.createElement(ToolsHeader, null, /*#__PURE__*/React.createElement("span", null, "GRAPHING TOOLS"), toolbarToolsNoLabel.length > 0 && /*#__PURE__*/React.createElement(DefaultTool, null, /*#__PURE__*/React.createElement("span", null, "Default graphing tool:"), /*#__PURE__*/React.createElement(DefaultToolSelect, {
152
+ variant: "standard",
200
153
  onChange: onDefaultToolChange,
201
154
  value: defaultTool,
202
- disableUnderline: true
203
- }, toolbarToolsNoLabel.map(function (tool, index) {
204
- return /*#__PURE__*/React.createElement(_core.MenuItem, {
205
- key: index,
206
- className: classes.menuItem,
207
- value: tool
208
- }, tool);
209
- })))), /*#__PURE__*/React.createElement("div", {
210
- className: classes.availableTools
211
- }, allTools.map(function (tool) {
212
- var selected = toolbarTools.find(function (t) {
213
- return t === tool;
214
- });
215
- return /*#__PURE__*/React.createElement("div", {
216
- key: tool,
217
- className: (0, _classnames["default"])(classes.availableTool, selected && classes.selectedTool, hasErrors && tool !== 'label' && classes.error),
218
- onClick: function onClick() {
219
- return toggleToolBarTool(tool);
155
+ disableUnderline: true,
156
+ MenuProps: {
157
+ transitionDuration: {
158
+ enter: 225,
159
+ exit: 195
220
160
  }
161
+ }
162
+ }, toolbarToolsNoLabel.map((tool, index) => /*#__PURE__*/React.createElement(StyledMenuItem, {
163
+ key: index,
164
+ value: tool
165
+ }, tool))))), /*#__PURE__*/React.createElement(AvailableTools, null, allTools.map(tool => {
166
+ const selected = toolbarTools.find(t => t === tool);
167
+ const ToolComponent = selected ? SelectedTool : AvailableTool;
168
+ return /*#__PURE__*/React.createElement(ToolComponent, {
169
+ key: tool,
170
+ style: {
171
+ ...(hasErrors && tool !== 'label' && {
172
+ color: 'red'
173
+ })
174
+ },
175
+ onClick: () => toggleToolBarTool(tool)
221
176
  }, tool.toUpperCase());
222
177
  })));
223
178
  };
224
-
225
179
  exports.Tools = Tools;
226
180
  Tools.propTypes = {
227
- classes: _propTypes["default"].object.isRequired,
228
- toolbarTools: _propTypes["default"].arrayOf(_propTypes["default"].string),
229
- toggleToolBarTool: _propTypes["default"].func,
230
- availableTools: _propTypes["default"].array,
231
- defaultTool: _propTypes["default"].string,
232
- hasErrors: _propTypes["default"].number,
233
- onDefaultToolChange: _propTypes["default"].func
181
+ toolbarTools: _propTypes.default.arrayOf(_propTypes.default.string),
182
+ toggleToolBarTool: _propTypes.default.func,
183
+ availableTools: _propTypes.default.array,
184
+ defaultTool: _propTypes.default.string,
185
+ hasErrors: _propTypes.default.number,
186
+ onDefaultToolChange: _propTypes.default.func
234
187
  };
235
-
236
- var CorrectResponse = /*#__PURE__*/function (_React$Component) {
237
- (0, _inherits2["default"])(CorrectResponse, _React$Component);
238
-
239
- var _super = _createSuper(CorrectResponse);
240
-
241
- function CorrectResponse() {
242
- var _this;
243
-
244
- (0, _classCallCheck2["default"])(this, CorrectResponse);
245
-
246
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
247
- args[_key] = arguments[_key];
248
- }
249
-
250
- _this = _super.call.apply(_super, [this].concat(args));
251
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
188
+ class CorrectResponse extends React.Component {
189
+ constructor(...args) {
190
+ super(...args);
191
+ (0, _defineProperty2.default)(this, "state", {
252
192
  dialog: {
253
193
  open: false
254
194
  }
255
195
  });
256
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAlertDialog", function (open, callback) {
257
- return _this.setState({
258
- dialog: {
259
- open: open
260
- }
261
- }, callback);
262
- });
263
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeMarks", function (key, marks) {
264
- var _this$props = _this.props,
265
- model = _this$props.model,
266
- onChange = _this$props.onChange;
267
- (0, _lodash.set)(model, "answers.".concat(key, ".marks"), marks);
196
+ (0, _defineProperty2.default)(this, "handleAlertDialog", (open, callback) => this.setState({
197
+ dialog: {
198
+ open
199
+ }
200
+ }, callback));
201
+ (0, _defineProperty2.default)(this, "changeMarks", (key, marks) => {
202
+ const {
203
+ model,
204
+ onChange
205
+ } = this.props;
206
+ (0, _lodash.set)(model, `answers.${key}.marks`, marks);
268
207
  onChange(model);
269
208
  });
270
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "filterMarks", function (tool) {
271
- var answers = _this.props.model.answers;
272
- return Object.entries(answers || {}).reduce(function (object, _ref2) {
273
- var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2),
274
- key = _ref3[0],
275
- answer = _ref3[1];
276
-
277
- object[key] = _objectSpread(_objectSpread({}, answer), {}, {
278
- marks: (answer.marks || []).filter(function (mark) {
279
- return mark.type !== tool;
280
- })
281
- });
209
+ (0, _defineProperty2.default)(this, "filterMarks", tool => {
210
+ const {
211
+ model: {
212
+ answers
213
+ }
214
+ } = this.props;
215
+ return Object.entries(answers || {}).reduce((object, [key, answer]) => {
216
+ object[key] = {
217
+ ...answer,
218
+ marks: (answer.marks || []).filter(mark => mark.type !== tool)
219
+ };
282
220
  return object;
283
221
  }, {});
284
222
  });
285
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeToolbarTools", function (toolbarTools) {
286
- var _this$props2 = _this.props,
287
- model = _this$props2.model,
288
- onChange = _this$props2.onChange;
223
+ (0, _defineProperty2.default)(this, "changeToolbarTools", toolbarTools => {
224
+ const {
225
+ model,
226
+ onChange
227
+ } = this.props;
289
228
  model.toolbarTools = toolbarTools;
290
229
  onChange(model);
291
230
  });
292
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateModel", function (props) {
293
- var _this$props3 = _this.props,
294
- model = _this$props3.model,
295
- onChange = _this$props3.onChange;
296
- onChange(_objectSpread(_objectSpread({}, model), props));
297
- });
298
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleToolBarTool", function (tool) {
299
- var _this$props$model = _this.props.model,
300
- defaultTool = _this$props$model.defaultTool,
301
- toolbarTools = _this$props$model.toolbarTools,
302
- _this$props$model$ans = _this$props$model.answers,
303
- answers = _this$props$model$ans === void 0 ? {} : _this$props$model$ans;
304
- var updatedToolbarTools = (0, _toConsumableArray2["default"])(toolbarTools);
305
- var newDefaultTool = defaultTool;
306
- var index = toolbarTools.findIndex(function (t) {
307
- return tool === t;
231
+ (0, _defineProperty2.default)(this, "updateModel", props => {
232
+ const {
233
+ model,
234
+ onChange
235
+ } = this.props;
236
+ onChange({
237
+ ...model,
238
+ ...props
308
239
  });
309
-
240
+ });
241
+ (0, _defineProperty2.default)(this, "toggleToolBarTool", tool => {
242
+ const {
243
+ model: {
244
+ defaultTool,
245
+ toolbarTools,
246
+ answers = {}
247
+ }
248
+ } = this.props;
249
+ const updatedToolbarTools = [...toolbarTools];
250
+ let newDefaultTool = defaultTool;
251
+ const index = toolbarTools.findIndex(t => tool === t);
310
252
  if (index >= 0) {
311
- var updatedAnswers = _this.filterMarks(tool);
312
-
253
+ const updatedAnswers = this.filterMarks(tool);
313
254
  updatedToolbarTools.splice(index, 1);
314
-
315
255
  if (tool === defaultTool) {
316
- var toolbarToolsNoLabel = (updatedToolbarTools || []).filter(function (tool) {
317
- return tool !== 'label';
318
- });
256
+ const toolbarToolsNoLabel = (updatedToolbarTools || []).filter(tool => tool !== 'label');
319
257
  newDefaultTool = toolbarToolsNoLabel.length && toolbarToolsNoLabel[0] || '';
320
258
  }
321
-
322
259
  if (!(0, _lodash.isEqual)(answers, updatedAnswers)) {
323
- _this.setState({
260
+ this.setState({
324
261
  dialog: {
325
262
  open: true,
326
263
  title: 'Warning',
327
- text: "Correct answer includes one or more ".concat(tool, " objects and all of them will be deleted."),
328
- onConfirm: function onConfirm() {
329
- return _this.handleAlertDialog(false, _this.updateModel({
330
- toolbarTools: updatedToolbarTools,
331
- answers: updatedAnswers,
332
- defaultTool: newDefaultTool
333
- }));
334
- },
335
- onClose: function onClose() {
336
- return _this.handleAlertDialog(false);
337
- }
264
+ text: `Correct answer includes one or more ${tool} objects and all of them will be deleted.`,
265
+ onConfirm: () => this.handleAlertDialog(false, this.updateModel({
266
+ toolbarTools: updatedToolbarTools,
267
+ answers: updatedAnswers,
268
+ defaultTool: newDefaultTool
269
+ })),
270
+ onClose: () => this.handleAlertDialog(false)
338
271
  }
339
272
  });
340
-
341
273
  return;
342
274
  }
343
275
  } else {
344
276
  updatedToolbarTools.push(tool);
345
-
346
277
  if (defaultTool === '' && tool !== 'label') {
347
278
  newDefaultTool = tool;
348
279
  }
349
280
  }
350
-
351
- _this.updateModel({
281
+ this.updateModel({
352
282
  toolbarTools: updatedToolbarTools,
353
283
  defaultTool: newDefaultTool
354
284
  });
355
285
  });
356
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDefaultToolChange", function (event) {
357
- var value = event.target.value;
358
-
359
- _this.updateModel({
286
+ (0, _defineProperty2.default)(this, "onDefaultToolChange", event => {
287
+ const {
288
+ value
289
+ } = event.target;
290
+ this.updateModel({
360
291
  defaultTool: value
361
292
  });
362
293
  });
363
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addAlternateResponse", function () {
364
- var _this$props4 = _this.props,
365
- model = _this$props4.model,
366
- onChange = _this$props4.onChange;
367
-
368
- var _ref4 = model || {},
369
- answers = _ref4.answers;
370
-
371
- var answersKeys = Object.keys(answers || {});
372
- (0, _lodash.set)(model, "answers.".concat("alternate".concat(answersKeys.length)), {
373
- name: "Alternate ".concat(answersKeys.length),
294
+ (0, _defineProperty2.default)(this, "addAlternateResponse", () => {
295
+ const {
296
+ model,
297
+ onChange
298
+ } = this.props;
299
+ const {
300
+ answers
301
+ } = model || {};
302
+ const answersKeys = Object.keys(answers || {});
303
+ (0, _lodash.set)(model, `answers.${`alternate${answersKeys.length}`}`, {
304
+ name: `Alternate ${answersKeys.length}`,
374
305
  marks: []
375
306
  });
376
307
  onChange(model);
377
308
  });
378
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteAlternateResponse", function (answerKey, answer) {
379
- var _this$props5 = _this.props,
380
- model = _this$props5.model,
381
- onChange = _this$props5.onChange;
382
-
383
- var _ref5 = model || {},
384
- answers = _ref5.answers;
385
-
386
- var _ref6 = answer || {},
387
- _ref6$marks = _ref6.marks,
388
- marks = _ref6$marks === void 0 ? [] : _ref6$marks,
389
- name = _ref6.name;
390
-
391
- var deleteAnswer = function deleteAnswer() {
392
- delete answers[answerKey]; // rebuild answers based on new alternate positions after deletion
393
-
394
- var newAnswers = Object.entries(answers).reduce(function (acc, currentValue, index) {
395
- var _currentValue = (0, _slicedToArray2["default"])(currentValue, 2),
396
- key = _currentValue[0],
397
- value = _currentValue[1];
398
-
399
- var newAnswer = key === 'correctAnswer' ? _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, key, value)) : _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, 'alternate' + index, _objectSpread(_objectSpread({}, value), {}, {
400
- name: "Alternate ".concat(index)
401
- })));
309
+ (0, _defineProperty2.default)(this, "deleteAlternateResponse", (answerKey, answer) => {
310
+ const {
311
+ model,
312
+ onChange
313
+ } = this.props;
314
+ const {
315
+ answers
316
+ } = model || {};
317
+ const {
318
+ marks = [],
319
+ name
320
+ } = answer || {};
321
+ const deleteAnswer = () => {
322
+ delete answers[answerKey];
323
+ // rebuild answers based on new alternate positions after deletion
324
+ const newAnswers = Object.entries(answers).reduce((acc, currentValue, index) => {
325
+ const [key, value] = currentValue;
326
+ const newAnswer = key === 'correctAnswer' ? {
327
+ ...acc,
328
+ [key]: value
329
+ } : {
330
+ ...acc,
331
+ ['alternate' + index]: {
332
+ ...value,
333
+ name: `Alternate ${index}`
334
+ }
335
+ };
402
336
  return newAnswer;
403
337
  }, {});
404
- onChange(_objectSpread(_objectSpread({}, model), {}, {
338
+ onChange({
339
+ ...model,
405
340
  answers: newAnswers
406
- }));
341
+ });
407
342
  };
408
-
409
343
  if (marks.length) {
410
- _this.setState({
344
+ this.setState({
411
345
  dialog: {
412
346
  open: true,
413
347
  title: 'Warning',
414
- text: "".concat(name, " includes one or more shapes and the entire response will be deleted."),
415
- onConfirm: function onConfirm() {
416
- return _this.handleAlertDialog(false, deleteAnswer);
417
- },
418
- onClose: function onClose() {
419
- return _this.handleAlertDialog(false);
420
- }
348
+ text: `${name} includes one or more shapes and the entire response will be deleted.`,
349
+ onConfirm: () => this.handleAlertDialog(false, deleteAnswer),
350
+ onClose: () => this.handleAlertDialog(false)
421
351
  }
422
352
  });
423
-
424
353
  return;
425
354
  }
426
-
427
355
  deleteAnswer();
428
356
  });
429
- return _this;
430
357
  }
431
-
432
- (0, _createClass2["default"])(CorrectResponse, [{
433
- key: "componentDidMount",
434
- value: function componentDidMount() {
435
- try {
436
- // eslint-disable-next-line react/no-find-dom-node
437
- var domNode = _reactDom["default"].findDOMNode(this);
438
-
439
- (0, _mathRendering.renderMath)(domNode);
440
- } catch (e) {
441
- // Added try-catch block to handle "Unable to find node on an unmounted component" error from tests, thrown because of the usage of shallow
442
- console.error('DOM not mounted');
443
- }
358
+ componentDidMount() {
359
+ try {
360
+ // eslint-disable-next-line react/no-find-dom-node
361
+ const domNode = _reactDom.default.findDOMNode(this);
362
+ (0, _mathRendering.renderMath)(domNode);
363
+ } catch (e) {
364
+ // Added try-catch block to handle "Unable to find node on an unmounted component" error from tests, thrown because of the usage of shallow
365
+ console.error('DOM not mounted');
444
366
  }
445
- }, {
446
- key: "render",
447
- value: function render() {
448
- var _this2 = this;
449
-
450
- var _this$props6 = this.props,
451
- availableTools = _this$props6.availableTools,
452
- classes = _this$props6.classes,
453
- errors = _this$props6.errors,
454
- model = _this$props6.model,
455
- _this$props6$mathMlOp = _this$props6.mathMlOptions,
456
- mathMlOptions = _this$props6$mathMlOp === void 0 ? {} : _this$props6$mathMlOp,
457
- removeIncompleteTool = _this$props6.removeIncompleteTool;
458
- var dialog = this.state.dialog;
459
-
460
- var _ref7 = model || {},
461
- _ref7$answers = _ref7.answers,
462
- answers = _ref7$answers === void 0 ? {} : _ref7$answers,
463
- arrows = _ref7.arrows,
464
- backgroundMarks = _ref7.backgroundMarks,
465
- coordinatesOnHover = _ref7.coordinatesOnHover,
466
- defaultTool = _ref7.defaultTool,
467
- domain = _ref7.domain,
468
- _ref7$graph = _ref7.graph,
469
- graph = _ref7$graph === void 0 ? {} : _ref7$graph,
470
- labels = _ref7.labels,
471
- labelsEnabled = _ref7.labelsEnabled,
472
- range = _ref7.range,
473
- title = _ref7.title,
474
- titleEnabled = _ref7.titleEnabled,
475
- toolbarTools = _ref7.toolbarTools;
476
-
477
- var _ref8 = errors || {},
478
- _ref8$correctAnswerEr = _ref8.correctAnswerErrors,
479
- correctAnswerErrors = _ref8$correctAnswerEr === void 0 ? {} : _ref8$correctAnswerEr,
480
- toolbarToolsError = _ref8.toolbarToolsError;
481
-
482
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_core.Typography, {
483
- component: "div",
484
- variant: "subheading"
485
- }, "Define Tool Set and Correct Response"), /*#__PURE__*/React.createElement(_core.Typography, {
486
- component: "div",
487
- variant: "body1",
488
- className: classes.subtitleText
489
- }, "Use this interface to choose which graphing tools students will be able to use, and to define the correct answer"), /*#__PURE__*/React.createElement(Tools, {
490
- classes: classes,
491
- availableTools: availableTools,
492
- defaultTool: defaultTool,
493
- hasErrors: !!toolbarToolsError,
494
- onDefaultToolChange: this.onDefaultToolChange,
495
- toggleToolBarTool: this.toggleToolBarTool,
496
- toolbarTools: toolbarTools
497
- }), toolbarToolsError && /*#__PURE__*/React.createElement("div", {
498
- className: classes.errorMessage
499
- }, toolbarToolsError), Object.entries(answers || {}).map(function (_ref9) {
500
- var _ref10 = (0, _slicedToArray2["default"])(_ref9, 2),
501
- key = _ref10[0],
502
- answer = _ref10[1];
503
-
504
- var _ref11 = answer || {},
505
- _ref11$marks = _ref11.marks,
506
- marks = _ref11$marks === void 0 ? [] : _ref11$marks,
507
- name = _ref11.name;
508
-
509
- return /*#__PURE__*/React.createElement(React.Fragment, {
510
- key: "correct-response-graph-".concat(name)
511
- }, /*#__PURE__*/React.createElement("div", {
512
- className: classes.responseTitle
513
- }, /*#__PURE__*/React.createElement("div", {
514
- className: classes.name
515
- }, name), key === 'correctAnswer' && /*#__PURE__*/React.createElement(_core.Tooltip, {
516
- classes: {
517
- tooltip: classes.tooltip
518
- },
519
- disableFocusListener: true,
520
- disableTouchListener: true,
521
- placement: 'right',
522
- title: 'At least 1 graph object should be defined.'
523
- }, /*#__PURE__*/React.createElement(_Info["default"], {
524
- fontSize: 'small',
525
- color: 'primary',
526
- style: {
527
- marginLeft: '8px',
528
- marginBottom: 'auto'
529
- }
530
- })), key !== 'correctAnswer' && /*#__PURE__*/React.createElement(_Delete["default"], {
531
- className: classes.iconButton,
532
- onClick: function onClick() {
533
- return _this2.deleteAlternateResponse(key, answer);
534
- }
535
- })), /*#__PURE__*/React.createElement(_graphing.GraphContainer, {
536
- className: correctAnswerErrors[key] && classes.graphError,
537
- axesSettings: {
538
- includeArrows: arrows
539
- },
540
- backgroundMarks: backgroundMarks.filter(function (mark) {
541
- return !mark.building;
542
- }),
543
- coordinatesOnHover: coordinatesOnHover,
544
- disabledLabels: true,
545
- disabledTitle: true,
546
- domain: domain,
547
- draggableTools: key === 'correctAnswer',
548
- labels: labels,
549
- marks: marks,
550
- onChangeMarks: function onChangeMarks(newMarks) {
551
- return _this2.changeMarks(key, newMarks);
552
- },
553
- range: range,
554
- showLabels: labelsEnabled,
555
- showTitle: titleEnabled,
556
- size: {
557
- width: graph.width,
558
- height: graph.height
559
- },
560
- title: title,
561
- toolbarTools: toolbarTools,
562
- onChangeTools: function onChangeTools(toolbarTools) {
563
- return _this2.updateModel({
564
- toolbarTools: toolbarTools
565
- });
566
- },
567
- mathMlOptions: mathMlOptions,
568
- removeIncompleteTool: removeIncompleteTool,
569
- limitLabeling: true
570
- }), correctAnswerErrors[key] && /*#__PURE__*/React.createElement("div", {
571
- className: classes.errorMessage
572
- }, correctAnswerErrors[key]));
573
- }), /*#__PURE__*/React.createElement("div", {
574
- className: classes.button,
575
- onClick: this.addAlternateResponse
576
- }, "ADD ALTERNATE"), /*#__PURE__*/React.createElement(_configUi.AlertDialog, {
577
- open: dialog.open,
578
- title: dialog.title,
579
- text: dialog.text,
580
- onClose: dialog.onClose,
581
- onConfirm: dialog.onConfirm
582
- }));
583
- }
584
- }]);
585
- return CorrectResponse;
586
- }(React.Component);
587
-
367
+ }
368
+ render() {
369
+ const {
370
+ availableTools,
371
+ errors,
372
+ model,
373
+ mathMlOptions = {},
374
+ removeIncompleteTool
375
+ } = this.props;
376
+ const {
377
+ dialog
378
+ } = this.state;
379
+ const {
380
+ answers = {},
381
+ arrows,
382
+ backgroundMarks,
383
+ coordinatesOnHover,
384
+ defaultTool,
385
+ domain,
386
+ graph = {},
387
+ labels,
388
+ labelsEnabled,
389
+ range,
390
+ title,
391
+ titleEnabled,
392
+ toolbarTools
393
+ } = model || {};
394
+ const {
395
+ correctAnswerErrors = {},
396
+ toolbarToolsError
397
+ } = errors || {};
398
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_material.Typography, {
399
+ component: "div",
400
+ variant: "h6"
401
+ }, "Define Tool Set and Correct Response"), /*#__PURE__*/React.createElement(SubtitleText, {
402
+ component: "div",
403
+ variant: "body1"
404
+ }, "Use this interface to choose which graphing tools students will be able to use, and to define the correct answer"), /*#__PURE__*/React.createElement(Tools, {
405
+ availableTools: availableTools,
406
+ defaultTool: defaultTool,
407
+ hasErrors: !!toolbarToolsError,
408
+ onDefaultToolChange: this.onDefaultToolChange,
409
+ toggleToolBarTool: this.toggleToolBarTool,
410
+ toolbarTools: toolbarTools
411
+ }), toolbarToolsError && /*#__PURE__*/React.createElement(ErrorMessage, null, toolbarToolsError), Object.entries(answers || {}).map(([key, answer]) => {
412
+ const {
413
+ marks = [],
414
+ name
415
+ } = answer || {};
416
+ return /*#__PURE__*/React.createElement(React.Fragment, {
417
+ key: `correct-response-graph-${name}`
418
+ }, /*#__PURE__*/React.createElement(ResponseTitle, null, /*#__PURE__*/React.createElement(Name, null, name), key === 'correctAnswer' && /*#__PURE__*/React.createElement(StyledTooltip, {
419
+ disableFocusListener: true,
420
+ disableTouchListener: true,
421
+ placement: 'right',
422
+ title: 'At least 1 graph object should be defined.'
423
+ }, /*#__PURE__*/React.createElement(_Info.default, {
424
+ fontSize: 'small',
425
+ color: 'primary',
426
+ style: {
427
+ marginLeft: '8px',
428
+ marginBottom: 'auto'
429
+ }
430
+ })), key !== 'correctAnswer' && /*#__PURE__*/React.createElement(IconButton, {
431
+ onClick: () => this.deleteAlternateResponse(key, answer)
432
+ }, /*#__PURE__*/React.createElement(_Delete.default, null))), /*#__PURE__*/React.createElement(_graphing.GraphContainer, {
433
+ style: correctAnswerErrors[key] && {
434
+ border: '2px solid red'
435
+ },
436
+ axesSettings: {
437
+ includeArrows: arrows
438
+ },
439
+ backgroundMarks: backgroundMarks.filter(mark => !mark.building),
440
+ coordinatesOnHover: coordinatesOnHover,
441
+ disabledLabels: true,
442
+ disabledTitle: true,
443
+ domain: domain,
444
+ draggableTools: key === 'correctAnswer',
445
+ labels: labels,
446
+ marks: marks,
447
+ onChangeMarks: newMarks => this.changeMarks(key, newMarks),
448
+ range: range,
449
+ showLabels: labelsEnabled,
450
+ showTitle: titleEnabled,
451
+ size: {
452
+ width: graph.width,
453
+ height: graph.height
454
+ },
455
+ title: title,
456
+ toolbarTools: toolbarTools,
457
+ onChangeTools: toolbarTools => this.updateModel({
458
+ toolbarTools
459
+ }),
460
+ mathMlOptions: mathMlOptions,
461
+ removeIncompleteTool: removeIncompleteTool,
462
+ limitLabeling: true
463
+ }), correctAnswerErrors[key] && /*#__PURE__*/React.createElement(ErrorMessage, null, correctAnswerErrors[key]));
464
+ }), /*#__PURE__*/React.createElement(Button, {
465
+ onClick: this.addAlternateResponse
466
+ }, "ADD ALTERNATE"), /*#__PURE__*/React.createElement(_configUi.AlertDialog, {
467
+ open: dialog.open,
468
+ title: dialog.title,
469
+ text: dialog.text,
470
+ onClose: dialog.onClose,
471
+ onConfirm: dialog.onConfirm
472
+ }));
473
+ }
474
+ }
588
475
  exports.CorrectResponse = CorrectResponse;
589
- (0, _defineProperty2["default"])(CorrectResponse, "propTypes", {
590
- availableTools: _propTypes["default"].array,
591
- classes: _propTypes["default"].object.isRequired,
592
- errors: _propTypes["default"].object,
593
- model: _propTypes["default"].object.isRequired,
594
- onChange: _propTypes["default"].func.isRequired,
595
- toolbarTools: _propTypes["default"].arrayOf(_propTypes["default"].String)
476
+ (0, _defineProperty2.default)(CorrectResponse, "propTypes", {
477
+ availableTools: _propTypes.default.array,
478
+ errors: _propTypes.default.object,
479
+ model: _propTypes.default.object.isRequired,
480
+ onChange: _propTypes.default.func.isRequired,
481
+ toolbarTools: _propTypes.default.arrayOf(_propTypes.default.String)
596
482
  });
597
-
598
- var _default = (0, _styles.withStyles)(styles)(CorrectResponse);
599
-
600
- exports["default"] = _default;
483
+ var _default = exports.default = CorrectResponse;
601
484
  //# sourceMappingURL=correct-response.js.map