@pie-element/graphing-solution-set 4.3.4-next.0 → 5.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,287 +1,161 @@
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.CorrectResponse = void 0;
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
-
20
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
-
22
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
-
7
+ exports.default = exports.CorrectResponse = void 0;
24
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
9
  var React = _interopRequireWildcard(require("react"));
27
-
28
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
29
-
30
- var _styles = require("@material-ui/core/styles");
31
-
11
+ var _styles = require("@mui/material/styles");
32
12
  var _graphingSolutionSet = require("@pie-lib/graphing-solution-set");
33
-
34
13
  var _configUi = require("@pie-lib/config-ui");
35
-
36
14
  var _lodash = require("lodash");
37
-
38
- var _core = require("@material-ui/core");
39
-
40
- var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));
41
-
42
- var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
43
-
15
+ var _material = require("@mui/material");
16
+ var _Radio = _interopRequireDefault(require("@mui/material/Radio"));
17
+ var _FormControlLabel = _interopRequireDefault(require("@mui/material/FormControlLabel"));
44
18
  var _utils = require("./utils");
45
-
46
- 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); }
47
-
48
- 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; }
49
-
50
- 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; }
51
-
52
- 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; }
53
-
54
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
55
-
56
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
57
-
58
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
59
-
60
- 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); }; }
61
-
62
- 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; } }
63
-
64
- var styles = function styles(theme) {
65
- return {
66
- column: {
67
- flex: 1
68
- },
69
- graphingTools: {
70
- color: theme.palette.grey['A200']
71
- },
72
- availableTool: {
73
- cursor: 'pointer',
74
- margin: theme.spacing.unit,
75
- padding: theme.spacing.unit,
76
- border: "2px solid ".concat(theme.palette.common.white),
77
- textTransform: 'capitalize',
78
- '&:hover': {
79
- color: theme.palette.grey[800]
80
- }
81
- },
82
- selectedTool: {
83
- background: theme.palette.grey['A100'],
84
- border: "2px solid ".concat(theme.palette.grey['A200'])
85
- },
86
- container: {
87
- border: "2px solid ".concat(theme.palette.grey['A200']),
88
- borderRadius: '4px',
89
- padding: "0 ".concat(theme.spacing.unit * 4, "px ").concat(theme.spacing.unit * 2, "px"),
90
- background: theme.palette.grey[50]
91
- },
92
- button: {
93
- margin: "".concat(theme.spacing.unit * 2.5, "px 0"),
94
- cursor: 'pointer',
95
- background: theme.palette.grey[200],
96
- padding: theme.spacing.unit * 1.5,
97
- width: 'fit-content',
98
- borderRadius: '4px',
99
- '&:hover': {
100
- background: theme.palette.grey['A100']
101
- }
102
- },
103
- responseTitle: {
104
- display: 'flex',
105
- alignItems: 'center',
106
- marginTop: theme.spacing.unit * 2.5
107
- },
108
- iconButton: {
109
- marginLeft: '6px',
110
- color: theme.palette.grey[600],
111
- '&:hover': {
112
- cursor: 'pointer',
113
- color: theme.palette.common.black
114
- }
115
- },
116
- name: {
117
- marginBottom: theme.spacing.unit / 2
118
- },
119
- tooltip: {
120
- fontSize: theme.typography.fontSize - 2,
121
- whiteSpace: 'pre',
122
- maxWidth: '500px'
123
- },
124
- subtitleText: {
125
- marginTop: theme.spacing.unit * 1.5,
126
- marginBottom: theme.spacing.unit
127
- },
128
- toolsHeader: {
129
- display: 'flex',
130
- alignItems: 'center',
131
- justifyContent: 'space-between'
132
- },
133
- defaultTool: {
134
- display: 'flex',
135
- alignItems: 'center',
136
- width: '300px'
137
- },
138
- defaultToolSelect: {
139
- marginLeft: theme.spacing.unit,
140
- textTransform: 'uppercase',
141
- color: theme.palette.grey[800]
142
- },
143
- menuItem: {
144
- textTransform: 'uppercase'
145
- },
146
- noDefaultTool: {
147
- padding: theme.spacing.unit / 2
148
- },
149
- error: {
150
- color: theme.palette.error.main
151
- },
152
- errorMessage: {
153
- fontSize: theme.typography.fontSize - 2,
154
- color: theme.palette.error.main,
155
- marginTop: theme.spacing.unit
156
- },
157
- graphError: {
158
- border: "2px solid ".concat(theme.palette.error.main)
159
- },
160
- radioButtonClass: {
161
- height: '20px',
162
- width: 'fit-content',
163
- padding: '.5rem 0'
164
- },
165
- radioButton: {
166
- color: '#000000 !important'
167
- }
168
- };
169
- };
170
-
171
- var CorrectResponse = /*#__PURE__*/function (_React$Component) {
172
- (0, _inherits2["default"])(CorrectResponse, _React$Component);
173
-
174
- var _super = _createSuper(CorrectResponse);
175
-
176
- function CorrectResponse() {
177
- var _this;
178
-
179
- (0, _classCallCheck2["default"])(this, CorrectResponse);
180
-
181
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
182
- args[_key] = arguments[_key];
183
- }
184
-
185
- _this = _super.call.apply(_super, [this].concat(args));
186
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
19
+ 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); }
20
+ const SubtitleText = (0, _styles.styled)(_material.Typography)(({
21
+ theme
22
+ }) => ({
23
+ marginTop: theme.spacing(1.5),
24
+ marginBottom: theme.spacing(1)
25
+ }));
26
+ const RadioButtonClass = (0, _styles.styled)(_FormControlLabel.default)({
27
+ height: '20px',
28
+ width: 'fit-content',
29
+ padding: '.5rem 0'
30
+ });
31
+ const StyledRadio = (0, _styles.styled)(_Radio.default)({
32
+ color: '#000000 !important'
33
+ });
34
+ const ErrorMessage = (0, _styles.styled)('div')(({
35
+ theme
36
+ }) => ({
37
+ fontSize: theme.typography.fontSize - 2,
38
+ color: theme.palette.error.main,
39
+ paddingTop: theme.spacing(1)
40
+ }));
41
+ class CorrectResponse extends React.Component {
42
+ constructor(...args) {
43
+ super(...args);
44
+ (0, _defineProperty2.default)(this, "state", {
187
45
  dialog: {
188
46
  open: false
189
47
  }
190
48
  });
191
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAlertDialog", function (open, callback) {
192
- return _this.setState({
193
- dialog: {
194
- open: open
195
- }
196
- }, callback);
197
- });
198
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeMarks", function (marks) {
199
- var _this$props = _this.props,
200
- model = _this$props.model,
201
- onChange = _this$props.onChange;
202
- var gssLineData = model.gssLineData;
203
-
49
+ /*
50
+ * Function to handle the alert dialog open and close
51
+ * @param {boolean} open - open or close the dialog
52
+ * @param {function} callback - callback function to be called after setting the state
53
+ * */
54
+ (0, _defineProperty2.default)(this, "handleAlertDialog", (open, callback) => this.setState({
55
+ dialog: {
56
+ open
57
+ }
58
+ }, callback));
59
+ /*
60
+ * Function to change the marks on the graph
61
+ * @param {array} marks - marks to be added on the graph
62
+ * */
63
+ (0, _defineProperty2.default)(this, "changeMarks", marks => {
64
+ const {
65
+ model,
66
+ onChange
67
+ } = this.props;
68
+ const {
69
+ gssLineData
70
+ } = model;
204
71
  if (gssLineData.selectedTool === 'lineA' && marks.length > 0) {
205
72
  marks[0].fill = gssLineData['lineA'].lineType;
206
73
  }
207
-
208
74
  if (gssLineData.selectedTool === 'lineB' && marks.length > 1) {
209
75
  marks[1].fill = gssLineData['lineB'].lineType;
210
76
  }
211
-
212
77
  if (marks.length === 0) {
213
78
  gssLineData.selectedTool = 'lineA';
214
- (0, _lodash.set)(model, "gssLineData", gssLineData);
79
+ (0, _lodash.set)(model, 'gssLineData', gssLineData);
215
80
  }
216
-
217
- (0, _lodash.set)(model, "answers.correctAnswer.marks", marks);
81
+ (0, _lodash.set)(model, 'answers.correctAnswer.marks', marks);
218
82
  onChange(model);
219
83
  });
220
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onResetClick", function () {
221
- var _this$props2 = _this.props,
222
- model = _this$props2.model,
223
- onChange = _this$props2.onChange;
224
- var gssLineData = model.gssLineData,
225
- answers = model.answers;
226
-
227
- _this.setState({
84
+ /*
85
+ * Reset the graph to original state and remove all the elements added on the graph
86
+ * */
87
+ (0, _defineProperty2.default)(this, "onResetClick", () => {
88
+ const {
89
+ model,
90
+ onChange
91
+ } = this.props;
92
+ const {
93
+ gssLineData,
94
+ answers
95
+ } = model;
96
+ this.setState({
228
97
  dialog: {
229
98
  open: true,
230
99
  title: 'Warning',
231
- text: "This will remove all the elements added on the graph and reset graph to original state. Are you sure you want to continue?",
232
- onConfirm: function onConfirm() {
100
+ text: 'This will remove all the elements added on the graph and reset graph to original state. Are you sure you want to continue?',
101
+ onConfirm: () => {
233
102
  // Reset the graph to original state
234
103
  answers.correctAnswer.marks = [];
235
104
  gssLineData.selectedTool = 'lineA';
236
105
  gssLineData.lineA.lineType = 'Solid';
237
106
  if (gssLineData.lineB) gssLineData.lineB.lineType = 'Solid';
238
- (0, _lodash.set)(model, "answers", answers);
239
- (0, _lodash.set)(model, "gssLineData", gssLineData);
107
+ (0, _lodash.set)(model, 'answers', answers);
108
+ (0, _lodash.set)(model, 'gssLineData', gssLineData);
240
109
  onChange(model);
241
-
242
- _this.handleAlertDialog(false);
110
+ this.handleAlertDialog(false);
243
111
  },
244
- onClose: function onClose() {
245
- return _this.handleAlertDialog(false);
246
- }
112
+ onClose: () => this.handleAlertDialog(false)
247
113
  }
248
114
  });
249
115
  });
250
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeNumberOfLines", function (e, value) {
251
- var model = _this.props.model;
252
- var gssLineData = model.gssLineData;
253
-
116
+ /*
117
+ * Function to change the number of lines on the graph
118
+ * @param {object} e - event object
119
+ * @param {number} value - number of lines to be added on the graph
120
+ * */
121
+ (0, _defineProperty2.default)(this, "changeNumberOfLines", (e, value) => {
122
+ const {
123
+ model
124
+ } = this.props;
125
+ let gssLineData = model.gssLineData;
254
126
  if (gssLineData.selectedTool === 'solutionSet') {
255
- _this.setState({
127
+ this.setState({
256
128
  dialog: {
257
129
  open: true,
258
130
  title: 'Warning',
259
- text: "Changing number of lines after adding solution set will remove added solution set. Are you sure you want to continue?",
260
- onConfirm: function onConfirm() {
261
- _this.changeLine(e, value);
262
-
263
- _this.handleAlertDialog(false);
131
+ text: 'Changing number of lines after adding solution set will remove added solution set. Are you sure you want to continue?',
132
+ onConfirm: () => {
133
+ this.changeLine(e, value);
134
+ this.handleAlertDialog(false);
264
135
  },
265
- onClose: function onClose() {
266
- return _this.handleAlertDialog(false);
267
- }
136
+ onClose: () => this.handleAlertDialog(false)
268
137
  }
269
138
  });
270
139
  } else {
271
- _this.changeLine(e, value);
140
+ this.changeLine(e, value);
272
141
  }
273
142
  });
274
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeLine", function (e, value) {
275
- var _this$props3 = _this.props,
276
- model = _this$props3.model,
277
- onChange = _this$props3.onChange;
278
- var answers = model.answers;
279
- var gssLineData = model.gssLineData; //remove polygon from correct answer
280
-
281
- answers.correctAnswer.marks = answers.correctAnswer.marks.filter(function (mark) {
282
- return mark.type !== 'polygon';
283
- });
284
-
143
+ /*
144
+ * Function to change the number of line on the graph
145
+ * @param {object} e - event object
146
+ * @param {number} value - number of lines to be added on the graph
147
+ * */
148
+ (0, _defineProperty2.default)(this, "changeLine", (e, value) => {
149
+ const {
150
+ model,
151
+ onChange
152
+ } = this.props;
153
+ const {
154
+ answers
155
+ } = model;
156
+ let gssLineData = model.gssLineData;
157
+ //remove polygon from correct answer
158
+ answers.correctAnswer.marks = answers.correctAnswer.marks.filter(mark => mark.type !== 'polygon');
285
159
  if (Number.parseInt(value) === 1) {
286
160
  //remove lineB from gssLineData and correct answer
287
161
  delete gssLineData.lineB;
@@ -294,308 +168,268 @@ var CorrectResponse = /*#__PURE__*/function (_React$Component) {
294
168
  gssLineData.lineB = {
295
169
  lineType: 'Solid'
296
170
  };
297
- } //reset solution set
298
-
299
-
300
- (0, _lodash.set)(model, "answers", answers);
301
- (0, _lodash.set)(model, "gssLineData", gssLineData);
171
+ }
172
+ //reset solution set
173
+ (0, _lodash.set)(model, 'answers', answers);
174
+ (0, _lodash.set)(model, 'gssLineData', gssLineData);
302
175
  onChange(model);
303
176
  });
304
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSolutionSetSelected", function (point) {
305
- var _this$props4 = _this.props,
306
- model = _this$props4.model,
307
- onChange = _this$props4.onChange;
308
- var answers = model.answers,
309
- gssLineData = model.gssLineData;
310
-
311
- var _iterator = _createForOfIteratorHelper(gssLineData.sections),
312
- _step;
313
-
314
- try {
315
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
316
- var section = _step.value;
317
-
318
- //check if the point is inside the polygon
319
- if ((0, _utils.pointInsidePolygon)(point, section)) {
320
- var polygon = {
321
- points: section,
322
- building: false,
323
- type: 'polygon',
324
- closed: true,
325
- isSolution: true
326
- }; //remove old answer section from correct answer
327
-
328
- answers.correctAnswer.marks = answers.correctAnswer.marks.filter(function (mark) {
329
- return mark.type !== 'polygon';
330
- }); //add new answer section to correct answer
331
-
332
- answers.correctAnswer.marks.push(polygon);
333
- break;
334
- }
177
+ /*
178
+ * Function to handle the changes to solution set on the graph
179
+ * @param {object} point - point selected on the graph
180
+ * */
181
+ (0, _defineProperty2.default)(this, "onSolutionSetSelected", point => {
182
+ const {
183
+ model,
184
+ onChange
185
+ } = this.props;
186
+ const {
187
+ answers,
188
+ gssLineData
189
+ } = model;
190
+ for (const section of gssLineData.sections) {
191
+ //check if the point is inside the polygon
192
+ if ((0, _utils.pointInsidePolygon)(point, section)) {
193
+ let polygon = {
194
+ points: section,
195
+ building: false,
196
+ type: 'polygon',
197
+ closed: true,
198
+ isSolution: true
199
+ };
200
+ //remove old answer section from correct answer
201
+ answers.correctAnswer.marks = answers.correctAnswer.marks.filter(mark => mark.type !== 'polygon');
202
+ //add new answer section to correct answer
203
+ answers.correctAnswer.marks.push(polygon);
204
+ break;
335
205
  }
336
- } catch (err) {
337
- _iterator.e(err);
338
- } finally {
339
- _iterator.f();
340
206
  }
341
-
342
- (0, _lodash.set)(model, "answers", answers);
207
+ (0, _lodash.set)(model, 'answers', answers);
343
208
  onChange(model);
344
209
  });
345
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChangeGssLineData", function (gssLineData, oldSelectedTool) {
346
- var model = _this.props.model;
347
- var answers = model.answers,
348
- domain = model.domain,
349
- range = model.range; //handle solution set changes
350
-
210
+ /*
211
+ * Function to handle the changes to line data on the graph
212
+ * @param {object} gssLineData - line data on the graph
213
+ * @param {string} oldSelectedTool - old selected tool
214
+ * */
215
+ (0, _defineProperty2.default)(this, "onChangeGssLineData", (gssLineData, oldSelectedTool) => {
216
+ const {
217
+ model
218
+ } = this.props;
219
+ const {
220
+ answers,
221
+ domain,
222
+ range
223
+ } = model;
224
+ //handle solution set changes
351
225
  if (gssLineData.selectedTool === 'solutionSet') {
352
- var lines = answers.correctAnswer.marks.filter(function (mark) {
353
- return mark.type !== 'polygon';
354
- });
355
-
226
+ let lines = answers.correctAnswer.marks.filter(mark => mark.type !== 'polygon');
356
227
  if (!(0, _utils.checkIfLinesAreAdded)(gssLineData, lines)) {
357
228
  gssLineData.selectedTool = oldSelectedTool;
358
-
359
- _this.setState({
229
+ this.setState({
360
230
  dialog: {
361
231
  open: true,
362
232
  title: 'Warning',
363
- text: "Please define the line(s) and then select a solution set for the item.",
364
- onConfirm: function onConfirm() {
365
- return _this.handleAlertDialog(false);
366
- }
233
+ text: 'Please define the line(s) and then select a solution set for the item.',
234
+ onConfirm: () => this.handleAlertDialog(false)
367
235
  }
368
236
  });
369
237
  } else {
370
- var _lines = answers.correctAnswer.marks.filter(function (mark) {
371
- return mark.type !== 'polygon';
372
- });
373
-
374
- gssLineData = (0, _utils.findSectionsInSolutionSet)(gssLineData, _lines, domain, range);
238
+ let lines = answers.correctAnswer.marks.filter(mark => mark.type !== 'polygon');
239
+ gssLineData = (0, _utils.findSectionsInSolutionSet)(gssLineData, lines, domain, range);
375
240
  }
376
-
377
- _this.handleGssLineDataChange(gssLineData, answers);
241
+ this.handleGssLineDataChange(gssLineData, answers);
378
242
  } else {
379
- var polygons = answers.correctAnswer.marks.filter(function (mark) {
380
- return mark.type === 'polygon';
381
- });
382
-
243
+ let polygons = answers.correctAnswer.marks.filter(mark => mark.type === 'polygon');
383
244
  if (oldSelectedTool === 'solutionSet' && polygons.length > 0) {
384
- _this.setState({
245
+ this.setState({
385
246
  dialog: {
386
247
  open: true,
387
248
  title: 'Warning',
388
- text: "Changing a line after adding a solution set will clear your selected solution set. Click 'Clear Solution Set' to change the line. Otherwise, click 'Cancel'.",
389
- onConfirm: function onConfirm() {
390
- answers.correctAnswer.marks = answers.correctAnswer.marks.filter(function (mark) {
391
- return mark.type !== 'polygon';
392
- });
393
-
394
- _this.handleGssLineDataChange(gssLineData, answers);
395
-
396
- _this.handleAlertDialog(false);
249
+ text: 'Changing a line after adding a solution set will clear your selected solution set. Click \'Clear Solution Set\' to change the line. Otherwise, click \'Cancel\'.',
250
+ onConfirm: () => {
251
+ answers.correctAnswer.marks = answers.correctAnswer.marks.filter(mark => mark.type !== 'polygon');
252
+ this.handleGssLineDataChange(gssLineData, answers);
253
+ this.handleAlertDialog(false);
397
254
  },
398
255
  onConfirmText: 'CLEAR SOLUTION SET',
399
- onClose: function onClose() {
256
+ onClose: () => {
400
257
  gssLineData.selectedTool = oldSelectedTool;
401
-
402
- _this.handleGssLineDataChange(gssLineData, answers);
403
-
404
- _this.handleAlertDialog(false);
258
+ this.handleGssLineDataChange(gssLineData, answers);
259
+ this.handleAlertDialog(false);
405
260
  }
406
261
  }
407
262
  });
408
263
  } else {
409
- _this.handleGssLineDataChange(gssLineData, answers);
264
+ this.handleGssLineDataChange(gssLineData, answers);
410
265
  }
411
266
  }
412
267
  });
413
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleGssLineDataChange", function (gssLineData, answers) {
414
- var _this$props5 = _this.props,
415
- model = _this$props5.model,
416
- onChange = _this$props5.onChange; //handle line type changes from solid to dashed and vice versa
417
-
268
+ /*
269
+ * Function to handle the changes to line data on the graph
270
+ * @param {object} gssLineData - line data on the graph
271
+ * @param {object} answers - correct answer
272
+ * */
273
+ (0, _defineProperty2.default)(this, "handleGssLineDataChange", (gssLineData, answers) => {
274
+ const {
275
+ model,
276
+ onChange
277
+ } = this.props;
278
+ //handle line type changes from solid to dashed and vice versa
418
279
  if (answers.correctAnswer.marks.length > 0 && answers.correctAnswer.marks[0] && gssLineData.lineA) {
419
280
  answers.correctAnswer.marks[0].fill = gssLineData.lineA.lineType;
420
281
  }
421
-
422
282
  if (answers.correctAnswer.marks.length > 1 && answers.correctAnswer.marks[1] && gssLineData.lineB) {
423
283
  answers.correctAnswer.marks[1].fill = gssLineData.lineB.lineType;
424
- } //check if line is added to the graph before switching to lineB
425
-
426
-
284
+ }
285
+ //check if line is added to the graph before switching to lineB
427
286
  if (gssLineData.selectedTool === 'lineB' && answers.correctAnswer.marks.length === 0 || gssLineData.selectedTool === 'lineB' && answers.correctAnswer.marks[0].building) {
428
- _this.setState({
287
+ this.setState({
429
288
  dialog: {
430
289
  open: true,
431
290
  title: 'Warning',
432
- text: "Please add Line A to the graph before adding Line B",
433
- onConfirm: function onConfirm() {
434
- return _this.handleAlertDialog(false);
435
- }
291
+ text: 'Please add Line A to the graph before adding Line B',
292
+ onConfirm: () => this.handleAlertDialog(false)
436
293
  }
437
294
  });
438
-
439
295
  gssLineData.selectedTool = 'lineA';
440
- } //check if lineB is added to the graph before switching to lineA
441
-
442
-
296
+ }
297
+ //check if lineB is added to the graph before switching to lineA
443
298
  if (gssLineData.selectedTool === 'lineA' && answers.correctAnswer.marks.length > 1 && answers.correctAnswer.marks[1].building) {
444
- _this.setState({
299
+ this.setState({
445
300
  dialog: {
446
301
  open: true,
447
302
  title: 'Warning',
448
- text: "Please add Line B to the graph before switching to Line A",
449
- onConfirm: function onConfirm() {
450
- return _this.handleAlertDialog(false);
451
- }
303
+ text: 'Please add Line B to the graph before switching to Line A',
304
+ onConfirm: () => this.handleAlertDialog(false)
452
305
  }
453
306
  });
454
-
455
307
  gssLineData.selectedTool = 'lineB';
456
308
  }
457
-
458
- (0, _lodash.set)(model, "gssLineData", gssLineData);
459
- (0, _lodash.set)(model, "answers", answers);
309
+ (0, _lodash.set)(model, 'gssLineData', gssLineData);
310
+ (0, _lodash.set)(model, 'answers', answers);
460
311
  onChange(model);
461
312
  });
462
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateModel", function (props) {
463
- var _this$props6 = _this.props,
464
- model = _this$props6.model,
465
- onChange = _this$props6.onChange;
466
- onChange(_objectSpread(_objectSpread({}, model), props));
467
- });
468
- return _this;
469
- }
470
-
471
- (0, _createClass2["default"])(CorrectResponse, [{
472
- key: "render",
473
- value:
474
313
  /*
475
- * Render the component
314
+ * Function to update the model
315
+ * @param {object} props - updated props
476
316
  * */
477
- function render() {
478
- var _this2 = this;
479
-
480
- var _this$props7 = this.props,
481
- classes = _this$props7.classes,
482
- errors = _this$props7.errors,
483
- model = _this$props7.model,
484
- _this$props7$mathMlOp = _this$props7.mathMlOptions,
485
- mathMlOptions = _this$props7$mathMlOp === void 0 ? {} : _this$props7$mathMlOp;
486
- var dialog = this.state.dialog; //get the default values to GssLineData
487
-
488
- var _ref = model || {},
489
- _ref$gssLineData = _ref.gssLineData,
490
- gssLineData = _ref$gssLineData === void 0 ? {
317
+ (0, _defineProperty2.default)(this, "updateModel", props => {
318
+ const {
319
+ model,
320
+ onChange
321
+ } = this.props;
322
+ onChange({
323
+ ...model,
324
+ ...props
325
+ });
326
+ });
327
+ }
328
+ /*
329
+ * Render the component
330
+ * */
331
+ render() {
332
+ const {
333
+ errors,
334
+ model,
335
+ mathMlOptions = {}
336
+ } = this.props;
337
+ const {
338
+ dialog
339
+ } = this.state;
340
+ //get the default values to GssLineData
341
+ const {
342
+ gssLineData = {
491
343
  numberOfLines: 1,
492
344
  selectedTool: 'lineA',
493
345
  lineA: {
494
346
  lineType: 'Solid'
495
347
  }
496
- } : _ref$gssLineData,
497
- arrows = _ref.arrows,
498
- coordinatesOnHover = _ref.coordinatesOnHover,
499
- domain = _ref.domain,
500
- _ref$graph = _ref.graph,
501
- graph = _ref$graph === void 0 ? {} : _ref$graph,
502
- labels = _ref.labels,
503
- labelsEnabled = _ref.labelsEnabled,
504
- range = _ref.range,
505
- title = _ref.title,
506
- titleEnabled = _ref.titleEnabled,
507
- marks = _ref.marks,
508
- answers = _ref.answers;
509
-
510
- var _ref2 = errors || {},
511
- _ref2$correctAnswerEr = _ref2.correctAnswerErrors,
512
- correctAnswerErrors = _ref2$correctAnswerEr === void 0 ? '' : _ref2$correctAnswerEr;
513
-
514
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_core.Typography, {
515
- component: "div",
516
- variant: "subheading"
517
- }, "Define Line Type(s) and Correct Response"), /*#__PURE__*/React.createElement(_core.Typography, {
518
- component: "div",
519
- variant: "body1",
520
- className: classes.subtitleText
521
- }, "Use this interface to choose how many lines students will be able to draw, and to define the correct answer."), /*#__PURE__*/React.createElement(_core.Typography, {
522
- component: "div",
523
- variant: "body1",
524
- className: classes.subtitleText
525
- }, "Choose Number of Lines"), /*#__PURE__*/React.createElement(_core.RadioGroup, {
526
- name: "numberOfLines",
527
- value: gssLineData.numberOfLines,
528
- onChange: this.changeNumberOfLines
529
- }, /*#__PURE__*/React.createElement(_FormControlLabel["default"], {
530
- className: classes.radioButtonClass,
531
- value: "1",
532
- control: /*#__PURE__*/React.createElement(_Radio["default"], {
533
- checked: gssLineData.numberOfLines === 1,
534
- className: classes.radioButton
535
- }),
536
- label: "One"
537
- }), /*#__PURE__*/React.createElement(_FormControlLabel["default"], {
538
- className: classes.radioButtonClass,
539
- value: "2",
540
- control: /*#__PURE__*/React.createElement(_Radio["default"], {
541
- checked: gssLineData.numberOfLines === 2,
542
- className: classes.radioButton
543
- }),
544
- label: "Two"
545
- })), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_graphingSolutionSet.GraphContainer, {
546
- className: correctAnswerErrors['correctAnswer'] && classes.graphError,
547
- axesSettings: {
548
- includeArrows: arrows
549
- },
550
- backgroundMarks: [],
551
- coordinatesOnHover: coordinatesOnHover,
552
- disabledLabels: true,
553
- disabledTitle: true,
554
- domain: domain,
555
- draggableTools: true,
556
- labels: labels,
557
- marks: answers && answers.correctAnswer && answers.correctAnswer.marks ? answers.correctAnswer.marks : [],
558
- onChangeMarks: function onChangeMarks(newMarks) {
559
- return _this2.changeMarks(newMarks);
560
- },
561
- onCustomReset: this.onResetClick,
562
- range: range,
563
- showLabels: labelsEnabled,
564
- showTitle: titleEnabled,
565
- size: {
566
- width: graph.width,
567
- height: graph.height
568
- },
569
- title: title,
570
- gssLineData: gssLineData,
571
- onChangeGssLineData: this.onChangeGssLineData,
572
- onSolutionSetSelected: this.onSolutionSetSelected,
573
- toolbarTools: ['line', 'polygon'],
574
- mathMlOptions: mathMlOptions
575
- }), correctAnswerErrors['correctAnswer'] && /*#__PURE__*/React.createElement("div", {
576
- className: classes.errorMessage
577
- }, correctAnswerErrors['correctAnswer'])), /*#__PURE__*/React.createElement(_configUi.AlertDialog, {
578
- open: dialog.open,
579
- title: dialog.title,
580
- text: dialog.text,
581
- onClose: dialog.onClose,
582
- onConfirm: dialog.onConfirm,
583
- onConfirmText: dialog.onConfirmText ? dialog.onConfirmText : 'OK'
584
- }));
585
- }
586
- }]);
587
- return CorrectResponse;
588
- }(React.Component);
589
-
348
+ },
349
+ arrows,
350
+ coordinatesOnHover,
351
+ domain,
352
+ graph = {},
353
+ labels,
354
+ labelsEnabled,
355
+ range,
356
+ title,
357
+ titleEnabled,
358
+ answers
359
+ } = model || {};
360
+ const {
361
+ correctAnswerErrors = ''
362
+ } = errors || {};
363
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_material.Typography, {
364
+ component: "div",
365
+ variant: "h6"
366
+ }, "Define Line Type(s) and Correct Response"), /*#__PURE__*/React.createElement(SubtitleText, {
367
+ component: "div",
368
+ variant: "body1"
369
+ }, "Use this interface to choose how many lines students will be able to draw, and to define the correct answer."), /*#__PURE__*/React.createElement(SubtitleText, {
370
+ component: "div",
371
+ variant: "body1"
372
+ }, "Choose Number of Lines"), /*#__PURE__*/React.createElement(_material.RadioGroup, {
373
+ name: "numberOfLines",
374
+ value: gssLineData.numberOfLines,
375
+ onChange: this.changeNumberOfLines
376
+ }, /*#__PURE__*/React.createElement(RadioButtonClass, {
377
+ value: "1",
378
+ control: /*#__PURE__*/React.createElement(StyledRadio, {
379
+ checked: gssLineData.numberOfLines === 1
380
+ }),
381
+ label: "One"
382
+ }), /*#__PURE__*/React.createElement(RadioButtonClass, {
383
+ value: "2",
384
+ control: /*#__PURE__*/React.createElement(StyledRadio, {
385
+ checked: gssLineData.numberOfLines === 2
386
+ }),
387
+ label: "Two"
388
+ })), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_graphingSolutionSet.GraphContainer, {
389
+ style: correctAnswerErrors['correctAnswer'] && {
390
+ border: '2px solid red'
391
+ },
392
+ axesSettings: {
393
+ includeArrows: arrows
394
+ },
395
+ backgroundMarks: [],
396
+ coordinatesOnHover: coordinatesOnHover,
397
+ disabledLabels: true,
398
+ disabledTitle: true,
399
+ domain: domain,
400
+ draggableTools: true,
401
+ labels: labels,
402
+ marks: answers && answers.correctAnswer && answers.correctAnswer.marks ? answers.correctAnswer.marks : [],
403
+ onChangeMarks: newMarks => this.changeMarks(newMarks),
404
+ onCustomReset: this.onResetClick,
405
+ range: range,
406
+ showLabels: labelsEnabled,
407
+ showTitle: titleEnabled,
408
+ size: {
409
+ width: graph.width,
410
+ height: graph.height
411
+ },
412
+ title: title,
413
+ gssLineData: gssLineData,
414
+ onChangeGssLineData: this.onChangeGssLineData,
415
+ onSolutionSetSelected: this.onSolutionSetSelected,
416
+ toolbarTools: ['line', 'polygon'],
417
+ mathMlOptions: mathMlOptions
418
+ }), correctAnswerErrors['correctAnswer'] && /*#__PURE__*/React.createElement(ErrorMessage, null, correctAnswerErrors['correctAnswer'])), /*#__PURE__*/React.createElement(_configUi.AlertDialog, {
419
+ open: dialog.open,
420
+ title: dialog.title,
421
+ text: dialog.text,
422
+ onClose: dialog.onClose,
423
+ onConfirm: dialog.onConfirm,
424
+ onConfirmText: dialog.onConfirmText ? dialog.onConfirmText : 'OK'
425
+ }));
426
+ }
427
+ }
590
428
  exports.CorrectResponse = CorrectResponse;
591
- (0, _defineProperty2["default"])(CorrectResponse, "propTypes", {
592
- classes: _propTypes["default"].object.isRequired,
593
- errors: _propTypes["default"].object,
594
- model: _propTypes["default"].object.isRequired,
595
- onChange: _propTypes["default"].func.isRequired
429
+ (0, _defineProperty2.default)(CorrectResponse, "propTypes", {
430
+ errors: _propTypes.default.object,
431
+ model: _propTypes.default.object.isRequired,
432
+ onChange: _propTypes.default.func.isRequired
596
433
  });
597
-
598
- var _default = (0, _styles.withStyles)(styles)(CorrectResponse);
599
-
600
- exports["default"] = _default;
434
+ var _default = exports.default = CorrectResponse;
601
435
  //# sourceMappingURL=correct-response.js.map